diff options
author | Jay Greco <jayv.greco@gmail.com> | 2023-04-02 12:12:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-02 12:12:06 -0700 |
commit | 27e6e27d3a2ff9d91bcf0f189cdc39509bef0335 (patch) | |
tree | 3cd569d4eb6aaacec06ab81878190284659c56e9 /keyboards/nullbitsco/snap/keymaps/oled | |
parent | 5687fc76468803db27dd9f04a72766f80141c6cd (diff) |
[Keyboard] Add nullbits SNAP keyboard (#18916)
Co-authored-by: Ryan <fauxpark@gmail.com>
Diffstat (limited to 'keyboards/nullbitsco/snap/keymaps/oled')
-rw-r--r-- | keyboards/nullbitsco/snap/keymaps/oled/config.h | 27 | ||||
-rw-r--r-- | keyboards/nullbitsco/snap/keymaps/oled/keymap.c | 163 | ||||
-rw-r--r-- | keyboards/nullbitsco/snap/keymaps/oled/oled_graphics.h | 82 | ||||
-rw-r--r-- | keyboards/nullbitsco/snap/keymaps/oled/rules.mk | 5 |
4 files changed, 277 insertions, 0 deletions
diff --git a/keyboards/nullbitsco/snap/keymaps/oled/config.h b/keyboards/nullbitsco/snap/keymaps/oled/config.h new file mode 100644 index 0000000000..d2000ce589 --- /dev/null +++ b/keyboards/nullbitsco/snap/keymaps/oled/config.h @@ -0,0 +1,27 @@ +/* Copyright 2021 Jay Greco + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#pragma once + +/* space savers */ +#define DYNAMIC_KEYMAP_LAYER_COUNT 3 +#define NO_ACTION_TAPPING +#define NO_ACTION_ONESHOT +#define TAPPING_FORCE_HOLD + +#define OLED_BRIGHTNESS 128 +#define OLED_TIMEOUT 30000 +#define OLED_UPDATE_INTERVAL 250 diff --git a/keyboards/nullbitsco/snap/keymaps/oled/keymap.c b/keyboards/nullbitsco/snap/keymaps/oled/keymap.c new file mode 100644 index 0000000000..4e566fa3ee --- /dev/null +++ b/keyboards/nullbitsco/snap/keymaps/oled/keymap.c @@ -0,0 +1,163 @@ +/* Copyright 2021 Jay Greco + * + * 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 <http://www.gnu.org/licenses/>. + */ +#include QMK_KEYBOARD_H +#include "oled_graphics.h" + +// clang-format off +enum layers { + _BASE, + _VIA1, + _VIA2 +}; + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BASE] = LAYOUT_all( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_PAUS, + KC_F13, KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_DEL, KC_HOME, + KC_F14, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_END, + KC_F15, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP, + KC_F16, KC_LSFT, KC_NUHS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN, + KC_F17, KC_LCTL, KC_LGUI, KC_LALT, MO(_VIA1), KC_SPC, KC_SPC, MO(_VIA1), KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT + ), + [_VIA1] = LAYOUT_all( + QK_BOOT,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO + ), + [_VIA2] = LAYOUT_all( + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, + KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO + ) +}; +// clang-format on + +#if defined(ENCODER_MAP_ENABLE) +const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = { + [_BASE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU), ENCODER_CCW_CW(KC_MPRV, KC_MNXT) }, + [_VIA1] = { ENCODER_CCW_CW(KC_NO, KC_NO), ENCODER_CCW_CW(KC_NO, KC_NO) }, + [_VIA2] = { ENCODER_CCW_CW(KC_NO, KC_NO), ENCODER_CCW_CW(KC_NO, KC_NO) } +}; +#endif + + +// Decompress and write a precompressed bitmap frame to the OLED. +// Documentation and python compression script available at: +// https://github.com/nullbitsco/squeez-o +#ifdef USE_OLED_BITMAP_COMPRESSION +static void oled_write_compressed_P(const char* input_block_map, const char* input_block_list) { + uint16_t block_index = 0; + for (uint16_t i = 0; i < NUM_OLED_BYTES; i++) { + uint8_t bit = i % 8; + uint8_t map_index = i / 8; + uint8_t _block_map = (uint8_t)pgm_read_byte_near(input_block_map + map_index); + uint8_t nonzero_byte = (_block_map & (1 << bit)); + if (nonzero_byte) { + const char data = (const char)pgm_read_byte_near(input_block_list + block_index++); + oled_write_raw_byte(data, i); + } else { + const char data = (const char)0x00; + oled_write_raw_byte(data, i); + } + } +} +#endif + +oled_rotation_t oled_init_user(oled_rotation_t rotation) { + if (is_keyboard_left()) + return OLED_ROTATION_0; + else + return OLED_ROTATION_180; +} + +static void render_nullbits_logo(void) { +#ifdef USE_OLED_BITMAP_COMPRESSION + oled_write_compressed_P(nullbits_logo_block_map, nullbits_logo_bmp); +#else + oled_write_raw_P(nullbits_logo, sizeof(nullbits_logo)); +#endif +} + +static void render_status(void) { + oled_set_cursor(0, 0); + oled_write_P(PSTR("SNAP75 "), false); + oled_write_P(PSTR("Layer "), false); + switch (get_highest_layer(layer_state)) { + case _VIA1: + oled_write_P(PSTR("FN1 "), false); + break; + case _VIA2: + oled_write_P(PSTR("FN2 "), false); + break; + default: // use BASE case as default + oled_write_P(PSTR("Base"), false); + } + + // Host Keyboard LED Status + oled_set_cursor(0, 1); + static uint8_t persistent_led_state = 0; + uint8_t led_usb_state = host_keyboard_leds(); + + // Only update if the LED state has changed + // Otherwise, the OLED will not turn off if an LED is on. + if (persistent_led_state != led_usb_state) { + persistent_led_state = led_usb_state; + + oled_write_ln_P(PSTR(""), false); + + if (IS_LED_ON(led_usb_state, USB_LED_CAPS_LOCK)) { + oled_set_cursor(0, 1); + oled_write_P(PSTR("CAPS"), false); + } + + if (IS_LED_ON(led_usb_state, USB_LED_NUM_LOCK)) { + oled_set_cursor(5, 1); + oled_write_P(PSTR("NUM"), true); + } + + if (IS_LED_ON(led_usb_state, USB_LED_SCROLL_LOCK)) { + oled_set_cursor(9, 1); + oled_write_P(PSTR("SCR"), false); + } + } + + // WPM and max WPM + oled_set_cursor(0, 2); + oled_write_P(PSTR("WPM "), false); + uint8_t current_wpm = get_current_wpm(); + oled_write(get_u8_str(current_wpm, '0'), true); + + oled_set_cursor(8, 2); + oled_write_P(PSTR("MAX "), false); + static uint8_t max_wpm; + max_wpm = MAX(max_wpm, current_wpm); + oled_write(get_u8_str(max_wpm, '0'), true); +} + +bool oled_task_user(void) { + if (is_keyboard_master()) { + render_status(); + } else { + render_nullbits_logo(); + } + return true; +} diff --git a/keyboards/nullbitsco/snap/keymaps/oled/oled_graphics.h b/keyboards/nullbitsco/snap/keymaps/oled/oled_graphics.h new file mode 100644 index 0000000000..487bb5974e --- /dev/null +++ b/keyboards/nullbitsco/snap/keymaps/oled/oled_graphics.h @@ -0,0 +1,82 @@ +/* Copyright 2022 Jay Greco + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#define NUM_OLED_BYTES 512 +#define USE_OLED_BITMAP_COMPRESSION + +#ifdef USE_OLED_BITMAP_COMPRESSION +static const char PROGMEM nullbits_logo_block_map[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x7c, 0x78, 0x00, 0xf0, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0xf7, 0x0f, 0x1e, 0x3c, 0x3c, 0x7c, 0xf8, 0x3f, 0xf0, 0xf9, 0x3f, 0xff, 0x0f, 0x00, + 0x00, 0x80, 0xf7, 0x1f, 0x1e, 0x3c, 0x3c, 0x7c, 0xf8, 0xff, 0xe1, 0xf9, 0xbf, 0xff, 0x0f, 0x00, + 0x00, 0x80, 0x07, 0x1e, 0xfe, 0x3f, 0x3c, 0x7c, 0xf8, 0xff, 0xe1, 0xc1, 0x83, 0xff, 0x0f, 0x00 +}; + +static const char PROGMEM nullbits_logo_bmp[] = { + 0xf6, 0xff, 0xff, 0xfe, 0xe4, 0xfe, 0xff, 0xfe, 0xf4, 0xfe, 0xff, 0xfe, 0xfe, 0xc0, 0xe0, 0xe0, + 0xe0, 0xe0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x80, 0xc0, 0xe0, + 0xe0, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0, 0xc0, 0x80, 0x01, 0xc3, 0xe3, 0xe3, 0xc3, 0xc0, + 0xe0, 0xe0, 0xfe, 0xfe, 0xff, 0xfe, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, + 0xe0, 0xe0, 0xc0, 0xe0, 0xe0, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x01, 0x01, 0x01, 0x03, 0x03, 0xff, + 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x01, 0x03, 0x03, 0x07, 0x0f, 0xff, 0xff, + 0xfe, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x01, 0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0x01, 0x01, 0x01, + 0x01, 0x1e, 0x3f, 0x7f, 0xff, 0xfb, 0xf3, 0xf1, 0xe1, 0xe1, 0xe1, 0xc1, 0x81, 0x01, 0x7f, 0xff, + 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x0f, 0x3f, 0x7f, 0xff, 0xf8, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, + 0x7f, 0x3f, 0x1f, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff, 0xff, 0x7f, + 0xf0, 0xf0, 0xf0, 0xf8, 0x78, 0x7e, 0x3f, 0x3f, 0x1f, 0x07, 0xff, 0xff, 0xff, 0x7f, 0x7f, 0xff, + 0xff, 0xff, 0x70, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xfb, 0x7f, 0x7f, 0x3f, 0x1f +}; + +#else +static const char PROGMEM nullbits_logo[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf6, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xe4, 0xfe, 0xff, 0xfe, 0xf4, 0x00, + 0x00, 0x00, 0x00, 0xfe, 0xff, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, + 0xe0, 0xe0, 0xe0, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0xe0, 0xe0, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xe0, 0xe0, 0xc0, 0xc0, 0xc0, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0xe3, 0xe3, 0xc3, 0x00, 0x00, 0xc0, 0xe0, 0xe0, 0xfe, 0xfe, + 0xff, 0xfe, 0xe0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xc0, 0xe0, 0xe0, 0xe0, 0xe0, + 0xc0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x01, 0x01, 0x03, 0x03, 0x07, 0x0f, 0xff, 0xff, 0xfe, + 0xfc, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x01, 0x01, 0x01, 0xff, 0xff, + 0xff, 0xff, 0x01, 0x01, 0x01, 0x01, 0x00, 0x1e, 0x3f, 0x7f, 0xff, 0xfb, 0xf3, 0xf1, 0xe1, 0xe1, + 0xe1, 0xc1, 0x81, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x0f, 0x3f, 0x7f, 0xff, 0xf8, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0x7f, 0x3f, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0x00, + 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0x7f, 0xf0, 0xf0, 0xf0, 0xf8, 0x78, 0x7e, 0x3f, 0x3f, 0x1f, + 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf1, 0xf1, 0xfb, + 0x7f, 0x7f, 0x3f, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +#endif diff --git a/keyboards/nullbitsco/snap/keymaps/oled/rules.mk b/keyboards/nullbitsco/snap/keymaps/oled/rules.mk new file mode 100644 index 0000000000..d0a184e961 --- /dev/null +++ b/keyboards/nullbitsco/snap/keymaps/oled/rules.mk @@ -0,0 +1,5 @@ +OLED_ENABLE = yes +OLED_DRIVER = SSD1306 +WPM_ENABLE = yes +VIA_ENABLE = yes +ENCODER_MAP_ENABLE = yes |