ESP-Mosaico_MagPad Magnetic Game Controller
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.
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.
| Item | Specification |
|---|---|
| Main MCU | CH592F (QFN28, RISC‑V + BLE 5.4 + USB 2.0 FS) |
| Power | Single‑cell Li‑battery 3.7 V → 3.3 V LDO, PB14 controls LDO self‑hold |
| Interface | USB (HID) / BLE (HID) / UART 19200 8N1 |
| Buttons | 14 keys (4‑direction hat, A/B/X/Y, LB/RB, LT/RT, Back/Start) |
| Indicator | PB23 red LED (active low) |
| Firmware | C, compiled with MounRiver Studio, approx. 156 KB Flash / 19 KB RAM |
1. Project Highlights
| All three modes present | USB HID, BLE HID, and UART can be connected simultaneously; input prefers USB, falls back to BLE, UART always mirrors output |
| 14 keys / W3C standard layout | A B X Y LB RB LT RT Back Start + directional hat; recognized directly by Windows joy.cpl, browser Gamepad API, emulators |
| Driver‑free | USB uses generic HID (VID:PID 0x0079:0x0006), driver‑free on Windows / Linux / macOS |
| Standard Bluetooth Battery Service | BAS 0x180F / 0x2A19, normal 100 %, low 5 %, phone/computer shows battery level directly |
| Triple low‑battery alert | UART A5 5B alarm frame + BLE battery 5 % + PB23 red LED 0.25 Hz flashing, power off after 10 s |
| Simple UART protocol | 19200 8N1, 5‑byte fixed‑length frames with XOR checksum and 400 ms heartbeat, includes ready‑to‑use C parsing code |
| Two enclosure versions | Ultra‑thin case for 800 mAh 504330 pouch cell, long‑run case for 18650 battery |
| Fully open source | Firmware source, protocol docs, pre‑compiled hex, build scripts all open |
2. Hardware Design
2.1 Main Components
| Reference | Part / Spec | Description |
|---|---|---|
| U1 | CH592F (QFN28) | RISC‑V + BLE 5.4 + USB 2.0 full‑speed |
| U2 | IP5305T (ESOP8) | Power‑bank buck‑boost integrated chip |
| X1 | 32 MHz crystal oscillator (no load) | BLE RF clock, required |
| LDO1 | ME6211C33M5G‑N | Single‑cell Li‑battery → 3.3 V, EN controlled by PB14 |
| USB | Type‑C recessed board 1.6 mm | D+/D‑ directly to PB11/PB10 |
2.2 Additional Components
| Name | Part / Spec | Description |
|---|---|---|
| Magnet | Diameter 4 mm, thickness 2 mm | Cylindrical axially magnetized |
| Battery | 18650 Li‑ion cell | Observe polarity |
| Spring pin | Outer diameter 2 mm, height 3 mm | See figure below |
2.3 Pin Assignment (CH592F QFN28)
| Function | Pin | GPIO | Description |
|---|---|---|---|
| LDO_EN | 9 | PB14 | Outputs high immediately on power‑up, LDO self‑hold |
| Red LED | 16 | PB23 | Active low, steady on during operation / flashes when low |
| USB D‑ | 13 | PB10 | USB device |
| USB D+ | 12 | PB11 | USB device |
| UART TX | 7 | PA9 / TXD1 | 19200 8N1, connects to main MCU RX |
| UART RX | 6 | PA8 / RXD1 | Reserved, not parsed by current firmware |
| 32 Mhz crystal | 19 / 18 | X32MI / X32MO | Required for BLE |
| K1 UP | 23 | PA4 | mask 0x0001 |
| K2 LEFT | 24 | PA5 | mask 0x0002 |
| K3 DOWN | 28 | PA12 | mask 0x0004 |
| K4 RIGHT | 27 | PA13 | mask 0x0008 |
| K5 Y | 26 | PA14 | mask 0x0010 |
| K6 X | 25 | PA15 | mask 0x0020 |
| K7 A | 15 | PB4 | mask 0x0040 |
| K8 B | 14 | PB7 | mask 0x0080 |
| K9 SELECT | 17 | PB22 | mask 0x0100 |
| K10 START | 8 | PB15 | mask 0x0200 |
| K11 LT | 11 | PB12 | mask 0x0400 |
| K12 RT | 10 | PB13 | mask 0x0800 |
| K13 LB | 2 | PA10 | mask 0x1000 (added in v1.2) |
| K14 RB | 1 | PA11 | mask 0x2000 (added in v1.2) |
3. Firmware Features
3.1 Three Connection Modes
| Channel | Behavior |
|---|---|
| UART | Always output: send frame immediately on key change, heartbeat every 400 ms when idle |
| USB | After successful enumeration, input prefers USB HID |
| BLE | When USB not ready, use BLE HID notifications; automatically re‑advertise after disconnection |
3.2 Shortcut Keys
| Operation | Effect |
|---|---|
| Long‑press SELECT for 5 s | Power‑off: PB14 pulled low (battery power cut; USB power resets after 0.5 s) |
| Long‑press SELECT + START for 3 s | Clear all Bluetooth pairing records |
| Idle 15 minutes | Automatic 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 5Balarm 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
| Button | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Function | A | B | X | Y | LB | RB | LT | RT | Back | Start |
| Key | K7 | K8 | K6 | K5 | K13 | K14 | K11 | K12 | K9 | K10 |
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;
mask14‑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
| Scope | License |
|---|---|
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.hexfirmware
Comments (0)