Add stock-USB native Joy-Con R/L hub bridge
This commit is contained in:
parent
9f6dddb790
commit
1748910316
41 changed files with 7101 additions and 909 deletions
|
|
@ -8,7 +8,17 @@ from pathlib import Path
|
|||
import pytest
|
||||
|
||||
|
||||
def test_switch2_usb_probe_deferred_sample(tmp_path: Path) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("left", "composite"),
|
||||
[(False, False), (True, False), (False, True)],
|
||||
ids=["right", "left", "composite"],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"imu_mode", [None, "OMIT_NATIVE_IMU", "ZERO_NATIVE_IMU_PAYLOAD"]
|
||||
)
|
||||
def test_switch2_usb_probe_protocol(
|
||||
tmp_path: Path, left: bool, composite: bool, imu_mode: str | None
|
||||
) -> None:
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
compiler = shutil.which("cc") or shutil.which("gcc")
|
||||
assert compiler is not None, "a host C compiler is required"
|
||||
|
|
@ -19,13 +29,42 @@ def test_switch2_usb_probe_deferred_sample(tmp_path: Path) -> None:
|
|||
if sdk_path := os.environ.get("PICO_SDK_PATH"):
|
||||
sdk_candidates.insert(0, Path(sdk_path))
|
||||
mbedtls = next(
|
||||
(sdk / "lib" / "mbedtls" for sdk in sdk_candidates
|
||||
if (sdk / "lib" / "mbedtls" / "library" / "aes.c").is_file()),
|
||||
(
|
||||
sdk / "lib" / "mbedtls"
|
||||
for sdk in sdk_candidates
|
||||
if (sdk / "lib" / "mbedtls" / "library" / "aes.c").is_file()
|
||||
),
|
||||
None,
|
||||
)
|
||||
if mbedtls is None:
|
||||
pytest.skip("Pico SDK mbedTLS required; configure firmware or set PICO_SDK_PATH")
|
||||
pytest.skip(
|
||||
"Pico SDK mbedTLS required; configure firmware or set PICO_SDK_PATH"
|
||||
)
|
||||
probe = root / "tools" / "switch2_usb_probe"
|
||||
sides = [False, True] if composite else [left]
|
||||
factory_rows = []
|
||||
user_rows = []
|
||||
for is_left in sides:
|
||||
factory_center = "0x00, 0x09, 0x90" if is_left else "0x00, 0x08, 0x80"
|
||||
factory_rows.append(
|
||||
f"{{[0xa8] = {factory_center}, 0, 3, 0x30, 0, 4, 0x40,"
|
||||
f" [8191] = {0xE2 if is_left else 0xE1}}}"
|
||||
)
|
||||
# L deliberately has invalid user calibration despite valid magic.
|
||||
user_center = "0, 0, 0" if is_left else "0x10, 0x08, 0x81"
|
||||
user_rows.append(
|
||||
f"{{[0x40] = 0xb2, 0xa1, {user_center}, 0, 3, 0x30, 0, 4, 0x40,"
|
||||
f" [4095] = {0xF2 if is_left else 0xF1}}}"
|
||||
)
|
||||
(tmp_path / "probe_memory_data.h").write_text(
|
||||
'#include "model.h"\n'
|
||||
"static const uint8_t probe_factory_memories[PROBE_CONTROLLER_COUNT][8192] = {\n"
|
||||
+ ",\n".join(factory_rows)
|
||||
+ "\n};\n"
|
||||
"static const uint8_t probe_user_calibrations[PROBE_CONTROLLER_COUNT][4096] = {\n"
|
||||
+ ",\n".join(user_rows)
|
||||
+ "\n};\n"
|
||||
)
|
||||
executable = tmp_path / "switch2_usb_probe_protocol"
|
||||
subprocess.run(
|
||||
[
|
||||
|
|
@ -36,9 +75,14 @@ def test_switch2_usb_probe_deferred_sample(tmp_path: Path) -> None:
|
|||
"-Werror",
|
||||
"-pedantic",
|
||||
f'-DMBEDTLS_CONFIG_FILE="{probe / "mbedtls_config.h"}"',
|
||||
f"-DSWITCH2_PROBE_JOYCON_LEFT={int(left)}",
|
||||
f"-DSWITCH2_PROBE_COMPOSITE={int(composite)}",
|
||||
*([f"-DSWITCH2_PROBE_{imu_mode}=1"] if imu_mode else []),
|
||||
f"-I{probe}",
|
||||
f"-I{tmp_path}",
|
||||
f"-I{mbedtls / 'include'}",
|
||||
str(probe / "protocol.c"),
|
||||
str(probe / "memory.c"),
|
||||
str(mbedtls / "library" / "aes.c"),
|
||||
str(mbedtls / "library" / "platform_util.c"),
|
||||
str(root / "tests" / "switch2_usb_probe_protocol_test.c"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue