Modified by ChatGPT for migration to microRecticulum_Firmware, not verified by me... yet, but I am preserving to document this stage.

This commit is contained in:
John Poole 2026-02-14 10:10:31 -08:00
commit 432f17b2be
12 changed files with 188 additions and 162 deletions

View file

@ -12,16 +12,13 @@ board = esp32-s3-devkitc-1
monitor_speed = 115200
lib_deps =
lewisxhe/XPowersLib@0.3.3
Wire
; SD pins based on T-Beam S3 core pin mapping
build_flags =
-D SD_SCK=36
-D SD_MISO=37
-D SD_MOSI=35
-D SD_CS=47
-D IMU_CS=34
-D I2C_SDA1=42
-D I2C_SCL1=41
-I ../../shared/boards
-I ../../external/microReticulum_Firmware
-D BOARD_MODEL=BOARD_TBEAM_S_V1
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1

View file

@ -7,30 +7,7 @@
#include <FS.h>
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <XPowersLib.h>
#ifndef SD_SCK
#define SD_SCK 36
#endif
#ifndef SD_MISO
#define SD_MISO 37
#endif
#ifndef SD_MOSI
#define SD_MOSI 35
#endif
#ifndef SD_CS
#define SD_CS 47
#endif
#ifndef IMU_CS
#define IMU_CS 34
#endif
#ifndef I2C_SDA1
#define I2C_SDA1 42
#endif
#ifndef I2C_SCL1
#define I2C_SCL1 41
#endif
#include "tbeam_supreme_adapter.h"
static SPIClass sdSpiH(HSPI);
static SPIClass sdSpiF(FSPI);
@ -78,32 +55,7 @@ static void logf(const char* fmt, ...) {
}
static bool initPmuForSdPower() {
Wire1.begin(I2C_SDA1, I2C_SCL1);
if (!g_pmu) {
g_pmu = new XPowersAXP2101(Wire1);
}
if (!g_pmu->init()) {
logf("PMU: AXP2101 init failed (SD power rail may be off)");
return false;
}
// Mirror Meshtastic tbeam-s3-core power setup needed for peripherals.
g_pmu->setPowerChannelVoltage(XPOWERS_ALDO4, 3300); // GNSS
g_pmu->enablePowerOutput(XPOWERS_ALDO4);
g_pmu->setPowerChannelVoltage(XPOWERS_ALDO3, 3300); // LoRa
g_pmu->enablePowerOutput(XPOWERS_ALDO3);
g_pmu->setPowerChannelVoltage(XPOWERS_ALDO2, 3300); // sensor/rtc path
g_pmu->enablePowerOutput(XPOWERS_ALDO2);
g_pmu->setPowerChannelVoltage(XPOWERS_ALDO1, 3300); // IMU/OLED path
g_pmu->enablePowerOutput(XPOWERS_ALDO1);
g_pmu->setPowerChannelVoltage(XPOWERS_BLDO1, 3300); // SD card rail
g_pmu->enablePowerOutput(XPOWERS_BLDO1);
logf("PMU: AXP2101 ready, BLDO1(SD)=%s",
g_pmu->isPowerChannelEnable(XPOWERS_BLDO1) ? "ON" : "OFF");
return g_pmu->isPowerChannelEnable(XPOWERS_BLDO1);
return tbeam_supreme::initPmuForPeripherals(g_pmu, &Serial);
}
static const char* cardTypeToString(uint8_t type) {
@ -121,18 +73,18 @@ static bool tryMountWithBus(SPIClass& bus, const char* busName, uint32_t hz, boo
delay(10);
// Keep inactive devices deselected on shared bus lines.
pinMode(SD_CS, OUTPUT);
digitalWrite(SD_CS, HIGH);
pinMode(IMU_CS, OUTPUT);
digitalWrite(IMU_CS, HIGH);
pinMode(tbeam_supreme::sdCs(), OUTPUT);
digitalWrite(tbeam_supreme::sdCs(), HIGH);
pinMode(tbeam_supreme::imuCs(), OUTPUT);
digitalWrite(tbeam_supreme::imuCs(), HIGH);
bus.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
bus.begin(tbeam_supreme::sdSck(), tbeam_supreme::sdMiso(), tbeam_supreme::sdMosi(), tbeam_supreme::sdCs());
delay(2);
if (verbose) {
logf("SD: trying bus=%s freq=%lu Hz", busName, (unsigned long)hz);
}
if (!SD.begin(SD_CS, bus, hz)) {
if (!SD.begin(tbeam_supreme::sdCs(), bus, hz)) {
if (verbose) {
logf("SD: mount failed (possible non-FAT format, power, or bus issue)");
}
@ -321,8 +273,11 @@ void setup() {
Serial.println("\r\n==================================================");
Serial.println("Exercise 05: SD Card Watcher");
Serial.println("==================================================");
Serial.printf("Pins: CS=%d SCK=%d MISO=%d MOSI=%d\r\n", SD_CS, SD_SCK, SD_MISO, SD_MOSI);
Serial.printf("PMU I2C: SDA1=%d SCL1=%d\r\n", I2C_SDA1, I2C_SCL1);
Serial.printf("Pins: CS=%d SCK=%d MISO=%d MOSI=%d\r\n",
tbeam_supreme::sdCs(), tbeam_supreme::sdSck(),
tbeam_supreme::sdMiso(), tbeam_supreme::sdMosi());
Serial.printf("PMU I2C: SDA1=%d SCL1=%d\r\n",
tbeam_supreme::i2cSda(), tbeam_supreme::i2cScl());
Serial.println("Note: SD must be FAT16/FAT32 for Arduino SD library.\r\n");
initPmuForSdPower();