1 /*
2 * Copyright (c) 2015 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 /**
8 * @file
9 * Public APIs for Pinmux drivers
10 */
11
12 #ifndef ZEPHYR_INCLUDE_DRIVERS_PINMUX_H_
13 #define ZEPHYR_INCLUDE_DRIVERS_PINMUX_H_
14
15 /**
16 * @brief Pinmux Interface
17 * @defgroup pinmux_interface Pinmux Interface
18 * @ingroup io_interfaces
19 * @{
20 */
21
22 #include <zephyr/types.h>
23 #include <device.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define PINMUX_FUNC_A 0
30 #define PINMUX_FUNC_B 1
31 #define PINMUX_FUNC_C 2
32 #define PINMUX_FUNC_D 3
33 #define PINMUX_FUNC_E 4
34 #define PINMUX_FUNC_F 5
35 #define PINMUX_FUNC_G 6
36 #define PINMUX_FUNC_H 7
37 #define PINMUX_FUNC_I 8
38 #define PINMUX_FUNC_J 9
39 #define PINMUX_FUNC_K 10
40 #define PINMUX_FUNC_L 11
41 #define PINMUX_FUNC_M 12
42 #define PINMUX_FUNC_N 13
43 #define PINMUX_FUNC_O 14
44 #define PINMUX_FUNC_P 15
45
46 #define PINMUX_PULLUP_ENABLE (0x1)
47 #define PINMUX_PULLUP_DISABLE (0x0)
48
49 #define PINMUX_INPUT_ENABLED (0x1)
50 #define PINMUX_OUTPUT_ENABLED (0x0)
51
52 /**
53 * @typedef pmux_set
54 * @brief Callback API upon setting a PIN's function
55 * See pinmux_pin_set() for argument description
56 */
57 typedef int (*pmux_set)(const struct device *dev, uint32_t pin, uint32_t func);
58 /**
59 * @typedef pmux_get
60 * @brief Callback API upon getting a PIN's function
61 * See pinmux_pin_get() for argument description
62 */
63 typedef int (*pmux_get)(const struct device *dev, uint32_t pin,
64 uint32_t *func);
65 /**
66 * @typedef pmux_pullup
67 * @brief Callback API upon setting a PIN's pullup
68 * See pinmix_pin_pullup() for argument description
69 */
70 typedef int (*pmux_pullup)(const struct device *dev, uint32_t pin,
71 uint8_t func);
72 /**
73 * @typedef pmux_input
74 * @brief Callback API upon setting a PIN's input function
75 * See pinmux_input() for argument description
76 */
77 typedef int (*pmux_input)(const struct device *dev, uint32_t pin,
78 uint8_t func);
79
80 __subsystem struct pinmux_driver_api {
81 pmux_set set;
82 pmux_get get;
83 pmux_pullup pullup;
84 pmux_input input;
85 };
86
pinmux_pin_set(const struct device * dev,uint32_t pin,uint32_t func)87 static inline int pinmux_pin_set(const struct device *dev, uint32_t pin,
88 uint32_t func)
89 {
90 const struct pinmux_driver_api *api =
91 (const struct pinmux_driver_api *)dev->api;
92
93 return api->set(dev, pin, func);
94 }
95
pinmux_pin_get(const struct device * dev,uint32_t pin,uint32_t * func)96 static inline int pinmux_pin_get(const struct device *dev, uint32_t pin,
97 uint32_t *func)
98 {
99 const struct pinmux_driver_api *api =
100 (const struct pinmux_driver_api *)dev->api;
101
102 return api->get(dev, pin, func);
103 }
104
pinmux_pin_pullup(const struct device * dev,uint32_t pin,uint8_t func)105 static inline int pinmux_pin_pullup(const struct device *dev, uint32_t pin,
106 uint8_t func)
107 {
108 const struct pinmux_driver_api *api =
109 (const struct pinmux_driver_api *)dev->api;
110
111 return api->pullup(dev, pin, func);
112 }
113
pinmux_pin_input_enable(const struct device * dev,uint32_t pin,uint8_t func)114 static inline int pinmux_pin_input_enable(const struct device *dev,
115 uint32_t pin,
116 uint8_t func)
117 {
118 const struct pinmux_driver_api *api =
119 (const struct pinmux_driver_api *)dev->api;
120
121 return api->input(dev, pin, func);
122 }
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 /**
129 *
130 * @}
131 */
132
133 #endif /* ZEPHYR_INCLUDE_DRIVERS_PINMUX_H_ */
134