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