1 /** 2 * @file adc.h 3 * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited 4 */ 5 6 #ifndef HAL_ADC_H 7 #define HAL_ADC_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /** @addtogroup hal_adc ADC 14 * ADC hal API. 15 * 16 * @{ 17 */ 18 19 #include <stdint.h> 20 21 /* Define the wait forever timeout macro */ 22 #define HAL_WAIT_FOREVER 0xFFFFFFFFU 23 24 /* Define ADC config args */ 25 typedef struct { 26 uint32_t sampling_cycle; /**< sampling period in number of ADC clock cycles */ 27 } adc_config_t; 28 29 /* Define ADC dev hal handle */ 30 typedef struct { 31 uint8_t port; /**< adc port */ 32 adc_config_t config; /**< adc config */ 33 void *priv; /**< priv data */ 34 } adc_dev_t; 35 36 /** 37 * Initialises an ADC interface, Prepares an ADC hardware interface for sampling 38 * 39 * @param[in] adc the interface which should be initialised 40 * 41 * @return 0 : on success, otherwise is error 42 */ 43 int32_t hal_adc_init(adc_dev_t *adc); 44 45 /** 46 * Takes a single sample from an ADC interface 47 * 48 * @note If the ADC is configured with mutiple channels, the result of each channel is 49 * copied to output buffer one by one according to the sequence of the channel registered, 50 * and each result takes sizeof(uint32_t) bytes. 51 * 52 * @param[in] adc the interface which should be sampled 53 * @param[out] output pointer to a variable which will receive the sample 54 * @param[in] timeout ms timeout 55 * 56 * @return 0 : on success, otherwise is error 57 */ 58 int32_t hal_adc_value_get(adc_dev_t *adc, uint32_t *output, uint32_t timeout); 59 60 /** 61 * De-initialises an ADC interface, Turns off an ADC hardware interface 62 * 63 * @param[in] adc the interface which should be de-initialised 64 * 65 * @return 0 : on success, otherwise is error 66 */ 67 int32_t hal_adc_finalize(adc_dev_t *adc); 68 69 /** @} */ 70 71 #ifdef __cplusplus 72 } 73 #endif 74 75 #endif /* HAL_ADC_H */ 76 77