Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ build_flags =
-D PIO_FRAMEWORK_ARDUINO_ENABLE_FREERTOS ; Required: Enable FreeRTOS
; -D USE_TINYUSB ; Optional but not recommended: It adds USB SDCARD mass storage, but USB Serial does not work nicely with USE_TINYUSB

; Use arduino-pico version 5 or later. A fixed version is used here, not #master, to prevent long downloads each time the source repository is updated
platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#5.5.0
; Use arduino-pico version 5 or later. A fixed version is used here, not #master, to prevent long downloads when the source repository is updated
platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#5.5.1

; Optional: Debugprobe debugger - see Appendix A "Getting started with Raspberry Pi Pico-series"
;debug_tool = cmsis-dap
Expand Down
72 changes: 72 additions & 0 deletions src/bbx/BbxGizmoOpenlog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*==========================================================================================
MIT License

Copyright (c) 2026 https://madflight.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
===========================================================================================*/

#pragma once

#include "bbx.h"
#include "../hal/hal.h"

class BbxGizmoOpenlog : public BbxGizmo {
private:
BbxConfig *config;
MF_Serial *ser;
BbxGizmoOpenlog() {} //private constructor

public:
static BbxGizmoOpenlog* create(BbxConfig *config) {
if(config->bbx_baud <= 0) config->bbx_baud = 115200;
MF_Serial *ser = hal_get_ser_bus(config->bbx_ser_bus, config->bbx_baud);
if(!ser) {
Serial.println("BBX: ERROR invalid serial port");
return nullptr;
}
auto gizmo = new BbxGizmoOpenlog();
gizmo->config = config;
gizmo->ser = ser;
return gizmo;
}

void write(const uint8_t *buf, const uint8_t len) override {
ser->write((uint8_t*)buf, len);
}

void printSummary() override {
Serial.printf("BBX: Openlog on serial%d at %d baud\n", config->bbx_ser_bus, config->bbx_baud);
}

void info() override {
printSummary();
}

bool writeOpen() override {
return true;
}

void setup() override {}
void close() override {}
void erase() override {}
void dir() override {}
void bench() override {}
int read(const char* filename, uint8_t **data) override {return 0;}
};
38 changes: 16 additions & 22 deletions src/bbx/bbx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ SOFTWARE.

#include "../madflight_modules.h"
#include "BinLogWriter.h"
#include "BbxGizmoOpenlog.h"

//create global module instance
Bbx bbx;
Expand All @@ -38,20 +39,15 @@ Bbx bbx;
#include "BbxGizmoSdcard_RP2.h"
#include "../hal/RP2040/pio_registry.h"

