| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2019-2025, Jacques Gagnon | ||
| 3 | * SPDX-License-Identifier: Apache-2.0 | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <string.h> | ||
| 7 | #include "adapter/config.h" | ||
| 8 | #include "zephyr/types.h" | ||
| 9 | #include "tools/util.h" | ||
| 10 | #include "parallel_2p.h" | ||
| 11 | #include "soc/gpio_struct.h" | ||
| 12 | #include "tests/cmds.h" | ||
| 13 | #include "bluetooth/mon.h" | ||
| 14 | #include "driver/gpio.h" | ||
| 15 | |||
| 16 | #define P1_TR_PIN 27 | ||
| 17 | #define P1_TL_PIN 26 | ||
| 18 | #define P1_R_PIN 23 | ||
| 19 | #define P1_L_PIN 18 | ||
| 20 | #define P1_D_PIN 5 | ||
| 21 | #define P1_U_PIN 3 | ||
| 22 | |||
| 23 | #define P2_TR_PIN 16 | ||
| 24 | #define P2_TL_PIN 33 | ||
| 25 | #define P2_R_PIN 25 | ||
| 26 | #define P2_L_PIN 22 | ||
| 27 | #define P2_D_PIN 21 | ||
| 28 | #define P2_U_PIN 19 | ||
| 29 | |||
| 30 | #define P1_1 P1_TL_PIN | ||
| 31 | #define P1_2 P1_TR_PIN | ||
| 32 | #define P1_LD_UP P1_U_PIN | ||
| 33 | #define P1_LD_DOWN P1_D_PIN | ||
| 34 | #define P1_LD_LEFT P1_L_PIN | ||
| 35 | #define P1_LD_RIGHT P1_R_PIN | ||
| 36 | |||
| 37 | #define P2_1 P2_TL_PIN | ||
| 38 | #define P2_2 P2_TR_PIN | ||
| 39 | #define P2_LD_UP P2_U_PIN | ||
| 40 | #define P2_LD_DOWN P2_D_PIN | ||
| 41 | #define P2_LD_LEFT P2_L_PIN | ||
| 42 | #define P2_LD_RIGHT P2_R_PIN | ||
| 43 | |||
| 44 | static const uint32_t para_2p_mask[4] = {0x00050F00, 0x00000000, 0x00000000, BR_COMBO_MASK}; | ||
| 45 | static const uint32_t para_2p_desc[4] = {0x00000000, 0x00000000, 0x00000000, 0x00000000}; | ||
| 46 | static DRAM_ATTR const uint32_t para_2p_btns_mask[2][32] = { | ||
| 47 | { | ||
| 48 | 0, 0, 0, 0, | ||
| 49 | 0, 0, 0, 0, | ||
| 50 | BIT(P1_LD_LEFT), BIT(P1_LD_RIGHT), BIT(P1_LD_DOWN), BIT(P1_LD_UP), | ||
| 51 | 0, 0, 0, 0, | ||
| 52 | BIT(P1_1), 0, BIT(P1_2), 0, | ||
| 53 | 0, 0, 0, 0, | ||
| 54 | 0, 0, 0, 0, | ||
| 55 | 0, 0, 0, 0, | ||
| 56 | }, | ||
| 57 | { | ||
| 58 | 0, 0, 0, 0, | ||
| 59 | 0, 0, 0, 0, | ||
| 60 | BIT(P2_LD_LEFT), BIT(P2_LD_RIGHT), BIT(P2_LD_DOWN), BIT(P2_LD_UP), | ||
| 61 | 0, 0, 0, 0, | ||
| 62 | BIT(P2_1 - 32) | 0xF0000000, 0, BIT(P2_2), 0, | ||
| 63 | 0, 0, 0, 0, | ||
| 64 | 0, 0, 0, 0, | ||
| 65 | 0, 0, 0, 0, | ||
| 66 | }, | ||
| 67 | }; | ||
| 68 | |||
| 69 | ✗ | void IRAM_ATTR para_2p_init_buffer(int32_t dev_mode, struct wired_data *wired_data) { | |
| 70 | ✗ | struct para_2p_map *map1 = (struct para_2p_map *)wired_adapter.data[0].output; | |
| 71 | ✗ | struct para_2p_map *map2 = (struct para_2p_map *)wired_adapter.data[1].output; | |
| 72 | ✗ | struct para_2p_map *map1_mask = (struct para_2p_map *)wired_adapter.data[0].output_mask; | |
| 73 | ✗ | struct para_2p_map *map2_mask = (struct para_2p_map *)wired_adapter.data[1].output_mask; | |
| 74 | |||
| 75 | ✗ | map1->buttons = 0xFFFDFFFD; | |
| 76 | ✗ | map2->buttons = 0xFFFDFFFD; | |
| 77 | ✗ | map1_mask->buttons = 0; | |
| 78 | ✗ | map2_mask->buttons = 0; | |
| 79 | |||
| 80 | ✗ | map1->buttons_high = 0xFFFFFFFE; | |
| 81 | ✗ | map2->buttons_high = 0xFFFFFFFE; | |
| 82 | ✗ | map1_mask->buttons_high = 0; | |
| 83 | ✗ | map2_mask->buttons_high = 0; | |
| 84 | ✗ | } | |
| 85 | |||
| 86 | ✗ | void para_2p_meta_init(struct wired_ctrl *ctrl_data) { | |
| 87 | ✗ | memset((void *)ctrl_data, 0, sizeof(*ctrl_data)*WIRED_MAX_DEV); | |
| 88 | |||
| 89 | ✗ | for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) { | |
| 90 | ✗ | ctrl_data[i].mask = para_2p_mask; | |
| 91 | ✗ | ctrl_data[i].desc = para_2p_desc; | |
| 92 | } | ||
| 93 | ✗ | } | |
| 94 | |||
| 95 | ✗ | void para_2p_from_generic(int32_t dev_mode, struct wired_ctrl *ctrl_data, struct wired_data *wired_data) { | |
| 96 | ✗ | if (ctrl_data->index < 2) { | |
| 97 | ✗ | struct para_2p_map map_tmp; | |
| 98 | ✗ | struct para_2p_map *map1 = (struct para_2p_map *)wired_adapter.data[0].output; | |
| 99 | ✗ | struct para_2p_map *map2 = (struct para_2p_map *)wired_adapter.data[1].output; | |
| 100 | ✗ | struct para_2p_map *map1_mask = (struct para_2p_map *)wired_adapter.data[0].output_mask; | |
| 101 | ✗ | struct para_2p_map *map2_mask = (struct para_2p_map *)wired_adapter.data[1].output_mask; | |
| 102 | |||
| 103 | ✗ | memcpy((void *)&map_tmp, wired_data->output, sizeof(map_tmp)); | |
| 104 | |||
| 105 | ✗ | for (uint32_t i = 0; i < ARRAY_SIZE(generic_btns_mask); i++) { | |
| 106 | ✗ | if (ctrl_data->map_mask[0] & BIT(i)) { | |
| 107 | ✗ | if (ctrl_data->btns[0].value & generic_btns_mask[i]) { | |
| 108 | ✗ | if ((para_2p_btns_mask[ctrl_data->index][i] & 0xF0000000) == 0xF0000000) { | |
| 109 | ✗ | map_tmp.buttons_high &= ~(para_2p_btns_mask[ctrl_data->index][i] & 0x000000FF); | |
| 110 | } | ||
| 111 | else { | ||
| 112 | ✗ | map_tmp.buttons &= ~para_2p_btns_mask[ctrl_data->index][i]; | |
| 113 | } | ||
| 114 | ✗ | wired_data->cnt_mask[i] = ctrl_data->btns[0].cnt_mask[i]; | |
| 115 | } | ||
| 116 | else { | ||
| 117 | ✗ | if ((para_2p_btns_mask[ctrl_data->index][i] & 0xF0000000) == 0xF0000000) { | |
| 118 | ✗ | map_tmp.buttons_high |= para_2p_btns_mask[ctrl_data->index][i] & 0x000000FF; | |
| 119 | } | ||
| 120 | else { | ||
| 121 | ✗ | map_tmp.buttons |= para_2p_btns_mask[ctrl_data->index][i]; | |
| 122 | } | ||
| 123 | ✗ | wired_data->cnt_mask[i] = 0; | |
| 124 | } | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | ✗ | memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp)); | |
| 129 | |||
| 130 | ✗ | GPIO.out = (map1->buttons | map1_mask->buttons) & (map2->buttons | map2_mask->buttons); | |
| 131 | ✗ | GPIO.out1.val = (map1->buttons_high | map1_mask->buttons_high) & (map2->buttons_high | map2_mask->buttons_high); | |
| 132 | |||
| 133 | ✗ | TESTS_CMDS_LOG("\"wired_output\": {\"btns\": [%ld, %ld]},\n", | |
| 134 | map_tmp.buttons, map_tmp.buttons_high); | ||
| 135 | BT_MON_LOG("\"wired_output\": {\"btns\": [%08lX, %08lX]},\n", | ||
| 136 | ✗ | map_tmp.buttons, map_tmp.buttons_high); | |
| 137 | } | ||
| 138 | ✗ | } | |
| 139 | |||
| 140 | ✗ | void para_2p_gen_turbo_mask(uint32_t index, struct wired_data *wired_data) { | |
| 141 | ✗ | struct para_2p_map *map_mask = (struct para_2p_map *)wired_data->output_mask; | |
| 142 | |||
| 143 | ✗ | memset(map_mask, 0, sizeof(*map_mask)); | |
| 144 | |||
| 145 | ✗ | for (uint32_t i = 0; i < ARRAY_SIZE(generic_btns_mask); i++) { | |
| 146 | ✗ | uint8_t mask = wired_data->cnt_mask[i] >> 1; | |
| 147 | |||
| 148 | ✗ | if (mask) { | |
| 149 | ✗ | if (para_2p_btns_mask[index][i]) { | |
| 150 | ✗ | if (wired_data->cnt_mask[i] & 1) { | |
| 151 | ✗ | if (!(mask & wired_data->frame_cnt)) { | |
| 152 | ✗ | if ((para_2p_btns_mask[index][i] & 0xF0000000) == 0xF0000000) { | |
| 153 | ✗ | map_mask->buttons_high |= para_2p_btns_mask[index][i]; | |
| 154 | } | ||
| 155 | else { | ||
| 156 | ✗ | map_mask->buttons |= para_2p_btns_mask[index][i]; | |
| 157 | } | ||
| 158 | } | ||
| 159 | } | ||
| 160 | else { | ||
| 161 | ✗ | if (!((mask & wired_data->frame_cnt) == mask)) { | |
| 162 | ✗ | if ((para_2p_btns_mask[index][i] & 0xF0000000) == 0xF0000000) { | |
| 163 | ✗ | map_mask->buttons_high |= para_2p_btns_mask[index][i]; | |
| 164 | } | ||
| 165 | else { | ||
| 166 | ✗ | map_mask->buttons |= para_2p_btns_mask[index][i]; | |
| 167 | } | ||
| 168 | } | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | ✗ | } | |
| 174 |