1 /*
2  * Copyright (c) 2022 Vestas Wind Systems A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_DRIVERS_CAN_TRANSCEIVER_H_
8 #define ZEPHYR_INCLUDE_DRIVERS_CAN_TRANSCEIVER_H_
9 
10 #include <zephyr/device.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /**
17  * @brief CAN Transceiver Driver APIs
18  * @defgroup can_transceiver CAN Transceiver
19  * @ingroup io_interfaces
20  * @{
21  */
22 
23 /**
24  * @cond INTERNAL_HIDDEN
25  *
26  * For internal driver use only, skip these in public documentation.
27  */
28 
29 /**
30  * @brief Callback API upon enabling CAN transceiver
31  * See @a can_transceiver_enable() for argument description
32  */
33 typedef int (*can_transceiver_enable_t)(const struct device *dev);
34 
35 /**
36  * @brief Callback API upon disabling CAN transceiver
37  * See @a can_transceiver_disable() for argument description
38  */
39 typedef int (*can_transceiver_disable_t)(const struct device *dev);
40 
41 __subsystem struct can_transceiver_driver_api {
42 	can_transceiver_enable_t enable;
43 	can_transceiver_disable_t disable;
44 };
45 
46 /** @endcond */
47 
48 /**
49  * @brief Enable CAN transceiver
50  *
51  * Enable the CAN transceiver.
52  *
53  * @note The CAN transceiver is controlled by the CAN controller driver and
54  *       should not normally be controlled by the application.
55  *
56  * @see can_start()
57  *
58  * @param dev Pointer to the device structure for the driver instance.
59  * @retval 0 If successful.
60  * @retval -EIO General input/output error, failed to enable device.
61  */
can_transceiver_enable(const struct device * dev)62 static inline int can_transceiver_enable(const struct device *dev)
63 {
64 	const struct can_transceiver_driver_api *api =
65 		(const struct can_transceiver_driver_api *)dev->api;
66 
67 	return api->enable(dev);
68 }
69 
70 /**
71  * @brief Disable CAN transceiver
72  *
73  * Disable the CAN transceiver.
74 
75  * @note The CAN transceiver is controlled by the CAN controller driver and
76  *       should not normally be controlled by the application.
77  *
78  * @see can_stop()
79  *
80  * @param dev Pointer to the device structure for the driver instance.
81  * @retval 0 If successful.
82  * @retval -EIO General input/output error, failed to disable device.
83  */
can_transceiver_disable(const struct device * dev)84 static inline int can_transceiver_disable(const struct device *dev)
85 {
86 	const struct can_transceiver_driver_api *api =
87 		(const struct can_transceiver_driver_api *)dev->api;
88 
89 	return api->disable(dev);
90 }
91 
92 /**
93  * @}
94  */
95 
96 #ifdef __cplusplus
97 }
98 #endif
99 
100 #endif /* ZEPHYR_INCLUDE_DRIVERS_CAN_TRANSCEIVER_H_ */
101