# hw definition file for processing by chibios_pins.py
# SuccexF4

MCU STM32F4xx STM32F405xx

HAL_CHIBIOS_ARCH_F405 1

# board ID for firmware load
APJ_BOARD_ID 1011

# crystal frequency
OSCILLATOR_HZ 8000000

STM32_ST_USE_TIMER 5

# flash size
FLASH_SIZE_KB 1024
FLASH_RESERVE_START_KB 64

# ADC
PC1 BAT_CURR_SENS ADC1 SCALE(1)
PC2 BAT_VOLT_SENS ADC1 SCALE(1)

# PWM outputs
PB0 TIM1_CH2N TIM1 PWM(1) GPIO(50)
PB1 TIM1_CH3N TIM1 PWM(2) GPIO(51)
PC9 TIM8_CH4 TIM8 PWM(3) GPIO(52)
PC8 TIM8_CH3 TIM8 PWM(4) GPIO(53)

# Two IMUs on SPI1
PC4 ICM20689_1_DRDY INPUT
PA8 ICM20689_2_DRDY INPUT
PA4 ICM20689_1_CS CS
PC3 ICM20689_2_CS CS
PA5 SPI1_SCK SPI1
PA6 SPI1_MISO SPI1
PA7 SPI1_MOSI SPI1

# OSD on SPI2
PB12 AT7456E_CS CS
PB13 SPI2_SCK SPI2
PB14 SPI2_MISO SPI2
PB15 SPI2_MOSI SPI2

# FLASH on SPI3
PA15 FLASH_CS CS
PC10 SPI3_SCK SPI3
PC11 SPI3_MISO SPI3
PC12 SPI3_MOSI SPI3

# Order of I2C buses
I2C_ORDER I2C1

# UART ports and I2C bus
SERIAL_ORDER OTG1 USART1 USART2 USART3 USART6

# Note that this board needs pull-ups on I2C pins
PB8 I2C1_SCL I2C1 PULLUP
PB9 I2C1_SDA I2C1 PULLUP

PA10 USART1_RX USART1
PA9 USART1_TX USART1

PA3 USART2_RX USART2
PA2 USART2_TX USART2

PB11 USART3_RX USART3
PB10 USART3_TX USART3

PC7 USART6_RX USART6
PC6 USART6_TX USART6

PA13 JTMS-SWDIO SWD
PA14 JTCK-SWCLK SWD

# LED and buzzer
PB4 TIM3_CH1 TIM3 GPIO(56) ALARM
PB5 LED OUTPUT HIGH GPIO(57)
define HAL_GPIO_A_LED_PIN 57

PA11 OTG_FS_DM OTG1
PA12 OTG_FS_DP OTG1
PC5 VBUS INPUT OPENDRAIN

# LED strip pad as RC input
PB6 TIM4_CH1 TIM4 RCININT PULLDOWN LOW

# SPI Device table 
SPIDEV icm20689_1 SPI1 DEVID1 ICM20689_1_CS MODE3 1*MHZ 8*MHZ
SPIDEV icm20689_2 SPI1 DEVID2 ICM20689_2_CS MODE3 1*MHZ 8*MHZ
SPIDEV osd        SPI2 DEVID3 AT7456E_CS  MODE0 10*MHZ 10*MHZ
SPIDEV dataflash  SPI3 DEVID4 FLASH_CS    MODE3 32*MHZ 32*MHZ

# Two IMUs
IMU Invensense SPI:icm20689_1 ROTATION_YAW_270
IMU Invensense SPI:icm20689_2 ROTATION_NONE

# one baro
BARO BMP280 I2C:0:0x76
define HAL_PROBE_EXTERNAL_I2C_BAROS
define HAL_BARO_ALLOW_INIT_NO_BARO

# no built-in compass, but probe the i2c bus for all possible
# external compass types
define ALLOW_ARM_NO_COMPASS
define HAL_COMPASS_DEFAULT HAL_COMPASS_NONE
define HAL_PROBE_EXTERNAL_I2C_COMPASSES
define HAL_I2C_INTERNAL_MASK 0
define HAL_COMPASS_AUTO_ROT_DEFAULT 2

define STORAGE_FLASH_PAGE 1
define HAL_STORAGE_SIZE 15360

# enable logging to dataflash
define HAL_LOGGING_DATAFLASH

# define default battery setup
define HAL_BATT_VOLT_PIN 12
define HAL_BATT_CURR_PIN 11
define HAL_BATT_VOLT_SCALE 11
define HAL_BATT_CURR_SCALE 18.2

define OSD_ENABLED 1
define HAL_OSD_TYPE_DEFAULT 1

define BOARD_PWM_COUNT_DEFAULT 4

#font for the osd
ROMFS_WILDCARD libraries/AP_OSD/fonts/font*.bin

# disable parachute and sprayer to save flash
define HAL_PARACHUTE_ENABLED 0
define HAL_SPRAYER_ENABLED 0

# reduce max size of embedded params for apj_tool.py
define AP_PARAM_MAX_EMBEDDED_PARAM 1024
