Skip to content

Commit 82653d3

Browse files
authored
Merge pull request #33 from rabbitholecomputing/feature/mouse-wheel-and-foreign-keyboards
Mouse wheel and foreign keyboards
2 parents 7c371f9 + 579181e commit 82653d3

File tree

18 files changed

+731
-161
lines changed

18 files changed

+731
-161
lines changed
1.37 KB
Binary file not shown.

src/firmware/include/quokkadb_tusb_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
#define CFG_TUH_HUB 7
7979
// max device support (excluding hub device)
8080
#define CFG_TUH_DEVICE_MAX 14 // hub typically has 4 ports
81-
#define CFG_TUH_HID 4 // typical keyboard + mouse device can have 3-4 HID interfaces
81+
#define CFG_TUH_HID 8 // typical keyboard + mouse device can have 3-4 HID interfaces
8282
#define CFG_TUH_MSC 0
8383

8484
#define CFG_TUH_HID_EPIN_BUFSIZE 64

src/firmware/lib/QuokkADB/include/flashsettings.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@
3232
struct __attribute((packed)) QuokkADBSettings
3333
{
3434
uint16_t magic_number;
35-
uint8_t led_on: 1;
36-
uint8_t swap_modifiers: 1;
37-
uint8_t reserved_bits: 6;
38-
uint8_t sensitivity_divisor;
39-
uint8_t reserved_bytes[252];
35+
uint8_t led_on: 1;
36+
uint8_t swap_modifiers: 1;
37+
uint8_t swap_mouse_wheel_axis: 1;
38+
uint8_t ctrl_lmb: 1;
39+
uint8_t reserved_bits: 4;
40+
uint8_t sensitivity_divisor;
41+
uint8_t region;
42+
int8_t mouse_wheel_count;
43+
uint8_t reserved_bytes[250];
4044
};
4145

4246
class FlashSettings

src/firmware/lib/QuokkADB/include/platform_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#pragma once
2626

2727
// Use macros for version number
28-
#define FW_VER_NUM "1.1.0"
28+
#define FW_VER_NUM "2.0.0"
2929
#define FW_VER_SUFFIX "release"
3030
#define PLATFORM_FW_VERSION FW_VER_NUM "-" FW_VER_SUFFIX
3131
#define PRODUCT_NAME "QuokkADB"

src/firmware/lib/QuokkADB/include/platformkbdparser.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <stdint.h>
3535
#include "tusb.h"
3636
#include "scqueue.h"
37+
#include <regions.h>
3738

3839
using simple_circular_queue::SCQueue;
3940

@@ -163,7 +164,8 @@ class PlatformKbdParser {
163164
virtual void OnKeyUp(uint8_t mod __attribute__((unused)), uint8_t key __attribute__((unused))) = 0;
164165
virtual void OnControlKeysChanged(uint8_t before __attribute__((unused)), uint8_t after __attribute__((unused))) = 0;
165166

166-
167+
virtual Region getRegion(){return region;}
168+
virtual void setRegion(Region rgn){region = rgn;}
167169
protected:
168170
SCQueue<KeyEvent*, KEYBOARD_QUEUE_CAPACITY> m_keyboard_events;
169171

@@ -209,4 +211,6 @@ class PlatformKbdParser {
209211
const uint8_t *getPadKeys() {
210212
return padKeys;
211213
};
214+
215+
Region region;
212216
};

src/firmware/lib/QuokkADB/include/platformmouseparser.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ using simple_circular_queue::SCQueue;
4141
// Queue length if using a machine USB clicker 160
4242
// Queue length for humans ~ 5
4343
// Using 10
44-
#define MOUSE_CLICK_QUEUE_CAPACITY (10)
44+
#define MOUSE_CLICK_QUEUE_CAPACITY (256)
4545

4646
//----------------------------------------------------------------------------
4747
// Mouse handler
@@ -57,6 +57,7 @@ struct MOUSEINFO {
5757
};
5858
int8_t dX;
5959
int8_t dY;
60+
int8_t dWheel;
6061
};
6162

6263
struct MOUSE_CLICK
@@ -67,11 +68,7 @@ struct MOUSE_CLICK
6768
uint8_t bmMiddleButton : 1;
6869
uint8_t bmDummy : 5;
6970
};
70-
};
71-
72-
enum class MouseRightBtnMode {
73-
ctrl_click,
74-
right_click
71+
int8_t dWheel;
7572
};
7673

