GCC Code Coverage Report


Directory: main/
File: adapter/wired/parallel_1p.c
Date: 2025-10-04 14:03:00
Exec Total Coverage
Lines: 0 59 0.0%
Functions: 0 4 0.0%
Branches: 0 34 0.0%

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_1p.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_LD_UP 3
17 #define P1_LD_DOWN 5
18 #define P1_LD_LEFT 18
19 #define P1_LD_RIGHT 23
20 #define P1_RB_DOWN 26
21 #define P1_RB_RIGHT 27
22 #define P1_RB_LEFT 19
23 #define P1_RB_UP 21
24 #define P1_MM 32
25 #define P1_MS 22
26 #define P1_MT 16
27 #define P1_LM 25
28 #define P1_RM 33
29
30 static const uint32_t para_1p_mask[4] = {0x337F0F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
31 static const uint32_t para_1p_desc[4] = {0x00000000, 0x00000000, 0x00000000, 0x00000000};
32 static DRAM_ATTR const uint32_t para_1p_btns_mask[32] = {
33 0, 0, 0, 0,
34 0, 0, 0, 0,
35 BIT(P1_LD_LEFT), BIT(P1_LD_RIGHT), BIT(P1_LD_DOWN), BIT(P1_LD_UP),
36 0, 0, 0, 0,
37 BIT(P1_RB_LEFT), BIT(P1_RB_RIGHT), BIT(P1_RB_DOWN), BIT(P1_RB_UP),
38 BIT(P1_MM - 32) | 0xF0000000, BIT(P1_MS), BIT(P1_MT), 0,
39 BIT(P1_LM), BIT(P1_LM), 0, 0,
40 BIT(P1_RM - 32) | 0xF0000000, BIT(P1_RM - 32) | 0xF0000000, 0, 0,
41 };
42
43 void IRAM_ATTR para_1p_init_buffer(int32_t dev_mode, struct wired_data *wired_data) {
44 struct para_1p_map *map = (struct para_1p_map *)wired_data->output;
45 struct para_1p_map *map_mask = (struct para_1p_map *)wired_data->output_mask;
46
47 map->buttons = 0xFFFDFFFF;
48 map->buttons_high = 0xFFFFFFFF;
49 map_mask->buttons = 0;
50 map_mask->buttons_high = 0;
51 }
52
53 void para_1p_meta_init(struct wired_ctrl *ctrl_data) {
54 memset((void *)ctrl_data, 0, sizeof(*ctrl_data)*WIRED_MAX_DEV);
55
56 for (uint32_t i = 0; i < WIRED_MAX_DEV; i++) {
57 ctrl_data[i].mask = para_1p_mask;
58 ctrl_data[i].desc = para_1p_desc;
59 }
60 }
61
62 void para_1p_from_generic(int32_t dev_mode, struct wired_ctrl *ctrl_data, struct wired_data *wired_data) {
63 if (ctrl_data->index < 1) {
64 struct para_1p_map map_tmp;
65 uint32_t map_mask = 0xFFFFFFFF;
66 uint32_t map_mask_high = 0xFFFFFFFF;
67 struct para_1p_map *turbo_map_mask = (struct para_1p_map *)wired_data->output_mask;
68
69 memcpy((void *)&map_tmp, wired_data->output, sizeof(map_tmp));
70
71 for (uint32_t i = 0; i < ARRAY_SIZE(generic_btns_mask); i++) {
72 if (ctrl_data->map_mask[0] & BIT(i)) {
73 if (ctrl_data->btns[0].value & generic_btns_mask[i]) {
74 if ((para_1p_btns_mask[i] & 0xF0000000) == 0xF0000000) {
75 map_tmp.buttons_high &= ~(para_1p_btns_mask[i] & 0x000000FF);
76 map_mask_high &= ~(para_1p_btns_mask[i] & 0x000000FF);
77 }
78 else {
79 map_tmp.buttons &= ~para_1p_btns_mask[i];
80 map_mask &= ~para_1p_btns_mask[i];
81 }
82 wired_data->cnt_mask[i] = ctrl_data->btns[0].cnt_mask[i];
83 }
84 else {
85 if ((para_1p_btns_mask[i] & 0xF0000000) == 0xF0000000) {
86 if (map_mask & (para_1p_btns_mask[i] & 0x000000FF)) {
87 map_tmp.buttons_high |= para_1p_btns_mask[i] & 0x000000FF;
88 }
89 }
90 else {
91 if (map_mask & para_1p_btns_mask[i]) {
92 map_tmp.buttons |= para_1p_btns_mask[i];
93 }
94 }
95 wired_data->cnt_mask[i] = 0;
96 }
97 }
98 }
99
100 GPIO.out = map_tmp.buttons | turbo_map_mask->buttons;
101 GPIO.out1.val = map_tmp.buttons_high | turbo_map_mask->buttons_high;
102
103 memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp));
104
105 TESTS_CMDS_LOG("\"wired_output\": {\"btns\": [%ld, %ld]},\n",
106 map_tmp.buttons, map_tmp.buttons_high);
107 BT_MON_LOG("\"wired_output\": {\"btns\": [%08lX, %08lX]},\n",
108 map_tmp.buttons, map_tmp.buttons_high);
109 }
110 }
111
112 void para_1p_gen_turbo_mask(struct wired_data *wired_data) {
113 struct para_1p_map *map_mask = (struct para_1p_map *)wired_data->output_mask;
114
115 memset(map_mask, 0, sizeof(*map_mask));
116
117 for (uint32_t i = 0; i < ARRAY_SIZE(generic_btns_mask); i++) {
118 uint8_t mask = wired_data->cnt_mask[i] >> 1;
119
120 if (mask) {
121 if (para_1p_btns_mask[i]) {
122 if (wired_data->cnt_mask[i] & 1) {
123 if (!(mask & wired_data->frame_cnt)) {
124 if ((para_1p_btns_mask[i] & 0xF0000000) == 0xF0000000) {
125 map_mask->buttons_high |= para_1p_btns_mask[i];
126 }
127 else {
128 map_mask->buttons |= para_1p_btns_mask[i];
129 }
130 }
131 }
132 else {
133 if (!((mask & wired_data->frame_cnt) == mask)) {
134 if ((para_1p_btns_mask[i] & 0xF0000000) == 0xF0000000) {
135 map_mask->buttons_high |= para_1p_btns_mask[i];
136 }
137 else {
138 map_mask->buttons |= para_1p_btns_mask[i];
139 }
140 }
141 }
142 }
143 }
144 }
145 }
146