mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-23 17:13:38 +00:00
Attempt to merge
This commit is contained in:
parent
7c08ff35f3
commit
f7feea63f7
@ -13,8 +13,10 @@
|
||||
#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);
|
||||
@ -29,7 +31,9 @@ SPIClass SPI1(HSPI);
|
||||
#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)
|
||||
@ -379,10 +383,10 @@ void fsInit()
|
||||
void setupSDCard()
|
||||
{
|
||||
#ifdef HAS_SDCARD
|
||||
concurrency::LockGuard g(spiLock);
|
||||
concurrency::LockGuard g(spiLock);
|
||||
#if (defined(ARCH_ESP32) || defined(ARCH_NRF52))
|
||||
#if (defined(ARCH_ESP32))
|
||||
SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
|
||||
SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
|
||||
#endif
|
||||
if (!SD.begin(SDCARD_CS, SDHandler)) { // param SDHandler only used for esp32
|
||||
LOG_DEBUG("No SD_MMC card detected");
|
||||
|
@ -613,6 +613,9 @@ void setup()
|
||||
i2cScanner.reset();
|
||||
#endif
|
||||
|
||||
// Init our SPI controller (must be before screen and lora)
|
||||
initSPI();
|
||||
|
||||
#ifdef HAS_SDCARD
|
||||
setupSDCard();
|
||||
#endif
|
||||
@ -704,7 +707,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);
|
||||
|
@ -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
|
||||
|
@ -99,6 +99,7 @@ void StoreForwardModule::populateSDCard()
|
||||
{
|
||||
#if defined(HAS_SDCARD)
|
||||
#if (defined(ARCH_ESP32) || defined(ARCH_NRF52))
|
||||
spiLock->lock();
|
||||
if (SD.cardType() != CARD_NONE) {
|
||||
if (!SD.exists("/storeforward")) {
|
||||
LOG_INFO("Creating StoreForward directory");
|
||||
@ -110,6 +111,7 @@ void StoreForwardModule::populateSDCard()
|
||||
this->packetHistory = (PacketHistoryStruct *)malloc(sizeof(PacketHistoryStruct));
|
||||
LOG_DEBUG("numberOfPackets for packetHistory - %u", numberOfPackets);
|
||||
}
|
||||
spiLock->unlock();
|
||||
#endif // ARCH_ESP32 || ARCH_NRF52
|
||||
#endif // HAS_SDCARD
|
||||
}
|
||||
@ -169,6 +171,7 @@ uint32_t StoreForwardModule::getNumAvailablePackets(NodeNum dest, uint32_t last_
|
||||
} else if (this->storageType == StorageType::ST_SDCARD) {
|
||||
#if defined(HAS_SDCARD)
|
||||
#if defined(ARCH_ESP32) || defined(ARCH_NRF52)
|
||||
spiLock->lock();
|
||||
auto handler = SD.open("/storeforward/" + String(i), FILE_READ);
|
||||
if (handler) {
|
||||
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
|
||||
} else {
|
||||
@ -262,9 +266,11 @@ void StoreForwardModule::historyAdd(const meshtastic_MeshPacket &mp)
|
||||
this->packetHistory[0].emoji = (bool)p.emoji;
|
||||
this->packetHistory[0].payload_size = p.payload.size;
|
||||
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);
|
||||
handler.write((uint8_t *)&this->packetHistory, sizeof(PacketHistoryStruct));
|
||||
handler.close();
|
||||
spiLock->unlock();
|
||||
#endif
|
||||
#endif
|
||||
} else {
|
||||
@ -353,10 +359,12 @@ meshtastic_MeshPacket *StoreForwardModule::preparePayload(NodeNum dest, uint32_t
|
||||
} else if (this->storageType == StorageType::ST_SDCARD) {
|
||||
#if defined(HAS_SDCARD)
|
||||
#if defined(ARCH_ESP32) || defined(ARCH_NRF52)
|
||||
spiLock->lock();
|
||||
auto handler = SD.open("/storeforward/" + String(i), FILE_READ);
|
||||
if (handler) {
|
||||
handler.read((uint8_t *)&this->packetHistory[0], sizeof(PacketHistoryStruct));
|
||||
handler.close();
|
||||
spiLock->unlock();
|
||||
if (this->packetHistory[0].time && (this->packetHistory[0].time > last_time)) {
|
||||
if (this->packetHistory[0].from != 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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
spiLock->unlock();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@ -735,11 +745,12 @@ StoreForwardModule::StoreForwardModule()
|
||||
}
|
||||
#ifdef HAS_SDCARD
|
||||
// If we have an SDCARD, format it for store&forward use
|
||||
this->populateSDCard();
|
||||
LOG_INFO("S&F: SDCARD initialized");
|
||||
is_server = true;
|
||||
if (SD.cardType() != CARD_NONE) {
|
||||
this->populateSDCard();
|
||||
LOG_INFO("S&F: SDCARD initialized");
|
||||
is_server = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Client
|
||||
} else {
|
||||
is_client = true;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#ifdef HAS_SDCARD
|
||||
#include "SPILock.h"
|
||||
#include <SD.h>
|
||||
#endif
|
||||
|
||||
|
@ -3,5 +3,11 @@ extends = esp32_base
|
||||
board = ttgo-lora32-v21
|
||||
board_check = true
|
||||
build_flags =
|
||||
${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.
|
||||
${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.
|
||||
-DRADIOLIB_EXCLUDE_SX128X=1
|
||||
-DRADIOLIB_EXCLUDE_SX126X=1
|
||||
-DRADIOLIB_EXCLUDE_LR11X0=1
|
||||
|
@ -22,4 +22,15 @@
|
||||
#define LORA_DIO1 33 // https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436
|
||||
#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
|
Loading…
Reference in New Issue
Block a user