Skip to content

feat(m5stack-cardputer): Add BSP component for M5Stack Cardputer#666

Open
finger563 wants to merge 11 commits into
mainfrom
feat/m5stack-cardputer
Open

feat(m5stack-cardputer): Add BSP component for M5Stack Cardputer#666
finger563 wants to merge 11 commits into
mainfrom
feat/m5stack-cardputer

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Description

  • Add espp::M5StackCardputer, a board support package for the M5Stack
    Cardputer (K132), an ESP32-S3 StampS3-based card computer with a 56-key
    QWERTY keyboard. All GPIO assignments are verified against the official
    M5Cardputer / M5Unified / M5GFX sources and the M5Stack documentation.

  • Display: 1.14" 240x135 IPS (ST7789V2) @ 40MHz SPI with LVGL via
    espp::Display, PWM backlight, panel offsets (40, 52) for the centered
    window in the controller RAM

  • Microphone: SPM1423 PDM with a recording task delivering 16-bit mono
    samples to a callback; mutually exclusive with the speaker (shared
    GPIO 43), enforced at initialization

  • uSD card: SPI mode on a dedicated bus, mounted at /sdcard

  • RGB LED (WS2812 via espp::Neopixel), battery voltage (2:1 divider into
    ADC1), G0/BOOT button via espp::Interrupt, IR TX / Grove pin accessors

  • Example: keyboard-driven text editor using the standard per-example
    Gui class pattern, with key-click beeps, LED color cycling on G0, and
    battery voltage in the status bar

  • Registered in build.yml (esp32s3), upload_components.yml, Doxyfile,
    and the m5stack dev-boards docs

  • Detect the variant at runtime by probing for the TCA8418; expose
    variant() / variant_name() and an internal_i2c() accessor (the ADV bus
    also hosts a BMI270 IMU at 0x68, usable with the espp bmi270 component)

  • ADV keyboard path: configure the TCA8418 as a 7x8 keypad and drain its
    key-event FIFO from the same scanner task, mapping controller key
    numbers onto the same logical 4x14 grid so both variants deliver
    identical KeyEvents (mapping verified against M5Stack's remap chart and
    an independent ESP-IDF implementation)

  • ADV audio: minimal ES8311 DAC bring-up (BCLK-derived clock) after I2S
    enable in initialize_sound(); ADV microphone: standard I2S from the
    codec ADC (ASDOUT on GPIO 46) with ES8311 ADC bring-up, replacing the
    PDM path used on the original

Motivation and Context

The M5Stack Cardputer is a unique ESP32-S3-based board with a built-in keyboard, display, and audio capabilities. This BSP component provides a standardized interface for developers to utilize the board's features in their applications, enabling easier development of keyboard-driven interfaces, audio playback, and microphone input.

The Cardputer ADV replaces the original's 74HC138 GPIO-matrix keyboard
with a TCA8418 I2C keyboard controller (0x34 on an internal I2C bus at
GPIO 8/9, the pins the original used as demux address lines), and routes
the same I2S speaker/microphone pins through an ES8311 codec instead of
the NS4168 amp / SPM1423 PDM mic.

How has this been tested?

  • Build and run m5stack-cardputer/example on the ADV variant, verify keyboard input, audio playback, microphone recording, and display output.

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

Copilot AI review requested due to automatic review settings July 14, 2026 03:59
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

@finger563 finger563 self-assigned this Jul 14, 2026
@finger563 finger563 added the enhancement New feature or request label Jul 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new ESPP board support package component for the M5Stack Cardputer (K132) and Cardputer ADV (ESP32-S3), including runtime variant detection, integrated peripherals (display/keyboard/audio/mic/uSD/LED/battery/button), an LVGL example app, and corresponding docs + CI registry integration.

