Organize firmware sources by responsibility

This commit is contained in:
Joey Yakimowich-Payne 2026-09-03 14:28:09 -06:00
commit 200ffc92be
101 changed files with 295 additions and 305 deletions

View file

@ -427,7 +427,7 @@ with the current identity.
#### 4A — Output-driver boundary and production XInput
- replace `SWITCH_PICO_ADAPTER_FEASIBILITY` branches in `switch-pico.cpp` with
- replace `SWITCH_PICO_ADAPTER_FEASIBILITY` branches in `src/firmware/main.cpp` with
one fixed static driver interface: descriptors, init/reset, input, task,
readiness/capabilities, and host output
- keep the Phase 3 profile/runtime transform exactly once before serialization

View file

@ -89,36 +89,37 @@ if(SWITCH_PICO_INPUT_BACKEND STREQUAL "BLUEPAD32")
)
endif()
# Add executable. Default name is the project name, version 0.1
# Firmware sources live under one include root and are grouped by responsibility.
set(SWITCH_PICO_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src/firmware)
add_executable(switch-pico
switch-pico.cpp
switch_pro_driver.cpp
usb_output_driver.cpp
switch_haptics.cpp
${SWITCH_PICO_SOURCE_DIR}/main.cpp
${SWITCH_PICO_SOURCE_DIR}/usb/usb_output_driver.cpp
${SWITCH_PICO_SOURCE_DIR}/usb/switch/switch_pro_driver.cpp
${SWITCH_PICO_SOURCE_DIR}/usb/switch/switch_haptics.cpp
)
if(SWITCH_PICO_INPUT_BACKEND STREQUAL "BLUEPAD32")
target_sources(switch-pico PRIVATE
bluepad32_input_backend.cpp
adapter_host_probe.cpp
adapter_mode_controller.cpp
controller_identity.cpp
controller_profile.cpp
controller_profile_transform.cpp
controller_synthetic_input.cpp
controller_profile_runtime.cpp
profile_storage.cpp
profile_service.cpp
pico_profile_storage.cpp
bootsel_pairing_button.cpp
adapter_configuration.cpp
configuration_storage.cpp
configuration_transaction.cpp
configuration_service.cpp
pico_configuration_storage.cpp
usb_configuration_management.cpp
xinput_driver.cpp
generic_hid_driver.cpp
${SWITCH_PICO_SOURCE_DIR}/adapter/adapter_host_probe.cpp
${SWITCH_PICO_SOURCE_DIR}/adapter/adapter_mode_controller.cpp
${SWITCH_PICO_SOURCE_DIR}/configuration/adapter_configuration.cpp
${SWITCH_PICO_SOURCE_DIR}/configuration/configuration_service.cpp
${SWITCH_PICO_SOURCE_DIR}/configuration/configuration_storage.cpp
${SWITCH_PICO_SOURCE_DIR}/configuration/configuration_transaction.cpp
${SWITCH_PICO_SOURCE_DIR}/core/controller_identity.cpp
${SWITCH_PICO_SOURCE_DIR}/input/bluepad32_input_backend.cpp
${SWITCH_PICO_SOURCE_DIR}/platform/pico/bootsel_pairing_button.cpp
${SWITCH_PICO_SOURCE_DIR}/platform/pico/pico_configuration_storage.cpp
${SWITCH_PICO_SOURCE_DIR}/platform/pico/pico_profile_storage.cpp
${SWITCH_PICO_SOURCE_DIR}/profile/controller_profile.cpp
${SWITCH_PICO_SOURCE_DIR}/profile/controller_profile_runtime.cpp
${SWITCH_PICO_SOURCE_DIR}/profile/controller_profile_transform.cpp
${SWITCH_PICO_SOURCE_DIR}/profile/controller_synthetic_input.cpp
${SWITCH_PICO_SOURCE_DIR}/profile/profile_service.cpp
${SWITCH_PICO_SOURCE_DIR}/profile/profile_storage.cpp
${SWITCH_PICO_SOURCE_DIR}/usb/generic_hid/generic_hid_driver.cpp
${SWITCH_PICO_SOURCE_DIR}/usb/usb_configuration_management.cpp
${SWITCH_PICO_SOURCE_DIR}/usb/xinput/xinput_driver.cpp
)
target_compile_definitions(switch-pico PRIVATE
SWITCH_PICO_BLUEPAD32=1
@ -166,9 +167,11 @@ if (SWITCH_PICO_LOG)
target_compile_definitions(switch-pico PRIVATE SWITCH_PICO_LOG=1)
endif()
# Add the standard include files to the build
# Internal includes are rooted at src/firmware. TinyUSB discovers tusb_config.h
# through the Pico platform directory.
target_include_directories(switch-pico PRIVATE
${CMAKE_CURRENT_LIST_DIR}
${SWITCH_PICO_SOURCE_DIR}
${SWITCH_PICO_SOURCE_DIR}/platform/pico
)
pico_add_extra_outputs(switch-pico)

View file

@ -3,11 +3,31 @@
Raspberry Pi Pico firmware that emulates one or more Switch Pro controllers over USB. Input can come from the SDL3-to-UART computer bridge or, on Pico 2 W, directly from Bluetooth controllers through Bluepad32.
## What you get
- **Firmware** (`switch-pico.cpp` + `switch_pro_driver.*`): acts as a Switch Pro controller (one on standard Pico, four on Pico 2 W AIO), accepting either UART bridge reports or the optional Pico 2 W Bluepad32 backend.
- **Firmware** (`src/firmware/`): acts as a Switch Pro controller (one on standard Pico, four on Pico 2 W AIO), accepting either UART bridge reports or the optional Pico 2 W Bluepad32 backend.
- **Python bridge** (`switch_pico_bridge.controller_uart_bridge` / CLI `controller-uart-bridge`): reads SDL3 controllers on the host, sends reports over UART, and applies rumble locally. Hotplug friendly and crossplatform (macOS/Windows/Linux).
- **Color configuration** (`controller_color_config.h`): compile-time RGB colors for emulated controller grips and supported Bluetooth controller LEDs.
- **Color configuration** (`src/firmware/platform/pico/controller_color_config.h`): compile-time RGB colors for emulated controller grips and supported Bluetooth controller LEDs.
- **Pico 2 W AIO firmware** (`firmware/switch-pico-aio.uf2`): hosts four concurrent Bluetooth controllers and sends their controls, calibrated motion, rumble, and slot identity through four separate Switch Pro USB interfaces without a computer.
## Source layout
Firmware code has one include root, `src/firmware`, with responsibility-based
modules:
| Path | Responsibility |
|---|---|
| `src/firmware/main.cpp` | Firmware entry point and backend orchestration |
| `src/firmware/adapter/` | USB mode selection, host probing, and managed reboot |
| `src/firmware/configuration/` | Persistent adapter configuration and transactions |
| `src/firmware/core/` | Shared controller identity, color, and input-state types |
| `src/firmware/input/` | Bluepad32 controller input backend and hotkeys |
| `src/firmware/platform/pico/` | Pico flash/BOOTSEL integrations and compile-time board configuration |
| `src/firmware/profile/` | Controller profiles, transforms, storage, and runtime |
| `src/firmware/usb/` | USB output boundary, management protocol, and per-protocol drivers |
Internal includes are rooted at `src/firmware`, for example
`#include "profile/controller_profile.h"`. Host-side Python remains in
`src/switch_pico_bridge/`; native firmware tests remain in `tests/`.
## Quick start
1. Flash the Pico with `firmware/switch-pico.uf2` (or build your own) using BOOTSEL drag-and-drop (see “Manual UF2 flashing” below).
2. Wire Pico UART1 to a USB↔UART adapter (GPIO4 TX, GPIO5 RX, GND) and plug that adapter into your host PC.
@ -162,7 +182,7 @@ Each AIO slot has one color shared by its emulated Switch Pro grips and its phys
3. Yellow `#F6C945`
4. Green `#2ECC71`
When a controller becomes ready, RGB-capable devices such as DualSense and DualShock 4 receive a darker, more saturated RGB value derived automatically from the slot's Switch grip color. Controllers without an RGB light use player indicator 1, 2, 3, or 4 when Bluepad32 exposes player-LED control. Devices without either capability are left unchanged. Edit only the four grip colors in `controller_color_config.h`; rebuilding automatically recalibrates their lightbar colors.
When a controller becomes ready, RGB-capable devices such as DualSense and DualShock 4 receive a darker, more saturated RGB value derived automatically from the slot's Switch grip color. Controllers without an RGB light use player indicator 1, 2, 3, or 4 when Bluepad32 exposes player-LED control. Devices without either capability are left unchanged. Edit only the four grip colors in `src/firmware/platform/pico/controller_color_config.h`; rebuilding automatically recalibrates their lightbar colors.
### Controller capabilities
@ -352,7 +372,7 @@ python3 build.py --grip-color FF00AA
```
Both options update all four slot definitions in
`controller_color_config.h` before building. With no color option, the
`src/firmware/platform/pico/controller_color_config.h` before building. With no color option, the
per-slot blue/red/yellow/green palette is left unchanged. Run
`python3 build.py --help` to see the available command-line options.
@ -547,7 +567,7 @@ Keep `SwitchImuMode` as a three-state value. Never acknowledge mode 2 and then e
#### Mode-2 implementation
`switch_pro_driver.cpp` implements this in `integrate_motion_sample()` and `fill_quaternion_imu_report_data()`:
`src/firmware/usb/switch/switch_pro_driver.cpp` implements this in `integrate_motion_sample()` and `fill_quaternion_imu_report_data()`:
1. Reset quaternion state to `(0, 0, 0, 1)` when transitioning into mode 2.
2. Integrate each report's three gyro samples at 5 ms per sample. The Nintendo quaternion axes use sensor `Y, X, Z`, not `X, Y, Z`.

View file

@ -10,7 +10,8 @@ import sys
from pathlib import Path
SCRIPT_DIR = Path(__file__).resolve().parent
CONFIG_FILE = SCRIPT_DIR / "controller_color_config.h"
FIRMWARE_SOURCE_DIR = SCRIPT_DIR / "src" / "firmware"
CONFIG_FILE = FIRMWARE_SOURCE_DIR / "platform" / "pico" / "controller_color_config.h"
BUILD_DIR = SCRIPT_DIR / "build"
AIO_BUILD_DIR = SCRIPT_DIR / "build-aio"
FEASIBILITY_BUILD_DIR = SCRIPT_DIR / "build-feasibility"
@ -265,7 +266,7 @@ def parse_args():
parser = argparse.ArgumentParser(
description="Build and flash the project, optionally setting grip colors.",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="Default behavior leaves controller_color_config.h unchanged.",
epilog=f"Default behavior leaves {CONFIG_FILE.relative_to(SCRIPT_DIR)} unchanged.",
)
mode_group = parser.add_mutually_exclusive_group()
mode_group.add_argument(

View file

@ -1,5 +1,4 @@
#include "adapter_host_probe.h"
#include "adapter/adapter_host_probe.h"
#include <stddef.h>
#ifdef SWITCH_PICO_LOG
#include <stdio.h>
@ -8,12 +7,12 @@
#define PROBE_LOG(...) ((void)0)
#endif
#include "adapter_host_probe_state.h"
#include "controller_profile_runtime.h"
#include "adapter/adapter_host_probe_state.h"
#include "profile/controller_profile_runtime.h"
#include "hardware/structs/watchdog.h"
#include "hardware/watchdog.h"
#include "pico/time.h"
#include "xinput_descriptors.h"
#include "usb/xinput/xinput_descriptors.h"
namespace {

View file

@ -2,7 +2,7 @@
#include <stdint.h>
#include "adapter_usb_mode.h"
#include "adapter/adapter_usb_mode.h"
#include "tusb.h"
// Consume watchdog scratch and freeze the active mode. Call exactly once

View file

@ -1,16 +1,15 @@
#include "adapter_mode_controller.h"
#include "adapter_reboot.h"
#include "adapter_configuration.h"
#include "adapter_host_probe.h"
#include "bluepad32_input_backend.h"
#include "configuration_service.h"
#include "controller_profile.h"
#include "controller_profile_runtime.h"
#include "adapter/adapter_mode_controller.h"
#include "adapter/adapter_reboot.h"
#include "configuration/adapter_configuration.h"
#include "adapter/adapter_host_probe.h"
#include "input/bluepad32_input_backend.h"
#include "configuration/configuration_service.h"
#include "profile/controller_profile.h"
#include "profile/controller_profile_runtime.h"
#include "hardware/watchdog.h"
#include "pico/bootrom.h"
#include "tusb.h"
#include "usb_output_driver.h"
#include "usb/usb_output_driver.h"
namespace {

View file

@ -2,8 +2,8 @@
#include <stdint.h>
#include "adapter_usb_mode.h"
#include "controller_state.h"
#include "adapter/adapter_usb_mode.h"
#include "core/controller_state.h"
constexpr uint8_t ADAPTER_MODE_CONTROLLER_SLOT_COUNT = 4;
constexpr uint32_t ADAPTER_MODE_CHORD_HOLD_MS = 3000;

View file

@ -1,4 +1,4 @@
#include "adapter_configuration.h"
#include "configuration/adapter_configuration.h"
namespace {

View file

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include "adapter_usb_mode.h"
#include "adapter/adapter_usb_mode.h"
constexpr uint16_t ADAPTER_CONFIGURATION_LEGACY_SCHEMA_VERSION = 1;
constexpr uint16_t ADAPTER_CONFIGURATION_SCHEMA_VERSION = 2;

View file

@ -1,9 +1,8 @@
#include "configuration_service.h"
#include "configuration/configuration_service.h"
#include <string.h>
#include "pico/critical_section.h"
#include "pico_configuration_storage.h"
#include "platform/pico/pico_configuration_storage.h"
namespace {

View file

@ -3,8 +3,8 @@
#include <stddef.h>
#include <stdint.h>
#include "adapter_configuration.h"
#include "configuration_transaction.h"
#include "configuration/adapter_configuration.h"
#include "configuration/configuration_transaction.h"
constexpr uint32_t CONFIGURATION_SERVICE_INTERNAL_TRANSACTION_ID_MASK =
0x80000000u;

View file

@ -1,5 +1,4 @@
#include "configuration_storage.h"
#include "configuration/configuration_storage.h"
#include <string.h>
namespace {

View file

@ -1,9 +1,7 @@
#include "configuration_transaction.h"
#include "configuration/configuration_transaction.h"
#include <string.h>
#include "adapter_configuration.h"
#include "configuration/adapter_configuration.h"
ConfigurationTransactionStatus ConfigurationTransaction::begin(
uint32_t transaction_id, uint16_t schema_version, size_t payload_size,
uint32_t payload_crc) {

View file

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include "configuration_storage.h"
#include "configuration/configuration_storage.h"
enum class ConfigurationTransactionStatus : uint8_t {
kIdle = 0,

View file

@ -1,5 +1,4 @@
#include "controller_identity.h"
#include "core/controller_identity.h"
#include <string.h>
namespace {

View file

@ -1,8 +1,7 @@
#include "bluepad32_input_backend.h"
#include "controller_hotkey_config.h"
#include "configuration_service.h"
#include "profile_service.h"
#include "input/bluepad32_input_backend.h"
#include "input/controller_hotkey_config.h"
#include "configuration/configuration_service.h"
#include "profile/profile_service.h"
#include <limits.h>
#include <stddef.h>
#include <string.h>
@ -15,7 +14,7 @@
#include <pico/stdlib.h>
#include <uni.h>
#ifdef SWITCH_PICO_USB_OUTPUT_MODES
#include "adapter_usb_mode.h"
#include "adapter/adapter_usb_mode.h"
#endif
namespace {

View file

@ -2,11 +2,11 @@
#include <stdint.h>
#include "controller_color.h"
#include "controller_identity.h"
#include "controller_profile.h"
#include "controller_state.h"
#include "switch_haptics.h"
#include "core/controller_color.h"
#include "core/controller_identity.h"
#include "profile/controller_profile.h"
#include "core/controller_state.h"
#include "usb/switch/switch_haptics.h"
constexpr uint8_t BLUEPAD32_INPUT_BACKEND_SLOT_COUNT = 4;
constexpr uint8_t BLUEPAD32_PAIRING_RECORD_CAPACITY = 16;

View file

@ -2,15 +2,15 @@
#include "bsp/board.h"
#include "pico/stdlib.h"
#include "tusb.h"
#include "switch_pro_driver.h"
#include "usb_output_driver.h"
#include "usb/switch/switch_pro_driver.h"
#include "usb/usb_output_driver.h"
#ifndef SWITCH_PICO_BLUEPAD32
#include "hardware/uart.h"
#else
#include "adapter_mode_controller.h"
#include "bluepad32_input_backend.h"
#include "bootsel_pairing_button.h"
#include "controller_profile_runtime.h"
#include "adapter/adapter_mode_controller.h"
#include "input/bluepad32_input_backend.h"
#include "platform/pico/bootsel_pairing_button.h"
#include "profile/controller_profile_runtime.h"
#endif
#ifdef SWITCH_PICO_LOG

View file

@ -1,5 +1,4 @@
#include "bootsel_pairing_button.h"
#include "platform/pico/bootsel_pairing_button.h"
#include "hardware/gpio.h"
#include "hardware/structs/ioqspi.h"
#include "hardware/structs/sio.h"

View file

@ -1,5 +1,4 @@
#include "pico_configuration_storage.h"
#include "platform/pico/pico_configuration_storage.h"
#include <string.h>
#include "hardware/flash.h"

View file

@ -1,5 +1,5 @@
#pragma once
#include "configuration_storage.h"
#include "configuration/configuration_storage.h"
ConfigurationStorageIo pico_configuration_storage_io();

View file

@ -1,8 +1,7 @@
#include "pico_profile_storage.h"
#include "platform/pico/pico_profile_storage.h"
#include <string.h>
#include "configuration_storage.h"
#include "configuration/configuration_storage.h"
#include "hardware/flash.h"
#include "pico/btstack_flash_bank.h"
#include "pico/flash.h"

View file

@ -1,5 +1,5 @@
#pragma once
#include "profile_storage.h"
#include "profile/profile_storage.h"
ProfileStorageIo pico_profile_storage_io();

View file

@ -1,5 +1,4 @@
#include "controller_profile.h"
#include "profile/controller_profile.h"
#include <string.h>
namespace {

View file

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include "controller_identity.h"
#include "core/controller_identity.h"
constexpr uint16_t CONTROLLER_PROFILE_LEGACY_SCHEMA_VERSION = 1;
constexpr uint16_t CONTROLLER_PROFILE_SCHEMA_VERSION = 2;

View file

@ -1,9 +1,8 @@
#include "controller_profile_runtime.h"
#include "configuration_service.h"
#include "controller_identity.h"
#include "controller_synthetic_input.h"
#include "profile_service.h"
#include "profile/controller_profile_runtime.h"
#include "configuration/configuration_service.h"
#include "core/controller_identity.h"
#include "profile/controller_synthetic_input.h"
#include "profile/profile_service.h"
namespace {

View file

@ -2,10 +2,10 @@
#include <stdint.h>
#include "adapter_usb_mode.h"
#include "adapter/adapter_usb_mode.h"
#include "bluepad32_input_backend.h"
#include "controller_profile_transform.h"
#include "input/bluepad32_input_backend.h"
#include "profile/controller_profile_transform.h"
constexpr uint8_t CONTROLLER_PROFILE_RUNTIME_SLOT_COUNT = 4;
constexpr uint16_t CONTROLLER_PROFILE_DEFAULT_SWITCHING_CHORD =

View file

@ -1,5 +1,4 @@
#include "controller_profile_transform.h"
#include "profile/controller_profile_transform.h"
#include <limits.h>
namespace {

View file

@ -2,9 +2,9 @@
#include <stdint.h>
#include "controller_profile.h"
#include "controller_state.h"
#include "switch_haptics.h"
#include "profile/controller_profile.h"
#include "core/controller_state.h"
#include "usb/switch/switch_haptics.h"
struct ControllerProfileTransformResult {
ControllerState state{};

View file

@ -1,4 +1,4 @@
#include "controller_synthetic_input.h"
#include "profile/controller_synthetic_input.h"
namespace {

View file

@ -2,7 +2,7 @@
#include <stdint.h>
#include "controller_profile_transform.h"
#include "profile/controller_profile_transform.h"
struct ControllerSyntheticBindingState {
bool active = false;

View file

@ -1,10 +1,9 @@
#include "profile_service.h"
#include "profile/profile_service.h"
#include <string.h>
#include "pico/critical_section.h"
#include "pico_profile_storage.h"
#include "profile_storage.h"
#include "platform/pico/pico_profile_storage.h"
#include "profile/profile_storage.h"
namespace {

View file

@ -3,8 +3,8 @@
#include <stddef.h>
#include <stdint.h>
#include "configuration_transaction.h"
#include "controller_profile.h"
#include "configuration/configuration_transaction.h"
#include "profile/controller_profile.h"
constexpr uint8_t PROFILE_SERVICE_LIST_CAPACITY =
CONTROLLER_PROFILE_STABLE_IDENTITY_CAPACITY + 1;

View file

@ -1,5 +1,4 @@
#include "profile_storage.h"
#include "profile/profile_storage.h"
#include <string.h>
namespace {

View file

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include "controller_profile.h"
#include "profile/controller_profile.h"
constexpr uint8_t PROFILE_STORAGE_BANK_COUNT = 2;
constexpr size_t PROFILE_STORAGE_SECTOR_SIZE = 4096;

View file

@ -3,7 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include "controller_state.h"
#include "core/controller_state.h"
#ifndef SWITCH_PICO_HID_INSTANCE_COUNT
#define SWITCH_PICO_HID_INSTANCE_COUNT 1

View file

@ -1,8 +1,7 @@
#include "generic_hid_driver.h"
#include "usb/generic_hid/generic_hid_driver.h"
#include <string.h>
#include "generic_hid_descriptors.h"
#include "usb/generic_hid/generic_hid_descriptors.h"
namespace {

View file

@ -2,8 +2,9 @@
#include <stdint.h>
#include "controller_state.h"
#include "core/controller_state.h"
#include "tusb.h"
namespace GenericHid {
enum class ReportDescriptorVariant : uint8_t {

View file

@ -1,5 +1,4 @@
#include "switch_haptics.h"
#include "usb/switch/switch_haptics.h"
#include <cmath>
#include <cstring>

View file

@ -1,4 +1,4 @@
#include "switch_pro_driver.h"
#include "usb/switch/switch_pro_driver.h"
#include <algorithm>
#include <cstddef>
@ -81,8 +81,8 @@ static SwitchProContext* context_for(uint8_t instance) {
}
// Optional compile-time color palette shared with Bluetooth controller LEDs.
#if __has_include("controller_color_config.h")
#include "controller_color_config.h"
#if __has_include("platform/pico/controller_color_config.h")
#include "platform/pico/controller_color_config.h"
#endif
#ifndef SWITCH_COLOR_BODY_R
#define SWITCH_COLOR_BODY_R 0x1B

View file

@ -8,11 +8,11 @@
#include <stdbool.h>
#include <stdint.h>
#include "controller_color.h"
#include "controller_state.h"
#include "switch_haptics.h"
#include "core/controller_color.h"
#include "core/controller_state.h"
#include "usb/switch/switch_haptics.h"
#include "tusb.h"
#include "switch_pro_descriptors.h"
#include "usb/switch/switch_pro_descriptors.h"
// Preserve the pre-neutral-state 35%-of-1023 digital trigger boundary.
constexpr uint32_t SWITCH_PRO_LEGACY_TRIGGER_RANGE_MAXIMUM = 1023;
constexpr uint32_t SWITCH_PRO_LEGACY_TRIGGER_PRESS_THRESHOLD = 358;

View file

@ -1,13 +1,12 @@
#include "usb_configuration_management.h"
#include "usb/usb_configuration_management.h"
#include <string.h>
#include "adapter_configuration.h"
#include "adapter_host_probe.h"
#include "adapter_reboot.h"
#include "adapter_usb_mode.h"
#include "configuration/adapter_configuration.h"
#include "adapter/adapter_host_probe.h"
#include "adapter/adapter_reboot.h"
#include "adapter/adapter_usb_mode.h"
#include "tusb.h"
#include "usb_output_driver.h"
#include "usb/usb_output_driver.h"
namespace UsbConfigurationManagement {
namespace {

View file

@ -5,9 +5,9 @@
#include "tusb.h"
#include "bluepad32_input_backend.h"
#include "configuration_service.h"
#include "profile_service.h"
#include "input/bluepad32_input_backend.h"
#include "configuration/configuration_service.h"
#include "profile/profile_service.h"
namespace UsbConfigurationManagement {

View file

@ -1,23 +1,23 @@
#include "usb_output_driver.h"
#include "usb/usb_output_driver.h"
#include <cstring>
#include <stdio.h>
#include "device/usbd_pvt.h"
#include "switch_pro_driver.h"
#include "switch_pro_descriptors.h"
#include "usb/switch/switch_pro_driver.h"
#include "usb/switch/switch_pro_descriptors.h"
#include "tusb.h"
#ifdef SWITCH_PICO_BLUEPAD32
#include "usb_configuration_management.h"
#include "usb/usb_configuration_management.h"
#endif
#ifdef SWITCH_PICO_USB_OUTPUT_MODES
#include "adapter_host_probe.h"
#include "generic_hid_descriptors.h"
#include "generic_hid_driver.h"
#include "xinput_descriptors.h"
#include "xinput_driver.h"
#include "adapter/adapter_host_probe.h"
#include "usb/generic_hid/generic_hid_descriptors.h"
#include "usb/generic_hid/generic_hid_driver.h"
#include "usb/xinput/xinput_descriptors.h"
#include "usb/xinput/xinput_driver.h"
#endif
#ifdef SWITCH_PICO_LOG

View file

@ -2,9 +2,9 @@
#include <stdint.h>
#include "adapter_usb_mode.h"
#include "controller_state.h"
#include "switch_haptics.h"
#include "adapter/adapter_usb_mode.h"
#include "core/controller_state.h"
#include "usb/switch/switch_haptics.h"
// Mode capability bits published in USB management info. Input is present in
// every current mode; rumble/motion describe host-visible USB capabilities.

View file

@ -1,12 +1,11 @@
#include "xinput_driver.h"
#include "usb/xinput/xinput_driver.h"
#include <stddef.h>
#include <string.h>
#include "device/usbd_pvt.h"
#include "tusb.h"
#include "xinput_descriptors.h"
#include "xinput_protocol.h"
#include "usb/xinput/xinput_descriptors.h"
#include "usb/xinput/xinput_protocol.h"
namespace {

View file

@ -2,9 +2,9 @@
#include <stdint.h>
#include "controller_state.h"
#include "core/controller_state.h"
#include "device/usbd_pvt.h"
#include "switch_haptics.h"
#include "usb/switch/switch_haptics.h"
void xinput_init(uint8_t instance);
void xinput_set_rumble_callback(uint8_t instance,

View file

@ -2,8 +2,8 @@
#include <stdint.h>
#include "controller_state.h"
#include "switch_haptics.h"
#include "core/controller_state.h"
#include "usb/switch/switch_haptics.h"
namespace XInput {

View file

@ -1,5 +1,4 @@
#include "adapter_host_probe.h"
#include "adapter/adapter_host_probe.h"
#include <cstdint>
#include <cstdlib>
#include <cstring>
@ -7,7 +6,7 @@
#include "hardware/structs/watchdog.h"
#include "pico/time.h"
#include "xinput_descriptors.h"
#include "usb/xinput/xinput_descriptors.h"
namespace {

View file

@ -1,16 +1,15 @@
#include "adapter_mode_controller.h"
#include "adapter/adapter_mode_controller.h"
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <vector>
#include "adapter_configuration.h"
#include "adapter_reboot.h"
#include "bluepad32_input_backend.h"
#include "configuration_service.h"
#include "controller_profile.h"
#include "configuration/adapter_configuration.h"
#include "adapter/adapter_reboot.h"
#include "input/bluepad32_input_backend.h"
#include "configuration/configuration_service.h"
#include "profile/controller_profile.h"
namespace {

View file

@ -4,7 +4,7 @@
#include <string>
#include <uni.h>
#include "../controller_color_config.h"
#include "platform/pico/controller_color_config.h"
namespace {
@ -442,8 +442,9 @@ uint32_t btstack_run_loop_get_time_ms() {
}
#include "../controller_identity.cpp"
#include "../bluepad32_input_backend.cpp"
#include "core/controller_identity.cpp"
#include "input/bluepad32_input_backend.cpp"
namespace {
void require_clear_completion_pending() {
if (expected_pending_clear_token != 0) {

View file

@ -1,5 +1,4 @@
#include "bootsel_pairing_button.h"
#include "platform/pico/bootsel_pairing_button.h"
#include <cstdlib>
#include <cstdint>
#include <iostream>

View file

@ -1,8 +1,7 @@
#include "adapter_configuration.h"
#include "configuration_service.h"
#include "configuration_storage.h"
#include "pico_configuration_storage.h"
#include "configuration/adapter_configuration.h"
#include "configuration/configuration_service.h"
#include "configuration/configuration_storage.h"
#include "platform/pico/pico_configuration_storage.h"
#include <cstdlib>
#include <cstring>
#include <iostream>

View file

@ -1,7 +1,6 @@
#include "adapter_configuration.h"
#include "configuration_storage.h"
#include "configuration_transaction.h"
#include "configuration/adapter_configuration.h"
#include "configuration/configuration_storage.h"
#include "configuration/configuration_transaction.h"
#include <cstdlib>
#include <cstring>
#include <iostream>

View file

@ -2,7 +2,7 @@
#include <stdint.h>
#include "controller_profile.h"
#include "profile/controller_profile.h"
constexpr uint8_t kLegacyDefaultProfile[CONTROLLER_PROFILE_ENCODED_SIZE] = {
0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,

View file

@ -1,9 +1,7 @@
#include "controller_profile_runtime.h"
#include "controller_identity.h"
#include "controller_profile.h"
#include "profile_service.h"
#include "profile/controller_profile_runtime.h"
#include "core/controller_identity.h"
#include "profile/controller_profile.h"
#include "profile/profile_service.h"
#include <array>
#include <cstdlib>
#include <cstring>

View file

@ -1,6 +1,6 @@
#include "controller_identity.h"
#include "controller_profile.h"
#include "tests/controller_profile_legacy_fixtures.h"
#include "core/controller_identity.h"
#include "profile/controller_profile.h"
#include "controller_profile_legacy_fixtures.h"
#include <cstdlib>
#include <cstring>

View file

@ -1,7 +1,6 @@
#include "controller_identity.h"
#include "controller_profile.h"
#include "controller_profile_transform.h"
#include "core/controller_identity.h"
#include "profile/controller_profile.h"
#include "profile/controller_profile_transform.h"
#include <cstdlib>
#include <cstring>
#include <iostream>

View file

@ -1,5 +1,4 @@
#include "controller_synthetic_input.h"
#include "profile/controller_synthetic_input.h"
#include <array>
#include <cstdlib>
#include <cstring>

View file

@ -1,5 +1,4 @@
#include "generic_hid_descriptors.h"
#include "usb/generic_hid/generic_hid_descriptors.h"
#include <array>
#include <cstddef>
#include <cstdint>

View file

@ -1,7 +1,5 @@
#include "generic_hid_driver.h"
#include "generic_hid_descriptors.h"
#include "usb/generic_hid/generic_hid_driver.h"
#include "usb/generic_hid/generic_hid_descriptors.h"
#include <array>
#include <cstddef>
#include <cstdint>

View file

@ -1,9 +1,8 @@
#include "controller_identity.h"
#include "controller_profile.h"
#include "pico_profile_storage.h"
#include "profile_service.h"
#include "profile_storage.h"
#include "core/controller_identity.h"
#include "profile/controller_profile.h"
#include "platform/pico/pico_profile_storage.h"
#include "profile/profile_service.h"
#include "profile/profile_storage.h"
#include <cstdlib>
#include <cstring>
#include <iostream>

View file

@ -1,7 +1,7 @@
#include "controller_identity.h"
#include "controller_profile.h"
#include "profile_storage.h"
#include "tests/controller_profile_legacy_fixtures.h"
#include "core/controller_identity.h"
#include "profile/controller_profile.h"
#include "profile/profile_storage.h"
#include "controller_profile_legacy_fixtures.h"
#include <cstdlib>
#include <cstring>

View file

@ -1,5 +1,4 @@
#include "switch_haptics.h"
#include "usb/switch/switch_haptics.h"
#include <array>
#include <cstdint>
#include <iostream>

View file

@ -1,6 +1,5 @@
#include "switch_pro_descriptors.h"
#include "tusb_config.h"
#include "usb/switch/switch_pro_descriptors.h"
#include "platform/pico/tusb_config.h"
#include <array>
#include <cstddef>
#include <cstdint>

View file

@ -1,6 +1,6 @@
#include "switch_pro_driver.h"
#include "usb_output_driver.h"
#include "controller_color_config.h"
#include "usb/switch/switch_pro_driver.h"
#include "usb/usb_output_driver.h"
#include "platform/pico/controller_color_config.h"
#include "tusb.h"
#include "pico/time.h"

View file

@ -20,8 +20,8 @@ def test_adapter_host_probe_native(tmp_path: Path) -> None:
"-pedantic",
"-DSWITCH_PICO_HID_INSTANCE_COUNT=4",
f"-I{root / 'tests' / 'mode_native_stubs'}",
f"-I{root}",
str(root / "adapter_host_probe.cpp"),
f"-I{root / 'src' / 'firmware'}",
str(root / "src" / "firmware" / "adapter" / "adapter_host_probe.cpp"),
str(root / "tests" / "adapter_host_probe_test.cpp"),
"-o",
str(executable),

View file

@ -20,8 +20,8 @@ def test_adapter_mode_controller_native(tmp_path: Path) -> None:
"-pedantic",
"-DSWITCH_PICO_HID_INSTANCE_COUNT=4",
f"-I{root / 'tests' / 'mode_native_stubs'}",
f"-I{root}",
str(root / "adapter_mode_controller.cpp"),
f"-I{root / 'src' / 'firmware'}",
str(root / "src" / "firmware" / "adapter" / "adapter_mode_controller.cpp"),
str(root / "tests" / "adapter_mode_controller_test.cpp"),
"-o",
str(executable),

View file

@ -27,7 +27,7 @@ def test_bluepad32_backend_lifecycle_native(tmp_path: Path) -> None:
command.extend(
[
f"-I{root / 'tests' / 'bluepad32_native_stubs'}",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "bluepad32_backend_lifecycle_test.cpp"),
"-o",
str(executable),

View file

@ -22,8 +22,8 @@ def test_bootsel_pairing_button_native(tmp_path: Path) -> None:
"-pedantic",
f"-DPICO_RP2350={rp2350}",
f"-I{root / 'tests' / 'bootsel_native_stubs'}",
f"-I{root}",
str(root / "bootsel_pairing_button.cpp"),
f"-I{root / 'src' / 'firmware'}",
str(root / "src" / "firmware" / "platform" / "pico" / "bootsel_pairing_button.cpp"),
str(root / "tests" / "bootsel_pairing_button_test.cpp"),
"-o",
str(executable),

View file

@ -18,12 +18,12 @@ def test_configuration_service_native(tmp_path: Path) -> None:
"-Werror",
"-pedantic",
f"-I{root / 'tests' / 'bluepad32_native_stubs'}",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "configuration_service_test.cpp"),
str(root / "adapter_configuration.cpp"),
str(root / "configuration_service.cpp"),
str(root / "configuration_storage.cpp"),
str(root / "configuration_transaction.cpp"),
str(root / "src" / "firmware" / "configuration" / "adapter_configuration.cpp"),
str(root / "src" / "firmware" / "configuration" / "configuration_service.cpp"),
str(root / "src" / "firmware" / "configuration" / "configuration_storage.cpp"),
str(root / "src" / "firmware" / "configuration" / "configuration_transaction.cpp"),
"-o",
str(executable),
],

View file

@ -17,11 +17,11 @@ def test_configuration_storage_native(tmp_path: Path) -> None:
"-Wextra",
"-Werror",
"-pedantic",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "configuration_storage_test.cpp"),
str(root / "adapter_configuration.cpp"),
str(root / "configuration_storage.cpp"),
str(root / "configuration_transaction.cpp"),
str(root / "src" / "firmware" / "configuration" / "adapter_configuration.cpp"),
str(root / "src" / "firmware" / "configuration" / "configuration_storage.cpp"),
str(root / "src" / "firmware" / "configuration" / "configuration_transaction.cpp"),
"-o",
str(executable),
],

View file

@ -17,10 +17,10 @@ def test_controller_profile_native(tmp_path: Path) -> None:
"-Wextra",
"-Werror",
"-pedantic",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "controller_profile_test.cpp"),
str(root / "controller_identity.cpp"),
str(root / "controller_profile.cpp"),
str(root / "src" / "firmware" / "core" / "controller_identity.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile.cpp"),
"-o",
str(executable),
],

View file

@ -17,13 +17,13 @@ def test_controller_profile_runtime_native(tmp_path: Path) -> None:
"-Wextra",
"-Werror",
"-pedantic",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "controller_profile_runtime_test.cpp"),
str(root / "controller_identity.cpp"),
str(root / "controller_profile.cpp"),
str(root / "controller_profile_transform.cpp"),
str(root / "controller_synthetic_input.cpp"),
str(root / "controller_profile_runtime.cpp"),
str(root / "src" / "firmware" / "core" / "controller_identity.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile_transform.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_synthetic_input.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile_runtime.cpp"),
"-o",
str(executable),
],

View file

@ -17,11 +17,11 @@ def test_controller_profile_transform_native(tmp_path: Path) -> None:
"-Wextra",
"-Werror",
"-pedantic",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "controller_profile_transform_test.cpp"),
str(root / "controller_identity.cpp"),
str(root / "controller_profile.cpp"),
str(root / "controller_profile_transform.cpp"),
str(root / "src" / "firmware" / "core" / "controller_identity.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile_transform.cpp"),
"-o",
str(executable),
],

View file

@ -17,12 +17,12 @@ def test_controller_synthetic_input_native(tmp_path: Path) -> None:
"-Wextra",
"-Werror",
"-pedantic",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "controller_synthetic_input_test.cpp"),
str(root / "controller_identity.cpp"),
str(root / "controller_profile.cpp"),
str(root / "controller_profile_transform.cpp"),
str(root / "controller_synthetic_input.cpp"),
str(root / "src" / "firmware" / "core" / "controller_identity.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile_transform.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_synthetic_input.cpp"),
"-o",
str(executable),
],

View file

@ -32,7 +32,7 @@ def compile_cpp(
command.append(f"-I{root / 'tests' / 'native_stubs'}")
command.extend(
[
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
*[str(source) for source in sources],
"-o",
str(output),
@ -98,7 +98,7 @@ def test_generic_hid_driver_contexts(tmp_path: Path) -> None:
host_compiler(),
executable,
[
root / "generic_hid_driver.cpp",
root / "src" / "firmware" / "usb" / "generic_hid" / "generic_hid_driver.cpp",
root / "tests" / "generic_hid_driver_test.cpp",
],
["SWITCH_PICO_HID_INSTANCE_COUNT=4"],

View file

@ -18,12 +18,12 @@ def test_profile_service_native(tmp_path: Path) -> None:
"-Werror",
"-pedantic",
f"-I{root / 'tests' / 'bluepad32_native_stubs'}",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "profile_service_test.cpp"),
str(root / "controller_identity.cpp"),
str(root / "controller_profile.cpp"),
str(root / "profile_storage.cpp"),
str(root / "profile_service.cpp"),
str(root / "src" / "firmware" / "core" / "controller_identity.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile.cpp"),
str(root / "src" / "firmware" / "profile" / "profile_storage.cpp"),
str(root / "src" / "firmware" / "profile" / "profile_service.cpp"),
"-o",
str(executable),
],

View file

@ -17,11 +17,11 @@ def test_profile_storage_native(tmp_path: Path) -> None:
"-Wextra",
"-Werror",
"-pedantic",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "profile_storage_test.cpp"),
str(root / "controller_identity.cpp"),
str(root / "controller_profile.cpp"),
str(root / "profile_storage.cpp"),
str(root / "src" / "firmware" / "core" / "controller_identity.cpp"),
str(root / "src" / "firmware" / "profile" / "controller_profile.cpp"),
str(root / "src" / "firmware" / "profile" / "profile_storage.cpp"),
"-o",
str(executable),
],

View file

@ -19,8 +19,8 @@ def test_switch_haptics_native(tmp_path: Path) -> None:
"-Wextra",
"-Werror",
"-pedantic",
f"-I{root}",
str(root / "switch_haptics.cpp"),
f"-I{root / 'src' / 'firmware'}",
str(root / "src" / "firmware" / "usb" / "switch" / "switch_haptics.cpp"),
str(root / "tests" / "switch_haptics_test.cpp"),
"-o",
str(executable),

View file

@ -25,7 +25,7 @@ def compile_descriptor_test(
command.append(f"-DSWITCH_PICO_HID_INSTANCE_COUNT={configured_count}")
command.extend(
[
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "switch_pro_descriptors_test.cpp"),
"-o",
str(output),

View file

@ -21,10 +21,10 @@ def test_switch_pro_driver_four_contexts_native(tmp_path: Path) -> None:
"-pedantic",
"-DSWITCH_PICO_HID_INSTANCE_COUNT=4",
f"-I{root / 'tests' / 'native_stubs'}",
f"-I{root}",
str(root / "switch_pro_driver.cpp"),
str(root / "usb_output_driver.cpp"),
str(root / "switch_haptics.cpp"),
f"-I{root / 'src' / 'firmware'}",
str(root / "src" / "firmware" / "usb" / "switch" / "switch_pro_driver.cpp"),
str(root / "src" / "firmware" / "usb" / "usb_output_driver.cpp"),
str(root / "src" / "firmware" / "usb" / "switch" / "switch_haptics.cpp"),
str(root / "tests" / "switch_pro_driver_context_test.cpp"),
"-o",
str(executable),

View file

@ -19,7 +19,7 @@ def test_usb_configuration_management_native(tmp_path: Path) -> None:
"-Werror",
"-pedantic",
f"-I{root / 'tests' / 'usb_management_native_stubs'}",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "usb_configuration_management_test.cpp"),
"-o",
str(executable),

View file

@ -36,13 +36,13 @@ def test_usb_output_driver_contracts(tmp_path: Path) -> None:
"-DSWITCH_PICO_USB_OUTPUT_MODES=1",
*backend_definitions,
f"-I{root / 'tests' / 'native_stubs'}",
f"-I{root}",
f"-I{root / 'src' / 'firmware'}",
str(root / "tests" / "usb_output_driver_test.cpp"),
str(root / "switch_pro_driver.cpp"),
str(root / "usb_output_driver.cpp"),
str(root / "generic_hid_driver.cpp"),
str(root / "xinput_driver.cpp"),
str(root / "switch_haptics.cpp"),
str(root / "src" / "firmware" / "usb" / "switch" / "switch_pro_driver.cpp"),
str(root / "src" / "firmware" / "usb" / "usb_output_driver.cpp"),
str(root / "src" / "firmware" / "usb" / "generic_hid" / "generic_hid_driver.cpp"),
str(root / "src" / "firmware" / "usb" / "xinput" / "xinput_driver.cpp"),
str(root / "src" / "firmware" / "usb" / "switch" / "switch_haptics.cpp"),
"-o",
str(executable),
],

View file

@ -1,12 +1,11 @@
#include "usb_configuration_management.h"
#include "usb/usb_configuration_management.h"
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <tusb.h>
#include "usb_output_driver.h"
#include "usb/usb_output_driver.h"
namespace {
@ -788,10 +787,10 @@ bool tud_control_status(uint8_t, const tusb_control_request_t*) {
return true;
}
#include "../adapter_configuration.cpp"
#include "../controller_identity.cpp"
#include "../controller_profile.cpp"
#include "../usb_configuration_management.cpp"
#include "configuration/adapter_configuration.cpp"
#include "core/controller_identity.cpp"
#include "profile/controller_profile.cpp"
#include "usb/usb_configuration_management.cpp"
int main() {
current_configuration.state = ConfigurationServiceState::kReady;

Some files were not shown because too many files have changed in this diff Show more