NANO130: Remove unnecessary synchronization in analog-in HAL

Driver AnalogIn has done with it, so remove synchronization in analog-in HAL.
pull/11780/head
Chun-Chieh Li 2019-10-31 11:25:54 +08:00
parent 72ea613a12
commit 0260f1b3df
1 changed files with 5 additions and 30 deletions

View File

@ -25,7 +25,6 @@
#include "nu_modutil.h"
static uint32_t adc_modinit_mask = 0;
volatile int adc_busy_flag = 0;
static const struct nu_modinit_s adc_modinit_tab[] = {
{ADC_0_0, ADC_MODULE, CLK_CLKSEL1_ADC_S_HIRC, CLK_ADC_CLK_DIVIDER(1), ADC_RST, ADC_IRQn, NULL},
@ -58,13 +57,7 @@ void analogin_init(analogin_t *obj, PinName pin)
ADC_T *adc_base = (ADC_T *) NU_MODBASE(obj->adc);
uint32_t chn = NU_MODSUBINDEX(obj->adc);
// Wait for ADC is not busy, due to all ADC channels share the same module
while (adc_busy_flag != 0) {
wait_us(100);
}
adc_busy_flag = 1;
// NOTE: All channels (identified by ADCName) share a ADC module. This reset will also affect other channels of the same ADC module.
if (! adc_modinit_mask) {
// Select clock source of paired channels
@ -88,10 +81,8 @@ void analogin_init(analogin_t *obj, PinName pin)
// Just enable channel N
adc_base->CHEN |= 1 << chn;
}
adc_modinit_mask |= 1 << chn;
adc_busy_flag = 0;
}
void analogin_free(analogin_t *obj)
@ -104,12 +95,6 @@ void analogin_free(analogin_t *obj)
ADC_T *adc_base = (ADC_T *) NU_MODBASE(obj->adc);
// Wait for ADC is not busy, due to all ADC channels share the same module
while (adc_busy_flag != 0) {
wait_us(100);
}
adc_busy_flag = 1;
/* Channel-level windup from here */
/* Mark channel free */
@ -132,8 +117,6 @@ void analogin_free(analogin_t *obj)
CLK_DisableModuleClock(modinit->clkidx);
}
adc_busy_flag = 0;
/* Free up pins */
gpio_set(obj->pin);
obj->pin = NC;
@ -143,27 +126,19 @@ uint16_t analogin_read_u16(analogin_t *obj)
{
ADC_T *adc_base = (ADC_T *) NU_MODBASE(obj->adc);
uint32_t chn = NU_MODSUBINDEX(obj->adc);
// Wait for ADC is not busy, due to all ADC channels share the same module
while (adc_busy_flag != 0) {
wait_us(100);
}
adc_busy_flag = 1;
// Start the A/D conversion
adc_base->CR |= ADC_CR_ADST_Msk;
// Wait for conversion finish
while (! ADC_GET_INT_FLAG(adc_base, ADC_ADF_INT) & ADC_ADF_INT) ;
ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT);
uint16_t conv_res_12 = ADC_GET_CONVERSION_DATA(adc_base, chn);
adc_busy_flag = 0;
// Just 12 bits are effective. Convert to 16 bits.
// conv_res_12: 0000 b11b10b9b8 b7b6b5b4 b3b2b1b0
// conv_res_16: b11b10b9b8 b7b6b5b4 b3b2b1b0 b11b10b9b8
uint16_t conv_res_16 = (conv_res_12 << 4) | (conv_res_12 >> 8);
return conv_res_16;
}