diff --git a/drivers/bl702_driver/hal_drv/inc/hal_adc.h b/drivers/bl702_driver/hal_drv/inc/hal_adc.h index aa812328..5d2ab97e 100644 --- a/drivers/bl702_driver/hal_drv/inc/hal_adc.h +++ b/drivers/bl702_driver/hal_drv/inc/hal_adc.h @@ -24,7 +24,7 @@ #define __HAL_ADC__H__ #ifdef __cplusplus -extern "C"{ +extern "C" { #endif #include "hal_common.h" @@ -126,12 +126,16 @@ typedef enum { } adc_pga_gain_t; enum adc_event_type { + ADC_EVENT_UNDERRUN, + ADC_EVENT_OVERRUN, ADC_EVENT_FIFO, - UART_EVENT_UNKNOWN + ADC_EVENT_UNKNOWN }; enum adc_it_type { - ADC_FIFO_IT = 1 << 0, + ADC_UNDERRUN_IT = 1 << 2, + ADC_OVERRUN_IT = 1 << 3, + ADC_FIFO_IT = 1 << 5, }; typedef struct diff --git a/drivers/bl702_driver/hal_drv/src/hal_adc.c b/drivers/bl702_driver/hal_drv/src/hal_adc.c index 61cb841d..1a32f55f 100644 --- a/drivers/bl702_driver/hal_drv/src/hal_adc.c +++ b/drivers/bl702_driver/hal_drv/src/hal_adc.c @@ -165,17 +165,31 @@ int adc_control(struct device *dev, int cmd, void *args) uint8_t rlt = 0; switch (cmd) { - case DEVICE_CTRL_SET_INT /* constant-expression */: - ADC_IntMask(ADC_INT_FIFO_READY, UNMASK); + case DEVICE_CTRL_SET_INT /* constant-expression */: { + uint32_t offset = __builtin_ctz((uint32_t)args); + while ((2 <= offset) && (offset < 6)) { + if ((uint32_t)args & (1 << offset)) { + ADC_IntMask(offset, UNMASK); + } + offset++; + } CPU_Interrupt_Enable(GPADC_DMA_IRQn); break; + } - case DEVICE_CTRL_CLR_INT /* constant-expression */: - ADC_IntMask(ADC_INT_FIFO_READY, MASK); + case DEVICE_CTRL_CLR_INT /* constant-expression */: { + uint32_t offset = __builtin_ctz((uint32_t)args); + while ((2 <= offset) && (offset < 6)) { + if ((uint32_t)args & (1 << offset)) { + ADC_IntMask(offset, UNMASK); + } + offset++; + } CPU_Interrupt_Disable(GPADC_DMA_IRQn); break; + } case DEVICE_CTRL_GET_INT /* constant-expression */: /* code */ @@ -340,12 +354,12 @@ void adc_isr(adc_device_t *handle) } if (ADC_GetIntStatus(ADC_INT_FIFO_UNDERRUN) == SET && ADC_IntGetMask(ADC_INT_FIFO_UNDERRUN) == UNMASK) { - //handle->parent.callback(&handle->parent, NULL, 0, ADC_EVENT_UNDERRUN); + handle->parent.callback(&handle->parent, NULL, 0, ADC_EVENT_UNDERRUN); ADC_IntClr(ADC_INT_FIFO_UNDERRUN); } if (ADC_GetIntStatus(ADC_INT_FIFO_OVERRUN) == SET && ADC_IntGetMask(ADC_INT_FIFO_OVERRUN) == UNMASK) { - //handle->parent.callback(&handle->parent, NULL, 0, ADC_EVENT_OVERRUN); + handle->parent.callback(&handle->parent, NULL, 0, ADC_EVENT_OVERRUN); ADC_IntClr(ADC_INT_FIFO_OVERRUN); }