Skip to content

Commit 42f83f4

Browse files
committed
Offline/SD - Fix regression RP2040
1 parent b6c3c27 commit 42f83f4

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

src/Wippersnapper_demo.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
// All text above must be included in any redistribution.
1111

1212
#include "ws_adapters.h"
13-
ws_adapter_wifi wipper;
13+
//ws_adapter_wifi wipper;
14+
ws_adapter_offline wipper;
1415
#define WS_DEBUG // Enable debug output!
1516

1617
void setup() {

src/components/uart/drivers/drvUartPm25.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class drvUartPm25 : public drvUartBase {
112112
*/
113113
bool getEventPM25_STD(sensors_event_t *pm25StdEvent) {
114114
PM25_AQI_Data data;
115-
if (!_pm25->read(&data)) {
115+
if (!_pm25->read(&data))
116116
return false; // couldn't read data
117117

118118
pm25StdEvent->pm25_std = (float)data.pm25_standard;

src/components/uart/hardware.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,37 @@ bool UARTHardware::ConfigureSerial() {
126126
_baud_rate = _config.baud_rate;
127127
#endif // HAS_SW_SERIAL
128128
} else {
129+
#if ARDUINO_ARCH_ESP32
129130
// Create a new HardwareSerial instance
130131
_hwSerial = new HardwareSerial(_config.uart_nbr);
131-
if (_hwSerial == nullptr) {
132-
WS_DEBUG_PRINTLN(
133-
"[uart] ERROR: Failed to allocate HardwareSerial instance!");
132+
if (_hwSerial == nullptr)
134133
return false;
135-
}
136-
// Calls to HardwareSerial begin() differ based on the platform
137-
#if ARDUINO_ARCH_ESP32
138134
_hwSerial->begin((unsigned long)_config.baud_rate, (uint32_t)cfg, rx_pin,
139135
tx_pin, false, (unsigned long)_config.timeout);
136+
#elif ARDUINO_ARCH_RP2040
137+
// Create a new SerialUART instance
138+
uart_inst_t *uart_hw = nullptr;
139+
// determine which bus to use (RP2040 only supports 2 hardware UARTs)
140+
if (_config.uart_nbr == 0) {
141+
uart_hw = uart0;
142+
} else if (_config.uart_nbr == 1) {
143+
uart_hw = uart1;
144+
} else {
145+
WS_DEBUG_PRINTLN("[uart] ERROR: Invalid UART bus number specified!");
146+
return false;
147+
}
148+
_hwSerial = new SerialUART(uart_hw, tx_pin, rx_pin);
149+
if (_hwSerial == nullptr) {
150+
return false;
151+
}
152+
_hwSerial->begin((unsigned long)_config.baud_rate, (uint32_t)cfg);
140153
#else
141-
// RP2040, ESP8266, SAMD, and other platforms
154+
// ESP8266, SAMD, and other platforms
142155
// take the default Arduino/Wiring API arguments
156+
// Create a new HardwareSerial instance
157+
_hwSerial = new HardwareSerial(_config.uart_nbr);
158+
if (_hwSerial == nullptr)
159+
return false;
143160
_hwSerial->begin((unsigned long)_config.baud_rate, (uint32_t)cfg);
144161
#endif
145162
_baud_rate = _config.baud_rate;

src/components/uart/hardware.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#include "Wippersnapper_V2.h"
1818
#include <Arduino.h>
1919
#include <HardwareSerial.h>
20+
#ifdef ARDUINO_ARCH_RP2040
21+
#include <SerialUART.h>
22+
#endif
2023

2124
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_SAMD) || \
2225
defined(ARDUINO_ARCH_ESP8266)
@@ -54,7 +57,11 @@ class UARTHardware {
5457
private:
5558
wippersnapper_uart_UartSerialConfig
5659
_config; ///< The UART serial configuration
60+
#ifdef ARDUINO_ARCH_RP2040
61+
SerialUART *_hwSerial = nullptr; ///< Pointer to the SerialUART instance
62+
#else
5763
HardwareSerial *_hwSerial = nullptr; ///< HardwareSerial instance for this bus
64+
#endif
5865
#if HAS_SW_SERIAL
5966
SoftwareSerial *_swSerial = nullptr; ///< SoftwareSerial instance for this bus
6067
#endif // HAS_SW_SERIAL

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ bool Wippersnapper_FS::WriteFileConfig() {
439439
// Write the document to the filesystem
440440
File32 file_cfg = wipperFatFs_v2.open("/config.json", FILE_WRITE);
441441
if (!file_cfg) {
442-
HaltFilesystem("Could not create the config file!");
442+
fsHalt("Could not create the config file!");
443443
return false;
444444
}
445445
_doc_cfg.shrinkToFit();
@@ -451,7 +451,7 @@ bool Wippersnapper_FS::WriteFileConfig() {
451451
flash_v2.syncBlocks();
452452
refreshMassStorage();
453453
delay(500);
454-
InitUsbMsc();
454+
initUSBMSC();
455455
WS_PRINTER.flush();
456456
delay(2500);
457457
WS_PRINTER.println("Config file written to flash!"); // List current config / components and periods

0 commit comments

Comments
 (0)