From 9216570d6c782b983e1d2671af4d381eb79a20b2 Mon Sep 17 00:00:00 2001 From: richardclli Date: Sun, 26 Feb 2023 20:27:37 +0800 Subject: [PATCH] feat: Flysky gimbal support for RM Boxer (#3139) * Adds Flysky digital hall gimbal support for RadioMaster Boxer. --------- Co-authored-by: rotorman --- radio/src/gui/128x64/radio_calibration.cpp | 41 +++++++++++++------ radio/src/gui/128x64/radio_diaganas.cpp | 16 +++++++- radio/src/gui/colorlcd/hw_inputs.cpp | 2 +- radio/src/gui/colorlcd/radio_diaganas.cpp | 8 ++-- radio/src/hal/adc_driver.cpp | 6 +-- radio/src/hal/adc_driver.h | 4 ++ .../targets/common/arm/stm32/CMakeLists.txt | 7 ++++ .../common/arm/stm32/stm32_hal_adc.cpp | 28 ++++++++----- radio/src/targets/horus/CMakeLists.txt | 8 ++-- radio/src/targets/horus/board.cpp | 8 ++-- radio/src/targets/nv14/CMakeLists.txt | 2 +- radio/src/targets/taranis/CMakeLists.txt | 1 + radio/src/targets/taranis/board.cpp | 16 ++++++++ radio/src/targets/taranis/hal.h | 20 +++++++++ 14 files changed, 125 insertions(+), 42 deletions(-) diff --git a/radio/src/gui/128x64/radio_calibration.cpp b/radio/src/gui/128x64/radio_calibration.cpp index a780f4d78..b813f5339 100644 --- a/radio/src/gui/128x64/radio_calibration.cpp +++ b/radio/src/gui/128x64/radio_calibration.cpp @@ -27,7 +27,7 @@ void menuCommonCalib(event_t event) { - for (uint8_t i=0; i> 1; - if (reusableBuffer.calib.xpotsCalib[idx].lastCount == 0 || vt < reusableBuffer.calib.xpotsCalib[idx].lastPosition - XPOT_DELTA || vt > reusableBuffer.calib.xpotsCalib[idx].lastPosition + XPOT_DELTA) { + if (reusableBuffer.calib.xpotsCalib[idx].lastCount == 0 || + vt < reusableBuffer.calib.xpotsCalib[idx].lastPosition - XPOT_DELTA || + vt > reusableBuffer.calib.xpotsCalib[idx].lastPosition + XPOT_DELTA) { reusableBuffer.calib.xpotsCalib[idx].lastPosition = vt; reusableBuffer.calib.xpotsCalib[idx].lastCount = 1; } else { - if (reusableBuffer.calib.xpotsCalib[idx].lastCount < 255) reusableBuffer.calib.xpotsCalib[idx].lastCount++; + if (reusableBuffer.calib.xpotsCalib[idx].lastCount < 255) + reusableBuffer.calib.xpotsCalib[idx].lastCount++; } if (reusableBuffer.calib.xpotsCalib[idx].lastCount == XPOT_DELAY) { int16_t position = reusableBuffer.calib.xpotsCalib[idx].lastPosition; @@ -99,7 +102,16 @@ void menuCommonCalib(event_t event) reusableBuffer.calib.loVals[i] = 15000; reusableBuffer.calib.hiVals[i] = -15000; #if defined(PCBTARANIS) - reusableBuffer.calib.midVals[i] = getAnalogValue(i) >> 1; + #if defined(FLYSKY_GIMBAL) + if (globalData.flyskygimbals && (i < FIRST_ANALOG_ADC_FS) ) + { + reusableBuffer.calib.midVals[i] = anaIn(i); + } + else + #endif + { + reusableBuffer.calib.midVals[i] = getAnalogValue(i) >> 1; + } if (isteps[j] = (reusableBuffer.calib.xpotsCalib[idx].steps[j+1] + reusableBuffer.calib.xpotsCalib[idx].steps[j]) >> 5; } } - else { + } + } +#endif + break; + + case CALIB_STORE: #if defined(RADIO_BOXER) - // load 6pos calib with factory data if 6 pos was not manually calibrated + for (uint8_t i=POT1; i<=POT_LAST; i++) { + int idx = i - POT1; + if (IS_POT_MULTIPOS(i)) { + int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount; + if (count < XPOTS_MULTIPOS_COUNT) + { + // load 6-pos calib with factory data if 6-pos was not manually calibrated constexpr int16_t factoryValues[]= {0x5,0xd,0x16,0x1f,0x28}; StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[POT3]; calib->count = 5; for (int j=0; jcount ; j++) { calib->steps[j] = factoryValues[j]; } -#else - g_eeGeneral.potsConfig &= ~(0x03<<(2*idx)); -#endif } } } diff --git a/radio/src/gui/128x64/radio_diaganas.cpp b/radio/src/gui/128x64/radio_diaganas.cpp index 5ce3afc46..00ef9f708 100644 --- a/radio/src/gui/128x64/radio_diaganas.cpp +++ b/radio/src/gui/128x64/radio_diaganas.cpp @@ -22,12 +22,16 @@ #include "opentx.h" #include "../../hal/adc_driver.h" +#if defined(FLYSKY_GIMBAL) + #include "flysky_gimbal_driver.h" +#endif + #define HOLDANAVALUEFRAMES 4 /* 4* 50ms = 200 ms update rate */ void menuRadioDiagAnalogs(event_t event) { static int8_t entryCount = 0; - static uint16_t lastShownAnalogValue[NUM_STICKS+NUM_POTS+NUM_SLIDERS]; + static int16_t lastShownAnalogValue[NUM_STICKS+NUM_POTS+NUM_SLIDERS]; enum ANAVIEWS{ ANAVIEW_FIRST, @@ -106,7 +110,15 @@ void menuRadioDiagAnalogs(event_t event) switch (viewpage) { case (ANAVIEW_RAWLOWFPS): if (entryCount == 0) { - lastShownAnalogValue[i] = getAnalogValue(i); // Update value +#if defined(FLYSKY_GIMBAL) + if (globalData.flyskygimbals && i < FIRST_ANALOG_ADC_FS) + { + lastShownAnalogValue[i] = hall_raw_values[i]; + } else +#endif + { + lastShownAnalogValue[i] = getAnalogValue(i); // Update value + } } lcdDrawNumber(x+3*FW-1, y, lastShownAnalogValue[i], LEADING0|LEFT, 4); diff --git a/radio/src/gui/colorlcd/hw_inputs.cpp b/radio/src/gui/colorlcd/hw_inputs.cpp index db6f43eb8..d2754b5d6 100644 --- a/radio/src/gui/colorlcd/hw_inputs.cpp +++ b/radio/src/gui/colorlcd/hw_inputs.cpp @@ -66,7 +66,7 @@ HWPots::HWPots(Window* parent) : FormGroup(parent, rect_t{}) for (int i = 0; i < NUM_POTS; i++) { // Display EX3 & EX4 (= last two pots) only when FlySky gimbals are present -#if !defined(SIMU) && defined(RADIO_FAMILY_T16) +#if !defined(SIMU) && defined(FLYSKY_GIMBAL) if (!globalData.flyskygimbals && (i >= (NUM_POTS - 2))) continue; #endif auto line = newLine(&grid); diff --git a/radio/src/gui/colorlcd/radio_diaganas.cpp b/radio/src/gui/colorlcd/radio_diaganas.cpp index 824c8df5c..1f7a16e4d 100644 --- a/radio/src/gui/colorlcd/radio_diaganas.cpp +++ b/radio/src/gui/colorlcd/radio_diaganas.cpp @@ -64,7 +64,7 @@ class AnaCalibratedViewWindow: public Window { void paint(BitmapBuffer * dc) override { -#if !defined(SIMU) && (defined(RADIO_FAMILY_T16) || defined(PCBNV14)) +#if !defined(SIMU) && defined(FLYSKY_GIMBAL) if (globalData.flyskygimbals) { for (uint8_t i = 0; i < FLYSKY_HALL_CHANNEL_COUNT; i++) { @@ -258,7 +258,7 @@ class AnaFilteredDevViewWindow: public Window { ClearStats = false; } -#if !defined(SIMU) && (defined(RADIO_FAMILY_T16) || defined(PCBNV14)) +#if !defined(SIMU) && defined(FLYSKY_GIMBAL) if (globalData.flyskygimbals) { for (uint8_t i = 0; i < FLYSKY_HALL_CHANNEL_COUNT; i++) { @@ -337,7 +337,7 @@ class AnaUnfilteredRawViewWindow: public Window { void paint(BitmapBuffer * dc) override { -#if !defined(SIMU) && (defined(RADIO_FAMILY_T16) || defined(PCBNV14)) +#if !defined(SIMU) && defined(FLYSKY_GIMBAL) if (globalData.flyskygimbals) { for (uint8_t i = 0; i < FLYSKY_HALL_CHANNEL_COUNT; i++) { @@ -460,7 +460,7 @@ class AnaMinMaxViewWindow: public Window { } dc->drawText(10, 1, STR_ANADIAGS_MOVE, COLOR_THEME_PRIMARY1); -#if !defined(SIMU) && (defined(RADIO_FAMILY_T16) || defined(PCBNV14)) +#if !defined(SIMU) && defined(FLYSKY_GIMBAL) if (globalData.flyskygimbals) { for (uint8_t i = 0; i < FLYSKY_HALL_CHANNEL_COUNT; i++) { diff --git a/radio/src/hal/adc_driver.cpp b/radio/src/hal/adc_driver.cpp index 1ad4489d6..33bb58a0e 100644 --- a/radio/src/hal/adc_driver.cpp +++ b/radio/src/hal/adc_driver.cpp @@ -134,7 +134,8 @@ bool adcRead() uint16_t temp[NUM_ANALOGS] = { 0 }; uint8_t first_analog_adc; -#if defined(RADIO_FAMILY_T16) || defined(PCBNV14) + +#if defined(FLYSKY_GIMBAL) if (globalData.flyskygimbals) { first_analog_adc = FIRST_ANALOG_ADC_FS; @@ -146,7 +147,6 @@ bool adcRead() first_analog_adc = FIRST_ANALOG_ADC; #endif - for (int i=0; i<4; i++) { if (!adcSingleRead()) return false; @@ -267,7 +267,7 @@ void getADC() for (uint8_t x=0; x