gr55xx_hal_adc.h
Go to the documentation of this file.
1
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 ------------------------------------------------------------*/
76 typedef enum
77 {
78 HAL_ADC_STATE_RESET = 0x00,
79 HAL_ADC_STATE_READY = 0x01,
80 HAL_ADC_STATE_BUSY = 0x02,
81 HAL_ADC_STATE_ERROR = 0x04
83 } hal_adc_state_t;
84
100 typedef ll_adc_init_t adc_init_t;
110 typedef struct _adc_handle
111 {
112 adc_init_t init;
114 uint16_t *p_buffer;
116 __IO uint32_t buff_size;
118 __IO uint32_t buff_count;
120 dma_handle_t *p_dma;
122 __IO hal_lock_t lock;
124 __IO hal_adc_state_t state;
126 __IO uint32_t error_code;
128 uint32_t retention[2];
130 } adc_handle_t;
146 typedef struct _adc_callback
147 {
148 void (*adc_msp_init)(adc_handle_t *p_adc);
149 void (*adc_msp_deinit)(adc_handle_t *p_adc);
150 void (*adc_conv_cplt_callback)(adc_handle_t *p_adc);
151 } adc_callback_t;
152
166 /* Exported constants --------------------------------------------------------*/
174 #define HAL_ADC_ERROR_NONE ((uint32_t)0x00000000)
175 #define HAL_ADC_ERROR_TIMEOUT ((uint32_t)0x00000001)
176 #define HAL_ADC_ERROR_DMA ((uint32_t)0x00000004)
177 #define HAL_ADC_ERROR_INVALID_PARAM ((uint32_t)0x00000008)
183 #define ADC_CLK_16M LL_ADC_CLK_16
184 #define ADC_CLK_1P6M LL_ADC_CLK_1P6
185 #define ADC_CLK_8M LL_ADC_CLK_8
186 #define ADC_CLK_4M LL_ADC_CLK_4
187 #define ADC_CLK_2M LL_ADC_CLK_2
188 #define ADC_CLK_1M LL_ADC_CLK_1
194 #define ADC_REF_VALUE_0P8 LL_ADC_REF_VALUE_0P8
195 #define ADC_REF_VALUE_1P2 LL_ADC_REF_VALUE_1P2
196 #define ADC_REF_VALUE_1P6 LL_ADC_REF_VALUE_1P6
203 #define ADC_INPUT_SINGLE LL_ADC_INPUT_SINGLE
204 #define ADC_INPUT_DIFFERENTIAL LL_ADC_INPUT_DIFFERENTIAL
210 #define ADC_INPUT_SRC_IO0 LL_ADC_INPUT_SRC_IO0
211 #define ADC_INPUT_SRC_IO1 LL_ADC_INPUT_SRC_IO1
212 #define ADC_INPUT_SRC_IO2 LL_ADC_INPUT_SRC_IO2
213 #define ADC_INPUT_SRC_IO3 LL_ADC_INPUT_SRC_IO3
214 #define ADC_INPUT_SRC_IO4 LL_ADC_INPUT_SRC_IO4
215 #define ADC_INPUT_SRC_TMP LL_ADC_INPUT_SRC_TMP
216 #define ADC_INPUT_SRC_BAT LL_ADC_INPUT_SRC_BAT
217 #define ADC_INPUT_SRC_REF LL_ADC_INPUT_SRC_REF
224 #define ADC_REF_SRC_BUF_INT LL_ADC_REF_SRC_BUF_INT
225 #define ADC_REF_SRC_IO0 LL_ADC_REF_SRC_IO0
226 #define ADC_REF_SRC_IO1 LL_ADC_REF_SRC_IO1
227 #define ADC_REF_SRC_IO2 LL_ADC_REF_SRC_IO2
228 #define ADC_REF_SRC_IO3 LL_ADC_REF_SRC_IO3
234 #define ADC_DEFAULT_CONFIG LL_ADC_DEFAULT_CONFIG
235
237 /* Exported macro ------------------------------------------------------------*/
246 #define __HAL_ADC_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_ADC_STATE_RESET)
247
252 #define __HAL_ADC_ENABLE(__HANDLE__) ll_adc_enable()
253
258 #define __HAL_ADC_DISABLE(__HANDLE__) ll_adc_disable()
259
264 #define __HAL_ADC_ENABLE_CLOCK(__HANDLE__) ll_adc_enable_clock()
265
270 #define __HAL_ADC_DISABLE_CLOCK(__HANDLE__) ll_adc_disable_clock()
271
276 #define __HAL_ADC_GET_FLAG_NOTEMPTY(__HANDLE__) ll_adc_is_fifo_notempty()
277
282 #define __HAL_ADC_FLUSH_FIFO(__HANDLE__) do { \
283 while(ll_adc_is_fifo_notempty()) \
284 { \
285 ll_adc_read_fifo(); \
286 } \
287 } while(0)
288
291 /* Private macros ------------------------------------------------------------*/
301 #define IS_ADC_INPUT(__INPUT__) (((__INPUT__) == ADC_INPUT_SRC_IO0) || \
302 ((__INPUT__) == ADC_INPUT_SRC_IO1) || \
303 ((__INPUT__) == ADC_INPUT_SRC_IO2) || \
304 ((__INPUT__) == ADC_INPUT_SRC_IO3) || \
305 ((__INPUT__) == ADC_INPUT_SRC_IO4) || \
306 ((__INPUT__) == ADC_INPUT_SRC_TMP) || \
307 ((__INPUT__) == ADC_INPUT_SRC_BAT) || \
308 ((__INPUT__) == ADC_INPUT_SRC_REF))
309
315 #define IS_ADC_INPUT_MODE(__MODE__) (((__MODE__) == ADC_INPUT_SINGLE) || \
316 ((__MODE__) == ADC_INPUT_DIFFERENTIAL)
317
323 #define IS_ADC_REF(__INPUT__) (((__INPUT__) == ADC_REF_SRC_BUF_INT) || \
324 ((__INPUT__) == ADC_REF_SRC_INT) || \
325 ((__INPUT__) == ADC_REF_SRC_IO0) || \
326 ((__INPUT__) == ADC_REF_SRC_IO1) || \
327 ((__INPUT__) == ADC_REF_SRC_IO2) || \
328 ((__INPUT__) == ADC_REF_SRC_IO3))
329
335 #define IS_ADC_REF_VALUE(__VALUE__) (((__VALUE__) >= ADC_REF_VALUE_0P8) && \
336 ((__VALUE__) <= ADC_REF_VALUE_1P6))
337
343 #define IS_ADC_CLOCK(__CLOCK__) (((__CLOCK__) == ADC_CLK_16M) || \
344 ((__CLOCK__) == ADC_CLK_8M) || \
345 ((__CLOCK__) == ADC_CLK_4M) || \
346 ((__CLOCK__) == ADC_CLK_2M) || \
347 ((__CLOCK__) == ADC_CLK_1M) || \
348 ((__CLOCK__) == ADC_CLK_1P6M))
349
354 /* Exported functions --------------------------------------------------------*/
378 hal_status_t hal_adc_init(adc_handle_t *p_adc);
379
393 hal_status_t hal_adc_deinit(adc_handle_t *p_adc);
394
406 void hal_adc_msp_init(adc_handle_t *p_adc);
407
419 void hal_adc_msp_deinit(adc_handle_t *p_adc);
420
442 hal_status_t hal_adc_set_dma_threshold(adc_handle_t *p_adc, uint32_t threshold);
443
454 uint32_t hal_adc_get_dma_threshold(adc_handle_t *p_adc);
455
470 hal_status_t hal_adc_poll_for_conversion(adc_handle_t *p_adc, uint16_t *p_data, uint32_t length);
471
486 hal_status_t hal_adc_start_dma(adc_handle_t *p_adc, uint16_t *p_data, uint32_t length);
487
507 hal_status_t hal_adc_stop_dma(adc_handle_t *p_adc);
508
520 void hal_adc_conv_cplt_callback(adc_handle_t* p_adc);
521
552 hal_adc_state_t hal_adc_get_state(adc_handle_t *p_adc);
553
564 uint32_t hal_adc_get_error(adc_handle_t *p_adc);
565
577 hal_status_t hal_adc_suspend_reg(adc_handle_t *p_adc);
578
591 hal_status_t hal_adc_resume_reg(adc_handle_t *p_adc);
592
598 #ifdef __cplusplus
599 }
600 #endif
601
602 #endif /* __GR55xx_HAL_ADC_H__ */
603
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_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: gr55xx_hal_def.h:81
_adc_handle::error_code
__IO uint32_t error_code
Definition: gr55xx_hal_adc.h:126
HAL_ADC_STATE_BUSY
@ HAL_ADC_STATE_BUSY
Definition: gr55xx_hal_adc.h:80
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_callback::adc_conv_cplt_callback
void(* adc_conv_cplt_callback)(adc_handle_t *p_adc)
Definition: gr55xx_hal_adc.h:150
_adc_handle::p_buffer
uint16_t * p_buffer
Definition: gr55xx_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_init
hal_status_t hal_adc_init(adc_handle_t *p_adc)
Initialize the ADC according to the specified parameters in the adc_init_t and initialize the associa...
hal_adc_resume_reg
hal_status_t hal_adc_resume_reg(adc_handle_t *p_adc)
Restore some registers related to ADC configuration after sleep. This function must be used in conjun...
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.
_ll_adc_init
LL ADC init Structure definition.
Definition: gr55xx_ll_adc.h:77
_adc_callback::adc_msp_init
void(* adc_msp_init)(adc_handle_t *p_adc)
Definition: gr55xx_hal_adc.h:148
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:124
hal_adc_conv_cplt_callback
void hal_adc_conv_cplt_callback(adc_handle_t *p_adc)
Conversion completed callback.
_adc_callback::adc_msp_deinit
void(* adc_msp_deinit)(adc_handle_t *p_adc)
Definition: gr55xx_hal_adc.h:149
_adc_handle
ADC handle Structure definition.
Definition: gr55xx_hal_adc.h:111
gr55xx_hal_dma.h
Header file containing functions prototypes of DMA HAL library.
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_callback_t
struct _adc_callback adc_callback_t
HAL ADC Callback function definition.
adc_init_t
ll_adc_init_t adc_init_t
ADC init structure definition.
Definition: gr55xx_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.
_adc_callback
HAL ADC Callback function definition.
Definition: gr55xx_hal_adc.h:147
_adc_handle::init
adc_init_t init
Definition: gr55xx_hal_adc.h:112
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:120
_adc_handle::retention
uint32_t retention[2]
Definition: gr55xx_hal_adc.h:128
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:122
_dma_handle
DMA handle Structure definition.
Definition: gr55xx_hal_dma.h:179
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:118
_adc_handle::buff_size
__IO uint32_t buff_size
Definition: gr55xx_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.