# hw definition file for processing by chibios_hwdef.py for  Qiotek ZealotH743
# MCU class and specific type
MCU STM32H7xx STM32H743xx

# crystal frequency
OSCILLATOR_HZ 8000000

# board ID for firmware load
APJ_BOARD_ID 1036

FLASH_SIZE_KB 2048

# with 2M flash we can afford to optimize for speed
env OPTIMIZE -O2

# ChibiOS system timer
STM32_ST_USE_TIMER 2

# bootloader takes first sector
FLASH_RESERVE_START_KB 128

# order of UARTs (and USB)
SERIAL_ORDER OTG1 USART1 USART2 USART3 UART4 UART7 OTG2

# now we define the pins that USB is connected on
PA11 OTG_FS_DM OTG1
PA12 OTG_FS_DP OTG1
PA9  VBUS INPUT

# these are the pins for SWD debugging with a STlinkv2 or black-magic probe
PA13 JTMS-SWDIO SWD
PA14 JTCK-SWCLK SWD

# SPI1 - internal sensors and OSD
PA5 SPI1_SCK SPI1
PA6 SPI1_MISO SPI1
PA7 SPI1_MOSI SPI1

# SPI2 - FRAM and SmartCard
PD3 SPI2_SCK SPI2
PC2 SPI2_MISO SPI2
PC3 SPI2_MOSI SPI2

# SPI3 - ADIS16470 sensor
PB3 SPI3_SCK SPI3
PB4 SPI3_MISO SPI3
PB5 SPI3_MOSI SPI3

# sensor 

PB2  IMU1_CS   CS
PE10 IMU2_CS   CS
PE12 IMU3_CS   CS
PE3  BARO1_CS  CS
PD7  BARO2_CS  CS   
PA8  AT7456_CS CS
PA10 FRAM_CS   CS    
PC10 FLASH_CS  CS    
PA15 ADIS16470_CS CS

# use GPIO(93) for data ready on ADIS16470
define ADIS_DRDY_PIN 93

# define the order that I2C buses 
I2C_ORDER I2C2 I2C1

# I2C1 is on GPS port
PB6 I2C1_SCL I2C1
PB7 I2C1_SDA I2C1

# I2C2
PB10 I2C2_SCL I2C2
PB11 I2C2_SDA I2C2

define HAL_I2C_INTERNAL_MASK 1

# define UARTs

# USART1 is telem1
PB15 USART1_RX USART1 
PB14 USART1_TX USART1

# USART2 is telem2
PD6 USART2_RX USART2 
PD5 USART2_TX USART2 

# USART3 is GPS1
PD9 USART3_RX USART3 
PD8 USART3_TX USART3 NODMA

# USART4 is GPS2
PB8 UART4_RX UART4 NODMA
PB9 UART4_TX UART4 NODMA

# UART7 is debug
PE7 UART7_RX UART7 NODMA
PE8 UART7_TX UART7 NODMA

# PWM AUX channels
PA2  TIM5_CH3 TIM5 PWM(1) GPIO(50)
PA3  TIM5_CH4 TIM5 PWM(2) GPIO(51)
PB0  TIM3_CH3 TIM3 PWM(3) GPIO(52)
PC9  TIM3_CH4 TIM3 PWM(4) GPIO(53) 
PE9  TIM1_CH1 TIM1 PWM(5) GPIO(54) 
PE11 TIM1_CH2 TIM1 PWM(6) GPIO(55)
PE13 TIM1_CH3 TIM1 PWM(7) GPIO(56)
PE14 TIM1_CH4 TIM1 PWM(8) GPIO(57)

PD12 TIM4_CH1 TIM4 PWM(9)  GPIO(58)
PD13 TIM4_CH2 TIM4 PWM(10) GPIO(59)
PD14 TIM4_CH3 TIM4 PWM(11) GPIO(60) 
PD15 TIM4_CH4 TIM4 PWM(12) GPIO(61) 
PC6  TIM3_CH1 TIM3 PWM(13) GPIO(62) NODMA
PC7  TIM3_CH2 TIM3 PWM(14) GPIO(63) NODMA


# PWM output for buzzer
PE5 TIM15_CH1 TIM15 GPIO(77) ALARM

# RC input
PC8 TIM8_CH3 TIM8 RCININT PULLUP LOW 

# analog in
PA0 BATT_VOLTAGE_SENS ADC1 SCALE(2)
PA1 BATT_CURRENT_SENS ADC1 SCALE(2)
PC0 BATT2_VOLTAGE_SENS ADC1 SCALE(2)
PC1 BATT2_CURRENT_SENS ADC1 SCALE(2)

# Board VCC and servo rail VCC
PA4 VDD_5V_SENS ADC1 SCALE(2)
PC4 FMU_SERVORAIL_VCC_SENS ADC1 SCALE(12)

