diff options
author | Maxim Devaev <[email protected]> | 2023-08-08 14:00:28 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2023-08-08 14:00:28 +0300 |
commit | 895ec1cb737a655a9b8ccdc6b6a911a9bfdd8e74 (patch) | |
tree | d7817a0f2880f4740839ec843ef4c28f3f3ad44f /hid | |
parent | cd599060a0febeaa8a0a96e222a1602c64924268 (diff) |
pico hid: ps/2 stubs
Diffstat (limited to 'hid')
-rw-r--r-- | hid/pico/CMakeLists.txt | 1 | ||||
-rw-r--r-- | hid/pico/Makefile | 25 | ||||
-rw-r--r-- | hid/pico/src/CMakeLists.txt | 3 | ||||
-rw-r--r-- | hid/pico/src/main.c | 3 | ||||
-rw-r--r-- | hid/pico/src/ph_cmds.c | 66 | ||||
-rw-r--r-- | hid/pico/src/ph_outputs.h | 2 | ||||
-rw-r--r-- | hid/pico/src/ph_ps2.c | 94 | ||||
-rw-r--r-- | hid/pico/src/ph_ps2.h | 42 |
8 files changed, 202 insertions, 34 deletions
diff --git a/hid/pico/CMakeLists.txt b/hid/pico/CMakeLists.txt index bd771016..edf93cec 100644 --- a/hid/pico/CMakeLists.txt +++ b/hid/pico/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.13) set(PICO_SDK_PATH ${CMAKE_CURRENT_LIST_DIR}/.pico-sdk) set(PICO_TINYUSB_PATH ${CMAKE_CURRENT_LIST_DIR}/.tinyusb) +# TODO: PS2: set(PS2_PATH ${CMAKE_CURRENT_LIST_DIR}/.yourlib/subdir) # For TinyUSB set(FAMILY rp2040) diff --git a/hid/pico/Makefile b/hid/pico/Makefile index 409f8067..714c8e9d 100644 --- a/hid/pico/Makefile +++ b/hid/pico/Makefile @@ -18,19 +18,16 @@ clean-all: clean rm -rf .pico-sdk.tmp .pico-sdk .tinyusb.tmp .tinyusb +define libdep + rm -rf .$(1).tmp + git clone https://github.com/$(2) .$(1).tmp + cd .$(1).tmp \ + && git checkout $(3) \ + && (test ! -f .gitmodules || git submodule update --init) + mv .$(1).tmp .$(1) +endef .pico-sdk: - rm -rf .pico-sdk.tmp - git clone https://github.com/raspberrypi/pico-sdk .pico-sdk.tmp - cd .pico-sdk.tmp \ - && git checkout 62201a83e2693ea165fdc7669b4ab2f3b4f43c36 \ - && git submodule update --init - mv .pico-sdk.tmp .pico-sdk - - + $(call libdep,pico-sdk,raspberrypi/pico-sdk,62201a83e2693ea165fdc7669b4ab2f3b4f43c36) .tinyusb: - rm -rf .tinyusb.tmp - git clone https://github.com/hathach/tinyusb .tinyusb.tmp - cd .tinyusb.tmp \ - && git checkout c998e9c60bc76894006c3bd049d661124a9bfbfd \ - && git submodule update --init - mv .tinyusb.tmp .tinyusb + $(call libdep,tinyusb,hathach/tinyusb,c998e9c60bc76894006c3bd049d661124a9bfbfd) +# TODO: PS2: Add your library here and add it to "all" and "clean-all" targets diff --git a/hid/pico/src/CMakeLists.txt b/hid/pico/src/CMakeLists.txt index f8ca0b8c..62cf440a 100644 --- a/hid/pico/src/CMakeLists.txt +++ b/hid/pico/src/CMakeLists.txt @@ -7,10 +7,12 @@ target_sources(${target_name} PRIVATE ph_usb.c ph_usb_kbd.c ph_usb_mouse.c + ph_ps2.c ph_cmds.c ph_spi.c ph_uart.c ph_debug.c + # TODO: PS2: ${PS2_PATH}/foo.c ) target_link_options(${target_name} PRIVATE -Xlinker --print-memory-usage) target_compile_options(${target_name} PRIVATE -Wall -Wextra) @@ -22,5 +24,6 @@ target_link_libraries(${target_name} PRIVATE hardware_spi hardware_watchdog tinyusb_device + # TODO: PS2: ... or make a library ) pico_add_extra_outputs(${target_name}) diff --git a/hid/pico/src/main.c b/hid/pico/src/main.c index 8b551a97..7f58e876 100644 --- a/hid/pico/src/main.c +++ b/hid/pico/src/main.c @@ -28,6 +28,7 @@ #include "ph_tools.h" #include "ph_outputs.h" #include "ph_usb.h" +#include "ph_ps2.h" #include "ph_spi.h" #include "ph_uart.h" #include "ph_proto.h" @@ -124,6 +125,7 @@ int main(void) { //ph_debug_uart_init(); ph_outputs_init(); ph_usb_init(); + ph_ps2_init(); gpio_init(_COMM_PIN); gpio_set_dir(_COMM_PIN, GPIO_IN); @@ -134,6 +136,7 @@ int main(void) { while (true) { ph_usb_task(); + ph_ps2_task(); if (!_reset_required) { _COMM(task); //ph_debug_act_pulse(100); diff --git a/hid/pico/src/ph_cmds.c b/hid/pico/src/ph_cmds.c index 11359638..8b2994b4 100644 --- a/hid/pico/src/ph_cmds.c +++ b/hid/pico/src/ph_cmds.c @@ -28,31 +28,38 @@ #include "ph_outputs.h" #include "ph_usb.h" #include "ph_usb_keymap.h" +#include "ph_ps2.h" u8 ph_cmd_kbd_get_leds(void) { - u8 retval = 0; + u8 leds = 0; if (PH_O_IS_KBD_USB) { -# define GET(x_mod) ((ph_g_usb_kbd_leds & KEYBOARD_LED_##x_mod##LOCK) ? PH_PROTO_PONG_##x_mod : 0) - retval = GET(CAPS) | GET(SCROLL) | GET(NUM); -# undef GET + leds = ph_g_usb_kbd_leds; + } else if (PH_O_IS_KBD_PS2) { + leds = ph_g_ps2_kbd_leds; } - return retval; +# define GET(x_mod) ((leds & KEYBOARD_LED_##x_mod##LOCK) ? PH_PROTO_PONG_##x_mod : 0) + return (GET(CAPS) | GET(SCROLL) | GET(NUM)); +# undef GET } u8 ph_cmd_get_offlines(void) { - u8 retval = 0; + bool kbd_online = true; if (PH_O_IS_KBD_USB) { - if (!ph_g_usb_kbd_online) { - retval |= PH_PROTO_PONG_KBD_OFFLINE; - } + kbd_online = ph_g_usb_kbd_online; + } else if (PH_O_IS_KBD_PS2) { + kbd_online = ph_g_ps2_kbd_online; } + bool mouse_online = true; if (PH_O_IS_MOUSE_USB) { - if (!ph_g_usb_mouse_online) { - retval |= PH_PROTO_PONG_MOUSE_OFFLINE; - } + mouse_online = ph_g_usb_mouse_online; + } else if (PH_O_IS_MOUSE_PS2) { + mouse_online = ph_g_ps2_mouse_online; } - return retval; + return ( + (kbd_online ? 0 : PH_PROTO_PONG_KBD_OFFLINE) + | (mouse_online ? 0 : PH_PROTO_PONG_MOUSE_OFFLINE) + ); } void ph_cmd_set_kbd(const u8 *args) { // 1 byte @@ -66,12 +73,17 @@ void ph_cmd_set_mouse(const u8 *args) { // 1 byte void ph_cmd_send_clear(const u8 *args) { // 0 bytes (void)args; ph_usb_send_clear(); + ph_ps2_send_clear(); } void ph_cmd_kbd_send_key(const u8 *args) { // 2 bytes const u8 key = ph_usb_keymap(args[0]); if (key > 0) { - ph_usb_kbd_send_key(key, args[1]); + if (PH_O_IS_KBD_USB) { + ph_usb_kbd_send_key(key, args[1]); + } else if (PH_O_IS_KBD_PS2) { + ph_ps2_kbd_send_key(key, args[1]); + } } } @@ -79,7 +91,11 @@ void ph_cmd_mouse_send_button(const u8 *args) { // 2 bytes # define HANDLE(x_byte_n, x_button) { \ if (args[x_byte_n] & PH_PROTO_CMD_MOUSE_##x_button##_SELECT) { \ const bool m_state = !!(args[x_byte_n] & PH_PROTO_CMD_MOUSE_##x_button##_STATE); \ - ph_usb_mouse_send_button(MOUSE_BUTTON_##x_button, m_state); \ + if (PH_O_IS_MOUSE_USB) { \ + ph_usb_mouse_send_button(MOUSE_BUTTON_##x_button, m_state); \ + } else if (PH_O_IS_MOUSE_PS2) { \ + ph_ps2_mouse_send_button(MOUSE_BUTTON_##x_button, m_state); \ + } \ } \ } HANDLE(0, LEFT); @@ -91,15 +107,25 @@ void ph_cmd_mouse_send_button(const u8 *args) { // 2 bytes } void ph_cmd_mouse_send_abs(const u8 *args) { // 4 bytes - ph_usb_mouse_send_abs( - ph_merge8_s16(args[0], args[1]), - ph_merge8_s16(args[2], args[3])); + if (PH_O_IS_MOUSE_USB_ABS) { + const s16 x = ph_merge8_s16(args[0], args[1]); + const s16 y = ph_merge8_s16(args[2], args[3]); + ph_usb_mouse_send_abs(x, y); + } } void ph_cmd_mouse_send_rel(const u8 *args) { // 2 bytes - ph_usb_mouse_send_rel(args[0], args[1]); + if (PH_O_IS_MOUSE_USB_REL) { + ph_usb_mouse_send_rel(args[0], args[1]); + } else if (PH_O_IS_MOUSE_PS2) { + ph_ps2_mouse_send_rel(args[0], args[1]); + } } void ph_cmd_mouse_send_wheel(const u8 *args) { // 2 bytes - ph_usb_mouse_send_wheel(args[0], args[1]); + if (PH_O_IS_MOUSE_USB) { + ph_usb_mouse_send_wheel(args[0], args[1]); + } else if (PH_O_IS_MOUSE_PS2) { + ph_ps2_mouse_send_wheel(args[0], args[1]); + } } diff --git a/hid/pico/src/ph_outputs.h b/hid/pico/src/ph_outputs.h index 1f8e3f40..13f1bbda 100644 --- a/hid/pico/src/ph_outputs.h +++ b/hid/pico/src/ph_outputs.h @@ -32,6 +32,8 @@ #define PH_O_IS_MOUSE_USB (PH_O_MOUSE(USB_ABS) || PH_O_MOUSE(USB_REL) || PH_O_MOUSE(USB_W98)) #define PH_O_IS_MOUSE_USB_ABS (PH_O_MOUSE(USB_ABS) || PH_O_MOUSE(USB_W98)) #define PH_O_IS_MOUSE_USB_REL PH_O_MOUSE(USB_REL) +#define PH_O_IS_KBD_PS2 PH_O_KBD(PS2) +#define PH_O_IS_MOUSE_PS2 PH_O_MOUSE(PS2) extern u8 ph_g_outputs_active; diff --git a/hid/pico/src/ph_ps2.c b/hid/pico/src/ph_ps2.c new file mode 100644 index 00000000..03fbe9b7 --- /dev/null +++ b/hid/pico/src/ph_ps2.c @@ -0,0 +1,94 @@ +/* ========================================================================= # +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2023 Maxim Devaev <[email protected]> # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <https://www.gnu.org/licenses/>. # +# # +# ========================================================================= */ + + +#include "ph_ps2.h" + +#include "ph_types.h" +#include "ph_outputs.h" + + +u8 ph_g_ps2_kbd_leds; +bool ph_g_ps2_kbd_online; +bool ph_g_ps2_mouse_online; + + +void ph_ps2_init(void) { + // TODO: PS2: Initialize PS/2 stuff here IF you have at least one PS/2 device, check ph_usb.c for the example + // Use macro PH_O_IS_KBD_PS2 and PH_O_IS_MOUSE_PS2 + if (PH_O_IS_KBD_PS2 || PH_O_IS_MOUSE_PS2) { + // ... + } +} + +void ph_ps2_task(void) { + // TODO: PS2: Perform periodic stuff here IF you have at least one PS/2 device, check ph_usb.c + if (PH_O_IS_KBD_PS2 || PH_O_IS_MOUSE_PS2) { + // ... + } + // Here you should update some values: + // - ph_g_ps2_kbd_leds - keyboard LEDs mask like on USB + // - ph_g_ps2_kbd_online - if keyboard online (by clock?) + // - ph_g_ps2_mouse_online if mouse online (by clock?) + // It is important not to have ANY sleep() call inside it. + // There should also be no freezes if the keyboard or mouse is not available. +} + +void ph_ps2_kbd_send_key(u8 key, bool state) { + // TODO: PS2: Send keyboard key + // @key - is a USB keycode, modifier keys has range 0xE0...0xE7, check ph_usb_kbd_send_key() + // @state - true if pressed, false if released + // The function should take care not to send duplicate events (if needed for PS/2) + // If the PS2 keyboard is not used (PH_O_IS_KBD_PS2 is false), the function should do nothing. + (void)key; // Remove this + (void)state; // Remove this +} + +void ph_ps2_mouse_send_button(u8 button, bool state) { + // TODO: PS2: Send mouse button + // @button - USB button code + // @state - true if pressed, false if released + // The function should take care not to send duplicate events (if needed for PS/2) + // If the PS2 keyboard is not used (PH_O_IS_MOUSE_PS2 is false), the function should do nothing. + (void)button; // Remove this + (void)state; // Remove this +} + +void ph_ps2_mouse_send_rel(s8 x, s8 y) { + // TODO: PS2: Send relative move event + // If the PS2 keyboard is not used (PH_O_IS_MOUSE_PS2 is false), the function should do nothing. + (void)x; // Remove this + (void)y; // Remove this +} + +void ph_ps2_mouse_send_wheel(s8 h, s8 v) { + (void)h; + // TODO: PS2: Send wheel. As I understand, PS/2 has no horizontal scrolling, so @h just can be ignored. + // @v - vertical scrolling like on USB + // If the PS2 keyboard is not used (PH_O_IS_MOUSE_PS2 is false), the function should do nothing. + (void)v; // Remove this +} + +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 +} diff --git a/hid/pico/src/ph_ps2.h b/hid/pico/src/ph_ps2.h new file mode 100644 index 00000000..057299f3 --- /dev/null +++ b/hid/pico/src/ph_ps2.h @@ -0,0 +1,42 @@ +/* ========================================================================= # +# # +# KVMD - The main PiKVM daemon. # +# # +# Copyright (C) 2018-2023 Maxim Devaev <[email protected]> # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <https://www.gnu.org/licenses/>. # +# # +# ========================================================================= */ + + +#pragma once + +#include "ph_types.h" + + +extern u8 ph_g_ps2_kbd_leds; +extern bool ph_g_ps2_kbd_online; +extern bool ph_g_ps2_mouse_online; + + +void ph_ps2_init(void); +void ph_ps2_task(void); + +void ph_ps2_kbd_send_key(u8 key, bool state); + +void ph_ps2_mouse_send_button(u8 button, bool state); +void ph_ps2_mouse_send_rel(s8 x, s8 y); +void ph_ps2_mouse_send_wheel(s8 h, s8 v); + +void ph_ps2_send_clear(void); |