7774
class PlatformMouseParser {
@@ -119,5 +116,4 @@ class PlatformMouseParser {
119116
int32_t m_x = 0;
120117
int32_t m_y = 0;
121118

122-
MouseRightBtnMode m_right_btn_mode = MouseRightBtnMode::ctrl_click;
123119
};

src/firmware/lib/QuokkADB/src/flashsettings.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ void FlashSettings::reset()
7070
_settings.led_on = 1;
7171
_settings.swap_modifiers = 0;
7272
_settings.sensitivity_divisor = DEFAULT_MOUSE_SENSITIVITY_DIVISOR;
73+
_settings.ctrl_lmb = 1;
74+
_settings.region = 0;
75+
_settings.swap_mouse_wheel_axis = 0;
76+
_settings.mouse_wheel_count = 1;
7377
}
7478

7579
void FlashSettings::write_settings_page(uint8_t *buf)

src/firmware/lib/QuokkADB/src/platformkbdparser.cpp

Lines changed: 182 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ uint8_t inline findModifierKey(hid_keyboard_report_t const *report, const hid_ke
5050
PlatformKbdParser::PlatformKbdParser()
5151
{
5252
kbdLockingKeys.bLeds = 0;
53+
region = RegionUS;
5354
}
5455
PlatformKbdParser::~PlatformKbdParser()
5556
{
@@ -168,16 +169,56 @@ void PlatformKbdParser::SetUSBkeyboardLEDs(bool capslock, bool numlock, bool scr
168169
usb_set_leds = true;
169170
}
170171

172+
173+
static const char ON_STRING[] = "On";
174+
static const char OFF_STRING[] = "Off";
175+
static const char REGION_US_STRING[] = "USA";
176+
static const char REGION_FR_STRING[] = "Belgium/France";
177+
static const char REGION_DE_STRING[] = "German";
178+
static const char REGION_CH_STRING[] = "Swiss-DE/FR";
179+
static const char REGION_DK_STRING[] = "Denmark";
180+
static const char REGION_UK_STRING[] = "Ireland/UK";
181+
static const char REGION_IT_QZ_STRING[] = "Italy-QZERTY";
182+
static const char REGION_IT_QW_STRING[] = "Italy-QWERTY";
183+
184+
static void region_selection_string(char* print_buf, size_t len, Region region)
185+
{
186+
snprintf(print_buf, len,
187+
"Regions:\n"
188+
" %c %s\n"
189+
" %c %s\n"
190+
" %c %s\n"
191+
" %c %s\n"
192+
" %c %s\n"
193+
" %c %s\n"
194+
" %c %s\n"
195+
" %c %s\n",
196+
region == RegionUS ? '*' : '-', REGION_US_STRING,
197+
region == RegionFR ? '*' : '-', REGION_FR_STRING,
198+
region == RegionDE ? '*' : '-', REGION_DE_STRING,
199+
region == RegionCH ? '*' : '-', REGION_CH_STRING,
200+
region == RegionDK ? '*' : '-', REGION_DK_STRING,
201+
region == RegionUK ? '*' : '-', REGION_UK_STRING,
202+
region == RegionITqz ? '*' : '-', REGION_IT_QZ_STRING,
203+
region == RegionITqw ? '*' : '-', REGION_IT_QW_STRING
204+
205+
);
206+
}
207+
171208
bool PlatformKbdParser::SpecialKeyCombo(KBDINFO *cur_kbd_info)
172209
{
173210
// Special keycombo actions
174-
const char ON_STRING[] = "On";
175-
const char OFF_STRING[] = "Off";
176211
uint8_t special_key_count = 0;
177212
uint8_t special_key = 0;
178-
uint8_t special_keys[] = {USB_KEY_V, USB_KEY_K, USB_KEY_L, USB_KEY_P, USB_KEY_EQUAL, USB_KEY_MINUS, USB_KEY_KPPLUS, USB_KEY_KPMINUS, USB_KEY_S, USB_KEY_R};
213+
uint8_t special_keys[] = {USB_KEY_V, USB_KEY_P, USB_KEY_H, USB_KEY_G, USB_KEY_S, USB_KEY_R, USB_KEY_T,
214+
USB_KEY_K, USB_KEY_L, USB_KEY_KPPLUS, USB_KEY_EQUAL, USB_KEY_SLASH, USB_KEY_1, USB_KEY_RIGHTBRACE,
215+
USB_KEY_KPMINUS, USB_KEY_MINUS, USB_KEY_C, USB_KEY_D, USB_KEY_U,
216+
};
179217
uint8_t caps_lock_down = false;
180-
char print_buf[1024];
218+
int16_t region_num;
219+
char print_buf[1536];
220+
221+
181222
for (uint8_t i = 0; i < 6; i++)
182223
{
183224
if (cur_kbd_info->Keys[i] == USB_KEY_CAPSLOCK)
@@ -205,71 +246,174 @@ bool PlatformKbdParser::SpecialKeyCombo(KBDINFO *cur_kbd_info)
205246

206247

207248
if (special_key_count == 1 && (enter_shortcut1 || enter_shortcut2))
208-
209249
{
210-
switch (special_key)
211-
{
212-
case USB_KEY_V:
250+
251+
if (special_key == USB_KEY_V)
213252
SendString(PLATFORM_FW_VER_STRING);
214-
break;
215-
case USB_KEY_P:
253+
else if (special_key == USB_KEY_P)
254+
{
216255
snprintf(print_buf, sizeof(print_buf),
217256
"Current Settings\n"
218257
"================\n"
219258
"Command <-> Option key swap: %s\n"
259+
"Layout: %s\n"
220260
"LED: %s\n"
221261
"Mouse Sensitivity Divisor: %u\n"
222262
"(higher = less sensitive)\n"
263+
"Right Mouse Button: %s\n"
264+
"Mouse wheel count: %d\n"
265+
"Flip mouse wheel axis: %s\n"
223266
"\n"
224-
"Special Keys = CAPS + Ctrl + Shift + [Key]\n"
225-
"Alternate Keys = Ctrl + Cmd + Option + [Key]\n"
267+
"Special Keys = CAPS + Ctrl + Shift + (Key)\n"
268+
"Alternate Keys = Ctrl + Cmd + Option + (Key)\n"
226269
"------------------------------------------\n"
227-
"[V]: print firmware version\n"
228-
"[S]: save settings to flash - LED blinks %d times\n"
229-
"[R]: remove settings from flash - LED blinks %d times\n"
230-
"[K]: swap option and command key positions\n"
231-
"[L]: toggle status LED On/Off\n"
232-
"[+]: increase sensitivity\n"
233-
"[-]: decrease sensitivity\n",
270+
"(V): print firmware version\n"
271+
"(P): print current settings (this message)\n"
272+
"(H): select next region layout\n"
273+
"(G): select previous region layout\n"
274+
"(S): save settings to flash - LED blinks %d times\n"
275+
"(R): remove settings from flash - LED blinks %d times\n"
276+
"(K): swap option and command key positions - LED blinks thrice\n"
277+
"(L): toggle status LED On/Off\n"
278+
"(+): increase sensitivity - LED blinks twice\n"
279+
"(-): decrease sensitivity - LED blink once\n"
280+
"(T): swap right mouse button (RMB) function between Ctrl + LMB and ADB RMB\n"
281+
"Blinks twice for Ctrl + LMB and blinks once for ADB RMB\n"
282+
"Note: In MacOS 8 and 9 you will want Ctrl + LMB - ADB RMB might work in NeXTSTEP\n"
283+
"\n"
284+
"Change mouse wheel count 'x' by one with 'C' or 'D'\n"
285+
"If positive press the up/down arrow 'x' times for each wheel movement\n"
286+
"If negative divide the mouse wheel movement by 'abs(x)'\n"
287+
"(D): increase the mouse wheel count - LED blinks twice\n"
288+
"(C): decrease the mouse wheel count - LED blink once\n"
289+
"(U): flip mouse wheel axis - LED blinks thrice\n"
290+
"Note: not all mice support the mouse wheel in HID boot protocol\n"
291+
,
234292
setting_storage.settings()->swap_modifiers ? ON_STRING : OFF_STRING,
293+
region == RegionFR ? REGION_FR_STRING :
294+
region == RegionDE ? REGION_DE_STRING :
295+
region == RegionCH ? REGION_CH_STRING :
296+
region == RegionDK ? REGION_DK_STRING :
297+
region == RegionUK ? REGION_UK_STRING :
298+
region == RegionITqz ? REGION_IT_QZ_STRING :
299+
region == RegionITqw ? REGION_IT_QW_STRING :
300+
REGION_US_STRING,
235301
setting_storage.settings()->led_on ? ON_STRING : OFF_STRING,
236302
setting_storage.settings()->sensitivity_divisor,
303+
setting_storage.settings()->ctrl_lmb ? "Ctrl+LBM" : "ADB RMB",
304+
setting_storage.settings()->mouse_wheel_count,
305+
setting_storage.settings()->swap_mouse_wheel_axis ? ON_STRING : OFF_STRING,
237306
SAVE_TO_FLASH_BLINK_COUNT,
238307
CLEAR_FLASH_BLINK_COUNT);
239308
SendString(print_buf);
240-
break;
241-
case USB_KEY_S:
309+
}
310+
else if (special_key == USB_KEY_S)
311+
{
242312
setting_storage.save();
243313
blink_led.blink(SAVE_TO_FLASH_BLINK_COUNT);
244-
break;
245-
case USB_KEY_R:
314+
}
315+
else if (special_key == USB_KEY_R)
316+
{
246317
setting_storage.clear();
247318
blink_led.blink(CLEAR_FLASH_BLINK_COUNT);
248-
break;
249-
case USB_KEY_K:
319+
}
320+
else if (special_key == USB_KEY_K)
321+
{
250322
setting_storage.settings()->swap_modifiers ^= 1;
251-
break;
252-
case USB_KEY_L:
323+
blink_led.blink(3);
324+
}
325+
else if (special_key == USB_KEY_L)
253326
setting_storage.settings()->led_on ^= 1;
254-
break;
255-
case USB_KEY_KPPLUS:
256-
case USB_KEY_EQUAL:
327+
else if ( ((region == RegionUS || region == RegionUK)
328+
&& (special_key == USB_KEY_KPPLUS || special_key == USB_KEY_EQUAL))
329+
|| (region == RegionFR && (special_key == USB_KEY_KPPLUS || special_key == USB_KEY_SLASH))
330+
|| (region == RegionDE && (special_key == USB_KEY_KPPLUS || special_key == USB_KEY_RIGHTBRACE))
331+
|| (region == RegionCH && (special_key == USB_KEY_KPPLUS || special_key == USB_KEY_1))
332+
|| (region == RegionDK && (special_key == USB_KEY_KPPLUS || special_key == USB_KEY_MINUS))
333+
)
334+
{
257335
if (setting_storage.settings()->sensitivity_divisor <= 1)
258336
setting_storage.settings()->sensitivity_divisor = 1;
259337
else
260338
setting_storage.settings()->sensitivity_divisor--;
261-
blink_led.blink(setting_storage.settings()->sensitivity_divisor);
262-
break;
263-
case USB_KEY_KPMINUS:
264-
case USB_KEY_MINUS:
339+
blink_led.blink(2);
340+
}
341+
else if ( ((region == RegionUS || region == RegionUK)
342+
&& (special_key == USB_KEY_KPMINUS || special_key == USB_KEY_MINUS))
343+
|| (region == RegionFR && (special_key == USB_KEY_KPMINUS || special_key == USB_KEY_EQUAL))
344+
|| ((region == RegionDE || region == RegionCH || region == RegionDK)
345+
&& (special_key == USB_KEY_KPMINUS || special_key == USB_KEY_SLASH))
346+
)
347+
{
265348
if (setting_storage.settings()->sensitivity_divisor >= 16)
266349
setting_storage.settings()->sensitivity_divisor = 16;
267350
else
268351
setting_storage.settings()->sensitivity_divisor++;
269-
blink_led.blink(setting_storage.settings()->sensitivity_divisor);
270-
break;
352+
blink_led.blink(1);
271353
}
272-
354+
else if (special_key == USB_KEY_H)
355+
{
356+
region_num = setting_storage.settings()->region;
357+
region_num++;
358+
if (region_num > LAST_REGION)
359+
region_num = 0;
360+
361+
setting_storage.settings()->region = region_num;
362+
region = (Region) region_num;
363+
region_selection_string(print_buf, sizeof(print_buf), region);
364+
SendString(print_buf);
365+
}
366+
else if (special_key == USB_KEY_G)
367+
{
368+
region_num = setting_storage.settings()->region;
369+
region_num--;
370+
if (region_num < 0)
371+
region_num = LAST_REGION;
372+
373+
setting_storage.settings()->region = region_num;
374+
region = (Region) region_num;
375+
region_selection_string(print_buf, sizeof(print_buf), region);
376+
SendString(print_buf);
377+
}
378+
else if (special_key == USB_KEY_T)
379+
{
380+
setting_storage.settings()->ctrl_lmb ^= 1;
381+
if (setting_storage.settings()->ctrl_lmb == 1)
382+
blink_led.blink(2);
383+
else
384+
blink_led.blink(1);
385+
}
386+
else if (special_key == USB_KEY_C)
387+
{
388+
if (setting_storage.settings()->mouse_wheel_count <= -8)
389+
{
390+
setting_storage.settings()->mouse_wheel_count = -8;
391+
}
392+
else
393+
{
394+
setting_storage.settings()->mouse_wheel_count--;
395+
blink_led.blink(1);
396+
}
397+
}
398+
else if (special_key == USB_KEY_D)
399+
{
400+
if (setting_storage.settings()->mouse_wheel_count >= 10)
401+
{
402+
setting_storage.settings()->mouse_wheel_count = 10;
403+
}
404+
else
405+
{
406+
setting_storage.settings()->mouse_wheel_count++;
407+
blink_led.blink(2);
408+
}
409+
}
410+
else if (special_key == USB_KEY_U)
411+
{
412+
setting_storage.settings()->swap_mouse_wheel_axis ^= 1;
413+
blink_led.blink(3);
414+
}
415+
else
416+
return false;
273417
return true;
274418
}
275419
return false;
@@ -311,7 +455,7 @@ void PlatformKbdParser::SendString(const char *message)
311455
while (PendingKeyboardEvent())
312456
;
313457

314-
key = char_to_usb_keycode(message[i++]);
458+
key = char_to_usb_keycode(message[i++], region);
315459

316460
if (key.shift_down)
317461
{

0 commit comments

Comments
 (0)