Skip to content

Commit d2caf65

Browse files
committed
madflight_config
1 parent 07040d8 commit d2caf65

File tree

448 files changed

+3139
-2682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

448 files changed

+3139
-2682
lines changed

examples/00.HelloWorld/madflight_config.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*========================================================================================================================
2-
MADFLIGHT CONFIG
2+
MADFLIGHT CONFIG
33
==========================================================================================================================
44
5-
MADFLIGHT_CONFIG is a multi-line raw string in with a key-value list. Anything after '#' or '/' is ignored as comment.
5+
madflight_config is a multi-line raw string in with a key-value list. Anything after '#' or '/' is ignored as comment.
66
77
You have 4 options to setup the pins (gpio numbers) and serial/spi/i2c busses for the flight controller:
88
99
1) Default - #include <madflight_board.h> and see https://madflight.com for default pinout diagrams for the supported
1010
processor families. Default pinouts are defined in the board header files library/madflight/src/madflight_board_XXX.h
11-
Leave lines with "pin_..." and "..._bus" commented in MADFLIGHT_CONFIG.
11+
Leave lines with "pin_..." and "..._bus" commented in madflight_config.
1212
1313
2) BetaFlight - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
1414
boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
1515
16-
3) Override - Keep #include <madflight_board.h>, and uncomment lines in MADFLIGHT_CONFIG to override the board settings.
16+
3) Override - Keep #include <madflight_board.h>, and uncomment lines in madflight_config to override the board settings.
1717
18-
4) Custom - Remove #include <madflight_board.h>, and set the full configuration in MADFLIGHT_CONFIG below.
18+
4) Bare Metal - Remove #include <madflight_board.h>, and set the full configuration in madflight_config below.
1919
2020
Pins and busses use zero-based numbering, i.e. imu_spi_bus 0 is the first spi bus. Use -1 to disable a pin or bus.
2121
@@ -28,7 +28,7 @@ If things do not work as expected, have a good look at the startup messages!
2828

2929
#include <madflight_board.h>
3030

31-
#define MADFLIGHT_CONFIG R""(
31+
const char* madflight_config = R""(
3232

3333
//--- IMU --- Inertial Measurement Unit (use spi -OR- i2c bus)
3434
imu_gizmo MPU6500 // options: NONE, BMI270, MPU6000, MPU6050, MPU6500, MPU9150, MPU9250
@@ -138,7 +138,7 @@ ahr_gizmo MAHONY // options: MAHONY, MAHONY_BF, MADGWICK, VQF
138138
//pin_out14 -1
139139
//pin_out15 -1
140140

141-
)"" // End of MADFLIGHT_CONFIG
141+
)""; // End of madflight_config
142142

143143

144144
//========================================================================================================================//

examples/01.Quadcopter/madflight_config.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*========================================================================================================================
2-
MADFLIGHT CONFIG
2+
MADFLIGHT CONFIG
33
==========================================================================================================================
44
5-
MADFLIGHT_CONFIG is a multi-line raw string in with a key-value list. Anything after '#' or '/' is ignored as comment.
5+
madflight_config is a multi-line raw string in with a key-value list. Anything after '#' or '/' is ignored as comment.
66
77
You have 4 options to setup the pins (gpio numbers) and serial/spi/i2c busses for the flight controller:
88
99
1) Default - #include <madflight_board.h> and see https://madflight.com for default pinout diagrams for the supported
1010
processor families. Default pinouts are defined in the board header files library/madflight/src/madflight_board_XXX.h
11-
Leave lines with "pin_..." and "..._bus" commented in MADFLIGHT_CONFIG.
11+
Leave lines with "pin_..." and "..._bus" commented in madflight_config.
1212
1313
2) BetaFlight - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
1414
boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
1515
16-
3) Override - Keep #include <madflight_board.h>, and uncomment lines in MADFLIGHT_CONFIG to override the board settings.
16+
3) Override - Keep #include <madflight_board.h>, and uncomment lines in madflight_config to override the board settings.
1717
18-
4) Custom - Remove #include <madflight_board.h>, and set the full configuration in MADFLIGHT_CONFIG below.
18+
4) Bare Metal - Remove #include <madflight_board.h>, and set the full configuration in madflight_config below.
1919
2020
Pins and busses use zero-based numbering, i.e. imu_spi_bus 0 is the first spi bus. Use -1 to disable a pin or bus.
2121
@@ -28,7 +28,7 @@ If things do not work as expected, have a good look at the startup messages!
2828

2929
#include <madflight_board.h>
3030

