Skip to content

Commit c12e4c5

Browse files
committed
gizmoize bbx
1 parent 19131ed commit c12e4c5

File tree

26 files changed

+1194
-1269
lines changed

26 files changed

+1194
-1269
lines changed

examples/02.QuadcopterAdvanced/madflight_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ imu_i2c_bus -1
180180
// COMPILER OPTIONS //
181181
//========================================================================================================================//
182182

183+
#define BBX_USE BBX_USE_SDSPI
184+
183185
//-- AHRS sensor fusion
184186
#define AHR_USE AHR_USE_MAHONY // Select one: AHRS_USE_MAHONY, AHRS_USE_MAHONY_BF, AHRS_USE_MADGWICK, AHRS_USE_VQF
185187

src/madflight.h

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SOFTWARE.
2828

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

31-
//madflight config string
31+
// madflight config string
3232
#ifndef MADFLIGHT_BOARD
3333
#define MADFLIGHT_BOARD ""
3434
#endif
@@ -37,14 +37,13 @@ SOFTWARE.
3737
#endif
3838
const char* madflight_config = MADFLIGHT_BOARD MADFLIGHT_CONFIG;
3939

40-
//bus abstraction
40+
// bus abstraction
4141
#include "madflight/hal/MF_Serial.h"
4242
#include "madflight/hal/MF_I2C.h"
4343

44-
//include all "_cpp.h" modules which have compile time config options
44+
// include all "_cpp.h" modules which have compile time config options
4545
#define MF_ALLOW_INCLUDE_CCP_H
46-
#include "madflight/cfg/cfg_cpp.h" //include this first, because cfg.xxx parameters are used by other "_cpp.h" modules
47-
#include "madflight/bbx/bbx_cpp.h"
46+
#include "madflight/cfg/cfg_cpp.h" //include this first, because cfg.xxx parameters are used by other "_cpp.h" modules
4847
#include "madflight/ahr/ahr_cpp.h"
4948
#include "madflight/alt/alt_cpp.h"
5049
#include "madflight/cli/cli_cpp.h"
@@ -53,21 +52,21 @@ const char* madflight_config = MADFLIGHT_BOARD MADFLIGHT_CONFIG;
5352
#include "madflight/rcl/rcl_cpp.h"
5453
#undef MF_ALLOW_INCLUDE_CCP_H
5554

56-
//include all other modules without compile time config options
55+
// include all other modules without compile time config options
5756
#include "madflight/bar/bar.h"
5857
#include "madflight/bat/bat.h"
58+
#include "madflight/bbx/bbx.h"
5959
#include "madflight/gps/gps.h"
6060
#include "madflight/led/led.h"
6161
#include "madflight/mag/mag.h"
6262
#include "madflight/out/out.h"
6363
#include "madflight/pid/pid.h"
64-
6564
#include "madflight/veh/veh.h"
6665

67-
//toolbox
66+
// toolbox
6867
#include "madflight/tbx/RuntimeTrace.h"
6968

