From ce01091eeaabcc7ebdf2683be20f7109ead019b2 Mon Sep 17 00:00:00 2001 From: 3djc Date: Sun, 18 Aug 2024 03:52:21 +0200 Subject: [PATCH] feat: indicate in analog debug if serial gimbals are used (#5442) --- radio/src/boards/generic_stm32/analog_inputs.cpp | 12 +++++++----- radio/src/gui/128x64/radio_diaganas.cpp | 8 +++++++- radio/src/gui/212x64/radio_diaganas.cpp | 8 +++++++- radio/src/gui/colorlcd/radio/radio_diaganas.cpp | 5 ++++- radio/src/hal/adc_driver.cpp | 14 ++++++++++++++ radio/src/hal/adc_driver.h | 6 ++++++ .../common/arm/stm32/flysky_gimbal_driver.cpp | 2 +- radio/src/targets/common/arm/stm32/stm32_adc.cpp | 7 ++++++- radio/src/targets/common/arm/stm32/stm32_adc.h | 3 ++- .../STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h | 2 ++ 10 files changed, 56 insertions(+), 11 deletions(-) diff --git a/radio/src/boards/generic_stm32/analog_inputs.cpp b/radio/src/boards/generic_stm32/analog_inputs.cpp index e7c3cb74ef7..2c0c5053c4f 100644 --- a/radio/src/boards/generic_stm32/analog_inputs.cpp +++ b/radio/src/boards/generic_stm32/analog_inputs.cpp @@ -81,11 +81,13 @@ static void adc_wait_completion() } const etx_hal_adc_driver_t _adc_driver = { - _hal_inputs, - _pot_default_config, - adc_init, - adc_start_read, - adc_wait_completion + .inputs = _hal_inputs, + .default_pots_cfg = _pot_default_config, + .init = adc_init, + .start_conversion = adc_start_read, + .wait_completion = adc_wait_completion, + .set_input_mask = stm32_hal_set_inputs_mask, + .get_input_mask = stm32_hal_get_inputs_mask, }; #if defined(PWM_STICKS) diff --git a/radio/src/gui/128x64/radio_diaganas.cpp b/radio/src/gui/128x64/radio_diaganas.cpp index 893ae86b97d..5f3c5af245b 100644 --- a/radio/src/gui/128x64/radio_diaganas.cpp +++ b/radio/src/gui/128x64/radio_diaganas.cpp @@ -86,7 +86,13 @@ void menuRadioDiagAnalogs(event_t event) x = INDENT_WIDTH; y += FH; } - drawStringWithIndex(x, y, "A", i + 1); + if (((adcGetInputMask() & (1 << i)) != 0) && i < adcGetMaxInputs(ADC_INPUT_MAIN)) { + lcdDrawText(x, y, "D"); + lcdDrawNumber(lcdNextPos, y, i + 1); + } + else { + lcdDrawNumber(x, y, i+1, LEADING0|LEFT, 2); + } lcdDrawChar(lcdNextPos, y, ':'); switch (viewpage) { case (ANAVIEW_RAWLOWFPS): diff --git a/radio/src/gui/212x64/radio_diaganas.cpp b/radio/src/gui/212x64/radio_diaganas.cpp index d469926b06a..ee0f48cea06 100644 --- a/radio/src/gui/212x64/radio_diaganas.cpp +++ b/radio/src/gui/212x64/radio_diaganas.cpp @@ -56,7 +56,13 @@ void menuRadioDiagAnalogs(event_t event) for (uint8_t i = 0; i < MAX_ANALOG_INPUTS; i++) { coord_t y = MENU_HEADER_HEIGHT + 1 + (i/2)*FH; uint8_t x = i&1 ? LCD_W/2 + FW : 0; - lcdDrawNumber(x, y, i+1, LEADING0|LEFT, 2); + if (((adcGetInputMask() & (1 << i)) != 0) && i < adcGetMaxInputs(ADC_INPUT_MAIN)) { + lcdDrawText(x, y, "D"); + lcdDrawNumber(lcdNextPos, y, i + 1); + } + else { + lcdDrawNumber(x, y, i + 1, LEADING0 | LEFT, 2); + } lcdDrawChar(x+2*FW-2, y, ':'); switch (viewpage) diff --git a/radio/src/gui/colorlcd/radio/radio_diaganas.cpp b/radio/src/gui/colorlcd/radio/radio_diaganas.cpp index ed192e54ccd..35033614951 100644 --- a/radio/src/gui/colorlcd/radio/radio_diaganas.cpp +++ b/radio/src/gui/colorlcd/radio/radio_diaganas.cpp @@ -84,8 +84,11 @@ class AnaViewWindow : public Window #endif lv_obj_set_style_pad_column(line->getLvObj(), 8, 0); + if (((adcGetInputMask() & (1 << i)) != 0) && i < adcGetMaxInputs(ADC_INPUT_MAIN)) + sprintf(s, "D%d :", i + 1); + else + sprintf(s, "%02d :", i + 1); - sprintf(s, "%02d :", i + 1); new StaticText(line, rect_t{}, s); auto lbl = new DynamicText( diff --git a/radio/src/hal/adc_driver.cpp b/radio/src/hal/adc_driver.cpp index cc1a1ac3bfb..46b7c5263bd 100644 --- a/radio/src/hal/adc_driver.cpp +++ b/radio/src/hal/adc_driver.cpp @@ -579,3 +579,17 @@ const char* adcGetInputShortLabel(uint8_t type, uint8_t idx) return _hal_adc_inputs[type].inputs[idx].short_label; } + +void adcSetInputMask(uint32_t mask) +{ + if (_hal_adc_driver && _hal_adc_driver->set_input_mask) { + _hal_adc_driver->set_input_mask(mask); + } +} + +uint32_t adcGetInputMask() +{ + return _hal_adc_driver && _hal_adc_driver->get_input_mask + ? _hal_adc_driver->get_input_mask() + : 0; +} diff --git a/radio/src/hal/adc_driver.h b/radio/src/hal/adc_driver.h index 0c6f70f0980..0fed7765bf8 100644 --- a/radio/src/hal/adc_driver.h +++ b/radio/src/hal/adc_driver.h @@ -77,6 +77,9 @@ struct etx_hal_adc_driver_t { bool (*init)(); bool (*start_conversion)(); void (*wait_completion)(); + + void (*set_input_mask)(uint32_t); + uint32_t (*get_input_mask)(); }; bool adcInit(const etx_hal_adc_driver_t* driver); @@ -137,6 +140,9 @@ int adcGetInputIdx(const char* input, uint8_t len); const char* adcGetInputLabel(uint8_t type, uint8_t idx); const char* adcGetInputShortLabel(uint8_t type, uint8_t idx); +void adcSetInputMask(uint32_t mask); +uint32_t adcGetInputMask(); + // To be implemented by the target driver // int8_t adcGetVRTC(); // int8_t adcGetVBAT(); diff --git a/radio/src/targets/common/arm/stm32/flysky_gimbal_driver.cpp b/radio/src/targets/common/arm/stm32/flysky_gimbal_driver.cpp index bc4eca4e28a..f03dcb886a0 100644 --- a/radio/src/targets/common/arm/stm32/flysky_gimbal_driver.cpp +++ b/radio/src/targets/common/arm/stm32/flysky_gimbal_driver.cpp @@ -173,7 +173,7 @@ bool flysky_gimbal_init() delay_ms(1); if (_fs_gimbal_detected) { // Mask the first 4 inputs (sticks) - stm32_hal_mask_inputs(0xF); + stm32_hal_set_inputs_mask(0xF); return true; } } diff --git a/radio/src/targets/common/arm/stm32/stm32_adc.cpp b/radio/src/targets/common/arm/stm32/stm32_adc.cpp index 3cd623bcb76..3931665b2fe 100644 --- a/radio/src/targets/common/arm/stm32/stm32_adc.cpp +++ b/radio/src/targets/common/arm/stm32/stm32_adc.cpp @@ -77,11 +77,16 @@ static uint8_t _adc_run; static uint8_t _adc_oversampling_disabled; static uint16_t _adc_oversampling[MAX_ADC_INPUTS]; -void stm32_hal_mask_inputs(uint32_t inputs) +void stm32_hal_set_inputs_mask(uint32_t inputs) { _adc_input_inhibt_mask |= inputs; } +uint32_t stm32_hal_get_inputs_mask() +{ + return _adc_input_inhibt_mask; +} + // STM32 uses a 25K+25K voltage divider bridge to measure the battery voltage // Measuring VBAT puts considerable drain (22 µA) on the battery instead of // normal drain (~10 nA) diff --git a/radio/src/targets/common/arm/stm32/stm32_adc.h b/radio/src/targets/common/arm/stm32/stm32_adc.h index 97ee324e1dc..9812a1526b0 100644 --- a/radio/src/targets/common/arm/stm32/stm32_adc.h +++ b/radio/src/targets/common/arm/stm32/stm32_adc.h @@ -67,4 +67,5 @@ void stm32_hal_adc_disable_oversampling(); void stm32_hal_adc_dma_isr(const stm32_adc_t* adc); void stm32_hal_adc_isr(const stm32_adc_t* adc); -void stm32_hal_mask_inputs(uint32_t inputs); +void stm32_hal_set_inputs_mask(uint32_t inputs); +uint32_t stm32_hal_get_inputs_mask(); diff --git a/radio/src/thirdparty/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h b/radio/src/thirdparty/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h index 975f70bd4b2..bdee082e019 100644 --- a/radio/src/thirdparty/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h +++ b/radio/src/thirdparty/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h @@ -55,7 +55,9 @@ typedef enum /* Exported macro ------------------------------------------------------------*/ +#if !defined(UNUSED) #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ +#endif #define HAL_MAX_DELAY 0xFFFFFFFFU