Skip to content

Commit

Permalink
[Keymap] Drashna's OLED rewrite (#15981)
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Jan 22, 2022
1 parent 8901c9e commit b090ff0
Show file tree
Hide file tree
Showing 30 changed files with 1,773 additions and 292 deletions.
2 changes: 0 additions & 2 deletions keyboards/handwired/tractyl_manuform/5x6_right/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define NO_ACTION_MACRO
#define NO_ACTION_FUNCTION

#define OLED_DISPLAY_128X64

#define POINTING_DEVICE_TASK_THROTTLE
#define POINTING_DEVICE_RIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define RGBLED_SPLIT \
{ 10, 10 }
#define RGBLIGHT_LIMIT_VAL 80
#define OLED_BRIGHTNESS 50

#define AUDIO_PIN C6

Expand Down
11 changes: 7 additions & 4 deletions keyboards/handwired/tractyl_manuform/5x6_right/f411/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//#define WS2812_PWM_COMPLEMENTARY_OUTPUT // Define for a complementary timer output (TIMx_CHyN); omit for a normal timer output (TIMx_CHy).
#define WS2812_DMA_STREAM STM32_DMA1_STREAM7 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.
#define WS2812_DMA_CHANNEL 3 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.
#define WS2812_PWM_TARGET_PERIOD 800000


#define RGBLED_NUM 52
#define RGBLIGHT_SPLIT
#define RGBLED_SPLIT \
{ 26, 26 }
#define RGBLIGHT_LIMIT_VAL 150

#define DEBUG_LED_PIN C13

Expand All @@ -68,16 +69,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define SERIAL_USART_RX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
#define SERIAL_USART_TIMEOUT 100 // USART driver timeout. default 100


#define CRC8_USE_TABLE
#define CRC8_OPTIMIZE_SPEED

/* i2c config for oleds */
#define I2C_DRIVER I2CD1
#define I2C1_SCL_PIN B8
#define I2C1_SDA_PIN B9
#define I2C1_SCL_PAL_MODE 4
#define I2C1_SDA_PAL_MODE 4
// #define I2C1_CLOCK_SPEED 400000
/* For Legacy Compatibility: */
#define I2C1_SCL 8
#define I2C1_SDA 9

/* encoder config */
#define ENCODERS_PAD_A \
Expand Down Expand Up @@ -110,3 +112,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define PMW3360_CS_PIN B0
#define PMW3360_SPI_MODE 3
#define PMW3360_SPI_DIVISOR 64
#define PMW3360_FIRMWARE_UPLOAD_FAST
20 changes: 20 additions & 0 deletions keyboards/handwired/tractyl_manuform/5x6_right/f411/post_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#ifndef RGBLIGHT_LIMIT_VAL
# if defined(OLED_ENABLE)
# define RGBLIGHT_LIMIT_VAL 100
# else
# define RGBLIGHT_LIMIT_VAL 150
# endif
#endif

#ifndef OLED_BRIGHTNESS
# ifdef RGBLIGHT_ENABLE
# define OLED_BRIGHTNESS 80
# else
# define OLED_BRIGHTNESS 150
# endif
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@

#define TRACKBALL_DPI_OPTIONS { 1200, 1800, 2600, 3400 }

#define DEBOUNCE 45
#define DEBOUNCE 60
#define ENCODER_DEFAULT_POS 0x3

#ifdef OLED_DRIVER_SH1107
# undef OLED_DISPLAY_128X64
#endif

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ ifeq ($(strip $(KEYBOARD)), handwired/tractyl_manuform/5x6_right/teensy2pp)
CAPS_WORD_ENABLE = yes
endif
# DEBOUNCE_TYPE = sym_eager_pk

OLED_DRIVER = custom
2 changes: 2 additions & 0 deletions keyboards/handwired/tractyl_manuform/tractyl_manuform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef struct {
uint16_t device_cpi;
} kb_config_data_t;

extern kb_config_data_t kb_config;

void trackball_set_cpi(uint16_t cpi);
void matrix_init_sub_kb(void);
void matrix_scan_sub_kb(void);
Expand Down
2 changes: 1 addition & 1 deletion keyboards/moonlander/keymaps/drashna/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KEYLOCK, _________________ADJUST_L2_________________, _______, _______, _________________ADJUST_R2_________________, RGB_IDL,
UC_MOD, _________________ADJUST_L3_________________, _________________ADJUST_R3_________________, TG_MODS,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, AUTO_CTN,
_______, _______, _______, _______, _______, _______
REBOOT, _______, _______, _______, _______, _______
),
};

