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