From 0237ff0c62d4278df3c0c93f5f85f84c1a0ed519 Mon Sep 17 00:00:00 2001 From: Marek Kraus Date: Wed, 31 Aug 2022 09:16:07 +0200 Subject: [PATCH] [Core] Rework PS/2 driver selection (#17892) * [Core] Rework PS/2 driver selection Enabling and selecting PS/2 driver was using old approach, so it was reworked to current approach, inspired by Serial and WS2812 driver selections. * [Keyboard] Update keyboards using PS/2 to use new PS/2 driver selection * [Docs] Update PS/2 documentation to use new PS/2 driver selection * Fix indentation * [Core] Add PS2 to data driver * Fix oversight in property name Co-authored-by: Drashna Jaelre * Add PS/2 pins to data driven mappings Co-authored-by: Drashna Jaelre --- builddefs/common_features.mk | 34 ++++++++----------- builddefs/show_options.mk | 2 ++ data/mappings/info_config.json | 2 ++ data/mappings/info_rules.json | 3 ++ data/schemas/keyboard.jsonschema | 14 ++++++++ docs/feature_ps2_mouse.md | 18 ++++++---- docs/ja/feature_ps2_mouse.md | 16 +++++---- keyboards/buzzard/rev1/config.h | 2 +- keyboards/buzzard/rev1/rules.mk | 3 +- keyboards/converter/ibm_terminal/config.h | 6 ++-- .../ibm_terminal/keymaps/default/rules.mk | 3 +- .../ibm_terminal/keymaps/priyadi/rules.mk | 7 ++-- keyboards/converter/ibm_terminal/rules.mk | 3 +- .../evyd13/gh80_3700/keymaps/ps2/config.h | 4 +-- .../evyd13/gh80_3700/keymaps/ps2/rules.mk | 3 +- .../handwired/108key_trackpoint/config.h | 2 +- .../handwired/108key_trackpoint/rules.mk | 3 +- keyboards/handwired/promethium/config.h | 6 ++-- .../promethium/keymaps/default/rules.mk | 3 +- .../promethium/keymaps/priyadi/rules.mk | 3 +- keyboards/handwired/promethium/rules.mk | 3 +- keyboards/handwired/trackpoint/config.h | 2 +- keyboards/handwired/trackpoint/rules.mk | 3 +- keyboards/kapcave/paladin64/config.h | 4 +-- keyboards/pierce/keymaps/durken1/config.h | 2 +- keyboards/pierce/post_rules.mk | 3 +- 26 files changed, 93 insertions(+), 61 deletions(-) diff --git a/builddefs/common_features.mk b/builddefs/common_features.mk index a23b5e82b9..9fa9e18814 100644 --- a/builddefs/common_features.mk +++ b/builddefs/common_features.mk @@ -805,31 +805,25 @@ ifeq ($(strip $(PS2_MOUSE_ENABLE)), yes) OPT_DEFS += -DMOUSE_ENABLE endif -ifeq ($(strip $(PS2_USE_BUSYWAIT)), yes) - PS2_ENABLE := yes - SRC += ps2_busywait.c - SRC += ps2_io.c - OPT_DEFS += -DPS2_USE_BUSYWAIT -endif - -ifeq ($(strip $(PS2_USE_INT)), yes) - PS2_ENABLE := yes - SRC += ps2_interrupt.c - SRC += ps2_io.c - OPT_DEFS += -DPS2_USE_INT -endif - -ifeq ($(strip $(PS2_USE_USART)), yes) - PS2_ENABLE := yes - SRC += ps2_usart.c - SRC += ps2_io.c - OPT_DEFS += -DPS2_USE_USART -endif +VALID_PS2_DRIVER_TYPES := busywait interrupt usart vendor +PS2_DRIVER ?= busywait ifeq ($(strip $(PS2_ENABLE)), yes) + ifeq ($(filter $(PS2_DRIVER),$(VALID_PS2_DRIVER_TYPES)),) + $(call CATASTROPHIC_ERROR,Invalid PS2_DRIVER,PS2_DRIVER="$(PS2_DRIVER)" is not a valid PS/2 driver) + endif + + OPT_DEFS += -DPS2_DRIVER_$(strip $(shell echo $(PS2_DRIVER) | tr '[:lower:]' '[:upper:]')) + COMMON_VPATH += $(DRIVER_PATH)/ps2 COMMON_VPATH += $(PLATFORM_PATH)/$(PLATFORM_KEY)/$(DRIVER_DIR)/ps2 OPT_DEFS += -DPS2_ENABLE + + ifneq ($(strip $(PS2_DRIVER)), vendor) + SRC += ps2_io.c + endif + + SRC += ps2_$(strip $(PS2_DRIVER)).c endif JOYSTICK_ENABLE ?= no diff --git a/builddefs/show_options.mk b/builddefs/show_options.mk index 98537e6da2..8d992c080c 100644 --- a/builddefs/show_options.mk +++ b/builddefs/show_options.mk @@ -66,7 +66,9 @@ OTHER_OPTION_NAMES = \ KEYLOGGER_ENABLE \ LCD_BACKLIGHT_ENABLE \ MACROS_ENABLED \ + PS2_ENABLE \ PS2_MOUSE_ENABLE \ + PS2_DRIVER \ RAW_ENABLE \ SWAP_HANDS_ENABLE \ RING_BUFFERED_6KRO_REPORT_ENABLE \ diff --git a/data/mappings/info_config.json b/data/mappings/info_config.json index d0f67f4e3a..cc13a7cea4 100644 --- a/data/mappings/info_config.json +++ b/data/mappings/info_config.json @@ -52,6 +52,8 @@ "ONESHOT_TAP_TOGGLE": {"info_key": "oneshot.tap_toggle", "value_type": "int"}, "PERMISSIVE_HOLD": {"info_key": "tapping.permissive_hold", "value_type": "bool"}, "PERMISSIVE_HOLD_PER_KEY": {"info_key": "tapping.permissive_hold_per_key", "value_type": "bool"}, + "PS2_CLOCK_PIN": {"info_key": "ps2.clock_pin"}, + "PS2_DATA_PIN": {"info_key": "ps2.data_pin"}, "RETRO_TAPPING": {"info_key": "tapping.retro", "value_type": "bool"}, "RETRO_TAPPING_PER_KEY": {"info_key": "tapping.retro_per_key", "value_type": "bool"}, "RGB_DI_PIN": {"info_key": "rgblight.pin"}, diff --git a/data/mappings/info_rules.json b/data/mappings/info_rules.json index 87a4b795b6..eaeafeda79 100644 --- a/data/mappings/info_rules.json +++ b/data/mappings/info_rules.json @@ -32,6 +32,9 @@ "WAIT_FOR_USB": {"info_key": "usb.wait_for", "value_type": "bool"}, "STENO_ENABLE": {"info_key": "stenography.enabled", "value_type": "bool"}, "STENO_PROTOCOL": {"info_key": "stenography.protocol"}, + "PS2_ENABLE": {"info_key": "ps2.enabled", "value_type": "bool"}, + "PS2_MOUSE_ENABLE": {"info_key": "ps2.mouse_enabled", "value_type": "bool"}, + "PS2_DRIVER": {"info_key": "ps2.driver"}, # Items we want flagged in lint "CTPC": {"info_key": "_deprecated.ctpc", "deprecated": true, "replace_with": "CONVERT_TO=proton_c"}, diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index e425d13dd8..d0375fcdc4 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema @@ -390,6 +390,20 @@ } } }, + "ps2": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": {"type": "boolean"}, + "mouse_enabled": {"type": "boolean"}, + "clock_pin": {"$ref": "qmk.definitions.v1#/mcu_pin"}, + "data_pin": {"$ref": "qmk.definitions.v1#/mcu_pin"}, + "driver": { + "type": "string", + "enum": ["busywait", "interrupt", "usart", "vendor"] + } + } + }, "split": { "type": "object", "additionalProperties": false, diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index c980705ae7..e714d9b867 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -32,13 +32,14 @@ In rules.mk: ```make PS2_MOUSE_ENABLE = yes -PS2_USE_BUSYWAIT = yes +PS2_ENABLE = yes +PS2_DRIVER = busywait ``` In your keyboard config.h: ```c -#ifdef PS2_USE_BUSYWAIT +#ifdef PS2_DRIVER_BUSYWAIT # define PS2_CLOCK_PIN D1 # define PS2_DATA_PIN D2 #endif @@ -52,13 +53,14 @@ In rules.mk: ```make PS2_MOUSE_ENABLE = yes -PS2_USE_INT = yes +PS2_ENABLE = yes +PS2_DRIVER = interrupt ``` In your keyboard config.h: ```c -#ifdef PS2_USE_INT +#ifdef PS2_DRIVER_INTERRUPT #define PS2_CLOCK_PIN D2 #define PS2_DATA_PIN D5 @@ -84,7 +86,8 @@ In rules.mk: ``` PS2_MOUSE_ENABLE = yes -PS2_USE_INT = yes +PS2_ENABLE = yes +PS2_DRIVER = interrupt ``` In your keyboard config.h: @@ -108,13 +111,14 @@ In rules.mk: ```make PS2_MOUSE_ENABLE = yes -PS2_USE_USART = yes +PS2_ENABLE = yes +PS2_DRIVER = usart ``` In your keyboard config.h: ```c -#ifdef PS2_USE_USART +#ifdef PS2_DRIVER_USART #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 diff --git a/docs/ja/feature_ps2_mouse.md b/docs/ja/feature_ps2_mouse.md index 569934c187..2798f61283 100644 --- a/docs/ja/feature_ps2_mouse.md +++ b/docs/ja/feature_ps2_mouse.md @@ -36,13 +36,14 @@ rules.mk で: ```makefile PS2_MOUSE_ENABLE = yes -PS2_USE_BUSYWAIT = yes +PS2_ENABLE = yes +PS2_DRIVER = busywait ``` キーボードの config.h で: ```c -#ifdef PS2_USE_BUSYWAIT +#ifdef PS2_DRIVER_BUSYWAIT # define PS2_CLOCK_PIN D1 # define PS2_DATA_PIN D2 #endif @@ -56,13 +57,14 @@ rules.mk で: ```makefile PS2_MOUSE_ENABLE = yes -PS2_USE_INT = yes +PS2_ENABLE = yes +PS2_DRIVER = interrupt ``` キーボードの config.h で: ```c -#ifdef PS2_USE_INT +#ifdef PS2_DRIVER_INTERRUPT #define PS2_CLOCK_PIN D2 #define PS2_DATA_PIN D5 @@ -88,14 +90,14 @@ rules.mk で: ```makefile PS2_MOUSE_ENABLE = yes -PS2_USE_USART = yes +PS2_ENABLE = yes +PS2_DRIVER = usart ``` キーボードの config.h で: ```c -#ifdef PS2_USE_USART -#ifdef PS2_USE_USART +#ifdef PS2_DRIVER_USART #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 diff --git a/keyboards/buzzard/rev1/config.h b/keyboards/buzzard/rev1/config.h index 66c1a9a42e..67555ba92c 100644 --- a/keyboards/buzzard/rev1/config.h +++ b/keyboards/buzzard/rev1/config.h @@ -35,7 +35,7 @@ #define SPLIT_OLED_ENABLE #endif -#ifdef PS2_USE_INT +#ifdef PS2_DRIVER_INTERRUPT #define PS2_CLOCK_PIN E6 #define PS2_DATA_PIN D7 diff --git a/keyboards/buzzard/rev1/rules.mk b/keyboards/buzzard/rev1/rules.mk index 9a479c64e6..13c63d5b17 100644 --- a/keyboards/buzzard/rev1/rules.mk +++ b/keyboards/buzzard/rev1/rules.mk @@ -1,3 +1,4 @@ OLED_DRIVER = SSD1306 -PS2_USE_INT = yes +PS2_ENABLE = yes +PS2_DRIVER = interrupt diff --git a/keyboards/converter/ibm_terminal/config.h b/keyboards/converter/ibm_terminal/config.h index 9e7d140809..9b44bfa3ea 100644 --- a/keyboards/converter/ibm_terminal/config.h +++ b/keyboards/converter/ibm_terminal/config.h @@ -36,7 +36,7 @@ along with this program. If not, see . /* * PS/2 USART configuration for ATMega32U4 */ -#ifdef PS2_USE_USART +#ifdef PS2_DRIVER_USART /* XCK for clock line */ #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 @@ -77,7 +77,7 @@ along with this program. If not, see . /* * PS/2 Interrupt configuration */ -#ifdef PS2_USE_INT +#ifdef PS2_DRIVER_INTERRUPT /* uses INT1 for clock line(ATMega32U4) */ #define PS2_CLOCK_PIN D1 #define PS2_DATA_PIN D0 @@ -99,7 +99,7 @@ along with this program. If not, see . /* * PS/2 Busywait configuration */ -#ifdef PS2_USE_BUSYWAIT +#ifdef PS2_DRIVER_BUSYWAIT #define PS2_CLOCK_PIN D1 #define PS2_DATA_PIN D0 #endif diff --git a/keyboards/converter/ibm_terminal/keymaps/default/rules.mk b/keyboards/converter/ibm_terminal/keymaps/default/rules.mk index e3cb087a76..10f43dc416 100644 --- a/keyboards/converter/ibm_terminal/keymaps/default/rules.mk +++ b/keyboards/converter/ibm_terminal/keymaps/default/rules.mk @@ -7,4 +7,5 @@ NKRO_ENABLE = yes BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality AUDIO_ENABLE = no # Audio output RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. -PS2_USE_USART = yes +PS2_ENABLE = yes +PS2_DRIVER = usart diff --git a/keyboards/converter/ibm_terminal/keymaps/priyadi/rules.mk b/keyboards/converter/ibm_terminal/keymaps/priyadi/rules.mk index 8c5f3d7034..b18dc2d4d8 100644 --- a/keyboards/converter/ibm_terminal/keymaps/priyadi/rules.mk +++ b/keyboards/converter/ibm_terminal/keymaps/priyadi/rules.mk @@ -1,5 +1,5 @@ # Build Options -# change to "no" to disable the options, or define them in the Makefile in +# change to "no" to disable the options, or define them in the Makefile in # the appropriate keymap folder that will get included automatically # BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite @@ -14,8 +14,9 @@ AUDIO_ENABLE = no # Audio output on port C6 UNICODE_ENABLE = no # Unicode UNICODEMAP_ENABLE = yes BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID -RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. -PS2_USE_USART = yes +RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. +PS2_ENABLE = yes +PS2_DRIVER = usart # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend diff --git a/keyboards/converter/ibm_terminal/rules.mk b/keyboards/converter/ibm_terminal/rules.mk index 277e828269..6304e20fb4 100644 --- a/keyboards/converter/ibm_terminal/rules.mk +++ b/keyboards/converter/ibm_terminal/rules.mk @@ -16,7 +16,8 @@ NKRO_ENABLE = yes # Enable N-Key Rollover BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality AUDIO_ENABLE = no # Audio output RGBLIGHT_ENABLE = no # Enable WS2812 RGB underlight. -PS2_USE_USART = yes +PS2_ENABLE = yes +PS2_DRIVER = usart CUSTOM_MATRIX = yes SRC = matrix.c led.c diff --git a/keyboards/evyd13/gh80_3700/keymaps/ps2/config.h b/keyboards/evyd13/gh80_3700/keymaps/ps2/config.h index b77ac95d7d..5f6d855966 100644 --- a/keyboards/evyd13/gh80_3700/keymaps/ps2/config.h +++ b/keyboards/evyd13/gh80_3700/keymaps/ps2/config.h @@ -16,7 +16,7 @@ #pragma once -#ifdef PS2_USE_USART +#ifdef PS2_DRIVER_USART #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 @@ -51,7 +51,7 @@ #define PS2_USART_ERROR (UCSR1A & ((1<. #define BOOTMAGIC_LITE_COLUMN 6 /* Only required if you add in a trackpoint hardware to the pcb */ -#ifdef PS2_USE_USART +#ifdef PS2_DRIVER_USART #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 @@ -63,7 +63,7 @@ along with this program. If not, see . #define PS2_USART_RX_VECT USART1_RX_vect #endif -#ifdef PS2_USE_INT +#ifdef PS2_DRIVER_INTERRUPT #define PS2_CLOCK_PIN D2 #define PS2_DATA_PIN D5 diff --git a/keyboards/pierce/keymaps/durken1/config.h b/keyboards/pierce/keymaps/durken1/config.h index bc0bb1c4b8..7c9970c5a9 100644 --- a/keyboards/pierce/keymaps/durken1/config.h +++ b/keyboards/pierce/keymaps/durken1/config.h @@ -31,7 +31,7 @@ #define COMBO_COUNT 3 #define COMBO_TERM 35 -#ifdef PS2_USE_USART +#ifdef PS2_DRIVER_USART #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 diff --git a/keyboards/pierce/post_rules.mk b/keyboards/pierce/post_rules.mk index e0360a3391..9cc6739d78 100644 --- a/keyboards/pierce/post_rules.mk +++ b/keyboards/pierce/post_rules.mk @@ -1,6 +1,7 @@ ifeq ($(strip $(TRACKPOINT)), yes) PS2_MOUSE_ENABLE = yes - PS2_USE_USART = yes + PS2_ENABLE = yes + PS2_DRIVER = usart OPT_DEFS += -DUSART endif