feat: expose dongle debug info through the C API

Add an opaque xone_dongle session handle to the C ABI bridge:
xone_open() probes, resets, and loads the firmware (path optional),
and xone_pid/xone_chip_id/xone_mac_address/xone_firmware_build return
debug info for the open session. chip captures the firmware build
string from the image header during load.

The Swift app opens a session when the dongle appears and shows PID,
chip ID, MAC address, and firmware build string in a debug section.

Co-Authored-By: qwen3.8-27b@q2_k_xl: added C API session handle and debug UI
This commit is contained in:
portersky
2026-08-17 16:44:02 +02:00
parent 21dc0e09b3
commit 4f5f16e43f
6 changed files with 153 additions and 5 deletions
+27
View File
@@ -8,6 +8,7 @@
// ==============================================================================
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@@ -19,6 +20,32 @@ const char *xone_version(void);
// TRUE if an Xbox Wireless Dongle is connected, FALSE otherwise.
bool xone_dongle_present(void);
// Opaque handle to an open dongle session (probe + firmware load).
// Create with xone_open(); call the getters from the thread that opened
// it, and before xone_close(). Only one session may be open at a time.
typedef struct xone_dongle xone_dongle;
// Open a dongle session: probe, USB reset, and (if firmware_path is not
// NULL) load the firmware image from that file. Returns NULL if no dongle
// is present or opening fails.
xone_dongle *xone_open(const char *firmware_path);
// Close the session and release the dongle.
void xone_close(xone_dongle *d);
// Product ID of the connected dongle (e.g. 0x02E6).
uint16_t xone_pid(const xone_dongle *d);
// Chip ID from EFUSE (e.g. 0x7612 for MT7612). 0 if unknown.
uint16_t xone_chip_id(const xone_dongle *d);
// MAC address from EFUSE as "xx:xx:xx:xx:xx:xx". Valid until xone_close().
const char *xone_mac_address(const xone_dongle *d);
// Build string of the loaded firmware image (e.g. "201703281033____").
// Empty string if the firmware was not loaded. Valid until xone_close().
const char *xone_firmware_build(const xone_dongle *d);
#ifdef __cplusplus
}
#endif
+4
View File
@@ -45,6 +45,9 @@ public:
// Resets the MCU if firmware is already loaded. Returns 0 or -errno.
auto load_firmware(char const *path) -> int;
// Build string of the loaded firmware image (empty until load_firmware).
auto firmware_build() const -> char const *;
private:
// Send an MCU command (port of xone_mt76_send_command). `cmd` is the
// MT_MCU_MSG_CMD_TYPE field. Returns bytes written, or a negative errno.
@@ -59,6 +62,7 @@ private:
auto reset_firmware() -> int;
usb::transport &transport_;
char build_time_[17] = {};
};
} // namespace xone::mt76