@@ -99,11 +99,10 @@ const uint8_t Veh::flightmode_ap_ids[6] = VEH_FLIGHTMODE_AP_IDS; //mapping from
9999const char * Veh ::flightmode_names [6 ] = VEH_FLIGHTMODE_NAMES ; //define flightmode name strings for telemetry
100100
101101void madflight_setup () {
102- hal_startup (); //setup USB CDC/MSC and do other things which have to be done first
103-
104- Serial .begin (115200 ); //start console serial
105-
106- // CFG - Configuration parameters (execute before delay to start LED)
102+ // HAL - Detach USB to until SDCARD is setup
103+ hal_startup ();
104+
105+ // CFG - Configuration parameters (execute before delay to start LED + SDCARD)
107106 cfg .begin ();
108107 #ifdef MF_CONFIG_CLEAR
109108 cfg .clear ();
@@ -113,14 +112,14 @@ void madflight_setup() {
113112 cfg .loadFromEeprom (); //load parameters from EEPROM
114113 cfg .load_madflight (madflight_board , madflight_config ); //load config
115114
116- // LED - Setup LED (execute before delay)
115+ // LED - Setup LED (execute before delay to turn it on )
117116 led .config .gizmo = (Cfg ::led_gizmo_enum )cfg .led_gizmo ;
118117 led .config .pin = cfg .pin_led ;
119118 led .setup ();
120119 led .color (0x0000ff ); //turn on blue to signal startup
121120 led .enabled = false; //do not change state until setup compled
122121
123- // BBX - Black Box (execute before delay to start USB-MSC)
122+ // BBX - Black Box (execute before delay to start USB-MSC if card is inserted )
124123 bbx .config .gizmo = (Cfg ::bbx_gizmo_enum )cfg .bbx_gizmo ; //the gizmo to use
125124 bbx .config .spi_bus = hal_get_spi_bus (cfg .bbx_spi_bus ); //SPI bus
126125 bbx .config .spi_cs = cfg .pin_bbx_cs ; //SPI select pin
@@ -129,10 +128,16 @@ void madflight_setup() {
129128 bbx .config .pin_mmc_cmd = cfg .pin_mmc_cmd ;
130129 bbx .setup ();
131130
132- // 6 second startup delay
131+ // USB - Start USB-CDC (Serial) and USB-MSC (if sdcard is inserted)
132+ hal_usb_setup ();
133+
134+ // Serial - Start serial console
135+ Serial .begin (115200 );
136+
137+ // Delay - 6 second startup delay
133138 for (int i = 12 ; i > 0 ; i -- ) {
134139 Serial .printf (MADFLIGHT_VERSION " starting %d ...\n" , i );
135- Serial .flush ();
140+ Serial .flush ();
136141 #ifndef MF_DEBUG
137142 delay (500 );
138143 #else
@@ -161,12 +166,13 @@ void madflight_setup() {
161166 // HAL - Hardware abstraction layer setup: serial, spi, i2c (see hal.h)
162167 hal_setup ();
163168
169+ // I2C - Show i2c devices
164170 cli .print_i2cScan (); //print i2c scan
165171
166172 // LED and BBX summary
167173 cfg .printModule ("led" );
168174 bbx .printSummary ();
169-
175+
170176 // RCL - Radio Control Link
171177 rcl .config .gizmo = (Cfg ::rcl_gizmo_enum )cfg .rcl_gizmo ; //the gizmo to use
172178 rcl .config .ser_bus_id = cfg .rcl_ser_bus ; //serial bus id
@@ -200,7 +206,7 @@ void madflight_setup() {
200206 bat .config .rshunt = cfg .bat_cal_i ;
201207 bat .setup ();
202208
203- //RDR
209+ // RDR - Radar/Lidar/Sonar sensors
204210 rdr .config .gizmo = (Cfg ::rdr_gizmo_enum )cfg .rdr_gizmo ; //the gizmo to use
205211 rdr .config .rdr_ser_bus = cfg .rdr_ser_bus ; //serial bus
206212 rdr .config .rdr_baud = cfg .rdr_baud ; //baud rate
@@ -210,7 +216,7 @@ void madflight_setup() {
210216 rdr .config .rdr_i2c_adr = cfg .rdr_i2c_adr ;
211217 rdr .setup ();
212218
213- //OFL
219+ // OFL - Optical flow sensor
214220 ofl .config .ofl_gizmo = (Cfg ::ofl_gizmo_enum )cfg .ofl_gizmo ; //the gizmo to use
215221 ofl .config .ofl_spi_bus = cfg .ofl_spi_bus ; // spi bus
216222 ofl .config .pin_ofl_cs = cfg .pin_ofl_cs ; // spi cs pin
@@ -257,7 +263,7 @@ void madflight_setup() {
257263 imu .config .uses_i2c = ((Cfg ::imu_bus_type_enum )cfg .imu_bus_type == Cfg ::imu_bus_type_enum ::mf_I2C );
258264 imu .config .pin_clkin = cfg .pin_imu_clkin ; //CLKIN pin for ICM-42866-P - only tested for RP2 targets
259265
260- // Some sensors need a couple of tries...
266+ // Some IMU sensors need a couple of tries...
261267 int tries = 10 ;
262268 while (true) {
263269 int rv = imu .setup (); //request 1000 Hz sample rate, returns 0 on success, positive on error, negative on warning
@@ -268,7 +274,7 @@ void madflight_setup() {
268274 if (!imu .installed () && (Cfg ::imu_gizmo_enum )cfg .imu_gizmo != Cfg ::imu_gizmo_enum ::mf_NONE ) {
269275 madflight_die ("IMU install failed." );
270276 }
271- // start IMU update handler
277+ // Start IMU update handler
272278 if (imu .installed ()) {
273279 ahr .setInitalOrientation (); //do this before IMU update handler is started
274280
@@ -277,12 +283,12 @@ void madflight_setup() {
277283 if (!imu .waitNewSample ()) madflight_die ("IMU interrupt not firing. Is pin 'pin_imu_int' connected?" );
278284
279285 #ifndef MF_DEBUG
280- // switch off LED to signal calibration
286+ // Switch off LED to signal calibration
281287 led .enabled = true;
282288 led .off ();
283289 led .enabled = false;
284290
285- //Calibrate for zero gyro readings, assuming vehicle not moving when powered up. Comment out to only use cfg values. (Use CLI to calibrate acc.)
291+ // Calibrate for zero gyro readings, assuming vehicle not moving when powered up. Comment out to only use cfg values. (Use CLI to calibrate acc.)
286292 cli .calibrate_gyro ();
287293 #endif
288294 }
@@ -293,7 +299,7 @@ void madflight_setup() {
293299 // CLI - Command Line Interface
294300 cli .begin ();
295301
296- // Enable LED, and switch it to green to signal end of startup.
302+ // LED - Enable and switch it to green to signal end of startup.
297303 led .enabled = true;
298304 led .color (0x00ff00 ); //switch color to green
299305 led .on ();
0 commit comments