From 3ae97acb4ab61a3a34e03ed2f8ae5ad0458ad41b Mon Sep 17 00:00:00 2001 From: Jacques Gagnon Date: Tue, 12 Apr 2022 21:43:10 -0400 Subject: [PATCH] [QUIRKS] Add support for 8bitdo N64 controller --- main/adapter/adapter.h | 1 + main/adapter/mapping_quirks.c | 19 +++++++++++++++++++ main/bluetooth/hci.c | 1 + 3 files changed, 21 insertions(+) diff --git a/main/adapter/adapter.h b/main/adapter/adapter.h index 26d67f87..2e507365 100644 --- a/main/adapter/adapter.h +++ b/main/adapter/adapter.h @@ -271,6 +271,7 @@ enum { BT_QUIRK_TRIGGER_PRI_SEC_INVERT, BT_QUIRK_SW_LEFT_JOYCON, BT_QUIRK_SW_RIGHT_JOYCON, + BT_QUIRK_8BITDO_N64, }; /* Wired flags */ diff --git a/main/adapter/mapping_quirks.c b/main/adapter/mapping_quirks.c index c898ba9a..472c5ec9 100644 --- a/main/adapter/mapping_quirks.c +++ b/main/adapter/mapping_quirks.c @@ -81,6 +81,22 @@ static void sw_right_joycon(uint32_t btns_mask[32]) { face_btns_rotate_right(btns_mask); } +void n64_8bitdo(struct bt_data *bt_data) { + bt_data->raw_src_mappings[PAD].mask[0] = 0x23150FFF; + bt_data->raw_src_mappings[PAD].desc[0] = 0x0000000F; + + bt_data->raw_src_mappings[PAD].btns_mask[PAD_RY_UP] = BIT(8); + bt_data->raw_src_mappings[PAD].btns_mask[PAD_RX_RIGHT] = BIT(9); + bt_data->raw_src_mappings[PAD].btns_mask[PAD_RY_DOWN] = bt_data->raw_src_mappings[PAD].btns_mask[PAD_RB_LEFT]; + bt_data->raw_src_mappings[PAD].btns_mask[PAD_RX_LEFT] = bt_data->raw_src_mappings[PAD].btns_mask[PAD_RB_UP]; + bt_data->raw_src_mappings[PAD].btns_mask[PAD_LM] = bt_data->raw_src_mappings[PAD].btns_mask[PAD_MS]; + bt_data->raw_src_mappings[PAD].btns_mask[PAD_RB_LEFT] = bt_data->raw_src_mappings[PAD].btns_mask[PAD_RB_RIGHT]; + bt_data->raw_src_mappings[PAD].btns_mask[PAD_RB_RIGHT] = 0; + bt_data->raw_src_mappings[PAD].btns_mask[PAD_RB_UP] = 0; + bt_data->raw_src_mappings[PAD].btns_mask[PAD_MS] = 0; + bt_data->raw_src_mappings[PAD].btns_mask[PAD_RT] = 0; +} + void mapping_quirks_apply(struct bt_data *bt_data) { if (atomic_test_bit(&bt_data->flags, BT_QUIRK_FACE_BTNS_INVERT)) { face_btns_invert(bt_data->raw_src_mappings[PAD].btns_mask); @@ -97,4 +113,7 @@ void mapping_quirks_apply(struct bt_data *bt_data) { if (atomic_test_bit(&bt_data->flags, BT_QUIRK_SW_RIGHT_JOYCON)) { sw_right_joycon(bt_data->raw_src_mappings[PAD].btns_mask); } + if (atomic_test_bit(&bt_data->flags, BT_QUIRK_8BITDO_N64)) { + n64_8bitdo(bt_data); + } } diff --git a/main/bluetooth/hci.c b/main/bluetooth/hci.c index a28365be..824fe86d 100644 --- a/main/bluetooth/hci.c +++ b/main/bluetooth/hci.c @@ -65,6 +65,7 @@ static const struct bt_name_type bt_name_type[] = { {"MD/Gen Control Pad", BT_SW, BT_SW_MD_GEN, 0}, {"8Bitdo SF30", BT_HID_GENERIC, BT_SUBTYPE_DEFAULT, BIT(BT_QUIRK_FACE_BTNS_INVERT)}, {"8BitDo GBros Adapter", BT_XBOX, BT_8BITDO_GBROS, 0}, + {"8Bitdo N64 GamePad", BT_HID_GENERIC, BT_SUBTYPE_DEFAULT, BIT(BT_QUIRK_8BITDO_N64)}, }; static const struct bt_hci_cp_set_event_filter clr_evt_filter = {