# analog in ADC6.6
PC5 PRESSURE_SENS ADC1 SCALE(2)
PB1 RSSI_IN ADC1 SCALE(2)


# CAN bus
PD0  CAN1_RX CAN1
PD1  CAN1_TX CAN1

# 2nd CAN bus
PB12 CAN2_RX CAN2
PB13 CAN2_TX CAN2

# control for silent (no output) for CAN
PD11 GPIO_CAN1_SILENT OUTPUT PUSHPULL SPEED_LOW LOW GPIO(70)
PD10 GPIO_CAN2_SILENT OUTPUT PUSHPULL SPEED_LOW LOW GPIO(71)


# SPI devices
SPIDEV adis16470      SPI3 DEVID1  ADIS16470_CS MODE3   1*MHZ    2*MHZ
SPIDEV imu1           SPI1 DEVID1  IMU1_CS      MODE3   2*MHZ    8*MHZ
SPIDEV imu2           SPI1 DEVID2  IMU2_CS      MODE3   2*MHZ    8*MHZ
SPIDEV imu3           SPI1 DEVID3  IMU3_CS      MODE3   2*MHZ    8*MHZ
SPIDEV baro1          SPI1 DEVID2  BARO1_CS     MODE3   5*MHZ    5*MHZ
SPIDEV baro2          SPI1 DEVID1  BARO2_CS     MODE3   5*MHZ    5*MHZ
SPIDEV osd            SPI1 DEVID2  AT7456_CS    MODE0  10*MHZ   10*MHZ
SPIDEV ramtron        SPI2 DEVID2  FRAM_CS      MODE3   8*MHZ    8*MHZ 
SPIDEV sdcard         SPI2 DEVID3  FLASH_CS     MODE0 400*KHZ   10*MHZ


# four IMUs, adi16740 is used, then imu3 will be removed
IMU ADIS1647x    SPI:adis16470 ROTATION_ROLL_180 ADIS_DRDY_PIN
IMU Invensense   SPI:imu1      ROTATION_ROLL_180
IMU Invensensev3 SPI:imu1      ROTATION_YAW_270
IMU Invensense   SPI:imu2      ROTATION_ROLL_180
IMU Invensensev3 SPI:imu2      ROTATION_YAW_270
IMU Invensense   SPI:imu3      ROTATION_ROLL_180
IMU Invensensev3 SPI:imu3      ROTATION_YAW_270


# two Baro sensors
BARO DPS280 SPI:baro1
BARO DPS280 SPI:baro2


define HAL_DEFAULT_INS_FAST_SAMPLE 5


# look for I2C compass
COMPASS IST8310 I2C:0:0x0E false ROTATION_ROLL_180_YAW_270
COMPASS QMC5883L I2C:0:0x0D false ROTATION_ROLL_180_YAW_270
define HAL_PROBE_EXTERNAL_I2C_COMPASSES
define HAL_I2C_INTERNAL_MASK 1


# LED setup is similar to PixRacer
define HAL_HAVE_PIXRACER_LED
PE2 LED_RED OUTPUT GPIO(10)
PE1 LED_GREEN OUTPUT GPIO(11)
PE0 LED_BLUE OUTPUT GPIO(12)

define HAL_GPIO_A_LED_PIN 10
define HAL_GPIO_B_LED_PIN 11
define HAL_GPIO_C_LED_PIN 12

define HAL_GPIO_LED_ON  0
define HAL_GPIO_LED_OFF 1

#define GPIOs

PE15 HEATER_EN OUTPUT LOW GPIO(80)
define HAL_HEATER_GPIO_PIN 80
define HAL_HAVE_IMU_HEATER 1

PC11 EXTERN_GPIO1 OUTPUT GPIO(1)
PC12 EXTERN_GPIO2 OUTPUT GPIO(2)
PD2  EXTERN_GPIO3 OUTPUT GPIO(3)
PE6  EXTERN_GPIO4 OUTPUT GPIO(4)

# enable FAT filesystem support
define HAL_OS_FATFS_IO 1
define HAL_BOARD_LOG_DIRECTORY "/APM/LOGS"
define HAL_BOARD_TERRAIN_DIRECTORY "/APM/TERRAIN"

# enable RAMTROM parameter storage
define HAL_STORAGE_SIZE 32768
define HAL_WITH_RAMTRON 1

# allow to have have a dedicated safety switch pin
define HAL_HAVE_SAFETY_SWITCH 1
PC13 LED_SAFETY OUTPUT
PE4  SAFETY_IN INPUT PULLDOWN

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

DMA_PRIORITY  SPI1* SPI3* TIM*UP*
DMA_NOSHARE  SPI1* TIM*UP* 
