gr55xx_hal_adc.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_hal_adc.h
5 * @author BLE Driver Team
6 * @brief Header file containing functions prototypes of ADC HAL 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 HAL_DRIVER HAL Driver
43 * @{
44 */
45
46 /** @defgroup HAL_ADC ADC
47 * @brief ADC HAL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_ADC_H__
53 #define __GR55xx_HAL_ADC_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_adc.h"
61 #include "gr55xx_hal_def.h"
62 #include "gr55xx_hal_dma.h"
63
64 /* Exported types ------------------------------------------------------------*/
65 /** @addtogroup HAL_ADC_ENUMERATIONS Enumerations
66 * @{
67 */
68
69 /** @defgroup HAL_ADC_state HAL ADC State
70 * @{
71 */
72
73 /**
74 * @brief HAL ADC State Enumerations definition
75 */
76 typedef enum
77 {
78 HAL_ADC_STATE_RESET = 0x00, /**< Peripheral not initialized */
79 HAL_ADC_STATE_READY = 0x01, /**< Peripheral initialized and ready for use */
80 HAL_ADC_STATE_BUSY = 0x02, /**< An internal process is ongoing */
81 HAL_ADC_STATE_ERROR = 0x04 /**< Peripheral in error */
82
83 } hal_adc_state_t;
84
85 /** @} */
86
87 /** @} */
88
89 /** @addtogroup HAL_ADC_STRUCTURES Structures
90 * @{
91 */
92
93 /**@brief ADC trim parameter information definition.
94 * @{
95 */
96 typedef struct
97 {
98 uint16_t adc_temp; /**< ADC TEMP. */
99 uint16_t slope_int_0p8; /**< Internal reference 0.8v. */
100 uint16_t offset_int_0p8; /**< Internal reference 0.8v. */
101 uint16_t slope_int_1p2; /**< Internal reference 1.2v. */
102 uint16_t offset_int_1p2; /**< Internal reference 1.2v. */
103 uint16_t slope_int_1p6; /**< Internal reference 1.6v. */
104 uint16_t offset_int_1p6; /**< Internal reference 1.6v. */
105 uint16_t slope_int_2p0; /**< Internal reference 2.0v. */
106 uint16_t offset_int_2p0; /**< Internal reference 2.0v. */
107 uint16_t slope_ext_1p0; /**< External reference 1.0v. */
108 uint16_t offset_ext_1p0; /**< External reference 1.0v. */
109 } adc_trim_info_t;
110 /** @} */
111
112 /** @defgroup ADC_Configuration ADC Configuration
113 * @{
114 */
115
116 /**
117 * @brief ADC init structure definition
118 */
119 typedef ll_adc_init_t adc_init_t;
120 /** @} */
121
122 /** @defgroup ADC_handle ADC Handle
123 * @{
124 */
125
126 /**
127 * @brief ADC handle Structure definition
128 */
129 typedef struct _adc_handle
130 {
131 adc_init_t init; /**< ADC configuration parameters */
132
133 uint16_t *p_buffer; /**< Pointer to ADC conversion buffer */
134
135 __IO uint32_t buff_size; /**< Conversion buffer size */
136
137 __IO uint32_t buff_count; /**< Conversion buffer counter */
138
139 dma_handle_t *p_dma; /**< ADC DMA Handle parameters */
140
141 __IO hal_lock_t lock; /**< Locking object */
142
143 __IO hal_adc_state_t state; /**< ADC communication state */
144
145 __IO uint32_t error_code; /**< ADC error code */
146
147 uint32_t retention[2]; /**< ADC important register information. */
148
149 } adc_handle_t;
150 /** @} */
151
152 /** @} */
153
154 /** @addtogroup HAL_ADC_CALLBACK_STRUCTURES Callback Structures
155 * @{
156 */
157
158 /** @defgroup ADC_Callback ADC Callback
159 * @{
160 */
161
162 /**
163 * @brief HAL ADC Callback function definition
164 */
165 typedef struct _hal_adc_callback
166 {
167 void (*adc_msp_init)(adc_handle_t *p_adc); /**< ADC init MSP callback */
168 void (*adc_msp_deinit)(adc_handle_t *p_adc); /**< ADC de-init MSP callback */
169 void (*adc_conv_cplt_callback)(adc_handle_t *p_adc); /**< ADC conversion completed callback */
170 uint16_t (*adc_get_trim_func)(adc_trim_info_t *p_adc_trim); /**< ADC get trim information callback(must return 0x0000 when successful)*/
171 } hal_adc_callback_t;
172
173 /** @} */
174
175 /** @} */
176
177 /**
178 * @defgroup HAL_ADC_MACRO Defines
179 * @{
180 */
181
182 /* Exported constants --------------------------------------------------------*/
183 /** @defgroup ADC_Exported_Constants ADC Exported Constants
184 * @{
185 */
186
187 /** @defgroup ADC_Error_Code ADC Error Code
188 * @{
189 */
190 #define HAL_ADC_ERROR_NONE ((uint32_t)0x00000000) /**< No error */
191 #define HAL_ADC_ERROR_TIMEOUT ((uint32_t)0x00000001) /**< Timeout error */
192 #define HAL_ADC_ERROR_DMA ((uint32_t)0x00000004) /**< DMA transfer error */
193 #define HAL_ADC_ERROR_INVALID_PARAM ((uint32_t)0x00000008) /**< Invalid parameter error */
194 /** @} */
195
196 /** @defgroup ADC_CLK ADC Clock Select
197 * @{
198 */
199 #if defined(GR552xx)
200 #define ADC_CLK_16M LL_ADC_CLK_16M /**< ADC Clock = 16 MHz */
201 #define ADC_CLK_8M LL_ADC_CLK_8M /**< ADC Clock = 8 MHz */
202 #define ADC_CLK_4M LL_ADC_CLK_4M /**< ADC Clock = 4 MHz */
203 #define ADC_CLK_1M LL_ADC_CLK_1M /**< ADC Clock = 1MHz */
204 #define ADC_CLK_16K LL_ADC_CLK_16K /**< ADC Clock = 16KHz */
205 #define ADC_CLK_8K LL_ADC_CLK_8K /**< ADC Clock = 8KHz */
206 #define ADC_CLK_4K LL_ADC_CLK_4K /**< ADC Clock = 4KHz */
207 #define ADC_CLK_NONE LL_ADC_CLK_NONE /**< Close ADC Clock */
208 #endif
209 /** @} */
210
211 /** @defgroup ADC_REFERENCE ADC Reference Value Select
212 * @{
213 */
214 #define ADC_REF_VALUE_0P8 LL_ADC_REF_VALUE_0P8 /**< Reference = 0.85 V */
215 #define ADC_REF_VALUE_1P2 LL_ADC_REF_VALUE_1P2 /**< Reference = 1.28 V */
216 #define ADC_REF_VALUE_1P6 LL_ADC_REF_VALUE_1P6 /**< Reference = 1.60 V */
217 #define ADC_REF_VALUE_2P0 LL_ADC_REF_VALUE_2P0 /**< Reference = 2.00 V */
218 /** @} */
219
220 /** @defgroup ADC_INPUT_MODE ADC Input Mode
221 * @brief Single or Differential mode
222 * @{
223 */
224 #define ADC_INPUT_SINGLE LL_ADC_INPUT_SINGLE /**< Single ended mode */
225 #define ADC_INPUT_DIFFERENTIAL LL_ADC_INPUT_DIFFERENTIAL/**< Differential mode */
226 /** @} */
227
228 /** @defgroup ADC_INPUT_SOURCE ADC Input Channel Select
229 * @{
230 */
231 #define ADC_INPUT_SRC_IO0 LL_ADC_INPUT_SRC_IO0 /**< Select MSIO0 as input */
232 #define ADC_INPUT_SRC_IO1 LL_ADC_INPUT_SRC_IO1 /**< Select MSIO1 as input */
233 #define ADC_INPUT_SRC_IO2 LL_ADC_INPUT_SRC_IO2 /**< Select MSIO2 as input */
234 #define ADC_INPUT_SRC_IO3 LL_ADC_INPUT_SRC_IO3 /**< Select MSIO3 as input */
235 #define ADC_INPUT_SRC_IO4 LL_ADC_INPUT_SRC_IO4 /**< Select MSIO4 as input */
236 #define ADC_INPUT_SRC_IO5 LL_ADC_INPUT_SRC_IO5 /**< Select MSIO5 as input */
237 #define ADC_INPUT_SRC_IO6 LL_ADC_INPUT_SRC_IO6 /**< Select MSIO6 as input */
238 #define ADC_INPUT_SRC_IO7 LL_ADC_INPUT_SRC_IO7 /**< Select MSIO7 as input */
239 #define ADC_INPUT_SRC_TMP LL_ADC_INPUT_SRC_TMP /**< Select temperature as input */
240 #define ADC_INPUT_SRC_BAT LL_ADC_INPUT_SRC_BAT /**< Select Vbattery as input */
241 #define ADC_INPUT_SRC_REF LL_ADC_INPUT_SRC_REF /**< Select reference as input */
242
243 /** @} */
244
245 /** @defgroup ADC_REFERENCE_SOURCE ADC Reference Source Select
246 * @{
247 */
248 #define ADC_REF_SRC_BUF_INT LL_ADC_REF_SRC_BUF_INT /**< Select buffered internal reference as reference */
249 #define ADC_REF_SRC_IO0 LL_ADC_REF_SRC_IO0 /**< Select MSIO0 as reference */
250 #define ADC_REF_SRC_IO1 LL_ADC_REF_SRC_IO1 /**< Select MSIO1 as reference */
251 #define ADC_REF_SRC_IO2 LL_ADC_REF_SRC_IO2 /**< Select MSIO2 as reference */
252 #define ADC_REF_SRC_IO3 LL_ADC_REF_SRC_IO3 /**< Select MSIO3 as reference */
253 /** @} */
254
255 /**
256 * @brief ADC_default_config initStruct default configuartion
257 */
258 #define ADC_DEFAULT_CONFIG LL_ADC_DEFAULT_CONFIG
259 /** @} */
260
261 /* Exported macro ------------------------------------------------------------*/
262 /** @defgroup ADC_Exported_Macros ADC Exported Macros
263 * @{
264 */
265
266 /** @brief Reset ADC handle states.
267 * @param __HANDLE__ ADC handle.
268 * @retval None
269 */
270 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_ADC_STATE_RESET)
271
272 /** @brief Enable the specified ADC peripheral.
273 * @param __HANDLE__ Specify the ADC Handle.
274 * @retval None
275 */
276 #define __HAL_ADC_ENABLE(__HANDLE__) ll_adc_enable()
277
278 /** @brief Disable the specified ADC peripheral.
279 * @param __HANDLE__ Specify the ADC Handle.
280 * @retval None
281 */
282 #define __HAL_ADC_DISABLE(__HANDLE__) ll_adc_disable()
283
284 /** @brief Check the FIFO is not empty.
285 * @param __HANDLE__ Specify the ADC Handle.
286 * @retval The new state of notempty flag (TRUE or FALSE).
287 */
288 #define __HAL_ADC_GET_FLAG_NOTEMPTY(__HANDLE__) ll_adc_is_fifo_notempty()
289
290 /** @brief Try to lock ADC token by SW.
291 * @param __HANDLE__ Specify the ADC Handle.
292 * @retval if the token locked by SW is success (TRUE or FALSE).
293 */
294 #define __HAL_ADC_TRY_SWTOKEN_LOCK(__HANDLE__) ll_adc_try_lock_sw_token()
295
296 /** @brief Flush the FIFO.
297 * @param __HANDLE__ Specify the ADC Handle.
298 * @retval None
299 */
300 #define __HAL_ADC_FLUSH_FIFO(__HANDLE__) do { \
301 while(ll_adc_is_fifo_notempty()) \
302 { \
303 ll_adc_flush_fifo(); \
304 } \
305 } while(0)
306
307 /** @} */
308
309 /* Private macros ------------------------------------------------------------*/
310 /** @addtogroup ADC_Private_Macros ADC Private Macros
311 * @{
312 */
313
314 /**
315 * @brief Check if ADC input source is valid.
316 * @param __INPUT__ ADC input source.
317 * @retval SET (__INPUT__ is valid) or RESET (__INPUT__ is invalid)
318 */
319 #define IS_ADC_INPUT(__INPUT__) (((__INPUT__) == ADC_INPUT_SRC_IO0) || \
320 ((__INPUT__) == ADC_INPUT_SRC_IO1) || \
321 ((__INPUT__) == ADC_INPUT_SRC_IO2) || \
322 ((__INPUT__) == ADC_INPUT_SRC_IO3) || \
323 ((__INPUT__) == ADC_INPUT_SRC_IO4) || \
324 ((__INPUT__) == ADC_INPUT_SRC_IO5) || \
325 ((__INPUT__) == ADC_INPUT_SRC_IO6) || \
326 ((__INPUT__) == ADC_INPUT_SRC_IO7) || \
327 ((__INPUT__) == ADC_INPUT_SRC_TMP) || \
328 ((__INPUT__) == ADC_INPUT_SRC_BAT) || \
329 ((__INPUT__) == ADC_INPUT_SRC_REF))
330
331 /**
332 * @brief Check if ADC input mode is valid.
333 * @param __MODE__ ADC input mode.
334 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
335 */
336 #define IS_ADC_INPUT_MODE(__MODE__) (((__MODE__) == ADC_INPUT_SINGLE) || \
337 ((__MODE__) == ADC_INPUT_DIFFERENTIAL)
338
339 /**
340 * @brief Check if ADC reference source is valid.
341 * @param __INPUT__ ADC reference source.
342 * @retval SET (__INPUT__ is valid) or RESET (__INPUT__ is invalid)
343 */
344 #define IS_ADC_REF(__INPUT__) (((__INPUT__) == ADC_REF_SRC_BUF_INT) || \
345 ((__INPUT__) == ADC_REF_SRC_INT) || \
346 ((__INPUT__) == ADC_REF_SRC_IO0) || \
347 ((__INPUT__) == ADC_REF_SRC_IO1) || \
348 ((__INPUT__) == ADC_REF_SRC_IO2) || \
349 ((__INPUT__) == ADC_REF_SRC_IO3))
350
351 /**
352 * @brief Check if ADC reference value is valid.
353 * @param __VALUE__ ADC reference value.
354 * @retval SET (__VALUE__ is valid) or RESET (__VALUE__ is invalid)
355 */
356 #define IS_ADC_REF_VALUE(__VALUE__) (((__VALUE__) >= ADC_REF_VALUE_0P5) && \
357 ((__VALUE__) <= ADC_REF_VALUE_2P0))
358
359 /**
360 * @brief Check if ADC clock is valid.
361 * @param __CLOCK__ ADC clock.
362 * @retval SET (__CLOCK__ is valid) or RESET (__CLOCK__ is invalid)
363 */
364 #if defined(GR552xx)
365 #define IS_ADC_CLOCK(__CLOCK__) (((__CLOCK__) == ADC_CLK_16M) || \
366 ((__CLOCK__) == ADC_CLK_8M) || \
367 ((__CLOCK__) == ADC_CLK_1M) || \
368 ((__CLOCK__) == ADC_CLK_250K)|| \
369 ((__CLOCK__) == ADC_CLK_16K)|| \
370 ((__CLOCK__) == ADC_CLK_8K)|| \
371 ((__CLOCK__) == ADC_CLK_1K)|| \
372 ((__CLOCK__) == ADC_CLK_NONE))
373 #else
374 #define IS_ADC_CLOCK(__CLOCK__) (((__CLOCK__) == ADC_CLK_16M) || \
375 ((__CLOCK__) == ADC_CLK_8M) || \
376 ((__CLOCK__) == ADC_CLK_4M) || \
377 ((__CLOCK__) == ADC_CLK_2M) || \
378 ((__CLOCK__) == ADC_CLK_1M) || \
379 ((__CLOCK__) == ADC_CLK_1P6M))
380 #endif
381
382 /** @} */
383
384 /** @} */
385
386 /* Exported functions --------------------------------------------------------*/
387 /** @addtogroup HAL_ADC_DRIVER_FUNCTIONS Functions
388 * @{
389 */
390
391 /** @addtogroup ADC_Exported_Functions_Group1 Initialization and de-initialization Functions
392 * @brief Initialization and Configuration functions
393 * @{
394 */
395
396 /**
397 ****************************************************************************************
398 * @brief Initialize the ADC according to the specified parameters
399 * in the adc_init_t and initialize the associated handle.
400 *
401 * @param[in] p_adc: Pointer to an ADC handle which contains the configuration information for
402 * the specified ADC module.
403 *
404 * @retval ::HAL_OK: Operation is OK.
405 * @retval ::HAL_ERROR: Parameter error or operation not supported.
406 * @retval ::HAL_BUSY: Driver is busy.
407 * @retval ::HAL_TIMEOUT: Timeout occurred.
408 ****************************************************************************************
409 */
410 hal_status_t hal_adc_init(adc_handle_t *p_adc);
411
412 /**
413 ****************************************************************************************
414 * @brief De-initialize the ADC peripheral.
415 *
416 * @param[in] p_adc: Pointer to an ADC handle which contains the configuration information for
417 * the specified ADC module.
418 *
419 * @retval ::HAL_OK: Operation is OK.
420 * @retval ::HAL_ERROR: Parameter error or operation not supported.
421 * @retval ::HAL_BUSY: Driver is busy.
422 * @retval ::HAL_TIMEOUT: Timeout occurred.
423 ****************************************************************************************
424 */
425 hal_status_t hal_adc_deinit(adc_handle_t *p_adc);
426
427 /**
428 ****************************************************************************************
429 * @brief Initialize the ADC MSP.
430 *
431 * @note This function should not be modified. When the callback is needed,
432 * the hal_adc_msp_deinit can be implemented in the user file.
433 *
434 * @param[in] p_adc: Pointer to an ADC handle which contains the configuration information for
435 * the specified ADC module.
436 ****************************************************************************************
437 */
438 void hal_adc_msp_init(adc_handle_t *p_adc);
439
440 /**
441 ****************************************************************************************
442 * @brief De-initialize the ADC MSP.
443 *
444 * @note This function should not be modified. When the callback is needed,
445 * the hal_adc_msp_deinit can be implemented in the user file.
446 *
447 * @param[in] p_adc: Pointer to an ADC handle which contains the configuration information for
448 * the specified ADC module.
449 ****************************************************************************************
450 */
451 void hal_adc_msp_deinit(adc_handle_t *p_adc);
452
453 /**
454 ****************************************************************************************
455 * @brief adc_get_trim_func.
456 *
457 * @note This function should not be modified. When the callback is needed,
458 * the adc_get_trim_func can be implemented in the user file.
459 *
460 * @param[in] p_adc_trim: Pointer to save the trim information.
461 ****************************************************************************************
462 */
463 uint16_t adc_get_trim_func(adc_trim_info_t *p_adc_trim);
464
465 /** @} */
466
467 /** @addtogroup ADC_Exported_Functions_Group2 IO Operation Functions
468 * @brief ADC polling and DMA conversion management functions.
469 * @{
470 */
471
472 /**
473 ****************************************************************************************
474 * @brief Polling for conversion.
475 *
476 * @param[in] p_adc: Pointer to an ADC handle.
477 * @param[in] p_data: Pointer to data buffer which to store ADC conversion results.
478 * @param[in] length: Length of data buffer.
479 *
480 * @retval ::HAL_OK: Operation is OK.
481 * @retval ::HAL_ERROR: Parameter error or operation not supported.
482 * @retval ::HAL_BUSY: Driver is busy.
483 * @retval ::HAL_TIMEOUT: Timeout occurred.
484 ****************************************************************************************
485 */
486 hal_status_t hal_adc_poll_for_conversion(adc_handle_t *p_adc, uint16_t *p_data, uint32_t length);
487
488 /**
489 ****************************************************************************************
490 * @brief DMA for conversion.
491 *
492 * @param[in] p_adc: Pointer to an ADC handle.
493 * @param[in] p_data: Pointer to data buffer which to store ADC conversion results.
494 * @param[in] length: Length of data buffer, ranging between 0 and 4095.
495 *
496 * @retval ::HAL_OK: Operation is OK.
497 * @retval ::HAL_ERROR: Parameter error or operation not supported.
498 * @retval ::HAL_BUSY: Driver is busy.
499 * @retval ::HAL_TIMEOUT: Timeout occurred.
500 ****************************************************************************************
501 */
502 hal_status_t hal_adc_start_dma(adc_handle_t *p_adc, uint16_t *p_data, uint32_t length);
503
504 /**
505 ****************************************************************************************
506 * @brief DMA for conversion.
507 *
508 * @param[in] p_adc: Pointer to an ADC handle.
509 * @param[in] p_data: Pointer to data buffer which to store ADC conversion results.
510 * @param[in] length: Length of data buffer, ranging between 0 and 4095.
511 * @param[in] sg_llp_config: The config of source and destination's SG and LLP functions.
512 *
513 * @retval ::HAL_OK: Operation is OK.
514 * @retval ::HAL_ERROR: Parameter error or operation not supported.
515 * @retval ::HAL_BUSY: Driver is busy.
516 * @retval ::HAL_TIMEOUT: Timeout occurred.
517 ****************************************************************************************
518 */
519 hal_status_t hal_adc_start_dma_sg_llp(adc_handle_t *p_adc, uint16_t *p_data, uint32_t length, dma_sg_llp_config_t *sg_llp_config);
520
521 /**
522 ****************************************************************************************
523 * @brief Abort ongoing conversion (blocking mode).
524 *
525 * @note This procedure could be only used for aborting conversion started in DMA mode.
526 * This procedure performs following operations:
527 * - Disable ADC clock, stop conversion
528 * - Abort DMA transfer by calling hal_dma_abort (in case of transfer in DMA mode)
529 * - Set handle State to READY.
530 * This procedure is executed in blocking mode: when exiting function, Abort is considered as completed.
531 *
532 * @param[in] p_adc: ADC handle.
533 *
534 * @retval ::HAL_OK: Operation is OK.
535 * @retval ::HAL_ERROR: Parameter error or operation not supported.
536 * @retval ::HAL_BUSY: Driver is busy.
537 * @retval ::HAL_TIMEOUT: Timeout occurred.
538 ****************************************************************************************
539 */
540 hal_status_t hal_adc_stop_dma(adc_handle_t *p_adc);
541
542 /**
543 ****************************************************************************************
544 * @brief Conversion completed callback.
545 *
546 * @note This function should not be modified. When the callback is needed,
547 * the hal_adc_conv_cplt_callback can be implemented in the user file.
548 *
549 * @param[in] p_adc: Pointer to an ADC handle which contains the configuration information for
550 * the specified ADC module.
551 ****************************************************************************************
552 */
553 void hal_adc_conv_cplt_callback(adc_handle_t* p_adc);
554
555 /** @} */
556
557 /** @defgroup ADC_Exported_Functions_Group3 Peripheral State and Errors Functions
558 * @brief ADC control functions
559 *
560 @verbatim
561 ===============================================================================
562 ##### Peripheral State and Errors functions #####
563 ===============================================================================
564 [..]
565 This subsection provides a set of functions allowing to control the ADC.
566 (+) hal_adc_get_state() API can be helpful to check in run-time the state of the ADC peripheral.
567 (+) hal_adc_get_error() check in run-time Errors occurring during communication.
568 @endverbatim
569 * @{
570 */
571
572 /**
573 ****************************************************************************************
574 * @brief Return the ADC handle state.
575 *
576 * @param[in] p_adc: Pointer to an ADC handle which contains the configuration information for
577 * the specified ADC module.
578 *
579 * @retval ::HAL_ADC_STATE_RESET: Peripheral not initialized.
580 * @retval ::HAL_ADC_STATE_READY: Peripheral initialized and ready for use.
581 * @retval ::HAL_ADC_STATE_BUSY: An internal process is ongoing.
582 * @retval ::HAL_ADC_STATE_ERROR: Peripheral in error.
583 ****************************************************************************************
584 */
585 hal_adc_state_t hal_adc_get_state(adc_handle_t *p_adc);
586
587 /**
588 ****************************************************************************************
589 * @brief Return the ADC error code.
590 *
591 * @param[in] p_adc: Pointer to an ADC handle which contains the configuration information for
592 * the specified ADC module.
593 *
594 * @return ADC error code in bitmap format
595 ****************************************************************************************
596 */
597 uint32_t hal_adc_get_error(adc_handle_t *p_adc);
598
599 /**
600 ****************************************************************************************
601 * @brief Suspend some registers related to ADC configuration before sleep.
602 * @param[in] p_adc: Pointer to a ADC handle which contains the configuration
603 * information for the specified ADC module.
604 * @retval ::HAL_OK: Operation is OK.
605 * @retval ::HAL_ERROR: Parameter error or operation not supported.
606 * @retval ::HAL_BUSY: Driver is busy.
607 * @retval ::HAL_TIMEOUT: Timeout occurred.
608 ****************************************************************************************
609 */
610 hal_status_t hal_adc_suspend_reg(adc_handle_t *p_adc);
611
612 /**
613 ****************************************************************************************
614 * @brief Restore some registers related to ADC configuration after sleep.
615 * This function must be used in conjunction with the hal_adc_suspend_reg().
616 * @param[in] p_adc: Pointer to a ADC handle which contains the configuration
617 * information for the specified ADC module.
618 * @retval ::HAL_OK: Operation is OK.
619 * @retval ::HAL_ERROR: Parameter error or operation not supported.
620 * @retval ::HAL_BUSY: Driver is busy.
621 * @retval ::HAL_TIMEOUT: Timeout occurred.
622 ****************************************************************************************
623 */
624 hal_status_t hal_adc_resume_reg(adc_handle_t *p_adc);
625
626
627 /**
628 ****************************************************************************************
629 * @brief Set the new channels parameter to ADC
630 *
631 * @param[in] p_adc: Pointer to a ADC handle which contains the new channels parameter.
632 *
633 * @retval ::HAL_OK: Operation is OK.
634 * @retval ::HAL_ERROR: Parameter error or operation not supported.
635 * @retval ::HAL_BUSY: Driver is busy.
636 * @retval ::HAL_TIMEOUT: Timeout occurred.
637 ****************************************************************************************
638 */
639 hal_status_t hal_adc_change_channels(adc_handle_t *p_adc);
640
641 /**
642 ****************************************************************************************
643 * @brief Start the ADC clock
644 *
645 * @param[in] p_adc: Pointer to an ADC handle which contains the configuration information for
646 * the specified ADC module.
647 *
648 * @retval ::HAL_OK: Operation is OK.
649 * @retval ::HAL_ERROR: Parameter error or operation not supported.
650 * @retval ::HAL_BUSY: Driver is busy.
651 * @retval ::HAL_TIMEOUT: Timeout occurred.
652 ****************************************************************************************
653 */
654 hal_status_t hal_adc_clock_start(adc_handle_t *p_adc);
655
656 /**
657 ****************************************************************************************
658 * @brief Get the ADC sampling code by polling, and convert sampling code of the specified length to the average voltage.
659 *
660 * @param[in] p_adc: Pointer to a ADC handle which contains the new channels parameter.
661 * @param[in] p_data: Pointer to data which to storage average voltage results.
662 * @param[in] length: Length of the ADC sample values to be averaged.
663 *
664 * @retval ::HAL_OK: Operation is OK.
665 * @retval ::HAL_ERROR: Parameter error or operation not supported.
666 * @retval ::HAL_BUSY: Driver is busy.
667 * @retval ::HAL_TIMEOUT: Timeout occurred.
668 ****************************************************************************************
669 */
670 hal_status_t hal_adc_get_avg_voltage(adc_handle_t *p_adc, float *p_data, uint32_t length);
671
672 /** @} */
673
674 /** @} */
675
676
677 #ifdef __cplusplus
678 }
679 #endif
680
681 #endif /* __GR55xx_HAL_ADC_H__ */
682
683 /** @} */
684
685 /** @} */
686
687 /** @} */
hal_adc_poll_for_conversion
hal_status_t hal_adc_poll_for_conversion(adc_handle_t *p_adc, uint16_t *p_data, uint32_t length)
Polling for conversion.
_hal_adc_callback::adc_conv_cplt_callback
void(* adc_conv_cplt_callback)(adc_handle_t *p_adc)
ADC conversion completed callback
Definition: gr55xx_hal_adc.h:169
adc_trim_info_t::offset_int_1p2
uint16_t offset_int_1p2
Internal reference 1.2v.
Definition: gr55xx_hal_adc.h:102
hal_adc_get_error
uint32_t hal_adc_get_error(adc_handle_t *p_adc)
Return the ADC error code.
adc_trim_info_t::offset_int_2p0
uint16_t offset_int_2p0
Internal reference 2.0v.
Definition: gr55xx_hal_adc.h:106
adc_trim_info_t::slope_int_1p6
uint16_t slope_int_1p6
Internal reference 1.6v.
Definition: gr55xx_hal_adc.h:103
adc_get_trim_func
uint16_t adc_get_trim_func(adc_trim_info_t *p_adc_trim)
adc_get_trim_func.
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
_adc_handle::error_code
__IO uint32_t error_code
ADC error code
Definition: gr55xx_hal_adc.h:145
HAL_ADC_STATE_BUSY
@ HAL_ADC_STATE_BUSY
An internal process is ongoing
Definition: gr55xx_hal_adc.h:80
hal_adc_start_dma_sg_llp
hal_status_t hal_adc_start_dma_sg_llp(adc_handle_t *p_adc, uint16_t *p_data, uint32_t length, dma_sg_llp_config_t *sg_llp_config)
DMA for conversion.
_hal_adc_callback::adc_msp_init
void(* adc_msp_init)(adc_handle_t *p_adc)
ADC init MSP callback
Definition: gr55xx_hal_adc.h:167
gr55xx_ll_adc.h
Header file containing functions prototypes of ADC LL library.
HAL_ADC_STATE_RESET
@ HAL_ADC_STATE_RESET
Peripheral not initialized
Definition: gr55xx_hal_adc.h:78
adc_trim_info_t::offset_int_0p8
uint16_t offset_int_0p8
Internal reference 0.8v.
Definition: gr55xx_hal_adc.h:100
_adc_handle::p_buffer
uint16_t * p_buffer
Pointer to ADC conversion buffer
Definition: gr55xx_hal_adc.h:133
hal_adc_stop_dma
hal_status_t hal_adc_stop_dma(adc_handle_t *p_adc)
Abort ongoing conversion (blocking mode).
adc_trim_info_t::slope_ext_1p0
uint16_t slope_ext_1p0
External reference 1.0v.
Definition: gr55xx_hal_adc.h:107
hal_adc_init
hal_status_t hal_adc_init(adc_handle_t *p_adc)
Initialize the ADC according to the specified parameters in the adc_init_t and initialize the associa...
hal_adc_resume_reg
hal_status_t hal_adc_resume_reg(adc_handle_t *p_adc)
Restore some registers related to ADC configuration after sleep.
adc_trim_info_t::slope_int_0p8
uint16_t slope_int_0p8
Internal reference 0.8v.
Definition: gr55xx_hal_adc.h:99
dma_sg_llp_config
LL DMA sg and llp config definition.
Definition: gr55xx_hal_dma.h:219
adc_handle_t
struct _adc_handle adc_handle_t
ADC handle Structure definition.
hal_adc_suspend_reg
hal_status_t hal_adc_suspend_reg(adc_handle_t *p_adc)
Suspend some registers related to ADC configuration before sleep.
adc_trim_info_t::slope_int_2p0
uint16_t slope_int_2p0
Internal reference 2.0v.
Definition: gr55xx_hal_adc.h:105
hal_adc_state_t
hal_adc_state_t
HAL ADC State Enumerations definition.
Definition: gr55xx_hal_adc.h:77
hal_adc_msp_init
void hal_adc_msp_init(adc_handle_t *p_adc)
Initialize the ADC MSP.
_adc_handle::state
__IO hal_adc_state_t state
ADC communication state
Definition: gr55xx_hal_adc.h:143
hal_adc_clock_start
hal_status_t hal_adc_clock_start(adc_handle_t *p_adc)
Start the ADC clock.
hal_adc_conv_cplt_callback
void hal_adc_conv_cplt_callback(adc_handle_t *p_adc)
Conversion completed callback.
adc_trim_info_t::adc_temp
uint16_t adc_temp
ADC TEMP.
Definition: gr55xx_hal_adc.h:98
_hal_adc_callback::adc_get_trim_func
uint16_t(* adc_get_trim_func)(adc_trim_info_t *p_adc_trim)
ADC get trim information callback(must return 0x0000 when successful)
Definition: gr55xx_hal_adc.h:170
_adc_handle
ADC handle Structure definition.
Definition: gr55xx_hal_adc.h:130
gr55xx_hal_dma.h
Header file containing functions prototypes of DMA HAL library.
adc_trim_info_t::offset_ext_1p0
uint16_t offset_ext_1p0
External reference 1.0v.
Definition: gr55xx_hal_adc.h:108
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
hal_adc_msp_deinit
void hal_adc_msp_deinit(adc_handle_t *p_adc)
De-initialize the ADC MSP.
adc_trim_info_t
ADC trim parameter information definition.
Definition: gr55xx_hal_adc.h:97
adc_init_t
ll_adc_init_t adc_init_t
ADC init structure definition.
Definition: gr55xx_hal_adc.h:119
hal_adc_start_dma
hal_status_t hal_adc_start_dma(adc_handle_t *p_adc, uint16_t *p_data, uint32_t length)
DMA for conversion.
hal_adc_callback_t
struct _hal_adc_callback hal_adc_callback_t
HAL ADC Callback function definition.
adc_trim_info_t::slope_int_1p2
uint16_t slope_int_1p2
Internal reference 1.2v.
Definition: gr55xx_hal_adc.h:101
hal_adc_get_avg_voltage
hal_status_t hal_adc_get_avg_voltage(adc_handle_t *p_adc, float *p_data, uint32_t length)
Get the ADC sampling code by polling, and convert sampling code of the specified length to the averag...
hal_adc_change_channels
hal_status_t hal_adc_change_channels(adc_handle_t *p_adc)
Set the new channels parameter to ADC.
_adc_handle::init
adc_init_t init
ADC configuration parameters
Definition: gr55xx_hal_adc.h:131
HAL_ADC_STATE_ERROR
@ HAL_ADC_STATE_ERROR
Peripheral in error
Definition: gr55xx_hal_adc.h:81
hal_adc_deinit
hal_status_t hal_adc_deinit(adc_handle_t *p_adc)
De-initialize the ADC peripheral.
_adc_handle::p_dma
dma_handle_t * p_dma
ADC DMA Handle parameters
Definition: gr55xx_hal_adc.h:139
adc_trim_info_t::offset_int_1p6
uint16_t offset_int_1p6
Internal reference 1.6v.
Definition: gr55xx_hal_adc.h:104
_adc_handle::retention
uint32_t retention[2]
ADC important register information.
Definition: gr55xx_hal_adc.h:147
HAL_ADC_STATE_READY
@ HAL_ADC_STATE_READY
Peripheral initialized and ready for use
Definition: gr55xx_hal_adc.h:79
_adc_handle::lock
__IO hal_lock_t lock
Locking object
Definition: gr55xx_hal_adc.h:141
_dma_handle
DMA handle Structure definition.
Definition: gr55xx_hal_dma.h:277
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
_adc_handle::buff_count
__IO uint32_t buff_count
Conversion buffer counter
Definition: gr55xx_hal_adc.h:137
_hal_adc_callback
HAL ADC Callback function definition.
Definition: gr55xx_hal_adc.h:166
_adc_handle::buff_size
__IO uint32_t buff_size
Conversion buffer size
Definition: gr55xx_hal_adc.h:135
hal_adc_get_state
hal_adc_state_t hal_adc_get_state(adc_handle_t *p_adc)
Return the ADC handle state.
_hal_adc_callback::adc_msp_deinit
void(* adc_msp_deinit)(adc_handle_t *p_adc)
ADC de-init MSP callback
Definition: gr55xx_hal_adc.h:168