app_io.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file app_io.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of GPIO app library.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup APP_DRIVER APP DRIVER
43 * @{
44 */
45
46 /** @defgroup APP_GPIO GPIO
47 * @brief GPIO APP module driver.
48 * @{
49 */
50
51
52 #ifndef _APP_IO_H_
53 #define _APP_IO_H_
54
55 #include "app_drv_error.h"
56 #include <stdint.h>
57
58 /** @addtogroup APP_GPIO_PIN_DEFINES Defines
59 * @{
60 */
61 /** @addtogroup GR551x_pins IO pins
62 * @{
63 */
64
65 /**
66 * @brief APP_GPIO_DEFINE Defines
67 */
68 #define APP_IO_PIN_0 ((uint32_t)0x00000001U) /**< Pin 0 selected */
69 #define APP_IO_PIN_1 ((uint32_t)0x00000002U) /**< Pin 1 selected */
70 #define APP_IO_PIN_2 ((uint32_t)0x00000004U) /**< Pin 2 selected */
71 #define APP_IO_PIN_3 ((uint32_t)0x00000008U) /**< Pin 3 selected */
72 #define APP_IO_PIN_4 ((uint32_t)0x00000010U) /**< Pin 4 selected */
73 #define APP_IO_PIN_5 ((uint32_t)0x00000020U) /**< Pin 5 selected */
74 #define APP_IO_PIN_6 ((uint32_t)0x00000040U) /**< Pin 6 selected */
75 #define APP_IO_PIN_7 ((uint32_t)0x00000080U) /**< Pin 7 selected */
76 #define APP_IO_PIN_8 ((uint32_t)0x00000100U) /**< Pin 8 selected */
77 #define APP_IO_PIN_9 ((uint32_t)0x00000200U) /**< Pin 9 selected */
78 #define APP_IO_PIN_10 ((uint32_t)0x00000400U) /**< Pin 10 selected */
79 #define APP_IO_PIN_11 ((uint32_t)0x00000800U) /**< Pin 11 selected */
80 #define APP_IO_PIN_12 ((uint32_t)0x00001000U) /**< Pin 12 selected */
81 #define APP_IO_PIN_13 ((uint32_t)0x00002000U) /**< Pin 13 selected */
82 #define APP_IO_PIN_14 ((uint32_t)0x00004000U) /**< Pin 14 selected */
83 #define APP_IO_PIN_15 ((uint32_t)0x00008000U) /**< Pin 15 selected */
84 #define APP_IO_PIN_16 ((uint32_t)0x00010000U) /**< Pin 16 selected */
85 #define APP_IO_PIN_17 ((uint32_t)0x00020000U) /**< Pin 17 selected */
86 #define APP_IO_PIN_18 ((uint32_t)0x00040000U) /**< Pin 18 selected */
87 #define APP_IO_PIN_19 ((uint32_t)0x00080000U) /**< Pin 19 selected */
88 #define APP_IO_PIN_20 ((uint32_t)0x00100000U) /**< Pin 20 selected */
89 #define APP_IO_PIN_21 ((uint32_t)0x00200000U) /**< Pin 21 selected */
90 #define APP_IO_PIN_22 ((uint32_t)0x00400000U) /**< Pin 22 selected */
91 #define APP_IO_PIN_23 ((uint32_t)0x00800000U) /**< Pin 23 selected */
92 #define APP_IO_PIN_24 ((uint32_t)0x01000000U) /**< Pin 24 selected */
93 #define APP_IO_PIN_25 ((uint32_t)0x02000000U) /**< Pin 25 selected */
94 #define APP_IO_PIN_26 ((uint32_t)0x04000000U) /**< Pin 26 selected */
95 #define APP_IO_PIN_27 ((uint32_t)0x08000000U) /**< Pin 27 selected */
96 #define APP_IO_PIN_28 ((uint32_t)0x10000000U) /**< Pin 28 selected */
97 #define APP_IO_PIN_29 ((uint32_t)0x20000000U) /**< Pin 29 selected */
98 #define APP_IO_PIN_30 ((uint32_t)0x40000000U) /**< Pin 30 selected */
99 #define APP_IO_PIN_31 ((uint32_t)0x80000000U) /**< Pin 31 selected */
100
101 #define APP_IO_PINS_0_15 ((uint32_t)0x0000FFFFU) /**< 0~15 pins selected */
102 #define APP_IO_PINS_16_31 ((uint32_t)0xFFFF0000U) /**< 16~31 pins selected */
103 #define APP_IO_PIN_ALL ((uint32_t)0xFFFFFFFFU) /**< All pins selected */
104 #define APP_MSIO_PIN_MASK ((uint32_t)0x0000001FU) /**< PIN mask for assert test */
105 #define APP_MSIO_PIN_ALL ((uint32_t)0x001FU) /**< All pins selected */
106 #define APP_AON_IO_PIN_MASK ((uint32_t)0x000000FFU) /**< PIN mask for assert test */
107 #define APP_AON_IO_PIN_ALL ((uint32_t)0x00FFU) /**< All pins selected */
108
109 #define APP_IO_PIN_MASK ((uint32_t)0xFFFFFFFFU) /**< PIN mask for assert test */
110
111 /**
112 * @brief GR551x_APP_GPIO_default_config initStruct default configuart APP_GPIOn
113 */
114 #define APP_IO_DEFAULT_CONFIG \
115 { \
116 .pin = APP_IO_PIN_ALL, \
117 .mode = APP_IO_MODE_INPUT, \
118 .pull = APP_IO_PULLDOWN, \
119 .mux = APP_IO_MUX_7, \
120 }
121
122 /** @} */
123 /** @} */
124
125 /** @addtogroup APP_GPIO_ENUMERATIONS Enumerations
126 * @{
127 */
128 /**
129 * @brief GPIO state Enumerations definition
130 */
131 typedef enum
132 {
133 APP_IO_PIN_RESET, /**< IO pin low level. */
134 APP_IO_PIN_SET, /**< IO pin high level. */
135 } app_io_pin_state_t;
136
137 /**
138 * @brief GPIO type Enumerations definition
139 */
140 typedef enum
141 {
142 APP_IO_TYPE_NORMAL, /**< General Purpose Input/Output. */
143 APP_IO_TYPE_AON, /**< Always-on Input/Output. */
144 APP_IO_TYPE_MSIO, /**< Mixed Signal I/O. */
145 APP_IO_TYPE_MAX, /**< Only for check parameter, not used as input parameters. */
146 }app_io_type_t;
147
148 /**
149 * @brief GPIO mode Enumerations definition
150 */
151 typedef enum
152 {
153 APP_IO_MODE_INPUT, /**< Input Mode. */
154 APP_IO_MODE_OUT_PUT, /**< Output Mode. */
155 APP_IO_MODE_MUX, /**< Mux Mode. */
156 APP_IO_MODE_IT_RISING, /**< Interrupt Mode with Rising edge trigger detection. */
157 APP_IO_MODE_IT_FALLING, /**< Interrupt Mode with Falling edge trigger detection. */
158 APP_IO_MODE_IT_HIGH, /**< Interrupt Mode with High-level trigger detection. */
159 APP_IO_MODE_IT_LOW, /**< Interrupt Mode with Low-level trigger detection. */
160 APP_IO_MODE_ANALOG, /**< Analog IO Mode. */
161 APP_IO_MODE_MAX, /**< Only for check parameter, not used as input parameters. */
162 }app_io_mode_t;
163
164 /**
165 * @brief GPIO wake-up mode Enumerations definition
166 */
167 typedef enum
168 {
169 APP_IO_NONE_WAKEUP, /**< None Wakeup. */
170 APP_IO_DISABLE_WAKEUP, /**< Disable AON GPIO Wakeup. */
171 APP_IO_ENABLE_WAKEUP, /**< Enable AON GPIO Wakeup. */
172 }app_handle_mode_t;
173
174 /**
175 * @brief GPIO handler context type Enumerations definition
176 */
177 typedef enum
178 {
179 APP_IO_CTX_WAKEUP, /**< the event of wakeup. */
180 APP_IO_CTX_INT, /**< the event of interrupt. */
181 }app_ctx_type_t;
182
183 /**
184 * @brief GPIO pull Enumerations definition
185 */
186 typedef enum
187 {
188 APP_IO_NOPULL, /**< No Pull-up or Pull-down activation. */
189 APP_IO_PULLUP, /**< Pull-up activation. */
190 APP_IO_PULLDOWN, /**< Pull-down activation. */
191 APP_IO_PULL_MAX /**< Only for check parameter, not used as input parameters. */
192 }app_io_pull_t;
193
194 /**
195 * @brief GPIO mux Enumerations definition
196 */
197 typedef enum
198 {
199 APP_IO_MUX_0, /**< IO mux mode 0. */
200 APP_IO_MUX_1, /**< IO mux mode 1. */
201 APP_IO_MUX_2, /**< IO mux mode 2. */
202 APP_IO_MUX_3, /**< IO mux mode 3. */
203 APP_IO_MUX_4, /**< IO mux mode 4. */
204 APP_IO_MUX_5, /**< IO mux mode 5. */
205 APP_IO_MUX_6, /**< IO mux mode 6. */
206 APP_IO_MUX_7, /**< IO mux mode 7. */
207 APP_IO_MUX_8, /**< IO mux mode 8. */
208 APP_IO_MUX_MAX, /**< Only for check parameter, not used as input parameters. */
209 }app_io_mux_t;
210 /** @} */
211
212 /** @addtogroup APP_GPIO_STRUCT Structures
213 * @{
214 */
215 /**
216 * @brief GPIO parameter structure definition
217 */
218 typedef struct
219 {
220 uint32_t pin; /**< Specifies the IO pins to be configured.
221 This parameter can be any value of @ref GR551x_pins */
222 app_io_mode_t mode; /**< Specifies the operating mode for the selected pins. */
223 app_io_pull_t pull; /**< Specifies the Pull-up or Pull-Down activation for the selected pins. */
224 app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
225 } app_io_init_t;
226 /** @} */
227
228
229
230 /* Exported functions --------------------------------------------------------*/
231 /** @addtogroup HAL_APP_GPIO_DRIVER_FUNCTIONS Functions
232 * @{
233 */
234 /**
235 ****************************************************************************************
236 * @brief Initialize the APP GPIO DRIVER according to the specified parameters
237 * in the app_io_type_t and app_io_init_t.
238 *
239 * @param[in] type: GPIO type.
240 * @param[in] p_init: Pointer to app_io_init_t parameter which contains the
241 * configuration information for the specified GPIO.
242 *
243 * @return Result of initialization.
244 ****************************************************************************************
245 */
246 uint16_t app_io_init(app_io_type_t type, app_io_init_t *p_init);
247
248 /**
249 ****************************************************************************************
250 * @brief De-initialize the GPIOx peripheral.
251 *
252 * @param[in] type: GPIO type, See app_io_type_t.
253 * @param[in] pin: The pin want to De-initialization.
254 *
255 * @return Result of De-initialization.
256 ****************************************************************************************
257 */
258 uint16_t app_io_deinit(app_io_type_t type, uint32_t pin);
259
260 /**
261 ****************************************************************************************
262 * @brief Read the specified input port pin..
263 *
264 * @param[in] type: GPIO type, See app_io_type_t.
265 * @param[in] pin: The pin want to read.
266 *
267 * @return The GPIO state.
268 ****************************************************************************************
269 */
270 app_io_pin_state_t app_io_read_pin(app_io_type_t type, uint32_t pin);
271
272 /**
273 ****************************************************************************************
274 * @brief Set or clear the selected data port bit.
275 *
276 * @param[in] type: GPIO type, See app_io_type_t.
277 * @param[in] pin: The pin want to set or clear.
278 * @param[in] pin_state: Specifies the value to be written to the selected bit.
279 *
280 * @return Result of write.
281 ****************************************************************************************
282 */
283 uint16_t app_io_write_pin(app_io_type_t type, uint32_t pin, app_io_pin_state_t pin_state);
284
285 /**
286 ****************************************************************************************
287 * @brief Toggle the specified GPIO pin.
288 *
289 * @param[in] type: GPIO type, See app_io_type_t.
290 * @param[in] pin: The pin want to toggle.
291 *
292 * @return Result of toggle.
293 ****************************************************************************************
294 */
295 uint16_t app_io_toggle_pin(app_io_type_t type, uint32_t pin);
296 /** @} */
297
298 #endif
299
300 /** @} */
301 /** @} */
302 /** @} */
303
304
APP_IO_MUX_1
@ APP_IO_MUX_1
IO mux mode 1.
Definition: app_io.h:200
APP_IO_CTX_INT
@ APP_IO_CTX_INT
the event of interrupt.
Definition: app_io.h:180
APP_IO_MUX_6
@ APP_IO_MUX_6
IO mux mode 6.
Definition: app_io.h:205
app_io_init_t::mode
app_io_mode_t mode
Specifies the operating mode for the selected pins.
Definition: app_io.h:222
APP_IO_MODE_IT_HIGH
@ APP_IO_MODE_IT_HIGH
Interrupt Mode with High-level trigger detection.
Definition: app_io.h:158
APP_IO_MODE_ANALOG
@ APP_IO_MODE_ANALOG
Analog IO Mode.
Definition: app_io.h:160
APP_IO_NOPULL
@ APP_IO_NOPULL
No Pull-up or Pull-down activation.
Definition: app_io.h:188
APP_IO_MUX_4
@ APP_IO_MUX_4
IO mux mode 4.
Definition: app_io.h:203
app_io_write_pin
uint16_t app_io_write_pin(app_io_type_t type, uint32_t pin, app_io_pin_state_t pin_state)
Set or clear the selected data port bit.
APP_IO_MODE_IT_RISING
@ APP_IO_MODE_IT_RISING
Interrupt Mode with Rising edge trigger detection.
Definition: app_io.h:156
APP_IO_MODE_MAX
@ APP_IO_MODE_MAX
Only for check parameter, not used as input parameters.
Definition: app_io.h:161
app_io_deinit
uint16_t app_io_deinit(app_io_type_t type, uint32_t pin)
De-initialize the GPIOx peripheral.
APP_IO_ENABLE_WAKEUP
@ APP_IO_ENABLE_WAKEUP
Enable AON GPIO Wakeup.
Definition: app_io.h:171
app_io_pull_t
app_io_pull_t
GPIO pull Enumerations definition.
Definition: app_io.h:187
app_io_type_t
app_io_type_t
GPIO type Enumerations definition.
Definition: app_io.h:141
APP_IO_MUX_7
@ APP_IO_MUX_7
IO mux mode 7.
Definition: app_io.h:206
app_ctx_type_t
app_ctx_type_t
GPIO handler context type Enumerations definition.
Definition: app_io.h:178
APP_IO_TYPE_AON
@ APP_IO_TYPE_AON
Always-on Input/Output.
Definition: app_io.h:143
app_io_mode_t
app_io_mode_t
GPIO mode Enumerations definition.
Definition: app_io.h:152
APP_IO_MUX_8
@ APP_IO_MUX_8
IO mux mode 8.
Definition: app_io.h:207
app_io_init_t::pull
app_io_pull_t pull
Specifies the Pull-up or Pull-Down activation for the selected pins.
Definition: app_io.h:223
APP_IO_PULL_MAX
@ APP_IO_PULL_MAX
Only for check parameter, not used as input parameters.
Definition: app_io.h:191
APP_IO_PIN_RESET
@ APP_IO_PIN_RESET
IO pin low level.
Definition: app_io.h:133
APP_IO_MODE_IT_FALLING
@ APP_IO_MODE_IT_FALLING
Interrupt Mode with Falling edge trigger detection.
Definition: app_io.h:157
APP_IO_TYPE_NORMAL
@ APP_IO_TYPE_NORMAL
General Purpose Input/Output.
Definition: app_io.h:142
APP_IO_PULLUP
@ APP_IO_PULLUP
Pull-up activation.
Definition: app_io.h:189
APP_IO_TYPE_MSIO
@ APP_IO_TYPE_MSIO
Mixed Signal I/O.
Definition: app_io.h:144
APP_IO_MUX_MAX
@ APP_IO_MUX_MAX
Only for check parameter, not used as input parameters.
Definition: app_io.h:208
APP_IO_MUX_3
@ APP_IO_MUX_3
IO mux mode 3.
Definition: app_io.h:202
APP_IO_MUX_5
@ APP_IO_MUX_5
IO mux mode 5.
Definition: app_io.h:204
APP_IO_MUX_0
@ APP_IO_MUX_0
IO mux mode 0.
Definition: app_io.h:199
APP_IO_MUX_2
@ APP_IO_MUX_2
IO mux mode 2.
Definition: app_io.h:201
APP_IO_MODE_INPUT
@ APP_IO_MODE_INPUT
Input Mode.
Definition: app_io.h:153
APP_IO_PIN_SET
@ APP_IO_PIN_SET
IO pin high level.
Definition: app_io.h:134
APP_IO_PULLDOWN
@ APP_IO_PULLDOWN
Pull-down activation.
Definition: app_io.h:190
APP_IO_TYPE_MAX
@ APP_IO_TYPE_MAX
Only for check parameter, not used as input parameters.
Definition: app_io.h:145
app_io_read_pin
app_io_pin_state_t app_io_read_pin(app_io_type_t type, uint32_t pin)
Read the specified input port pin.
app_io_pin_state_t
app_io_pin_state_t
GPIO state Enumerations definition.
Definition: app_io.h:132
app_io_init
uint16_t app_io_init(app_io_type_t type, app_io_init_t *p_init)
Initialize the APP GPIO DRIVER according to the specified parameters in the app_io_type_t and app_io_...
APP_IO_DISABLE_WAKEUP
@ APP_IO_DISABLE_WAKEUP
Disable AON GPIO Wakeup.
Definition: app_io.h:170
app_handle_mode_t
app_handle_mode_t
GPIO wake-up mode Enumerations definition.
Definition: app_io.h:168
app_io_toggle_pin
uint16_t app_io_toggle_pin(app_io_type_t type, uint32_t pin)
Toggle the specified GPIO pin.
app_io_mux_t
app_io_mux_t
GPIO mux Enumerations definition.
Definition: app_io.h:198
app_io_init_t::mux
app_io_mux_t mux
Specifies the Peripheral to be connected to the selected pins.
Definition: app_io.h:224
APP_IO_MODE_MUX
@ APP_IO_MODE_MUX
Mux Mode.
Definition: app_io.h:155
app_drv_error.h
Header file of app driver error code.
APP_IO_MODE_OUT_PUT
@ APP_IO_MODE_OUT_PUT
Output Mode.
Definition: app_io.h:154
APP_IO_MODE_IT_LOW
@ APP_IO_MODE_IT_LOW
Interrupt Mode with Low-level trigger detection.
Definition: app_io.h:159
app_io_init_t
GPIO parameter structure definition.
Definition: app_io.h:219
app_io_init_t::pin
uint32_t pin
Specifies the IO pins to be configured.
Definition: app_io.h:220
APP_IO_NONE_WAKEUP
@ APP_IO_NONE_WAKEUP
None Wakeup.
Definition: app_io.h:169
APP_IO_CTX_WAKEUP
@ APP_IO_CTX_WAKEUP
the event of wakeup.
Definition: app_io.h:179