Expand Down
2 changes: 1 addition & 1 deletion keyboards/splitkb/kyria/keymaps/drashna/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_MAKE, _________________ADJUST_L1_________________, _________________ADJUST_R1_________________, KC_RESET,
VRSN, _________________ADJUST_L2_________________, _________________ADJUST_R2_________________, EEP_RST,
UC_MOD, _________________ADJUST_L3_________________, HPT_TOG, HPT_FBK, MG_NKRO, UC_MOD, _________________ADJUST_R3_________________, TG_MODS,
_______, _______, KEYLOCK, KC_NUKE, _______, _______, _______, _______, _______, _______
REBOOT, _______, KEYLOCK, KC_NUKE, _______, _______, _______, _______, _______, AUTO_CTN
),
// [_LAYERINDEX] = LAYOUT_wrapper(
// _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
Expand Down
4 changes: 0 additions & 4 deletions layouts/community/ergodox/drashna/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

#include "drashna.h"

#ifdef UNICODEMAP_ENABLE
# include "drashna_unicode.h"
#endif // UNICODEMAP_ENABLE
#include "drivers/sensors/pimoroni_trackball.h"
enum more_custom_keycodes {
KC_SWAP_NUM = NEW_SAFE_RANGE,
PM_SCROLL,
Expand Down
3 changes: 0 additions & 3 deletions layouts/community/ergodox/drashna/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ BOOTMAGIC_ENABLE = yes # Enable Bootmagic Lite
TAP_DANCE_ENABLE = no
COMMAND_ENABLE = no # Commands for debug and configuration
CONSOLE_ENABLE = no
SPACE_CADET_ENABLE = no

ifeq ($(strip $(KEYBOARD)), ergodox_ez)
RGBLIGHT_ENABLE = yes
Expand All @@ -16,5 +15,3 @@ endif
UNICODE_ENABLE = no
UNICDOEMAP_ENABLE = no
CUSTOM_UNICODE_ENABLE = no

DEBOUNCE_TYPE = sym_eager_pr
2 changes: 1 addition & 1 deletion layouts/community/ortho_4x12/drashna/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_MAKE, _________________ADJUST_L1_________________, _________________ADJUST_R1_________________, KC_RST,
VRSN, _________________ADJUST_L2_________________, _________________ADJUST_R2_________________, EEP_RST,
TH_LVL, _________________ADJUST_L3_________________, _________________ADJUST_R3_________________, RGB_IDL,
KEYLOCK, _______, _______, _______, _______, KC_NUKE, _______, _______, _______, _______, _______, TG_MODS
KEYLOCK, _______, _______, REBOOT, _______, KC_NUKE, _______, _______, AUTO_CTN,_______, _______, TG_MODS
)

};
Expand Down
2 changes: 1 addition & 1 deletion layouts/community/split_3x6_3/drashna/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_MAKE, _________________ADJUST_L1_________________, _________________ADJUST_R1_________________, KC_RESET,
VRSN, _________________ADJUST_L2_________________, _________________ADJUST_R2_________________, EEP_RST,
KEYLOCK, _________________ADJUST_L3_________________, _________________ADJUST_R3_________________, RGB_IDL,
AUTO_CTN,KC_NUKE, _______, _______, TG_MODS, HPT_FBK
REBOOT, KC_NUKE, _______, _______, TG_MODS, AUTO_CTN
)
};
// clang-format on
Expand Down
15 changes: 9 additions & 6 deletions users/drashna/callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ void shutdown_user(void) {
__attribute__((weak)) void suspend_power_down_keymap(void) {}

void suspend_power_down_user(void) {
if (layer_state_is(_GAMEPAD)) {
layer_off(_GAMEPAD);
}
if (layer_state_is(_DIABLO)) {
layer_off(_DIABLO);
}
if (layer_state_is(_DIABLOII)) {
layer_off(_DIABLOII);
}
#ifdef OLED_ENABLE
oled_off();
#endif
Expand All @@ -78,12 +87,6 @@ void suspend_power_down_user(void) {

__attribute__((weak)) void suspend_wakeup_init_keymap(void) {}
void suspend_wakeup_init_user(void) {
if (layer_state_is(_GAMEPAD)) {
layer_off(_GAMEPAD);
}
if (layer_state_is(_DIABLO)) {
layer_off(_DIABLO);
}
suspend_wakeup_init_keymap();
}

Expand Down
20 changes: 19 additions & 1 deletion users/drashna/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# define SELECT_SOFT_SERIAL_SPEED 1
# endif
# ifdef CUSTOM_SPLIT_TRANSPORT_SYNC
# define SPLIT_TRANSACTION_IDS_USER RPC_ID_USER_STATE_SYNC, RPC_ID_USER_KEYMAP_SYNC, RPC_ID_USER_CONFIG_SYNC, RPC_ID_USER_WATCHDOG_SYNC
# define SPLIT_TRANSACTION_IDS_USER RPC_ID_USER_STATE_SYNC, RPC_ID_USER_KEYMAP_SYNC, RPC_ID_USER_CONFIG_SYNC, RPC_ID_USER_WATCHDOG_SYNC, RPC_ID_USER_KEYLOG_STR
# endif
#endif

Expand Down Expand Up @@ -271,3 +271,21 @@
# define C14 PAL_LINE(GPIOC, 14)
# define C15 PAL_LINE(GPIOC, 15)
#endif

#ifdef OLED_DRIVER_SH1107
# define OLED_DISPLAY_CUSTOM
# define OLED_IC_SH1107 2
# define OLED_DISPLAY_128X128
# define OLED_DISPLAY_WIDTH 128
# define OLED_DISPLAY_HEIGHT 128
# define OLED_MATRIX_SIZE (OLED_DISPLAY_HEIGHT / 8 * OLED_DISPLAY_WIDTH)
# define OLED_BLOCK_TYPE uint16_t
# define OLED_SOURCE_MAP \
{ 0, 8, 16, 24, 32, 40, 48, 56 }
# define OLED_TARGET_MAP \
{ 56, 48, 40, 32, 24, 16, 8, 0 }
# define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8)
# define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT)
# define OLED_COM_PINS COM_PINS_ALT
# define OLED_IC OLED_IC_SH1107
#endif
96 changes: 84 additions & 12 deletions users/drashna/drashna.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,37 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include "drashna.h"
#ifdef __AVR__
# include <avr/wdt.h>
#endif

userspace_config_t userspace_config;

/**
* @brief Handle registering a keycode, with optional modifer based on timed event
*
* @param code keycode to send to host
* @param mod_code modifier to send with code, if held for tapping term or longer
* @param pressed the press/release event (can use "record->event.pressed" for this)
* @return true exits function
* @return false exits function
*/
bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
static uint16_t this_timer;
if (pressed) {
this_timer = timer_read();
} else {
if (timer_elapsed(this_timer) < TAPPING_TERM) {
tap_code(code);
} else {
register_code(mod_code);
tap_code(code);
unregister_code(mod_code);
}
}
mod_key_press(code, mod_code, pressed, this_timer);
return false;
}

/**
* @brief Handle registation of keycode, with optional modifier based on custom timer
*
* @param code keycode to send to host
* @param mod_code modifier keycode to send with code, if held for tapping term or longer
* @param pressed the press/release event
* @param this_timer custom timer to use
* @return true
* @return false
*/
bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
if (pressed) {
this_timer = timer_read();
Expand All @@ -36,17 +48,77 @@ bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this
return false;
}

/**
* @brief Performs exact match for modifier values
*
* @param value the modifer varible (get_mods/get_oneshot_mods/get_weak_mods)
* @param mask the modifier mask to check for
* @return true Has the exact modifiers specifed
* @return false Does not have the exact modifiers specified
*/
bool hasAllBitsInMask(uint8_t value, uint8_t mask) {
value &= 0xF;
mask &= 0xF;

return (value & mask) == mask;
}

void tap_code16_nomods(uint8_t kc) {
/**
* @brief Tap keycode, with no mods
*
* @param kc keycode to use
*/
void tap_code16_nomods(uint16_t kc) {
uint8_t temp_mod = get_mods();
clear_mods();
clear_oneshot_mods();
tap_code16(kc);
set_mods(temp_mod);
}

/**
* @brief Run shutdown routine and soft reboot firmware.
*
*/

#ifdef HAPTIC_ENABLE
# include "haptic.h"
#endif

#ifdef AUDIO_ENABLE
# ifndef GOODBYE_SONG
# define GOODBYE_SONG SONG(GOODBYE_SOUND)
# endif
float reset_song[][2] = GOODBYE_SONG;
#endif

void software_reset(void) {
clear_keyboard();
#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
process_midi_all_notes_off();
#endif
#ifdef AUDIO_ENABLE
# ifndef NO_MUSIC_MODE
music_all_notes_off();
# endif
uint16_t timer_start = timer_read();
PLAY_SONG(reset_song);
shutdown_user();
while (timer_elapsed(timer_start) < 250) wait_ms(1);
stop_all_notes();
#else
shutdown_user();
wait_ms(250);
#endif
#ifdef HAPTIC_ENABLE
haptic_shutdown();
#endif

#if defined(PROTOCOL_LUFA)
wdt_enable(WDTO_250MS);
#elif defined(PROTOCOL_CHIBIOS)
# if defined(MCU_STM32) || defined(MCU_KINETIS)
NVIC_SystemReset();
# endif
#endif
}
3 changes: 2 additions & 1 deletion users/drashna/drashna.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ enum userspace_layers {
bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed);
bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer);
bool hasAllBitsInMask(uint8_t value, uint8_t mask);
void tap_code16_nomods(uint8_t kc);
void tap_code16_nomods(uint16_t kc);
void software_reset(void);

// clang-format off
typedef union {
Expand Down
Loading

0 comments on commit b090ff0

Please sign in to comment.