# hw definition file for processing by chibios_pins.py
# for SP/Racing Extreme H7 hardware.
# thanks to betaflight for pin information

# MCU class and specific type
MCU STM32H7xx STM32H750xx

# board ID for firmware load
APJ_BOARD_ID 1060

# crystal frequency, setup to use external oscillator
OSCILLATOR_HZ 8000000

MCU_CLOCKRATE_MHZ 480

env OPTIMIZE -O2

define HAL_WITH_EKF_DOUBLE 0

STM32_ST_USE_TIMER 2

# internal flash is off limits
FLASH_SIZE_KB 128
FLASH_RESERVE_START_KB 0
define HAL_FLASH_PROTECTION 1

EXT_FLASH_SIZE_MB 16
EXT_FLASH_RESERVE_START_KB 1024
EXT_FLASH_RESERVE_END_KB 448

# only one I2C bus
I2C_ORDER I2C1

# order of UARTs (and USB)
SERIAL_ORDER OTG1 USART1 USART2 USART3 UART4 UART5 USART6 EMPTY UART8

# Buzzer - DMA timer channel use by LEDs
PD7 BUZZER OUTPUT GPIO(80) LOW
define HAL_BUZZER_PIN 80
define HAL_BUZZER_ON 1
define HAL_BUZZER_OFF 0

# USB
PA11 OTG_FS_DM OTG1
PA12 OTG_FS_DP OTG1

# Debug
PA13 JTMS-SWDIO SWD
PA14 JTCK-SWCLK SWD

# SPI2 ICM20602  #2
PB12 ICM20602_2_CS CS
PD3 SPI2_SCK SPI2
PC2 SPI2_MISO SPI2
PC3 SPI2_MOSI SPI2

# SPI3 ICM20602  #1
PA15 ICM20602_1_CS CS
PB3 SPI3_SCK SPI3
PB4 SPI3_MISO SPI3
PD6 SPI3_MOSI SPI3

# SPI4 for OSD
PE11 AT7456E_CS CS
PE12 SPI4_SCK SPI4
PE13 SPI4_MISO SPI4
PE14 SPI4_MOSI SPI4

# I2C1 for baro
PB8 I2C1_SCL I2C1 PULLUP
PB9 I2C1_SDA I2C1 PULLUP

# Internal current sensor
PC1 BATT_VOLTAGE_SENS ADC1 SCALE(1)
PC0 BATT_CURRENT_SENS ADC1 SCALE(1)
# External current sensor
PC5 BATT_CURRENT_SENS2 ADC1 SCALE(1)    # analog pin 8

# VTX Power control - should be high at startup to ensure power
PB01 VTX_PWR OUTPUT HIGH GPIO(81)
define RELAY2_PIN_DEFAULT 81

PC4 RSSI_IN ADC1
define BOARD_RSSI_ANA_PIN 0

# define default battery setup
define HAL_BATT_VOLT_PIN 11
define HAL_BATT_CURR_PIN 10
define HAL_BATT_VOLT_SCALE 10.9
define HAL_BATT_CURR_SCALE 28.5
define HAL_BATT_MONITOR_DEFAULT 4

# USART1 (RCIN)
PB15 USART1_RX USART1
PB14 USART1_TX USART1
define HAL_SERIAL1_PROTOCOL SerialProtocol_RCIN

# USART2 (SmartPort)
PD5 USART2_TX USART2

# USART3
PD9 USART3_RX USART3
PD8 USART3_TX USART3

# UART4
PD0 UART4_RX UART4
PD1 UART4_TX UART4

# UART5
PB5 UART5_RX UART5
PB13 UART5_TX UART5

# UART6
PC7 USART6_RX USART6 ALT(1)
PC6 USART6_TX USART6 ALT(1)

# UART8
PE0 UART8_RX UART8
PE1 UART8_TX UART8

# SD card
PC8 SDMMC1_D0 SDMMC1
PC9 SDMMC1_D1 SDMMC1
PC10 SDMMC1_D2 SDMMC1
PC11 SDMMC1_D3 SDMMC1
PC12 SDMMC1_CK SDMMC1
PD2 SDMMC1_CMD SDMMC1

# QuadSPI Flash
PD11 QUADSPI_BK1_IO0 QUADSPI1
PD12 QUADSPI_BK1_IO1 QUADSPI1
PE2 QUADSPI_BK1_IO2 QUADSPI1
PD13 QUADSPI_BK1_IO3 QUADSPI1
PB10 QUADSPI_BK1_NCS QUADSPI1
PB2 QUADSPI_CLK QUADSPI1

# Motors
PA0  TIM5_CH1 TIM5 PWM(1) GPIO(50) BIDIR    # M1
PA1  TIM5_CH2 TIM5 PWM(2) GPIO(51)          # M2
PA2  TIM5_CH3 TIM5 PWM(3) GPIO(52) BIDIR    # M3
PA3  TIM5_CH4 TIM5 PWM(4) GPIO(53)          # M4

PB6  TIM4_CH1 TIM4 PWM(5) GPIO(54)          # M5
PB7  TIM4_CH2 TIM4 PWM(6) GPIO(55)          # M6

PC6  TIM8_CH1 TIM8 PWM(7) GPIO(56)          # M7
PC7  TIM8_CH2 TIM8 PWM(8) GPIO(57)          # M8

PD14 TIM4_CH3 TIM4 PWM(9) GPIO(58)          # M9
PD15 TIM4_CH4 TIM4 PWM(10) GPIO(59)         # M10

# Motor outputs on the stacking connector
#PA6  TIM3_CH1 TIM3 PWM(1) GPIO(61)          # M11
#PA7  TIM3_CH2 TIM3 PWM(2) GPIO(62)          # M12
#PB0  TIM3_CH3 TIM3 PWM(3) GPIO(63)          # M13
#PB1  TIM3_CH4 TIM3 PWM(4) GPIO(64)          # M14

# NeoPixel LED strip
PA8 TIM1_CH1 TIM1 PWM(11) GPIO(60)
 # Red LED
PE3 LED0 OUTPUT LOW GPIO(90)

# spi devices
SPIDEV icm20602_1 SPI3 DEVID1 ICM20602_1_CS MODE3  2*MHZ  10*MHZ
SPIDEV icm20602_2 SPI2 DEVID2 ICM20602_2_CS MODE3  2*MHZ  10*MHZ
SPIDEV osd       SPI4 DEVID4 AT7456E_CS MODE0 10*MHZ 10*MHZ

DMA_PRIORITY SPI3* SPI2* TIM5*

define HAL_COMPASS_DEFAULT HAL_COMPASS_NONE
define ALLOW_ARM_NO_COMPASS
define HAL_PROBE_EXTERNAL_I2C_COMPASSES
define HAL_I2C_INTERNAL_MASK 0

# two IMUs
IMU Invensense SPI:icm20602_1 ROTATION_YAW_90
IMU Invensense SPI:icm20602_2 ROTATION_YAW_135
define HAL_DEFAULT_INS_FAST_SAMPLE 3

# one BARO
BARO BMP388 I2C:0:0x76

# setup for OSD
define OSD_ENABLED 1
define HAL_OSD_TYPE_DEFAULT 1
ROMFS_WILDCARD libraries/AP_OSD/fonts/font*.bin

define HAL_OS_FATFS_IO 1
define HAL_BOARD_LOG_DIRECTORY "/APM/LOGS"
define HAL_BOARD_TERRAIN_DIRECTORY "/APM/TERRAIN"

define BOARD_PWM_COUNT_DEFAULT 11
define STM32_PWM_USE_ADVANCED TRUE

define HAL_STORAGE_SIZE 16384
