Skip to content

Commit

Permalink
feat: indicate in analog debug if serial gimbals are used (#5442)
Browse files Browse the repository at this point in the history
  • Loading branch information
3djc authored Aug 18, 2024
1 parent 2cf8878 commit ce01091
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 11 deletions.
12 changes: 7 additions & 5 deletions radio/src/boards/generic_stm32/analog_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion radio/src/gui/128x64/radio_diaganas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 7 additions & 1 deletion radio/src/gui/212x64/radio_diaganas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion radio/src/gui/colorlcd/radio/radio_diaganas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions radio/src/hal/adc_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions radio/src/hal/adc_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
7 changes: 6 additions & 1 deletion radio/src/targets/common/arm/stm32/stm32_adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion radio/src/targets/common/arm/stm32/stm32_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ce01091

Please sign in to comment.