MD-9600: using STM32 ADC driver
This commit is contained in:
parent
10d7ded93f
commit
e1572f8eb5
|
|
@ -26,7 +26,7 @@
|
|||
#include <interfaces/delays.h>
|
||||
#include <interfaces/keyboard.h>
|
||||
#include <interfaces/platform.h>
|
||||
#include <ADC1_MDx.h>
|
||||
#include <adc_stm32.h>
|
||||
#include "hwconfig.h"
|
||||
|
||||
/**
|
||||
|
|
@ -178,8 +178,8 @@ keyboard_t kbd_getKeys()
|
|||
*/
|
||||
|
||||
/* Retrieve row/coloumn voltage measurements. */
|
||||
uint16_t row = ((uint16_t) adc1_getMeasurement(ADC_SW2_CH) + 0.5f);
|
||||
uint16_t col = ((uint16_t) adc1_getMeasurement(ADC_SW1_CH) + 0.5f);
|
||||
uint16_t row = ((uint16_t) adc_getVoltage(&adc1, ADC_SW2_CH) / 1000);
|
||||
uint16_t col = ((uint16_t) adc_getVoltage(&adc1, ADC_SW1_CH) / 1000);
|
||||
|
||||
/* Map row voltage to row index. */
|
||||
uint8_t rowIdx = 0xFF;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,11 @@
|
|||
|
||||
#include <hwconfig.h>
|
||||
#include <spi_stm32.h>
|
||||
#include <adc_stm32.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static pthread_mutex_t spi2Mutex;
|
||||
static pthread_mutex_t adcMutex;
|
||||
|
||||
SPI_STM32_DEVICE_DEFINE(spi2, SPI2, &spi2Mutex)
|
||||
ADC_STM32_DEVICE_DEFINE(adc1, ADC1, &adcMutex, 3300000)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,20 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum adcChannel
|
||||
{
|
||||
ADC_VOL_CH = 0,
|
||||
ADC_VBAT_CH = 1,
|
||||
ADC_VOX_CH = 3,
|
||||
ADC_RSSI_CH = 8,
|
||||
ADC_SW1_CH = 7,
|
||||
ADC_SW2_CH = 6,
|
||||
ADC_RSSI2_CH = 9,
|
||||
ADC_HTEMP_CH = 15
|
||||
};
|
||||
|
||||
extern const struct spiDevice spi2;
|
||||
extern const struct Adc adc1;
|
||||
|
||||
/* Device has a working real time clock */
|
||||
#define CONFIG_RTC
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <interfaces/delays.h>
|
||||
#include <hwconfig.h>
|
||||
#include <string.h>
|
||||
#include <ADC1_MDx.h>
|
||||
#include <adc_stm32.h>
|
||||
#include <calibInfo_MDx.h>
|
||||
#include <toneGenerator_MDx.h>
|
||||
#include <peripherals/rtc.h>
|
||||
|
|
@ -53,12 +53,16 @@ void platform_init()
|
|||
|
||||
gpio_setMode(PTT_SW, INPUT);
|
||||
|
||||
/*
|
||||
* Initialise ADC1, for vbat, RSSI, ...
|
||||
* Configuration of corresponding GPIOs in analog input mode is done inside
|
||||
* the driver.
|
||||
*/
|
||||
adc1_init();
|
||||
gpio_setMode(AIN_VBAT, ANALOG);
|
||||
gpio_setMode(AIN_MIC, ANALOG);
|
||||
gpio_setMode(AIN_RSSI, ANALOG);
|
||||
gpio_setMode(AIN_SW2, ANALOG);
|
||||
gpio_setMode(AIN_SW1, ANALOG);
|
||||
gpio_setMode(AIN_RSSI2, ANALOG);
|
||||
gpio_setMode(AIN_HTEMP, ANALOG);
|
||||
|
||||
/* Initialise ADC1, for vbat, RSSI, ... */
|
||||
adcStm32_init(&adc1);
|
||||
|
||||
/*
|
||||
* Initialise SPI2 for external flash and LCD
|
||||
|
|
@ -78,7 +82,7 @@ void platform_init()
|
|||
void platform_terminate()
|
||||
{
|
||||
/* Shut down all the modules */
|
||||
adc1_terminate();
|
||||
adcStm32_terminate(&adc1);
|
||||
toneGen_terminate();
|
||||
chSelector_terminate();
|
||||
audio_terminate();
|
||||
|
|
@ -98,19 +102,16 @@ uint16_t platform_getVbat()
|
|||
{
|
||||
/*
|
||||
* Battery voltage is measured through an 1:5.7 voltage divider and
|
||||
* adc1_getMeasurement returns a value in mV. To have effective battery
|
||||
* voltage we have to multiply by the ratio: with a simple trick we can do
|
||||
* it also without using floats and with a maximum error of -1mV.
|
||||
* adc1_getMeasurement returns a value in uV.
|
||||
*/
|
||||
|
||||
uint16_t vbat = adc1_getMeasurement(ADC_VBAT_CH);
|
||||
return (vbat * 6) - ((vbat * 3) / 10);
|
||||
uint32_t vbat = adc_getVoltage(&adc1, ADC_VBAT_CH) * 57;
|
||||
return vbat / 10000;
|
||||
}
|
||||
|
||||
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_VOX_CH) >> 4;
|
||||
}
|
||||
|
||||
uint8_t platform_getVolumeLevel()
|
||||
|
|
@ -120,7 +121,7 @@ uint8_t platform_getVolumeLevel()
|
|||
* converted to a value in range 0 - 255 using fixed point math: divide by
|
||||
* 1600 and then multiply by 256.
|
||||
*/
|
||||
uint16_t value = adc1_getMeasurement(ADC_VOL_CH);
|
||||
uint16_t value = adc_getVoltage(&adc1, ADC_VOL_CH) / 1000;
|
||||
if(value > 1599) value = 1599;
|
||||
uint32_t level = value << 16;
|
||||
level /= 1600;
|
||||
|
|
|
|||
Loading…
Reference in New Issue