/*==============================================================================
Generated on: 2025-03-24 13:58:25.084939
Generated by: betaflight_target_converter.py
Source: https://github.com/betaflight/unified-targets
Board name: MERCURYG4
Manufacturer ID: ANYL

//copy this line to madflight.ino to use this flight controller
#include <madflight_zzz_ANYL-MERCURYG4.h>

Note: madflight will pick the last sensor defined here, this might not be the sensor that is actually on the board. Comment the offending sensors out.
==============================================================================*/

#define HAL_BOARD_NAME "BETAFLIGHT-ANYL-MERCURYG4"
#define HAL_MCU "STM32G47X"

#define MADFLIGHT_BOARD R""(
imu_gizmo ICM42688P // #define USE_GYRO_SPI_ICM42688P
bar_gizmo DPS310 // #define USE_BARO_DPS310
pin_imu_int PC13 // resource GYRO_EXTI 1 C13
pin_imu_cs PB12 // resource GYRO_CS 1 B12
// set gyro_1_bustype = SPI
imu_spi_bus 0 // set gyro_1_spibus = 1
imu_align CW90 // set gyro_1_sensor_align = CW90
// set baro_hardware = DPS310
// set baro_bustype = I2C
bar_i2c_bus 1 // set baro_i2c_device = 2
// set baro_i2c_address = 119 # 0x77
// set i2c2_clockspeed_khz = 400
// set i2c2_pullup = ON # No hardware PUs are present.
// set mco_on_pa8 = OFF
// resource FLASH_CS 1 A00
// set blackbox_device = SPIFLASH
// set flash_spi_bus = 2
pin_spi0_sclk PA5 // resource SPI_SCK 1 A05
pin_spi0_miso PA6 // resource SPI_MISO 1 A06
pin_spi0_mosi PA7 // resource SPI_MOSI 1 A07
pin_spi1_sclk PB13 // resource SPI_SCK 2 B13
pin_spi1_miso PB14 // resource SPI_MISO 2 B14
pin_spi1_mosi PB15 // resource SPI_MOSI 2 B15
pin_i2c0_scl PA15 // resource I2C_SCL 1 A15
pin_i2c0_sda PB9 // resource I2C_SDA 1 B09
pin_i2c1_scl PA9 // resource I2C_SCL 2 A09
pin_i2c1_sda PA8 // resource I2C_SDA 2 A08
pin_ser0_tx PB6 // resource SERIAL_TX 1 B06
pin_ser0_rx PB7 // resource SERIAL_RX 1 B07
pin_ser1_tx PB3 // resource SERIAL_TX 2 B03
pin_ser1_rx PB4 // resource SERIAL_RX 2 B04
pin_ser2_tx PB10 // resource SERIAL_TX 3 B10
pin_ser2_rx PB11 // resource SERIAL_RX 3 B11
pin_ser3_tx PC10 // resource SERIAL_TX 4 C10
pin_ser3_rx PC11 // resource SERIAL_RX 4 C11
pin_ser8_tx PA2 // resource SERIAL_TX 9 A02
pin_ser8_rx PA3 // resource SERIAL_RX 9 A03
pin_bat_v PA1 // resource ADC_BATT 1 A01 # ADC2 In 2
bat_gizmo ADC
pin_bat_i PB2 // resource ADC_CURR 1 B02 # ADC2 In 12
bat_gizmo ADC
// set adc_device = 2
// set current_meter = ADC
// set battery_meter = ADC
// set vbat_scale = 118
// set vbat_divider = 5
// set vbat_multiplier = 2
pin_out0 PC6 // resource MOTOR 1 C06
pin_out1 PA4 // resource MOTOR 2 A04
pin_out2 PB0 // resource MOTOR 3 B00
pin_out3 PB1 // resource MOTOR 4 B01
// resource BEEPER 1 A10
// set serialrx_provider = CRSF
// set rssi_channel = 15
// set system_hse_mhz = 16
// set pid_process_denom = 2
)"" //end of MADFLIGHT_BOARD


