Skip to content

Commit

Permalink
Merge pull request #10 from EmanuelFeru/hovercar-variant
Browse files Browse the repository at this point in the history
Hovercar variant
  • Loading branch information
EFeru authored Dec 7, 2020
2 parents d80bde1 + 46d10a0 commit b5de1a6
Show file tree
Hide file tree
Showing 26 changed files with 2,828 additions and 1,706 deletions.
21 changes: 10 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ jobs:
- export PATH=$HOME/arm-gcc-toolchain/bin:$PATH
before_script: arm-none-eabi-gcc --version

# # Not yet supportted, see https://community.platformio.org/t/build-gd32-project-with-platformio/11944
# - name: platformio
# script: platformio run
# language: python
# python:
# - "2.7"
# install:
# - pip install -U platformio
# - platformio update
# cache:
# - directories: "~/.platformio"
- name: platformio
script: platformio run
language: python
python:
- "2.7"
install:
- pip install -U platformio
- platformio update
cache:
- directories: "~/.platformio"
60 changes: 43 additions & 17 deletions Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==================================== */
Expand All @@ -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.
Expand All @@ -59,32 +59,57 @@
#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
#define SERIAL_AUX_RX // [-] Use AUX4, AUX5 as USART port
// #define SERIAL_AUX_TX // [-] 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 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_RX // [-] Use AUX4, AUX5 as USART port
// #define SERIAL_AUX_TX // [-] 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.
Expand All @@ -94,7 +119,8 @@
#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(SERIAL_AUX_TX) || defined(AUX45_USE_I2C)) \
|| ((defined(SERIAL_AUX_RX) || defined(SERIAL_AUX_TX)) && defined(AUX45_USE_I2C))
#error AUX45_USE_(GPIO,USART,I2C) not allowed in the same time. It is on the same cable.
#endif

Expand Down
220 changes: 111 additions & 109 deletions Inc/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,156 +28,158 @@
#include "util.h"

#if defined(PRINTF_FLOAT_SUPPORT) && defined(SERIAL_DEBUG) && defined(__GNUC__)
asm(".global _printf_float"); // this is the magic trick for printf to support float. Warning: It will increase code considerably! Better to avoid!
asm(".global _printf_float"); // this is the magic trick for printf to support float. Warning: It will increase code considerably! Better to avoid!
#endif

/* =========================== Defines General =========================== */
// #define _BV(bit) (1 << (bit))
#define ARRAY_LEN(x) (uint32_t)(sizeof(x) / sizeof(*(x)))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define i2c_write i2c_writeBytes
#define i2c_read i2c_readBytes
#define delay_ms delay_1ms
#define get_ms get_tick_count_ms
#define log_i printf // redirect the log_i debug function to printf
// #define _BV(bit) (1 << (bit))
#define ARRAY_LEN(x) (uint32_t)(sizeof(x) / sizeof(*(x)))
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define i2c_write i2c_writeBytes
#define i2c_read i2c_readBytes
#define delay_ms delay_1ms
#define get_ms get_tick_count_ms
#define log_i printf // redirect the log_i debug function to printf


/* =========================== Defines LEDs =========================== */
#define LED1_GPIO_Port GPIOA
#define LED1_Pin GPIO_PIN_0 // RED
#define LED2_GPIO_Port GPIOB
#define LED2_Pin GPIO_PIN_9 // GREEN
#define LED3_GPIO_Port GPIOB
#define LED3_Pin GPIO_PIN_8 // YELLOW
#define LED4_GPIO_Port GPIOB
#define LED4_Pin GPIO_PIN_5 // BLUE1
#define LED5_GPIO_Port GPIOB
#define LED5_Pin GPIO_PIN_4 // BLUE2

#define LED1_SET (0x01)
#define LED2_SET (0x02)
#define LED3_SET (0x04)
#define LED4_SET (0x08)
#define LED5_SET (0x10)
#define LED1_GPIO_Port GPIOA
#define LED1_Pin GPIO_PIN_0 // RED
#define LED2_GPIO_Port GPIOB
#define LED2_Pin GPIO_PIN_9 // GREEN
#define LED3_GPIO_Port GPIOB
#define LED3_Pin GPIO_PIN_8 // YELLOW
#define LED4_GPIO_Port GPIOB
#define LED4_Pin GPIO_PIN_5 // BLUE1
#define LED5_GPIO_Port GPIOB
#define LED5_Pin GPIO_PIN_4 // BLUE2

#define LED1_SET (0x01)
#define LED2_SET (0x02)
#define LED3_SET (0x04)
#define LED4_SET (0x08)
#define LED5_SET (0x10)


/* =========================== Defines SENSORS =========================== */
#define SENSOR1_GPIO_Port GPIOA
#define SENSOR1_Pin GPIO_PIN_4
#define SENSOR2_GPIO_Port GPIOC
#define SENSOR2_Pin GPIO_PIN_14
#define SENSOR1_GPIO_Port GPIOA
#define SENSOR1_Pin GPIO_PIN_4
#define SENSOR2_GPIO_Port GPIOC
#define SENSOR2_Pin GPIO_PIN_14


/* =========================== Defines USART =========================== */
#define USART_GPIO_PORT GPIOA
#define USART_GPIO_CLK RCU_GPIOA
#define USART_AF GPIO_AF_1
#define USART_GPIO_PORT GPIOA
#define USART_GPIO_CLK RCU_GPIOA
#define USART_AF GPIO_AF_1

// USART ports number
#define USARTn 2


