Added iBUS on AUX Serial

- iBUS implementation
- changed default baud rate to 115200
- updated platformio.ini, the chip is now supported by Platformio
This commit is contained in:
EmanuelFeru
2020-11-30 19:23:30 +01:00
parent d80bde1d27
commit 46ee23e975
11 changed files with 464 additions and 221 deletions

View File

@@ -27,8 +27,9 @@
// Ubuntu: define the desired build variant here if you want to use make in console
// or use VARIANT environment variable for example like "make -e VARIANT=VARIANT_DEBUG". Select only one at a time.
#if !defined(PLATFORMIO)
// #define VARIANT_DEBUG // Variant for debugging and checking the capabilities of the side-board
// #define VARIANT_HOVERBOARD // Variant for using the side-boards connected to the Hoverboard mainboard
// #define VARIANT_DEBUG // Variant for debugging and checking the capabilities of the side-board
// #define VARIANT_HOVERCAR // Variant for using the side-boards connected to the Hoverboard mainboard
// #define VARIANT_HOVERBOARD // Variant for using the side-boards connected to the Hoverboard mainboard
#endif
/* ==================================== DO NOT TOUCH SETTINGS ==================================== */
@@ -40,7 +41,6 @@
// #define PRINTF_FLOAT_SUPPORT // [-] Uncomment this for printf to support float on Serial Debug. It will increase code size! Better to avoid it!
/* =============================================================================================== */
/* ==================================== SETTINGS MPU-6050 ==================================== */
#define MPU_SENSOR_ENABLE // [-] Enable flag for MPU-6050 sensor. Comment-out this flag to Disable the MPU sensor and reduce code size.
#define MPU_DMP_ENABLE // [-] Enable flag for MPU-6050 DMP (Digital Motion Processing) functionality.
@@ -59,32 +59,50 @@
#define DMP_SHAKE_REJECT_TIME 40 // [ms] Set shake rejection time. Sets the length of time that the gyro must be outside of the DMP_SHAKE_REJECT_THRESH before taps are rejected. A mandatory 60 ms is added to this parameter.
#define DMP_SHAKE_REJECT_TIMEOUT 10 // [ms] Set shake rejection timeout. Sets the length of time after a shake rejection that the gyro must stay inside of the threshold before taps can be detected again. A mandatory 60 ms is added to this parameter.
/* ==================================== SETTINGS USART ==================================== */
#if defined(VARIANT_DEBUG)
#define SERIAL_DEBUG // [-] Define for Serial Debug via the serial port
#elif defined(VARIANT_HOVERBOARD)
#define SERIAL_CONTROL // [-] Define for Serial Control via the serial port
#define SERIAL_FEEDBACK // [-] Define for Serial Feedback via the serial port
#endif
#define USART_MAIN_BAUD 38400 // [bit/s] MAIN Serial Tx/Rx baud rate
#define SERIAL_START_FRAME 0xABCD // [-] Start frame definition for reliable serial communication
#define SERIAL_BUFFER_SIZE 64 // [bytes] Size of Serial Rx buffer. Make sure it is always larger than the 'Feedback' structure size
#define SERIAL_TIMEOUT 600 // [-] Number of wrong received data for Serial timeout detection. Depends on DELAY_IN_MAIN_LOOP
#define USART_MAIN_BAUD 115200 // [bit/s] MAIN Serial Tx/Rx baud rate
#define USART_AUX_BAUD 115200 // [bit/s] AUX Serial Tx/Rx baud rate
/* ==================================== SETTINGS AUX ==================================== */
// #define AUX45_USE_GPIO // [-] Use AUX4, AUX5 as GPIO ports
// #define AUX45_USE_I2C // [-] Use AUX4, AUX5 as I2C port
#define AUX45_USE_USART // [-] Use AUX4, AUX5 as USART port
#ifdef AUX45_USE_USART
#define USART_AUX_BAUD 38400 // [bit/s] AUX Serial Tx/Rx baud rate
#endif
#ifdef AUX45_USE_I2C
#define AUX_I2C_SPEED 100000 // [bit/s] Define I2C speed for communicating via AUX45 wires
#endif
/* ==================================== VARIANT DEBUG ==================================== */
#ifdef VARIANT_DEBUG
#define SERIAL_DEBUG // [-] Define for Serial Debug via the serial port
#endif
/* ==================================== VARIANT HOVERCAR ==================================== */
#ifdef VARIANT_HOVERCAR
#define SERIAL_CONTROL // [-] Define for Serial Control via the serial port
#define SERIAL_FEEDBACK // [-] Define for Serial Feedback via the serial port
#define SERIAL_AUX_TX // [-] Use AUX4, AUX5 as USART port
#define SERIAL_AUX_RX // [-] Use AUX4, AUX5 as USART port
#define CONTROL_IBUS
#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
#endif
/* ==================================== VARIANT HOVERBOARD ==================================== */
#ifdef VARIANT_HOVERBOARD
#define SERIAL_CONTROL // [-] Define for Serial Control via the serial port
#define SERIAL_FEEDBACK // [-] Define for Serial Feedback via the serial port
#endif
/* ==================================== VALIDATE SETTINGS ==================================== */
#if defined(SERIAL_DEBUG) && defined(SERIAL_CONTROL)
#error SERIAL_DEBUG and SERIAL_CONTROL not allowed. It is on the same cable.
@@ -94,7 +112,7 @@
#error SERIAL_DEBUG and SERIAL_FEEDBACK not allowed. It is on the same cable.
#endif
#if defined(AUX45_USE_GPIO) && (defined(AUX45_USE_USART) || defined(AUX45_USE_I2C)) || (defined(AUX45_USE_USART) && defined(AUX45_USE_I2C))
#if defined(AUX45_USE_GPIO) && (defined(SERIAL_AUX_RX) || defined(AUX45_USE_I2C)) || (defined(SERIAL_AUX_RX) && defined(AUX45_USE_I2C))
#error AUX45_USE_(GPIO,USART,I2C) not allowed in the same time. It is on the same cable.
#endif

