Skip to content

Commit

Permalink
fix(flysky gimbals): mask first 4 channels when FS gimbals are detected
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Jul 8, 2023
1 parent 43db9c8 commit 09aada7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions radio/src/targets/common/arm/stm32/flysky_gimbal_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "flysky_gimbal_driver.h"
#include "stm32_serial_driver.h"
#include "stm32_adc.h"

#include "delays_driver.h"
#include "hal/adc_driver.h"

Expand Down Expand Up @@ -168,10 +170,10 @@ bool flysky_gimbal_init()
for (uint8_t i = 0; i < 70; i++) {
delay_ms(1);
if (_fs_gimbal_detected) {
// Mask the first 4 inputs (sticks)
stm32_hal_mask_inputs(0xF);
return true;
}
}

flysky_gimbal_deinit();
return false;
}
12 changes: 12 additions & 0 deletions radio/src/targets/common/arm/stm32/stm32_adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

// Max 32 inputs supported
static uint32_t _adc_input_mask;
static uint32_t _adc_input_inhibt_mask = 0;
static volatile uint32_t _adc_inhibit_mask;

// DMA buffers
Expand All @@ -52,6 +53,11 @@ 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)
{
_adc_input_inhibt_mask |= inputs;
}

// 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 Expand Up @@ -212,6 +218,12 @@ static uint8_t adc_init_channels(const stm32_adc_t* adc,
uint8_t input_idx = *chan;
const stm32_adc_input_t* input = &inputs[input_idx];

if (_adc_input_inhibt_mask & (1 << input_idx)) {
// skip input
nconv--; chan++;
continue;
}

// internal channel don't have a GPIO + pin defined
uint32_t mask = (1 << (ADC_CHANNEL_ID_MASK & input->ADC_Channel));
if (!__LL_ADC_IS_CHANNEL_INTERNAL(input->ADC_Channel)) {
Expand Down
2 changes: 2 additions & 0 deletions radio/src/targets/common/arm/stm32/stm32_adc.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,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);

0 comments on commit 09aada7

Please sign in to comment.