diff --git a/platform/targets/MD-UV3x0/hwconfig.c b/platform/targets/MD-UV3x0/hwconfig.c index 3c646bb9..524f0c89 100644 --- a/platform/targets/MD-UV3x0/hwconfig.c +++ b/platform/targets/MD-UV3x0/hwconfig.c @@ -24,9 +24,11 @@ #include #include #include +#include static pthread_mutex_t c6000_mutex; +static pthread_mutex_t adcMutex; /** * SPI bitbang function for HR_C6000 command interface (U_SPI). @@ -73,3 +75,4 @@ static uint8_t spiC6000_func(const void *priv, uint8_t value) SPI_CUSTOM_DEVICE_DEFINE(c6000_spi, spiC6000_func, NULL, &c6000_mutex) SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL) +ADC_STM32_DEVICE_DEFINE(adc1, ADC1, &adcMutex, 3300000) diff --git a/platform/targets/MD-UV3x0/hwconfig.h b/platform/targets/MD-UV3x0/hwconfig.h index d016fa57..2ccef7c2 100644 --- a/platform/targets/MD-UV3x0/hwconfig.h +++ b/platform/targets/MD-UV3x0/hwconfig.h @@ -33,8 +33,16 @@ extern HR_C6000 C6000; extern "C" { #endif +enum AdcChannel +{ + ADC_VOL_CH = 0, + ADC_VBAT_CH = 1, + ADC_MIC_CH = 3, +}; + extern const struct spiCustomDevice c6000_spi; extern const struct spiDevice nvm_spi; +extern const struct Adc adc1; /* Device has a working real time clock */ #define CONFIG_RTC diff --git a/platform/targets/MD-UV3x0/platform.c b/platform/targets/MD-UV3x0/platform.c index c386ac1b..426a4c2d 100644 --- a/platform/targets/MD-UV3x0/platform.c +++ b/platform/targets/MD-UV3x0/platform.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -51,12 +51,7 @@ void platform_init() gpio_setPin(PWR_SW); #endif - /* - * Initialise ADC1, for vbat, RSSI, ... - * Configuration of corresponding GPIOs in analog input mode is done inside - * the driver. - */ - adc1_init(); + adcStm32_init(&adc1); memset(&hwInfo, 0x00, sizeof(hwInfo)); @@ -76,7 +71,7 @@ void platform_terminate() gpio_clearPin(RED_LED); /* Shut down all the modules */ - adc1_terminate(); + adcStm32_terminate(&adc1); nvm_terminate(); toneGen_terminate(); chSelector_terminate(); @@ -90,16 +85,16 @@ uint16_t platform_getVbat() { /* * Battery voltage is measured through an 1:3 voltage divider and - * adc1_getMeasurement returns a value in mV. Thus, to have effective - * battery voltage, multiply by three. + * adc1_getMeasurement returns a value in uV. */ - return adc1_getMeasurement(ADC_VBAT_CH) * 3; + uint32_t vbat = adc_getVoltage(&adc1, ADC_VBAT_CH) * 3; + return vbat / 1000; } uint8_t platform_getMicLevel() { /* Value from ADC is 12 bit wide: shift right by four to get 0 - 255 */ - return (adc1_getRawSample(ADC_VOX_CH) >> 4); + return (adc_getRawSample(&adc1, ADC_MIC_CH) >> 4); } uint8_t platform_getVolumeLevel() @@ -110,7 +105,7 @@ uint8_t platform_getVolumeLevel() * lines with a breakpoint around 270mV. * Output value has range 0 - 255 with breakpoint at 150. */ - uint16_t value = adc1_getMeasurement(ADC_VOL_CH); + uint16_t value = adc_getVoltage(&adc1, ADC_VOL_CH) / 1000; uint32_t output; if(value < 20)