mirror of
https://github.com/torlando-tech/pyxis.git
synced 2026-08-28 13:34:17 +00:00
relocate shim to lib/; pyxis lib API renames Compile-tier graft progress on top of40e561f. Key changes: - Re-vendor lib/microreticulum-shim/ (was src-shim/) from the *actual* ca355e5 commit content rather than the stale "feat/t-deck HEAD" /tmp clone the previous commit pulled from. Recovers process_sync() on LXMRouter and MEMORY_MONITOR_POLL macro that were missing. - Move src-shim/ → lib/microreticulum-shim/ + add library.json so PlatformIO discovers the .cpp files and links them. Was previously only on the include path; the .cpps weren't in the build. (This unblocks the 30+ undefined-reference linker errors for LXMF and Instrumentation symbols.) - Drop -Isrc-shim/Utilities (/Cryptography/Instrumentation) from build_flags — they were over-broad and put our Stream.h on the GLOBAL header path, breaking Arduino's Wire.cpp which has `class TwoWire: public Stream`. -Ilib/microreticulum-shim alone resolves subdir lookups via <Cryptography/X.h>, <Utilities/Y.h>. - UniversalFileSystem migrated to microStore::Adapters::SPIFFSFileSystem (activated by -DUSTORE_USE_SPIFFS). Vanilla upstream microReticulum @ 0.3.0 deleted RNS::FileSystem in favor of microStore. Pyxis's lib/universal_filesystem/ is now dead code on this build path. - pyxis lib API renames for the post-graft world: SDLogger.cpp: RNS::setLogCallback -> RNS::set_log_callback AnnounceListScreen: Transport::get_destination_table -> Transport::get_path_table Transport::DestinationEntry -> RNS::Persistence::DestinationEntry UIManager.cpp: _lxst_destination ctor explicit RNS::Type::NONE (vanilla Destination has no default ctor) Identity::mark_persistent calls disabled w/ restoration TODO ConversationListScreen: Interface::get_rssi/get_stats calls disabled (the methods are non-virtual on BLEInterface/SX1262Interface post de-virtualization ina0ff631) Compile is clean against the fixed-cryptography submodule pin; current failure layer is fork-only Type::Channel constants referenced by the vendored shim's Buffer/ChannelData files. That's the next session's problem — see pyxis_microReticulum_graft_spike_findings.md for the plan options (most likely: remove Channel/Buffer/ChannelData/Ratchet from the shim, since LXMF doesn't use Channel anyway per the 2026-05-04 investigation).
88 lines
2.0 KiB
C++
88 lines
2.0 KiB
C++
/*
|
|
* PSRAMAllocator.h - Custom STL allocator for ESP32 PSRAM
|
|
*
|
|
* Routes std::vector allocations to PSRAM (external RAM) when available,
|
|
* falling back to internal heap if PSRAM allocation fails.
|
|
*
|
|
* This helps prevent internal heap fragmentation by keeping large
|
|
* data structures in PSRAM.
|
|
*
|
|
* Based on: https://github.com/atanisoft/esp32usb/blob/master/include/psram_allocator.h
|
|
*/
|
|
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <new>
|
|
|
|
#ifdef ARDUINO
|
|
#include <esp_heap_caps.h>
|
|
#else
|
|
// Non-ESP32 platforms: use standard allocation
|
|
#include <cstdlib>
|
|
#endif
|
|
|
|
template <class T>
|
|
class PSRAMAllocator
|
|
{
|
|
public:
|
|
using value_type = T;
|
|
|
|
PSRAMAllocator() noexcept {}
|
|
|
|
template <class U>
|
|
constexpr PSRAMAllocator(const PSRAMAllocator<U>&) noexcept {}
|
|
|
|
[[nodiscard]] value_type* allocate(std::size_t n)
|
|
{
|
|
#ifdef ARDUINO
|
|
#if CONFIG_SPIRAM || defined(BOARD_HAS_PSRAM)
|
|
// Attempt to allocate in PSRAM first
|
|
auto p = static_cast<value_type*>(
|
|
heap_caps_malloc(n * sizeof(value_type), MALLOC_CAP_SPIRAM));
|
|
if (p)
|
|
{
|
|
return p;
|
|
}
|
|
#endif // CONFIG_SPIRAM || BOARD_HAS_PSRAM
|
|
|
|
// If PSRAM allocation failed (or not available), try default memory pool
|
|
auto p2 = static_cast<value_type*>(
|
|
heap_caps_malloc(n * sizeof(value_type), MALLOC_CAP_DEFAULT));
|
|
if (p2)
|
|
{
|
|
return p2;
|
|
}
|
|
#else
|
|
// Non-Arduino: use standard malloc
|
|
auto p = static_cast<value_type*>(std::malloc(n * sizeof(value_type)));
|
|
if (p)
|
|
{
|
|
return p;
|
|
}
|
|
#endif
|
|
|
|
throw std::bad_alloc();
|
|
}
|
|
|
|
void deallocate(value_type* p, std::size_t) noexcept
|
|
{
|
|
#ifdef ARDUINO
|
|
heap_caps_free(p);
|
|
#else
|
|
std::free(p);
|
|
#endif
|
|
}
|
|
};
|
|
|
|
template <class T, class U>
|
|
bool operator==(const PSRAMAllocator<T>&, const PSRAMAllocator<U>&)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
template <class T, class U>
|
|
bool operator!=(const PSRAMAllocator<T>& x, const PSRAMAllocator<U>& y)
|
|
{
|
|
return !(x == y);
|
|
}
|