app_adc.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file app_adc.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of ADC 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_ADC ADC
47  * @brief ADC APP module driver.
48  * @{
49  */
50 
51 
52 #ifndef _APP_ADC_H_
53 #define _APP_ADC_H_
54 
55 #include "gr55xx_hal.h"
56 #include "app_io.h"
57 #include "app_drv_error.h"
58 #ifdef ENV_USE_FREERTOS
59 #include "app_rtos_cfg.h"
60 #endif
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 #ifdef HAL_ADC_MODULE_ENABLED
67 
68 /** @addtogroup APP_ADC_ENUM Enumerations
69  * @{
70  */
71 
72 /**
73  * @brief ADC operating mode Enumerations definition
74  */
75 typedef enum
76 {
77  APP_ADC_TYPE_POLLING, /**< Polling operation mode */
78  APP_ADC_TYPE_DMA, /**< DMA operation mode */
79  APP_ADC_TYPE_MAX, /**< Only for check parameter, not used as input parameters. */
81 
82 /**
83  * @brief ADC event Enumerations definition
84  */
85 typedef enum
86 {
87  APP_ADC_EVT_CONV_CPLT, /**< Conversion completed by ADC peripheral. */
89 
90 /** @} */
91 
92 
93 /** @addtogroup APP_ADC_STRUCT Structures
94  * @{
95  */
96 
97 /**
98  * @brief ADC pins Structures
99  */
100 typedef struct
101 {
102  app_io_type_t type; /**< Specifies the type of ADC IO. */
103  app_io_mux_t mux; /**< Specifies the Peripheral to be connected to the selected pins. */
104  uint32_t pin; /**< Specifies the IO pins to be configured.
105  This parameter can be any value of @ref GR551x_pins. */
106 } app_adc_pin_t;
107 
108 /**
109  * @brief ADC pins config Structures
110  */
111 typedef struct
112 {
113  app_adc_pin_t channel_p; /**< Set the configuration of ADC channel P pin;this parameter no need to configure and can be any value in single input mode*/
114  app_adc_pin_t channel_n; /**< Set the configuration of ADC channel N pin. */
115  app_adc_pin_t extern_ref; /**< Set the configuration of ADC extern reference pin; this parameter no need to configure and can be any value when ADC uses internal reference*/
117 
118 /**
119  * @brief ADC operate mode Structures
120  */
121 typedef struct
122 {
123  app_adc_type_t type; /**< Specifies the operation mode of ADC. */
124  dma_channel_t dma_channel; /**< Specifies the dma channel of ADC. */
126 
127 /**
128  * @brief ADC parameters structure definition
129  */
130 typedef struct
131 {
132  app_adc_pin_cfg_t pin_cfg; /**< the pin configuration information for the specified ADC module. */
133  app_adc_mode_t use_mode; /**< ADC operate mode. */
134  adc_init_t init; /**< ADC configuration parameters. */
136 
137 /**
138  * @brief ADC event structure definition
139  */
140 typedef struct
141 {
142  app_adc_evt_type_t type; /**< Type of event. */
143 } app_adc_evt_t;
144 
145 /**
146  * @brief ADC event callback definition
147  */
148 typedef void (*app_adc_evt_handler_t)(app_adc_evt_t *p_evt);
149 
150 /**
151  * @brief ADC sample-node definition
152  */
153 typedef struct link_node
154 {
155  uint32_t channel; /**< Which channel to be sample; This parameter can be any value of ADC_INPUT_SOURCE:ADC_INPUT_SRC_IO0~ADC_INPUT_SRC_REF*/
156  uint16_t *p_buf; /**< Buffer pointer of current channel sample codes. */
157  uint32_t len; /**< Sample len codes on current channel. */
158  struct link_node *next; /**< Point to the next sample node. */
160 
161 /** @} */
162 
163 /* Exported functions --------------------------------------------------------*/
164 /** @addtogroup APP_ADC_DRIVER_FUNCTIONS Functions
165  * @{
166  */
167 
168 /**
169  ****************************************************************************************
170  * @brief Initialize the APP ADC DRIVER according to the specified parameters
171  * in the app_adc_params_t and app_adc_evt_handler_t.
172  * @note If DMA mode is set, you can use blocking mode. Conversely, if blocking mode
173  * is set, you can't use DMA mode.
174  *
175  * @param[in] p_params: Pointer to app_adc_params_t parameter which contains the
176  * configuration information for the specified ADC module.
177  * @param[in] evt_handler: ADC user callback function.
178  *
179  * @return Result of initialization.
180  ****************************************************************************************
181  */
182 uint16_t app_adc_init(app_adc_params_t *p_params, app_adc_evt_handler_t evt_handler);
183 
184 /**
185  ****************************************************************************************
186  * @brief De-initialize the APP ADC DRIVER peripheral.
187  *
188  * @return Result of De-initialization.
189  ****************************************************************************************
190  */
191 uint16_t app_adc_deinit(void);
192 
193 /**
194  ****************************************************************************************
195  * @brief Polling for conversion.
196  *
197  * @param[in] p_data: Pointer to data buffer which to storage ADC conversion results.
198  * @param[in] length: Length of data buffer, must >=2.
199  * @param[in] timeout : Timeout duration
200  *
201  * @return Result of operation.
202  ****************************************************************************************
203  */
204 uint16_t app_adc_conversion_sync(uint16_t *p_data, uint32_t length, uint32_t timeout);
205 
206 /**
207  ****************************************************************************************
208  * @brief DMA for conversion.
209  *
210  * @param[in] p_data: Pointer to data buffer which to storage ADC conversion results.
211  * @param[in] length: Length of data buffer, ranging between 2 and 4095.
212  *
213  * @return Result of operation.
214  ****************************************************************************************
215  */
216 uint16_t app_adc_conversion_async(uint16_t *p_data, uint32_t length);
217 
218 /**
219  ****************************************************************************************
220  * @brief DMA for multi channels conversion; evt_handler in app_adc_init will callback when all channels finish.
221  *
222  * @param[in] p_begin_node: Pointer to the multi sample channels list node.
223  * @param[in] total_nodes: total sample channels.
224  *
225  * @return Result of operation.
226  ****************************************************************************************
227  */
228 uint16_t app_adc_multi_channel_conversion_async(app_adc_samle_node_t *p_begin_node, uint32_t total_nodes);
229 
230 /**
231  ****************************************************************************************
232  * @brief Convert the ADC conversion results to a voltage value(internal reference).
233  *
234  * @param[in] inbuf: Pointer to data buffer which storage ADC conversion results.
235  * @param[out] outbuf: Pointer to data buffer which to storage voltage results.
236  * @param[in] buflen: Length of data buffer, ranging between 2 and 4095.
237  *
238  * @return Result of operation.
239  ****************************************************************************************
240  */
241 uint16_t app_adc_voltage_intern(uint16_t *inbuf, double *outbuf, uint32_t buflen);
242 
243 /**
244  ****************************************************************************************
245  * @brief Convert the ADC conversion results to a voltage value(external reference).
246  *
247  * @param[in] ref: slope of ADC.
248  * @param[in] inbuf: Pointer to data buffer which storage ADC conversion results.
249  * @param[out] outbuf: Pointer to data buffer which to storage voltage results.
250  * @param[in] buflen: Length of data buffer, ranging between 2 and 4095.
251  *
252  * @return Result of operation.
253  ****************************************************************************************
254  */
255 uint16_t app_adc_voltage_extern(double ref, uint16_t *inbuf, double *outbuf, uint32_t buflen);
256 
257 /**
258  ****************************************************************************************
259  * @brief Return the ADC handle.
260  *
261  * @return Pointer to the ADC handle.
262  ****************************************************************************************
263  */
265 
266 
267 #ifdef ENV_RTOS_USE_SEMP
268 /**
269  ****************************************************************************************
270  * @brief [RTOS] Polling for conversion.
271  *
272  * @param[in] p_data: Pointer to data buffer which to storage ADC conversion results.
273  * @param[in] length: Length of data buffer,ranging between 2 and 4095.
274  *
275  * @return Result of operation.
276  ****************************************************************************************
277  */
278 uint16_t app_adc_conversion_sem_sync(uint16_t *p_data, uint32_t length);
279 
280 /**
281  ****************************************************************************************
282  * @brief [RTOS] Polling for multi channels conversion.
283  *
284  * @param[in] p_begin_node: Pointer to the multi sample channels list node.
285  * @param[in] total_nodes: total sample channels.
286  *
287  * @return Result of operation.
288  ****************************************************************************************
289  */
290 uint16_t app_adc_multi_channel_conversion_sem_sync(app_adc_samle_node_t *p_begin_node, uint32_t total_nodes);
291 #endif
292 
293 /** @} */
294 
295 #endif
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif
302 
303 /** @} */
304 /** @} */
305 /** @} */
306 
307 
app_adc_voltage_extern
uint16_t app_adc_voltage_extern(double ref, uint16_t *inbuf, double *outbuf, uint32_t buflen)
Convert the ADC conversion results to a voltage value(external reference).
APP_ADC_EVT_CONV_CPLT
@ APP_ADC_EVT_CONV_CPLT
Conversion completed by ADC peripheral.
Definition: app_adc.h:87
app_adc_pin_t::mux
app_io_mux_t mux
Specifies the Peripheral to be connected to the selected pins.
Definition: app_adc.h:103
app_adc_evt_t::type
app_adc_evt_type_t type
Type of event.
Definition: app_adc.h:142
app_io_type_t
app_io_type_t
GPIO type Enumerations definition.
Definition: app_io.h:141
app_adc_mode_t::dma_channel
dma_channel_t dma_channel
Specifies the dma channel of ADC.
Definition: app_adc.h:124
app_adc_mode_t
ADC operate mode Structures.
Definition: app_adc.h:122
app_adc_params_t
ADC parameters structure definition.
Definition: app_adc.h:131
app_adc_pin_t::pin
uint32_t pin
Specifies the IO pins to be configured.
Definition: app_adc.h:104
APP_ADC_TYPE_MAX
@ APP_ADC_TYPE_MAX
Only for check parameter, not used as input parameters.
Definition: app_adc.h:79
app_adc_params_t::pin_cfg
app_adc_pin_cfg_t pin_cfg
the pin configuration information for the specified ADC module.
Definition: app_adc.h:132
_ll_adc_init
LL ADC init Structure definition.
Definition: gr55xx_ll_adc.h:77
app_io.h
Header file containing functions prototypes of GPIO app library.
app_adc_evt_t
ADC event structure definition.
Definition: app_adc.h:141
app_adc_evt_type_t
app_adc_evt_type_t
ADC event Enumerations definition.
Definition: app_adc.h:86
app_adc_params_t::use_mode
app_adc_mode_t use_mode
ADC operate mode.
Definition: app_adc.h:133
app_adc_voltage_intern
uint16_t app_adc_voltage_intern(uint16_t *inbuf, double *outbuf, uint32_t buflen)
Convert the ADC conversion results to a voltage value(internal reference).
app_adc_type_t
app_adc_type_t
ADC operating mode Enumerations definition.
Definition: app_adc.h:76
app_adc_samle_node_t
struct link_node app_adc_samle_node_t
ADC sample-node definition.
APP_ADC_TYPE_POLLING
@ APP_ADC_TYPE_POLLING
Polling operation mode
Definition: app_adc.h:77
app_adc_mode_t::type
app_adc_type_t type
Specifies the operation mode of ADC.
Definition: app_adc.h:123
app_adc_evt_handler_t
void(* app_adc_evt_handler_t)(app_adc_evt_t *p_evt)
ADC event callback definition.
Definition: app_adc.h:148
app_adc_conversion_sync
uint16_t app_adc_conversion_sync(uint16_t *p_data, uint32_t length, uint32_t timeout)
Polling for conversion.
_adc_handle
ADC handle Structure definition.
Definition: gr55xx_hal_adc.h:111
app_adc_pin_t::type
app_io_type_t type
Specifies the type of ADC IO.
Definition: app_adc.h:102
app_adc_pin_cfg_t::extern_ref
app_adc_pin_t extern_ref
Set the configuration of ADC extern reference pin; this parameter no need to configure and can be any...
Definition: app_adc.h:115
app_adc_params_t::init
adc_init_t init
ADC configuration parameters.
Definition: app_adc.h:134
gr55xx_hal.h
This file contains all the functions prototypes for the HAL module driver.
app_adc_deinit
uint16_t app_adc_deinit(void)
De-initialize the APP ADC DRIVER peripheral.
app_adc_pin_cfg_t::channel_n
app_adc_pin_t channel_n
Set the configuration of ADC channel N pin.
Definition: app_adc.h:114
app_adc_get_handle
adc_handle_t * app_adc_get_handle(void)
Return the ADC handle.
app_io_mux_t
app_io_mux_t
GPIO mux Enumerations definition.
Definition: app_io.h:198
app_adc_conversion_async
uint16_t app_adc_conversion_async(uint16_t *p_data, uint32_t length)
DMA for conversion.
app_adc_pin_cfg_t::channel_p
app_adc_pin_t channel_p
Set the configuration of ADC channel P pin;this parameter no need to configure and can be any value i...
Definition: app_adc.h:113
APP_ADC_TYPE_DMA
@ APP_ADC_TYPE_DMA
DMA operation mode
Definition: app_adc.h:78
app_rtos_cfg.h
Header file of app rtos config code.
app_drv_error.h
Header file of app driver error code.
app_adc_multi_channel_conversion_async
uint16_t app_adc_multi_channel_conversion_async(app_adc_samle_node_t *p_begin_node, uint32_t total_nodes)
DMA for multi channels conversion; evt_handler in app_adc_init will callback when all channels finish...
app_adc_pin_cfg_t
ADC pins config Structures.
Definition: app_adc.h:112
dma_channel_t
dma_channel_t
HAL DMA Channel Enumerations definition.
Definition: gr55xx_hal_dma.h:93
app_adc_pin_t
ADC pins Structures.
Definition: app_adc.h:101
app_adc_init
uint16_t app_adc_init(app_adc_params_t *p_params, app_adc_evt_handler_t evt_handler)
Initialize the APP ADC DRIVER according to the specified parameters in the app_adc_params_t and app_a...