#!/bin/sh
set -x

make DEBUG=INFO TARGET=STM32H730 EXTRA_FLAGS="\
-D'TARGET_BOARD_IDENTIFIER=\"SP7R\"' \
-D'USBD_PRODUCT_STRING=\"SPRacingH7RF\"' \
\
-D'EEPROM_SIZE=8192' \
-DUSE_SPRACING_PERSISTENT_RTC_WORKAROUND \
\
-DUSE_BUTTONS  \
-D'BUTTON_A_PIN=PC14' \
-DBUTTON_A_PIN_INVERTED \
-D'BUTTON_B_PIN=PC14' \
-DBUTTON_B_PIN_INVERTED \
\
-DUSE_OCTOSPI \
-DUSE_OCTOSPI_DEVICE_1 \
-D'OCTOSPIM_P1_SCK_PIN=PB2' \
-D'OCTOSPIM_P1_CS_PIN=PB10' \
-D'OCTOSPIM_P1_IO0_PIN=PD11' \
-D'OCTOSPIM_P1_IO1_PIN=PD12' \
-D'OCTOSPIM_P1_IO2_PIN=PE2' \
-D'OCTOSPIM_P1_IO3_PIN=PD13' \
-D'OCTOSPIM_P1_IO4_PIN=NONE' \
-D'OCTOSPIM_P1_IO5_PIN=NONE' \
-D'OCTOSPIM_P1_IO6_PIN=NONE' \
-D'OCTOSPIM_P1_IO7_PIN=NONE' \
-D'OCTOSPIM_P1_MODE=OCTOSPIM_P1_MODE_IO03_ONLY' \
-D'OCTOSPIM_P1_CS_FLAGS=(OCTOSPIM_P1_CS_HARDWARE)' \
\
-DUSE_SPI \
\
-DUSE_SPI_DEVICE_2 \
-D'SPI2_SCK_PIN=PD3' \
-D'SPI2_MISO_PIN=PB14' \
-D'SPI2_MOSI_PIN=PB15' \
-D'SPI2_NSS_PIN=PB12' \
\
-DUSE_SPI_DEVICE_6 \
-D'SPI6_SCK_PIN=PB3' \
-D'SPI6_MISO_PIN=PB4' \
-D'SPI6_MOSI_PIN=PB5' \
-D'SPI6_NSS_PIN=PA15' \
\
-D'SX1280_BUSY_PIN=PC7' \
-D'SX1280_DIO1_PIN=PC6' \
-D'SX1280_DIO2_PIN=PD4' \
-D'SX1280_DIO3_PIN=NONE' \
-D'SX1280_NRESET_PIN=PD10' \
-DUSE_RX_SPI \
-DUSE_RX_EXPRESSLRS \
-DUSE_RX_SX1280 \
-D'RX_SPI_INSTANCE=SPI2' \
-D'RX_NSS_PIN=SPI2_NSS_PIN' \
-D'RX_SPI_EXTI_PIN=SX1280_DIO1_PIN' \
-D'RX_EXPRESSLRS_SPI_RESET_PIN=SX1280_NRESET_PIN' \
-D'RX_EXPRESSLRS_SPI_BUSY_PIN=SX1280_BUSY_PIN' \
-D'RX_EXPRESSLRS_TIMER_INSTANCE=TIM6' \
-D'DEFAULT_RX_FEATURE=FEATURE_RX_SPI' \
-D'RX_SPI_DEFAULT_PROTOCOL=RX_SPI_EXPRESSLRS' \
\
-D'VTX_ENABLE_PIN=PC15' \
-D'PINIO1_PIN=VTX_ENABLE_PIN' \
\
-DUSE_FLASH_MEMORY_MAPPED \
-DUSE_FLASH_W25Q128FV \
-D'FLASH_OCTOSPI_INSTANCE=OCTOSPI1' \
-DCONFIG_IN_MEMORY_MAPPED_FLASH \
-DUSE_FIRMWARE_PARTITION \
\
-D'SDCARD_DETECT_PIN=PC13' \
-DSDCARD_DETECT_INVERTED \
-D'SDIO_DEVICE=SDIODEV_1' \
-D'SDIO_USE_4BIT=true' \
-D'SDIO_CK_PIN=PC12' \
-D'SDIO_CMD_PIN=PD2' \
-D'SDIO_D0_PIN=PC8' \
-D'SDIO_D1_PIN=PC9' \
-D'SDIO_D2_PIN=PC10' \
-D'SDIO_D3_PIN=PC11' \
\
-D'TARGET_IO_PORTA=0xffff' \
-D'TARGET_IO_PORTB=(0xffff & ~(BIT(2)|BIT(6)))' \
-D'TARGET_IO_PORTC=0xffff' \
-D'TARGET_IO_PORTD=(0xffff & ~(BIT(11)|BIT(12)|BIT(13)))' \
-D'TARGET_IO_PORTE=(0xffff & ~(BIT(2)|BIT(7)|BIT(8)|BIT(9)|BIT(10)))' \
-D'TARGET_IO_PORTF=0xffff' \
-D'TARGET_IO_PORTG=0xffff' \
-D'TARGET_IO_PORTH=0xffff' \
\
-DUSE_I2C \
-DUSE_I2C_DEVICE_1 \
-D'I2C1_SCL=PB8' \
-D'I2C1_SDA=PB9' \
\
-DUSE_I2C_DEVICE_2 \
-D'I2C2_SCL=PB10' \
-D'I2C2_SDA=PB11' \
-D'MAG_I2C_INSTANCE=(I2CDEV_1)' \
-D'BARO_I2C_INSTANCE=(I2CDEV_2)' \
\
-DUSE_ACC \
-DUSE_GYRO \
\
-DUSE_MPU_DATA_READY_SIGNAL \
-DENSURE_MPU_DATA_READY_IS_LOW \
\
-D'ADC3_DMA_OPT=10' \
-D'ADC_INSTANCE=ADC3' \
-D'CURRENT_METER_2_ADC_PIN=PC0' \
-D'CURRENT_METER_2_ADC_INSTANCE=ADC3' \
-D'CURRENT_METER_1_ADC_PIN=PC1' \
-D'CURRENT_METER_1_ADC_INSTANCE=ADC3' \
-D'EXTERNAL1_ADC_PIN=PC2' \
-D'EXTERNAL1_ADC_INSTANCE=ADC3' \
-D'VIDEO_IN_ADC_PIN=PC5' \
-D'VIDEO_OUT_ADC_PIN=PC4' \
-D'VBAT_ADC_PIN=PC3' \
-D'VBAT_ADC_INSTANCE=ADC3' \
-D'RSSI_ADC_PIN=CURRENT_METER_2_ADC_PIN' \
-D'RSSI_ADC_INSTANCE=CURRENT_METER_2_ADC_INSTANCE' \
-D'CURRENT_METER_ADC_PIN=CURRENT_METER_1_ADC_PIN' \
-D'CURRENT_METER_ADC_INSTANCE=CURRENT_METER_1_ADC_INSTANCE' \
-D'DEFAULT_VOLTAGE_METER_SOURCE=VOLTAGE_METER_ADC' \
-D'DEFAULT_CURRENT_METER_SOURCE=CURRENT_METER_ADC' \
\
-DENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT \
\
-DUSE_SDCARD \
-DUSE_ACC_SPI_ICM42605 \
-DUSE_ACC_SPI_ICM42688P \
-DUSE_GYRO_SPI_ICM42605 \
-DUSE_GYRO_SPI_ICM42688P \
-DUSE_FLASH_W25Q128FV \
"

# Settings that are currently defined in target/common_pre.h for non-cloud builds that probably shouldn't be.
# There are here to illustrate that they SHOULD be included in THIS target when they are removed by default.

#-DUSE_MAG \
#-DUSE_MAG_HMC5883 \
#-DUSE_MAG_QMC5883 \
#-DUSE_BARO \
#-DUSE_BARO_BMP388 \
