1 / 4
Hardware

ESP-Mosaico_MagPad Magnetic Game Controller

This page was translated by AI and may differ from the original
电路

14-key magnetic‑suction controller based on CH592F: plug in USB for a driver‑free HID controller, also supports BLE wireless and 19200 serial reporting; onboard battery voltage detection, triple alerts for low power via serial/Bluetooth battery level/red LED, and automatic shutdown after 10 seconds.

6893

ESP-Mosaico Magnetic Pad · CH592F Triple‑Mode (USB / BLE / UART)

One‑sentence summary
A 14‑key magnetic pad based on CH592F: plug in USB for a driver‑free HID controller, also supports BLE wireless; reports over 19200 UART; onboard battery voltage detection with triple alerts (UART / Bluetooth battery level / red LED) when low; automatically powers off after 10 seconds.

ItemSpecification
Main MCUCH592F (QFN28, RISC‑V + BLE 5.4 + USB 2.0 FS)
PowerSingle‑cell Li‑battery 3.7 V → 3.3 V LDO, PB14 controls LDO self‑hold
InterfaceUSB (HID) / BLE (HID) / UART 19200 8N1
Buttons14 keys (4‑direction hat, A/B/X/Y, LB/RB, LT/RT, Back/Start)
IndicatorPB23 red LED (active low)
FirmwareC, compiled with MounRiver Studio, approx. 156 KB Flash / 19 KB RAM

1. Project Highlights

All three modes presentUSB HID, BLE HID, and UART can be connected simultaneously; input prefers USB, falls back to BLE, UART always mirrors output
14 keys / W3C standard layoutA B X Y LB RB LT RT Back Start + directional hat; recognized directly by Windows joy.cpl, browser Gamepad API, emulators
Driver‑freeUSB uses generic HID (VID:PID 0x0079:0x0006), driver‑free on Windows / Linux / macOS
Standard Bluetooth Battery ServiceBAS 0x180F / 0x2A19, normal 100 %, low 5 %, phone/computer shows battery level directly
Triple low‑battery alertUART A5 5B alarm frame + BLE battery 5 % + PB23 red LED 0.25 Hz flashing, power off after 10 s
Simple UART protocol19200 8N1, 5‑byte fixed‑length frames with XOR checksum and 400 ms heartbeat, includes ready‑to‑use C parsing code
Two enclosure versionsUltra‑thin case for 800 mAh 504330 pouch cell, long‑run case for 18650 battery
Fully open sourceFirmware source, protocol docs, pre‑compiled hex, build scripts all open

2. Hardware Design

2.1 Main Components

ReferencePart / SpecDescription
U1CH592F (QFN28)RISC‑V + BLE 5.4 + USB 2.0 full‑speed
U2IP5305T (ESOP8)Power‑bank buck‑boost integrated chip
X132 MHz crystal oscillator (no load)BLE RF clock, required
LDO1ME6211C33M5G‑NSingle‑cell Li‑battery → 3.3 V, EN controlled by PB14
USBType‑C recessed board 1.6 mmD+/D‑ directly to PB11/PB10

2.2 Additional Components

NamePart / SpecDescription
MagnetDiameter 4 mm, thickness 2 mmCylindrical axially magnetized
Battery18650 Li‑ion cellObserve polarity
Spring pinOuter diameter 2 mm, height 3 mmSee figure below

2.3 Pin Assignment (CH592F QFN28)

FunctionPinGPIODescription
LDO_EN9PB14Outputs high immediately on power‑up, LDO self‑hold
Red LED16PB23Active low, steady on during operation / flashes when low
USB D‑13PB10USB device
USB D+12PB11USB device
UART TX7PA9 / TXD119200 8N1, connects to main MCU RX
UART RX6PA8 / RXD1Reserved, not parsed by current firmware
32 Mhz crystal19 / 18X32MI / X32MORequired for BLE
K1 UP23PA4mask 0x0001
K2 LEFT24PA5mask 0x0002
K3 DOWN28PA12mask 0x0004
K4 RIGHT27PA13mask 0x0008
K5 Y26PA14mask 0x0010
K6 X25PA15mask 0x0020
K7 A15PB4mask 0x0040
K8 B14PB7mask 0x0080
K9 SELECT17PB22mask 0x0100
K10 START8PB15mask 0x0200
K11 LT11PB12mask 0x0400
K12 RT10PB13mask 0x0800
K13 LB2PA10mask 0x1000 (added in v1.2)
K14 RB1PA11mask 0x2000 (added in v1.2)