31-
#define MADFLIGHT_CONFIG R""(
31+
const char* madflight_config = R""(
3232

3333
//--- IMU --- Inertial Measurement Unit (use spi -OR- i2c bus)
3434
imu_gizmo MPU6500 // options: NONE, BMI270, MPU6000, MPU6050, MPU6500, MPU9150, MPU9250
@@ -138,7 +138,7 @@ ahr_gizmo MAHONY // options: MAHONY, MAHONY_BF, MADGWICK, VQF
138138
//pin_out14 -1
139139
//pin_out15 -1
140140

141-
)"" // End of MADFLIGHT_CONFIG
141+
)""; // End of madflight_config
142142

143143

144144
//========================================================================================================================//

examples/02.QuadcopterAdvanced/madflight_config.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*========================================================================================================================
2-
MADFLIGHT CONFIG
2+
MADFLIGHT CONFIG
33
==========================================================================================================================
44
5-
MADFLIGHT_CONFIG is a multi-line raw string in with a key-value list. Anything after '#' or '/' is ignored as comment.
5+
madflight_config is a multi-line raw string in with a key-value list. Anything after '#' or '/' is ignored as comment.
66
77
You have 4 options to setup the pins (gpio numbers) and serial/spi/i2c busses for the flight controller:
88
99
1) Default - #include <madflight_board.h> and see https://madflight.com for default pinout diagrams for the supported
1010
processor families. Default pinouts are defined in the board header files library/madflight/src/madflight_board_XXX.h
11-
Leave lines with "pin_..." and "..._bus" commented in MADFLIGHT_CONFIG.
11+
Leave lines with "pin_..." and "..._bus" commented in madflight_config.
1212
1313
2) BetaFlight - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
1414
boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
1515
16-
3) Override - Keep #include <madflight_board.h>, and uncomment lines in MADFLIGHT_CONFIG to override the board settings.
16+
3) Override - Keep #include <madflight_board.h>, and uncomment lines in madflight_config to override the board settings.
1717
18-
4) Custom - Remove #include <madflight_board.h>, and set the full configuration in MADFLIGHT_CONFIG below.
18+
4) Bare Metal - Remove #include <madflight_board.h>, and set the full configuration in madflight_config below.
1919
2020
Pins and busses use zero-based numbering, i.e. imu_spi_bus 0 is the first spi bus. Use -1 to disable a pin or bus.
2121
@@ -28,7 +28,7 @@ If things do not work as expected, have a good look at the startup messages!
2828

2929
#include <madflight_board.h>
3030

31-
#define MADFLIGHT_CONFIG R""(
31+
const char* madflight_config = R""(
3232

3333
//--- IMU --- Inertial Measurement Unit (use spi -OR- i2c bus)
3434
imu_gizmo MPU6500 // options: NONE, BMI270, MPU6000, MPU6050, MPU6500, MPU9150, MPU9250
@@ -138,7 +138,7 @@ ahr_gizmo MAHONY // options: MAHONY, MAHONY_BF, MADGWICK, VQF
138138
//pin_out14 -1
139139
//pin_out15 -1
140140

141-
)"" // End of MADFLIGHT_CONFIG
141+
)""; // End of madflight_config
142142

143143

144144
//========================================================================================================================//

examples/03.Plane/madflight_config.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*========================================================================================================================
2-
MADFLIGHT CONFIG
2+
MADFLIGHT CONFIG
33
==========================================================================================================================
44
5-
MADFLIGHT_CONFIG is a multi-line raw string in with a key-value list. Anything after '#' or '/' is ignored as comment.
5+
madflight_config is a multi-line raw string in with a key-value list. Anything after '#' or '/' is ignored as comment.
66
77
You have 4 options to setup the pins (gpio numbers) and serial/spi/i2c busses for the flight controller:
88
99
1) Default - #include <madflight_board.h> and see https://madflight.com for default pinout diagrams for the supported
1010
processor families. Default pinouts are defined in the board header files library/madflight/src/madflight_board_XXX.h
11-
Leave lines with "pin_..." and "..._bus" commented in MADFLIGHT_CONFIG.
11+
Leave lines with "pin_..." and "..._bus" commented in madflight_config.
1212
1313
2) BetaFlight - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
1414
boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
1515
16-
3) Override - Keep #include <madflight_board.h>, and uncomment lines in MADFLIGHT_CONFIG to override the board settings.
16+
3) Override - Keep #include <madflight_board.h>, and uncomment lines in madflight_config to override the board settings.
1717
18-
4) Custom - Remove #include <madflight_board.h>, and set the full configuration in MADFLIGHT_CONFIG below.
18+
4) Bare Metal - Remove #include <madflight_board.h>, and set the full configuration in madflight_config below.
1919
2020
Pins and busses use zero-based numbering, i.e. imu_spi_bus 0 is the first spi bus. Use -1 to disable a pin or bus.
2121
@@ -28,7 +28,7 @@ If things do not work as expected, have a good look at the startup messages!
2828