// USART to Auxiliary, 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_RDATA_ADDRESS ((uint32_t)0x40013824)
#define USART1_TDATA_ADDRESS ((uint32_t)0x40004428) // USART1: 0x4000 4400 - 0x4000 47FF
#define USART1_RDATA_ADDRESS ((uint32_t)0x40004424)

#define USARTn 2

// USART AUX, connected to USART0
#define USART_AUX USART0
#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)

// 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)

#define PRINT_AUX (0x01)

/* =========================== Defines AUX =========================== */
#define AUX1_PU_GPIO_Port GPIOC
#define AUX1_PU_Pin GPIO_PIN_15
#define AUX2_GPIO_Port GPIOA
#define AUX2_Pin GPIO_PIN_1
#define AUX3_GPIO_Port GPIOB
#define AUX3_Pin GPIO_PIN_10
#define AUX1_PU_GPIO_Port GPIOC
#define AUX1_PU_Pin GPIO_PIN_15
#define AUX2_GPIO_Port GPIOA
#define AUX2_Pin GPIO_PIN_1
#define AUX3_GPIO_Port GPIOB
#define AUX3_Pin GPIO_PIN_10
#ifdef AUX45_USE_GPIO
#define AUX4_GPIO_Port GPIOA
#define AUX4_Pin GPIO_PIN_10
#define AUX5_GPIO_Port GPIOA
#define AUX5_Pin GPIO_PIN_9
#define AUX4_GPIO_Port GPIOA
#define AUX4_Pin GPIO_PIN_10
#define AUX5_GPIO_Port GPIOA
#define AUX5_Pin GPIO_PIN_9
#endif


/* =========================== Defines I2C =========================== */
typedef enum {READ = 0, WRITE = !READ} i2c_cmd;
#define MPU_I2C I2C0
#define MPU_RCU_I2C RCU_I2C0
#define MPU_SCL_GPIO_Port GPIOB
#define MPU_SCL_Pin GPIO_PIN_6
#define MPU_SDA_GPIO_Port GPIOB
#define MPU_SDA_Pin GPIO_PIN_7
#define I2C_OWN_ADDRESS7 0x24
#define MPU_I2C I2C0
#define MPU_RCU_I2C RCU_I2C0
#define MPU_SCL_GPIO_Port GPIOB
#define MPU_SCL_Pin GPIO_PIN_6
#define MPU_SDA_GPIO_Port GPIOB
#define MPU_SDA_Pin GPIO_PIN_7
#define I2C_OWN_ADDRESS7 0x24

#ifdef AUX45_USE_I2C
#define AUX_I2C I2C1
#define AUX_RCU_I2C RCU_I2C1
#define AUX_SCL_GPIO_Port GPIOA
#define AUX_SCL_Pin GPIO_PIN_9
#define AUX_SDA_GPIO_Port GPIOA
#define AUX_SDA_Pin GPIO_PIN_10
#define AUX_I2C_OWN_ADDRESS7 0x34
#define AUX_I2C I2C1
#define AUX_RCU_I2C RCU_I2C1
#define AUX_SCL_GPIO_Port GPIOA
#define AUX_SCL_Pin GPIO_PIN_9
#define AUX_SDA_GPIO_Port GPIOA
#define AUX_SDA_Pin GPIO_PIN_10
#define AUX_I2C_OWN_ADDRESS7 0x34
#endif

/* =========================== Defines MPU-6050 =========================== */
#define RAD2DEG 57.295779513082323 // RAD2DEG = 180/pi. Example: angle[deg] = angle[rad] * RAD2DEG
#define q30 1073741824 // 1073741824 = 2^30
#define ACCEL_ON (0x01)
#define GYRO_ON (0x02)
#define COMPASS_ON (0x04)

#define PRINT_ACCEL (0x01)
#define PRINT_GYRO (0x02)
#define PRINT_QUAT (0x04)
#define PRINT_EULER (0x08)
#define PRINT_TEMP (0x10)
#define PRINT_PEDO (0x20)
#define RAD2DEG 57.295779513082323 // RAD2DEG = 180/pi. Example: angle[deg] = angle[rad] * RAD2DEG
#define q30 1073741824 // 1073741824 = 2^30
#define ACCEL_ON (0x01)
#define GYRO_ON (0x02)
#define COMPASS_ON (0x04)

#define PRINT_ACCEL (0x01)
#define PRINT_GYRO (0x02)
#define PRINT_QUAT (0x04)
#define PRINT_EULER (0x08)
#define PRINT_TEMP (0x10)
#define PRINT_PEDO (0x20)

typedef struct{
int16_t x;
int16_t y;
int16_t z;
int16_t x;
int16_t y;
int16_t z;
} Gyro;

typedef struct{
int16_t x;
int16_t y;
int16_t z;
int16_t x;
int16_t y;
int16_t z;
} Accel;

typedef struct{
int32_t w;
int32_t x;
int32_t y;
int32_t z;
int32_t w;
int32_t x;
int32_t y;
int32_t z;
} Quaternion;

typedef struct{
int16_t roll;
int16_t pitch;
int16_t yaw;
int16_t roll;
int16_t pitch;
int16_t yaw;
} Euler;

typedef struct {
Gyro gyro;
Accel accel;
Quaternion quat;
Euler euler;
int16_t temp;
Gyro gyro;
Accel accel;
Quaternion quat;
Euler euler;
int16_t temp;
} MPU_Data;

#endif // DEFINES_H
Loading

0 comments on commit b5de1a6

Please sign in to comment.