1
0
Fork 0
forked from forks/qmk_firmware

bandominedoni, Drashna's method is applied to encoder_update_kb. (#15287)

* Drashna's method is applied to rotary encoder rotation detection. rgb_matrix_user.inc -> rgb_matrix_kb.inc.

* Disabled some RGB MATRIX effects to shrink the firmware size.

* via # of layers changed from 5 to 4.
This commit is contained in:
3araht 2021-12-27 19:27:15 +09:00 committed by GitHub
parent 07465c0ebb
commit 4e077250d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 143 additions and 169 deletions

View file

@ -119,33 +119,53 @@ static enum { UNKNOWN, LEFT, RIGHT } hand_side = UNKNOWN;
}
#ifdef ENCODER_ENABLE
const uint16_t rt_matrix[2][2] = {
{5, 5}, {5, 6}
# ifdef ENCODERS
static uint8_t encoder_state[ENCODERS] = {0};
static keypos_t encoder_cw[ENCODERS] = ENCODERS_CW_KEY;
static keypos_t encoder_ccw[ENCODERS] = ENCODERS_CCW_KEY;
# endif
void encoder_action_unregister(void) {
# ifdef ENCODERS
for (int index = 0; index < ENCODERS; ++index) {
if (encoder_state[index]) {
keyevent_t encoder_event = (keyevent_t) {
.key = encoder_state[index] >> 1 ? encoder_cw[index] : encoder_ccw[index],
.pressed = false,
.time = (timer_read() | 1)
};
encoder_state[index] = 0;
action_exec(encoder_event);
}
}
# endif
}
void encoder_action_register(uint8_t index, bool clockwise) {
# ifdef ENCODERS
keyevent_t encoder_event = (keyevent_t) {
.key = clockwise ? encoder_cw[index] : encoder_ccw[index],
.pressed = true,
.time = (timer_read() | 1)
};
encoder_state[index] = (clockwise ^ 1) | (clockwise << 1);
# ifdef CONSOLE_ENABLE
uprintf("encoder_action_register index = %u, clockwise = %u, row = %u, col = %u\n", index, clockwise, encoder_event.key.row, encoder_event.key.col);
# endif
action_exec(encoder_event);
# endif
}
void matrix_scan_kb(void) {
encoder_action_unregister();
matrix_scan_user();
}
bool encoder_update_kb(uint8_t index, bool clockwise) {
if (index == 1) { /* An encoder on the right side */
keypos_t key;
int cw = 0;
cw = clockwise ? 1 : 0;
key.row = rt_matrix[cw][0];
key.col = rt_matrix[cw][1];
uint8_t layer = layer_switch_get_layer(key);
uint16_t keycode = keymap_key_to_keycode(layer, key);
keyrecord_t record;
record.event.key = key;
if (keycode < MI_ON){
tap_code16(keycode);
} else {
record.event.pressed = true;
process_midi(keycode, &record);
wait_ms(TAP_CODE_DELAY);
record.event.pressed = false;
process_midi(keycode, &record);
}
}
encoder_action_register(index, clockwise);
// don't return user actions, because they are in the keymap
// encoder_update_user(index, clockwise);
return true;
}
#endif // ENCODER_ENABLE
};
#endif

View file

@ -82,3 +82,7 @@
// reason: bandoMIneDonI has no space on right hand side to use "SPLIT_HAND_MATRIX_GRID".
// However, It enables to decide the handedness by the HW by adding one condition: "not to press any keys (especially r30) dusing startup."
bool is_keyboard_left(void);
void encoder_action_unregister(void);
void encoder_action_register(uint8_t index, bool clockwise);

View file

