From 54283ca7dd0c7a6251bc7a7b926245b01d0eb612 Mon Sep 17 00:00:00 2001 From: MultiMote Date: Mon, 4 May 2026 20:37:23 +0300 Subject: [PATCH] Fix Cap LoRa868 invalid initialization --- variants/m5stack_cardputer/M5CardputerBoard.h | 16 ++-------------- variants/m5stack_cardputer/target.cpp | 8 ++++++++ variants/m5stack_cardputer/target.h | 3 +++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/variants/m5stack_cardputer/M5CardputerBoard.h b/variants/m5stack_cardputer/M5CardputerBoard.h index 89bb152..6e9948c 100644 --- a/variants/m5stack_cardputer/M5CardputerBoard.h +++ b/variants/m5stack_cardputer/M5CardputerBoard.h @@ -11,15 +11,10 @@ class M5CardputerBoard : public ESP32Board { public: void begin() { - // Step 1: Enable power to I/O expander on LoRa Cap (GPIO 46) - pinMode(46, OUTPUT); - digitalWrite(46, HIGH); - delay(100); // Give I/O expander time to power up - - // Step 2: Initialize main I2C (SDA=2, SCL=1) before M5Cardputer keyboard init + // Step 1: Initialize main I2C (SDA=2, SCL=1) before M5Cardputer keyboard init ESP32Board::begin(); - // Step 3: Initialize M5Cardputer hardware with keyboard enabled + // Step 2: Initialize M5Cardputer hardware with keyboard enabled auto cfg = M5.config(); cfg.clear_display = true; cfg.internal_imu = false; // No IMU on Cardputer-Adv @@ -30,13 +25,6 @@ class M5CardputerBoard : public ESP32Board { delay(100); M5Cardputer.Keyboard.begin(); - M5.In_I2C.writeRegister8(0x43, 0x03, 0x00, 100000); - delay(10); - M5.In_I2C.writeRegister8(0x43, 0x01, 0xFF, 100000); - delay(200); - - Serial.println("LoRa Cap I/O expander (PI4IOE at 0x43 on SDA=8,SCL=9) configured"); - Serial.println("M5Stack Cardputer-Adv initialized"); Serial.print("Battery voltage: "); Serial.print(getBattMilliVolts()); diff --git a/variants/m5stack_cardputer/target.cpp b/variants/m5stack_cardputer/target.cpp index 86ec54a..97eeb08 100644 --- a/variants/m5stack_cardputer/target.cpp +++ b/variants/m5stack_cardputer/target.cpp @@ -2,6 +2,7 @@ #include "target.h" M5CardputerBoard board; +m5::PI4IOE5V6408_Class ioe(0x43, 400000, &m5::In_I2C);; static SPIClass spi; RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi, SPISettings()); @@ -189,6 +190,13 @@ SensorManager sensors; bool radio_init() { fallback_clock.begin(); rtc_clock.begin(Wire); + + if (ioe.begin()) { + Serial.printf("Using Cap LoRa-1262\n"); + ioe.setDirection(0, true); // Output + ioe.setHighImpedance(0, false); // Disable high-impedance so pin can actually drive + ioe.digitalWrite(0, true); // High Level + } // Hardware reset sequence for LoRa module // This ensures proper initialization even if module is connected after power-on diff --git a/variants/m5stack_cardputer/target.h b/variants/m5stack_cardputer/target.h index 5884797..5951fd6 100644 --- a/variants/m5stack_cardputer/target.h +++ b/variants/m5stack_cardputer/target.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #ifdef HAS_GPS @@ -39,6 +40,8 @@ class CardputerSensorManager : public SensorManager { extern M5CardputerBoard board; extern WRAPPER_CLASS radio_driver; extern AutoDiscoverRTCClock rtc_clock; +extern m5::PI4IOE5V6408_Class ioe; + #ifdef HAS_GPS extern CardputerSensorManager sensors; #else