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