- 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.
100 lines
4.2 KiB
C
100 lines
4.2 KiB
C
#include <stdio.h>
|
|
#include <inttypes.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_system.h"
|
|
#include "esp_log.h"
|
|
|
|
#include "board_esp32_s3_zero.h"
|
|
#include "controller_state.h"
|
|
#include "status_led.h"
|
|
#include "profile_manager.h"
|
|
#include "input_calibration.h"
|
|
#include "console_output/usb_gamepad.h"
|
|
#include "ble_hid_host.h"
|
|
#include "config_server.h"
|
|
#include "version.h"
|
|
|
|
static const char *TAG = "APP_MAIN";
|
|
|
|
/* Callback invoked whenever the user switches console emulation profile */
|
|
static void on_profile_changed(console_mode_t new_mode)
|
|
{
|
|
ESP_LOGI(TAG, "Profile changed event: Reconfiguring USB for [%s]", profile_manager_mode_name(new_mode));
|
|
usb_gamepad_change_mode(new_mode);
|
|
}
|
|
|
|
/* Callback invoked whenever a wireless BLE controller sends an input report */
|
|
static void on_controller_report(const controller_state_t *state)
|
|
{
|
|
/* Apply user deadzones, axis inversions, and button swaps */
|
|
controller_state_t calibrated;
|
|
input_calibration_apply(state, &calibrated);
|
|
|
|
/* Forward translated report to host console via USB */
|
|
usb_gamepad_send_state(&calibrated);
|
|
|
|
/* Update live visualizer state if Config AP is active */
|
|
if (config_server_is_active()) {
|
|
config_server_set_latest_state(&calibrated);
|
|
}
|
|
}
|
|
|
|
void app_main(void)
|
|
{
|
|
ESP_LOGI(TAG, "=====================================================");
|
|
ESP_LOGI(TAG, " ESP32-S3-Zero HID Translation Layer Initializing ");
|
|
ESP_LOGI(TAG, " Wireless BLE Input -> USB Console Gamepad Output ");
|
|
ESP_LOGI(TAG, "=====================================================");
|
|
|
|
/* 1. Initialize Onboard WS2812 RGB LED (GPIO21) */
|
|
ESP_ERROR_CHECK(status_led_init());
|
|
|
|
/* 2. Initialize Profile Manager (NVS + BOOT Button on GPIO0) */
|
|
ESP_ERROR_CHECK(profile_manager_init(on_profile_changed));
|
|
console_mode_t initial_mode = profile_manager_get_mode();
|
|
|
|
/* 3. Initialize Input Calibration & Button Remapping */
|
|
ESP_ERROR_CHECK(input_calibration_init());
|
|
|
|
/* 3. Initialize USB Gamepad Device via TinyUSB (Native USB GPIO19/20) */
|
|
ESP_ERROR_CHECK(usb_gamepad_init(initial_mode));
|
|
|
|
/* 4. Initialize BLE Central Host (NimBLE Scanner & Pairing) */
|
|
ESP_ERROR_CHECK(ble_hid_host_init(on_controller_report));
|
|
|
|
/* 5. Initialize Config Server Manager Task */
|
|
ESP_ERROR_CHECK(config_server_init());
|
|
|
|
/* 6. Auto-connect to home Wi-Fi and enable mDNS / OTA if credentials exist */
|
|
if (config_server_has_saved_wifi()) {
|
|
ESP_LOGI(TAG, "Saved Wi-Fi credentials found: Auto-starting Station & mDNS for remote OTA access");
|
|
config_server_request_start();
|
|
}
|
|
|
|
ESP_LOGI(TAG, "=====================================================");
|
|
ESP_LOGI(TAG, " __ __ _ _ _____ ");
|
|
ESP_LOGI(TAG, " | \\/ (_) (_)/ ____| ");
|
|
ESP_LOGI(TAG, " | \\ / |_ _ __ ___ _| | ___ _ __ ");
|
|
ESP_LOGI(TAG, " | |\\/| | | '_ ` _ \\| | | / _ \\| '_ \\ ");
|
|
ESP_LOGI(TAG, " | | | | | | | | | | | |___| (_) | | | |");
|
|
ESP_LOGI(TAG, " |_| |_|_|_| |_| |_|_|\\_____\\___/|_| |_|");
|
|
ESP_LOGI(TAG, " Universal Gamepad Bridge v%s (%s)", MIMICON_VERSION_STRING, MIMICON_BUILD_NAME);
|
|
ESP_LOGI(TAG, "=====================================================");
|
|
ESP_LOGI(TAG, "Target Console Mode: %s", profile_manager_mode_name(initial_mode));
|
|
ESP_LOGI(TAG, "How to launch Config Web Server:");
|
|
ESP_LOGI(TAG, " - Hold [SELECT + START + D-PAD UP] on controller for 1.5s");
|
|
ESP_LOGI(TAG, " - Or hold BOOT button (GPIO0) on the ESP32 for 2s");
|
|
ESP_LOGI(TAG, " - Connect to Wi-Fi [MimiCon-Setup] -> http://192.168.4.1/");
|
|
ESP_LOGI(TAG, " - Or via Home Network: http://mimicon.local/ (or http://esp32-hid.local/)");
|
|
ESP_LOGI(TAG, "How to switch console profiles instantly:");
|
|
ESP_LOGI(TAG, " - Hold [START + Face Button] for 1.5s (Configurable in Web Portal)");
|
|
ESP_LOGI(TAG, " - Supported: Switch, PC, PS3, PS4, Xbox 360, Original Xbox, Mouse/Keys");
|
|
ESP_LOGI(TAG, " - Or press physical BOOT button (GPIO0) to cycle modes");
|
|
ESP_LOGI(TAG, "=====================================================");
|
|
|
|
while (1) {
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
}
|
|
}
|