X12S fixes (not tested)
This commit is contained in:
@@ -76,13 +76,15 @@ const etx_hal_adc_driver_t* etx_hal_adc_driver = nullptr;
|
|||||||
0 /*TX_VOLTAGE*/, 0 /*TX_VBAT*/,
|
0 /*TX_VOLTAGE*/, 0 /*TX_VBAT*/,
|
||||||
0 /*SWB*/, 0 /*SWD*/};
|
0 /*SWB*/, 0 /*SWD*/};
|
||||||
|
|
||||||
|
#elif defined(PCBX12S)
|
||||||
|
const int8_t adcDirection[NUM_ANALOGS] = {1,-1,1,-1, -1,1,-1, -1,-1, -1,1, 0,0,0};
|
||||||
#else
|
#else
|
||||||
#error "ADC driver does not suppport this target"
|
#error "ADC driver does not suppport this target"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint16_t adcValues[NUM_ANALOGS] __DMA;
|
uint16_t adcValues[NUM_ANALOGS] __DMA;
|
||||||
|
|
||||||
#if defined(PCBX10)
|
#if defined(PCBX10) || defined(PCBX12S)
|
||||||
uint16_t rtcBatteryVoltage;
|
uint16_t rtcBatteryVoltage;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -117,7 +119,9 @@ static bool adcSingleRead()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool adcRead() __attribute__((weak))
|
// Declare adcRead() weak so it can be re-declared
|
||||||
|
#pragma weak adcRead
|
||||||
|
bool adcRead()
|
||||||
{
|
{
|
||||||
uint16_t temp[NUM_ANALOGS] = { 0 };
|
uint16_t temp[NUM_ANALOGS] = { 0 };
|
||||||
|
|
||||||
@@ -151,7 +155,7 @@ uint16_t getRTCBatteryVoltage()
|
|||||||
{
|
{
|
||||||
#if defined(HAS_TX_RTC_VOLTAGE)
|
#if defined(HAS_TX_RTC_VOLTAGE)
|
||||||
return (getAnalogValue(TX_RTC_VOLTAGE) * ADC_VREF_PREC2) / 2048;
|
return (getAnalogValue(TX_RTC_VOLTAGE) * ADC_VREF_PREC2) / 2048;
|
||||||
#elif defined(PCBX10)
|
#elif defined(PCBX10) || defined(PCBX12S)
|
||||||
return (rtcBatteryVoltage * 2 * ADC_VREF_PREC2) / 2048;
|
return (rtcBatteryVoltage * 2 * ADC_VREF_PREC2) / 2048;
|
||||||
#elif defined(PCBNV14)
|
#elif defined(PCBNV14)
|
||||||
#warning "TODO RTC voltage"
|
#warning "TODO RTC voltage"
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: get rid of this special case
|
// TODO: get rid of this special case
|
||||||
#if defined(PCBX10)
|
#if defined(PCBX10) || defined(PCBX12S)
|
||||||
extern uint16_t rtcBatteryVoltage;
|
extern uint16_t rtcBatteryVoltage;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -54,8 +54,6 @@ struct etx_hal_adc_driver_t {
|
|||||||
bool adcInit(const etx_hal_adc_driver_t* driver);
|
bool adcInit(const etx_hal_adc_driver_t* driver);
|
||||||
// void adcDeInit();
|
// void adcDeInit();
|
||||||
|
|
||||||
// Declare adcRead() weak so it can be re-declared
|
bool adcRead();
|
||||||
bool adcRead() __attribute__((weak));
|
|
||||||
|
|
||||||
uint16_t getRTCBatteryVoltage();
|
uint16_t getRTCBatteryVoltage();
|
||||||
uint16_t getAnalogValue(uint8_t index);
|
uint16_t getAnalogValue(uint8_t index);
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ elseif (PCB STREQUAL X12S)
|
|||||||
)
|
)
|
||||||
set(FIRMWARE_TARGET_SRC
|
set(FIRMWARE_TARGET_SRC
|
||||||
${FIRMWARE_TARGET_SRC}
|
${FIRMWARE_TARGET_SRC}
|
||||||
|
../../hal/adc_driver.cpp
|
||||||
x12s_adc_driver.cpp
|
x12s_adc_driver.cpp
|
||||||
)
|
)
|
||||||
set(BITMAPS_TARGET x12s_bitmaps)
|
set(BITMAPS_TARGET x12s_bitmaps)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include "../common/arm/stm32/stm32_hal_adc.h"
|
#include "../common/arm/stm32/stm32_hal_adc.h"
|
||||||
#define ADC_DRIVER stm32_hal_adc_driver
|
#define ADC_DRIVER stm32_hal_adc_driver
|
||||||
#else
|
#else
|
||||||
#include "x12_adc_driver.h"
|
#include "x12s_adc_driver.h"
|
||||||
#define ADC_DRIVER x12s_adc_driver
|
#define ADC_DRIVER x12s_adc_driver
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
#include "x12s_adc_driver.h"
|
||||||
|
|
||||||
uint16_t adcValues[NUM_ANALOGS] __DMA;
|
|
||||||
uint16_t rtcBatteryVoltage;
|
|
||||||
|
|
||||||
#define ADC_CS_HIGH() (ADC_SPI_GPIO->BSRRL = ADC_SPI_PIN_CS)
|
#define ADC_CS_HIGH() (ADC_SPI_GPIO->BSRRL = ADC_SPI_PIN_CS)
|
||||||
#define ADC_CS_LOW() (ADC_SPI_GPIO->BSRRH = ADC_SPI_PIN_CS)
|
#define ADC_CS_LOW() (ADC_SPI_GPIO->BSRRH = ADC_SPI_PIN_CS)
|
||||||
@@ -137,11 +136,8 @@ static bool x12s_adc_init()
|
|||||||
ADC1->SQR3 = (ADC_Channel_Vbat << 0);
|
ADC1->SQR3 = (ADC_Channel_Vbat << 0);
|
||||||
ADC1->SMPR1 = (ADC_SAMPTIME << 0) + (ADC_SAMPTIME << 3) + (ADC_SAMPTIME << 6) + (ADC_SAMPTIME << 9) + (ADC_SAMPTIME << 12) + (ADC_SAMPTIME << 15) + (ADC_SAMPTIME << 18) + (ADC_SAMPTIME << 21) + (ADC_SAMPTIME << 24);
|
ADC1->SMPR1 = (ADC_SAMPTIME << 0) + (ADC_SAMPTIME << 3) + (ADC_SAMPTIME << 6) + (ADC_SAMPTIME << 9) + (ADC_SAMPTIME << 12) + (ADC_SAMPTIME << 15) + (ADC_SAMPTIME << 18) + (ADC_SAMPTIME << 21) + (ADC_SAMPTIME << 24);
|
||||||
ADC1->SMPR2 = (ADC_SAMPTIME << 0) + (ADC_SAMPTIME << 3) + (ADC_SAMPTIME << 6) + (ADC_SAMPTIME << 9) + (ADC_SAMPTIME << 12) + (ADC_SAMPTIME << 15) + (ADC_SAMPTIME << 18) + (ADC_SAMPTIME << 21) + (ADC_SAMPTIME << 24) + (ADC_SAMPTIME << 27);
|
ADC1->SMPR2 = (ADC_SAMPTIME << 0) + (ADC_SAMPTIME << 3) + (ADC_SAMPTIME << 6) + (ADC_SAMPTIME << 9) + (ADC_SAMPTIME << 12) + (ADC_SAMPTIME << 15) + (ADC_SAMPTIME << 18) + (ADC_SAMPTIME << 21) + (ADC_SAMPTIME << 24) + (ADC_SAMPTIME << 27);
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getRTCBatteryVoltage()
|
return true;
|
||||||
{
|
|
||||||
return (rtcBatteryVoltage * 2 * ADC_VREF_PREC2) / 2048;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint16_t adcCommands[MOUSE1+2] =
|
const uint16_t adcCommands[MOUSE1+2] =
|
||||||
@@ -229,7 +225,7 @@ bool adcOnChipReadFinished()
|
|||||||
|
|
||||||
// Re-declare adcRead()
|
// Re-declare adcRead()
|
||||||
// (takes precedence over hal/adc_driver.cpp)
|
// (takes precedence over hal/adc_driver.cpp)
|
||||||
void adcRead()
|
bool adcRead()
|
||||||
{
|
{
|
||||||
uint16_t temp[NUM_ANALOGS-MOUSE1] = { 0 };
|
uint16_t temp[NUM_ANALOGS-MOUSE1] = { 0 };
|
||||||
uint8_t noInternalReads = 0;
|
uint8_t noInternalReads = 0;
|
||||||
@@ -268,19 +264,9 @@ void adcRead()
|
|||||||
if (isVBatBridgeEnabled()) {
|
if (isVBatBridgeEnabled()) {
|
||||||
rtcBatteryVoltage = ADC1->DR;
|
rtcBatteryVoltage = ADC1->DR;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#if !defined(SIMU)
|
return true;
|
||||||
const int8_t ana_direction[NUM_ANALOGS] = {1,-1,1,-1, -1,1,-1, -1,-1, -1,1, 0,0,0};
|
|
||||||
|
|
||||||
uint16_t getAnalogValue(uint8_t index)
|
|
||||||
{
|
|
||||||
if (ana_direction[index] < 0)
|
|
||||||
return 4095 - adcValues[index];
|
|
||||||
else
|
|
||||||
return adcValues[index];
|
|
||||||
}
|
}
|
||||||
#endif // #if !defined(SIMU)
|
|
||||||
|
|
||||||
//TODO: implement these based on stm32_hal_adc.cpp
|
//TODO: implement these based on stm32_hal_adc.cpp
|
||||||
//static bool x12s_adc_init();
|
//static bool x12s_adc_init();
|
||||||
|
|||||||
Reference in New Issue
Block a user