70-
//prototypes
69+
// prototypes
7170
void madflight_die(String msg);
7271
void madflight_warn(String msg);
7372
void madflight_warn_or_die(String msg, bool die);
@@ -79,7 +78,7 @@ void madflight_warn_or_die(String msg, bool die);
7978
void madflight_setup() {
8079
Serial.begin(115200); //start console serial
8180

82-
//6 second startup delay
81+
// 6 second startup delay
8382
for(int i = 12; i > 0; i--) {
8483
Serial.printf(MADFLIGHT_VERSION " starting %d ...\n", i);
8584
#ifndef MF_DEBUG
@@ -99,6 +98,7 @@ void madflight_setup() {
9998
Serial.println("Processor: " HAL_MCU);
10099
#endif
101100

101+
// CFG - Configuration parameters
102102
cfg.begin();
103103
#ifdef MF_CONFIG_CLEAR
104104
cfg.clear();
@@ -118,14 +118,14 @@ void madflight_setup() {
118118
}
119119
cfg.printPins();
120120

121-
//setup LED
121+
// LED - Setup LED
122122
led.config.pin = cfg.pin_led;
123123
led.config.on_value = cfg.led_on;
124124
led.setup();
125125
led.on(); //turn on to signal startup
126126
led.enabled = false; //do not change state until setup compled
127127

128-
//hardware abstraction layer setup: serial, spi, i2c (see hal.h)
128+
// HAL - Hardware abstraction layer setup: serial, spi, i2c (see hal.h)
129129
hal_setup();
130130

131131
cli.print_i2cScan(); //print i2c scan
@@ -136,21 +136,21 @@ void madflight_setup() {
136136
rcl.config.ppm_pin = cfg.getValue("pin_ser" + String(cfg.rcl_ser_bus) + "_rx", -1);
137137
rcl.setup(); //Initialize radio communication.
138138

139-
//Barometer
139+
// BAR - Barometer
140140
bar.config.gizmo = (Cfg::bar_gizmo_enum)cfg.bar_gizmo; //the gizmo to use
141141
bar.config.i2c_bus = hal_get_i2c_bus(cfg.bar_i2c_bus); //i2c bus
142142
bar.config.i2c_adr = cfg.bar_i2c_adr; //i2c address. 0=default address
143143
bar.config.sampleRate = 100; //sample rate [Hz]
144144
bar.setup();
145145

146-
//External Magnetometer
146+
// MAG - External Magnetometer
147147
mag.config.gizmo = (Cfg::mag_gizmo_enum)cfg.mag_gizmo; //the gizmo to use
148148
mag.config.i2c_bus = hal_get_i2c_bus(cfg.mag_i2c_bus); //i2c bus
149149
mag.config.i2c_adr = cfg.mag_i2c_adr; //i2c address. 0=default address
150150
mag.config.sampleRate = 100; //sample rate [Hz]
151151
mag.setup();
152152

153-
//Battery Monitor
153+
// BAT - Battery Monitor
154154
bat.config.gizmo = (Cfg::bat_gizmo_enum)cfg.bat_gizmo; //the gizmo to use
155155
bat.config.i2c_bus = hal_get_i2c_bus(cfg.bat_i2c_bus); //i2c bus
156156
bat.config.i2c_adr = cfg.bat_i2c_adr; //i2c address. 0=default address
@@ -162,30 +162,36 @@ void madflight_setup() {
162162
bat.config.rshunt = cfg.bat_cal_i;
163163
bat.setup();
164164

165-
//GPS
165+
// GPS
166166
gps.config.gizmo = (Cfg::gps_gizmo_enum)cfg.gps_gizmo; //the gizmo to use
167167
gps.config.ser_bus = hal_get_ser_bus(cfg.gps_ser_bus); //serial bus
168168
gps.config.baud = cfg.gps_baud; //baud rate
169169
gps.setup();
170170

171-
//Black Box
171+
// BBX - Black Box
172+
bbx.config.gizmo = (Cfg::bbx_gizmo_enum)cfg.bbx_gizmo; //the gizmo to use
173+
bbx.config.spi_bus = hal_get_spi_bus(cfg.bbx_spi_bus); //SPI bus
174+
bbx.config.spi_cs = cfg.pin_bbx_cs; //SPI select pin
175+
bbx.config.pin_mmc_dat = cfg.pin_mmc_dat;
176+
bbx.config.pin_mmc_clk = cfg.pin_mmc_clk;
177+
bbx.config.pin_mmc_cmd = cfg.pin_mmc_cmd;
172178
bbx.setup();
173179

174-
//Altitude Estimator
180+
// ALT - Altitude Estimator
175181
alt.setup(bar.alt);
176182

177-
//setup low pass filters for AHRS filters
183+
// AHR - setup low pass filters for AHRS filters
178184
ahr.setup(cfg.imu_gyr_lp, cfg.imu_acc_lp, cfg.mag_lp);
179185

180-
//IMU
186+
// IMU - Intertial Measurement Unit (gyro/acc/mag)
181187
imu.config.sampleRate = cfg.imu_rate; //sample rate [Hz]
182188
imu.config.pin_int = cfg.pin_imu_int; //IMU data ready interrupt pin
183189
imu.config.gizmo = (Cfg::imu_gizmo_enum)cfg.imu_gizmo; //the gizmo to use
184190
imu.config.spi_bus = hal_get_spi_bus(cfg.imu_spi_bus); //SPI bus
185191
imu.config.spi_cs = cfg.pin_imu_cs; //SPI select pin
186192
imu.config.i2c_bus = hal_get_i2c_bus(cfg.imu_i2c_bus); //I2C bus (only used if spi_bus==nullptr)
187193
imu.config.i2c_adr = cfg.imu_i2c_adr; //i2c address. 0=default address
188-
//Some sensors need a couple of tries...
194+
// Some sensors need a couple of tries...
189195
int tries = 10;
190196
while(true) {
191197
int rv = imu.setup(); //request 1000 Hz sample rate, returns 0 on success, positive on error, negative on warning
@@ -196,7 +202,7 @@ void madflight_setup() {
196202
if(!imu.installed() && (Cfg::imu_gizmo_enum)cfg.imu_gizmo != Cfg::imu_gizmo_enum::mf_NONE) {
197203
madflight_die("IMU install failed.");
198204
}
199-
//start IMU update handler
205+
// start IMU update handler
200206
if(imu.installed()) {
201207
ahr.setInitalOrientation(); //do this before IMU update handler is started
202208

@@ -210,10 +216,10 @@ void madflight_setup() {
210216
#endif
211217
}
212218

213-
//CLI - command line interface
219+
// CLI - Command Line Interface
214220
cli.begin();
215221

216-
//Enable LED, and switch it off signal end of startup.
222+
// Enable LED, and switch it off signal end of startup.
217223
led.enabled = true;
218224
led.off();
219225
}

src/madflight/ahr/ahr_cpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOFTWARE.
2424

2525
//This file is kept as header to allow #AHR_xxx defines to be added in user code (Arduino IDE has no easy way to add -D compiler options)
2626

27-
// Make sure this file is includes from madflight.h and not from somewhere else
27+
// Make sure this file is included from madflight.h and not from somewhere else
2828
#ifndef MF_ALLOW_INCLUDE_CCP_H
2929
#error "Only include this file from madflight.h"
3030
#endif

src/madflight/alt/alt_cpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SOFTWARE.
2626
Each ALT_USE_xxx section in this file defines a specific altimeter estimator class
2727
=================================================================================================*/
2828

29-
// Make sure this file is includes from madflight.h and not from somewhere else
29+
// Make sure this file is included from madflight.h and not from somewhere else
3030
#ifndef MF_ALLOW_INCLUDE_CCP_H
3131
#error "Only include this file from madflight.h"
3232
#endif

src/madflight/bbx/bbx_sdcard/BBFS_SD_ESP32.h renamed to src/madflight/bbx/BbxGizmoSdspi+Sdmmc_ESP32.h

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,39 @@
1-
/*==========================================================================================
2-
BBFS_SD_ESP32.h: madflight sdcard spi/mmc logging file system
31

4-
MIT License
2+
#include "bbx.h"
53

6-
Copyright (c) 2024 qqqlab - https://github.com/qqqlab
7-
8-
Permission is hereby granted, free of charge, to any person obtaining a copy
9-
of this software and associated documentation files (the "Software"), to deal
10-
in the Software without restriction, including without limitation the rights
11-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12-
copies of the Software, and to permit persons to whom the Software is
13-
furnished to do so, subject to the following conditions:
14-
15-
The above copyright notice and this permission notice shall be included in all
16-
copies or substantial portions of the Software.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24-
SOFTWARE.
25-
===========================================================================================*/
26-
27-
28-
#if BB_USE == BB_USE_SDMMC
4+
#ifdef BBX_USE_MMC
295

306
#include "SD_MMC.h"
317

328
#define _BB_SDFS SD_MMC
339
#define _BB_SETUP_STR "BBX: SDMMC"
3410

11+
class BbxGizmoSdmmc : public BbxGizmo {
12+
13+
public:
14+
BbxGizmoSdmmc(BbxConfig *config) {
15+
this->config = config;
16+
}
17+
3518
#else
3619

3720
#include "SPI.h"
3821
#include "SD.h"
3922

4023
#define _BB_SDFS SD
41-
#define _BB_SETUP_STR "BBX: SD"
42-
extern SPIClass *bbx_spi;
24+
#define _BB_SETUP_STR "BBX: SDSPI"
25+
26+
class BbxGizmoSdspi : public BbxGizmo {
27+
public:
28+
BbxGizmoSdspi(BbxConfig *config) {
29+
this->config = config;
30+
}
4331

4432
#endif
4533

46-
class BBFS_SD : public BBFS {
34+
4735
private:
36+
BbxConfig *config;
4837
const char* BB_LOG_DIR_NAME = "/log";
4938
bool setup_done = false;
5039
uint8_t wbuf[512];
@@ -214,16 +203,15 @@ class BBFS_SD : public BBFS {
214203

215204
_BB_SDFS.end(); //force begin() to re-initialize
216205

217-
#if BB_USE == BB_USE_SDMMC
218-
_BB_SDFS.setPins(HW_PIN_SDMMC_CLK, HW_PIN_SDMMC_CMD, HW_PIN_SDMMC_DATA);
206+
#ifdef BBX_USE_MMC
207+
_BB_SDFS.setPins(config->pin_mmc_clk, config->pin_mmc_cmd, config->pin_mmc_dat);
219208
if (!_BB_SDFS.begin("/sdcard", true, true, SDMMC_FREQ_DEFAULT, 5)) {
220-
Serial.println("BBX: BB_USE_SDMMC Card Mount Failed");
209+
Serial.println("BBX: SDMMC Card Mount Failed");
221210
return setup_done;
222211
}
223212
#else
224-
bbx_spi->begin(HW_PIN_SPI2_SCLK, HW_PIN_SPI2_MISO, HW_PIN_SPI2_MOSI, HW_PIN_BB_CS);
225-
if (!_BB_SDFS.begin(HW_PIN_BB_CS, *bbx_spi)) {
226-
Serial.println("BBX: BB_USE_SD Card Mount Failed");
213+
if (!_BB_SDFS.begin(config->spi_cs, *config->spi_bus)) {
214+
Serial.println("BBX: SDSPI Card Mount Failed");
227215
return setup_done;
228216
}
229217
#endif
@@ -312,4 +300,8 @@ class BBFS_SD : public BBFS {
312300
Serial.println(filename);
313301
file = _BB_SDFS.open(filename, FILE_WRITE, true);
314302
}
315-
};
303+
};
304+
305+
306+
#undef _BB_SDFS
307+
#undef _BB_SETUP_STR

0 commit comments

Comments
 (0)