3. Firmware Features

3.1 Three Connection Modes

ChannelBehavior
UARTAlways output: send frame immediately on key change, heartbeat every 400 ms when idle
USBAfter successful enumeration, input prefers USB HID
BLEWhen USB not ready, use BLE HID notifications; automatically re‑advertise after disconnection

3.2 Shortcut Keys

OperationEffect
Long‑press SELECT for 5 sPower‑off: PB14 pulled low (battery power cut; USB power resets after 0.5 s)
Long‑press SELECT + START for 3 sClear all Bluetooth pairing records
Idle 15 minutesAutomatic shutdown; press START to wake and reset

3.3 Battery Management

  • Uses CH592 internal VBAT channel (ADC channel 14), sampled once per second, no external resistor divider needed;
  • < 3.3 V: PB23 red LED flashes at 0.25 Hz (2 s on / 2 s off) as early warning;
  • < 3.0 V (confirmed three consecutive times): UART sends A5 5B alarm frame, BLE battery level drops to 5 %, power off after 10 s;
  • Voltage rising above 3.05 V automatically clears the alarm.

Note: The internal channel measures VDD33. When the LDO regulates, it reads 3.3 V; only when the battery voltage falls below the LDO dropout does the reading follow the battery, so the 3.0 V trigger point is actually about “3.0 V + LDO dropout”. It is only used to distinguish full vs low battery levels, not a percentage measurement.

3.4 HID Report (USB and BLE identical)

7 bytes: X, Y, Rx, Ry, hat+pad, btnLo, btnHi

Button12345678910
FunctionABXYLBRBLTRTBackStart
KeyK7K8K6K5K13K14K11K12K9K10

USB VID:PID = 0x0079:0x0006; BLE name ESP-Mosaico MagPad, HID service 0x1812.

3.5 UART Protocol (for main‑controller developers)

A5 5A           // Key frame, mask_H = (mask>>8) & 0x3F
A5 5B               // Low‑battery alarm frame, mv unit mV
  • 19200 8N1, unidirectional transmission;
  • mask 14‑bit, bit n = KEY_(n+1) pressed, e.g., K1 → A5 5A 01 00 FE;
  • Full mask table, example frames and ready‑to‑use C state machine are in the repository docs/protocol.md.

4. File Overview

├── src/            Firmware source (main/board/keys/pad_hid/usb_hid/pad_ble/
│                   hidpadservice/bas_service/battery/uart_link/...)
├── sdk/ch59x/      WCH CH592 EVT code and libraries (HAL, StdPeriphDriver, BLE lib)
├── docs/protocol.md UART protocol + mask table + C parsing code
├── scripts/build.ps1 One‑click build
├── hardware/       Schematics / PCB / BOM / enclosures (to be added)
├── prebuilt/       PAD_CH592.hex (release), PAD_DIAG.hex (diagnostic)
├── README.md       Detailed description
└── THIRD-PARTY.md  Third‑party code and licenses

5. Open‑Source License

ScopeLicense
Application‑layer code (source under src/ except WCH‑derived files, scripts/, docs/)MIT
src/hiddev.c/.h, src/devinfoservice.c/.h, sdk/ch59x/ (including libCH59xBLE.a, libISP592.a)Owned by WCH, under its original terms

MIT does not cover the WCH SDK portion.

6. Revision History

  • v1.2: Added K13/K14 (PA10/PA11 → LB/RB, UART mask bits 12/13); PB23 LED changed to active low; PB15 button changed to active low (power‑off wake‑up changed to falling edge); BLE firmware version updated to 1.2.
  • v1.0: Initial release (12 keys, LED active high, PB15 active high).

7. Acknowledgements

  • Key layout and UART protocol based on ESP-Mosaico (CH552T version);
  • Chip and peripheral libraries from WCH (Nanjing Qinheng) CH592 EVT SDK;
  • Thanks to JLCPCB for PCB fabrication and open‑source platform.

Release Information

  • Source repository: https://github.com/GhostVisitor/ESP-Mosaico-MagPad

  • Open‑source platform address: https://oshwhub.com/ghostvisitor/project_dmqmmtyf

  • Tags: CH592F, game controller, USB HID, BLE, open-source firmware, magnetic pad

  • Attachments: enclosure STEP, ESP-Mosaico_MagPad_v1_2.hex firmware

Comments (0)