MD-UV3x0: using STM32 ADC driver
This commit is contained in:
parent
81c55b5377
commit
10d7ded93f
|
|
@ -24,9 +24,11 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <pinmap.h>
|
#include <pinmap.h>
|
||||||
#include <spi_stm32.h>
|
#include <spi_stm32.h>
|
||||||
|
#include <adc_stm32.h>
|
||||||
|
|
||||||
|
|
||||||
static pthread_mutex_t c6000_mutex;
|
static pthread_mutex_t c6000_mutex;
|
||||||
|
static pthread_mutex_t adcMutex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SPI bitbang function for HR_C6000 command interface (U_SPI).
|
* 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_CUSTOM_DEVICE_DEFINE(c6000_spi, spiC6000_func, NULL, &c6000_mutex)
|
||||||
SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL)
|
SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL)
|
||||||
|
ADC_STM32_DEVICE_DEFINE(adc1, ADC1, &adcMutex, 3300000)
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,16 @@ extern HR_C6000 C6000;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum AdcChannel
|
||||||
|
{
|
||||||
|
ADC_VOL_CH = 0,
|
||||||
|
ADC_VBAT_CH = 1,
|
||||||
|
ADC_MIC_CH = 3,
|
||||||
|
};
|
||||||
|
|
||||||
extern const struct spiCustomDevice c6000_spi;
|
extern const struct spiCustomDevice c6000_spi;
|
||||||
extern const struct spiDevice nvm_spi;
|
extern const struct spiDevice nvm_spi;
|
||||||
|
extern const struct Adc adc1;
|
||||||
|
|
||||||
/* Device has a working real time clock */
|
/* Device has a working real time clock */
|
||||||
#define CONFIG_RTC
|
#define CONFIG_RTC
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
#include <peripherals/gpio.h>
|
#include <peripherals/gpio.h>
|
||||||
#include <hwconfig.h>
|
#include <hwconfig.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ADC1_MDx.h>
|
#include <adc_stm32.h>
|
||||||
#include <calibInfo_MDx.h>
|
#include <calibInfo_MDx.h>
|
||||||
#include <interfaces/nvmem.h>
|
#include <interfaces/nvmem.h>
|
||||||
#include <toneGenerator_MDx.h>
|
#include <toneGenerator_MDx.h>
|
||||||
|
|
@ -51,12 +51,7 @@ void platform_init()
|
||||||
gpio_setPin(PWR_SW);
|
gpio_setPin(PWR_SW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
adcStm32_init(&adc1);
|
||||||
* Initialise ADC1, for vbat, RSSI, ...
|
|
||||||
* Configuration of corresponding GPIOs in analog input mode is done inside
|
|
||||||
* the driver.
|
|
||||||
*/
|
|
||||||
adc1_init();
|
|
||||||
|
|
||||||
memset(&hwInfo, 0x00, sizeof(hwInfo));
|
memset(&hwInfo, 0x00, sizeof(hwInfo));
|
||||||
|
|
||||||
|
|
@ -76,7 +71,7 @@ void platform_terminate()
|
||||||
gpio_clearPin(RED_LED);
|
gpio_clearPin(RED_LED);
|
||||||
|
|
||||||
/* Shut down all the modules */
|
/* Shut down all the modules */
|
||||||
adc1_terminate();
|
adcStm32_terminate(&adc1);
|
||||||
nvm_terminate();
|
nvm_terminate();
|
||||||
toneGen_terminate();
|
toneGen_terminate();
|
||||||
chSelector_terminate();
|
chSelector_terminate();
|
||||||
|
|
@ -90,16 +85,16 @@ uint16_t platform_getVbat()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Battery voltage is measured through an 1:3 voltage divider and
|
* Battery voltage is measured through an 1:3 voltage divider and
|
||||||
* adc1_getMeasurement returns a value in mV. Thus, to have effective
|
* adc1_getMeasurement returns a value in uV.
|
||||||
* battery voltage, multiply by three.
|
|
||||||
*/
|
*/
|
||||||
return adc1_getMeasurement(ADC_VBAT_CH) * 3;
|
uint32_t vbat = adc_getVoltage(&adc1, ADC_VBAT_CH) * 3;
|
||||||
|
return vbat / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t platform_getMicLevel()
|
uint8_t platform_getMicLevel()
|
||||||
{
|
{
|
||||||
/* Value from ADC is 12 bit wide: shift right by four to get 0 - 255 */
|
/* 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()
|
uint8_t platform_getVolumeLevel()
|
||||||
|
|
@ -110,7 +105,7 @@ uint8_t platform_getVolumeLevel()
|
||||||
* lines with a breakpoint around 270mV.
|
* lines with a breakpoint around 270mV.
|
||||||
* Output value has range 0 - 255 with breakpoint at 150.
|
* 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;
|
uint32_t output;
|
||||||
|
|
||||||
if(value < 20)
|
if(value < 20)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue