Skip to content

Commit

Permalink
Easy override pins
Browse files Browse the repository at this point in the history
  • Loading branch information
qqqlab committed May 14, 2024
1 parent 0d59dc2 commit d713b4b
Show file tree
Hide file tree
Showing 416 changed files with 26,229 additions and 11,201 deletions.
70 changes: 57 additions & 13 deletions examples/01.Quadcopter/01.Quadcopter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,62 @@ blink interval longer than 1 second - loop() is taking too much time
fast blinking - something is wrong, connect USB serial for info
##########################################################################################################################*/


//========================================================================================================================//
// PINS //
//========================================================================================================================//
// PINS are setup in the board header file library/src/madflight_board_default_*.h, but you can use these defines to
// override the pins. The pin numbers below are the default for Raspberry Pi Pico

//LED:
//#define HW_PIN_LED 25
//#define HW_LED_ON 1 //0:low is on, 1:high is on

//IMU SPI:
//#define HW_PIN_SPI_MISO 16
//#define HW_PIN_SPI_MOSI 19
//#define HW_PIN_SPI_SCLK 18
//#define HW_PIN_IMU_CS 17
//#define HW_PIN_IMU_EXTI 22 //external interrupt pin

//I2C for BARO, MAG, BAT sensors and for IMU if not using SPI
//#define HW_PIN_I2C_SDA 20
//#define HW_PIN_I2C_SCL 21

//Outputs:
//#define HW_OUT_COUNT 12 //number of outputs
//#define HW_PIN_OUT_LIST {2,3,4,5,6,7,10,11,12,13,14,15} //list of output pins

//Serial debug on USB Serial port (no GPIO pins)

//RC Receiver:
//#define HW_PIN_RCIN_RX 1
//#define HW_PIN_RCIN_TX 0
//#define HW_PIN_RCIN_INVERTER -1 //only used for STM32 targets

//GPS:
//#define HW_PIN_GPS_RX 9
//#define HW_PIN_GPS_TX 8
//#define HW_PIN_GPS_INVERTER -1 //only used for STM32 targets

//Battery ADC
//#define HW_PIN_BAT_V 28
//#define HW_PIN_BAT_I -1

//BlackBox SPI:
//#define HW_PIN_SPI2_MISO -1
//#define HW_PIN_SPI2_MOSI -1
//#define HW_PIN_SPI2_SCLK -1
//#define HW_PIN_BB_CS -1

//========================================================================================================================//
// BOARD //
//========================================================================================================================//
// Uncomment/change the following #include to the flight controller you want to use, or leave commented out to use the
// default board pinout (madflight_board_default_*.h). See library/madflight/src for all available boards

//#include <madflight_board_betaflight_MTKS-MATEKH743.h>

//========================================================================================================================//
// USER-SPECIFIED DEFINES //
//========================================================================================================================//
Expand Down Expand Up @@ -68,18 +124,6 @@ fast blinking - something is wrong, connect USB serial for info
//--- BLACKBOX LOGGER
#define BB_USE BB_USE_NONE //BB_USE_INTFLASH internal flash, BB_USE_FLASH external flash, BB_USE_RAM ram or psram, BB_USE_NONE

//========================================================================================================================//
// BOARD //
//========================================================================================================================//
// Uncomment/change the following #include to the flight controller you want to use, or leave commented out
// to use the default board pinout (madflight_board_default_XXX.h). See library/madflight/src for all available boards

//#include <madflight_board_custom_DYST-DYSF4PRO_V2.h>
//#include <madflight_board_betaflight_MTKS-MATEKH743.h>

//Note: after the board include, you can override the sensors if needed. For example:
//#define IMU_USE IMU_USE_SPI_BMI270 //force use of BMI270 sensor, even if other sensor defined in the board header

