pico hid: better ps2x2pico integration (#149) (#151)

Co-authored-by: No0ne <github@exa.solar>
This commit is contained in:
Maxim Devaev
2023-09-28 02:19:07 +03:00
committed by GitHub
parent cfc556f412
commit b606cd60d2
7 changed files with 74 additions and 386 deletions

View File

@@ -37,6 +37,12 @@ u8 ph_g_ps2_kbd_leds = 0;
bool ph_g_ps2_kbd_online = 0;
bool ph_g_ps2_mouse_online = 0;
u8 ph_ps2_kbd_modifiers = 0;
u8 ph_ps2_mouse_buttons = 0;
void tuh_kb_set_leds(u8 leds) {
ph_g_ps2_kbd_leds = leds;
}
void ph_ps2_init(void) {
if (PH_O_HAS_PS2) {
@@ -51,13 +57,13 @@ void ph_ps2_init(void) {
}
if (PH_O_IS_KBD_PS2) {
ph_ps2_kbd_init(_KBD_DATA_PIN);
kb_init(_KBD_DATA_PIN);
} else {
INIT_STUB(_KBD_DATA_PIN);
}
if (PH_O_IS_MOUSE_PS2) {
ph_ps2_mouse_init(_MOUSE_DATA_PIN);
ms_init(_MOUSE_DATA_PIN);
} else {
INIT_STUB(_MOUSE_DATA_PIN);
}
@@ -67,16 +73,66 @@ void ph_ps2_init(void) {
void ph_ps2_task(void) {
if (PH_O_IS_KBD_PS2) {
ph_ps2_kbd_task();
ph_g_ps2_kbd_online = kb_task();
}
if (PH_O_IS_MOUSE_PS2) {
ph_ps2_mouse_task();
ph_g_ps2_mouse_online = ms_task();
}
}
void ph_ps2_kbd_send_key(u8 key, bool state) {
if (PH_O_IS_KBD_PS2) {
if (key >= 0xe0 && key <= 0xe7) {
if (state) {
ph_ps2_kbd_modifiers = ph_ps2_kbd_modifiers | (1 << (key - 0xe0));
} else {
ph_ps2_kbd_modifiers = ph_ps2_kbd_modifiers & ~(1 << (key - 0xe0));
}
}
kb_send_key(key, state, ph_ps2_kbd_modifiers);
}
}
void ph_ps2_mouse_send_button(u8 button, bool state) {
if (PH_O_IS_MOUSE_PS2) {
button--;
if (state) {
ph_ps2_mouse_buttons = ph_ps2_mouse_buttons | (1 << button);
} else {
ph_ps2_mouse_buttons = ph_ps2_mouse_buttons & ~(1 << button);
}
ms_send_packet(ph_ps2_mouse_buttons, 0, 0, 0, 0);
}
}
void ph_ps2_mouse_send_rel(s8 x, s8 y) {
if (PH_O_IS_MOUSE_PS2) {
ms_send_packet(ph_ps2_mouse_buttons, x, y, 0, 0);
}
}
void ph_ps2_mouse_send_wheel(s8 h, s8 v) {
if (PH_O_IS_MOUSE_PS2) {
ms_send_packet(ph_ps2_mouse_buttons, 0, 0, h, v);
}
}
void ph_ps2_send_clear(void) {
// TODO: PS2: Release all pressed buttons and keys.
// If PH_O_IS_KBD_PS2, release all PS/2 buttons
// also if PH_O_IS_MOUSE_PS2 is true, release all mouse buttons
if (PH_O_IS_KBD_PS2) {
for(u8 key = 0xe0; key <= 0xe7; key++) {
kb_send_key(key, false, 0);
}
for(u8 key = 4; key <= 116; key++) {
kb_send_key(key, false, 0);
}
}
if (PH_O_IS_MOUSE_PS2) {
ms_send_packet(0, 0, 0, 0, 0);
}
}