@ -133,120 +133,54 @@
// Enable suspend mode.
# define RGB_DISABLE_WHEN_USB_SUSPENDED true
// // enable below to shrink the firmware size ( -1974 bytes )
// # define REDUCE_RGB_MATRIX_EFFECTS
// enable below to shrink the firmware size ( -1574 bytes )
// # define REDUCE_RGB_MATRIX_EFFECTS_2
// # ifdef AUDIO_ENABLE
# ifdef CONSOLE_ENABLE
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
# else
// #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_PINWHEEL_SAT
// #define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT
// #define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
// #define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS
# define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN
# define ENABLE_RGB_MATRIX_BREATHING
# define ENABLE_RGB_MATRIX_BAND_SAT
# define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT
# define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT
# define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
# define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS
// #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_MULTICROSS
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
# define ENABLE_RGB_MATRIX_SPLASH
# define ENABLE_RGB_MATRIX_SOLID_SPLASH
// RAINDROPS don't match well with layer LED indicator (oc) using rgb_matrix_set_color().
// #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_FRACTAL
# define ENABLE_RGB_MATRIX_PIXEL_RAIN
# if !defined(REDUCE_RGB_MATRIX_EFFECTS) && !defined(VIA_ENABLE)
// # ifdef REDUCE_RGB_MATRIX_EFFECTS
// Recommendend not to use these.
# ifndef VIA_ENABLE
# define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT
# define ENABLE_RGB_MATRIX_BAND_VAL
# define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL
# define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL
# define ENABLE_RGB_MATRIX_CYCLE_OUT_IN
# define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
# define ENABLE_RGB_MATRIX_DUAL_BEACON
# define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL
# define ENABLE_RGB_MATRIX_CYCLE_SPIRAL
# endif
// #define ENABLE_RGB_MATRIX_HUE_BREATHING
// #define ENABLE_RGB_MATRIX_HUE_PENDULUM
// #define ENABLE_RGB_MATRIX_HUE_WAVE
// #define ENABLE_RGB_MATRIX_FRACTAL
// #define ENABLE_RGB_MATRIX_PIXEL_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
# if !defined(REDUCE_RGB_MATRIX_EFFECTS_2) && !defined(VIA_ENABLE)
// # ifdef REDUCE_RGB_MATRIX_EFFECTS_2
# define ENABLE_RGB_MATRIX_BAND_VAL
# define ENABLE_RGB_MATRIX_CYCLE_ALL
# 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_HUE_BREATHING
# define ENABLE_RGB_MATRIX_HUE_PENDULUM
# define ENABLE_RGB_MATRIX_HUE_WAVE
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
# define ENABLE_RGB_MATRIX_MULTISPLASH
# define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
# endif
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE
// #define ENABLE_RGB_MATRIX_SPLASH
// #define ENABLE_RGB_MATRIX_SOLID_SPLASH
# endif // AUDIO_ENABLE
// #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_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
# endif // CONSOLE_ENABLE
#endif // RGB_MATRIX_ENABLE
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
@ -330,4 +264,7 @@
# define ENCODERS_PAD_B_RIGHT { F4 }
# define ENCODER_RESOLUTION 4
# define TAP_CODE_DELAY 10
# define ENCODERS 2
# define ENCODERS_CW_KEY { {4, 5}, {6, 5} }
# define ENCODERS_CCW_KEY { {3, 5}, {5, 5} }
#endif // ENCODER_ENABLE

View file

@ -141,7 +141,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
XXXXXXX, XXXXXXX, AG_NORM, AG_SWAP, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
_______, MI_OCTD, MI_OCTU, MI_VELD, MI_VELU, _______,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_RMOD, RGB_MOD,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
RGB_SAD, RGB_SAI, RGB_HUD, RGB_HUI, RGB_SPD, RGB_SPI, RGB_VAD, RGB_VAI,
@ -149,7 +149,17 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void my_init(void){
// Set octave to MI_OCT_0
midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN;
// avoid using 127 since it is used as a special number in some sound sources.
midi_config.velocity = MIDI_INITIAL_VELOCITY;
}
void eeconfig_init_user(void) { // EEPROM is getting reset!
midi_init();
my_init();
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_enable();
rgb_matrix_set_speed(RGB_MATRIX_STARTUP_SPD);
@ -161,11 +171,7 @@ void eeconfig_init_user(void) { // EEPROM is getting reset!
}
void keyboard_post_init_user(void) {
// Set octave to MI_OCT_0
midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN;
// avoid using 127 since it is used as a special number in some sound sources.
midi_config.velocity = MIDI_INITIAL_VELOCITY;
my_init();
// party mode (for LED soldering test. Enable rainbow color effect, and disable led_indicator to check all LEDs)
rgb_matrix_mode(RGB_MATRIX_RAINBOW_MOVING_CHEVRON);

View file

@ -1,2 +1,2 @@
RGB_MATRIX_ENABLE = yes # Use RGB matrix (Don't enable this when RGBLIGHT_ENABLE is used.)
RGB_MATRIX_CUSTOM_USER = yes #
RGB_MATRIX_CUSTOM_KB = yes #

View file

@ -15,4 +15,4 @@
*/
#pragma once
#define DYNAMIC_KEYMAP_LAYER_COUNT 5
#define DYNAMIC_KEYMAP_LAYER_COUNT 4

View file

@ -82,7 +82,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
_______, MI_OCTD, MI_OCTU, MI_VELD, MI_VELU, _______,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_RMOD, RGB_MOD,
XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
_______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
RGB_SAD, RGB_SAI, RGB_HUD, RGB_HUI, RGB_SPD, RGB_SPI, RGB_VAD, RGB_VAI,
@ -90,7 +90,17 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void my_init(void){
// Set octave to MI_OCT_0
midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN;
// avoid using 127 since it is used as a special number in some sound sources.
midi_config.velocity = MIDI_INITIAL_VELOCITY;
}
void eeconfig_init_user(void) { // EEPROM is getting reset!
midi_init();
my_init();
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_enable();
rgb_matrix_set_speed(RGB_MATRIX_STARTUP_SPD);
@ -102,11 +112,7 @@ void eeconfig_init_user(void) { // EEPROM is getting reset!
}
void keyboard_post_init_user(void) {
// Set octave to MI_OCT_0
midi_config.octave = MI_OCT_0 - MIDI_OCTAVE_MIN;
// avoid using 127 since it is used as a special number in some sound sources.
midi_config.velocity = MIDI_INITIAL_VELOCITY;
my_init();
};
#ifdef RGB_MATRIX_ENABLE

View file

@ -1,3 +1,4 @@
RGB_MATRIX_ENABLE = yes # Use RGB matrix (Don't enable this when RGBLIGHT_ENABLE is used.)
RGB_MATRIX_CUSTOM_KB = yes #
VIA_ENABLE = yes
MOUSEKEY_ENABLE = yes # Mouse keys