//========================================================================================================================//
// RC RECEIVER CONFIG //
//========================================================================================================================//
Expand Down Expand Up @@ -364,7 +408,7 @@ void imu_loop() {
out_SetCommands(); //Sends command pulses to motors (only if out_armed=true) and servos

#ifdef USE_IMU_BUS_I2C
//if IMU uses i2c bus, then get i2c sensor readings in the imu_loop to prevent i2c bus. Or, put the imu on a separate i2c bus.
//if IMU uses i2c bus, then get i2c sensor readings in imu_loop() to prevent i2c bus collisions. Alternatively, put the IMU on a separate i2c bus.
i2c_sensors_update();
#endif

Expand Down
95 changes: 68 additions & 27 deletions src/boards/betaflight_target_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,53 +167,94 @@ def fprint(txt) :

fprint( "" )
fprint( "//LED:" )
fprint( "const int HW_PIN_LED = " + resources.get("LED:1","-1") + ";" )
fprint( "const int HW_LED_ON = 1; //0:low is on, 1:high is on" )

fprint( "#ifndef HW_PIN_LED" )
fprint( " #define HW_PIN_LED " + resources.get("LED:1","-1") )
fprint( "#endif" )
fprint( "#ifndef HW_LED_ON" )
fprint( " #define HW_LED_ON 1 //0:low is on, 1:high is on" )
fprint( "#endif" )

spi = sets.get("gyro_1_spibus","1")
fprint( "" )
fprint( "//IMU SPI: (SPI"+spi+")" )
fprint( "const int HW_PIN_SPI_MISO = " + resources.get("SPI_MISO:" + spi,"-1") + ";" )
fprint( "const int HW_PIN_SPI_MOSI = " + resources.get("SPI_MOSI:" + spi,"-1") + ";" )
fprint( "const int HW_PIN_SPI_SCLK = " + resources.get("SPI_SCK:" + spi,"-1") + ";" )
fprint( "const int HW_PIN_IMU_CS = " + resources.get("GYRO_CS:1","-1") + ";" )
fprint( "const int HW_PIN_IMU_EXTI = " + resources.get("GYRO_EXTI:1","-1") + ";" )
fprint( "#ifndef HW_PIN_SPI_MISO" )
fprint( " #define HW_PIN_SPI_MISO " + resources.get("SPI_MISO:" + spi,"-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_SPI_MOSI" )
fprint( " #define HW_PIN_SPI_MOSI " + resources.get("SPI_MOSI:" + spi,"-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_SPI_SCLK" )
fprint( " #define HW_PIN_SPI_SCLK " + resources.get("SPI_SCK:" + spi,"-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_IMU_CS" )
fprint( " #define HW_PIN_IMU_CS " + resources.get("GYRO_CS:1","-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_IMU_EXTI" )
fprint( " #define HW_PIN_IMU_EXTI " + resources.get("GYRO_EXTI:1","-1") )
fprint( "#endif" )

i2c = sets.get("mag_i2c_device")
i2c = sets.get("baro_i2c_device",i2c)
if i2c is None: i2c = "1"
fprint( "" )
fprint( "//BARO/MAG I2C: (I2C"+i2c+")" )
fprint( "const int HW_PIN_I2C_SDA = " + resources.get("I2C_SCL:" + i2c,"-1") + ";" )
fprint( "const int HW_PIN_I2C_SCL = " + resources.get("I2C_SDA:" + i2c,"-1") + ";" )
fprint( "#ifndef HW_PIN_I2C_SDA" )
fprint( " #define HW_PIN_I2C_SDA " + resources.get("I2C_SCL:" + i2c,"-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_I2C_SCL" )
fprint( " #define HW_PIN_I2C_SCL " + resources.get("I2C_SDA:" + i2c,"-1") )
fprint( "#endif" )

fprint( "" )
fprint( "//Outputs:" )
fprint( "const int HW_OUT_COUNT = " + str(len(motors)) + ";" )
fprint( "const int HW_PIN_OUT[] = {" + ",".join(motors) + "};" )
fprint( "#ifndef HW_OUT_COUNT" )
fprint( " #define HW_OUT_COUNT " + str(len(motors)) )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_OUT_LIST" )
fprint( " #define HW_PIN_OUT_LIST {" + ",".join(motors) + "}" )
fprint( "#endif" )

fprint( "" )
fprint( "//RC Receiver: (SERIAL"+rcin_serial+")" )
fprint( "const int HW_PIN_RCIN_RX = " + resources.get("SERIAL_RX:"+rcin_serial,"-1") + ";" )
fprint( "const int HW_PIN_RCIN_TX = " + resources.get("SERIAL_TX:"+rcin_serial,"-1") + ";" )
fprint( "const int HW_PIN_RCIN_INVERTER = " + resources.get("INVERTER:"+rcin_serial,"-1") + ";" )
fprint( "#ifndef HW_PIN_RCIN_RX" )
fprint( " #define HW_PIN_RCIN_RX " + resources.get("SERIAL_RX:"+rcin_serial,"-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_RCIN_TX" )
fprint( " #define HW_PIN_RCIN_TX " + resources.get("SERIAL_TX:"+rcin_serial,"-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_RCIN_INVERTER" )
fprint( " #define HW_PIN_RCIN_INVERTER " + resources.get("INVERTER:"+rcin_serial,"-1") )
fprint( "#endif" )

fprint( "" )
fprint( "//GPS: (SERIAL"+gps_serial+")" )
fprint( "const int HW_PIN_GPS_RX = " + resources.get("SERIAL_RX:"+gps_serial,"-1") + ";" )
fprint( "const int HW_PIN_GPS_TX = " + resources.get("SERIAL_TX:"+gps_serial,"-1") + ";" )
fprint( "const int HW_PIN_GPS_INVERTER = " + resources.get("INVERTER:"+gps_serial,"-1") + ";" )
fprint( "#ifndef HW_PIN_GPS_RX" )
fprint( " #define HW_PIN_GPS_RX " + resources.get("SERIAL_RX:"+gps_serial,"-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_GPS_TX" )
fprint( " #define HW_PIN_GPS_TX " + resources.get("SERIAL_TX:"+gps_serial,"-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_GPS_INVERTER" )
fprint( " #define HW_PIN_GPS_INVERTER " + resources.get("INVERTER:"+gps_serial,"-1") )
fprint( "#endif" )

fprint( "" )
fprint( "//Battery ADC voltage and current inputs:" )
fprint( "const int HW_PIN_BAT_V = " + resources.get("ADC_BATT:1","-1") + ";" )
fprint( "const int HW_PIN_BAT_I = " + resources.get("ADC_CURR:1","-1") + ";" )
fprint( "#ifndef HW_PIN_BAT_V" )
fprint( " #define HW_PIN_BAT_V " + resources.get("ADC_BATT:1","-1") )
fprint( "#endif" )
fprint( "#ifndef HW_PIN_BAT_I" )
fprint( " #define HW_PIN_BAT_I " + resources.get("ADC_CURR:1","-1") )
fprint( "#endif" )

fprint( "" )
fprint( "const int HW_PIN_OUT[] = HW_PIN_OUT_LIST;" )

fprint( "" )
fprint( "//Include Libraries" )
fprint( "#include <Wire.h> //I2C communication" )
fprint( "#include <SPI.h> //SPI communication" )
fprint( "#include \"madflight/hw_STM32/STM32_PWM.h\" //Servo and oneshot" )
fprint( "#include <Wire.h> //I2C communication" )
fprint( "#include <SPI.h> //SPI communication" )
fprint( "#include \"madflight/hw_STM32/STM32_PWM.h\" //Servo and oneshot" )

fprint( "" )
fprint( "//Bus Setup" )
Expand Down Expand Up @@ -254,10 +295,10 @@ def fprint(txt) :
fprint( "#define HW_PIN_I2C { " + ", ".join(p) + " } // {INDEX,SCL,SDA}" )


fprint( "" )
fprint( "//Motors:" )
fprint( "#define HW_MOTOR_COUNT " + str(len(motors)) )
fprint( "#define HW_MOTOR_OUT {" + ",".join(motors) + "}" )
# fprint( "" )
# fprint( "//Motors:" )
# fprint( "#define HW_MOTOR_COUNT " + str(len(motors)) )
# fprint( "#define HW_MOTOR_OUT {" + ",".join(motors) + "}" )

fprint( "" )
fprint( "//other pins" )
Expand Down
90 changes: 63 additions & 27 deletions src/madflight_board_betaflight_AFNG-ALIENFLIGHTF4.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*==============================================================================
Generated on: 2024-03-11 20:33:42.870150
Generated on: 2024-05-14 03:27:31.771662
Generated by: betaflight_target_converter.py
Source: https://github.com/betaflight/unified-targets
Board name: ALIENFLIGHTF4
Expand All @@ -25,42 +25,82 @@ Manufacturer ID: AFNG
#define MAG_I2C_ADR 0

//LED:
const int HW_PIN_LED = PC12;
const int HW_LED_ON = 1; //0:low is on, 1:high is on
#ifndef HW_PIN_LED
#define HW_PIN_LED PC12
#endif
#ifndef HW_LED_ON
#define HW_LED_ON 1 //0:low is on, 1:high is on
#endif

//IMU SPI: (SPI1)
const int HW_PIN_SPI_MISO = PA6;
const int HW_PIN_SPI_MOSI = PA7;
const int HW_PIN_SPI_SCLK = PA5;
const int HW_PIN_IMU_CS = PA4;
const int HW_PIN_IMU_EXTI = PC14;
#ifndef HW_PIN_SPI_MISO
#define HW_PIN_SPI_MISO PA6
#endif
#ifndef HW_PIN_SPI_MOSI
#define HW_PIN_SPI_MOSI PA7
#endif
#ifndef HW_PIN_SPI_SCLK
#define HW_PIN_SPI_SCLK PA5
#endif
#ifndef HW_PIN_IMU_CS
#define HW_PIN_IMU_CS PA4
#endif
#ifndef HW_PIN_IMU_EXTI
#define HW_PIN_IMU_EXTI PC14
#endif

//BARO/MAG I2C: (I2C1)
const int HW_PIN_I2C_SDA = PB6;
const int HW_PIN_I2C_SCL = PB7;
#ifndef HW_PIN_I2C_SDA
#define HW_PIN_I2C_SDA PB6
#endif
#ifndef HW_PIN_I2C_SCL
#define HW_PIN_I2C_SCL PB7
#endif

//Outputs:
const int HW_OUT_COUNT = 8;
const int HW_PIN_OUT[] = {PB8,PB9,PA0,PA1,PC6,PC7,PC8,PC9};
#ifndef HW_OUT_COUNT
#define HW_OUT_COUNT 8
#endif
#ifndef HW_PIN_OUT_LIST
#define HW_PIN_OUT_LIST {PB8,PB9,PA0,PA1,PC6,PC7,PC8,PC9}
#endif

//RC Receiver: (SERIAL1)
const int HW_PIN_RCIN_RX = PA10;
const int HW_PIN_RCIN_TX = PA9;
const int HW_PIN_RCIN_INVERTER = -1;
#ifndef HW_PIN_RCIN_RX
#define HW_PIN_RCIN_RX PA10
#endif
#ifndef HW_PIN_RCIN_TX
#define HW_PIN_RCIN_TX PA9
#endif
#ifndef HW_PIN_RCIN_INVERTER
#define HW_PIN_RCIN_INVERTER -1
#endif

//GPS: (SERIAL2)
const int HW_PIN_GPS_RX = PA3;
const int HW_PIN_GPS_TX = PA2;
const int HW_PIN_GPS_INVERTER = PC15;
#ifndef HW_PIN_GPS_RX
#define HW_PIN_GPS_RX PA3
#endif
#ifndef HW_PIN_GPS_TX
#define HW_PIN_GPS_TX PA2
#endif
#ifndef HW_PIN_GPS_INVERTER
#define HW_PIN_GPS_INVERTER PC15
#endif

//Battery ADC voltage and current inputs:
const int HW_PIN_BAT_V = PC0;
const int HW_PIN_BAT_I = PC1;
#ifndef HW_PIN_BAT_V
#define HW_PIN_BAT_V PC0
#endif
#ifndef HW_PIN_BAT_I
#define HW_PIN_BAT_I PC1
#endif

const int HW_PIN_OUT[] = HW_PIN_OUT_LIST;

//Include Libraries
#include <Wire.h> //I2C communication
#include <SPI.h> //SPI communication
#include "madflight/hw_STM32/STM32_PWM.h" //Servo and oneshot
#include <Wire.h> //I2C communication
#include <SPI.h> //SPI communication
#include "madflight/hw_STM32/STM32_PWM.h" //Servo and oneshot

//Bus Setup
HardwareSerial *rcin_Serial = new HardwareSerial(HW_PIN_RCIN_RX, HW_PIN_RCIN_TX);
Expand All @@ -81,10 +121,6 @@ SPIClass *spi = &SPI;
#define HW_I2C_COUNT 1
#define HW_PIN_I2C { {1,PB6,PB7} } // {INDEX,SCL,SDA}

//Motors:
#define HW_MOTOR_COUNT 8
#define HW_MOTOR_OUT {PB8,PB9,PA0,PA1,PC6,PC7,PC8,PC9}

//other pins
#define HW_PIN_BEEPER PC13
#define HW_PIN_PPM PA8
Expand Down
Loading

0 comments on commit d713b4b

Please sign in to comment.