• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef LZ_HARDWARE_GPIO_H
17 #define LZ_HARDWARE_GPIO_H
18 
19 typedef enum {
20     GPIO0_PA0 = 0,
21     GPIO0_PA1,
22     GPIO0_PA2,
23     GPIO0_PA3,
24     GPIO0_PA4,
25     GPIO0_PA5,
26     GPIO0_PA6,
27     GPIO0_PA7,
28 
29     GPIO0_PB0,
30     GPIO0_PB1,
31     GPIO0_PB2,
32     GPIO0_PB3,
33     GPIO0_PB4,
34     GPIO0_PB5,
35     GPIO0_PB6,
36     GPIO0_PB7,
37 
38     GPIO0_PC0,
39     GPIO0_PC1,
40     GPIO0_PC2,
41     GPIO0_PC3,
42     GPIO0_PC4,
43     GPIO0_PC5,
44     GPIO0_PC6,
45     GPIO0_PC7,
46 
47     GPIO0_PD0,
48     GPIO0_PD1,
49     GPIO0_PD2,
50     GPIO0_PD3,
51     GPIO0_PD4,
52     GPIO0_PD5,
53     GPIO0_PD6,
54     GPIO0_PD7,
55 
56     GPIO1_PA0 = 32,
57     GPIO1_PA1,
58     GPIO1_PA2,
59     GPIO1_PA3,
60     GPIO1_PA4,
61     GPIO1_PA5,
62     GPIO1_PA6,
63     GPIO1_PA7,
64 
65     GPIO1_PB0,
66     GPIO1_PB1,
67     GPIO1_PB2,
68     GPIO1_PB3,
69     GPIO1_PB4,
70     GPIO1_PB5,
71     GPIO1_PB6,
72     GPIO1_PB7,
73 
74     GPIO1_PC0,
75     GPIO1_PC1,
76     GPIO1_PC2,
77     GPIO1_PC3,
78     GPIO1_PC4,
79     GPIO1_PC5,
80     GPIO1_PC6,
81     GPIO1_PC7,
82 
83     GPIO1_PD0,
84     GPIO1_PD1,
85     GPIO1_PD2,
86     GPIO1_PD3,
87     GPIO1_PD4,
88     GPIO1_PD5,
89     GPIO1_PD6,
90     GPIO1_PD7,
91 
92     GPIO2_PA0 = 64,
93     GPIO2_PA1,
94     GPIO2_PA2,
95     GPIO2_PA3,
96     GPIO2_PA4,
97     GPIO2_PA5,
98     GPIO2_PA6,
99     GPIO2_PA7,
100 
101     GPIO2_PB0,
102     GPIO2_PB1,
103     GPIO2_PB2,
104     GPIO2_PB3,
105     GPIO2_PB4,
106     GPIO2_PB5,
107     GPIO2_PB6,
108     GPIO2_PB7,
109 
110     GPIO2_PC0,
111     GPIO2_PC1,
112     GPIO2_PC2,
113     GPIO2_PC3,
114     GPIO2_PC4,
115     GPIO2_PC5,
116     GPIO2_PC6,
117     GPIO2_PC7,
118 
119     GPIO2_PD0,
120     GPIO2_PD1,
121     GPIO2_PD2,
122     GPIO2_PD3,
123     GPIO2_PD4,
124     GPIO2_PD5,
125     GPIO2_PD6,
126     GPIO2_PD7,
127 
128     GPIO3_PA0 = 96,
129     GPIO3_PA1,
130     GPIO3_PA2,
131     GPIO3_PA3,
132     GPIO3_PA4,
133     GPIO3_PA5,
134     GPIO3_PA6,
135     GPIO3_PA7,
136 
137     GPIO3_PB0,
138     GPIO3_PB1,
139     GPIO3_PB2,
140     GPIO3_PB3,
141     GPIO3_PB4,
142     GPIO3_PB5,
143     GPIO3_PB6,
144     GPIO3_PB7,
145 
146     GPIO3_PC0,
147     GPIO3_PC1,
148     GPIO3_PC2,
149     GPIO3_PC3,
150     GPIO3_PC4,
151     GPIO3_PC5,
152     GPIO3_PC6,
153     GPIO3_PC7,
154 
155     GPIO3_PD0,
156     GPIO3_PD1,
157     GPIO3_PD2,
158     GPIO3_PD3,
159     GPIO3_PD4,
160     GPIO3_PD5,
161     GPIO3_PD6,
162     GPIO3_PD7,
163 
164     GPIO4_PA0 = 128,
165     GPIO4_PA1,
166     GPIO4_PA2,
167     GPIO4_PA3,
168     GPIO4_PA4,
169     GPIO4_PA5,
170     GPIO4_PA6,
171     GPIO4_PA7,
172 
173     GPIO4_PB0,
174     GPIO4_PB1,
175     GPIO4_PB2,
176     GPIO4_PB3,
177     GPIO4_PB4,
178     GPIO4_PB5,
179     GPIO4_PB6,
180     GPIO4_PB7,
181 
182     GPIO4_PC0,
183     GPIO4_PC1,
184     GPIO4_PC2,
185     GPIO4_PC3,
186     GPIO4_PC4,
187     GPIO4_PC5,
188     GPIO4_PC6,
189     GPIO4_PC7,
190 
191     GPIO4_PD0,
192     GPIO4_PD1,
193     GPIO4_PD2,
194     GPIO4_PD3,
195     GPIO4_PD4,
196     GPIO4_PD5,
197     GPIO4_PD6,
198     GPIO4_PD7,
199 
200     INVALID_GPIO,
201 } GpioID;
202 
203 /**
204  * @brief Enumerates GPIO level values.
205  */
206 typedef enum {
207     /** Low GPIO level */
208     LZGPIO_LEVEL_LOW = 0,
209     /** High GPIO level */
210     LZGPIO_LEVEL_HIGH,
211     /** Keep the last value, no set */
212     LZGPIO_LEVEL_KEEP,
213 } LzGpioValue;
214 
215 /**
216  * @brief Enumerates GPIO directions.
217  */
218 typedef enum {
219     /** Input */
220     LZGPIO_DIR_IN = 0,
221     /** Output */
222     LZGPIO_DIR_OUT,
223     /** Keep the last direction, no set */
224     LZGPIO_DIR_KEEP,
225 } LzGpioDir;
226 
227 /**
228  * @brief Enumerates GPIO interrupt trigger types.
229  */
230 typedef enum {
231     LZGPIO_INT_NONE,
232     /** Interrupt at rising edge */
233     LZGPIO_INT_EDGE_RISING,
234     /** Interrupt at falling edge */
235     LZGPIO_INT_EDGE_FALLING,
236     /** Interrupt at falling and rising edge */
237     LZGPIO_INT_EDGE_BOTH,
238     /** Interrupt at high level */
239     LZGPIO_INT_LEVEL_HIGH,
240     /** Interrupt at low level */
241     LZGPIO_INT_LEVEL_LOW = 0x8,
242 } LzGpioIntType;
243 
244 /**
245  * @brief Indicates the GPIO interrupt callback.
246  *
247  */
248 typedef void (*GpioIsrFunc) (void *arg);
249 
250 /**
251  * @brief Initializes a GPIO device.
252  *
253  * @param id Indicates the GPIO pin number.
254  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the GPIO device is initialized;
255  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
256  */
257 unsigned int LzGpioInit(GpioID id);
258 
259 /**
260  * @brief Deinitializes a GPIO device.
261  *
262  * @param id Indicates the GPIO pin number.
263  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the GPIO device is deinitialized;
264  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
265  */
266 unsigned int LzGpioDeinit(GpioID id);
267 
268 /**
269  * @brief Sets the direction for a GPIO pin.
270  *
271  * @param id Indicates the GPIO pin number.
272  * @param dir Indicates the GPIO input/output direction.
273  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the direction is set;
274  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
275  */
276 unsigned int LzGpioSetDir(GpioID id, LzGpioDir dir);
277 
278 /**
279  * @brief Obtains the direction for a GPIO pin.
280  *
281  * @param id Indicates the GPIO pin number.
282  * @param dir Indicates the pointer to the GPIO input/output direction.
283  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the direction is obtained;
284  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
285  */
286 unsigned int LzGpioGetDir(GpioID id, LzGpioDir *dir);
287 
288 /**
289  * @brief Sets the level value for a GPIO pin.
290  *
291  * @param id Indicates the GPIO pin number.
292  * @param val Indicates the level value.
293  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the level value is set;
294  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
295  */
296 unsigned int LzGpioSetVal(GpioID id, LzGpioValue val);
297 
298 /**
299  * @brief Obtains the level value of a GPIO pin.
300  *
301  * @param id Indicates the GPIO pin number.
302  * @param val Indicates the pointer to the level value.
303  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the level value is obtained;
304  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
305  */
306 unsigned int LzGpioGetVal(GpioID id, LzGpioValue *val);
307 
308 /**
309  * @brief Enables the interrupt feature for a GPIO pin.
310  *
311  * This function can be used to set the interrupt type, interrupt polarity, and interrupt callback for a GPIO pin.
312  *
313  * @param id Indicates the GPIO pin number.
314  * @param type Indicates the interrupt type.
315  * @param func Indicates the interrupt callback function.
316  * @param arg Indicates the pointer to the argument used in the interrupt callback function.
317  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the interrupt feature is enabled;
318  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
319  */
320 unsigned int LzGpioRegisterIsrFunc(GpioID id, LzGpioIntType type, GpioIsrFunc func, void *arg);
321 
322 /**
323  * @brief Disables the interrupt feature for a GPIO pin.
324  *
325  * @param id Indicates the GPIO pin number.
326  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the interrupt feature is disabled;
327  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
328  */
329 unsigned int LzGpioUnregisterIsrFunc(GpioID id);
330 
331 /**
332  * @brief Enable the interrupt for a GPIO pin.
333  *
334  * @param id Indicates the GPIO pin number.
335  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the interrupt feature is masked;
336  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
337  */
338 unsigned int LzGpioEnableIsr(GpioID id);
339 
340 /**
341  * @brief Disable the interrupt for a GPIO pin.
342  *
343  * @param id Indicates the GPIO pin number.
344  * @return Returns {@link LZ_HARDWARE_SUCCESS} if the interrupt feature is masked;
345  * returns {@link LZ_HARDWARE_FAILURE} otherwise. For details about other return values, see the chip description.
346  */
347 unsigned int LzGpioDisableIsr(GpioID id);
348 
349 #endif
350