From 7638797c923fd8564259da01c6f460f288a1a984 Mon Sep 17 00:00:00 2001 From: 9R Date: Sat, 12 Oct 2024 03:19:30 +0100 Subject: [PATCH] add vial support for replicazeron (#798) * add vial support for replicazeron * reduce firmware size --- .../handwired/replicazeron/common/leds.c | 43 ++++++ .../handwired/replicazeron/common/leds.h | 23 +++ .../handwired/replicazeron/common/oled.c | 96 +++++++++++++ .../handwired/replicazeron/common/oled.h | 34 +++++ .../handwired/replicazeron/common/state.c | 28 ++++ .../handwired/replicazeron/common/state.h | 28 ++++ .../replicazeron/common/thumbstick.c | 111 +++++++++++++++ .../replicazeron/common/thumbstick.h | 51 +++++++ keyboards/handwired/replicazeron/config.h | 31 ++++ keyboards/handwired/replicazeron/info.json | 47 +++++++ .../replicazeron/keymaps/default/keymap.c | 57 ++++++++ .../replicazeron/keymaps/vial/config.h | 8 ++ .../replicazeron/keymaps/vial/keymap.c | 57 ++++++++ .../replicazeron/keymaps/vial/rules.mk | 5 + .../replicazeron/keymaps/vial/vial.json | 133 ++++++++++++++++++ .../handwired/replicazeron/post_rules.mk | 14 ++ .../handwired/replicazeron/promicro/config.h | 23 +++ .../replicazeron/promicro/keyboard.json | 18 +++ keyboards/handwired/replicazeron/readme.md | 69 +++++++++ .../handwired/replicazeron/replicazeron.c | 103 ++++++++++++++ .../handwired/replicazeron/replicazeron.h | 50 +++++++ keyboards/handwired/replicazeron/rules.mk | 14 ++ .../handwired/replicazeron/stm32f103/config.h | 29 ++++ .../replicazeron/stm32f103/keyboard.json | 31 ++++ .../replicazeron/stm32f103/mcuconf.h | 31 ++++ 25 files changed, 1134 insertions(+) create mode 100644 keyboards/handwired/replicazeron/common/leds.c create mode 100644 keyboards/handwired/replicazeron/common/leds.h create mode 100644 keyboards/handwired/replicazeron/common/oled.c create mode 100644 keyboards/handwired/replicazeron/common/oled.h create mode 100644 keyboards/handwired/replicazeron/common/state.c create mode 100644 keyboards/handwired/replicazeron/common/state.h create mode 100644 keyboards/handwired/replicazeron/common/thumbstick.c create mode 100644 keyboards/handwired/replicazeron/common/thumbstick.h create mode 100644 keyboards/handwired/replicazeron/config.h create mode 100644 keyboards/handwired/replicazeron/info.json create mode 100644 keyboards/handwired/replicazeron/keymaps/default/keymap.c create mode 100644 keyboards/handwired/replicazeron/keymaps/vial/config.h create mode 100644 keyboards/handwired/replicazeron/keymaps/vial/keymap.c create mode 100644 keyboards/handwired/replicazeron/keymaps/vial/rules.mk create mode 100644 keyboards/handwired/replicazeron/keymaps/vial/vial.json create mode 100644 keyboards/handwired/replicazeron/post_rules.mk create mode 100644 keyboards/handwired/replicazeron/promicro/config.h create mode 100644 keyboards/handwired/replicazeron/promicro/keyboard.json create mode 100644 keyboards/handwired/replicazeron/readme.md create mode 100644 keyboards/handwired/replicazeron/replicazeron.c create mode 100644 keyboards/handwired/replicazeron/replicazeron.h create mode 100644 keyboards/handwired/replicazeron/rules.mk create mode 100644 keyboards/handwired/replicazeron/stm32f103/config.h create mode 100644 keyboards/handwired/replicazeron/stm32f103/keyboard.json create mode 100644 keyboards/handwired/replicazeron/stm32f103/mcuconf.h diff --git a/keyboards/handwired/replicazeron/common/leds.c b/keyboards/handwired/replicazeron/common/leds.c new file mode 100644 index 00000000000..7bcb0cf39c8 --- /dev/null +++ b/keyboards/handwired/replicazeron/common/leds.c @@ -0,0 +1,43 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#include "leds.h" +#include +#include "gpio.h" + +//////////// Status LEDs ////////////// +void init_leds(void) { + // Both LEDs off, they have inverted logic + gpio_set_pin_output(STATUS_LED_A_PIN); + gpio_set_pin_output(STATUS_LED_B_PIN); + gpio_write_pin_high(STATUS_LED_A_PIN); + gpio_write_pin_high(STATUS_LED_B_PIN); +} + +void set_leds(uint8_t highest_active_layer) { + // any layer other than 0-3, quit and LEDs off + if (highest_active_layer > 3) { + gpio_write_pin_high(STATUS_LED_A_PIN); + gpio_write_pin_high(STATUS_LED_B_PIN); + return; + } + + // use bitwise operations to display active layer in binary + bool bit1 = !(highest_active_layer & 1); + bool bit2 = !(highest_active_layer & 2); + gpio_write_pin(STATUS_LED_A_PIN, bit1); + gpio_write_pin(STATUS_LED_B_PIN, bit2); +} diff --git a/keyboards/handwired/replicazeron/common/leds.h b/keyboards/handwired/replicazeron/common/leds.h new file mode 100644 index 00000000000..e9ccec1bb6f --- /dev/null +++ b/keyboards/handwired/replicazeron/common/leds.h @@ -0,0 +1,23 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#pragma once + +#include + +void init_leds(void); + +void set_leds(uint8_t active_layer); diff --git a/keyboards/handwired/replicazeron/common/oled.c b/keyboards/handwired/replicazeron/common/oled.c new file mode 100644 index 00000000000..9d3a3147a3c --- /dev/null +++ b/keyboards/handwired/replicazeron/common/oled.c @@ -0,0 +1,96 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#include "oled.h" +#include "oled_driver.h" +#include "progmem.h" +#include "util.h" + +uint8_t shiftbits =32 ; + +//////////// OLED output helpers ////////////// +void draw_mode(controller_state_t controller_state) { + //draw oled row showing thumbstick mode + oled_write_P(PSTR("Mode: "), false); + if (controller_state.wasdShiftMode) { + oled_write_ln_P(PSTR("WASD + Shift"), false); + } else if (controller_state.wasdMode) { + oled_write_ln_P(PSTR("WASD"), false); + } else { + oled_write_ln_P(PSTR("JoyStick"), false); + } +} + +void draw_wasd_key(wasd_state_t wasd_state) { + //draw oled row showing active keypresses emulated from thumbstick + const char* keys = "wasd"; + bool keystates [] = { wasd_state.w, wasd_state.a, wasd_state.s, wasd_state.d }; + // iterate over keystates + for (uint8_t i = 0 ; i < ARRAY_SIZE(keystates); ++i) { + if (keystates[i]) { + char k = keys[i] ; + //bitshift char to upper case + if (wasd_state.shift) { + k &= ~shiftbits; + } + oled_write_char(k, false); + } else { + oled_write_P(PSTR(" "), false); + } + } +} + +void draw_thumb_debug(thumbstick_polar_position_t thumbstick_polar_position) { + //draw oled row showing thumbstick direction and distance from center + oled_write_P(PSTR("Dir:"), false); + oled_write(get_u16_str(thumbstick_polar_position.angle, ' '), false); + oled_write_P(PSTR(" Dist:"), false); + oled_write_ln(get_u16_str(thumbstick_polar_position.distance, ' '), false); + //print registered key codes + oled_write_P(PSTR("Keycodes: "), false); + draw_wasd_key( wasd_state ); +} + +//////////// draw OLED output ////////////// +void draw_oled(controller_state_t controller_state) { + oled_write_P(PSTR("Layer: "), false); + + switch (controller_state.highestActiveLayer) { + case _SHOOTER: + oled_write_ln_P(PSTR("Shooter"), false); + break; + + case _MISC: + oled_write_ln_P(PSTR("Misc"), false); + break; + + case _SETTINGS: + oled_write_ln_P(PSTR("Settings"), false); + break; + + default: + oled_write_ln_P(PSTR("Default"), false); + } + + draw_mode(controller_state); + if (controller_state.highestActiveLayer == _SETTINGS ) { + draw_thumb_debug(thumbstick_polar_position); + } + else { + oled_write_ln_P(PSTR(" "), false); + } + oled_write_ln_P(PSTR(" "), false); +} diff --git a/keyboards/handwired/replicazeron/common/oled.h b/keyboards/handwired/replicazeron/common/oled.h new file mode 100644 index 00000000000..977aaa2c8da --- /dev/null +++ b/keyboards/handwired/replicazeron/common/oled.h @@ -0,0 +1,34 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ +#pragma once + +#include "replicazeron.h" + +#include +#include "state.h" +#include "thumbstick.h" + +uint8_t shiftbits; + +char stringbuffer[8]; + +void draw_oled(controller_state_t controller_state); + +void draw_mode(controller_state_t controller_state); + +void draw_thumb_debug(thumbstick_polar_position_t thumbstick_polar_position); + +void draw_wasd_key(wasd_state_t wasd_state); diff --git a/keyboards/handwired/replicazeron/common/state.c b/keyboards/handwired/replicazeron/common/state.c new file mode 100644 index 00000000000..b80fcb5c3b3 --- /dev/null +++ b/keyboards/handwired/replicazeron/common/state.c @@ -0,0 +1,28 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#include "state.h" + +controller_state_t init_state (void) { + controller_state_t controller_state = { + .wasdMode = true, + .wasdShiftMode = false, + .autoRun = false, + .highestActiveLayer = 0, + }; + + return controller_state; +} diff --git a/keyboards/handwired/replicazeron/common/state.h b/keyboards/handwired/replicazeron/common/state.h new file mode 100644 index 00000000000..8ff69181a56 --- /dev/null +++ b/keyboards/handwired/replicazeron/common/state.h @@ -0,0 +1,28 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ +#pragma once + +#include +#include + +typedef struct { + bool wasdMode; + bool wasdShiftMode; + bool autoRun; + uint8_t highestActiveLayer; +} controller_state_t; + +controller_state_t init_state(void); diff --git a/keyboards/handwired/replicazeron/common/thumbstick.c b/keyboards/handwired/replicazeron/common/thumbstick.c new file mode 100644 index 00000000000..51f27966c43 --- /dev/null +++ b/keyboards/handwired/replicazeron/common/thumbstick.c @@ -0,0 +1,111 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#include "thumbstick.h" +#include +#include "action.h" +#include "keycode.h" +#include "debug.h" + +void init_wasd_state (void) { + wasd_state.w = wasd_state.a = wasd_state.s = wasd_state.d = false; + last_wasd_state = wasd_state; + wasd_state.shift = false; +} + +thumbstick_polar_position_t get_thumbstick_polar_position(int16_t x, int16_t y) { + static thumbstick_polar_position_t position; + +#ifdef THUMBSTICK_DEBUG + dprintf("xN: %4d yN: %4d\n", x, y); +#endif + + //transform to carthesian coordinates to polar coordinates + //get distance from center as int in range [0-600] + position.distance = (double)sqrt((double)x * (double)x + (double)y * (double)y); + //get direction as int in range [0 to 359] + position.angle = (double)atan2(y, x) * (180 /M_PI) + 180; + + //apply thumbstick rotation const to modify forward direction + position.angle = (position.angle + _THUMBSTICK_ROTATION) % 360; + + return position; +} + +bool update_keystate(uint16_t angle_from, uint16_t angle_to, uint16_t angle) { + return (angle_from < angle && angle <= angle_to); +} + +void update_keycode(uint16_t keycode, bool keystate, bool last_keystate) { + if (keystate && keystate != last_keystate) { + register_code16(keycode); + } else if (!keystate) { + unregister_code16(keycode); + } +} + +void thumbstick(controller_state_t controller_state) { + xPos = joystick_state.axes[0]; + yPos = joystick_state.axes[1]; + + thumbstick_polar_position = get_thumbstick_polar_position(xPos, yPos); + +#ifdef THUMBSTICK_DEBUG + dprintf("distance: %5d angle: %5d\n", thumbstick_polar_position.distance, thumbstick_polar_position.angle); +#endif + + // Update WASD state depending on thumbstick position + // if thumbstick out of of deadzone + if (thumbstick_polar_position.distance >= _DEADZONE) { + wasd_state.w = update_keystate( 0, 90, thumbstick_polar_position.angle); + // A angle: 45 - 180 + wasd_state.a = update_keystate( 45, 181, thumbstick_polar_position.angle); + // S angle: 135 - 270 + wasd_state.s = update_keystate(135, 270, thumbstick_polar_position.angle); + // D angle: 225 - 359 + wasd_state.d = update_keystate(225, 359, thumbstick_polar_position.angle); + + if (!wasd_state.w ) { + wasd_state.w = update_keystate(315, 360, thumbstick_polar_position.angle); + } + } else { + //reset WASD state when in _DEADZONE + init_wasd_state(); + } + +#ifdef THUMBSTICK_DEBUG + dprintf("w: %2d a: %2d s: %2d d: %2d\n", wasd_state.w, wasd_state.a, wasd_state.s, wasd_state.d); +#endif + + update_keycode(KC_W, wasd_state.w, last_wasd_state.w); + update_keycode(KC_A, wasd_state.a, last_wasd_state.a); + update_keycode(KC_S, wasd_state.s, last_wasd_state.s); + update_keycode(KC_D, wasd_state.d, last_wasd_state.d); + + last_wasd_state = wasd_state ; + + // handle WASD-Shift mode + if (controller_state.wasdShiftMode) { + bool Shifted = thumbstick_polar_position.distance > _SHIFTZONE; + if (!wasd_state.shift && Shifted) { + register_code(KC_LSFT); + wasd_state.shift = true; + } else if (wasd_state.shift && !Shifted) { + unregister_code(KC_LSFT); + wasd_state.shift = false; + } + } +} diff --git a/keyboards/handwired/replicazeron/common/thumbstick.h b/keyboards/handwired/replicazeron/common/thumbstick.h new file mode 100644 index 00000000000..d9b4394a091 --- /dev/null +++ b/keyboards/handwired/replicazeron/common/thumbstick.h @@ -0,0 +1,51 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ +#pragma once + +#include +#include "state.h" +#include "quantum.h" + +int16_t xPos; +int16_t yPos; + +typedef struct { + uint16_t angle; + uint16_t distance; +} thumbstick_polar_position_t; + +typedef struct { + bool w; + bool a; + bool s; + bool d; + bool shift; +} wasd_state_t; + +thumbstick_polar_position_t thumbstick_polar_position ; + +wasd_state_t wasd_state; +wasd_state_t last_wasd_state; + +void init_wasd_state(void); + +thumbstick_polar_position_t get_thumbstick_polar_position(int16_t x, int16_t y); + +bool update_keystate(uint16_t angle_from, uint16_t angle_to, uint16_t angle); + +void update_keycode(uint16_t keycode, bool keystate, bool last_keystate); + +void thumbstick(controller_state_t controller_state); diff --git a/keyboards/handwired/replicazeron/config.h b/keyboards/handwired/replicazeron/config.h new file mode 100644 index 00000000000..0c20f1d4b9b --- /dev/null +++ b/keyboards/handwired/replicazeron/config.h @@ -0,0 +1,31 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#pragma once + +#define THUMBSTICK_DEBUG + +/* joystick configuration */ +#define JOYSTICK_BUTTON_COUNT 0 +#define JOYSTICK_AXIS_COUNT 2 +#define JOYSTICK_AXIS_RESOLUTION 10 + +#define _DEADZONE 100 // 0 to _SHIFTZONE-1 +#define _SHIFTZONE 350 // _DEADZONE+1 to 600 +#define _THUMBSTICK_ROTATION 100 //degrees, adjusts forward direction + +/* Locking resynchronize hack */ +#define LOCKING_RESYNC_ENABLE diff --git a/keyboards/handwired/replicazeron/info.json b/keyboards/handwired/replicazeron/info.json new file mode 100644 index 00000000000..88f884c0bd9 --- /dev/null +++ b/keyboards/handwired/replicazeron/info.json @@ -0,0 +1,47 @@ +{ + "manufacturer": "9R", + "keyboard_name": "Replicazeron", + "maintainer": "9R", + "diode_direction": "COL2ROW", + "url": "https://github.com/9R/replicazeron", + "usb": { + "pid": "0x2305", + "vid": "0x4142" + }, + "layouts": { + "LAYOUT": { + "layout": [ + {"label": "K04", "matrix": [0, 0], "x": 1.75, "y": 0.25, "w": 1.25}, + {"label": "K10", "matrix": [0, 1], "x": 3, "y": 0.25, "w": 1.25}, + {"label": "K16", "matrix": [0, 2], "x": 4.25, "y": 0.25, "w": 1.25}, + {"label": "K22", "matrix": [0, 3], "x": 5.5, "y": 0.25, "w": 1.25}, + {"label": "dwn", "matrix": [0, 4], "x": 9.5, "y": 2, "w": 1.25}, + {"label": "K03", "matrix": [1, 0], "x": 1.75, "y": 1, "w": 1.25, "h": 1.25}, + {"label": "K09", "matrix": [1, 1], "x": 3, "y": 1, "w": 1.25, "h": 1.25}, + {"label": "K15", "matrix": [1, 2], "x": 4.25, "y": 1, "w": 1.25, "h": 1.25}, + {"label": "K21", "matrix": [1, 3], "x": 5.5, "y": 1, "w": 1.25, "h": 1.25}, + {"label": "lft", "matrix": [1, 4], "x": 8.25, "y": 1, "w": 1.25}, + {"label": "K02", "matrix": [2, 0], "x": 1.75, "y": 2.5, "w": 1.25, "h": 1.25}, + {"label": "K08", "matrix": [2, 1], "x": 3, "y": 2.5, "w": 1.25, "h": 1.25}, + {"label": "K14", "matrix": [2, 2], "x": 4.25, "y": 2.5, "w": 1.25, "h": 1.25}, + {"label": "K20", "matrix": [2, 3], "x": 5.5, "y": 2.5, "w": 1.25, "h": 1.25}, + {"label": "ent", "matrix": [2, 4], "x": 9.5, "y": 1, "w": 1.25}, + {"label": "K01", "matrix": [3, 0], "x": 1.75, "y": 3.75, "w": 1.25}, + {"label": "K07", "matrix": [3, 1], "x": 3, "y": 3.75, "w": 1.25}, + {"label": "K13", "matrix": [3, 2], "x": 4.25, "y": 3.75, "w": 1.25}, + {"label": "K19", "matrix": [3, 3], "x": 5.5, "y": 3.75, "w": 1.25}, + {"label": "rgt", "matrix": [3, 4], "x": 10.75, "y": 1, "w": 1.25}, + {"label": "K00", "matrix": [4, 0], "x": 1.75, "y": 4.75, "w": 1.25}, + {"label": "K06", "matrix": [4, 1], "x": 3, "y": 4.75, "w": 1.25}, + {"label": "K12", "matrix": [4, 2], "x": 4.25, "y": 4.75, "w": 1.25}, + {"label": "K18", "matrix": [4, 3], "x": 5.5, "y": 4.75, "w": 1.25}, + {"label": "up ", "matrix": [4, 4], "x": 9.5, "y": 0, "w": 1.25}, + {"label": "K05", "matrix": [5, 0], "x": 0, "y": 2.5, "w": 1.75}, + {"label": "lyr", "matrix": [5, 1], "x": 7.5, "y": 4.25, "w": 1.5}, + {"label": "K17", "matrix": [5, 2], "x": 10.75, "y": 4, "w": 1.5}, + {"label": "K23", "matrix": [5, 3], "x": 6.75, "y": 2.5, "w": 1.5}, + {"label": "spc", "matrix": [5, 4], "x": 10.75, "y": 3, "w": 1.25} + ] + } + } +} diff --git a/keyboards/handwired/replicazeron/keymaps/default/keymap.c b/keyboards/handwired/replicazeron/keymaps/default/keymap.c new file mode 100644 index 00000000000..feb027271d9 --- /dev/null +++ b/keyboards/handwired/replicazeron/keymaps/default/keymap.c @@ -0,0 +1,57 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BASE] = LAYOUT( + // little | ring | middle | index | 5way-dpad | -finger + KC_GRV, KC_ESC, KC_J, KC_M, KC_RIGHT, // up + KC_T, KC_3, KC_4, KC_R, KC_ENT, // forward + KC_X, KC_LCTL, KC_LCTL, KC_LALT, KC_DOWN, // down + KC_LSFT, KC_SPC, KC_C, KC_F, KC_LEFT, // back 2 + KC_LSFT, KC_6, KC_Z, KC_V, KC_UP, // back 1 + KC_TAB, TG(_SHOOTER), KC_I, KC_B, KC_P // special + // ^side_l | ^case | ^thumb | ^side_r | ^analog click <= special row mapping + ), + + [_SHOOTER] = LAYOUT( + KC_NO, KC_NO, KC_NO, KC_NO, KC_RIGHT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_ENT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_DOWN, + KC_NO, KC_NO, KC_NO, KC_NO, KC_LEFT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_UP, + KC_NO, TG(_MISC), KC_NO, KC_NO, KC_P + ), + + [_MISC] = LAYOUT( + KC_NO, KC_NO, KC_NO, KC_NO, KC_RIGHT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_ENT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_DOWN, + KC_NO, KC_NO, KC_NO, KC_NO, KC_LEFT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_UP, + KC_NO, TG(_SETTINGS), KC_NO, KC_NO, KC_P + ), + + [_SETTINGS] = LAYOUT( + RGB_M_P, RGB_M_B, RGB_M_K, RGB_M_T, KC_RIGHT, + KC_NO, RGB_SAI, RGB_VAI, RGB_HUI, KC_ENT, + RGB_TOG, KC_NO, KC_NO, KC_NO , KC_DOWN, + EE_CLR, RGB_SAD, RGB_VAD, RGB_HUD, KC_LEFT, + QK_BOOT, AUTORUN, JOYMODE, KC_V, KC_UP, + RGB_MOD, TO(_BASE), KC_NO, RGB_RMOD, KC_P + ) +}; diff --git a/keyboards/handwired/replicazeron/keymaps/vial/config.h b/keyboards/handwired/replicazeron/keymaps/vial/config.h new file mode 100644 index 00000000000..60cec8eeaca --- /dev/null +++ b/keyboards/handwired/replicazeron/keymaps/vial/config.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#pragma once + +#define VIAL_KEYBOARD_UID {0x3E, 0x15, 0xC1, 0x32, 0xC3, 0xDE, 0xCD, 0x83} + +#define VIAL_UNLOCK_COMBO_ROWS { 4, 4 } +#define VIAL_UNLOCK_COMBO_COLS { 0, 3 } diff --git a/keyboards/handwired/replicazeron/keymaps/vial/keymap.c b/keyboards/handwired/replicazeron/keymaps/vial/keymap.c new file mode 100644 index 00000000000..feb027271d9 --- /dev/null +++ b/keyboards/handwired/replicazeron/keymaps/vial/keymap.c @@ -0,0 +1,57 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BASE] = LAYOUT( + // little | ring | middle | index | 5way-dpad | -finger + KC_GRV, KC_ESC, KC_J, KC_M, KC_RIGHT, // up + KC_T, KC_3, KC_4, KC_R, KC_ENT, // forward + KC_X, KC_LCTL, KC_LCTL, KC_LALT, KC_DOWN, // down + KC_LSFT, KC_SPC, KC_C, KC_F, KC_LEFT, // back 2 + KC_LSFT, KC_6, KC_Z, KC_V, KC_UP, // back 1 + KC_TAB, TG(_SHOOTER), KC_I, KC_B, KC_P // special + // ^side_l | ^case | ^thumb | ^side_r | ^analog click <= special row mapping + ), + + [_SHOOTER] = LAYOUT( + KC_NO, KC_NO, KC_NO, KC_NO, KC_RIGHT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_ENT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_DOWN, + KC_NO, KC_NO, KC_NO, KC_NO, KC_LEFT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_UP, + KC_NO, TG(_MISC), KC_NO, KC_NO, KC_P + ), + + [_MISC] = LAYOUT( + KC_NO, KC_NO, KC_NO, KC_NO, KC_RIGHT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_ENT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_DOWN, + KC_NO, KC_NO, KC_NO, KC_NO, KC_LEFT, + KC_NO, KC_NO, KC_NO, KC_NO, KC_UP, + KC_NO, TG(_SETTINGS), KC_NO, KC_NO, KC_P + ), + + [_SETTINGS] = LAYOUT( + RGB_M_P, RGB_M_B, RGB_M_K, RGB_M_T, KC_RIGHT, + KC_NO, RGB_SAI, RGB_VAI, RGB_HUI, KC_ENT, + RGB_TOG, KC_NO, KC_NO, KC_NO , KC_DOWN, + EE_CLR, RGB_SAD, RGB_VAD, RGB_HUD, KC_LEFT, + QK_BOOT, AUTORUN, JOYMODE, KC_V, KC_UP, + RGB_MOD, TO(_BASE), KC_NO, RGB_RMOD, KC_P + ) +}; diff --git a/keyboards/handwired/replicazeron/keymaps/vial/rules.mk b/keyboards/handwired/replicazeron/keymaps/vial/rules.mk new file mode 100644 index 00000000000..4afa6d59dda --- /dev/null +++ b/keyboards/handwired/replicazeron/keymaps/vial/rules.mk @@ -0,0 +1,5 @@ +VIA_ENABLE = yes +VIAL_ENABLE = yes + +COMBO_ENABLE = no +QMK_SETTINGS = no diff --git a/keyboards/handwired/replicazeron/keymaps/vial/vial.json b/keyboards/handwired/replicazeron/keymaps/vial/vial.json new file mode 100644 index 00000000000..42d809028c2 --- /dev/null +++ b/keyboards/handwired/replicazeron/keymaps/vial/vial.json @@ -0,0 +1,133 @@ +{ + "lighting": "none", + "matrix": { + "rows": 6, + "cols": 5 + }, + "layouts": { + "keymap": [ + [ + { + "x": 1.75 + }, + "0,0", + "0,1", + "0,2", + "0,3", + { + "x": 2.5 + }, + "0,4" + ], + [ + { + "x": 1.75, + "h": 1.25 + }, + "1,0", + { + "h": 1.25 + }, + "1,1", + { + "h": 1.25 + }, + "1,2", + { + "h": 1.25 + }, + "1,3", + { + "x": 1.5 + }, + "4,4", + "1,4", + "2,4" + ], + [ + { + "x": 8.25 + }, + "3,4" + ], + [ + { + "y": -0.75, + "x": 1.75, + "h": 1.5 + }, + "2,0", + { + "h": 1.5 + }, + "2,1", + { + "h": 1.5 + }, + "2,2", + { + "h": 1.5 + }, + "2,3" + ], + [ + { + "y": 0.5, + "x": 1.75 + }, + "3,0", + "3,1", + "3,2", + "3,3", + { + "x": 1.5, + "h": 1.5, + "w": 1.5 + }, + "5,4" + ], + [ + { + "x": 1.75 + }, + "4,0", + "4,1", + "4,2", + "4,3", + { + "x": 0.25 + }, + "5,1" + ], + [ + { + "r": 15, + "rx": 0.5, + "ry": 3, + "y": -0.75, + "x": -0.5, + "w": 1.5 + }, + "5,0" + ], + [ + { + "rx": 7, + "y": 0.5, + "x": 2.75, + "w": 1.5 + }, + "5,2" + ], + [ + { + "r": -15, + "y": -2.25, + "x": -1, + "w": 1.5 + }, + "5,3" + ] + ] + } +} diff --git a/keyboards/handwired/replicazeron/post_rules.mk b/keyboards/handwired/replicazeron/post_rules.mk new file mode 100644 index 00000000000..101759aa07f --- /dev/null +++ b/keyboards/handwired/replicazeron/post_rules.mk @@ -0,0 +1,14 @@ +ifeq ($(strip $(LEDS_ENABLE)), yes) + OPT_DEFS += -DLEDS_ENABLE + SRC += leds.c +endif + +ifeq ($(strip $(OLED_ENABLE)), yes) + SRC += oled.c +endif + +ifeq ($(strip $(THUMBSTICK_ENABLE)), yes) + OPT_DEFS += -DTHUMBSTICK_ENABLE + SRC += thumbstick.c + ANALOG_DRIVER_REQUIRED = yes +endif diff --git a/keyboards/handwired/replicazeron/promicro/config.h b/keyboards/handwired/replicazeron/promicro/config.h new file mode 100644 index 00000000000..55b4d5c2f4d --- /dev/null +++ b/keyboards/handwired/replicazeron/promicro/config.h @@ -0,0 +1,23 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#pragma once + +#define STATUS_LED_A_PIN D2 +#define STATUS_LED_B_PIN D3 + +#define ANALOG_AXIS_PIN_X F4 +#define ANALOG_AXIS_PIN_Y F5 diff --git a/keyboards/handwired/replicazeron/promicro/keyboard.json b/keyboards/handwired/replicazeron/promicro/keyboard.json new file mode 100644 index 00000000000..dbc2e1edf38 --- /dev/null +++ b/keyboards/handwired/replicazeron/promicro/keyboard.json @@ -0,0 +1,18 @@ +{ + "usb": { + "device_version": "0.0.1" + }, + "matrix_pins": { + "cols": ["C6", "D4", "D7", "E6", "F7"], + "rows": ["B1", "B3", "B2", "B6", "B5", "B4"] + }, + "development_board": "promicro", + "features": { + "bootmagic": false, + "console": false, + "extrakey": false, + "mousekey": false, + "nkro": false, + "rgblight": false, + } +} diff --git a/keyboards/handwired/replicazeron/readme.md b/keyboards/handwired/replicazeron/readme.md new file mode 100644 index 00000000000..c933ebc0920 --- /dev/null +++ b/keyboards/handwired/replicazeron/readme.md @@ -0,0 +1,69 @@ + +# Replicazeron + +This is a config to run a 3dprinted keyboard controller with qmk based on this project: + +https://sites.google.com/view/alvaro-rosati/azeron-keypad-diy-tutorial + +Some additional and redesigned files (i.e. for the OLED-display) can be found in [this repo](https://github.com/9R/replicazeron). + +![Replicazeron](https://i.imgur.com/WTys4SM.jpg) + +[Gallery](https://imgur.com/a/2qlEPVl) + +## Features + + * 23 keys + * analog stick with WASD emulation + * 5way dpad + * 2 status LEDS + * 6x WS2812 RGB-LED lighting + +## Supported MCUs + +Currently configs for STM32F103 and atmega32U4 are available, but STM32 is recommended, since the atmega may run out of flash with all features enabled. + +With minor adjustments to Pinconfig it should be possible to use other MCUs that are supported by QMK + + +## Wirering + +Full schematics can be found in this repo: + +https://github.com/9R/replicazeron_schematics + +### Rows +|row| promiro gpios | promicro pin | stm32F103 gpios | color | +|---|---------------|--------------|-----------------|---------| +| 0 | B1 | 15 | B15 | red | +| 1 | B3 | 14 | A8 | blue | +| 2 | B2 | 16 | A9 | yellow | +| 3 | B6 | 10 | A10 | brown | +| 4 | B5 | 9 | A15 | orange | +| 5 | B4 | 8 | B3 | green | + +### Columns +|col| promiro gpios | promicro pin | stm32F103 gpios | color | +|---|---------------|--------------|-----------------|---------| +| 0 | C6 | 5 | A7 | white | +| 1 | D4 | 4 | A6 | grey | +| 2 | D7 | 6 | A5 | violet | +| 3 | E6 | 7 | A4 | grey | +| 4 | F7 | A0 | B4 | white | + +### Analog +| promicro gpio | stm32F103 gpio | pin | color | +|---------------|----------------|-----|-------| +| GND | GND | GND | white | +| VCC | VCC | VCC | red | +| F4 | B1 | VRx | brown | +| F5 | B0 | VRy | yellow| +| | | SW | blue | + +### OLED +| promicro gpio | stm32F103 gpio | pin | color | +|---------------|----------------|-----|-------| +| GND | GND | GND | white | +| VCC | VCC | VCC | red | +| D4 | B10 | SDA | green | +| C6 | B11 | SCL | yellow| diff --git a/keyboards/handwired/replicazeron/replicazeron.c b/keyboards/handwired/replicazeron/replicazeron.c new file mode 100644 index 00000000000..5c27916a7b7 --- /dev/null +++ b/keyboards/handwired/replicazeron/replicazeron.c @@ -0,0 +1,103 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#include "replicazeron.h" + +controller_state_t controller_state; + +#ifdef JOYSTICK_ENABLE +joystick_config_t joystick_axes[JOYSTICK_AXIS_COUNT] = { + JOYSTICK_AXIS_IN(ANALOG_AXIS_PIN_X , 0, 512, 1023), + JOYSTICK_AXIS_IN(ANALOG_AXIS_PIN_Y , 0, 512, 1023) +}; +#endif + +#ifdef THUMBSTICK_ENABLE +void housekeeping_task_kb(void) { + if (controller_state.wasdMode) { + thumbstick(controller_state); + } +} +#endif + +void keyboard_post_init_kb(void) { + // Customise these values to desired behaviour + debug_enable = true; + debug_matrix = true; + // debug_keyboard = true; + // debug_mouse = true; + +#ifdef LEDS_ENABLE + init_leds(); +#endif // LEDS_ENABLE + +#ifdef THUMBSTICK_ENABLE + init_wasd_state(); +#endif // THUMBSTICK_ENABLE + + controller_state = init_state(); + + keyboard_post_init_user(); +} + +#ifdef OLED_ENABLE +bool oled_task_kb(void) { + if (!oled_task_user()) { + return false; + } + + draw_oled(controller_state); + return false; +} +#endif + +bool process_record_kb(uint16_t keycode, keyrecord_t *record) { + if (!process_record_user(keycode, record)) { + return false; + } + + + if (keycode == JOYMODE && record->event.pressed) { + if (!controller_state.wasdMode) { + controller_state.wasdMode = true; + } else if (controller_state.wasdMode && !controller_state.wasdShiftMode) { + controller_state.wasdShiftMode = true; + } else { + controller_state.wasdMode = false; + controller_state.wasdShiftMode = false; + } + } else if (keycode == AUTORUN && record->event.pressed) { + if (!controller_state.autoRun) { + controller_state.autoRun = true; + register_code(KC_W); + } else { + controller_state.autoRun = false; + unregister_code(KC_W); + } + } + return true; +}; + +layer_state_t layer_state_set_kb(layer_state_t state) { + state = layer_state_set_user(state); + controller_state.highestActiveLayer = get_highest_layer(state) ; + +#ifdef LEDS_ENABLE + set_leds(controller_state.highestActiveLayer) ; +#endif // LEDS_ENABLE + + return state; +} diff --git a/keyboards/handwired/replicazeron/replicazeron.h b/keyboards/handwired/replicazeron/replicazeron.h new file mode 100644 index 00000000000..dbfc8cca333 --- /dev/null +++ b/keyboards/handwired/replicazeron/replicazeron.h @@ -0,0 +1,50 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#pragma once + +#include "quantum.h" + +#include "state.h" + +#ifdef LEDS_ENABLE +# include "leds.h" +#endif + +#ifdef OLED_ENABLE +# include "oled.h" +#endif + +#ifdef THUMBSTICK_ENABLE +# include "thumbstick.h" +#endif + +enum kb_layers { + _BASE, + _SHOOTER, + _MISC, + _SETTINGS, +}; + +enum kb_keycodes { + JOYMODE = QK_USER, + AUTORUN, + M_UP, + M_DWN, + M_L, + M_R, + M_SEL +}; diff --git a/keyboards/handwired/replicazeron/rules.mk b/keyboards/handwired/replicazeron/rules.mk new file mode 100644 index 00000000000..8a812f4fc3b --- /dev/null +++ b/keyboards/handwired/replicazeron/rules.mk @@ -0,0 +1,14 @@ +JOYSTICK_ENABLE = yes +OLED_ENABLE = yes + +LEDS_ENABLE = yes +THUMBSTICK_ENABLE = yes + +LTO_ENABLE = yes + +SRC += state.c + +VPATH += keyboards/handwired/replicazeron/common + +# redirect compilation against "handwired/replicazeron" to the stm32 variant +DEFAULT_FOLDER = handwired/replicazeron/stm32f103 diff --git a/keyboards/handwired/replicazeron/stm32f103/config.h b/keyboards/handwired/replicazeron/stm32f103/config.h new file mode 100644 index 00000000000..1efc89d080e --- /dev/null +++ b/keyboards/handwired/replicazeron/stm32f103/config.h @@ -0,0 +1,29 @@ +/* Copyright 2023 9R + * + * 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 2 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 . + */ + +#pragma once + +/* I2C Config */ +#define I2C_DRIVER I2CD2 +#define I2C1_SDA_PIN B11 +#define I2C1_SCL_PIN B10 + +#define STATUS_LED_A_PIN B13 +#define STATUS_LED_B_PIN B12 + +#define ANALOG_AXIS_PIN_X B0 +#define ANALOG_AXIS_PIN_Y B1 + diff --git a/keyboards/handwired/replicazeron/stm32f103/keyboard.json b/keyboards/handwired/replicazeron/stm32f103/keyboard.json new file mode 100644 index 00000000000..7298da11091 --- /dev/null +++ b/keyboards/handwired/replicazeron/stm32f103/keyboard.json @@ -0,0 +1,31 @@ +{ + "development_board": "bluepill", + "features": { + "bootmagic": true, + "console": true, + "extrakey": true, + "mousekey": true, + "nkro": true, + "rgblight": true + }, + "matrix_pins": { + "cols": ["A7", "A6", "A5", "A4", "B4"], + "rows": ["B15", "A8", "A9", "A10", "A15", "B3"] + }, + "rgblight": { + "led_count": 6 + "animations": { + "breathing": true, + "knight": true, + "rainbow_mood": true, + "rainbow_swirl": true, + "twinkle": true + } + }, + "usb": { + "device_version": "0.0.2" + }, + "ws2812": { + "pin": "B14" + } +} diff --git a/keyboards/handwired/replicazeron/stm32f103/mcuconf.h b/keyboards/handwired/replicazeron/stm32f103/mcuconf.h new file mode 100644 index 00000000000..26db5392cfc --- /dev/null +++ b/keyboards/handwired/replicazeron/stm32f103/mcuconf.h @@ -0,0 +1,31 @@ +/* Copyright 2022 9R + * + * 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 2 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 . + */ + +#pragma once + +#include_next + +//enable i2c for OLED +#undef STM32_I2C_USE_I2C2 +#define STM32_I2C_USE_I2C2 TRUE + +#undef STM32_PWM_USE_TIM1 +#define STM32_PWM_USE_TIM1 TRUE + +//enable ADC for thumbstick +#undef STM32_ADC_USE_ADC1 +#define STM32_ADC_USE_ADC1 TRUE +