1 /* 2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited 3 */ 4 #ifndef __HAL_GPADC_H__ 5 #define __HAL_GPADC_H__ 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 #define HAL_GPADC_BAD_VALUE 0xFFFF 12 13 enum HAL_GPADC_CHAN_T { 14 HAL_GPADC_CHAN_0 = 0, 15 HAL_GPADC_CHAN_BATTERY = 1, 16 HAL_GPADC_CHAN_2 = 2, 17 HAL_GPADC_CHAN_3 = 3, 18 HAL_GPADC_CHAN_4 = 4, 19 HAL_GPADC_CHAN_5 = 5, 20 HAL_GPADC_CHAN_6 = 6, 21 HAL_GPADC_CHAN_ADCKEY = 7, 22 HAL_GPADC_CHAN_QTY, 23 }; 24 25 enum HAL_GPADC_ATP_T { 26 HAL_GPADC_ATP_NULL = 0, 27 HAL_GPADC_ATP_125US = 125, 28 HAL_GPADC_ATP_500US = 500, 29 HAL_GPADC_ATP_1MS = 1000, 30 HAL_GPADC_ATP_2MS = 2000, 31 HAL_GPADC_ATP_5MS = 5000, 32 HAL_GPADC_ATP_10MS = 10000, 33 HAL_GPADC_ATP_20MS = 20000, 34 HAL_GPADC_ATP_30MS = 30000, 35 HAL_GPADC_ATP_40MS = 40000, 36 HAL_GPADC_ATP_50MS = 50000, 37 HAL_GPADC_ATP_60MS = 60000, 38 HAL_GPADC_ATP_ONESHOT = -1, 39 }; 40 41 enum HAL_ADCKEY_IRQ_T { 42 HAL_ADCKEY_IRQ_NONE = 0, 43 HAL_ADCKEY_IRQ_PRESSED = (1 << 0), 44 HAL_ADCKEY_IRQ_RELEASED = (1 << 1), 45 HAL_ADCKEY_IRQ_BOTH = (HAL_ADCKEY_IRQ_PRESSED | HAL_ADCKEY_IRQ_RELEASED), 46 }; 47 48 enum HAL_ADCKEY_IRQ_STATUS_T { 49 HAL_ADCKEY_ADC_VALID = (1 << 0), 50 HAL_ADCKEY_RELEASED = (1 << 1), 51 HAL_ADCKEY_PRESSED = (1 << 2), 52 HAL_ADCKEY_ERR0 = (1 << 3), 53 HAL_ADCKEY_ERR1 = (1 << 4), 54 }; 55 56 typedef uint16_t HAL_GPADC_MV_T; 57 58 typedef void (*HAL_GPADC_EVENT_CB_T)(uint16_t raw_val, HAL_GPADC_MV_T volt); 59 typedef void (*HAL_ADCKEY_EVENT_CB_T)(enum HAL_ADCKEY_IRQ_STATUS_T irq_status, uint16_t raw_val); 60 61 int hal_gpadc_open(enum HAL_GPADC_CHAN_T channel, enum HAL_GPADC_ATP_T atp, HAL_GPADC_EVENT_CB_T cb); 62 63 bool hal_gpadc_get_volt(enum HAL_GPADC_CHAN_T ch, HAL_GPADC_MV_T *volt); 64 65 int hal_gpadc_close(enum HAL_GPADC_CHAN_T channel); 66 67 void hal_gpadc_sleep(void); 68 69 void hal_gpadc_wakeup(void); 70 71 void hal_adckey_set_irq_handler(HAL_ADCKEY_EVENT_CB_T cb); 72 73 int hal_adckey_set_irq(enum HAL_ADCKEY_IRQ_T type); 74 75 #ifdef __cplusplus 76 } 77 #endif 78 79 #endif//__FMDEC_H__ 80