Bouffalo SDK  1.0
Bouffalolab Software Development Kit
bflb_gpio.h
Go to the documentation of this file.
1 #ifndef _BFLB_GPIO_H
2 #define _BFLB_GPIO_H
3 
4 #include "bflb_core.h"
5 
34 #define GPIO_PIN_0 0
35 #define GPIO_PIN_1 1
36 #define GPIO_PIN_2 2
37 #define GPIO_PIN_3 3
38 #define GPIO_PIN_4 4
39 #define GPIO_PIN_5 5
40 #define GPIO_PIN_6 6
41 #define GPIO_PIN_7 7
42 #define GPIO_PIN_8 8
43 #define GPIO_PIN_9 9
44 #define GPIO_PIN_10 10
45 #define GPIO_PIN_11 11
46 #define GPIO_PIN_12 12
47 #define GPIO_PIN_13 13
48 #define GPIO_PIN_14 14
49 #define GPIO_PIN_15 15
50 #define GPIO_PIN_16 16
51 #define GPIO_PIN_17 17
52 #define GPIO_PIN_18 18
53 #define GPIO_PIN_19 19
54 #define GPIO_PIN_20 20
55 #define GPIO_PIN_21 21
56 #define GPIO_PIN_22 22
57 #define GPIO_PIN_23 23
58 #define GPIO_PIN_24 24
59 #define GPIO_PIN_25 25
60 #define GPIO_PIN_26 26
61 #define GPIO_PIN_27 27
62 #define GPIO_PIN_28 28
63 #define GPIO_PIN_29 29
64 #define GPIO_PIN_30 30
65 #define GPIO_PIN_31 31
66 #define GPIO_PIN_32 32
67 #define GPIO_PIN_33 33
68 #define GPIO_PIN_34 34
69 #define GPIO_PIN_35 35
70 #define GPIO_PIN_36 36
71 #define GPIO_PIN_37 37
72 #define GPIO_PIN_38 38
73 #define GPIO_PIN_39 39
74 #define GPIO_PIN_40 40
75 #define GPIO_PIN_41 41
76 #define GPIO_PIN_42 42
77 #define GPIO_PIN_43 43
78 #define GPIO_PIN_44 44
79 #define GPIO_PIN_45 45
80 
84 /* cfgset list */
85 #define GPIO_FUNC_SHIFT (0) /* Bits 0-4: GPIO function */
86 #define GPIO_FUNC_MASK (0x1f << GPIO_FUNC_SHIFT)
87 #if defined(BL602)
88 #define GPIO_FUNC_SDU (1 << GPIO_FUNC_SHIFT)
89 #define GPIO_FUNC_SPI0 (4 << GPIO_FUNC_SHIFT)
90 #define GPIO_FUNC_I2C0 (6 << GPIO_FUNC_SHIFT)
91 #define GPIO_FUNC_PWM0 (8 << GPIO_FUNC_SHIFT)
92 #define GPIO_FUNC_JTAG (14 << GPIO_FUNC_SHIFT)
93 #elif defined(BL702)
94 #define GPIO_FUNC_CLK_OUT (0 << GPIO_FUNC_SHIFT)
95 #define GPIO_FUNC_I2S (3 << GPIO_FUNC_SHIFT)
96 #define GPIO_FUNC_SPI0 (4 << GPIO_FUNC_SHIFT)
97 #define GPIO_FUNC_I2C0 (6 << GPIO_FUNC_SHIFT)
98 #define GPIO_FUNC_PWM0 (8 << GPIO_FUNC_SHIFT)
99 #define GPIO_FUNC_CAM (9 << GPIO_FUNC_SHIFT)
100 #define GPIO_FUNC_JTAG (14 << GPIO_FUNC_SHIFT)
101 #define GPIO_FUNC_EMAC (19 << GPIO_FUNC_SHIFT)
102 #define GPIO_FUNC_CAM_MCLK (23 << GPIO_FUNC_SHIFT)
103 #elif defined(BL702L)
104 #define GPIO_FUNC_SPI0 (4 << GPIO_FUNC_SHIFT)
105 #define GPIO_FUNC_I2C0 (6 << GPIO_FUNC_SHIFT)
106 #define GPIO_FUNC_PWM0 (8 << GPIO_FUNC_SHIFT)
107 #define GPIO_FUNC_KEYSCAN (13 << GPIO_FUNC_SHIFT)
108 #define GPIO_FUNC_JTAG (14 << GPIO_FUNC_SHIFT)
109 #elif defined(BL616)
110 #define GPIO_FUNC_SDH (0 << GPIO_FUNC_SHIFT)
111 #define GPIO_FUNC_SPI0 (1 << GPIO_FUNC_SHIFT)
112 #define GPIO_FUNC_I2S (3 << GPIO_FUNC_SHIFT)
113 #define GPIO_FUNC_PDM (4 << GPIO_FUNC_SHIFT)
114 #define GPIO_FUNC_I2C0 (5 << GPIO_FUNC_SHIFT)
115 #define GPIO_FUNC_I2C1 (6 << GPIO_FUNC_SHIFT)
116 #define GPIO_FUNC_EMAC (8 << GPIO_FUNC_SHIFT)
117 #define GPIO_FUNC_CAM (9 << GPIO_FUNC_SHIFT)
118 #define GPIO_FUNC_SDU (12 << GPIO_FUNC_SHIFT)
119 #define GPIO_FUNC_PWM0 (16 << GPIO_FUNC_SHIFT)
120 #define GPIO_FUNC_DBI_B (22 << GPIO_FUNC_SHIFT)
121 #define GPIO_FUNC_DBI_C (23 << GPIO_FUNC_SHIFT)
122 #define GPIO_FUNC_DBI_QSPI (24 << GPIO_FUNC_SHIFT)
123 #define GPIO_FUNC_AUDAC_PWM (25 << GPIO_FUNC_SHIFT)
124 #define GPIO_FUNC_JTAG (26 << GPIO_FUNC_SHIFT)
125 #define GPIO_FUNC_CLKOUT (31 << GPIO_FUNC_SHIFT)
126 #elif defined(BL606P) || defined(BL808)
127 #define GPIO_FUNC_SDH (0 << GPIO_FUNC_SHIFT)
128 #define GPIO_FUNC_SPI0 (1 << GPIO_FUNC_SHIFT)
129 #define GPIO_FUNC_I2S (3 << GPIO_FUNC_SHIFT)
130 #define GPIO_FUNC_PDM (4 << GPIO_FUNC_SHIFT)
131 #define GPIO_FUNC_I2C0 (5 << GPIO_FUNC_SHIFT)
132 #define GPIO_FUNC_I2C1 (6 << GPIO_FUNC_SHIFT)
133 #define GPIO_FUNC_EMAC (8 << GPIO_FUNC_SHIFT)
134 #define GPIO_FUNC_CAM (9 << GPIO_FUNC_SHIFT)
135 #define GPIO_FUNC_SDU (12 << GPIO_FUNC_SHIFT)
136 #define GPIO_FUNC_PWM0 (16 << GPIO_FUNC_SHIFT)
137 #define GPIO_FUNC_PWM1 (17 << GPIO_FUNC_SHIFT)
138 #define GPIO_FUNC_SPI1 (18 << GPIO_FUNC_SHIFT)
139 #define GPIO_FUNC_I2C2 (19 << GPIO_FUNC_SHIFT)
140 #define GPIO_FUNC_I2C3 (20 << GPIO_FUNC_SHIFT)
141 #define GPIO_FUNC_DBI_B (22 << GPIO_FUNC_SHIFT)
142 #define GPIO_FUNC_DBI_C (23 << GPIO_FUNC_SHIFT)
143 #define GPIO_FUNC_JTAG_LP (25 << GPIO_FUNC_SHIFT)
144 #define GPIO_FUNC_JTAG_M0 (26 << GPIO_FUNC_SHIFT)
145 #define GPIO_FUNC_JTAG_D0 (27 << GPIO_FUNC_SHIFT)
146 #define GPIO_FUNC_CLKOUT (31 << GPIO_FUNC_SHIFT)
147 #elif defined(BL628)
148 #define GPIO_FUNC_SDH (0 << GPIO_FUNC_SHIFT)
149 #define GPIO_FUNC_SPI0 (1 << GPIO_FUNC_SHIFT)
150 #define GPIO_FUNC_I2S (3 << GPIO_FUNC_SHIFT)
151 #define GPIO_FUNC_PDM (4 << GPIO_FUNC_SHIFT)
152 #define GPIO_FUNC_I2C0 (5 << GPIO_FUNC_SHIFT)
153 #define GPIO_FUNC_I2C1 (6 << GPIO_FUNC_SHIFT)
154 #define GPIO_FUNC_UART (7 << GPIO_FUNC_SHIFT)
155 #define GPIO_FUNC_EMAC (8 << GPIO_FUNC_SHIFT)
156 #define GPIO_FUNC_CAM (9 << GPIO_FUNC_SHIFT)
157 #define GPIO_FUNC_SDU (12 << GPIO_FUNC_SHIFT)
158 #define GPIO_FUNC_PWM0 (16 << GPIO_FUNC_SHIFT)
159 #define GPIO_FUNC_DBI_B (22 << GPIO_FUNC_SHIFT)
160 #define GPIO_FUNC_DBI_C (23 << GPIO_FUNC_SHIFT)
161 #define GPIO_FUNC_CLKOUT (31 << GPIO_FUNC_SHIFT)
162 #endif
163 
164 #define GPIO_MODE_SHIFT (5) /* Bits 5-6: Port Mode */
165 #define GPIO_MODE_MASK (3 << GPIO_MODE_SHIFT)
166 #define GPIO_INPUT (0 << GPIO_MODE_SHIFT) /* Input Enable */
167 #define GPIO_OUTPUT (1 << GPIO_MODE_SHIFT) /* Output Enable */
168 #define GPIO_ANALOG (2 << GPIO_MODE_SHIFT) /* Analog Enable */
169 #define GPIO_ALTERNATE (3 << GPIO_MODE_SHIFT) /* Alternate Enable */
170 
171 #define GPIO_PUPD_SHIFT (7) /* Bits 7-8: Pull-up/down */
172 #define GPIO_PUPD_MASK (3 << GPIO_PUPD_SHIFT)
173 #define GPIO_FLOAT (0 << GPIO_PUPD_SHIFT) /* No pull-up, pull-down */
174 #define GPIO_PULLUP (1 << GPIO_PUPD_SHIFT) /* Pull-up */
175 #define GPIO_PULLDOWN (2 << GPIO_PUPD_SHIFT) /* Pull-down */
176 
177 #define GPIO_SMT_SHIFT (9) /* Bits 9: SMT Enable */
178 #define GPIO_SMT_MASK (1 << GPIO_SMT_SHIFT)
179 #define GPIO_SMT_DIS (0 << GPIO_SMT_SHIFT)
180 #define GPIO_SMT_EN (1 << GPIO_SMT_SHIFT)
181 
182 #define GPIO_DRV_SHIFT (10) /* Bits 10-11: Drive */
183 #define GPIO_DRV_MASK (3 << GPIO_DRV_SHIFT)
184 #define GPIO_DRV_0 (0 << GPIO_DRV_SHIFT)
185 #define GPIO_DRV_1 (1 << GPIO_DRV_SHIFT)
186 #define GPIO_DRV_2 (2 << GPIO_DRV_SHIFT)
187 #define GPIO_DRV_3 (3 << GPIO_DRV_SHIFT)
188 
192 #define GPIO_INT_TRIG_MODE_SYNC_FALLING_EDGE 0
193 #define GPIO_INT_TRIG_MODE_SYNC_RISING_EDGE 1
194 #define GPIO_INT_TRIG_MODE_SYNC_LOW_LEVEL 2
195 #define GPIO_INT_TRIG_MODE_SYNC_HIGH_LEVEL 3
196 #if defined(BL602) || defined(BL702)
197 #define GPIO_INT_TRIG_MODE_ASYNC_FALLING_EDGE 4
198 #define GPIO_INT_TRIG_MODE_ASYNC_RISING_EDGE 5
199 #define GPIO_INT_TRIG_MODE_ASYNC_LOW_LEVEL 6
200 #define GPIO_INT_TRIG_MODE_ASYNC_HIGH_LEVEL 7
201 #else
202 #define GPIO_INT_TRIG_MODE_SYNC_FALLING_RISING_EDGE 4
203 #define GPIO_INT_TRIG_MODE_ASYNC_FALLING_EDGE 8
204 #define GPIO_INT_TRIG_MODE_ASYNC_RISING_EDGE 9
205 #define GPIO_INT_TRIG_MODE_ASYNC_LOW_LEVEL 10
206 #define GPIO_INT_TRIG_MODE_ASYNC_HIGH_LEVEL 11
207 #endif
208 
215 #define GPIO_UART_FUNC_UART0_RTS 0
216 #define GPIO_UART_FUNC_UART0_CTS 1
217 #define GPIO_UART_FUNC_UART0_TX 2
218 #define GPIO_UART_FUNC_UART0_RX 3
219 #define GPIO_UART_FUNC_UART1_RTS 4
220 #define GPIO_UART_FUNC_UART1_CTS 5
221 #define GPIO_UART_FUNC_UART1_TX 6
222 #define GPIO_UART_FUNC_UART1_RX 7
223 #if defined(BL808) || defined(BL606P)
224 #define GPIO_UART_FUNC_UART2_RTS 8
225 #define GPIO_UART_FUNC_UART2_CTS 9
226 #define GPIO_UART_FUNC_UART2_TX 10
227 #define GPIO_UART_FUNC_UART2_RX 11
228 #endif
229 
236 #define GPIO_CMD_GET_GPIO_FUN (0x01)
237 
241 #ifdef __cplusplus
242 extern "C" {
243 #endif
244 
252 void bflb_gpio_init(struct bflb_device_s *dev, uint8_t pin, uint32_t cfgset);
253 
260 void bflb_gpio_deinit(struct bflb_device_s *dev, uint8_t pin);
261 
268 void bflb_gpio_set(struct bflb_device_s *dev, uint8_t pin);
269 
276 void bflb_gpio_reset(struct bflb_device_s *dev, uint8_t pin);
277 
285 bool bflb_gpio_read(struct bflb_device_s *dev, uint8_t pin);
286 
293 void bflb_gpio_pin0_31_write(struct bflb_device_s *dev, uint32_t val);
294 
301 void bflb_gpio_pin32_63_write(struct bflb_device_s *dev, uint32_t val);
302 
309 uint32_t bflb_gpio_pin0_31_read(struct bflb_device_s *dev);
310 
317 uint32_t bflb_gpio_pin32_63_read(struct bflb_device_s *dev);
318 
326 void bflb_gpio_int_init(struct bflb_device_s *dev, uint8_t pin, uint8_t trig_mode);
327 
335 void bflb_gpio_int_mask(struct bflb_device_s *dev, uint8_t pin, bool mask);
336 
344 bool bflb_gpio_get_intstatus(struct bflb_device_s *dev, uint8_t pin);
345 
352 void bflb_gpio_int_clear(struct bflb_device_s *dev, uint8_t pin);
353 
361 void bflb_gpio_uart_init(struct bflb_device_s *dev, uint8_t pin, uint8_t uart_func);
362 
372 int bflb_gpio_feature_control(struct bflb_device_s *dev, int cmd, size_t arg);
373 
374 #ifdef __cplusplus
375 }
376 #endif
377 
386 #endif
void bflb_gpio_deinit(struct bflb_device_s *dev, uint8_t pin)
Deinitialize gpio pin with input float.
int bflb_gpio_feature_control(struct bflb_device_s *dev, int cmd, size_t arg)
Control gpio feature.
void bflb_gpio_int_mask(struct bflb_device_s *dev, uint8_t pin, bool mask)
Enable or disable gpio pin interrupt.
void bflb_gpio_int_init(struct bflb_device_s *dev, uint8_t pin, uint8_t trig_mode)
Config gpio pin interrupt.
void bflb_gpio_int_clear(struct bflb_device_s *dev, uint8_t pin)
Clear gpio pin interrupt status.
uint32_t bflb_gpio_pin0_31_read(struct bflb_device_s *dev)
Read level from gpio pin 0~31.
void bflb_gpio_pin0_31_write(struct bflb_device_s *dev, uint32_t val)
Write gpio pin 0~31.
void bflb_gpio_init(struct bflb_device_s *dev, uint8_t pin, uint32_t cfgset)
Initialize gpio pin.
void bflb_gpio_pin32_63_write(struct bflb_device_s *dev, uint32_t val)
Write gpio pin 32~63.
bool bflb_gpio_read(struct bflb_device_s *dev, uint8_t pin)
Read level from gpio pin.
void bflb_gpio_reset(struct bflb_device_s *dev, uint8_t pin)
Write gpio pin with low level.
uint32_t bflb_gpio_pin32_63_read(struct bflb_device_s *dev)
Read level from gpio pin 32~63.
bool bflb_gpio_get_intstatus(struct bflb_device_s *dev, uint8_t pin)
Get gpio pin interrupt status.
void bflb_gpio_set(struct bflb_device_s *dev, uint8_t pin)
Write gpio pin with high level.
void bflb_gpio_uart_init(struct bflb_device_s *dev, uint8_t pin, uint8_t uart_func)
Config gpio pin with uart function.