View File

@@ -77,24 +77,24 @@
// USART ports number
#define USARTn 2
// USART to Auxiliary, connected to USART0
// USART AUX, connected to USART0
#define USART_AUX USART0
#define USART_AUX_CLK RCU_USART0
#define USART_AUX_TX_PIN GPIO_PIN_9
#define USART_AUX_RX_PIN GPIO_PIN_10
// USART to Mainboard, connected to USART1
#define USART_MAIN USART1
#define USART_MAIN_CLK RCU_USART1
#define USART_MAIN_TX_PIN GPIO_PIN_2
#define USART_MAIN_RX_PIN GPIO_PIN_3
// USART address for DMA defines
#define USART0_TDATA_ADDRESS ((uint32_t)0x40013828) // USART0: 0x4001 3800 - 0x4001 3BFF
#define USART0_CLK RCU_USART0
#define USART0_TX_PIN GPIO_PIN_9
#define USART0_RX_PIN GPIO_PIN_10
#define USART0_TX_DMA_CH DMA_CH1
#define USART0_RX_DMA_CH DMA_CH2
#define USART0_TDATA_ADDRESS ((uint32_t)0x40013828) // USART0: 0x4001 3800 - 0x4001 3BFF, Rx offset: 0x28, Tx offset: 0x24
#define USART0_RDATA_ADDRESS ((uint32_t)0x40013824)
#define USART1_TDATA_ADDRESS ((uint32_t)0x40004428) // USART1: 0x4000 4400 - 0x4000 47FF
// USART MAIN, connected to USART1
#define USART_MAIN USART1
#define USART1_CLK RCU_USART1
#define USART1_TX_PIN GPIO_PIN_2
#define USART1_RX_PIN GPIO_PIN_3
#define USART1_TX_DMA_CH DMA_CH3
#define USART1_RX_DMA_CH DMA_CH4
#define USART1_TDATA_ADDRESS ((uint32_t)0x40004428) // USART1: 0x4000 4400 - 0x4000 47FF, Rx offset: 0x28, Tx offset: 0x24
#define USART1_RDATA_ADDRESS ((uint32_t)0x40004424)

