diff options
Diffstat (limited to 'keyboards/tzarc/ghoul/keymaps')
-rw-r--r-- | keyboards/tzarc/ghoul/keymaps/default/config.h | 54 | ||||
-rw-r--r-- | keyboards/tzarc/ghoul/keymaps/default/keymap.c | 75 | ||||
-rw-r--r-- | keyboards/tzarc/ghoul/keymaps/default/rules.mk | 5 | ||||
-rw-r--r-- | keyboards/tzarc/ghoul/keymaps/default/ui.c | 139 |
4 files changed, 273 insertions, 0 deletions
diff --git a/keyboards/tzarc/ghoul/keymaps/default/config.h b/keyboards/tzarc/ghoul/keymaps/default/config.h new file mode 100644 index 0000000000..af069d28cb --- /dev/null +++ b/keyboards/tzarc/ghoul/keymaps/default/config.h @@ -0,0 +1,54 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +// Configurables +#define TAPPING_TERM 200 + +// RGB settings +#define RGB_MATRIX_KEYPRESSES +#define RGB_MATRIX_FRAMEBUFFER_EFFECTS + +// RGB Effects +#define ENABLE_RGB_MATRIX_ALPHAS_MODS +#define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN +#define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT +#define ENABLE_RGB_MATRIX_BREATHING +#define ENABLE_RGB_MATRIX_BAND_SAT +#define ENABLE_RGB_MATRIX_BAND_VAL +#define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +#define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +#define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT +#define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL +#define ENABLE_RGB_MATRIX_CYCLE_ALL +#define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +#define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN +#define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +#define ENABLE_RGB_MATRIX_CYCLE_OUT_IN +#define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +#define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL +#define ENABLE_RGB_MATRIX_CYCLE_SPIRAL +#define ENABLE_RGB_MATRIX_DUAL_BEACON +#define ENABLE_RGB_MATRIX_RAINBOW_BEACON +#define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS +#define ENABLE_RGB_MATRIX_RAINDROPS +#define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS +#define ENABLE_RGB_MATRIX_HUE_BREATHING +#define ENABLE_RGB_MATRIX_HUE_PENDULUM +#define ENABLE_RGB_MATRIX_HUE_WAVE +#define ENABLE_RGB_MATRIX_PIXEL_FRACTAL +#define ENABLE_RGB_MATRIX_PIXEL_RAIN +#define ENABLE_RGB_MATRIX_TYPING_HEATMAP +#define ENABLE_RGB_MATRIX_DIGITAL_RAIN +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS +#define ENABLE_RGB_MATRIX_SPLASH +#define ENABLE_RGB_MATRIX_MULTISPLASH +#define ENABLE_RGB_MATRIX_SOLID_SPLASH +#define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH diff --git a/keyboards/tzarc/ghoul/keymaps/default/keymap.c b/keyboards/tzarc/ghoul/keymaps/default/keymap.c new file mode 100644 index 0000000000..e64270fe4f --- /dev/null +++ b/keyboards/tzarc/ghoul/keymaps/default/keymap.c @@ -0,0 +1,75 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-3.0-or-later +#include QMK_KEYBOARD_H + +enum { _QWERTY, _LOWER, _RAISE, _ADJUST }; + +#define LOWER MO(_LOWER) +#define RAISE MO(_RAISE) + +// Left-hand home row mods +#define HOME_A LGUI_T(KC_A) +#define HOME_S LALT_T(KC_S) +#define HOME_D LSFT_T(KC_D) +#define HOME_F LCTL_T(KC_F) + +// Right-hand home row mods +#define HOME_J RCTL_T(KC_J) +#define HOME_K RSFT_T(KC_K) +#define HOME_L LALT_T(KC_L) +#define HOME_SCLN RGUI_T(KC_SCLN) + +#define SFT_ESC LSFT_T(KC_ESC) + +extern void ui_init(void); +extern void ui_task(void); + +// clang-format off +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_QWERTY] = LAYOUT( + KC_Q, KC_W, KC_E, KC_R, KC_T, RGB_MOD, KC_Y, KC_U, KC_I, KC_O, KC_P, + HOME_A, HOME_S, HOME_D, HOME_F, KC_G, KC_H, HOME_J, HOME_K, HOME_L, HOME_SCLN, + KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, + SFT_ESC, KC_LCTL, KC_LGUI, KC_SPC, LOWER, RAISE, KC_SPC, KC_LALT, KC_BSPC, KC_SFTENT + ), + [_LOWER] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_MOD, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ), + [_RAISE] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_MOD, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ), + [_ADJUST] = LAYOUT( + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_MOD, KC_TRNS, KC_TRNS, DEBUG, EEP_RST, QK_BOOT, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, + KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS + ) +}; +// clang-format on + +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { + [_QWERTY] = {ENCODER_CCW_CW(RGB_HUI, RGB_HUD)}, + [_LOWER] = {ENCODER_CCW_CW(RGB_HUI, RGB_HUD)}, + [_RAISE] = {ENCODER_CCW_CW(RGB_HUI, RGB_HUD)}, + [_ADJUST] = {ENCODER_CCW_CW(RGB_HUI, RGB_HUD)}, +}; + +layer_state_t layer_state_set_user(layer_state_t state) { + return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST); +} + +void keyboard_post_init_user(void) { + // Init the display + ui_init(); +} + +void housekeeping_task_user(void) { + // Draw the display + ui_task(); +} diff --git a/keyboards/tzarc/ghoul/keymaps/default/rules.mk b/keyboards/tzarc/ghoul/keymaps/default/rules.mk new file mode 100644 index 0000000000..8da104df85 --- /dev/null +++ b/keyboards/tzarc/ghoul/keymaps/default/rules.mk @@ -0,0 +1,5 @@ +NKRO_ENABLE = yes +ENCODER_MAP_ENABLE = yes +DEBUG_MATRIX_SCAN_RATE_ENABLE = yes +WPM_ENABLE = yes +SRC += ui.c diff --git a/keyboards/tzarc/ghoul/keymaps/default/ui.c b/keyboards/tzarc/ghoul/keymaps/default/ui.c new file mode 100644 index 0000000000..ac56e52d19 --- /dev/null +++ b/keyboards/tzarc/ghoul/keymaps/default/ui.c @@ -0,0 +1,139 @@ +// Copyright 2018-2022 Nick Brassel (@tzarc) +// SPDX-License-Identifier: GPL-3.0-or-later +#include <stdio.h> +#include QMK_KEYBOARD_H +#include "analog.h" +#include "qp.h" +#include "qp_ssd1351.h" + +#define NUM_ADC_READS 32 + +#include "graphics/ghoul-logo.qgf.c" +#include "graphics/ghoul-name.qgf.c" +#include "graphics/lock-caps.qgf.c" +#include "graphics/lock-num.qgf.c" +#include "graphics/lock-scrl.qgf.c" +#include "graphics/thintel15.qff.c" + +static painter_device_t oled; +static painter_image_handle_t logo; +static painter_image_handle_t name; +static painter_font_handle_t font; +static painter_image_handle_t lock_caps; +static painter_image_handle_t lock_num; +static painter_image_handle_t lock_scrl; + +void ui_init(void) { + oled = qp_ssd1351_make_spi_device(128, 128, OLED_CS_PIN, OLED_DC_PIN, OLED_RST_PIN, 8, 0); + logo = qp_load_image_mem(gfx_ghoul_logo); + name = qp_load_image_mem(gfx_ghoul_name); + font = qp_load_font_mem(font_thintel15); + lock_caps = qp_load_image_mem(gfx_lock_caps); + lock_num = qp_load_image_mem(gfx_lock_num); + lock_scrl = qp_load_image_mem(gfx_lock_scrl); + + qp_init(oled, QP_ROTATION_90); + qp_rect(oled, 0, 0, 127, 127, 0, 0, 0, true); + qp_flush(oled); +} + +void ui_task(void) { + bool hue_redraw = false; + static uint16_t last_hue = 0xFFFF; + uint8_t curr_hue = rgblight_get_hue(); + if (last_hue != curr_hue) { + last_hue = curr_hue; + hue_redraw = true; + } + + if (hue_redraw) { + qp_drawimage_recolor(oled, 0, 64 - (name->height / 2), name, curr_hue, 255, 255, curr_hue, 255, 0); + qp_drawimage_recolor(oled, 127 - logo->width, 0, logo, curr_hue, 255, 255, curr_hue, 255, 0); + } + + static led_t last_led_state = {0}; + if (hue_redraw || last_led_state.raw != host_keyboard_led_state().raw) { + last_led_state.raw = host_keyboard_led_state().raw; + qp_drawimage_recolor(oled, lock_caps->width * 0, 0, lock_caps, curr_hue, 255, last_led_state.caps_lock ? 255 : 32, curr_hue, 255, 0); + qp_drawimage_recolor(oled, lock_caps->width * 1, 0, lock_num, curr_hue, 255, last_led_state.num_lock ? 255 : 32, curr_hue, 255, 0); + qp_drawimage_recolor(oled, lock_caps->width * 2, 0, lock_scrl, curr_hue, 255, last_led_state.scroll_lock ? 255 : 32, curr_hue, 255, 0); + + qp_rect(oled, lock_caps->width * 0 + 1, lock_caps->height + 2, lock_caps->width * 1 - 1, lock_caps->height + 3, curr_hue, 255, last_led_state.caps_lock ? 255 : 0, true); + qp_rect(oled, lock_caps->width * 1 + 1, lock_caps->height + 2, lock_caps->width * 2 - 1, lock_caps->height + 3, curr_hue, 255, last_led_state.num_lock ? 255 : 0, true); + qp_rect(oled, lock_caps->width * 2 + 1, lock_caps->height + 2, lock_caps->width * 3 - 1, lock_caps->height + 3, curr_hue, 255, last_led_state.scroll_lock ? 255 : 0, true); + } + +#if HAL_USE_ADC + static int16_t current_reads[NUM_ADC_READS] = {0}; + static int16_t voltage_reads[NUM_ADC_READS] = {0}; + static int write_offset = 0; + + static uint32_t last_read = 0; + if (timer_elapsed32(last_read) >= 1) { + // Perform the reads + int16_t current = analogReadPin(ADC_CURRENT_PIN); + int16_t voltage = analogReadPin(ADC_VOLTAGE_PIN); + int16_t current_ma = (int16_t)(((3300 * (int32_t)current) / ADC_SATURATION)); + int16_t voltage_mv = (int16_t)((2 * (3300 * (int32_t)voltage)) / ADC_SATURATION); + + // Duplicate the first read so that averages work + if (last_read == 0) { + for (int i = 0; i < NUM_ADC_READS; ++i) { + current_reads[i] = current_ma; + voltage_reads[i] = voltage_mv; + } + } + + // Dump in the current value + current_reads[write_offset] = current_ma; + voltage_reads[write_offset] = voltage_mv; + write_offset = (write_offset + 1) % NUM_ADC_READS; + + static int counter = 0; + counter = (counter + 1) % 2500; + if (counter == 0) { + dprintf("Current: %dmA (%d) -- Voltage: %dmV (%d)\n", (int)current_ma, (int)current, (int)voltage_mv, (int)voltage); + } + + last_read = timer_read32(); + } + + static uint32_t last_draw = 0; + if (hue_redraw || timer_elapsed32(last_draw) >= 250) { + // Accumulate + int32_t total_current_ma = 0; + int32_t total_voltage_mv = 0; + for (int i = 0; i < NUM_ADC_READS; ++i) { + total_current_ma += current_reads[i]; + total_voltage_mv += voltage_reads[i]; + } + + // Get the averages + int16_t avg_current_ma = (int16_t)(total_current_ma / NUM_ADC_READS); + int16_t avg_voltage_mv = (int16_t)(total_voltage_mv / NUM_ADC_READS); + + char buf[32] = {0}; + sprintf(buf, "Current: %dmA", avg_current_ma); + static int16_t maxlen_curr = 0; + int16_t len = qp_drawtext_recolor(oled, 0, 127 - (font->line_height * 2), font, buf, 0, 0, 32, 0, 0, 0); + if (len < maxlen_curr) { + qp_rect(oled, len, 127 - (font->line_height * 2), maxlen_curr, 127 - (font->line_height * 1), 0, 0, 0, true); + } else if (len > maxlen_curr) { + maxlen_curr = len; + } + + static int16_t maxlen_volt = 0; + sprintf(buf, "Voltage: %dmV", avg_voltage_mv); + len = qp_drawtext_recolor(oled, 0, 127 - (font->line_height * 1), font, buf, 0, 0, 32, 0, 0, 0); + if (len < maxlen_volt) { + qp_rect(oled, len, 127 - (font->line_height * 1), maxlen_volt, 127 - (font->line_height * 0), 0, 0, 0, true); + } else if (len > maxlen_volt) { + maxlen_volt = len; + } + + qp_flush(oled); + + last_draw = timer_read32(); + } +#endif // HAL_USE_ADC +} |