feat(boards): Add secondary button support to Waveshare ESP32-C6-Touch-AMOLED-2.16

- Enable BTN_FWD_GPIO (GPIO 10) as secondary button for mode toggle (Shift+Tab)
- Update BOARD_HAS_SECONDARY_BUTTON flag from 0 to 1
- Clarify button layout: BOOT (primary PTT), PWR (cycle screens via AXP), KEY (secondary mode toggle)
- Document KEY GPIO discovery method (empirical scanning of unused GPIOs)
- Update button_count calculation to include secondary button when available
- Initialize both BTN_BACK_GPIO and BTN_FWD_GPIO in input_hal_init()
- Refactor input_hal_is_held() to use switch statement for cleaner multi-button handling
This commit is contained in:
Alexander Wennerstrøm
2026-05-24 09:47:31 +02:00
parent ab8b64d949
commit 9f75de55a2
3 changed files with 17 additions and 9 deletions
@@ -42,12 +42,17 @@
#define AXP2101_ADDR 0x34
// ---- Buttons ----
// Only one user GPIO button (BOOT). The "PWR" side button is the AXP2101
// PKEY input — already serviced by power.cpp via the PKEY_SHORT_IRQ path.
#define BTN_BACK_GPIO 9 // BOOT — primary, Space (PTT)
// Three side-mounted buttons:
// BOOT (primary) — GPIO 9, sends Space (PTT) over BLE HID
// PWR (cycle screens) — AXP2101 PKEY IRQ, handled in power.cpp
// KEY (secondary) — GPIO 10, sends Shift+Tab (mode toggle) over BLE HID
// KEY GPIO isn't documented by Waveshare; identified empirically by
// scanning unused GPIOs at boot (see git history of board_init.cpp).
#define BTN_BACK_GPIO 9
#define BTN_FWD_GPIO 10
// ---- Capability flags ----
#define BOARD_HAS_SECONDARY_BUTTON 0
#define BOARD_HAS_SECONDARY_BUTTON 1
#define BOARD_HAS_ROTATION 0 // C6 has no PSRAM headroom for the rotation strip
#define BOARD_HAS_IMU 1 // present + initialized for I2C bus health
#define BOARD_HAS_BATTERY 1
@@ -5,7 +5,9 @@ static const BoardCaps caps = {
.name = BOARD_NAME,
.width = LCD_WIDTH,
.height = LCD_HEIGHT,
.button_count = 1, // BOOT only; PWR is via AXP PKEY IRQ
// BOOT (primary) + KEY (secondary) GPIO buttons. PWR is on the AXP
// PKEY and handled separately (not counted here).
.button_count = (uint8_t)(1 + BOARD_HAS_SECONDARY_BUTTON),
.has_rotation = (bool)BOARD_HAS_ROTATION,
.has_battery = (bool)BOARD_HAS_BATTERY,
.has_imu = (bool)BOARD_HAS_IMU,
@@ -2,16 +2,17 @@
#include "board.h"
#include <Arduino.h>
// Only BOOT is wired to a MCU GPIO. The "PWR" side button is the AXP2101
// PKEY, handled in power.cpp.
void input_hal_init(void) {
pinMode(BTN_BACK_GPIO, INPUT_PULLUP);
pinMode(BTN_FWD_GPIO, INPUT_PULLUP);
}
bool input_hal_is_held(InputButton btn) {
if (btn == INPUT_BTN_PRIMARY) {
switch (btn) {
case INPUT_BTN_PRIMARY:
return digitalRead(BTN_BACK_GPIO) == LOW;
case INPUT_BTN_SECONDARY:
return digitalRead(BTN_FWD_GPIO) == LOW;
}
return false;
}