Skip to content

Commit

Permalink
[QUIRKS] Add support for 8bitdo N64 controller
Browse files Browse the repository at this point in the history
  • Loading branch information
darthcloud committed May 23, 2022
1 parent e3679f7 commit 3ae97ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions main/adapter/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
19 changes: 19 additions & 0 deletions main/adapter/mapping_quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
1 change: 1 addition & 0 deletions main/bluetooth/hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 3ae97ac

Please sign in to comment.