fix(flysky gimbals): mask first 4 channels when FS gimbals are detected (#3778)

* fix(flysky gimbals): mask first 4 channels when FS gimbals are detected.
* re-adjust center value to 4096 (2^12).This prevents values higher than necessary being displayed.
This commit is contained in:
Raphael Coeffic
2023-07-17 17:53:32 +02:00
committed by GitHub
parent 8325f722c4
commit 179c677427
13 changed files with 78 additions and 24 deletions
@@ -44,6 +44,7 @@ set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
../common/arm/stm32/stm32_switch_driver.cpp
../common/arm/stm32/stm32_adc.cpp
../common/arm/stm32/stm32_timer.cpp
../common/arm/stm32/stm32_dma.cpp
../common/arm/stm32/stm32_gpio_driver.cpp
../common/arm/stm32/mixer_scheduler_driver.cpp
)
@@ -69,8 +70,8 @@ if(AUX_SERIAL OR AUX2_SERIAL)
endif()
if(FLYSKY_GIMBAL)
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
../common/arm/stm32/flysky_gimbal_driver.cpp
set(FIRMWARE_SRC ${FIRMWARE_SRC}
targets/common/arm/stm32/flysky_gimbal_driver.cpp
)
add_definitions(-DFLYSKY_GIMBAL)
endif()
@@ -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"
@@ -168,6 +170,8 @@ 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;
}
}
@@ -23,7 +23,13 @@
#define FLYSKY_HALL_BAUDRATE ( 921600 )
#define FLYSKY_HALL_CHANNEL_COUNT ( 4 )
#define FLYSKY_OFFSET_VALUE ( 16384 )
// This value has been chosen arbitrarily to allow
// for 13-bit precision.
//
// Note: Flysky gimbals provide signed 16-bit values, whereby
// ADC sampling uses unsigned 16-bit values.
//
#define FLYSKY_OFFSET_VALUE ( 1 << 12 )
#define FLYSKY_HALL_PROTOLO_HEAD 0x55
#define FLYSKY_HALL_RESP_TYPE_VALUES 0x0c
@@ -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
@@ -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)
@@ -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)) {
@@ -65,3 +65,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,0 +1,31 @@
/*
* Copyright (C) EdgeTx
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "stm32_dma.h"
void stm32_dma_enable_clock(DMA_TypeDef* DMAx)
{
if (DMAx == DMA1) {
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
} else if (DMAx == DMA2) {
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA2);
}
}
@@ -47,3 +47,5 @@ inline static bool stm32_dma_check_tc_flag(DMA_TypeDef* DMAx, uint32_t DMA_Strea
return true;
}
void stm32_dma_enable_clock(DMA_TypeDef* DMAx);
@@ -20,6 +20,7 @@
*/
#include "stm32_usart_driver.h"
#include "stm32_gpio_driver.h"
#include "stm32_dma.h"
#include <string.h>
@@ -178,6 +179,7 @@ void stm32_usart_init_rx_dma(const stm32_usart_t* usart, const void* buffer, uin
NVIC_DisableIRQ(usart->IRQn);
}
stm32_dma_enable_clock(usart->rxDMA);
LL_DMA_DeInit(usart->rxDMA, usart->rxDMA_Stream);
LL_DMA_InitTypeDef dmaInit;
@@ -224,7 +226,6 @@ void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
enable_usart_clock(usart->USARTx);
LL_USART_DeInit(usart->USARTx);
// TODO: enable GPIO clock
LL_GPIO_InitTypeDef pinInit;
LL_GPIO_StructInit(&pinInit);
@@ -234,6 +235,8 @@ void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
pinInit.Pull = LL_GPIO_PULL_UP;
pinInit.Alternate = _get_usart_af(usart->USARTx);
stm32_gpio_enable_clock(usart->GPIOx);
LL_GPIO_Init(usart->GPIOx, &pinInit);
LL_USART_InitTypeDef usartInit;
@@ -344,6 +347,7 @@ void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, u
_half_duplex_output(usart);
if (usart->txDMA) {
stm32_dma_enable_clock(usart->txDMA);
LL_DMA_DeInit(usart->txDMA, usart->txDMA_Stream);
LL_DMA_InitTypeDef dmaInit;