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