2929
#include <madflight_board.h>
3030

31-
#define MADFLIGHT_CONFIG R""(
31+
const char* madflight_config = R""(
3232

3333
//--- IMU --- Inertial Measurement Unit (use spi -OR- i2c bus)
3434
imu_gizmo MPU6500 // options: NONE, BMI270, MPU6000, MPU6050, MPU6500, MPU9150, MPU9250
@@ -138,7 +138,7 @@ ahr_gizmo MAHONY // options: MAHONY, MAHONY_BF, MADGWICK, VQF
138138
//pin_out14 -1
139139
//pin_out15 -1
140140

141-
)"" // End of MADFLIGHT_CONFIG
141+
)""; // End of madflight_config
142142

143143

144144
//========================================================================================================================//

extras/betaflight_target_converter/betaflight_target_converter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,21 @@ def fprint(txt) :
146146
fprint( "//copy this line to madflight.ino to use this flight controller" )
147147
fprint( "#include <" + outfilename + ">" )
148148
fprint( "" )
149-
fprint( "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." )
149+
fprint( "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, or use madflight_config to override." )
150150
fprint( "==============================================================================*/" )
151151

152152
fprint( "" )
153-
fprint( "#define HAL_BOARD_NAME \"BETAFLIGHT-" + strippedfilename + "\"" )
153+
fprint( "#define MF_BOARD_NAME \"BETAFLIGHT-" + strippedfilename + "\"" )
154154
mcu_re = re.search(r"\bSTM32\w+", lines[0] + " " + lines[1]);
155-
if mcu_re : fprint( "#define HAL_MCU \"" + mcu_re.group() + "\"" )
155+
if mcu_re : fprint( "#define MF_MCU_NAME \"" + mcu_re.group() + "\"" )
156156

157157
fprint( "" )
158158

159-
fprint( '#define MADFLIGHT_BOARD R""(' )
159+
fprint( 'const char* madflight_board = R""(' )
160+
fprint( 'imu_bus_type SPI' ) #all bf controllers use SPI
160161
for define in defines:
161162
fprint( define.strip() )
162-
fprint( ')"" //end of MADFLIGHT_BOARD' )
163+
fprint( ')""; //end of madflight_board' )
163164

164165
fprint( "" )
165166
fprint( "" )

src/madflight.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ SOFTWARE.
2828

2929
//#pragma once //don't use here, we want to get an error if this file is included twice
3030

31+
//const char* madflight_config = "..."; should be defined before including this file
32+
33+
#ifndef MF_BOARD_NAME
34+
const char* madflight_board = nullptr;
35+
#endif
36+
3137
// bus abstraction
3238
#include "madflight/hal/MF_Serial.h"
3339
#include "madflight/hal/MF_I2C.h"
@@ -67,14 +73,7 @@ void madflight_warn_or_die(String msg, bool die);
6773
// madflight_setup()
6874
//===============================================================================================
6975

70-
// madflight config string by defines MADFLIGHT_BOARD, MADFLIGHT_CONFIG
71-
#ifndef MADFLIGHT_BOARD
72-
#define MADFLIGHT_BOARD ""
73-
#endif
74-
#ifndef MADFLIGHT_CONFIG
75-
#define MADFLIGHT_CONFIG ""
76-
#endif
77-
const char* madflight_config = MADFLIGHT_BOARD MADFLIGHT_CONFIG;
76+
7877

