mirror of
https://github.com/torlando-tech/pyxis.git
synced 2026-08-28 05:24:22 +00:00
Add shared SPI bus mutex for SD card, display, and LoRa coexistence
The T-Deck Plus shares HSPI across the display (CS=12), LoRa (CS=9), and SD card (CS=39). Previously SD logging was disabled because SD.begin() reconfigured the SPI bus and blanked the display. This introduces a FreeRTOS mutex created in main.cpp and injected into Display, SX1262Interface, and a new SDAccess class so all three peripherals serialize their SPI transactions safely. - Add SDAccess class wrapping SD.begin() and file ops with mutex - Add set_spi_mutex() to Display and SX1262Interface - Wrap Display flush, fill, draw, and power ops in mutex - Refactor SDLogger to use SDAccess mutex instead of owning SD.begin() - Wire up mutex creation and injection order in setup() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
d9411fb4bb
commit
d03f0b308f
@@ -12,9 +12,17 @@
|
||||
using namespace RNS;
|
||||
|
||||
#ifdef ARDUINO
|
||||
// Static members for SPI mutex (shared with display)
|
||||
// Static members for SPI mutex (shared with display and SD card)
|
||||
SemaphoreHandle_t SX1262Interface::_spi_mutex = nullptr;
|
||||
bool SX1262Interface::_mutex_initialized = false;
|
||||
|
||||
void SX1262Interface::set_spi_mutex(SemaphoreHandle_t mutex) {
|
||||
_spi_mutex = mutex;
|
||||
_mutex_initialized = (mutex != nullptr);
|
||||
if (_mutex_initialized) {
|
||||
DEBUG("SX1262Interface: Using external SPI mutex");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SX1262Interface::SX1262Interface(const char* name) : InterfaceImpl(name) {
|
||||
@@ -58,15 +66,15 @@ bool SX1262Interface::start() {
|
||||
INFO(" CR: 4/" + std::to_string(_config.coding_rate));
|
||||
INFO(" TX Power: " + std::to_string(_config.tx_power) + " dBm");
|
||||
|
||||
// Initialize SPI mutex if not already done
|
||||
// Use external mutex if provided, otherwise create our own (fallback)
|
||||
if (!_mutex_initialized) {
|
||||
WARNING("SX1262Interface: No external SPI mutex set, creating own");
|
||||
_spi_mutex = xSemaphoreCreateMutex();
|
||||
if (_spi_mutex == nullptr) {
|
||||
ERROR("SX1262Interface: Failed to create SPI mutex");
|
||||
return false;
|
||||
}
|
||||
_mutex_initialized = true;
|
||||
DEBUG("SX1262Interface: SPI mutex created");
|
||||
}
|
||||
|
||||
// Acquire SPI mutex
|
||||
|
||||
Reference in New Issue
Block a user