diff --git a/platformio.ini b/platformio.ini index 5d894097..f170f80a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/bbx/BbxGizmoOpenlog.h b/src/bbx/BbxGizmoOpenlog.h new file mode 100644 index 00000000..f0bf5b2a --- /dev/null +++ b/src/bbx/BbxGizmoOpenlog.h @@ -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;} +}; diff --git a/src/bbx/bbx.cpp b/src/bbx/bbx.cpp index d3beb32a..9ebe47e8 100644 --- a/src/bbx/bbx.cpp +++ b/src/bbx/bbx.cpp @@ -26,6 +26,7 @@ SOFTWARE. #include "../madflight_modules.h" #include "BinLogWriter.h" +#include "BbxGizmoOpenlog.h" //create global module instance Bbx bbx; @@ -38,12 +39,8 @@ 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"); @@ -51,7 +48,6 @@ Bbx bbx; pio_registry_name_unclaimed("Sdcard"); break; } - return 0; } #elif defined ARDUINO_ARCH_ESP32 @@ -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(); diff --git a/src/bbx/bbx.h b/src/bbx/bbx.h index 3fe58d8b..17935934 100644 --- a/src/bbx/bbx.h +++ b/src/bbx/bbx.h @@ -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 @@ -64,7 +66,7 @@ class BbxGizmo { class Bbx { private: - int gizmo_create(); + void gizmo_create_sd(); public: BbxConfig config; diff --git a/src/cfg/cfg.h b/src/cfg/cfg.h index 1b2a555c..54e48e28 100644 --- a/src/cfg/cfg.h +++ b/src/cfg/cfg.h @@ -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*/ \ @@ -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 diff --git a/src/madflight.h b/src/madflight.h index 64c86475..b9999132 100644 --- a/src/madflight.h +++ b/src/madflight.h @@ -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)