7978
// vehicle setup by defines VEH_TYPE, VEH_FLIGHTMODE_AP_IDS, VEH_FLIGHTMODE_NAMES
8079
#ifndef VEH_TYPE
@@ -105,12 +104,12 @@ void madflight_setup() {
105104

106105
Serial.printf("Arduino library: " HAL_ARDUINO_STR "\n");
107106

108-
#ifdef HAL_BOARD_NAME
109-
Serial.println("Board: " HAL_BOARD_NAME);
107+
#ifdef MF_BOARD_NAME
108+
Serial.println("Board: " MF_BOARD_NAME);
110109
#endif
111110

112-
#ifdef HAL_MCU
113-
Serial.println("Processor: " HAL_MCU);
111+
#ifdef MF_MCU_NAME
112+
Serial.println("Processor: " MF_MCU_NAME);
114113
#endif
115114

116115
// CFG - Configuration parameters
@@ -121,13 +120,7 @@ void madflight_setup() {
121120
madflight_die("Config cleared. comment out '#define MF_CONFIG_CLEAR' and upload again.");
122121
#endif
123122
cfg.loadFromEeprom(); //load parameters from EEPROM
124-
if(madflight_config) {
125-
if(cfg.load_madflight_param(madflight_config)) {
126-
Serial.println("CFG: Loading MADFLIGHT_CONFIG - OK");
127-
}else{
128-
Serial.println("CFG: Loading MADFLIGHT_CONFIG - Skipped (EEPROM is newer than MADFLIGHT_CONFIG)");
129-
}
130-
}
123+
cfg.load_madflight(madflight_board, madflight_config); //load config
131124

132125
#ifdef MF_DEBUG
133126
if(madflight_config) {
@@ -152,6 +145,7 @@ void madflight_setup() {
152145

153146
cli.print_i2cScan(); //print i2c scan
154147

148+
// RCL - Radio Control Link
155149
rcl.config.gizmo = (Cfg::rcl_gizmo_enum)cfg.rcl_gizmo; //the gizmo to use
156150
rcl.config.ser_bus_id = cfg.rcl_ser_bus; //serial bus id
157151
rcl.config.baud = cfg.rcl_baud; //baud rate

src/madflight/cfg/cfg.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,34 @@ void CfgClass::loadFromString(const char *batch) {
406406
}
407407
}
408408

409-
//load text if crc is different, returns true when loaded
410-
bool CfgClass::load_madflight_param(const char *batch) {
411-
uint32_t crc = tbx_crc32((const uint8_t*)batch, strlen(batch));
412-
if(hdr.madflight_param_crc == crc) return false; //the parameters were already applied (and potentially modified since, so do not re-apply)
413-
loadFromString(batch);
409+
void CfgClass::load_madflight(const char *board, const char *config) {
410+
//calc crc
411+
uint32_t crc = 0xFFFFFFFF;
412+
if(board) crc = tbx_crc32((const uint8_t*)board, strlen(board), crc);
413+
if(config) crc = tbx_crc32((const uint8_t*)config, strlen(config), crc);
414+
415+
//check board+config crc against board+config crc stored in eeprom
416+
if(hdr.madflight_param_crc == crc) {
417+
//the board+config parameters were already applied (and potentially modified since, so do not re-apply)
418+
Serial.println("CFG: Skipping madflight_board + madflight_config (EEPROM is newer)");
419+
return;
420+
}
421+
422+
//load board + config
423+
Serial.print("CFG: ");
424+
if(board) {
425+
loadFromString(board);
426+
Serial.print("Loading madflight_board, ");
427+
}else{
428+
Serial.print("madflight_board is empty, ");
429+
}
430+
if(config) {
431+
loadFromString(config);
432+
Serial.println("loading madflight_config");
433+
}else{
434+
Serial.println("madflight_config is empty");
435+
}
414436
hdr.madflight_param_crc = crc; //save crc (and write it to eeprom with next CLI cwrite)
415-
return true;
416437
}
417438

418439
//returns true on success

src/madflight/cfg/cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class CfgClass : public CfgParam {
314314
void clear(); //load defaults from param_list
315315
void loadFromEeprom(); //read parameters from eeprom/flash
316316
void loadFromString(const char *batch); //load text unconditional
317-
bool load_madflight_param(const char *batch); //load text if crc is different, returns true when loaded
317+
void load_madflight(const char *board, const char *config); //load board+config if crc is different
318318
void writeToEeprom(); //write config to flash
319319
float getValue(String namestr, float default_value);
320320

src/madflight/hal/ESP32/hal_ESP32_cpp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
#define mf_df2str(s) mf_df2xstr(s)
1414
#define HAL_ARDUINO_STR "Arduino-ESP32 v" mf_df2str(ESP_ARDUINO_VERSION_MAJOR) "." mf_df2str(ESP_ARDUINO_VERSION_MINOR) "." mf_df2str(ESP_ARDUINO_VERSION_PATCH)
1515

16+
#ifndef MF_MCU_NAME
17+
#ifdef CONFIG_IDF_TARGET_ESP32S3
18+
#define MF_MCU_NAME "ESP32-S3"
19+
#elif defined CONFIG_IDF_TARGET_ESP32
20+
#define MF_MCU_NAME "ESP32"
21+
#else
22+
#define MF_MCU_NAME "ESP32 (unsupported type)"
23+
#endif
24+
#endif
25+
1626
//======================================================================================================================//
1727
// IMU
1828
//======================================================================================================================//

src/madflight/hal/RP2040/hal_RP2040_cpp.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//Arduino version string
22
#define HAL_ARDUINO_STR "Arduino-Pico v" ARDUINO_PICO_VERSION_STR
33

4-
#ifndef HAL_MCU
4+
#ifndef MF_MCU_NAME
55
#ifdef PICO_RP2350
6-
#define HAL_MCU "RP2350"
6+
#define MF_MCU_NAME "RP2350"
77
#else
8-
#define HAL_MCU "RP2040"
8+
#define MF_MCU_NAME "RP2040"
99
#endif
1010
#endif
1111

0 commit comments

Comments
 (0)