aboutsummaryrefslogtreecommitdiff
path: root/keyboards/kyria
diff options
context:
space:
mode:
authorGautham Yerroju <gautham.yerroju@gmail.com>2020-06-13 01:24:13 -0700
committerGitHub <noreply@github.com>2020-06-13 01:24:13 -0700
commit4057d44989e2ee83ca3b171bdb1a29bc9f3ae0cd (patch)
treef74840f3af9af8ed245748fb430e363594a3d8c3 /keyboards/kyria
parent2bfcb6bfc5766ede2b63041af3a163408caa6ad9 (diff)
downloadqmk_firmware-4057d44989e2ee83ca3b171bdb1a29bc9f3ae0cd.tar.gz
qmk_firmware-4057d44989e2ee83ca3b171bdb1a29bc9f3ae0cd.zip
[Keymap] Add Kyria keymap (#9224)
* Add Kyria keymap * clean split hand detection code * rename "joystick" to "thumbstick" * thumbstick overhaul * removed angle correction, seems buggy * save some memory * Remove deprecated config option * Use the correct types for getting host led states * Fix include path * Made .h files for encoder and oled code * Increase speed cap on thumbstick
Diffstat (limited to 'keyboards/kyria')
-rw-r--r--keyboards/kyria/keymaps/gotham/README.md56
-rw-r--r--keyboards/kyria/keymaps/gotham/config.h48
-rw-r--r--keyboards/kyria/keymaps/gotham/encoder_utils.c94
-rw-r--r--keyboards/kyria/keymaps/gotham/encoder_utils.h37
-rw-r--r--keyboards/kyria/keymaps/gotham/keycodes.h16
-rw-r--r--keyboards/kyria/keymaps/gotham/keymap.c126
-rw-r--r--keyboards/kyria/keymaps/gotham/oled_utils.c103
-rw-r--r--keyboards/kyria/keymaps/gotham/oled_utils.h25
-rw-r--r--keyboards/kyria/keymaps/gotham/rules.mk21
-rw-r--r--keyboards/kyria/keymaps/gotham/thumbstick.c195
-rw-r--r--keyboards/kyria/keymaps/gotham/thumbstick.h98
11 files changed, 819 insertions, 0 deletions
diff --git a/keyboards/kyria/keymaps/gotham/README.md b/keyboards/kyria/keymaps/gotham/README.md
new file mode 100644
index 000000000..1598e95a7
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/README.md
@@ -0,0 +1,56 @@
1# Gotham's Keymap for [Kyria](https://github.com/splitkb/kyria)
2
3## Keymap
4This is my personal keymap for Kyria with some mods.
5
6More information about the Kyria keyboard can be found [here](https://blog.splitkb.com/blog/introducing-the-kyria)
7
8### Rotary Encoders
9
10Press the encoder on each half to cycle between:
11- Volume
12- Word Nav (Ctrl + Left / Right)
13- Left / Right
14- Up / Down
15- Page Up / Page Down
16
17### OLEDs
18
19Master-side OLED displays dynamic data:
20- Current layer
21- Current mode of each rotary encoder
22- Current mode of thumbstick
23
24Slave-side OLED currently only displays a static content.
25
26### Thumbstick
27
28A PSP 2000 thumbstick is attached to the right half. It will currently only function when the USB cable is connected to the right half. When I figure out how to transfer data between halves using serial link, I will make this work regardless of which side is the master.
29
30#### Thumbstick Configuration
31
32- __THUMBSTICK_ENABLE:__ Enable thumbstick.
33- __THUMBSTICK_PIN_X/Y (mandatory):__ The QMK pins to use for the respective axis. The values are from the [QMK's ADC driver](https://docs.qmk.fm/#/adc_driver). I used F0 and F1, for example.
34- __THUMBSTICK_FLIP_X/Y:__ Mirror the direction of the respective axis. Use to compensate for actual orientation of thumbstick.
35- __THUMBSTICK_DEBUG:__ Print raw and calculated values from analogReadPin to console. Will only work with CONSOLE_ENABLE turned on.
36
37#### Thumbstick Fine-tuning
38
39More tunables are described here. Values like deadzone threshold are hardware-specific. The theoretical range for analog readings is [0, 1023], but emperical readings don't extend the entire range. To find the right values, turn on CONSOLE_ENABLE in rules.mk and THUMBSTICK_DEBUG in config.h to look at the raw values from the pins using hid_listen (or QMK Toolbox).
40
41- __THUMBSTICK_DEAD_ZONE 90:__ Values below this are ignored (deadzone).
42- __THUMBSTICK_FINE_ZONE 180:__ Values below this enable fine movement.
43
44- __THUMBSTICK_MODE <mode>:__ One of THUMBSTICK_MODE_MOUSE, THUMBSTICK_MODE_ARROWS and THUMBSTICK_MODE_SCROLL. This is just the default mode, it can be changed by calling ```void thumbstick_mode_cycle(bool reverse)``` within code.
45
46- __THUMBSTICK_SPEED 127:__ Cursor speed in THUMBSTICK_MODE_MOUSE.
47- __THUMBSTICK_FINE_SPEED 64:__ Fine cursor speed in THUMBSTICK_MODE_MOUSE (kicks in when slightly nudging the thumbstick).
48- __THUMBSTICK_SCROLL_SPEED 1:__ Scrolling speed in THUMBSTICK_MODE_SCROLL.
49
50- __THUMBSTICK_EIGHT_AXIS true:__ 8-axis toggle for ARROW and SCROLL modes. Disable to fall back to 4 axes (think D-pads vs analog stick).
51- __THUMBSTICK_AXIS_SEPARATION 0.5f:__ Float value between 0 and 1, used to discretize the circular range into distinct zones for 8-axis. Imagine the top-right quadrant on a graph, and picture the diagonal. This value indicates the angular "distance" from the diagonal to either axis. Moving from the diagonal to each of the axes, this value changes from 0 to 1. So, a value of 0.5 will "sweep" from the center to half-way towards each axis, creating a zone across the diagonal. Smaller values make narrower diagonal zones, and vice versa.
52
53#### Thanks
54
55- @pyrho and u/\_GEIST\_ for the inspiration and initial reference code.
56- @zvecr and @drashna for code review and more pointers.
diff --git a/keyboards/kyria/keymaps/gotham/config.h b/keyboards/kyria/keymaps/gotham/config.h
new file mode 100644
index 000000000..1b84d996f
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/config.h
@@ -0,0 +1,48 @@
1/* Copyright 2019 Thomas Baart <thomas@splitkb.com>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#pragma once
18
19#define EE_HANDS
20#define IGNORE_MOD_TAP_INTERRUPT
21
22// Fix for Elite C rev3
23#define SPLIT_USB_DETECT
24// Speed up slave half startup
25#define SPLIT_USB_TIMEOUT 1000
26
27#ifdef OLED_DRIVER_ENABLE
28# define OLED_DISPLAY_128X64
29# define OLED_TIMEOUT 10000
30#endif
31
32#ifdef RGBLIGHT_ENABLE
33# define RGBLIGHT_EFFECT_BREATHING
34# define RGBLIGHT_EFFECT_RAINBOW_MOOD
35# define RGBLIGHT_EFFECT_RAINBOW_SWIRL
36# define RGBLIGHT_EFFECT_KNIGHT
37#endif
38
39#ifdef ENCODER_ENABLE
40# define ENCODER_DIRECTION_FLIP
41# define ENCODER_RESOLUTION 2
42#endif
43
44#ifdef THUMBSTICK_ENABLE
45# define THUMBSTICK_FLIP_X
46# define THUMBSTICK_PIN_X F0
47# define THUMBSTICK_PIN_Y F1
48#endif
diff --git a/keyboards/kyria/keymaps/gotham/encoder_utils.c b/keyboards/kyria/keymaps/gotham/encoder_utils.c
new file mode 100644
index 000000000..1c2962339
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/encoder_utils.c
@@ -0,0 +1,94 @@
1#include "encoder_utils.h"
2
3void encoder_utils_init(void) {
4 encoder_left_mode = ENC_MODE_VOLUME;
5 encoder_right_mode = ENC_MODE_LEFT_RIGHT;
6}
7
8void set_encoder_mode(bool left, encoder_mode_t mode) {
9 if (left) {
10 encoder_left_mode = mode;
11 } else {
12 encoder_right_mode = mode;
13 }
14}
15
16encoder_mode_t get_encoder_mode(bool left) {
17 if (left) {
18 return encoder_left_mode;
19 } else {
20 return encoder_right_mode;
21 }
22}
23
24void cycle_encoder_mode(bool left, bool reverse) {
25 encoder_mode_t mode = get_encoder_mode(left);
26 if (reverse) {
27 mode = (mode == 0) ? (_ENC_MODE_LAST - 1) : (mode - 1);
28 } else {
29 mode = (mode == (_ENC_MODE_LAST - 1)) ? 0 : (mode + 1);
30 }
31 set_encoder_mode(left, mode);
32}
33
34void encoder_action_volume(uint8_t clockwise) {
35 if (clockwise) {
36 tap_code(KC_VOLU);
37 } else {
38 tap_code(KC_VOLD);
39 }
40}
41
42void encoder_action_word_nav(uint8_t clockwise) {
43 if (clockwise) {
44 tap_code16(C(KC_RIGHT));
45 } else {
46 tap_code16(C(KC_LEFT));
47 }
48}
49
50void encoder_action_left_right(uint8_t clockwise) {
51 if (clockwise) {
52 tap_code(KC_RIGHT);
53 } else {
54 tap_code(KC_LEFT);
55 }
56}
57
58void encoder_action_up_down(uint8_t clockwise) {
59 if (clockwise) {
60 tap_code(KC_UP);
61 } else {
62 tap_code(KC_DOWN);
63 }
64}
65
66void encoder_action_paging(uint8_t clockwise) {
67 if (clockwise) {
68 tap_code(KC_PGUP);
69 } else {
70 tap_code(KC_PGDN);
71 }
72}
73
74void encoder_action(encoder_mode_t mode, uint8_t clockwise) {
75 switch (mode) {
76 case ENC_MODE_VOLUME:
77 encoder_action_volume(clockwise);
78 break;
79 case ENC_MODE_WORD_NAV:
80 encoder_action_word_nav(clockwise);
81 break;
82 case ENC_MODE_LEFT_RIGHT:
83 encoder_action_left_right(clockwise);
84 break;
85 case ENC_MODE_UP_DOWN:
86 encoder_action_up_down(clockwise);
87 break;
88 case ENC_MODE_PAGING:
89 encoder_action_paging(clockwise);
90 break;
91 default:
92 encoder_action_volume(clockwise);
93 }
94}
diff --git a/keyboards/kyria/keymaps/gotham/encoder_utils.h b/keyboards/kyria/keymaps/gotham/encoder_utils.h
new file mode 100644
index 000000000..60db6c6bd
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/encoder_utils.h
@@ -0,0 +1,37 @@
1#pragma once
2
3#include <stdbool.h>
4
5#include "quantum.h"
6
7typedef enum {
8 ENC_MODE_VOLUME = 0,
9 ENC_MODE_WORD_NAV,
10 ENC_MODE_LEFT_RIGHT,
11 ENC_MODE_UP_DOWN,
12 ENC_MODE_PAGING,
13 _ENC_MODE_LAST // Do not use, except for looping through enum values
14} encoder_mode_t;
15
16encoder_mode_t encoder_left_mode;
17encoder_mode_t encoder_right_mode;
18
19void encoder_utils_init(void);
20
21void set_encoder_mode(bool left, encoder_mode_t mode);
22
23encoder_mode_t get_encoder_mode(bool left);
24
25void cycle_encoder_mode(bool left, bool reverse);
26
27void encoder_action_volume(uint8_t clockwise);
28
29void encoder_action_word_nav(uint8_t clockwise);
30
31void encoder_action_left_right(uint8_t clockwise);
32
33void encoder_action_up_down(uint8_t clockwise);
34
35void encoder_action_paging(uint8_t clockwise);
36
37void encoder_action(encoder_mode_t mode, uint8_t clockwise);
diff --git a/keyboards/kyria/keymaps/gotham/keycodes.h b/keyboards/kyria/keymaps/gotham/keycodes.h
new file mode 100644
index 000000000..0730d4925
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/keycodes.h
@@ -0,0 +1,16 @@
1#pragma once
2
3#include "quantum.h"
4
5enum layers { _QWERTY = 0, _LOWER, _RAISE, _ADJUST };
6
7enum custom_keycodes {
8 ENC_MODE_L = SAFE_RANGE,
9 ENC_MODE_R,
10 TMB_MODE,
11};
12
13#define ESC_RAISE LT(_RAISE, KC_ESC)
14#define BSLS_RAISE LT(_RAISE, KC_BSLS)
15#define SFT_QUOT MT(MOD_RSFT, KC_QUOT)
16#define CTL_MINS MT(MOD_RCTL, KC_MINS)
diff --git a/keyboards/kyria/keymaps/gotham/keymap.c b/keyboards/kyria/keymaps/gotham/keymap.c
new file mode 100644
index 000000000..572ea067e
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/keymap.c
@@ -0,0 +1,126 @@
1/* Copyright 2019 Thomas Baart <thomas@splitkb.com>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include QMK_KEYBOARD_H
18
19#include "keycodes.h"
20
21#ifdef ENCODER_ENABLE
22# include "encoder_utils.h"
23#endif
24
25#ifdef OLED_DRIVER_ENABLE
26# include "oled_utils.h"
27#endif
28
29#ifdef THUMBSTICK_ENABLE
30# include "thumbstick.h"
31#endif
32
33// clang-format off
34const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
35/*
36 * Base Layer: QWERTY
37*/
38 [_QWERTY] = LAYOUT(
39 ESC_RAISE, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, BSLS_RAISE,
40 KC_LSFT, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, SFT_QUOT,
41 KC_LCTL, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_LGUI, KC_NO, TMB_MODE, KC_NO, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, CTL_MINS,
42 ENC_MODE_L, KC_LALT, LT(_LOWER, KC_SPC), LT(_RAISE, KC_TAB), KC_LSFT, KC_EQL, LT(_RAISE, KC_ENT), LT(_LOWER, KC_BSPC), KC_DEL, ENC_MODE_R
43 ),
44/*
45 * Lower Layer: Symbols, Navigation
46 */
47 [_LOWER] = LAYOUT(
48 _______, KC_HASH, KC_DLR, KC_LCBR, KC_RCBR, KC_PIPE, _______, _______, _______, _______, _______, KC_PIPE,
49 _______, KC_EXLM, KC_AT, KC_LPRN, KC_RPRN, KC_GRV, KC_PGUP, KC_LEFT, KC_UP, KC_RGHT, _______, KC_QUOT,
50 _______, KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD, _______, _______, _______, _______, KC_PGDN, KC_HOME, KC_DOWN, KC_END, _______, KC_MINS,
51 _______, _______, _______, KC_SCLN, KC_EQL, KC_EQL, KC_SCLN, _______, _______, _______
52 ),
53/*
54 * Raise Layer: Number keys, media, more symbols
55 */
56 [_RAISE] = LAYOUT(
57 _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______,
58 _______, _______, KC_MPRV, KC_MPLY, KC_MNXT, KC_VOLU, KC_MINS, KC_PLUS, KC_ASTR, KC_SLSH, KC_PERC, _______,
59 _______, _______, _______, _______, KC_MUTE, KC_VOLD, _______, _______, _______, _______, KC_AMPR, KC_PIPE, KC_COMM, KC_DOT, KC_SLSH, _______,
60 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
61 ),
62/*
63 * Adjust Layer: Function keys, RGB
64 */
65 [_ADJUST] = LAYOUT(
66 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, _______,
67 _______, RGB_TOG, RGB_SAI, RGB_HUI, RGB_VAI, RGB_MOD, _______, _______, _______, KC_F11, KC_F12, _______,
68 _______, _______, RGB_SAD, RGB_HUD, RGB_VAD, RGB_RMOD,_______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
69 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
70 ),
71};
72// clang-format on
73
74void matrix_init_user(void) {
75#ifdef ENCODER_ENABLE
76 encoder_utils_init();
77#endif
78}
79
80layer_state_t layer_state_set_user(layer_state_t state) { return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST); }
81
82bool process_record_user(uint16_t keycode, keyrecord_t *record) {
83 switch (keycode) {
84#ifdef ENCODER_ENABLE
85 case ENC_MODE_L:
86 if (record->event.pressed) {
87 cycle_encoder_mode(true, false);
88 }
89 break;
90 case ENC_MODE_R:
91 if (record->event.pressed) {
92 cycle_encoder_mode(false, false);
93 }
94 break;
95#endif
96#ifdef THUMBSTICK_ENABLE
97 case TMB_MODE:
98 if (record->event.pressed) {
99 thumbstick_mode_cycle(false);
100 }
101#endif
102 }
103 return true;
104}
105
106#ifdef OLED_DRIVER_ENABLE
107oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_180; }
108
109void oled_task_user(void) { render_status(); }
110#endif
111
112#ifdef ENCODER_ENABLE
113void encoder_update_user(uint8_t index, bool clockwise) {
114 if (index == 0) {
115 encoder_action(get_encoder_mode(true), clockwise);
116# ifdef OLED_DRIVER_ENABLE
117 oled_on();
118# endif
119 } else if (index == 1) {
120 encoder_action(get_encoder_mode(false), clockwise);
121# ifdef OLED_DRIVER_ENABLE
122 oled_on();
123# endif
124 }
125}
126#endif
diff --git a/keyboards/kyria/keymaps/gotham/oled_utils.c b/keyboards/kyria/keymaps/gotham/oled_utils.c
new file mode 100644
index 000000000..9d76c9749
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/oled_utils.c
@@ -0,0 +1,103 @@
1#include "oled_utils.h"
2
3 void render_qmk_logo(void) {
4 static const char PROGMEM qmk_logo[] = {
5 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94,
6 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0xB4,
7 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0x00
8 };
9
10 oled_write_P(qmk_logo, false);
11 }
12
13void render_layer(void) {
14 oled_write_P(PSTR("\nLayer: "), false);
15 switch (get_highest_layer(layer_state)) {
16 case _QWERTY:
17 oled_write_P(PSTR("Default\n"), false);
18 break;
19 case _LOWER:
20 oled_write_P(PSTR("Lower\n"), false);
21 break;
22 case _RAISE:
23 oled_write_P(PSTR("Raise\n"), false);
24 break;
25 case _ADJUST:
26 oled_write_P(PSTR("Adjust\n"), false);
27 break;
28 default:
29 oled_write_P(PSTR("???\n"), false);
30 }
31}
32
33#ifdef ENCODER_ENABLE
34void render_encoder(encoder_mode_t mode) {
35 switch (mode) {
36 case ENC_MODE_VOLUME:
37 oled_write_P(PSTR("Volume\n"), false);
38 break;
39 case ENC_MODE_WORD_NAV:
40 oled_write_P(PSTR("Word Nav\n"), false);
41 break;
42 case ENC_MODE_LEFT_RIGHT:
43 oled_write_P(PSTR("Left / Right\n"), false);
44 break;
45 case ENC_MODE_UP_DOWN:
46 oled_write_P(PSTR("Up / Down\n"), false);
47 break;
48 case ENC_MODE_PAGING:
49 oled_write_P(PSTR("PgUp / PgDwn\n"), false);
50 break;
51 default:
52 oled_write_P(PSTR("???\n"), false);
53 }
54}
55#endif
56
57#ifdef THUMBSTICK_ENABLE
58void render_thumbstick(thumbstick_mode_t mode) {
59 switch (mode) {
60 case THUMBSTICK_MODE_MOUSE:
61 oled_write_P(PSTR("Mouse"), false);
62 break;
63 case THUMBSTICK_MODE_ARROWS:
64 oled_write_P(PSTR("Arrows"), false);
65 break;
66 case THUMBSTICK_MODE_SCROLL:
67 oled_write_P(PSTR("Scroll"), false);
68 break;
69 default:
70 oled_write_P(PSTR("???\n"), false);
71 }
72}
73#endif
74
75void render_status(void) {
76 if (is_keyboard_master()) {
77 // Host Keyboard Layer Status
78 render_layer();
79#ifdef ENCODER_ENABLE
80 // Encoder state
81 oled_write_P(PSTR("L-Enc: "), false);
82 render_encoder(encoder_left_mode);
83 oled_write_P(PSTR("R-Enc: "), false);
84 render_encoder(encoder_right_mode);
85#endif
86#ifdef THUMBSTICK_ENABLE
87 if (!isLeftHand) {
88 // Thumbstick state
89 oled_write_P(PSTR("Joystick: "), false);
90 render_thumbstick(thumbstick_state.config.mode);
91 }
92#endif
93 // Host Keyboard LED Status
94 led_t led_state = host_keyboard_led_state();
95 oled_write_P(led_state.num_lock ? PSTR("NUMLCK ") : PSTR(" "), false);
96 oled_write_P(led_state.caps_lock ? PSTR("CAPLCK ") : PSTR(" "), false);
97 oled_write_P(led_state.scroll_lock ? PSTR("SCRLCK ") : PSTR(" "), false);
98 } else {
99 // QMK Logo and version information
100 render_qmk_logo();
101 oled_write_P(PSTR("\n Kyria v1.0\n"), false);
102 }
103}
diff --git a/keyboards/kyria/keymaps/gotham/oled_utils.h b/keyboards/kyria/keymaps/gotham/oled_utils.h
new file mode 100644
index 000000000..7e3bf44c8
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/oled_utils.h
@@ -0,0 +1,25 @@
1#pragma once
2
3#include "keycodes.h"
4
5#ifdef ENCODER_ENABLE
6# include "encoder_utils.h"
7#endif
8
9#ifdef THUMBSTICK_ENABLE
10# include "thumbstick.h"
11#endif
12
13void render_kyria_logo(void);
14
15void render_layer(void);
16
17#ifdef ENCODER_ENABLE
18void render_encoder(encoder_mode_t mode);
19#endif
20
21#ifdef THUMBSTICK_ENABLE
22void render_thumbstick(thumbstick_mode_t mode);
23#endif
24
25void render_status(void);
diff --git a/keyboards/kyria/keymaps/gotham/rules.mk b/keyboards/kyria/keymaps/gotham/rules.mk
new file mode 100644
index 000000000..0bd8badb4
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/rules.mk
@@ -0,0 +1,21 @@
1CONSOLE_ENABLE = yes # Console for debug
2ENCODER_ENABLE = yes # ENables the use of one or more encoders
3RGBLIGHT_ENABLE = yes # Enable keyboard RGB underglow
4MOUSEKEY_ENABLE = no # Mouse keys
5OLED_DRIVER_ENABLE = yes # Enables the use of OLED displays
6THUMBSTICK_ENABLE = yes # Enables analog thumbstick code
7
8ifeq ($(strip $(ENCODER_ENABLE)), yes)
9 SRC += encoder_utils.c
10endif
11
12ifeq ($(strip $(OLED_DRIVER_ENABLE)), yes)
13 SRC += oled_utils.c
14endif
15
16ifeq ($(strip $(THUMBSTICK_ENABLE)), yes)
17 POINTING_DEVICE_ENABLE = yes
18 OPT_DEFS += -DTHUMBSTICK_ENABLE
19 SRC += analog.c
20 SRC += thumbstick.c
21endif
diff --git a/keyboards/kyria/keymaps/gotham/thumbstick.c b/keyboards/kyria/keymaps/gotham/thumbstick.c
new file mode 100644
index 000000000..ec08fb07d
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/thumbstick.c
@@ -0,0 +1,195 @@
1#include "thumbstick.h"
2
3void thumbstick_init(void) {
4 thumbstickTimer = 0;
5 thumbstickScrollTimer = 0;
6
7 thumbstick_state.config.mode = THUMBSTICK_MODE_MOUSE;
8 thumbstick_state.config.deadZone = THUMBSTICK_DEAD_ZONE;
9 thumbstick_state.config.fineZone = THUMBSTICK_FINE_ZONE;
10 thumbstick_state.config.speed = THUMBSTICK_SPEED;
11 thumbstick_state.config.fineSpeed = THUMBSTICK_FINE_SPEED;
12 thumbstick_state.config.axisSeparation = THUMBSTICK_AXIS_SEPARATION;
13 thumbstick_state.config.eightAxis = THUMBSTICK_EIGHT_AXIS;
14
15#if defined THUMBSTICK_DEBUG
16 rawX = 0;
17 rawY = 0;
18 distX = 0;
19 distY = 0;
20 thumbstickLogTimer = 0;
21#endif
22}
23
24// Axis-level wrapper to read raw value, do logging and calculate speed
25int16_t thumbstick_get_component(uint8_t pin) {
26 uint16_t analogValue = analogReadPin(pin);
27 // Compute direction
28 bool directionIsPositive = (analogValue > THUMBSTICK_RANGE_CENTER);
29 // Compute distance from the center
30 uint16_t distance = directionIsPositive ? (analogValue - THUMBSTICK_RANGE_CENTER) : (THUMBSTICK_RANGE_CENTER - analogValue);
31#if defined THUMBSTICK_DEBUG
32 if (pin == THUMBSTICK_PIN_X) {
33 rawX = analogValue;
34 distX = distance;
35 } else {
36 rawY = analogValue;
37 distY = distance;
38 }
39#endif
40 // Compute component (range of [0 to 1023])
41 return directionIsPositive ? distance : -(int16_t)distance;
42}
43
44void thumbstick_mode_set(thumbstick_mode_t mode) { thumbstick_state.config.mode = mode; }
45
46thumbstick_mode_t thumbstick_mode_get(void) { return thumbstick_state.config.mode; }
47
48void thumbstick_mode_cycle(bool reverse) {
49 thumbstick_mode_t mode = thumbstick_mode_get();
50 if (reverse) {
51 mode = (mode == 0) ? (_THUMBSTICK_MODE_LAST - 1) : (mode - 1);
52 } else {
53 mode = (mode == (_THUMBSTICK_MODE_LAST - 1)) ? 0 : (mode + 1);
54 }
55 thumbstick_mode_set(mode);
56}
57
58// Get mouse speed
59int16_t thumbstick_get_mouse_speed(int16_t component) {
60 int16_t maxSpeed;
61 uint16_t distance = abs(component);
62 if (distance > THUMBSTICK_FINE_ZONE) {
63 maxSpeed = THUMBSTICK_SPEED;
64 } else if (distance > THUMBSTICK_DEAD_ZONE) {
65 maxSpeed = THUMBSTICK_FINE_SPEED;
66 } else {
67 return 0;
68 }
69 return (float)maxSpeed * component / THUMBSTICK_RANGE_CENTER;
70}
71
72// Fix direction within one of 8 axes (or 4 if 8-axis is disabled)
73thumbstick_direction_t thumbstick_get_discretized_direction(thumbstick_vector_t vector, float axisSeparation, bool eightAxis) {
74 thumbstick_direction_t direction;
75 uint16_t absX = abs(vector.x);
76 uint16_t absY = abs(vector.y);
77 uint16_t maxComponent = (absX > absY) ? absX : absY;
78 bool insideDeadZone = (maxComponent <= THUMBSTICK_DEAD_ZONE);
79 bool outsideDiagonalZone = ((abs(absX - absY) / (float)maxComponent) >= axisSeparation);
80 if (insideDeadZone) {
81 direction.up = direction.down = direction.left = direction.right = false;
82 } else {
83 direction.up = (vector.y < 0);
84 direction.down = (vector.y > 0);
85 direction.left = (vector.x < 0);
86 direction.right = (vector.x > 0);
87 // Let only the dominant direction remain under the right conditions
88 if (outsideDiagonalZone || !eightAxis) {
89 if (absX > absY) {
90 direction.up = direction.down = false;
91 } else {
92 direction.left = direction.right = false;
93 }
94 }
95 }
96 return direction;
97}
98
99thumbstick_direction_t scrollDirection; // Declaring global to save stack space
100void thumbstick_process(void) {
101 if (timer_elapsed(thumbstickTimer) > THUMBSTICK_TIMEOUT) {
102 thumbstickTimer = timer_read();
103#ifndef THUMBSTICK_FLIP_X
104 thumbstick_state.vector.x = thumbstick_get_component(THUMBSTICK_PIN_X);
105#else
106 thumbstick_state.vector.x = -thumbstick_get_component(THUMBSTICK_PIN_X);
107#endif
108#ifndef THUMBSTICK_FLIP_Y
109 thumbstick_state.vector.y = thumbstick_get_component(THUMBSTICK_PIN_Y);
110#else
111 thumbstick_state.vector.y = -thumbstick_get_component(THUMBSTICK_PIN_Y);
112#endif
113 switch (thumbstick_state.config.mode) {
114 case THUMBSTICK_MODE_MOUSE:
115 thumbstick_state.report.x = thumbstick_get_mouse_speed(thumbstick_state.vector.x);
116 thumbstick_state.report.y = thumbstick_get_mouse_speed(thumbstick_state.vector.y);
117 break;
118 case THUMBSTICK_MODE_ARROWS:
119 thumbstick_state.direction = thumbstick_get_discretized_direction(thumbstick_state.vector, thumbstick_state.config.axisSeparation, thumbstick_state.config.eightAxis);
120 break;
121 case THUMBSTICK_MODE_SCROLL:
122 if (timer_elapsed(thumbstickScrollTimer) > THUMBSTICK_SCROLL_TIMEOUT) {
123 thumbstickScrollTimer = timer_read();
124 scrollDirection = thumbstick_get_discretized_direction(thumbstick_state.vector, thumbstick_state.config.axisSeparation, false);
125 thumbstick_state.report.v = (scrollDirection.up || scrollDirection.down) ? (scrollDirection.up ? THUMBSTICK_SCROLL_SPEED : -THUMBSTICK_SCROLL_SPEED) : 0;
126 thumbstick_state.report.h = (scrollDirection.left || scrollDirection.right) ? (scrollDirection.left ? -THUMBSTICK_SCROLL_SPEED : THUMBSTICK_SCROLL_SPEED) : 0;
127 } else {
128 thumbstick_state.report.v = thumbstick_state.report.h = 0;
129 }
130 break;
131 default:
132 break;
133 }
134 }
135}
136
137void update_keycode_status(uint16_t keycode, bool last, bool current) {
138 if (last != current) {
139 if (current) {
140 register_code16(keycode);
141 } else {
142 unregister_code16(keycode);
143 }
144 }
145}
146
147void pointing_device_init(void) { thumbstick_init(); }
148
149void pointing_device_task(void) {
150 report_mouse_t report = pointing_device_get_report();
151
152 if (!isLeftHand) {
153 thumbstick_process();
154 switch (thumbstick_state.config.mode) {
155 case THUMBSTICK_MODE_MOUSE:
156 report.x = thumbstick_state.report.x;
157 report.y = thumbstick_state.report.y;
158#ifdef THUMBSTICK_DEBUG
159 if (timer_elapsed(thumbstickLogTimer) > 100) {
160 thumbstickLogTimer = timer_read();
161 uprintf("Raw (%d, %d); Dist (%u, %u); Vec (%d, %d);\n", rawX, rawY, distX, distY, thumbstick_state.vector.x, thumbstick_state.vector.y);
162 }
163#endif
164 break;
165 case THUMBSTICK_MODE_ARROWS:
166 update_keycode_status(KC_UP, thumbstick_state.lastDirection.up, thumbstick_state.direction.up);
167 update_keycode_status(KC_DOWN, thumbstick_state.lastDirection.down, thumbstick_state.direction.down);
168 update_keycode_status(KC_LEFT, thumbstick_state.lastDirection.left, thumbstick_state.direction.left);
169 update_keycode_status(KC_RIGHT, thumbstick_state.lastDirection.right, thumbstick_state.direction.right);
170 thumbstick_state.lastDirection = thumbstick_state.direction;
171#ifdef THUMBSTICK_DEBUG
172 if (timer_elapsed(thumbstickLogTimer) > 100) {
173 thumbstickLogTimer = timer_read();
174 uprintf("Up %d; Down %d; Left: %d; Right %d; Vec (%d, %d);\n", direction.up, direction.down, direction.left, direction.right, thumbstick_state.vector.x, thumbstick_state.vector.y);
175 }
176#endif
177 break;
178 case THUMBSTICK_MODE_SCROLL:
179 report.v = thumbstick_state.report.v;
180 report.h = thumbstick_state.report.h;
181#ifdef THUMBSTICK_DEBUG
182 if (timer_elapsed(thumbstickLogTimer) > 100) {
183 thumbstickLogTimer = timer_read();
184 uprintf("Scroll (%d, %d)\n", report.h, report.v);
185 }
186#endif
187 break;
188 default:
189 break;
190 }
191 }
192
193 pointing_device_set_report(report);
194 pointing_device_send();
195}
diff --git a/keyboards/kyria/keymaps/gotham/thumbstick.h b/keyboards/kyria/keymaps/gotham/thumbstick.h
new file mode 100644
index 000000000..aff939c74
--- /dev/null
+++ b/keyboards/kyria/keymaps/gotham/thumbstick.h
@@ -0,0 +1,98 @@
1#pragma once
2
3typedef enum {
4 THUMBSTICK_MODE_MOUSE = 0,
5 THUMBSTICK_MODE_ARROWS,
6 THUMBSTICK_MODE_SCROLL,
7 _THUMBSTICK_MODE_LAST // Do not use, except for looping through enum values
8} thumbstick_mode_t;
9
10// Parameters
11#define THUMBSTICK_DEAD_ZONE 90 // Values below this are ignored (deadzone)
12#define THUMBSTICK_FINE_ZONE 180 // Values below this enable fine movement
13
14#define THUMBSTICK_MODE THUMBSTICK_MODE_MOUSE
15#define THUMBSTICK_SPEED 256
16#define THUMBSTICK_FINE_SPEED 96
17#define THUMBSTICK_SCROLL_SPEED 1
18
19#define THUMBSTICK_EIGHT_AXIS true
20#define THUMBSTICK_AXIS_SEPARATION 0.5f
21
22// Implicit and derived constants
23#define THUMBSTICK_TIMEOUT 10 // Mouse report throttling time in ms
24#define THUMBSTICK_SCROLL_TIMEOUT 200 // Mouse scroll throttling time in ms
25#define THUMBSTICK_RANGE_START 0
26#define THUMBSTICK_RANGE_STOP 1023
27#define THUMBSTICK_RANGE_CENTER (THUMBSTICK_RANGE_STOP - THUMBSTICK_RANGE_START + 1) / 2
28#define THUMBSTICK_RANGE_MOVEMENT (THUMBSTICK_RANGE_CENTER - THUMBSTICK_DEAD_ZONE)
29
30#include "timer.h"
31#include "analog.h"
32#include "split_util.h"
33#include "pointing_device.h"
34
35#if defined THUMBSTICK_DEBUG
36# include "print.h"
37uint16_t rawX;
38uint16_t rawY;
39uint16_t distX;
40uint16_t distY;
41uint16_t thumbstickLogTimer;
42#endif
43
44typedef struct {
45 thumbstick_mode_t mode;
46 uint16_t deadZone;
47 uint16_t fineZone;
48 uint16_t speed;
49 uint16_t fineSpeed;
50 float axisSeparation;
51 bool eightAxis;
52} thumbstick_config_t;
53
54typedef struct {
55 int16_t x;
56 int16_t y;
57} thumbstick_vector_t;
58
59typedef struct {
60 bool up;
61 bool right;
62 bool down;
63 bool left;
64} thumbstick_direction_t;
65
66typedef struct {
67 thumbstick_config_t config;
68 thumbstick_vector_t vector;
69 thumbstick_direction_t direction;
70 thumbstick_direction_t lastDirection;
71 report_mouse_t report;
72} thumbstick_state_t;
73
74uint16_t thumbstickTimer;
75uint16_t thumbstickScrollTimer;
76
77thumbstick_state_t thumbstick_state;
78
79void thumbstick_mode_set(thumbstick_mode_t mode);
80
81thumbstick_mode_t thumbstick_mode_get(void);
82
83void thumbstick_mode_cycle(bool reverse);
84
85void thumbstick_init(void);
86
87// Axis-level wrapper to read raw value, do logging and calculate speed
88int16_t thumbstick_get_component(uint8_t pin);
89
90// Get mouse speed
91int16_t thumbstick_get_mouse_speed(int16_t component);
92
93// Fix direction within one of 8 axes (or 4 if 8-axis is disabled)
94thumbstick_direction_t thumbstick_get_discretized_direction(thumbstick_vector_t vector, float axisSeparation, bool eightAxis);
95
96void thumbstick_process(void);
97
98void update_keycode_status(uint16_t keycode, bool last, bool current);