int Bbx::gizmo_create() {
//create gizmo
delete gizmo;
void Bbx::gizmo_create_sd() {
switch(config.gizmo) {
case Cfg::bbx_gizmo_enum::mf_NONE :
break;
case Cfg::bbx_gizmo_enum::mf_SDSPI :
case Cfg::bbx_gizmo_enum::mf_SDMMC :
pio_registry_name_unclaimed("1Sdcard");
gizmo = BbxGizmoSdcard::create(&config); //Note: Sdfat claims a full PIO including 4 SM
pio_registry_name_unclaimed("Sdcard");
break;
}
return 0;
}

#elif defined ARDUINO_ARCH_ESP32
Expand All @@ -61,42 +57,40 @@ Bbx bbx;
#undef BBX_USE_MMC
#include "BbxGizmoSdspi+Sdmmc_ESP32.h"

int Bbx::gizmo_create() {
//create gizmo
void Bbx::gizmo_create_sd() {
switch(config.gizmo) {
case Cfg::bbx_gizmo_enum::mf_NONE :
break;
case Cfg::bbx_gizmo_enum::mf_SDSPI :
gizmo = new BbxGizmoSdspi(&config);
break;
case Cfg::bbx_gizmo_enum::mf_SDMMC :
gizmo = new BbxGizmoSdmmc(&config);
break;
return -1001;
break;
}
return 0;
}

#else
int Bbx::gizmo_create() {
if(config.gizmo != Cfg::bbx_gizmo_enum::mf_NONE) {
Serial.println("\n" MF_MOD ": ERROR BBX not available for this processor\n");
return -1001;
}
return 0;
void Bbx::gizmo_create_sd() {
Serial.println("\n" MF_MOD ": ERROR BBX not available for this processor\n");
}
#endif


int Bbx::setup() {
cfg.printModule(MF_MOD);

//create gizmo
delete gizmo;
gizmo = nullptr;
int rv = gizmo_create();
if(rv!=0) return rv;
switch(config.gizmo) {
case Cfg::bbx_gizmo_enum::mf_NONE :
break;
case Cfg::bbx_gizmo_enum::mf_SDSPI :
case Cfg::bbx_gizmo_enum::mf_SDMMC :
gizmo_create_sd();
break;
case Cfg::bbx_gizmo_enum::mf_OPENLOG :
gizmo = BbxGizmoOpenlog::create(&config);
break;
}

//setup BinLogWriter
BinLogWriter::setup();
Expand Down
6 changes: 4 additions & 2 deletions src/bbx/bbx.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ struct BbxConfig {
int32_t pin_mmc_dat = -1;
int32_t pin_mmc_clk = -1;
int32_t pin_mmc_cmd = -1;
int32_t bbx_ser_bus = -1;
int32_t bbx_baud = 0;
};

class BbxGizmo {
public:
virtual ~BbxGizmo() {}
virtual void setup() = 0; //setup the file system (can be called multiple times)
virtual void setup() = 0; //setup the gizmo

virtual bool writeOpen() = 0; //create new file for writing (closes previously opened file first)
virtual void write(const uint8_t *buf, const uint8_t len) = 0; //write to file
Expand All @@ -64,7 +66,7 @@ class BbxGizmo {

class Bbx {
private:
int gizmo_create();
void gizmo_create_sd();

public:
BbxConfig config;
Expand Down
6 changes: 5 additions & 1 deletion src/cfg/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ SOFTWARE.
MF_PARAM( bat_i2c_adr, 0, int32_t, 'i') \
\
/*BBX - Black Box Data Logger*/ \
MF_PARAM( bbx_gizmo, 0, int32_t, 'e', mf_NONE,mf_SDSPI,mf_SDMMC) \
MF_PARAM( bbx_gizmo, 0, int32_t, 'e', mf_NONE,mf_SDSPI,mf_SDMMC,mf_OPENLOG) \
MF_PARAM( bbx_spi_bus, -1, int32_t, 'i') \
\
/*GPS*/ \
Expand Down Expand Up @@ -264,6 +264,10 @@ SOFTWARE.
MF_PARAM( bbx_log_out, 100, int32_t, 'i') /* Max log interval in [Hz] for OUT*/ \
MF_PARAM( bbx_log_ahr, 100, int32_t, 'i') /* Max log interval in [Hz] for AHR*/ \
MF_PARAM( bbx_log_rcl, 100, int32_t, 'i') /* Max log interval in [Hz] for RCL*/ \
\
/*v2.3.1 additions */ \
MF_PARAM( bbx_ser_bus, -1, int32_t, 'i') \
MF_PARAM( bbx_baud, 0, int32_t, 'i') \
\
//end MF_PARAM_LIST

Expand Down
2 changes: 2 additions & 0 deletions src/madflight.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ void madflight_setup() {
bbx.config.pin_mmc_dat = cfg.pin_mmc_dat;
bbx.config.pin_mmc_clk = cfg.pin_mmc_clk;
bbx.config.pin_mmc_cmd = cfg.pin_mmc_cmd;
bbx.config.bbx_ser_bus = cfg.bbx_ser_bus;
bbx.config.bbx_baud = cfg.bbx_baud;
bbx.setup();

// USB - Start USB-CDC (Serial) and USB-MSC (if sdcard is inserted)
Expand Down