Changes:

  • Introduces espp::M5StackCardputer BSP implementation (display, keyboard for both variants, audio output, microphone input, uSD, RGB LED, battery voltage, button, internal I2C accessor).
  • Adds a keyboard-driven LVGL example (text editor + key-click beeps + LED cycling + battery status).
  • Registers the new component in docs (Sphinx + Doxygen) and CI workflows (build matrix + component upload list).

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
doc/en/dev_boards/m5stack/m5stack_cardputer.rst New dev-board documentation page for Cardputer + ADV.
doc/en/dev_boards/m5stack/m5stack_cardputer_example.md Includes the example README into the docs site.
doc/en/dev_boards/m5stack/index.rst Adds Cardputer page to the M5Stack boards index.
doc/Doxyfile Registers the component header + example for Doxygen.
components/m5stack-cardputer/CMakeLists.txt New component build registration and dependencies.
components/m5stack-cardputer/Kconfig Adds configurable task stacks/priorities/affinity for BSP tasks.
components/m5stack-cardputer/README.md Component overview and feature documentation.
components/m5stack-cardputer/idf_component.yml Component Manager manifest metadata and dependencies.
components/m5stack-cardputer/include/m5stack-cardputer.hpp Public BSP API (singleton, peripherals, variant detection, keyboard mapping, etc.).
components/m5stack-cardputer/src/m5stack-cardputer.cpp Core BSP implementation (button/LED, ES8311 init, battery readout).
components/m5stack-cardputer/src/display.cpp LCD + LVGL display initialization and helpers.
components/m5stack-cardputer/src/keyboard.cpp Runtime variant probe, keyboard init, matrix scan + TCA8418 FIFO handling.
components/m5stack-cardputer/src/audio.cpp I2S speaker path + ADV codec bring-up and playback task.
components/m5stack-cardputer/src/microphone.cpp PDM mic (original) and I2S codec ADC mic (ADV) recording task.
components/m5stack-cardputer/src/sdcard.cpp Dedicated SPI uSD card mount helper.
components/m5stack-cardputer/example/CMakeLists.txt Example project CMake with component wiring.
components/m5stack-cardputer/example/sdkconfig.defaults Example defaults (LVGL, USB-Serial-JTAG console, etc.).
components/m5stack-cardputer/example/README.md Example usage guide and controls.
components/m5stack-cardputer/example/main/CMakeLists.txt Example “main” component registration.
components/m5stack-cardputer/example/main/m5stack_cardputer_example.cpp Example app main: initializes peripherals + GUI + callbacks.
components/m5stack-cardputer/example/main/gui.hpp Example GUI class interface and task pattern.
components/m5stack-cardputer/example/main/gui.cpp Example LVGL UI implementation and thread-safe helpers.
.github/workflows/build.yml Adds Cardputer example to CI build matrix (esp32s3).
.github/workflows/upload_components.yml Adds m5stack-cardputer to component upload workflow.

Comment thread components/m5stack-cardputer/src/keyboard.cpp
Comment thread components/m5stack-cardputer/src/keyboard.cpp
Comment thread components/m5stack-cardputer/src/keyboard.cpp Outdated
Comment thread components/m5stack-cardputer/src/microphone.cpp
Comment thread components/m5stack-cardputer/src/audio.cpp
finger563 and others added 5 commits July 13, 2026 23:09
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…call_once

variant() and internal_i2c() lazily detect the board variant; the
previous atomic-flag double-check let two concurrent first callers both
probe the I2C bus. Funnel both through a shared std::once_flag so the
detection runs exactly once and concurrent callers block until it
completes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
finger563 and others added 4 commits July 13, 2026 23:35
…pport

- battery_soc(): estimate the battery state of charge (0-100%) from the
  measured voltage via a piecewise-linear 1S lithium-ion discharge curve
  (documented as an approximation since the voltage sags under load)
- initialize_imu() / imu(): bring up the Cardputer ADV's BMI270 on the
  internal I2C bus using the espp bmi270 driver (with optional
  orientation filter and configurable ImuConfig); fails with a clear
  error on the original Cardputer, which has no IMU
- Example: status bar now shows voltage and state of charge; on the ADV
  a top-right overlay shows live accelerometer / gyroscope readings
  updated at 10 Hz

Clean-built with ESP-IDF for esp32s3.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…unked config upload)

The BMI270 init failed on hardware: the driver uploads its 8kB config
blob, which by default is written in a single I2C transaction that
exceeds the internal I2C bus timeout. Upload it in 128-byte bursts
instead, and probe both possible I2C addresses (0x68/0x69) to find the
device rather than assuming the SDO strap.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… example

- fn+1 (F1) toggles a centered popup listing the controls; fn+2 (F2)
  toggles the IMU overlay visibility (IMU updates pause while hidden)
- The controls are defined once (Gui::HELP_TEXT), shown in the popup, and
  printed to the log at startup
- Document the new controls in the example README

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request m5stack cardputer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants