-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathcircle_8bitdo_keyboard_patch.diff
More file actions
200 lines (193 loc) · 6.06 KB
/
Copy pathcircle_8bitdo_keyboard_patch.diff
File metadata and controls
200 lines (193 loc) · 6.06 KB
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
diff --git a/include/circle/usb/usbkeyboard.h b/include/circle/usb/usbkeyboard.h
index 373b0d26..3c26d61d 100644
--- a/include/circle/usb/usbkeyboard.h
+++ b/include/circle/usb/usbkeyboard.h
@@ -62,9 +62,13 @@ public:
// works in cooked and raw mode
boolean SetLEDs (u8 ucStatus); // must not be called in interrupt context
-private:
+
+protected:
+ boolean ConfigureKeyboard (unsigned nReportSize);
void ReportHandler (const u8 *pReport, unsigned nReportSize);
+
+private:
static boolean FindByte (const u8 *pBuffer, u8 ucByte, unsigned nLength);
private:
diff --git a/include/circle/usb/usbkeyboard8bitdo.h b/include/circle/usb/usbkeyboard8bitdo.h
new file mode 100644
index 00000000..4cc7a8f6
--- /dev/null
+++ b/include/circle/usb/usbkeyboard8bitdo.h
@@ -0,0 +1,22 @@
+//
+// usbkeyboard8bitdo.h
+//
+
+#ifndef _circle_usb_usbkeyboard8bitdo_h
+#define _circle_usb_usbkeyboard8bitdo_h
+
+#include <circle/usb/usbkeyboard.h>
+
+class CUSBKeyboard8BitDoDevice : public CUSBKeyboardDevice
+{
+public:
+ CUSBKeyboard8BitDoDevice (CUSBFunction *pFunction);
+ ~CUSBKeyboard8BitDoDevice (void);
+
+ boolean Configure (void);
+
+protected:
+ void ReportHandler (const u8 *pReport, unsigned nReportSize);
+};
+
+#endif
\ No newline at end of file
diff --git a/lib/usb/Makefile b/lib/usb/Makefile
index 14471753..e3e2e8d4 100644
--- a/lib/usb/Makefile
+++ b/lib/usb/Makefile
@@ -28,7 +28,7 @@ OBJS = lan7800.o smsc951x.o usbbluetooth.o usbcdcethernet.o usbfloppydevice.o \
usbconfigparser.o usbdevice.o usbdevicefactory.o usbendpoint.o usbfunction.o \
usbgamepad.o usbgamepadps3.o usbgamepadps4.o usbgamepadstandard.o usbgamepadswitchpro.o \
usbgamepadxbox360.o usbgamepadxboxone.o usbhiddevice.o usbhostcontroller.o \
- usbkeyboard.o usbmassdevice.o usbmidi.o usbmidihost.o usbmouse.o usbprinter.o usbrequest.o \
+ usbkeyboard.o usbkeyboard8bitdo.o usbmassdevice.o usbmidi.o usbmidihost.o usbmouse.o usbprinter.o usbrequest.o \
usbstandardhub.o usbstring.o usbserial.o usbserialhost.o usbserialch341.o usbserialcp210x.o \
usbserialpl2303.o usbserialft231x.o usbserialcdc.o usbtouchscreen.o dwhciregister.o
diff --git a/lib/usb/usbdevicefactory.cpp b/lib/usb/usbdevicefactory.cpp
index 75210581..fefd0f34 100644
--- a/lib/usb/usbdevicefactory.cpp
+++ b/lib/usb/usbdevicefactory.cpp
@@ -30,6 +30,7 @@
#include <circle/usb/usbmassdevice.h>
#include <circle/usb/usbfloppydevice.h>
#include <circle/usb/usbkeyboard.h>
+#include <circle/usb/usbkeyboard8bitdo.h>
#include <circle/usb/usbmouse.h>
#include <circle/usb/usbgamepadstandard.h>
#include <circle/usb/usbgamepadps3.h>
@@ -91,7 +92,12 @@ CUSBFunction *CUSBDeviceFactory::GetDevice (CUSBFunction *pParent, CString *pNam
CString *pVendor = pParent->GetDevice ()->GetName (DeviceNameVendor);
assert (pVendor != 0);
- if (pVendor->Compare ("ven3f0-1198") != 0) // HP USB 1000dpi Laser Mouse
+ if ( pVendor->Compare ("ven2dc8-5200") == 0
+ || pVendor->Compare ("ven2dc8-5201") == 0) // 8bitDo Retro Keyboard
+ {
+ pResult = new CUSBKeyboard8BitDoDevice (pParent);
+ }
+ else if (pVendor->Compare ("ven3f0-1198") != 0) // HP USB 1000dpi Laser Mouse
{
pResult = new CUSBKeyboardDevice (pParent);
}
@@ -102,7 +108,16 @@ CUSBFunction *CUSBDeviceFactory::GetDevice (CUSBFunction *pParent, CString *pNam
#ifndef EXCLUDE_USB_MOUSE
else if (pName->Compare ("int3-1-2") == 0)
{
- pResult = new CUSBMouseDevice (pParent);
+ CString *pVendor = pParent->GetDevice ()->GetName (DeviceNameVendor);
+ assert (pVendor != 0);
+
+ if ( pVendor->Compare ("ven2dc8-5200") != 0
+ && pVendor->Compare ("ven2dc8-5201") != 0) // 8bitDo Retro Keyboard
+ {
+ pResult = new CUSBMouseDevice (pParent);
+ }
+
+ delete pVendor;
}
#endif
else if ( pName->Compare ("int3-0-0") == 0
diff --git a/lib/usb/usbkeyboard.cpp b/lib/usb/usbkeyboard.cpp
index 05fe2fab..b5adf198 100644
--- a/lib/usb/usbkeyboard.cpp
+++ b/lib/usb/usbkeyboard.cpp
@@ -67,7 +67,12 @@ boolean CUSBKeyboardDevice::Configure (void)
m_nReportSize++;
}
- if (!CUSBHIDDevice::ConfigureHID (m_nReportSize))
+ return ConfigureKeyboard (m_nReportSize);
+}
+
+boolean CUSBKeyboardDevice::ConfigureKeyboard (unsigned nReportSize)
+{
+ if (!CUSBHIDDevice::ConfigureHID (nReportSize))
{
CLogger::Get ()->Write (FromUSBKbd, LogError, "Cannot configure HID device");
diff --git a/lib/usb/usbkeyboard8bitdo.cpp b/lib/usb/usbkeyboard8bitdo.cpp
new file mode 100644
index 00000000..0c67c0e3
--- /dev/null
+++ b/lib/usb/usbkeyboard8bitdo.cpp
@@ -0,0 +1,70 @@
+//
+// usbkeyboard8bitdo.cpp
+//
+
+#include <circle/usb/usbkeyboard8bitdo.h>
+
+#define USBKEYB8BITDO_REPORT_SIZE 17
+
+static const char FromUSBKbd8BitDo[] = "ukbd8bitdo";
+
+CUSBKeyboard8BitDoDevice::CUSBKeyboard8BitDoDevice (CUSBFunction *pFunction)
+: CUSBKeyboardDevice (pFunction)
+{
+}
+
+CUSBKeyboard8BitDoDevice::~CUSBKeyboard8BitDoDevice (void)
+{
+}
+
+boolean CUSBKeyboard8BitDoDevice::Configure (void)
+{
+ return ConfigureKeyboard (USBKEYB8BITDO_REPORT_SIZE);
+}
+
+void CUSBKeyboard8BitDoDevice::ReportHandler (const u8 *pReport, unsigned nReportSize)
+{
+ // Forward HID transfer failures to the common keyboard driver.
+ if (pReport == 0)
+ {
+ CUSBKeyboardDevice::ReportHandler (0, 0);
+
+ return;
+ }
+
+ // Convert the 8BitDo NKRO bitmap report to a boot keyboard report.
+ if ( nReportSize == USBKEYB8BITDO_REPORT_SIZE
+ && (pReport[0] == 0x0A || pReport[0] == 0x0C))
+ {
+ u8 Report[USBKEYB_REPORT_SIZE] = {pReport[1]};
+ unsigned nSlots = 0;
+
+ for (unsigned nUsage = 0x04; nUsage <= 0x77 && nSlots < 6; nUsage++)
+ {
+ if (pReport[2 + nUsage / 8] & (1U << (nUsage % 8)))
+ {
+ Report[2 + nSlots++] = nUsage;
+ }
+ }
+
+ CUSBKeyboardDevice::ReportHandler (Report, sizeof Report);
+
+ return;
+ }
+
+ // Strip the report ID from a standard boot keyboard report.
+ if (nReportSize == 9 && pReport[0] == 0x01)
+ {
+ CUSBKeyboardDevice::ReportHandler (pReport + 1, USBKEYB_REPORT_SIZE);
+
+ return;
+ }
+
+ // Forward an unprefixed standard boot keyboard report.
+ if (nReportSize == USBKEYB_REPORT_SIZE)
+ {
+ CUSBKeyboardDevice::ReportHandler (pReport, nReportSize);
+
+ return;
+ }
+}
\ No newline at end of file