| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2019-2025, Jacques Gagnon | ||
| 3 | * SPDX-License-Identifier: Apache-2.0 | ||
| 4 | */ | ||
| 5 | |||
| 6 | #ifndef _ADAPTER_H_ | ||
| 7 | #define _ADAPTER_H_ | ||
| 8 | |||
| 9 | #include <stdio.h> | ||
| 10 | #include <esp_attr.h> | ||
| 11 | #include "zephyr/atomic.h" | ||
| 12 | #include "tests/cmds.h" | ||
| 13 | #include "bluetooth/mon.h" | ||
| 14 | |||
| 15 | #ifndef __packed | ||
| 16 | #define __packed __attribute__((__packed__)) | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #define RESET "\033[0m" | ||
| 20 | #define BOLD "\033[1m\033[37m" | ||
| 21 | #define GREEN "\033[1;32m" | ||
| 22 | |||
| 23 | #define BT_MAX_DEV 7 /* BT limitation */ | ||
| 24 | |||
| 25 | #ifdef CONFIG_BLUERETRO_QEMU | ||
| 26 | #define WIRED_MAX_DEV 8 /* Saturn limit */ | ||
| 27 | #else | ||
| 28 | #define WIRED_MAX_DEV 12 /* Saturn limit */ | ||
| 29 | #endif | ||
| 30 | #define ADAPTER_MAX_AXES 6 | ||
| 31 | #define ADAPTER_PS2_MAX_AXES 16 | ||
| 32 | #define REPORT_MAX_USAGE 24 | ||
| 33 | #define HID_MAX_REPORT 10 | ||
| 34 | #define MAX_PULL_BACK 0.95 | ||
| 35 | |||
| 36 | /* BT device type ID */ | ||
| 37 | enum { | ||
| 38 | BT_NONE = -1, | ||
| 39 | BT_HID_GENERIC, | ||
| 40 | BT_PS3, | ||
| 41 | BT_WII, | ||
| 42 | BT_PS, | ||
| 43 | BT_SW, | ||
| 44 | BT_SW2, | ||
| 45 | BT_TYPE_MAX, | ||
| 46 | }; | ||
| 47 | |||
| 48 | /* BT device subtype ID */ | ||
| 49 | enum { | ||
| 50 | BT_SUBTYPE_DEFAULT = 0, | ||
| 51 | BT_WII_NUNCHUCK, | ||
| 52 | BT_WII_CLASSIC, | ||
| 53 | BT_WII_CLASSIC_8BIT, | ||
| 54 | BT_WII_CLASSIC_PRO, | ||
| 55 | BT_WII_CLASSIC_PRO_8BIT, | ||
| 56 | BT_WIIU_PRO, | ||
| 57 | BT_PS5_DS, | ||
| 58 | BT_SW_LEFT_JOYCON, | ||
| 59 | BT_SW_RIGHT_JOYCON, | ||
| 60 | BT_SW_NES, | ||
| 61 | BT_SW_SNES, | ||
| 62 | BT_SW_N64, | ||
| 63 | BT_SW_MD_GEN, | ||
| 64 | BT_SW_HYPERKIN_ADMIRAL, | ||
| 65 | BT_SUBTYPE_MAX, | ||
| 66 | }; | ||
| 67 | |||
| 68 | /* Wired system ID */ | ||
| 69 | enum { | ||
| 70 | WIRED_AUTO = 0, | ||
| 71 | PARALLEL_1P, | ||
| 72 | PARALLEL_2P, | ||
| 73 | NES, | ||
| 74 | PCE, | ||
| 75 | GENESIS, | ||
| 76 | SNES, | ||
| 77 | CDI, | ||
| 78 | CD32, | ||
| 79 | REAL_3DO, | ||
| 80 | JAGUAR, | ||
| 81 | PSX, | ||
| 82 | SATURN, | ||
| 83 | PCFX, | ||
| 84 | JVS, | ||
| 85 | N64, | ||
| 86 | DC, | ||
| 87 | PS2, | ||
| 88 | GC, | ||
| 89 | WII_EXT, | ||
| 90 | VBOY, | ||
| 91 | PARALLEL_1P_OD, | ||
| 92 | PARALLEL_2P_OD, | ||
| 93 | SEA_BOARD, | ||
| 94 | WIRED_MAX, | ||
| 95 | }; | ||
| 96 | |||
| 97 | /* Report type ID */ | ||
| 98 | enum { | ||
| 99 | REPORT_NONE = -1, | ||
| 100 | KB, | ||
| 101 | MOUSE, | ||
| 102 | PAD, | ||
| 103 | RUMBLE, | ||
| 104 | REPORT_MAX, | ||
| 105 | //LEDS, | ||
| 106 | }; | ||
| 107 | |||
| 108 | enum { | ||
| 109 | BTN_NONE = -1, | ||
| 110 | PAD_LX_LEFT, | ||
| 111 | PAD_LX_RIGHT, | ||
| 112 | PAD_LY_DOWN, | ||
| 113 | PAD_LY_UP, | ||
| 114 | PAD_RX_LEFT, | ||
| 115 | PAD_RX_RIGHT, | ||
| 116 | PAD_RY_DOWN, | ||
| 117 | PAD_RY_UP, | ||
| 118 | PAD_LD_LEFT, | ||
| 119 | PAD_LD_RIGHT, | ||
| 120 | PAD_LD_DOWN, | ||
| 121 | PAD_LD_UP, | ||
| 122 | PAD_RD_LEFT, | ||
| 123 | PAD_RD_RIGHT, | ||
| 124 | PAD_RD_DOWN, | ||
| 125 | PAD_RD_UP, | ||
| 126 | PAD_RB_LEFT, | ||
| 127 | PAD_RB_RIGHT, | ||
| 128 | PAD_RB_DOWN, | ||
| 129 | PAD_RB_UP, | ||
| 130 | PAD_MM, | ||
| 131 | PAD_MS, | ||
| 132 | PAD_MT, | ||
| 133 | PAD_MQ, | ||
| 134 | PAD_LM, | ||
| 135 | PAD_LS, | ||
| 136 | PAD_LT, | ||
| 137 | PAD_LJ, | ||
| 138 | PAD_RM, | ||
| 139 | PAD_RS, | ||
| 140 | PAD_RT, | ||
| 141 | PAD_RJ, | ||
| 142 | }; | ||
| 143 | |||
| 144 | /* Stage the Mouse & KB mapping to be a good default when used as a joystick */ | ||
| 145 | enum { | ||
| 146 | KBM_NONE = -1, | ||
| 147 | KB_A, | ||
| 148 | KB_D, | ||
| 149 | KB_S, | ||
| 150 | KB_W, | ||
| 151 | MOUSE_X_LEFT, | ||
| 152 | MOUSE_X_RIGHT, | ||
| 153 | MOUSE_Y_DOWN, | ||
| 154 | MOUSE_Y_UP, | ||
| 155 | KB_LEFT, | ||
| 156 | KB_RIGHT, | ||
| 157 | KB_DOWN, | ||
| 158 | KB_UP, | ||
| 159 | MOUSE_WX_LEFT, | ||
| 160 | MOUSE_WX_RIGHT, | ||
| 161 | MOUSE_WY_DOWN, | ||
| 162 | MOUSE_WY_UP, | ||
| 163 | KB_Q, MOUSE_4 = KB_Q, | ||
| 164 | KB_R, MOUSE_5 = KB_R, | ||
| 165 | KB_E, MOUSE_6 = KB_E, | ||
| 166 | KB_F, MOUSE_7 = KB_F, | ||
| 167 | KB_ESC, | ||
| 168 | KB_ENTER, | ||
| 169 | KB_LWIN, | ||
| 170 | KB_HASH, | ||
| 171 | MOUSE_RIGHT, | ||
| 172 | KB_Z, | ||
| 173 | KB_LCTRL, | ||
| 174 | MOUSE_MIDDLE, | ||
| 175 | MOUSE_LEFT, | ||
| 176 | KB_X, MOUSE_8 = KB_X, | ||
| 177 | KB_LSHIFT, | ||
| 178 | KB_SPACE, | ||
| 179 | KB_B, | ||
| 180 | KB_C, | ||
| 181 | KB_G, | ||
| 182 | KB_H, | ||
| 183 | KB_I, | ||
| 184 | KB_J, | ||
| 185 | KB_K, | ||
| 186 | KB_L, | ||
| 187 | KB_M, | ||
| 188 | KB_N, | ||
| 189 | KB_O, | ||
| 190 | KB_P, | ||
| 191 | KB_T, | ||
| 192 | KB_U, | ||
| 193 | KB_V, | ||
| 194 | KB_Y, | ||
| 195 | KB_1, | ||
| 196 | KB_2, | ||
| 197 | KB_3, | ||
| 198 | KB_4, | ||
| 199 | KB_5, | ||
| 200 | KB_6, | ||
| 201 | KB_7, | ||
| 202 | KB_8, | ||
| 203 | KB_9, | ||
| 204 | KB_0, | ||
| 205 | KB_BACKSPACE, | ||
| 206 | KB_TAB, | ||
| 207 | KB_MINUS, | ||
| 208 | KB_EQUAL, | ||
| 209 | KB_LEFTBRACE, | ||
| 210 | KB_RIGHTBRACE, | ||
| 211 | KB_BACKSLASH, | ||
| 212 | KB_SEMICOLON, | ||
| 213 | KB_APOSTROPHE, | ||
| 214 | KB_GRAVE, | ||
| 215 | KB_COMMA, | ||
| 216 | KB_DOT, | ||
| 217 | KB_SLASH, | ||
| 218 | KB_CAPSLOCK, | ||
| 219 | KB_F1, | ||
| 220 | KB_F2, | ||
| 221 | KB_F3, | ||
| 222 | KB_F4, | ||
| 223 | KB_F5, | ||
| 224 | KB_F6, | ||
| 225 | KB_F7, | ||
| 226 | KB_F8, | ||
| 227 | KB_F9, | ||
| 228 | KB_F10, | ||
| 229 | KB_F11, | ||
| 230 | KB_F12, | ||
| 231 | KB_PSCREEN, | ||
| 232 | KB_SCROLL, | ||
| 233 | KB_PAUSE, | ||
| 234 | KB_INSERT, | ||
| 235 | KB_HOME, | ||
| 236 | KB_PAGEUP, | ||
| 237 | KB_DEL, | ||
| 238 | KB_END, | ||
| 239 | KB_PAGEDOWN, | ||
| 240 | KB_NUMLOCK, | ||
| 241 | KB_KP_DIV, | ||
| 242 | KB_KP_MULTI, | ||
| 243 | KB_KP_MINUS, | ||
| 244 | KB_KP_PLUS, | ||
| 245 | KB_KP_ENTER, | ||
| 246 | KB_KP_1, | ||
| 247 | KB_KP_2, | ||
| 248 | KB_KP_3, | ||
| 249 | KB_KP_4, | ||
| 250 | KB_KP_5, | ||
| 251 | KB_KP_6, | ||
| 252 | KB_KP_7, | ||
| 253 | KB_KP_8, | ||
| 254 | KB_KP_9, | ||
| 255 | KB_KP_0, | ||
| 256 | KB_KP_DOT, | ||
| 257 | KB_LALT, | ||
| 258 | KB_RCTRL, | ||
| 259 | KB_RSHIFT, | ||
| 260 | KB_RALT, | ||
| 261 | KB_RWIN, | ||
| 262 | KBM_MAX, | ||
| 263 | }; | ||
| 264 | |||
| 265 | enum { | ||
| 266 | BR_COMBO_BASE_1 = 118, | ||
| 267 | BR_COMBO_BASE_2, | ||
| 268 | BR_COMBO_BASE_3, | ||
| 269 | BR_COMBO_BASE_4, | ||
| 270 | BR_COMBO_SYS_RESET, | ||
| 271 | BR_COMBO_BT_INQUIRY, | ||
| 272 | BR_COMBO_SYS_POWER_OFF, | ||
| 273 | BR_COMBO_FACTORY_RESET, | ||
| 274 | BR_COMBO_DEEP_SLEEP, | ||
| 275 | BR_COMBO_WIRED_RST, | ||
| 276 | BR_COMBO_MAX, | ||
| 277 | }; | ||
| 278 | #define BR_COMBO_CNT (BR_COMBO_MAX - BR_COMBO_BASE_1) | ||
| 279 | #define BR_COMBO_MASK 0xFFC00000 | ||
| 280 | |||
| 281 | enum { | ||
| 282 | AXIS_NONE = -1, | ||
| 283 | AXIS_LX, | ||
| 284 | AXIS_LY, | ||
| 285 | AXIS_RX, | ||
| 286 | AXIS_RY, | ||
| 287 | TRIG_L, | ||
| 288 | TRIG_R, | ||
| 289 | TRIG_LS, | ||
| 290 | TRIG_RS, | ||
| 291 | DPAD_LEFT, | ||
| 292 | DPAD_RIGHT, | ||
| 293 | DPAD_DOWN, | ||
| 294 | DPAD_UP, | ||
| 295 | BTN_LEFT, | ||
| 296 | BTN_RIGHT, | ||
| 297 | BTN_DOWN, | ||
| 298 | BTN_UP, | ||
| 299 | }; | ||
| 300 | |||
| 301 | /* BT flags */ | ||
| 302 | enum { | ||
| 303 | BT_INIT = 0, | ||
| 304 | BT_WAITING_FOR_RELEASE_MACRO1, | ||
| 305 | BT_WAITING_FOR_RELEASE_MACRO2, | ||
| 306 | BT_WAITING_FOR_RELEASE_MACRO3, | ||
| 307 | BT_WAITING_FOR_RELEASE_MACRO4, | ||
| 308 | BT_WAITING_FOR_RELEASE_MACRO5, | ||
| 309 | BT_WAITING_FOR_RELEASE_MACRO6, | ||
| 310 | BT_QUIRK_FACE_BTNS_INVERT, | ||
| 311 | BT_QUIRK_FACE_BTNS_ROTATE_RIGHT, | ||
| 312 | BT_QUIRK_FACE_BTNS_TRIGGER_TO_6BUTTONS, | ||
| 313 | BT_QUIRK_FACE_BTNS_TRIGGER_TO_8BUTTONS, | ||
| 314 | BT_QUIRK_TRIGGER_PRI_SEC_INVERT, | ||
| 315 | BT_QUIRK_8BITDO_N64, | ||
| 316 | BT_QUIRK_8BITDO_N64_MK, | ||
| 317 | BT_QUIRK_8BITDO_M30, | ||
| 318 | BT_QUIRK_8BITDO_M30_MODKIT, | ||
| 319 | BT_QUIRK_BLUEN64_N64, | ||
| 320 | BT_QUIRK_RF_WARRIOR, | ||
| 321 | BT_QUIRK_8BITDO_SATURN, | ||
| 322 | BT_QUIRK_OUYA, | ||
| 323 | BT_QUIRK_8BITDO_GC, | ||
| 324 | BT_QUIRK_8BITDO_GBROS, | ||
| 325 | }; | ||
| 326 | |||
| 327 | /* Wired flags */ | ||
| 328 | enum { | ||
| 329 | WIRED_NEW_DATA = 0, | ||
| 330 | WIRED_SAVE_MEM, | ||
| 331 | WIRED_WAITING_FOR_RELEASE, | ||
| 332 | WIRED_WAITING_FOR_RELEASE2, | ||
| 333 | WIRED_GPIO_INIT, | ||
| 334 | WIRED_KBMON_INIT, | ||
| 335 | }; | ||
| 336 | |||
| 337 | /* Dev mode */ | ||
| 338 | enum { | ||
| 339 | DEV_PAD = 0, | ||
| 340 | DEV_PAD_ALT, | ||
| 341 | DEV_KB, | ||
| 342 | DEV_MOUSE, | ||
| 343 | }; | ||
| 344 | |||
| 345 | /* Acc mode */ | ||
| 346 | enum { | ||
| 347 | ACC_NONE = 0, | ||
| 348 | ACC_MEM, | ||
| 349 | ACC_RUMBLE, | ||
| 350 | ACC_BOTH, | ||
| 351 | }; | ||
| 352 | |||
| 353 | /* Multitap mode */ | ||
| 354 | enum { | ||
| 355 | MT_NONE = 0, | ||
| 356 | MT_SLOT_1, | ||
| 357 | MT_SLOT_2, | ||
| 358 | MT_DUAL, | ||
| 359 | MT_ALT, | ||
| 360 | }; | ||
| 361 | |||
| 362 | /* Inquiry mode */ | ||
| 363 | enum { | ||
| 364 | INQ_AUTO = 0, | ||
| 365 | INQ_MANUAL, | ||
| 366 | }; | ||
| 367 | |||
| 368 | /* Scaling mode */ | ||
| 369 | enum { | ||
| 370 | LINEAR = 0, | ||
| 371 | AGGRESSIVE, | ||
| 372 | RELAXED, | ||
| 373 | WIDE, | ||
| 374 | S_CURVE, | ||
| 375 | PASSTHROUGH, | ||
| 376 | }; | ||
| 377 | |||
| 378 | /* Diagonal Scaling mode */ | ||
| 379 | enum { | ||
| 380 | DIAG_PASSTHROUGH = 0, | ||
| 381 | CIRCLE_SQUARE, | ||
| 382 | CIRCLE_HEX, | ||
| 383 | SQUARE_CIRCLE, | ||
| 384 | SQUARE_HEX, | ||
| 385 | }; | ||
| 386 | |||
| 387 | /* Feedback type */ | ||
| 388 | enum { | ||
| 389 | FB_TYPE_NONE = 0, | ||
| 390 | FB_TYPE_RUMBLE, | ||
| 391 | FB_TYPE_STATUS_LED, | ||
| 392 | FB_TYPE_PLAYER_LED, | ||
| 393 | FB_TYPE_MEM_WRITE, | ||
| 394 | FB_TYPE_GAME_ID, | ||
| 395 | FB_TYPE_SYS_ID, | ||
| 396 | }; | ||
| 397 | |||
| 398 | enum { | ||
| 399 | HID_IN = 0, | ||
| 400 | HID_OUT, | ||
| 401 | //HID_FTR, | ||
| 402 | HID_TAG_CNT, | ||
| 403 | }; | ||
| 404 | |||
| 405 | struct ctrl_meta { | ||
| 406 | int32_t neutral; | ||
| 407 | int32_t deadzone; | ||
| 408 | int32_t abs_max; | ||
| 409 | int32_t abs_min; | ||
| 410 | int32_t polarity; | ||
| 411 | int32_t size_min; | ||
| 412 | int32_t size_max; | ||
| 413 | int32_t relative; | ||
| 414 | }; | ||
| 415 | |||
| 416 | struct ctrl_axis { | ||
| 417 | int32_t value; | ||
| 418 | int32_t relative; | ||
| 419 | struct ctrl_meta *meta; | ||
| 420 | }; | ||
| 421 | |||
| 422 | struct ctrl_axis_wired { | ||
| 423 | int32_t value; | ||
| 424 | int32_t relative; | ||
| 425 | const struct ctrl_meta *meta; | ||
| 426 | uint32_t cnt_mask; | ||
| 427 | }; | ||
| 428 | |||
| 429 | struct ctrl_btn { | ||
| 430 | int32_t value; | ||
| 431 | uint32_t cnt_mask[32]; | ||
| 432 | }; | ||
| 433 | |||
| 434 | struct wireless_ctrl { | ||
| 435 | const uint32_t *mask; | ||
| 436 | const uint32_t *desc; | ||
| 437 | struct ctrl_btn btns[4]; | ||
| 438 | struct ctrl_axis axes[ADAPTER_PS2_MAX_AXES]; | ||
| 439 | }; | ||
| 440 | |||
| 441 | struct wired_ctrl { | ||
| 442 | uint32_t index; | ||
| 443 | const uint32_t *mask; | ||
| 444 | const uint32_t *desc; | ||
| 445 | uint32_t map_mask[4]; | ||
| 446 | struct ctrl_btn btns[4]; | ||
| 447 | struct ctrl_axis_wired axes[ADAPTER_PS2_MAX_AXES]; | ||
| 448 | }; | ||
| 449 | |||
| 450 | struct generic_fb { | ||
| 451 | uint8_t wired_id; | ||
| 452 | uint8_t type; | ||
| 453 | union { | ||
| 454 | struct { | ||
| 455 | uint32_t state; | ||
| 456 | uint32_t lf_pwr; | ||
| 457 | uint32_t hf_pwr; | ||
| 458 | }; | ||
| 459 | uint32_t led; | ||
| 460 | }; | ||
| 461 | }; | ||
| 462 | |||
| 463 | struct raw_fb_header { | ||
| 464 | uint8_t wired_id; | ||
| 465 | uint8_t type; | ||
| 466 | uint8_t data_len; | ||
| 467 | } __packed; | ||
| 468 | |||
| 469 | struct raw_fb { | ||
| 470 | struct raw_fb_header header; | ||
| 471 | uint8_t data[13]; | ||
| 472 | } __packed; | ||
| 473 | |||
| 474 | struct hid_usage { | ||
| 475 | uint32_t usage_page; | ||
| 476 | uint32_t usage; | ||
| 477 | uint32_t usage_max; | ||
| 478 | uint32_t flags; | ||
| 479 | uint32_t bit_offset; | ||
| 480 | uint32_t bit_size; | ||
| 481 | int32_t logical_min; | ||
| 482 | int32_t logical_max; | ||
| 483 | }; | ||
| 484 | |||
| 485 | struct hid_report { | ||
| 486 | uint32_t id; | ||
| 487 | uint32_t len; | ||
| 488 | uint32_t tag; | ||
| 489 | uint32_t usage_cnt; | ||
| 490 | uint32_t type; | ||
| 491 | struct hid_usage usages[REPORT_MAX_USAGE]; | ||
| 492 | }; | ||
| 493 | |||
| 494 | struct raw_src_mapping { | ||
| 495 | uint32_t mask[4]; | ||
| 496 | uint32_t desc[4]; | ||
| 497 | uint32_t btns_mask[32]; | ||
| 498 | int32_t axes_idx[ADAPTER_PS2_MAX_AXES]; | ||
| 499 | struct ctrl_meta meta[ADAPTER_PS2_MAX_AXES]; | ||
| 500 | }; | ||
| 501 | |||
| 502 | struct bt_ids { | ||
| 503 | int32_t id; | ||
| 504 | int32_t out_idx; | ||
| 505 | int32_t type; | ||
| 506 | uint32_t subtype; | ||
| 507 | uint32_t report_type; | ||
| 508 | } __packed; | ||
| 509 | |||
| 510 | struct bt_data_base { | ||
| 511 | atomic_t flags[REPORT_MAX]; | ||
| 512 | struct bt_ids *pids; | ||
| 513 | uint32_t report_id; | ||
| 514 | int32_t report_type; | ||
| 515 | uint32_t report_cnt; | ||
| 516 | uint32_t report_cnt_last; | ||
| 517 | uint8_t *input; | ||
| 518 | uint32_t input_len; | ||
| 519 | uint8_t *sdp_data; | ||
| 520 | uint32_t sdp_len; | ||
| 521 | uint8_t *pnp_data; | ||
| 522 | uint32_t pnp_len; | ||
| 523 | int32_t axes_cal[ADAPTER_PS2_MAX_AXES]; | ||
| 524 | uint16_t vid; | ||
| 525 | uint16_t pid; | ||
| 526 | uint8_t output[128]; | ||
| 527 | }; | ||
| 528 | |||
| 529 | struct bt_data { | ||
| 530 | struct bt_data_base base; | ||
| 531 | struct raw_src_mapping *raw_src_mappings; | ||
| 532 | struct hid_report *reports[REPORT_MAX]; | ||
| 533 | }; | ||
| 534 | |||
| 535 | struct wired_data { | ||
| 536 | uint32_t index; | ||
| 537 | void *fb_timer_hdl; | ||
| 538 | /* Bi-directional */ | ||
| 539 | atomic_t flags; | ||
| 540 | /* from wired driver */ | ||
| 541 | uint32_t frame_cnt; | ||
| 542 | /* from adapter */ | ||
| 543 | union { | ||
| 544 | uint8_t output[64]; | ||
| 545 | uint16_t output16[32]; | ||
| 546 | uint32_t output32[16]; | ||
| 547 | }; | ||
| 548 | union { | ||
| 549 | uint8_t output_mask[64]; | ||
| 550 | uint16_t output_mask16[32]; | ||
| 551 | uint32_t output_mask32[16]; | ||
| 552 | }; | ||
| 553 | uint8_t cnt_mask[KBM_MAX]; | ||
| 554 | }; | ||
| 555 | |||
| 556 | struct wired_adapter { | ||
| 557 | /* from wired driver */ | ||
| 558 | int32_t system_id; | ||
| 559 | void *input_q_hdl; | ||
| 560 | /* from adapter */ | ||
| 561 | int32_t driver_mode; | ||
| 562 | /* Bi-directional */ | ||
| 563 | struct wired_data data[WIRED_MAX_DEV]; | ||
| 564 | }; | ||
| 565 | |||
| 566 | struct bt_adapter { | ||
| 567 | struct bt_data data[BT_MAX_DEV]; | ||
| 568 | }; | ||
| 569 | |||
| 570 | typedef int32_t (*to_generic_t)(struct bt_data *bt_data, struct wireless_ctrl *ctrl_data); | ||
| 571 | typedef void (*from_generic_t)(int32_t dev_mode, struct wired_ctrl *ctrl_data, struct wired_data *wired_data); | ||
| 572 | typedef void (*fb_to_generic_t)(int32_t dev_mode, struct raw_fb *raw_fb_data, struct generic_fb *fb_data); | ||
| 573 | typedef bool (*fb_from_generic_t)(struct generic_fb *fb_data, struct bt_data *bt_data); | ||
| 574 | typedef void (*meta_init_t)(struct wired_ctrl *ctrl_data); | ||
| 575 | typedef void (*buffer_init_t)(int32_t dev_mode, struct wired_data *wired_data); | ||
| 576 | |||
| 577 | extern const uint32_t hat_to_ld_btns[16]; | ||
| 578 | extern const uint32_t generic_btns_mask[32]; | ||
| 579 | extern struct bt_adapter bt_adapter; | ||
| 580 | extern struct wired_adapter wired_adapter; | ||
| 581 | |||
| 582 | uint32_t adapter_get_out_mask(uint8_t dev_id); | ||
| 583 | int32_t btn_id_to_axis(uint8_t btn_id); | ||
| 584 | uint8_t btn_is_axis(uint8_t dst_id, uint8_t dst_btn_id); | ||
| 585 | uint32_t axis_to_btn_mask(uint8_t axis); | ||
| 586 | uint32_t axis_to_btn_id(uint8_t axis); | ||
| 587 | int8_t btn_sign(uint32_t polarity, uint8_t btn_id); | ||
| 588 | void adapter_init_buffer(uint8_t wired_id); | ||
| 589 | void adapter_bridge(struct bt_data *bt_data); | ||
| 590 | void adapter_fb_stop_timer_start(uint8_t dev_id, uint64_t dur_us); | ||
| 591 | void adapter_fb_stop_timer_stop(uint8_t dev_id); | ||
| 592 | bool adapter_bridge_fb(struct raw_fb *fb_data, struct bt_data *bt_data); | ||
| 593 | void adapter_q_fb(struct raw_fb *fb_data); | ||
| 594 | void adapter_toggle_fb(uint32_t wired_id, uint32_t duration_us, uint8_t lf_pwr, uint8_t hf_pwr); | ||
| 595 | void adapter_init(void); | ||
| 596 | void adapter_meta_init(void); | ||
| 597 | |||
| 598 | 149 | static inline void bt_type_update(int32_t dev_id, int32_t type, uint32_t subtype) { | |
| 599 | 149 | struct bt_data *bt_data = &bt_adapter.data[dev_id]; | |
| 600 | |||
| 601 |
1/2✓ Branch 0 (2→3) taken 149 times.
✗ Branch 1 (2→10) not taken.
|
149 | if (bt_data->base.pids) { |
| 602 | 149 | bt_data->base.pids->type = type; | |
| 603 | 149 | bt_data->base.pids->subtype = subtype; | |
| 604 | 149 | bt_data->base.report_cnt = 0; | |
| 605 | 149 | bt_data->base.report_cnt_last = 0; | |
| 606 |
2/2✓ Branch 0 (6→4) taken 596 times.
✓ Branch 1 (6→7) taken 149 times.
|
745 | for (uint32_t i = 0; i < REPORT_MAX; i++) { |
| 607 | 596 | atomic_clear_bit(&bt_data->base.flags[i], BT_INIT); | |
| 608 | } | ||
| 609 | 149 | printf("%s: dev: %ld type: %ld subtype: %ld\n", __FUNCTION__, dev_id, type, subtype); | |
| 610 | 149 | TESTS_CMDS_LOG("\"type_update\": {\"device_id\": %d, \"device_type\": %d, \"device_subtype\": %d},\n", | |
| 611 | dev_id, type, subtype); | ||
| 612 | 149 | bt_mon_log(true, "%s: dev: %ld type: %ld subtype: %ld\n", __FUNCTION__, dev_id, type, subtype); | |
| 613 | } | ||
| 614 | 149 | } | |
| 615 | |||
| 616 | #endif /* _ADAPTER_H_ */ | ||
| 617 | |||
| 618 |