Skip to content

Commit d295ac9

Browse files
committed
.
1 parent d92979a commit d295ac9

File tree

6 files changed

+101
-27
lines changed

6 files changed

+101
-27
lines changed

platformio.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ build_flags =
6666
-D PIO_FRAMEWORK_ARDUINO_ENABLE_FREERTOS ; Required: Enable FreeRTOS
6767
; -D USE_TINYUSB ; Optional but not recommended: It adds USB SDCARD mass storage, but USB Serial does not work nicely with USE_TINYUSB
6868

69-
; 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
70-
platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#5.5.0
69+
; 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
70+
platform_packages = framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#5.5.1
7171

7272
; Optional: Debugprobe debugger - see Appendix A "Getting started with Raspberry Pi Pico-series"
7373
;debug_tool = cmsis-dap

src/bbx/BbxGizmoOpenlog.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*==========================================================================================
2+
MIT License
3+
4+
Copyright (c) 2026 https://madflight.com
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
===========================================================================================*/
24+
25+
#pragma once
26+
27+
#include "bbx.h"
28+
#include "../hal/hal.h"
29+
30+
class BbxGizmoOpenlog : public BbxGizmo {
31+
private:
32+
BbxConfig *config;
33+
MF_Serial *ser;
34+
BbxGizmoOpenlog() {} //private constructor
35+
36+
public:
37+
static BbxGizmoOpenlog* create(BbxConfig *config) {
38+
if(config->bbx_baud <= 0) config->bbx_baud = 115200;
39+
MF_Serial *ser = hal_get_ser_bus(config->bbx_ser_bus, config->bbx_baud);
40+
if(!ser) {
41+
Serial.println("BBX: ERROR invalid serial port");
42+
return nullptr;
43+
}
44+
auto gizmo = new BbxGizmoOpenlog();
45+
gizmo->config = config;
46+
gizmo->ser = ser;
47+
return gizmo;
48+
}
49+
50+
void write(const uint8_t *buf, const uint8_t len) override {
51+
ser->write((uint8_t*)buf, len);
52+
}
53+
54+
void printSummary() override {
55+
Serial.printf("BBX: Openlog on serial%d at %d baud\n", config->bbx_ser_bus, config->bbx_baud);
56+
}
57+
58+
void info() override {
59+
printSummary();
60+
}
61+
62+
bool writeOpen() override {
63+
return true;
64+
}
65+
66+
void setup() override {}
67+
void close() override {}
68+
void erase() override {}
69+
void dir() override {}
70+
void bench() override {}
71+
int read(const char* filename, uint8_t **data) override {return 0;}
72+
};

src/bbx/bbx.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ SOFTWARE.
2626

2727
#include "../madflight_modules.h"
2828
#include "BinLogWriter.h"
29+
#include "BbxGizmoOpenlog.h"
2930

3031
//create global module instance
3132
Bbx bbx;
@@ -38,20 +39,15 @@ Bbx bbx;
3839
#include "BbxGizmoSdcard_RP2.h"
3940
#include "../hal/RP2040/pio_registry.h"
4041

