kopia lustrzana https://github.com/OpenRTX/OpenRTX
MD-3x0: using STM32 ADC driver
rodzic
df5d6dccef
commit
81c55b5377
|
@ -156,8 +156,7 @@ openrtx_def += {'GIT_VERSION': git_version}
|
||||||
## TYT MDx family
|
## TYT MDx family
|
||||||
##
|
##
|
||||||
|
|
||||||
mdx_src = ['platform/drivers/ADC/ADC1_MDx.c',
|
mdx_src = ['platform/drivers/GPS/GPS_MDx.cpp',
|
||||||
'platform/drivers/GPS/GPS_MDx.cpp',
|
|
||||||
'platform/drivers/NVM/W25Qx.c',
|
'platform/drivers/NVM/W25Qx.c',
|
||||||
'platform/drivers/NVM/nvmem_settings_MDx.c',
|
'platform/drivers/NVM/nvmem_settings_MDx.c',
|
||||||
'platform/drivers/NVM/nvmem_MDx.c',
|
'platform/drivers/NVM/nvmem_MDx.c',
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include <peripherals/gpio.h>
|
#include <peripherals/gpio.h>
|
||||||
#include <calibInfo_MDx.h>
|
#include <calibInfo_MDx.h>
|
||||||
#include <spi_bitbang.h>
|
#include <spi_bitbang.h>
|
||||||
|
#include <adc_stm32.h>
|
||||||
#include <hwconfig.h>
|
#include <hwconfig.h>
|
||||||
#include <ADC1_MDx.h>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include "HR_C5000.h"
|
#include "HR_C5000.h"
|
||||||
|
@ -383,7 +383,7 @@ rssi_t radio_getRssi()
|
||||||
if(rxFreq < 401035000) offset_index = 0;
|
if(rxFreq < 401035000) offset_index = 0;
|
||||||
if(rxFreq > 479995000) offset_index = 8;
|
if(rxFreq > 479995000) offset_index = 8;
|
||||||
|
|
||||||
float rssi_mv = ((float) adc1_getMeasurement(ADC_RSSI_CH));
|
float rssi_mv = ((float) adc_getVoltage(&adc1, ADC_RSSI_CH)) / 1000.0f;
|
||||||
float rssi_dbm = (rssi_mv - rssi_offset[offset_index]) / rssi_gain;
|
float rssi_dbm = (rssi_mv - rssi_offset[offset_index]) / rssi_gain;
|
||||||
return static_cast< rssi_t >(rssi_dbm);
|
return static_cast< rssi_t >(rssi_dbm);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <spi_bitbang.h>
|
#include <spi_bitbang.h>
|
||||||
#include <spi_custom.h>
|
#include <spi_custom.h>
|
||||||
#include <spi_stm32.h>
|
#include <spi_stm32.h>
|
||||||
|
#include <adc_stm32.h>
|
||||||
#include <SKY72310.h>
|
#include <SKY72310.h>
|
||||||
#include <hwconfig.h>
|
#include <hwconfig.h>
|
||||||
#include <pinmap.h>
|
#include <pinmap.h>
|
||||||
|
@ -43,9 +44,12 @@ const struct spiConfig spiC5000Cfg =
|
||||||
.flags = SPI_FLAG_CPHA
|
.flags = SPI_FLAG_CPHA
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static pthread_mutex_t adc1Mutex;
|
||||||
|
|
||||||
SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL)
|
SPI_STM32_DEVICE_DEFINE(nvm_spi, SPI1, NULL)
|
||||||
SPI_BITBANG_DEVICE_DEFINE(pll_spi, spiPllCfg, NULL)
|
SPI_BITBANG_DEVICE_DEFINE(pll_spi, spiPllCfg, NULL)
|
||||||
SPI_BITBANG_DEVICE_DEFINE(c5000_spi, spiC5000Cfg, NULL)
|
SPI_BITBANG_DEVICE_DEFINE(c5000_spi, spiC5000Cfg, NULL)
|
||||||
|
ADC_STM32_DEVICE_DEFINE(adc1, ADC1, &adc1Mutex, 3300000)
|
||||||
|
|
||||||
const struct sky73210 pll =
|
const struct sky73210 pll =
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,10 +27,19 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum adcChannel
|
||||||
|
{
|
||||||
|
ADC_VOL_CH = 0,
|
||||||
|
ADC_VBAT_CH = 1,
|
||||||
|
ADC_VOX_CH = 3,
|
||||||
|
ADC_RSSI_CH = 8
|
||||||
|
};
|
||||||
|
|
||||||
extern const struct spiDevice nvm_spi;
|
extern const struct spiDevice nvm_spi;
|
||||||
extern const struct spiCustomDevice pll_spi;
|
extern const struct spiCustomDevice pll_spi;
|
||||||
extern const struct spiCustomDevice c5000_spi;
|
extern const struct spiCustomDevice c5000_spi;
|
||||||
extern const struct sky73210 pll;
|
extern const struct sky73210 pll;
|
||||||
|
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
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include <interfaces/platform.h>
|
#include <interfaces/platform.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 <toneGenerator_MDx.h>
|
#include <toneGenerator_MDx.h>
|
||||||
#include <peripherals/rtc.h>
|
#include <peripherals/rtc.h>
|
||||||
|
@ -44,17 +44,18 @@ void platform_init()
|
||||||
gpio_setMode(PTT_SW, INPUT_PULL_UP);
|
gpio_setMode(PTT_SW, INPUT_PULL_UP);
|
||||||
gpio_setMode(PTT_EXT, INPUT_PULL_UP);
|
gpio_setMode(PTT_EXT, INPUT_PULL_UP);
|
||||||
|
|
||||||
|
gpio_setMode(AIN_VBAT, ANALOG);
|
||||||
|
gpio_setMode(AIN_VOLUME, ANALOG);
|
||||||
|
gpio_setMode(AIN_MIC, ANALOG);
|
||||||
|
gpio_setMode(AIN_RSSI, ANALOG);
|
||||||
|
|
||||||
#ifndef RUNNING_TESTSUITE
|
#ifndef RUNNING_TESTSUITE
|
||||||
gpio_setMode(PWR_SW, OUTPUT);
|
gpio_setMode(PWR_SW, OUTPUT);
|
||||||
gpio_setPin(PWR_SW);
|
gpio_setPin(PWR_SW);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/* Initialise ADC1, for vbat, RSSI, ... */
|
||||||
* Initialise ADC1, for vbat, RSSI, ...
|
adcStm32_init(&adc1);
|
||||||
* 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));
|
||||||
|
|
||||||
|
@ -72,7 +73,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();
|
||||||
audio_terminate();
|
audio_terminate();
|
||||||
|
@ -85,16 +86,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_VOX_CH) >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t platform_getVolumeLevel()
|
uint8_t platform_getVolumeLevel()
|
||||||
|
@ -105,7 +106,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);
|
uint32_t value = adc_getVoltage(&adc1, ADC_VOL_CH) / 1000;
|
||||||
uint32_t output;
|
uint32_t output;
|
||||||
|
|
||||||
if(value <= 270)
|
if(value <= 270)
|
||||||
|
|
Ładowanie…
Reference in New Issue