View File

@@ -38,6 +38,8 @@ void PendSV_Handler(void);
/* SysTick handle function */
void SysTick_Handler(void);
/* USART0 handle function */
void USART0_IRQHandler(void);
/* USART1 handle function */
void USART1_IRQHandler(void);
/* I2C0 event handle function */
void I2C0_EV_IRQHandler(void);

View File

@@ -104,18 +104,13 @@ int mpu_get_compass_reg(short *data, unsigned long *timestamp);
int mpu_get_temperature(long *data, unsigned long *timestamp);
int mpu_get_int_status(short *status);
int mpu_read_fifo(short *gyro, short *accel, unsigned long *timestamp,
unsigned char *sensors, unsigned char *more);
int mpu_read_fifo_stream(unsigned short length, unsigned char *data,
unsigned char *more);
int mpu_read_fifo(short *gyro, short *accel, unsigned long *timestamp, unsigned char *sensors, unsigned char *more);
int mpu_read_fifo_stream(unsigned short length, unsigned char *data, unsigned char *more);
int mpu_reset_fifo(void);
int mpu_write_mem(unsigned short mem_addr, unsigned short length,
unsigned char *data);
int mpu_read_mem(unsigned short mem_addr, unsigned short length,
unsigned char *data);
int mpu_load_firmware(unsigned short length, const unsigned char *firmware,
unsigned short start_addr, unsigned short sample_rate);
int mpu_write_mem(unsigned short mem_addr, unsigned short length, unsigned char *data);
int mpu_read_mem(unsigned short mem_addr, unsigned short length, unsigned char *data);
int mpu_load_firmware(unsigned short length, const unsigned char *firmware, unsigned short start_addr, unsigned short sample_rate);
int mpu_reg_dump(void);
int mpu_read_reg(unsigned char reg, unsigned char *data);

View File

@@ -23,8 +23,7 @@
#include <stdint.h>
/* Rx Structures USART */
/* Tx structure USART MAIN */
#ifdef SERIAL_CONTROL
typedef struct{
uint16_t start;
@@ -35,6 +34,7 @@ typedef struct{
uint16_t checksum;
} SerialSideboard;
#endif
/* Rx structure USART MAIN */
#ifdef SERIAL_FEEDBACK
typedef struct{
uint16_t start;
@@ -49,6 +49,28 @@ typedef struct{
} SerialFeedback;
#endif
/* Tx structure USART AUX */
#ifdef SERIAL_AUX_TX
typedef struct{
uint16_t start;
int16_t signal1;
int16_t signal2;
uint16_t checksum;
} SerialAuxTx;
#endif
/* Rx structure USART AUX */
#ifdef SERIAL_AUX_RX
#ifdef CONTROL_IBUS
typedef struct{
uint8_t start;
uint8_t type;
uint8_t channels[IBUS_NUM_CHANNELS*2];
uint8_t checksuml;
uint8_t checksumh;
} SerialCommand;
#endif
#endif
/* general functions */
void consoleLog(char *message);
void toggle_led(uint32_t gpio_periph, uint32_t pin);
@@ -58,13 +80,17 @@ void intro_demo_led(uint32_t tDelay);
void input_init(void);
/* usart read functions */
void usart_rx_check(void);
void usart0_rx_check(void);
void usart1_rx_check(void);
#ifdef SERIAL_DEBUG
void usart_process_debug(uint8_t *userCommand, uint32_t len);
#endif
#ifdef SERIAL_FEEDBACK
void usart_process_data(SerialFeedback *Feedback_in, SerialFeedback *Feedback_out);
#endif
#ifdef SERIAL_AUX_RX
void usart_process_command(SerialCommand *command_in, SerialCommand *command_out);
#endif
/* i2c write/read functions */
int8_t i2c_writeBytes(uint8_t slaveAddr, uint8_t regAddr, uint8_t length, uint8_t *data);