Files
MimiCon/main/parsers/controller_parser.h
T
dark98 21f54f1b92 Initial commit: MimiCon v1.0.0 - Universal Gamepad Mimic & Console Bridge
- Dual-Core Architecture: Dedicated 1000Hz USB gaming pipeline on Core 1 and BLE/Wi-Fi/Web telemetry on Core 0.
- Multi-Input BLE Host: Parsers for Xbox Wireless, Google Stadia, 8BitDo (Ultimate/Pro2/SN30), and Generic HOGP gamepads.
- Multi-Console USB Emulation: Nintendo Switch, PC DirectInput, PS3, PS4, Xbox 360 (libxsm3 cryptographic challenge-response), Original Xbox, and Couch Mouse/Keyboard.
- Onboard Web Portal & Captive Portal: Real-time SVG gamepad visualizer, stick deadzone calibration, button combo remapping, and Wi-Fi manager.
- Low-Latency Radio Management: Interactive SoftAP toggle to drop to 0-latency gaming mode.
- Dual OTA Firmware Flashing: Browser-based wireless firmware updater and automated Python OTA script.
- Strict Build Quality: Clean build under -Wall -Wextra with zero warnings or errors.
- Versioning & Licensing: Semantic Versioning v1.0.0 and GNU GPLv3 with Commercial Restrictions.
2026-10-17 18:26:50 +01:00

61 lines
1.6 KiB
C

#pragma once
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "controller_state.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
CONTROLLER_TYPE_UNKNOWN = 0,
CONTROLLER_TYPE_XBOX_BLE,
CONTROLLER_TYPE_GENERIC_HOGP,
CONTROLLER_TYPE_8BITDO,
CONTROLLER_TYPE_STADIA,
} controller_type_t;
/**
* @brief Scale an 8-bit analog stick axis (0..255, 128 centered) to signed 16-bit (-32768..32767)
* with overflow protection.
*/
static inline int16_t scale_axis_8bit(uint8_t raw, bool invert)
{
int32_t val = invert ? ((int32_t)128 - raw) * 256 : ((int32_t)raw - 128) * 256;
if (val > 32767) val = 32767;
if (val < -32768) val = -32768;
return (int16_t)val;
}
/**
* @brief Parse a standard 0-indexed 8-way Hat Switch (D-Pad).
* 0=Up, 1=Up-Right, 2=Right, 3=Down-Right, 4=Down, 5=Down-Left, 6=Left, 7=Up-Left, 8=Centered
*/
static inline void parse_hat_switch_8way(uint8_t hat, controller_state_t *out_state)
{
hat &= 0x0F;
if (hat < 8) {
out_state->dpad_up = (hat == 0 || hat == 1 || hat == 7) ? 1 : 0;
out_state->dpad_right = (hat == 1 || hat == 2 || hat == 3) ? 1 : 0;
out_state->dpad_down = (hat == 3 || hat == 4 || hat == 5) ? 1 : 0;
out_state->dpad_left = (hat == 5 || hat == 6 || hat == 7) ? 1 : 0;
}
}
/**
* @brief Base parser function prototype
*/
typedef bool (*controller_parse_fn_t)(const uint8_t *report, size_t len, controller_state_t *out_state);
typedef struct {
const char *name;
controller_type_t type;
controller_parse_fn_t parse;
} controller_driver_t;
#ifdef __cplusplus
}
#endif