Files
MeshCore/variants/m5stack_cardputer_adv/CardputerAdvBoard.h
T
mjgodatandClaude Opus 5.5 5681898ad4 Add M5Stack Cardputer-Adv variant with keyboard/display companion UI
New variant variants/m5stack_cardputer_adv for the Cardputer-Adv
(ESP32-S3, 8 MB) with the Cap LoRa-1262 (SX1262 + GNSS):

- Envs: companion_radio_ble, companion_radio_usb, repeater, room_server.
- Board: enables the Cap's antenna path via the PI4IOE5V6408 on the
  internal I2C bus (Wire1, G8/G9); Wire stays on the Grove port. LoRa and
  microSD share FSPI because the display owns SPI3. TCXO 1.8 V.
- Companion UI adapted from MultiMote/meshcore-cardputer-adv (MIT,
  LICENSE.MultiMote), running on the standard companion so the USB
  terminal CLI stays available. Contacts/identity stay in internal
  SPIFFS; the microSD card is optional (chat history, keyboard layouts).
- Sticky Shift, one-shot Fn with Fn+letter shortcuts, top button (G0)
  sends a flood advert, brightness control.
- Text size setting (Normal/Large/Extra large) with DejaVu Sans fonts
  generated by tools/gen_vlw_font.py; layouts derive from the font size.
- Power save maps to the companion's powersaving pref; the UI vetoes
  light sleep while the screen is on. Low-battery power-off at 3.4 V.
- win_long_cmdline.py: Windows-only -iprefix include shortening so the
  ESP32 compile command stays under the 32,767-character limit.

Shared companion changes are guarded by CARDPUTER_ADV_UI: main.cpp
selects CardputerDataStore/CardputerUITask/CardputerMesh, and MyMesh.h
maps the_mesh to the subclass like the PSRAM storage path does.

Tested on hardware (910.525 MHz mesh): radio RX/TX, USB CLI, BLE, UI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:24:43 -07:00

68 lines
2.0 KiB
C++

#pragma once
#include <Arduino.h>
#include <Wire.h>
#include <helpers/ESP32Board.h>
#include "globals.h"
#if CARDPUTER_ADV_UI
#include <FS.h>
#include "hw/CardputerSpeaker.h"
#include "hw/CardputerKeyboard.h"
#include "hw/CardputerLayout.h"
#endif
// M5Stack Cardputer-Adv with the Cap LoRa-1262 (SX1262 + ATGM336H GNSS).
// The internal I2C bus (G8/G9, Wire1) carries the keyboard, the audio codec
// and the Cap's PI4IOE5V6408 expander; Wire stays on the Grove port (G2/G1).
// The radio cannot reach the antenna until expander P0 is driven high.
// Sleep, deep sleep and power-off are ESP32Board's (no LoRa wake on power-off).
// Keyboard/display/speaker UI adapted from MultiMote/meshcore-cardputer-adv
// (MIT, see LICENSE.MultiMote).
#define CARDPUTER_PI4IO_REG_IO_DIR 0x03
#define CARDPUTER_PI4IO_REG_OUT_SET 0x05
#define CARDPUTER_PI4IO_REG_OUT_HIZ 0x07
class CardputerAdvBoard : public ESP32Board {
bool _lora_cap_ok = false;
#if CARDPUTER_ADV_UI
CardputerSpeaker speaker;
CardputerKeyboard keyboard;
CardputerLayout layout;
#endif
static bool pi4ioWrite(uint8_t reg, uint8_t val) {
Wire1.beginTransmission(LORA_IOE_I2C_ADDRESS);
Wire1.write(reg);
Wire1.write(val);
return Wire1.endTransmission() == 0;
}
public:
void begin() {
ESP32Board::begin(); // starts Wire on PIN_BOARD_SDA/SCL (Grove)
Wire1.begin(PIN_I2C_INTERNAL_SDA, PIN_I2C_INTERNAL_SCL, 100000);
_lora_cap_ok = pi4ioWrite(CARDPUTER_PI4IO_REG_IO_DIR, 0x01)
&& pi4ioWrite(CARDPUTER_PI4IO_REG_OUT_HIZ, 0x00)
&& pi4ioWrite(CARDPUTER_PI4IO_REG_OUT_SET, 0x01);
#if CARDPUTER_ADV_UI
keyboard.begin();
#endif
}
bool isLoraCapReady() const { return _lora_cap_ok; }
#if CARDPUTER_ADV_UI
CardputerSpeaker *getSpeaker() { return &speaker; }
CardputerKeyboard *getKeyboard() { return &keyboard; }
CardputerLayout *getLayout() { return &layout; }
void readKeyboardLayout(FS &fs) { layout.begin(fs); }
#endif
const char* getManufacturerName() const override {
return "M5Stack Cardputer-Adv";
}
};