/*
#==============================================================================
# BetaFlight Source file
#==============================================================================
# Betaflight / STM32G47X (SG47) 4.4.0 Feb 25 2023 / 03:35:00 (8d4f005) MSP API: 1.44

#define USE_GYRO
#define USE_GYRO_SPI_ICM42688P
#define USE_ACC
#define USE_ACC_SPI_ICM42688P
#define USE_BARO
#define USE_BARO_DPS310
#define USE_FLASH
#define USE_FLASH_M25P16
#define USE_GPS
//TODO#define SYSTEM_HSE_MHZ 16

board_name MERCURYG4
manufacturer_id ANYL


# IMU
resource GYRO_EXTI 1 C13
resource GYRO_CS 1 B12
set gyro_1_bustype = SPI
set gyro_1_spibus = 1
set gyro_1_sensor_align = CW90


# Barometer
set baro_hardware = DPS310
set baro_bustype = I2C
set baro_i2c_device = 2
set baro_i2c_address = 119  # 0x77
set i2c2_clockspeed_khz = 400
set i2c2_pullup = ON  # No hardware PUs are present.
set mco_on_pa8 = OFF


# Flash
resource FLASH_CS 1 A00
set blackbox_device = SPIFLASH
set flash_spi_bus = 2


# SPI
# SPI 1: IMU
resource SPI_SCK 1 A05
resource SPI_MISO 1 A06
resource SPI_MOSI 1 A07

# SPI 2: Blackbox flash 
resource SPI_SCK 2 B13
resource SPI_MISO 2 B14
resource SPI_MOSI 2 B15


# I2C
resource I2C_SCL 1 A15
resource I2C_SDA 1 B09

# I2c 2: Barometer
resource I2C_SCL 2 A09
resource I2C_SDA 2 A08


# UART
resource SERIAL_TX 1 B06
resource SERIAL_RX 1 B07

# UART 2: ELRS receiver
resource SERIAL_TX 2 B03
resource SERIAL_RX 2 B04

resource SERIAL_TX 3 B10
resource SERIAL_RX 3 B11

# UART 4: OSD
resource SERIAL_TX 4 C10
resource SERIAL_RX 4 C11

# LPUART 1:
resource SERIAL_TX 9 A02
resource SERIAL_RX 9 A03


# ADC
resource ADC_BATT 1 A01 # ADC2 In 2
resource ADC_CURR 1 B02 # ADC2 In 12
set adc_device = 2

set current_meter = ADC
set battery_meter = ADC
set vbat_scale = 118
set vbat_divider = 5
set vbat_multiplier = 2


# Motors and timer pins for burst DMA DSHOT
timer C06 AF2    # Tim3 ch1
timer A04 AF2    # Tim3 ch2
timer B00 AF2    # Tim3 ch3
timer B01 AF2    # Tim3 ch4

resource MOTOR 1 C06
resource MOTOR 2 A04
resource MOTOR 3 B00
resource MOTOR 4 B01

timer A10 AF10  # Beeper: Tim2 ch4
resource BEEPER 1 A10


# Control Rx
set serialrx_provider = CRSF
# For RSSI on the OSD, use AUX11/ch15 for Link Quality Indictaor, or AUX12/ch16 for RSSI dBm
set rssi_channel = 15


# DMA
# Assign DMA channels explicitly. Leaving the default assignments triggers
# system failures indicated by the attitude indication responding strangely
# on the `Setup` page.

# We don't use ADC 1 directly, but it is mandatory to assign it, since
# the MCU's temperature sensor, and VDDA measurement are on ADC1.
dma ADC 1 6
dma ADC 2 7
dma SPI_MOSI 1 8
dma SPI_MISO 1 9
dma SPI_MOSI 2 10
dma SPI_MISO 2 11


# Features
feature TELEMETRY
feature OSD
feature RX_SERIAL  # For the built-en ELRS receiver, via CRSF.


# Configure UART4 for digital (MSP Displayport) OSD.
serial 3 1 115200 57600 0 115200
# Configure UART2 for the built-in ELRS receiver, via CRSF.
serial 1 64 115200 57600 0 115200


# Master
set system_hse_mhz = 16
# 4kHz PID loop frequency.
set pid_process_denom = 2

*/
