Attempt to merge

This commit is contained in:
Thomas Göttgens 2025-01-05 21:34:38 +01:00
parent 7c08ff35f3
commit f7feea63f7
7 changed files with 47 additions and 12 deletions

View File

@ -13,8 +13,10 @@
#include "configuration.h" #include "configuration.h"
#ifdef HAS_SDCARD #ifdef HAS_SDCARD
#include "SPILock.h"
#include <SD.h> #include <SD.h>
#include <SPI.h> #include <SPI.h>
#ifndef SDCARD_USE_HSPI // old ESP32
#ifdef SDCARD_USE_SPI1 #ifdef SDCARD_USE_SPI1
#ifdef ARCH_ESP32 #ifdef ARCH_ESP32
SPIClass SPI1(HSPI); SPIClass SPI1(HSPI);
@ -29,7 +31,9 @@ SPIClass SPI1(HSPI);
#endif // NRF52 #endif // NRF52
#define SDHandler SPI // only used for esp32 #define SDHandler SPI // only used for esp32
#endif // SDCARD_USE_SPI1 #endif // SDCARD_USE_SPI1
#else
SPIClass SDHandler = SPIClass(HSPI);
#endif
#endif // HAS_SDCARD #endif // HAS_SDCARD
#if defined(ARCH_STM32WL) #if defined(ARCH_STM32WL)
@ -379,10 +383,10 @@ void fsInit()
void setupSDCard() void setupSDCard()
{ {
#ifdef HAS_SDCARD #ifdef HAS_SDCARD
concurrency::LockGuard g(spiLock); concurrency::LockGuard g(spiLock);
#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) #if (defined(ARCH_ESP32) || defined(ARCH_NRF52))
#if (defined(ARCH_ESP32)) #if (defined(ARCH_ESP32))
SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI); SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
#endif #endif
if (!SD.begin(SDCARD_CS, SDHandler)) { // param SDHandler only used for esp32 if (!SD.begin(SDCARD_CS, SDHandler)) { // param SDHandler only used for esp32
LOG_DEBUG("No SD_MMC card detected"); LOG_DEBUG("No SD_MMC card detected");

View File

@ -613,6 +613,9 @@ void setup()
i2cScanner.reset(); i2cScanner.reset();
#endif #endif
// Init our SPI controller (must be before screen and lora)
initSPI();
#ifdef HAS_SDCARD #ifdef HAS_SDCARD
setupSDCard(); setupSDCard();
#endif #endif
@ -704,7 +707,6 @@ void setup()
drv.setMode(DRV2605_MODE_INTTRIG); drv.setMode(DRV2605_MODE_INTTRIG);
#endif #endif
// Init our SPI controller (must be before screen and lora)
#ifdef ARCH_RP2040 #ifdef ARCH_RP2040
#ifdef HW_SPI1_DEVICE #ifdef HW_SPI1_DEVICE
SPI1.setSCK(LORA_SCK); SPI1.setSCK(LORA_SCK);

View File

@ -185,7 +185,7 @@ bool RF95Interface::init()
#endif #endif
if (res == RADIOLIB_ERR_NONE) if (res == RADIOLIB_ERR_NONE)
res = lora->setCRC(RADIOLIB_SX126X_LORA_CRC_ON); res = lora->setCRC(true);
if (res == RADIOLIB_ERR_NONE) if (res == RADIOLIB_ERR_NONE)
startReceive(); // start receiving startReceive(); // start receiving

View File

@ -99,6 +99,7 @@ void StoreForwardModule::populateSDCard()
{ {
#if defined(HAS_SDCARD) #if defined(HAS_SDCARD)
#if (defined(ARCH_ESP32) || defined(ARCH_NRF52)) #if (defined(ARCH_ESP32) || defined(ARCH_NRF52))
spiLock->lock();
if (SD.cardType() != CARD_NONE) { if (SD.cardType() != CARD_NONE) {
if (!SD.exists("/storeforward")) { if (!SD.exists("/storeforward")) {
LOG_INFO("Creating StoreForward directory"); LOG_INFO("Creating StoreForward directory");
@ -110,6 +111,7 @@ void StoreForwardModule::populateSDCard()
this->packetHistory = (PacketHistoryStruct *)malloc(sizeof(PacketHistoryStruct)); this->packetHistory = (PacketHistoryStruct *)malloc(sizeof(PacketHistoryStruct));
LOG_DEBUG("numberOfPackets for packetHistory - %u", numberOfPackets); LOG_DEBUG("numberOfPackets for packetHistory - %u", numberOfPackets);
} }
spiLock->unlock();
#endif // ARCH_ESP32 || ARCH_NRF52 #endif // ARCH_ESP32 || ARCH_NRF52
#endif // HAS_SDCARD #endif // HAS_SDCARD
} }
@ -169,6 +171,7 @@ uint32_t StoreForwardModule::getNumAvailablePackets(NodeNum dest, uint32_t last_
} else if (this->storageType == StorageType::ST_SDCARD) { } else if (this->storageType == StorageType::ST_SDCARD) {
#if defined(HAS_SDCARD) #if defined(HAS_SDCARD)
#if defined(ARCH_ESP32) || defined(ARCH_NRF52) #if defined(ARCH_ESP32) || defined(ARCH_NRF52)
spiLock->lock();
auto handler = SD.open("/storeforward/" + String(i), FILE_READ); auto handler = SD.open("/storeforward/" + String(i), FILE_READ);
if (handler) { if (handler) {
handler.read((uint8_t *)&this->packetHistory[0], sizeof(PacketHistoryStruct)); handler.read((uint8_t *)&this->packetHistory[0], sizeof(PacketHistoryStruct));
@ -181,6 +184,7 @@ uint32_t StoreForwardModule::getNumAvailablePackets(NodeNum dest, uint32_t last_
} }
} }
} }
spiLock->unlock();
#endif #endif
#endif #endif
} else { } else {
@ -262,9 +266,11 @@ void StoreForwardModule::historyAdd(const meshtastic_MeshPacket &mp)
this->packetHistory[0].emoji = (bool)p.emoji; this->packetHistory[0].emoji = (bool)p.emoji;
this->packetHistory[0].payload_size = p.payload.size; this->packetHistory[0].payload_size = p.payload.size;
memcpy(this->packetHistory[0].payload, p.payload.bytes, meshtastic_Constants_DATA_PAYLOAD_LEN); memcpy(this->packetHistory[0].payload, p.payload.bytes, meshtastic_Constants_DATA_PAYLOAD_LEN);
spiLock->lock();
auto handler = SD.open("/storeforward/" + String(this->packetHistoryTotalCount), FILE_WRITE); auto handler = SD.open("/storeforward/" + String(this->packetHistoryTotalCount), FILE_WRITE);
handler.write((uint8_t *)&this->packetHistory, sizeof(PacketHistoryStruct)); handler.write((uint8_t *)&this->packetHistory, sizeof(PacketHistoryStruct));
handler.close(); handler.close();
spiLock->unlock();
#endif #endif
#endif #endif
} else { } else {
@ -353,10 +359,12 @@ meshtastic_MeshPacket *StoreForwardModule::preparePayload(NodeNum dest, uint32_t
} else if (this->storageType == StorageType::ST_SDCARD) { } else if (this->storageType == StorageType::ST_SDCARD) {
#if defined(HAS_SDCARD) #if defined(HAS_SDCARD)
#if defined(ARCH_ESP32) || defined(ARCH_NRF52) #if defined(ARCH_ESP32) || defined(ARCH_NRF52)
spiLock->lock();
auto handler = SD.open("/storeforward/" + String(i), FILE_READ); auto handler = SD.open("/storeforward/" + String(i), FILE_READ);
if (handler) { if (handler) {
handler.read((uint8_t *)&this->packetHistory[0], sizeof(PacketHistoryStruct)); handler.read((uint8_t *)&this->packetHistory[0], sizeof(PacketHistoryStruct));
handler.close(); handler.close();
spiLock->unlock();
if (this->packetHistory[0].time && (this->packetHistory[0].time > last_time)) { if (this->packetHistory[0].time && (this->packetHistory[0].time > last_time)) {
if (this->packetHistory[0].from != dest && if (this->packetHistory[0].from != dest &&
(this->packetHistory[0].to == NODENUM_BROADCAST || this->packetHistory[0].to == dest)) { (this->packetHistory[0].to == NODENUM_BROADCAST || this->packetHistory[0].to == dest)) {
@ -395,6 +403,8 @@ meshtastic_MeshPacket *StoreForwardModule::preparePayload(NodeNum dest, uint32_t
return p; return p;
} }
} }
} else {
spiLock->unlock();
} }
#endif #endif
#endif #endif
@ -735,11 +745,12 @@ StoreForwardModule::StoreForwardModule()
} }
#ifdef HAS_SDCARD #ifdef HAS_SDCARD
// If we have an SDCARD, format it for store&forward use // If we have an SDCARD, format it for store&forward use
this->populateSDCard(); if (SD.cardType() != CARD_NONE) {
LOG_INFO("S&F: SDCARD initialized"); this->populateSDCard();
is_server = true; LOG_INFO("S&F: SDCARD initialized");
is_server = true;
}
#endif #endif
// Client // Client
} else { } else {
is_client = true; is_client = true;

View File

@ -10,6 +10,7 @@
#include <unordered_map> #include <unordered_map>
#ifdef HAS_SDCARD #ifdef HAS_SDCARD
#include "SPILock.h"
#include <SD.h> #include <SD.h>
#endif #endif

View File

@ -3,5 +3,11 @@ extends = esp32_base
board = ttgo-lora32-v21 board = ttgo-lora32-v21
board_check = true board_check = true
build_flags = build_flags =
${esp32_base.build_flags} -D TLORA_V2_1_16 -I variants/tlora_v2_1_16 ${esp32_base.build_flags}
-D TLORA_V2_1_16
-I variants/tlora_v2_1_16
-DGPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely. -DGPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely.
-DRADIOLIB_EXCLUDE_SX128X=1
-DRADIOLIB_EXCLUDE_SX126X=1
-DRADIOLIB_EXCLUDE_LR11X0=1

View File

@ -23,3 +23,14 @@
#endif #endif
#define LORA_DIO2 32 // Not really used #define LORA_DIO2 32 // Not really used
/*
* Use SD Card for Store and Forward
*/
#define HAS_SDCARD
#define SDCARD_USE_HSPI
#define SPI_MOSI 15
#define SPI_MISO 2
#define SPI_SCK 14
#define SPI_CS 13
#define SDCARD_CS SPI_CS