Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SD card as store&forward memory #5083

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extra_scripts = bin/platformio-custom.py
build_flags = -Wno-missing-field-initializers

-Wno-format
-Isrc -Isrc/mesh -Isrc/mesh/generated -Isrc/gps -Isrc/buzz -Wl,-Map,${platformio.build_dir}/output.map
-Isrc -Isrc/mesh -Isrc/mesh/generated -Isrc/gps -Isrc/buzz -Wl,-Map,"${platformio.build_dir}"/output.map
-DUSE_THREAD_NAMES
-DTINYGPS_OPTION_NO_CUSTOM_FIELDS
-DPB_ENABLE_MALLOC=1
Expand Down
30 changes: 23 additions & 7 deletions src/FSCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,27 @@
#include "configuration.h"

#ifdef HAS_SDCARD
#include "SPILock.h"
#include <SD.h>
#include <SPI.h>

#ifndef SDCARD_USE_HSPI // old ESP32
#ifdef SDCARD_USE_SPI1
#ifdef ARCH_ESP32
SPIClass SPI1(HSPI);
#define SDHandler SPI1
#endif // ARCH_ESP32
#ifdef ARCH_NRF52
#define SDCARD_SPI SPI1
#endif // NRF52
#define SDHandler SPI1 // only used for esp32
#else
#define SDHandler SPI
#ifdef ARCH_NRF52
#define SDCARD_SPI SPI
#endif // NRF52
#define SDHandler SPI // only used for esp32
#endif // SDCARD_USE_SPI1
#else
SPIClass SDHandler = SPIClass(HSPI);
#endif

#endif // HAS_SDCARD

#if defined(ARCH_STM32WL)
Expand All @@ -47,7 +58,7 @@ void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte *input)
input++;
}
}
#endif
#endif // ARCH_STM32WL

bool lfs_assert_failed =
false; // Note: we use this global on all platforms, though it can only be set true on nrf52 (in our modified lfs_util.h)
Expand Down Expand Up @@ -373,9 +384,11 @@ void setupSDCard()
{
#ifdef HAS_SDCARD
concurrency::LockGuard g(spiLock);
#if (defined(ARCH_ESP32) || defined(ARCH_NRF52))
#if (defined(ARCH_ESP32))
SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI);

if (!SD.begin(SDCARD_CS, SDHandler)) {
#endif
if (!SD.begin(SDCARD_CS, SDHandler)) { // param SDHandler only used for esp32
LOG_DEBUG("No SD_MMC card detected");
return;
}
Expand All @@ -398,6 +411,9 @@ void setupSDCard()
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
LOG_DEBUG("SD Card Size: %lu MB", (uint32_t)cardSize);
LOG_DEBUG("Total space: %lu MB", (uint32_t)(SD.totalBytes() / (1024 * 1024)));
#if (defined(ARCH_ESP32)) // not implemented in arduino sd library
LOG_DEBUG("Used space: %lu MB", (uint32_t)(SD.usedBytes() / (1024 * 1024)));
#endif
#endif
#endif
}
12 changes: 8 additions & 4 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "modules/ExternalNotificationModule.h"
#include "modules/TextMessageModule.h"
#include "modules/WaypointModule.h"
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
#include "modules/StoreForwardModule.h"
#endif
#include "sleep.h"
#include "target_specific.h"

Expand All @@ -57,11 +60,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifdef ARCH_ESP32
#include "esp_task_wdt.h"
#include "modules/StoreForwardModule.h"
#endif

#if ARCH_PORTDUINO
#include "modules/StoreForwardModule.h"
#include "platform/portduino/PortduinoGlue.h"
#endif

