@@ -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
3838const 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
7170void madflight_die (String msg );
7271void madflight_warn (String msg );
7372void madflight_warn_or_die (String msg , bool die );
@@ -79,7 +78,7 @@ void madflight_warn_or_die(String msg, bool die);
7978void 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}
0 commit comments