diff --git a/arch/apollo3/apollo3.ini b/arch/apollo3/apollo3.ini index dfa7eea67..edde6058c 100644 --- a/arch/apollo3/apollo3.ini +++ b/arch/apollo3/apollo3.ini @@ -1,7 +1,7 @@ [apollo3_base] +extends = arduino_base platform = https://github.com/nigelb/platform-apollo3blue.git#2e8a9895cf82f2836c483885e6f89b3f83d3ade4 platform_packages=framework-arduinoapollo3@https://github.com/sparkfun/Arduino_Apollo3#v2.2.2rc2 -framework = arduino build_type = debug build_flags = ${arduino_base.build_flags} @@ -16,6 +16,7 @@ build_src_filter = - - - + - - - - @@ -26,5 +27,6 @@ build_src_filter = lib_deps = ${env.lib_deps} jgromes/RadioLib@^6.3.0 + charlesbaynham/OSFS@^1.2.3 lib_ignore = mathertel/OneButton diff --git a/src/FSCommon.cpp b/src/FSCommon.cpp index 0139db0c0..6537529a4 100644 --- a/src/FSCommon.cpp +++ b/src/FSCommon.cpp @@ -33,7 +33,33 @@ SPIClass SPI1(HSPI); */ bool copyFile(const char *from, const char *to) { -#ifdef FSCom +#if defined(ARCH_STM32WL) || defined(ARCH_APOLLO3) + unsigned char cbuffer[2048]; + + // Var to hold the result of actions + OSFS::result r; + + r = OSFS::getFile(from, cbuffer); + + if (r == notfound) { + LOG_ERROR("Failed to open source file %s\n", from); + return false; + } else if (r == noerr) { + r = OSFS::newFile(to, cbuffer, true); + if (r == noerr) { + return true; + } else { + LOG_ERROR("OSFS Error %d\n", r); + return false; + } + + } else { + LOG_ERROR("OSFS Error %d\n", r); + return false; + } +return true; + +#elif defined(FSCom) unsigned char cbuffer[16]; File f1 = FSCom.open(from, FILE_O_READ); @@ -56,8 +82,8 @@ bool copyFile(const char *from, const char *to) f2.flush(); f2.close(); f1.close(); -#endif return true; +#endif } /** @@ -70,7 +96,13 @@ bool copyFile(const char *from, const char *to) */ bool renameFile(const char *pathFrom, const char *pathTo) { -#ifdef FSCom +#if defined(ARCH_STM32WL) || defined(ARCH_APOLLO3) + if (copyFile(pathFrom, pathTo) && (OSFS::deleteFile(pathFrom) == OSFS::result::NO_ERROR)) { + return true; + } else { + return false; + } +#elif defined(FSCom) #ifdef ARCH_ESP32 // rename was fixed for ESP32 IDF LittleFS in April return FSCom.rename(pathFrom, pathTo); @@ -82,7 +114,6 @@ bool renameFile(const char *pathFrom, const char *pathTo) } #endif #endif - return true; } /** diff --git a/src/FSCommon.h b/src/FSCommon.h index 4564eae3c..7fc511937 100644 --- a/src/FSCommon.h +++ b/src/FSCommon.h @@ -21,10 +21,32 @@ using namespace LittleFS_Namespace; #endif #if defined(ARCH_APOLLO3) -#include "platform/apollo3/InternalFileSystem.h" // Apollo3 -#define FSCom InternalFS -#define FSBegin() FSCom.begin() -using namespace LittleFS_Namespace; +// Apollo series 2 Kbytes (8 rows of 256 bytes) +#include +#include + +uint16_t OSFS::startOfEEPROM = 1; +uint16_t OSFS::endOfEEPROM = 2048; + +// Useful consts +const OSFS::result noerr = OSFS::result::NO_ERROR; +const OSFS::result notfound = OSFS::result::FILE_NOT_FOUND; + +// 3) How do I read from the medium? +void OSFS::readNBytes(uint16_t address, unsigned int num, byte* output) { + for (uint16_t i = address; i < address + num; i++) { + *output = EEPROM.read(i); + output++; + } +} + +// 4) How to I write to the medium? +void OSFS::writeNBytes(uint16_t address, unsigned int num, const byte* input) { + for (uint16_t i = address; i < address + num; i++) { + EEPROM.update(i, *input); + input++; + } +} #endif #if defined(ARCH_RP2040) diff --git a/src/freertosinc.h b/src/freertosinc.h index a25268959..166054241 100644 --- a/src/freertosinc.h +++ b/src/freertosinc.h @@ -12,8 +12,7 @@ #include #endif -#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_RP2040) || \ - defined(ARDUINO_ARCH_APOLLO3) +#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_ARCH_RP2040) #define HAS_FREE_RTOS #include diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index f51fb0588..e7f85a0e2 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -748,7 +748,7 @@ int GPS::prepareDeepSleep(void *unused) GnssModel_t GPS::probe(int serialSpeed) { -#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_RP2040) +#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_RP2040) || defined(ARCH_APOLLO3) _serial_gps->end(); _serial_gps->begin(serialSpeed); #else @@ -803,7 +803,7 @@ GnssModel_t GPS::probe(int serialSpeed) _serial_gps->write(_message_prt, sizeof(_message_prt)); delay(500); serialSpeed = 9600; -#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_RP2040) +#if defined(ARCH_NRF52) || defined(ARCH_PORTDUINO) || defined(ARCH_RP2040) || defined(ARCH_APOLLO3) _serial_gps->end(); _serial_gps->begin(serialSpeed); #else diff --git a/src/main.cpp b/src/main.cpp index e7b401ac4..7319f2d91 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,7 +79,7 @@ NRF52Bluetooth *nrf52Bluetooth; #endif #include "PowerFSMThread.h" -#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) +#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !defined(ARCH_APOLLO3) #include "AccelerometerThread.h" #include "AmbientLightingThread.h" #endif @@ -610,7 +610,7 @@ void setup() } #endif -#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) +#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !defined(ARCH_APOLLO3) if (rgb_found.type != ScanI2C::DeviceType::NONE) { ambientLightingThread = new AmbientLightingThread(rgb_found.type); } diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index a01647bfa..66578f14d 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -36,7 +36,9 @@ void PhoneAPI::handleStartConfig() if (!isConnected()) { onConnectionChanged(true); observe(&service.fromNumChanged); +#ifdef FSCom observe(&xModem.packetReady); +#endif } // even if we were already connected - restart our state machine @@ -53,7 +55,9 @@ void PhoneAPI::close() state = STATE_SEND_NOTHING; unobserve(&service.fromNumChanged); +#ifdef FSCom unobserve(&xModem.packetReady); +#endif releasePhonePacket(); // Don't leak phone packets on shutdown releaseQueueStatusPhonePacket(); releaseMqttClientProxyPhonePacket(); @@ -99,7 +103,9 @@ bool PhoneAPI::handleToRadio(const uint8_t *buf, size_t bufLength) break; case meshtastic_ToRadio_xmodemPacket_tag: LOG_INFO("Got xmodem packet\n"); +#ifdef FSCom xModem.handlePacket(toRadioScratch.xmodemPacket); +#endif break; case meshtastic_ToRadio_mqttClientProxyMessage_tag: LOG_INFO("Got MqttClientProxy message\n"); @@ -423,12 +429,14 @@ bool PhoneAPI::available() if (hasPacket) return true; +#ifdef FSCom if (xmodemPacketForPhone.control == meshtastic_XModem_Control_NUL) xmodemPacketForPhone = xModem.getForPhone(); if (xmodemPacketForPhone.control != meshtastic_XModem_Control_NUL) { xModem.resetForPhone(); return true; } +#endif if (!packetForPhone) packetForPhone = service.getForPhone(); diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index b2d8d585d..59c32f2fc 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -3,7 +3,7 @@ #include "CryptoEngine.h" #include "MeshRadio.h" #include "NodeDB.h" -#include "RTC.h" +#include "gps/RTC.h" #include "configuration.h" #include "main.h" #include "mesh-pb-constants.h" diff --git a/src/modules/ExternalNotificationModule.h b/src/modules/ExternalNotificationModule.h index 3331ec428..4f2aec3fe 100644 --- a/src/modules/ExternalNotificationModule.h +++ b/src/modules/ExternalNotificationModule.h @@ -3,7 +3,7 @@ #include "SinglePortModule.h" #include "concurrency/OSThread.h" #include "configuration.h" -#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) +#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !defined(ARCH_APOLLO3) #include #else // Noop class for portduino. diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index cf2276f0e..0e4ad338f 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -1,7 +1,7 @@ #include "NeighborInfoModule.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" +#include "gps/RTC.h" #define MAX_NUM_NEIGHBORS 10 // also defined in NeighborInfo protobuf options NeighborInfoModule *neighborInfoModule; diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 69cd4848e..da10504d8 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -2,7 +2,7 @@ #include "GPS.h" #include "MeshService.h" #include "NodeDB.h" -#include "RTC.h" +#include "gps/RTC.h" #include "Router.h" #include "TypeConversions.h" #include "airtime.h" diff --git a/src/xmodem.cpp b/src/xmodem.cpp index 852ff3453..973ed689d 100644 --- a/src/xmodem.cpp +++ b/src/xmodem.cpp @@ -50,6 +50,8 @@ #include "xmodem.h" +#ifdef FSCom + XModemAdapter xModem; XModemAdapter::XModemAdapter() {} @@ -248,4 +250,6 @@ void XModemAdapter::handlePacket(meshtastic_XModem xmodemPacket) // Unknown control character break; } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/xmodem.h b/src/xmodem.h index 2ba0bb39f..795fab302 100644 --- a/src/xmodem.h +++ b/src/xmodem.h @@ -38,6 +38,8 @@ #define MAXRETRANS 25 +#ifdef FSCom + class XModemAdapter { public: @@ -59,7 +61,7 @@ class XModemAdapter uint16_t packetno = 0; -#if defined(ARCH_NRF52) || defined(ARCH_STM32WL) +#if defined(ARCH_NRF52) File file = File(FSCom); #else File file; @@ -75,3 +77,4 @@ class XModemAdapter }; extern XModemAdapter xModem; +#endif // FSCom \ No newline at end of file diff --git a/variants/rak11720/mbed/.c-flags b/variants/rak11720/mbed/.c-flags new file mode 100644 index 000000000..33d97d23b --- /dev/null +++ b/variants/rak11720/mbed/.c-flags @@ -0,0 +1 @@ +-c -std=gnu11 -DMBED_MINIMAL_PRINTF -DMBED_TRAP_ERRORS_ENABLED=1 -Os -fdata-sections -ffunction-sections -fmessage-length=0 -fno-exceptions -fomit-frame-pointer -funsigned-char -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb \ No newline at end of file diff --git a/variants/rak11720/mbed/.c-symbols b/variants/rak11720/mbed/.c-symbols new file mode 100644 index 000000000..c73c3ed67 --- /dev/null +++ b/variants/rak11720/mbed/.c-symbols @@ -0,0 +1 @@ +-DAM_CUSTOM_BDADDR -DAM_PACKAGE_BGA -DARDUINO_BLE_FIX -DARM_MATH_CM4 -DCOMPONENT_FLASHIAP=1 -DCORDIO_ZERO_COPY_HCI -DDEVICE_FLASH=1 -DDEVICE_I2C=1 -DDEVICE_INTERRUPTIN=1 -DDEVICE_LPTICKER=1 -DDEVICE_MPU=1 -DDEVICE_SERIAL=1 -DDEVICE_SPI=1 -DDEVICE_STDIO_MESSAGES=1 -DDEVICE_USTICKER=1 -DFEATURE_BLE=1 -DTARGET_AMA3B1KK -DTARGET_Ambiq_Micro -DTARGET_Apollo3 -DTARGET_CORDIO -DTARGET_CORTEX -DTARGET_CORTEX_M -DTARGET_FAMILY_Apollo3 -DTARGET_LIKE_CORTEX_M4 -DTARGET_LIKE_MBED -DTARGET_M4 -DTARGET_NAME=SFE_ARTEMIS -DTARGET_RELEASE -DTARGET_RTOS_M4_M7 -DTARGET_SFE_ARTEMIS -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -D__CMSIS_RTOS -D__CORTEX_M4 -D__FPU_PRESENT=1 -D__MBED_CMSIS_RTOS_CM -D__MBED__=1 \ No newline at end of file diff --git a/variants/rak11720/variant.h b/variants/rak11720/variant.h index 4b5c44dd9..82db03f04 100644 --- a/variants/rak11720/variant.h +++ b/variants/rak11720/variant.h @@ -176,6 +176,9 @@ static const uint8_t SCK = PIN_SPI_SCK; #define PIN_WIRE_SDA WB_I2C1_SDA #define PIN_WIRE_SCL WB_I2C1_SCL +#define VARIANT_Wire_SDA PIN_WIRE_SDA +#define VARIANT_Wire_SCL PIN_WIRE_SCL + #ifdef __cplusplus } #endif