41-
int Bbx::gizmo_create() {
42-
//create gizmo
43-
delete gizmo;
42+
void Bbx::gizmo_create_sd() {
4443
switch(config.gizmo) {
45-
case Cfg::bbx_gizmo_enum::mf_NONE :
46-
break;
4744
case Cfg::bbx_gizmo_enum::mf_SDSPI :
4845
case Cfg::bbx_gizmo_enum::mf_SDMMC :
4946
pio_registry_name_unclaimed("1Sdcard");
5047
gizmo = BbxGizmoSdcard::create(&config); //Note: Sdfat claims a full PIO including 4 SM
5148
pio_registry_name_unclaimed("Sdcard");
5249
break;
5350
}
54-
return 0;
5551
}
5652

5753
#elif defined ARDUINO_ARCH_ESP32
@@ -61,42 +57,40 @@ Bbx bbx;
6157
#undef BBX_USE_MMC
6258
#include "BbxGizmoSdspi+Sdmmc_ESP32.h"
6359

64-
int Bbx::gizmo_create() {
65-
//create gizmo
60+
void Bbx::gizmo_create_sd() {
6661
switch(config.gizmo) {
67-
case Cfg::bbx_gizmo_enum::mf_NONE :
68-
break;
6962
case Cfg::bbx_gizmo_enum::mf_SDSPI :
7063
gizmo = new BbxGizmoSdspi(&config);
7164
break;
7265
case Cfg::bbx_gizmo_enum::mf_SDMMC :
7366
gizmo = new BbxGizmoSdmmc(&config);
7467
break;
75-
return -1001;
76-
break;
7768
}
78-
return 0;
7969
}
8070

8171
#else
82-
int Bbx::gizmo_create() {
83-
if(config.gizmo != Cfg::bbx_gizmo_enum::mf_NONE) {
84-
Serial.println("\n" MF_MOD ": ERROR BBX not available for this processor\n");
85-
return -1001;
86-
}
87-
return 0;
72+
void Bbx::gizmo_create_sd() {
73+
Serial.println("\n" MF_MOD ": ERROR BBX not available for this processor\n");
8874
}
8975
#endif
9076

91-
9277
int Bbx::setup() {
9378
cfg.printModule(MF_MOD);
9479

9580
//create gizmo
9681
delete gizmo;
9782
gizmo = nullptr;
98-
int rv = gizmo_create();
99-
if(rv!=0) return rv;
83+
switch(config.gizmo) {
84+
case Cfg::bbx_gizmo_enum::mf_NONE :
85+
break;
86+
case Cfg::bbx_gizmo_enum::mf_SDSPI :
87+
case Cfg::bbx_gizmo_enum::mf_SDMMC :
88+
gizmo_create_sd();
89+
break;
90+
case Cfg::bbx_gizmo_enum::mf_OPENLOG :
91+
gizmo = BbxGizmoOpenlog::create(&config);
92+
break;
93+
}
10094

10195
//setup BinLogWriter
10296
BinLogWriter::setup();

src/bbx/bbx.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ struct BbxConfig {
4242
int32_t pin_mmc_dat = -1;
4343
int32_t pin_mmc_clk = -1;
4444
int32_t pin_mmc_cmd = -1;
45+
int32_t bbx_ser_bus = -1;
46+
int32_t bbx_baud = 0;
4547
};
4648

4749
class BbxGizmo {
4850
public:
4951
virtual ~BbxGizmo() {}
50-
virtual void setup() = 0; //setup the file system (can be called multiple times)
52+
virtual void setup() = 0; //setup the gizmo
5153

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

6567
class Bbx {
6668
private:
67-
int gizmo_create();
69+
void gizmo_create_sd();
6870

6971
public:
7072
BbxConfig config;

src/cfg/cfg.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ SOFTWARE.
196196
MF_PARAM( bat_i2c_adr, 0, int32_t, 'i') \
197197
\
198198
/*BBX - Black Box Data Logger*/ \
199-
MF_PARAM( bbx_gizmo, 0, int32_t, 'e', mf_NONE,mf_SDSPI,mf_SDMMC) \
199+
MF_PARAM( bbx_gizmo, 0, int32_t, 'e', mf_NONE,mf_SDSPI,mf_SDMMC,mf_OPENLOG) \
200200
MF_PARAM( bbx_spi_bus, -1, int32_t, 'i') \
201201
\
202202
/*GPS*/ \
@@ -264,6 +264,10 @@ SOFTWARE.
264264
MF_PARAM( bbx_log_out, 100, int32_t, 'i') /* Max log interval in [Hz] for OUT*/ \
265265
MF_PARAM( bbx_log_ahr, 100, int32_t, 'i') /* Max log interval in [Hz] for AHR*/ \
266266
MF_PARAM( bbx_log_rcl, 100, int32_t, 'i') /* Max log interval in [Hz] for RCL*/ \
267+
\
268+
/*v2.3.1 additions */ \
269+
MF_PARAM( bbx_ser_bus, -1, int32_t, 'i') \
270+
MF_PARAM( bbx_baud, 0, int32_t, 'i') \
267271
\
268272
//end MF_PARAM_LIST
269273

src/madflight.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ void madflight_setup() {
165165
bbx.config.pin_mmc_dat = cfg.pin_mmc_dat;
166166
bbx.config.pin_mmc_clk = cfg.pin_mmc_clk;
167167
bbx.config.pin_mmc_cmd = cfg.pin_mmc_cmd;
168+
bbx.config.bbx_ser_bus = cfg.bbx_ser_bus;
169+
bbx.config.bbx_baud = cfg.bbx_baud;
168170
bbx.setup();
169171

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

0 commit comments

Comments
 (0)