From 9470468ede4bbe212e0aad42a8256d76b5297763 Mon Sep 17 00:00:00 2001 From: somepin <79652090+somepin@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:35:08 -0500 Subject: [PATCH] Add Libra Mini joystick remapping (#334) * Enable remapping Libra Mini joystick as keys * Move config to default keycap so make passes --- keyboards/libra_mini/config.h | 15 +- keyboards/libra_mini/keymaps/default/config.h | 6 + keyboards/libra_mini/keymaps/vial/config.h | 9 - keyboards/libra_mini/keymaps/vial/keymap.c | 56 +++- keyboards/libra_mini/keymaps/vial/rules.mk | 7 +- keyboards/libra_mini/keymaps/vial/vial.json | 269 +++++------------- keyboards/libra_mini/rules.mk | 3 + 7 files changed, 148 insertions(+), 217 deletions(-) diff --git a/keyboards/libra_mini/config.h b/keyboards/libra_mini/config.h index ae0fde6298..01070228f7 100644 --- a/keyboards/libra_mini/config.h +++ b/keyboards/libra_mini/config.h @@ -4,21 +4,18 @@ /* Matrix config */ -#define MATRIX_ROWS 4 +#define MATRIX_ROWS 5 #define MATRIX_COLS 12 -#define MATRIX_ROW_PINS { E6, B4, B5, B2 } +#define MATRIX_ROW_PINS { E6, B4, B5, B2, NO_PIN } #define MATRIX_COL_PINS { B3, B1, F7, F6, F5, F4, C6, D4, D0, D1, D2, D3 } #define DIODE_DIRECTION ROW2COL -/* Joystick config */ - -#define ANALOG_JOYSTICK_Y_AXIS_PIN B6 -#define ANALOG_JOYSTICK_X_AXIS_PIN D7 - -#define POINTING_DEVICE_INVERT_X -#define POINTING_DEVICE_INVERT_Y +// Max 32 +#define JOYSTICK_BUTTON_COUNT 0 +// Max 6: X, Y, Z, Rx, Ry, Rz +#define JOYSTICK_AXES_COUNT 2 /* Use 1000hz polling */ #define USB_POLLING_INTERVAL_MS 1 diff --git a/keyboards/libra_mini/keymaps/default/config.h b/keyboards/libra_mini/keymaps/default/config.h index cf26ca1058..a99404b0e9 100644 --- a/keyboards/libra_mini/keymaps/default/config.h +++ b/keyboards/libra_mini/keymaps/default/config.h @@ -8,5 +8,11 @@ #define ANALOG_JOYSTICK_SPEED_MAX 5 #define ANALOG_JOYSTICK_SPEED_REGULATOR 10 +#define ANALOG_JOYSTICK_Y_AXIS_PIN B6 +#define ANALOG_JOYSTICK_X_AXIS_PIN D7 + +#define POINTING_DEVICE_INVERT_X +#define POINTING_DEVICE_INVERT_Y + /* Mouse inertia (keeps sliding after a flick) */ // #define POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE diff --git a/keyboards/libra_mini/keymaps/vial/config.h b/keyboards/libra_mini/keymaps/vial/config.h index feaf11dfef..449e44b22e 100644 --- a/keyboards/libra_mini/keymaps/vial/config.h +++ b/keyboards/libra_mini/keymaps/vial/config.h @@ -5,12 +5,3 @@ #define VIAL_KEYBOARD_UID {0xEA, 0xE3, 0x29, 0x4F, 0x79, 0xFF, 0x86, 0xC6} #define VIAL_UNLOCK_COMBO_ROWS {0, 1} #define VIAL_UNLOCK_COMBO_COLS {0, 11} - -/* Mouse control configuration */ - -/* Cursor speed */ -#define ANALOG_JOYSTICK_SPEED_MAX 5 -#define ANALOG_JOYSTICK_SPEED_REGULATOR 10 - -/* Mouse inertia (keeps sliding after a flick) */ -// #define POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE diff --git a/keyboards/libra_mini/keymaps/vial/keymap.c b/keyboards/libra_mini/keymaps/vial/keymap.c index 4bb8715ab3..307e198500 100644 --- a/keyboards/libra_mini/keymaps/vial/keymap.c +++ b/keyboards/libra_mini/keymaps/vial/keymap.c @@ -1,9 +1,14 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ +#include QMK_KEYBOARD_H +#include "joystick.h" +#include "analog.h" + #define KC_LSQB S(KC_LBRC) // Left square bracket #define KC_RSQB S(KC_RBRC) // Right square bracket -#include QMK_KEYBOARD_H +static int actuation = 256; // actuation point for arrows (0-511) +bool arrows[4]; const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { @@ -36,3 +41,52 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { ), }; + +void matrix_scan_user(void) { + // Up + if (!arrows[0] && analogReadPin(B6) - 512 > actuation) { + arrows[0] = true; + uint16_t keycode = dynamic_keymap_get_keycode(biton32(layer_state), 4,3); + register_code16(keycode); + } else if (arrows[0] && analogReadPin(B6) - 512 < actuation) { + arrows[0] = false; + uint16_t keycode = dynamic_keymap_get_keycode(biton32(layer_state), 4,3); + unregister_code16(keycode); + } + // Down + if (!arrows[1] && analogReadPin(B6) - 512 < -actuation) { + arrows[1] = true; + uint16_t keycode = dynamic_keymap_get_keycode(biton32(layer_state), 4,4); + register_code16(keycode); + } else if (arrows[1] && analogReadPin(B6) - 512 > -actuation) { + arrows[1] = false; + uint16_t keycode = dynamic_keymap_get_keycode(biton32(layer_state), 4,4); + unregister_code16(keycode); + } + // Left + if (!arrows[2] && analogReadPin(D7) - 512 > actuation) { + arrows[2] = true; + uint16_t keycode = dynamic_keymap_get_keycode(biton32(layer_state), 4,6); + register_code16(keycode); + } else if (arrows[2] && analogReadPin(D7) - 512 < actuation) { + arrows[2] = false; + uint16_t keycode = dynamic_keymap_get_keycode(biton32(layer_state), 4,6); + unregister_code16(keycode); + } + // Right + if (!arrows[3] && analogReadPin(D7) - 512 < -actuation) { + arrows[3] = true; + uint16_t keycode = dynamic_keymap_get_keycode(biton32(layer_state), 4,7); + register_code16(keycode); + } else if (arrows[3] && analogReadPin(D7) - 512 > -actuation) { + arrows[3] = false; + uint16_t keycode = dynamic_keymap_get_keycode(biton32(layer_state), 4,7); + unregister_code16(keycode); + } +} + +// Joystick config +joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = { + [0] = JOYSTICK_AXIS_VIRTUAL, + [1] = JOYSTICK_AXIS_VIRTUAL +}; diff --git a/keyboards/libra_mini/keymaps/vial/rules.mk b/keyboards/libra_mini/keymaps/vial/rules.mk index 41e811c2dd..4852be61c5 100644 --- a/keyboards/libra_mini/keymaps/vial/rules.mk +++ b/keyboards/libra_mini/keymaps/vial/rules.mk @@ -1,8 +1,3 @@ VIA_ENABLE = yes VIAL_ENABLE = yes -LTO_ENABLE = yes - -# Enable joystick as mouse - -POINTING_DEVICE_ENABLE = yes -POINTING_DEVICE_DRIVER = analog_joystick \ No newline at end of file +LTO_ENABLE = yes \ No newline at end of file diff --git a/keyboards/libra_mini/keymaps/vial/vial.json b/keyboards/libra_mini/keymaps/vial/vial.json index fce249a11d..5924ca92e2 100644 --- a/keyboards/libra_mini/keymaps/vial/vial.json +++ b/keyboards/libra_mini/keymaps/vial/vial.json @@ -4,7 +4,7 @@ "productId": "0x4C24", "lighting": "none", "matrix": { - "rows": 4, + "rows": 5, "cols": 12 }, "layouts": { @@ -13,197 +13,82 @@ "Joystick" ], "keymap": [ - [ - { - "x": 12.5 - }, - "0,11\n\n\n0,1", - "3,11\n\n\n0,1" - ], - [ - { - "y": 0.25, - "x": 0.25 - }, - "0,0", - "0,1", - { - "x": 9.25 - }, - "0,10", - { - "w": 2 - }, - "0,11\n\n\n0,0" - ], - [ - { - "x": 0.125, - "w": 1.25 - }, - "1,0", - "1,1", - { - "x": 9.5 - }, - "1,10", - { - "w": 1.75 - }, - "1,11" - ], - [ - { - "w": 1.75 - }, - "2,0", - "2,1", - { - "x": 8.75 - }, - "2,10", - "2,11", - { - "w": 1.25 - }, - "3,10" - ], - [ - { - "y": 1.25, - "x": 12.625 - }, - "3,8\n\n\n1,1", - "3,9\n\n\n1,1" - ], - [ - { - "ry": 4.5, - "y": -0.25, - "x": 0.125, - "w": 1.25 - }, - "3,0", - { - "w": 1.25 - }, - "3,1", - { - "x": 9.5, - "w": 1.25 - }, - "3,8\n\n\n1,0", - { - "w": 1.25 - }, - "3,9\n\n\n1,0" - ], - [ - { - "r": 8, - "rx": 3, - "ry": 2.25, - "y": -1, - "x": -0.75 - }, - "0,2", - "0,3", - "0,4", - "0,5" - ], - [ - { - "ry": 3.25, - "y": -1, - "x": -0.625 - }, - "1,2", - "1,3", - "1,4", - "1,5" - ], - [ - { - "ry": 4.25, - "y": -1, - "x": -0.25 - }, - "2,2", - "2,3", - "2,4", - "2,5" - ], - [ - { - "x": 1.75, - "w": 2 - }, - "3,4" - ], - [ - { - "ry": 5.25, - "y": -1, - "x": 0.375, - "w": 1.25 - }, - "3,3" - ], - [ - { - "r": -8, - "rx": 11.5, - "ry": 2.25, - "y": -1, - "x": -4 - }, - "0,6", - "0,7", - "0,8", - "0,9" - ], - [ - { - "ry": 3.25, - "y": -1, - "x": -3.625 - }, - "1,6", - "1,7", - "1,8", - "1,9" - ], - [ - { - "ry": 4.25, - "y": -1, - "x": -4 - }, - "2,6", - "2,7", - "2,8", - "2,9" - ], - [ - { - "ry": 5.25, - "y": -1, - "x": -3.875, - "w": 2.25 - }, - "3,6", - { - "w": 1.25 - }, - "3,7\n\n\n1,0" - ], - [ - { - "y": 0.25, - "x": -1.625 - }, - "3,7\n\n\n1,1" - ] + [{ "x": 12.5 }, "0,11\n\n\n0,1", "3,11\n\n\n0,1"], + [ + { "y": 0.25, "x": 0.25 }, + "0,0", + "0,1", + { "x": 9.25 }, + "0,10", + { "w": 2 }, + "0,11\n\n\n0,0" + ], + [ + { "x": 0.125, "w": 1.25 }, + "1,0", + "1,1", + { "x": 9.5 }, + "1,10", + { "w": 1.75 }, + "1,11" + ], + [ + { "w": 1.75 }, + "2,0", + "2,1", + { "x": 8.75 }, + "2,10", + "2,11", + { "w": 1.25 }, + "3,10" + ], + [{ "y": 1.25, "x": 12.625 }, "3,8\n\n\n1,1", "3,9\n\n\n1,1"], + [{ "y": -0.9, "x": 11.6, "w": 0.5, "h": 0.5 }, "4,3\n\n\n1,1"], + [ + { "y": -0.5, "x": 11.1, "w": 0.5, "h": 0.5 }, + "4,6\n\n\n1,1", + { "w": 0.5, "h": 0.5 }, + "4,4\n\n\n1,1", + { "w": 0.5, "h": 0.5 }, + "4,7\n\n\n1,1" + ], + [ + { "ry": 4.5, "y": -0.25, "x": 0.125, "w": 1.25 }, + "3,0", + { "w": 1.25 }, + "3,1", + { "x": 9.5, "w": 1.25 }, + "3,8\n\n\n1,0", + { "w": 1.25 }, + "3,9\n\n\n1,0" + ], + [ + { "r": 8, "rx": 3, "ry": 2.25, "y": -1, "x": -0.75 }, + "0,2", + "0,3", + "0,4", + "0,5" + ], + [{ "ry": 3.25, "y": -1, "x": -0.625 }, "1,2", "1,3", "1,4", "1,5"], + [{ "ry": 4.25, "y": -1, "x": -0.25 }, "2,2", "2,3", "2,4", "2,5"], + [{ "x": 1.75, "w": 2 }, "3,4"], + [{ "ry": 5.25, "y": -1, "x": 0.375, "w": 1.25 }, "3,3"], + [ + { "r": -8, "rx": 11.5, "ry": 2.25, "y": -1, "x": -4 }, + "0,6", + "0,7", + "0,8", + "0,9" + ], + [{ "ry": 3.25, "y": -1, "x": -3.625 }, "1,6", "1,7", "1,8", "1,9"], + [{ "ry": 4.25, "y": -1, "x": -4 }, "2,6", "2,7", "2,8", "2,9"], + [ + { "ry": 5.25, "y": -1, "x": -3.875, "w": 2.25 }, + "3,6", + { "w": 1.25 }, + "3,7\n\n\n1,0" + ], + [{ "y": 0.25, "x": -1.625 }, "3,7\n\n\n1,1"] ] } } \ No newline at end of file diff --git a/keyboards/libra_mini/rules.mk b/keyboards/libra_mini/rules.mk index 69e2e6cc46..9319d1d83f 100644 --- a/keyboards/libra_mini/rules.mk +++ b/keyboards/libra_mini/rules.mk @@ -1,2 +1,5 @@ +JOYSTICK_ENABLE = yes +JOYSTICK_DRIVER = analog +BOOTMAGIC_ENABLE = yes # Add analog functionality to the source tree SRC += analog.c