forked from 48productions/piuio-pico
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpiuio_config.h
294 lines (228 loc) · 8.01 KB
/
piuio_config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*******************************************************************************************/
/* SPDX-License-Identifier: MIT */
/* SPDX-FileCopyrightText: Copyright (c) 2023 48productions, therathatter, dj505, sugoku */
/* https://github.com/sugoku/piuio-pico-brokeIO */
/*******************************************************************************************/
#ifndef _PIUIO_CONFIG_H
#define _PIUIO_CONFIG_H
#include "piuio_ws2812_helpers.h"
#include "hardware/timer.h"
#include "usb_descriptors.h"
#include "usb_hid_keys.h"
// debounce time in milliseconds
// adjust if you are getting misfires!
#define DEBOUNCE_PRESS_TIME 15
#define DEBOUNCE_RELEASE_TIME 15
// enable debouncing
#define DEBOUNCING
// use joystick instead of d-pad in Switch mode
#define SWITCH_JOYSTICK
// merge all sensor inputs, improving response time at the cost of not being able
// to read individual sensors in the service menu.
// in PIUIO mode, one poll reads one sensor per panel (10/40 sensors per poll).
// official games only poll the PIUIO every 10ms, which is 100Hz best case but
// 25Hz worst case the game is reading the wrong sensor.
// setting this to true will improve sensor press polling to always be 100Hz,
// but release polling will still be 25Hz worst case.
#define MERGE_MUX_PIUIO false
// time in microseconds to wait between input/lights operations
// this accounts for variance in the brokeIO's multiplexer and latch chips
// the delay is negligible, so you would not notice it
#define WAIT_INPUT_MUX4067 20
#define WAIT_LIGHTS_LATCH32 20
// always allow pad combo to enter bootloader; otherwise, it must be done in the service mode
#define ALWAYS_BOOTLOADER false
// default input mode unless otherwise specified in the flash memory
#define DEFAULT_INPUT_MODE INPUT_MODE_SERIAL
// use software SPI to control latch for outputs
// for some reason hardware SPI wasn't working right for me so I have it enabled
#define SOFTWARE_LATCH
// toggle pin on and off on the main loop for debugging purposes
// #define BENCHMARK
// uncomment to always use the default input mode on boot instead of what's in the flash memory
// disables reading/writing to flash also
// (you will not be able to change the mode until reflashing!)
// #define ALWAYS_DEFAULT_INPUT_MODE
// threshold in ms to hold SERVICE button to enter mode select (settings menu)
#define SETTINGS_THRESHOLD 2000
// these PIDs are granted by Openmoko! they are not used for PIUIO/LXIO modes
// https://github.com/openmoko/openmoko-usb-oui
#define VENDOR_ID 0x1D50
#define PRODUCT_ID_GAMEPAD 0x6181
#define PRODUCT_ID_KEYBOARD 0x6182
#define PRODUCT_ID_OTHER 0x6183
// enable pullup resistors for inputs
// (only disable this if you know what you are doing!)
#define PULLUP_IN
#define MUX_GLOBAL 4
#define MUX_COUNT 5
#define MAX_USB_POWER 0xFA // (500mA)
// Uncomment these defines to enable WS2812 LED support. NOT WORKING WITH brokeIO
//#define ENABLE_WS2812_SUPPORT
//#define WS2812_IS_RGBW false
//#define WS2812_PIN 22
// Modify these to edit the colors of the cabinet lamps.
#ifdef ENABLE_WS2812_SUPPORT
static uint32_t ws2812_color[5] = {
urgb_u32(0, 255, 0), // Lower left
urgb_u32(255, 0, 0), // Upper left
urgb_u32(0, 0, 255), // Bass / neon
urgb_u32(255, 0, 0), // Upper right
urgb_u32(0, 255, 0) // Lower right
};
#endif
// helper defines
#define GETBIT(port,bit) ((port) & (1 << (bit))) // get value at bit
#define SETBIT(port,bit) ((port) |= (1 << (bit))) // set bit to 1
#define CLRBIT(port,bit) ((port) &= ~(1 << (bit))) // set bit to 0 (clear bit)
#define SETORCLRBIT(port,bit,val) if (val) { SETBIT(port,bit); } else { CLRBIT(port,bit); } // if true, set bit to 1, if false, clear bit to 0
#define LSB(n) (n & 255)
#define MSB(n) ((n >> 8) & 255)
// prototype boards from july to december 2023 have a different pinout (blue, forward facing molex)
//#define IDC_FLIP_REV
#if defined(IDC_FLIP_REV)
// Modify these arrays to edit the pin out.
// Map these according to your button pins.
#define MUX4067_P1_UPLEFT 7
#define MUX4067_P1_UPRIGHT 6
#define MUX4067_P1_CENTER 5
#define MUX4067_P1_DOWNLEFT 4
#define MUX4067_P1_DOWNRIGHT 3
#define MUX4067_P2_UPLEFT 20
#define MUX4067_P2_UPRIGHT 19
#define MUX4067_P2_CENTER 18
#define MUX4067_P2_DOWNLEFT 17
#define MUX4067_P2_DOWNRIGHT 16
#define MUX4067_P1_COIN 10
#define MUX4067_P2_COIN 29
#define MUX4067_TEST 9
#define MUX4067_SERVICE 14
#define MUX4067_CLEAR 15
#define MUX4067_JAMMA_Q 11
#define MUX4067_JAMMA_17 28
#define MUX4067_JAMMA_W 2
#define MUX4067_JAMMA_X 1
#define MUX4067_JAMMA_Y 0
#define MUX4067_JAMMA_Z 8
// Map these according to your LED pins.
#define LATCH_P1L_UPLEFT 2
#define LATCH_P1L_UPRIGHT 3
#define LATCH_P1L_CENTER 4
#define LATCH_P1L_DOWNLEFT 5
#define LATCH_P1L_DOWNRIGHT 6
#define LATCH_P2L_UPLEFT 18
#define LATCH_P2L_UPRIGHT 19
#define LATCH_P2L_CENTER 20
#define LATCH_P2L_DOWNLEFT 21
#define LATCH_P2L_DOWNRIGHT 22
#define LATCH_P1_S0 0
#define LATCH_P1_S1 1
#define LATCH_P2_S0 16
#define LATCH_P2_S1 17
#define LATCH_CABL_MARQ1 25
#define LATCH_CABL_MARQ2 23
#define LATCH_CABL_MARQ3 24
#define LATCH_CABL_MARQ4 26
#define LATCH_CABL_NEON 10
#define LATCH_COIN_COUNTER 28
#define LATCH_ALWAYS_ON 27
#define LATCH_JAMMA_LED 14
#else
// Modify these arrays to edit the pin out.
// Map these according to your button pins.
#define MUX4067_P1_UPLEFT 23
#define MUX4067_P1_UPRIGHT 22
#define MUX4067_P1_CENTER 21
#define MUX4067_P1_DOWNLEFT 20
#define MUX4067_P1_DOWNRIGHT 19
#define MUX4067_P2_UPLEFT 4
#define MUX4067_P2_UPRIGHT 3
#define MUX4067_P2_CENTER 2
#define MUX4067_P2_DOWNLEFT 1
#define MUX4067_P2_DOWNRIGHT 0
#define MUX4067_P1_COIN 29
#define MUX4067_P2_COIN 10
#define MUX4067_TEST 30
#define MUX4067_SERVICE 25
#define MUX4067_CLEAR 24
#define MUX4067_JAMMA_Q 28
#define MUX4067_JAMMA_17 11
#define MUX4067_JAMMA_W 18
#define MUX4067_JAMMA_X 17
#define MUX4067_JAMMA_Y 16
#define MUX4067_JAMMA_Z 31
// Map these according to your LED pins.
#define LATCH_P1L_UPLEFT 29
#define LATCH_P1L_UPRIGHT 28
#define LATCH_P1L_CENTER 27
#define LATCH_P1L_DOWNLEFT 26
#define LATCH_P1L_DOWNRIGHT 25
#define LATCH_P2L_UPLEFT 13
#define LATCH_P2L_UPRIGHT 12
#define LATCH_P2L_CENTER 11
#define LATCH_P2L_DOWNLEFT 10
#define LATCH_P2L_DOWNRIGHT 9
#define LATCH_P1_S0 31
#define LATCH_P1_S1 30
#define LATCH_P2_S0 15
#define LATCH_P2_S1 14
#define LATCH_CABL_MARQ1 6
#define LATCH_CABL_MARQ2 8
#define LATCH_CABL_MARQ3 7
#define LATCH_CABL_MARQ4 5
#define LATCH_CABL_NEON 21
#define LATCH_COIN_COUNTER 3
#define LATCH_ALWAYS_ON 4
#define LATCH_JAMMA_LED 20
#endif
// other pins
#define MUX_ENABLE_PIN 21
#define MUX1_IN_PIN 26
#define MUX2_IN_PIN 27
#define MUX_S0_PIN 22
#define MUX_S1_PIN 23
#define MUX_S2_PIN 24
#define MUX_S3_PIN 25
#define LATCH_ENABLE_PIN 20
#define LATCH_RST_PIN 19
#define LATCH_RCLK_PIN 18
#define SOFTWARE_SPI_DIN_PIN 9
#define SOFTWARE_SPI_CLK_PIN 8
#define UART_TX_PIN 16
#define UART_RX_PIN 17
#define UART_SHDN_PIN 14
#define UART_RE_PIN 15
#define BENCHMARK_PIN_1 4
#define BENCHMARK_PIN_2 5
#define BENCHMARK_PIN_3 6
#define BENCHMARK_PIN_4 7
// other defines
// offset from XIP_BASE, let's make it 1MiB from the start
#define INPUT_MODE_OFFSET (1024 * 1024)
// turn LED on for 200ms every 400ms
#define SERVICE_BLINK_LENGTH 200
#define SERVICE_BLINK_INTERVAL 400
// UART defines
#define UART_HOST true
#define UART_HOST_ID '0'
#define UART_DEVICE_ID '1'
// HID defines
// in lane order: zqsec 17593
#define KEYCODE_P1_UPLEFT KEY_Q
#define KEYCODE_P1_UPRIGHT KEY_E
#define KEYCODE_P1_CENTER KEY_S
#define KEYCODE_P1_DOWNLEFT KEY_Z
#define KEYCODE_P1_DOWNRIGHT KEY_C
#define KEYCODE_P2_UPLEFT KEY_KP7
#define KEYCODE_P2_UPRIGHT KEY_KP9
#define KEYCODE_P2_CENTER KEY_KP5
#define KEYCODE_P2_DOWNLEFT KEY_KP1
#define KEYCODE_P2_DOWNRIGHT KEY_KP3
// F5, F6
#define KEYCODE_P1_COIN KEY_F5
#define KEYCODE_P2_COIN KEY_F6
// F2, F9, F1
#define KEYCODE_TEST KEY_F2
#define KEYCODE_SERVICE KEY_F9
#define KEYCODE_CLEAR KEY_F1
#endif //_PIUIO_CONFIG_H