Expand Down Expand Up @@ -2406,9 +2407,9 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
display->setColor(WHITE);
// Draw the channel name
display->drawString(x, y + FONT_HEIGHT_SMALL, channelStr);
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
// Draw our hardware ID to assist with bluetooth pairing. Either prefix with Info or S&F Logo
if (moduleConfig.store_forward.enabled) {
#ifdef ARCH_ESP32
if (!Throttle::isWithinTimespanMs(storeForwardModule->lastHeartbeat,
(storeForwardModule->heartbeatInterval * 1200))) { // no heartbeat, overlap a bit
#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \
Expand All @@ -2424,7 +2425,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
#endif
} else {
#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \
defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \
defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS) || ARCH_PORTDUINO) && \
!defined(DISPLAY_FORCE_SMALL_FONTS)
display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8,
imgSFL1);
Expand All @@ -2435,6 +2436,9 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
imgSF);
#endif
}
#else
// No store and forward, show a exclamation mark
if (false) {
#endif
} else {
// TODO: Raspberry Pi supports more than just the one screen size
Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,9 @@ void setup()
i2cScanner.reset();
#endif

// Init our SPI controller (must be before screen and lora)
initSPI();

#ifdef HAS_SDCARD
setupSDCard();
#endif
Expand Down Expand Up @@ -706,7 +709,6 @@ void setup()
drv.setMode(DRV2605_MODE_INTTRIG);
#endif

// Init our SPI controller (must be before screen and lora)
#ifdef ARCH_RP2040
#ifdef HW_SPI1_DEVICE
SPI1.setSCK(LORA_SCK);
Expand Down
4 changes: 4 additions & 0 deletions src/memGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ uint32_t MemGet::getFreePsram()
{
#ifdef ARCH_ESP32
return ESP.getFreePsram();
#elif (defined(HAS_SDCARD) && defined(ARCH_ESP32))
return SD.totalBytes() - SD.usedBytes();
#elif defined(ARCH_PORTDUINO)
return 4194252;
#else
Expand All @@ -73,6 +75,8 @@ uint32_t MemGet::getPsramSize()
{
#ifdef ARCH_ESP32
return ESP.getPsramSize();
#elif (defined(HAS_SDCARD) && defined(ARCH_ESP32))
return SD.totalBytes();
#elif defined(ARCH_PORTDUINO)
return 4194252;
#else
Expand Down
2 changes: 0 additions & 2 deletions src/mesh/MeshService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,13 @@ void MeshService::sendToPhone(meshtastic_MeshPacket *p)
{
perhapsDecode(p);

#ifdef ARCH_ESP32
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
if (moduleConfig.store_forward.enabled && storeForwardModule->isServer() &&
p->decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) {
releaseToPool(p); // Copy is already stored in StoreForward history
fromNum++; // Notify observers for packet from radio
return;
}
#endif
#endif

if (toPhoneQueue.numFree() == 0) {
Expand Down
2 changes: 0 additions & 2 deletions src/mesh/MeshService.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#if defined(ARCH_PORTDUINO)
#include "../platform/portduino/SimRadio.h"
#endif
#if defined(ARCH_ESP32) || defined(ARCH_PORTDUINO)
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
#include "modules/StoreForwardModule.h"
#endif
#endif

extern Allocator<meshtastic_QueueStatus> &queueStatusPool;
extern Allocator<meshtastic_MqttClientProxyMessage> &mqttClientProxyMessagePool;
Expand Down
9 changes: 6 additions & 3 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "mesh-pb-constants.h"
#include "meshUtils.h"
#include "modules/NeighborInfoModule.h"
// #if !MESHTASTIC_EXCLUDE_STOREFORWARD
// #include "modules/StoreForwardModule.h"
// #endif
#include <ErriezCRC32.h>
#include <algorithm>
#include <iostream>
Expand All @@ -32,8 +35,6 @@
#if HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h"
#endif
#include "SPILock.h"
#include "modules/StoreForwardModule.h"
#include <Preferences.h>
#include <esp_efuse.h>
#include <esp_efuse_table.h>
Expand All @@ -42,8 +43,10 @@
#include <soc/soc.h>
#endif

#ifdef ARCH_PORTDUINO
#include "SPILock.h"
#include "modules/StoreForwardModule.h"

#ifdef ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/mesh/RF95Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool RF95Interface::init()
#endif

if (res == RADIOLIB_ERR_NONE)
res = lora->setCRC(RADIOLIB_SX126X_LORA_CRC_ON);
res = lora->setCRC(true);

if (res == RADIOLIB_ERR_NONE)
startReceive(); // start receiving
Expand Down
9 changes: 3 additions & 6 deletions src/modules/Modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
#endif
#if ARCH_PORTDUINO
#include "input/LinuxInputImpl.h"
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
#include "modules/StoreForwardModule.h"
#endif
#endif
#if HAS_TELEMETRY
#include "modules/Telemetry/DeviceTelemetry.h"
Expand All @@ -63,16 +60,16 @@
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_POWER_TELEMETRY
#include "modules/Telemetry/PowerTelemetry.h"
#endif
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
#include "modules/StoreForwardModule.h"
#endif
#ifdef ARCH_ESP32
#if defined(USE_SX1280) && !MESHTASTIC_EXCLUDE_AUDIO
#include "modules/esp32/AudioModule.h"
#endif
#if !MESHTASTIC_EXCLUDE_PAXCOUNTER
#include "modules/esp32/PaxcounterModule.h"
#endif
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
#include "modules/StoreForwardModule.h"
#endif
#endif
#if defined(ARCH_ESP32) || defined(ARCH_NRF52) || defined(ARCH_RP2040) || defined(ARCH_PORTDUINO)
#if !MESHTASTIC_EXCLUDE_EXTERNALNOTIFICATION
Expand Down
Loading
Loading