MD-UV3x0: using STM32 ADC driver

master
Silvano Seva 2024-11-10 12:04:26 +01:00
rodzic 81c55b5377
commit 10d7ded93f
3 zmienionych plików z 19 dodań i 13 usunięć

Wyświetl plik

@ -24,9 +24,11 @@
#include <pthread.h>
#include <pinmap.h>
#include <spi_stm32.h>
#include <adc_stm32.h>
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)

Wyświetl plik

@ -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

Wyświetl plik

@ -21,7 +21,7 @@
#include <peripherals/gpio.h>
#include <hwconfig.h>
#include <string.h>
#include <ADC1_MDx.h>
#include <adc_stm32.h>
#include <calibInfo_MDx.h>
#include <interfaces/nvmem.h>
#include <toneGenerator_MDx.h>
@ -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)