Add FLYSKY IBUS support
This commit is contained in:
parent
bdb3b00a6d
commit
faca885c9a
25
Inc/config.h
25
Inc/config.h
|
@ -133,6 +133,21 @@
|
||||||
// #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuck or lcd) is used!
|
// #define DEBUG_SERIAL_USART3 // right sensor board cable, disable if I2C (nunchuck or lcd) is used!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef VARIANT_IBUS
|
||||||
|
// ###### CONTROL VIA RC REMOTE WITH FLYSKY IBUS PROTOCOL ######
|
||||||
|
// left sensor board cable. Channel 1: steering, Channel 2: speed.
|
||||||
|
#define CONTROL_IBUS // use IBUS as input
|
||||||
|
#define IBUS_NUM_CHANNELS 14 // total number of IBUS channels to receive, even if they are not used.
|
||||||
|
#define IBUS_LENGTH 0x20
|
||||||
|
#define IBUS_COMMAND 0x40
|
||||||
|
|
||||||
|
#define CONTROL_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used! For Arduino control check the hoverSerial.ino
|
||||||
|
#define FEEDBACK_SERIAL_USART2 // left sensor board cable, disable if ADC or PPM is used!
|
||||||
|
#undef USART2_BAUD
|
||||||
|
#define USART2_BAUD 115200
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined(FEEDBACK_SERIAL_USART2) || defined(DEBUG_SERIAL_USART2)
|
#if defined(FEEDBACK_SERIAL_USART2) || defined(DEBUG_SERIAL_USART2)
|
||||||
#define UART_DMA_CHANNEL DMA1_Channel7
|
#define UART_DMA_CHANNEL DMA1_Channel7
|
||||||
#endif
|
#endif
|
||||||
|
@ -142,10 +157,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VARIANT_PPM
|
#ifdef VARIANT_PPM
|
||||||
// ###### CONTROL VIA RC REMOTE ######
|
// ###### CONTROL VIA RC REMOTE ######
|
||||||
// left sensor board cable. Channel 1: steering, Channel 2: speed.
|
// left sensor board cable. Channel 1: steering, Channel 2: speed.
|
||||||
#define CONTROL_PPM // use PPM-Sum as input. disable CONTROL_SERIAL_USART2!
|
#define CONTROL_PPM // use PPM-Sum as input. disable CONTROL_SERIAL_USART2!
|
||||||
#define PPM_NUM_CHANNELS 6 // total number of PPM channels to receive, even if they are not used.
|
#define PPM_NUM_CHANNELS 6 // total number of PPM channels to receive, even if they are not used.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ###### CONTROL VIA TWO POTENTIOMETERS ######
|
// ###### CONTROL VIA TWO POTENTIOMETERS ######
|
||||||
|
@ -317,7 +332,7 @@
|
||||||
|
|
||||||
// ############################### VALIDATE SETTINGS ###############################
|
// ############################### VALIDATE SETTINGS ###############################
|
||||||
|
|
||||||
#if !defined(VARIANT_ADC) && !defined(VARIANT_USART3) && !defined(VARIANT_HOVERCAR) && !defined(VARIANT_TRANSPOTTER) && !defined(VARIANT_NUNCHUCK) && !defined(VARIANT_PPM)
|
#if !defined(VARIANT_ADC) && !defined(VARIANT_USART3) && !defined(VARIANT_HOVERCAR) && !defined(VARIANT_TRANSPOTTER) && !defined(VARIANT_NUNCHUCK) && !defined(VARIANT_PPM)&& !defined(VARIANT_IBUS)
|
||||||
#error Variant not defined! Please check platformio.ini or Inc/config.h for available variants.
|
#error Variant not defined! Please check platformio.ini or Inc/config.h for available variants.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
41
Src/main.c
41
Src/main.c
|
@ -106,12 +106,25 @@ static int16_t timeoutCntADC = 0; // Timeout counter for ADC Protection
|
||||||
static uint8_t timeoutFlagADC = 0; // Timeout Flag for for ADC Protection: 0 = OK, 1 = Problem detected (line disconnected or wrong ADC data)
|
static uint8_t timeoutFlagADC = 0; // Timeout Flag for for ADC Protection: 0 = OK, 1 = Problem detected (line disconnected or wrong ADC data)
|
||||||
|
|
||||||
#if defined(CONTROL_SERIAL_USART2) || defined(CONTROL_SERIAL_USART3)
|
#if defined(CONTROL_SERIAL_USART2) || defined(CONTROL_SERIAL_USART3)
|
||||||
typedef struct{
|
#ifdef CONTROL_IBUS
|
||||||
uint16_t start;
|
static uint16_t ibus_chksum;
|
||||||
int16_t steer;
|
static uint16_t ibus_captured_value[IBUS_NUM_CHANNELS];
|
||||||
int16_t speed;
|
|
||||||
uint16_t checksum;
|
typedef struct{
|
||||||
} Serialcommand;
|
uint8_t start;
|
||||||
|
uint8_t type;
|
||||||
|
uint8_t channels[IBUS_NUM_CHANNELS*2];
|
||||||
|
uint8_t checksuml;
|
||||||
|
uint8_t checksumh;
|
||||||
|
} Serialcommand;
|
||||||
|
#elif
|
||||||
|
typedef struct{
|
||||||
|
uint16_t start;
|
||||||
|
int16_t steer;
|
||||||
|
int16_t speed;
|
||||||
|
uint16_t checksum;
|
||||||
|
} Serialcommand;
|
||||||
|
#endif
|
||||||
static volatile Serialcommand command;
|
static volatile Serialcommand command;
|
||||||
static int16_t timeoutCntSerial = 0; // Timeout counter for Rx Serial command
|
static int16_t timeoutCntSerial = 0; // Timeout counter for Rx Serial command
|
||||||
#endif
|
#endif
|
||||||
|
@ -510,13 +523,29 @@ int main(void) {
|
||||||
#if defined CONTROL_SERIAL_USART2 || defined CONTROL_SERIAL_USART3
|
#if defined CONTROL_SERIAL_USART2 || defined CONTROL_SERIAL_USART3
|
||||||
|
|
||||||
// Handle received data validity, timeout and fix out-of-sync if necessary
|
// Handle received data validity, timeout and fix out-of-sync if necessary
|
||||||
|
#ifdef CONTROL_IBUS
|
||||||
|
ibus_chksum = 0xFFFF - IBUS_LENGTH - IBUS_COMMAND;
|
||||||
|
for (uint8_t i = 0; i < (IBUS_NUM_CHANNELS * 2); i ++) {
|
||||||
|
ibus_chksum -= command.channels[i];
|
||||||
|
}
|
||||||
|
if (command.start == IBUS_LENGTH && command.type == IBUS_COMMAND && ibus_chksum == ( command.checksumh << 8) + command.checksuml ) {
|
||||||
|
#elif
|
||||||
if (command.start == START_FRAME && command.checksum == (uint16_t)(command.start ^ command.steer ^ command.speed)) {
|
if (command.start == START_FRAME && command.checksum == (uint16_t)(command.start ^ command.steer ^ command.speed)) {
|
||||||
|
#endif
|
||||||
if (timeoutFlagSerial) { // Check for previous timeout flag
|
if (timeoutFlagSerial) { // Check for previous timeout flag
|
||||||
if (timeoutCntSerial-- <= 0) // Timeout de-qualification
|
if (timeoutCntSerial-- <= 0) // Timeout de-qualification
|
||||||
timeoutFlagSerial = 0; // Timeout flag cleared
|
timeoutFlagSerial = 0; // Timeout flag cleared
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef CONTROL_IBUS
|
||||||
|
for (uint8_t i = 0; i < (IBUS_NUM_CHANNELS * 2); i +=2) {
|
||||||
|
ibus_captured_value[(i/2)] = CLAMP( command.channels[i] + (command.channels[i+1] << 8) - 1000, INPUT_MIN, INPUT_MAX);
|
||||||
|
}
|
||||||
|
cmd1 = CLAMP((ibus_captured_value[0] - INPUT_MID) * 2, INPUT_MIN, INPUT_MAX);
|
||||||
|
cmd2 = CLAMP((ibus_captured_value[1] - INPUT_MID) * 2, INPUT_MIN, INPUT_MAX);
|
||||||
|
#elif
|
||||||
cmd1 = CLAMP((int16_t)command.steer, INPUT_MIN, INPUT_MAX);
|
cmd1 = CLAMP((int16_t)command.steer, INPUT_MIN, INPUT_MAX);
|
||||||
cmd2 = CLAMP((int16_t)command.speed, INPUT_MIN, INPUT_MAX);
|
cmd2 = CLAMP((int16_t)command.speed, INPUT_MIN, INPUT_MAX);
|
||||||
|
#endif
|
||||||
command.start = 0xFFFF; // Change the Start Frame for timeout detection in the next cycle
|
command.start = 0xFFFF; // Change the Start Frame for timeout detection in the next cycle
|
||||||
timeoutCntSerial = 0; // Reset the timeout counter
|
timeoutCntSerial = 0; // Reset the timeout counter
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ src_dir = Src
|
||||||
;default_envs = VARIANT_USART3 ; Variant for Serial control via USART3 input
|
;default_envs = VARIANT_USART3 ; Variant for Serial control via USART3 input
|
||||||
;default_envs = VARIANT_NUNCHUCK ; Variant for Nunchuck controlled vehicle build
|
;default_envs = VARIANT_NUNCHUCK ; Variant for Nunchuck controlled vehicle build
|
||||||
;default_envs = VARIANT_PPM ; Variant for RC-Remotes with PPM-Sum signal
|
;default_envs = VARIANT_PPM ; Variant for RC-Remotes with PPM-Sum signal
|
||||||
|
;default_envs = VARIANT_IBUS ; Variant for RC-Remotes with FLYSKY IBUS
|
||||||
;default_envs = VARIANT_HOVERCAR ; Variant for HOVERCAR build
|
;default_envs = VARIANT_HOVERCAR ; Variant for HOVERCAR build
|
||||||
;default_envs = VARIANT_TRANSPOTTER ; Variant for TRANSPOTTER build https://github.com/NiklasFauth/hoverboard-firmware-hack/wiki/Build-Instruction:-TranspOtter https://hackaday.io/project/161891-transpotter-ng
|
;default_envs = VARIANT_TRANSPOTTER ; Variant for TRANSPOTTER build https://github.com/NiklasFauth/hoverboard-firmware-hack/wiki/Build-Instruction:-TranspOtter https://hackaday.io/project/161891-transpotter-ng
|
||||||
;================================================================
|
;================================================================
|
||||||
|
@ -111,6 +112,27 @@ build_flags =
|
||||||
|
|
||||||
;================================================================
|
;================================================================
|
||||||
|
|
||||||
|
[env:VARIANT_IBUS]
|
||||||
|
platform = ststm32
|
||||||
|
framework = stm32cube
|
||||||
|
board = genericSTM32F103RC
|
||||||
|
debug_tool = stlink
|
||||||
|
upload_protocol = stlink
|
||||||
|
|
||||||
|
build_flags =
|
||||||
|
-I${PROJECT_DIR}/inc/
|
||||||
|
-DUSE_HAL_DRIVER
|
||||||
|
-DSTM32F103xE
|
||||||
|
-Wl,-T./STM32F103RCTx_FLASH.ld
|
||||||
|
-Wl,-lc
|
||||||
|
-Wl,-lm
|
||||||
|
-g -ggdb ; to generate correctly the 'firmware.elf' for STM STUDIO vizualization
|
||||||
|
# -Wl,-lnosys
|
||||||
|
-D VARIANT_IBUS
|
||||||
|
-D PALTFORMIO
|
||||||
|
|
||||||
|
;================================================================
|
||||||
|
|
||||||
[env:VARIANT_HOVERCAR]
|
[env:VARIANT_HOVERCAR]
|
||||||
platform = ststm32
|
platform = ststm32
|
||||||
framework = stm32cube
|
framework = stm32cube
|
||||||
|
|
Loading…
Reference in New Issue