forked from mirrors/qmk_firmware
flesh out dip and encoder support
This commit is contained in:
parent
ddee61c9ba
commit
bb71a988c2
4 changed files with 66 additions and 22 deletions
|
@ -25,7 +25,7 @@
|
||||||
/* enable basic MIDI features:
|
/* enable basic MIDI features:
|
||||||
- MIDI notes can be sent when in Music mode is on
|
- MIDI notes can be sent when in Music mode is on
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MIDI_BASIC
|
#define MIDI_BASIC
|
||||||
|
|
||||||
/* enable advanced MIDI features:
|
/* enable advanced MIDI features:
|
||||||
|
@ -39,4 +39,8 @@
|
||||||
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
||||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||||
|
|
||||||
#endif
|
|
||||||
|
// Most tactile encoders have detents every 4 stages
|
||||||
|
#define ENCODER_RESOLUTION 4
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -75,7 +75,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
|
KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
|
||||||
KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
|
KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
|
||||||
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
|
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
|
||||||
KC_SPC, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
|
BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
|
||||||
),
|
),
|
||||||
|
|
||||||
/* Dvorak
|
/* Dvorak
|
||||||
|
@ -266,3 +266,31 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void encoder_update(bool direction) {
|
||||||
|
if (direction) {
|
||||||
|
register_code(KC_PGUP);
|
||||||
|
unregister_code(KC_PGUP);
|
||||||
|
} else {
|
||||||
|
register_code(KC_PGDN);
|
||||||
|
unregister_code(KC_PGDN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dip_update(uint8_t index, bool value) {
|
||||||
|
switch (index) {
|
||||||
|
case 0:
|
||||||
|
if (value) {
|
||||||
|
#ifdef AUDIO_ENABLE
|
||||||
|
PLAY_SONG(plover_song);
|
||||||
|
#endif
|
||||||
|
layer_on(_ADJUST);
|
||||||
|
} else {
|
||||||
|
#ifdef AUDIO_ENABLE
|
||||||
|
PLAY_SONG(plover_gb_song);
|
||||||
|
#endif
|
||||||
|
layer_off(_ADJUST);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -60,11 +60,11 @@
|
||||||
{ k00, k01, k02, k03, k04, k05 }, \
|
{ k00, k01, k02, k03, k04, k05 }, \
|
||||||
{ k10, k11, k12, k13, k14, k15 }, \
|
{ k10, k11, k12, k13, k14, k15 }, \
|
||||||
{ k20, k21, k22, k23, k24, k25 }, \
|
{ k20, k21, k22, k23, k24, k25 }, \
|
||||||
{ k30, k31, k32, k33, k34, k35 }, \
|
{ k30, k31, k32, k39, k3a, k3b }, \
|
||||||
{ k06, k07, k08, k09, k0a, k0b }, \
|
{ k06, k07, k08, k09, k0a, k0b }, \
|
||||||
{ k16, k17, k18, k19, k1a, k1b }, \
|
{ k16, k17, k18, k19, k1a, k1b }, \
|
||||||
{ k26, k27, k28, k29, k2a, k2b }, \
|
{ k26, k27, k28, k29, k2a, k2b }, \
|
||||||
{ k36, k37, k38, k39, k3a, k3b } \
|
{ k36, k37, k38, k33, k34, k35 } \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LAYOUT_planck_1x2uR( \
|
#define LAYOUT_planck_1x2uR( \
|
||||||
|
@ -77,11 +77,11 @@
|
||||||
{ k00, k01, k02, k03, k04, k05 }, \
|
{ k00, k01, k02, k03, k04, k05 }, \
|
||||||
{ k10, k11, k12, k13, k14, k15 }, \
|
{ k10, k11, k12, k13, k14, k15 }, \
|
||||||
{ k20, k21, k22, k23, k24, k25 }, \
|
{ k20, k21, k22, k23, k24, k25 }, \
|
||||||
{ k30, k31, k32, k33, k34, k35 }, \
|
{ k30, k31, k32, k39, k3a, k3b }, \
|
||||||
{ k06, k07, k08, k09, k0a, k0b }, \
|
{ k06, k07, k08, k09, k0a, k0b }, \
|
||||||
{ k16, k17, k18, k19, k1a, k1b }, \
|
{ k16, k17, k18, k19, k1a, k1b }, \
|
||||||
{ k26, k27, k28, k29, k2a, k2b }, \
|
{ k26, k27, k28, k29, k2a, k2b }, \
|
||||||
{ k36, k37, k38, k39, k3a, k3b } \
|
{ k36, k37, k38, k33, k34, k35 } \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LAYOUT_planck_1x2uL( \
|
#define LAYOUT_planck_1x2uL( \
|
||||||
|
@ -94,11 +94,11 @@
|
||||||
{ k00, k01, k02, k03, k04, k05 }, \
|
{ k00, k01, k02, k03, k04, k05 }, \
|
||||||
{ k10, k11, k12, k13, k14, k15 }, \
|
{ k10, k11, k12, k13, k14, k15 }, \
|
||||||
{ k20, k21, k22, k23, k24, k25 }, \
|
{ k20, k21, k22, k23, k24, k25 }, \
|
||||||
{ k30, k31, k32, k33, k34, k35 }, \
|
{ k30, k31, k32, k39, k3a, k3b }, \
|
||||||
{ k06, k07, k08, k09, k0a, k0b }, \
|
{ k06, k07, k08, k09, k0a, k0b }, \
|
||||||
{ k16, k17, k18, k19, k1a, k1b }, \
|
{ k16, k17, k18, k19, k1a, k1b }, \
|
||||||
{ k26, k27, k28, k29, k2a, k2b }, \
|
{ k26, k27, k28, k29, k2a, k2b }, \
|
||||||
{ k36, k37, k38, k39, k3a, k3b } \
|
{ k36, k37, k38, k33, k34, k35 } \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LAYOUT_planck_2x2u( \
|
#define LAYOUT_planck_2x2u( \
|
||||||
|
@ -111,11 +111,11 @@
|
||||||
{ k00, k01, k02, k03, k04, k05 }, \
|
{ k00, k01, k02, k03, k04, k05 }, \
|
||||||
{ k10, k11, k12, k13, k14, k15 }, \
|
{ k10, k11, k12, k13, k14, k15 }, \
|
||||||
{ k20, k21, k22, k23, k24, k25 }, \
|
{ k20, k21, k22, k23, k24, k25 }, \
|
||||||
{ k30, k31, k32, k33, k34, k35 }, \
|
{ k30, k31, k32, k39, k3a, k3b }, \
|
||||||
{ k06, k07, k08, k09, k0a, k0b }, \
|
{ k06, k07, k08, k09, k0a, k0b }, \
|
||||||
{ k16, k17, k18, k19, k1a, k1b }, \
|
{ k16, k17, k18, k19, k1a, k1b }, \
|
||||||
{ k26, k27, k28, k29, k2a, k2b }, \
|
{ k26, k27, k28, k29, k2a, k2b }, \
|
||||||
{ k36, k37, k38, k39, k3a, k3b } \
|
{ k36, k37, k38, k33, k34, k35 } \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LAYOUT_planck_grid( \
|
#define LAYOUT_planck_grid( \
|
||||||
|
@ -128,11 +128,11 @@
|
||||||
{ k00, k01, k02, k03, k04, k05 }, \
|
{ k00, k01, k02, k03, k04, k05 }, \
|
||||||
{ k10, k11, k12, k13, k14, k15 }, \
|
{ k10, k11, k12, k13, k14, k15 }, \
|
||||||
{ k20, k21, k22, k23, k24, k25 }, \
|
{ k20, k21, k22, k23, k24, k25 }, \
|
||||||
{ k30, k31, k32, k33, k34, k35 }, \
|
{ k30, k31, k32, k39, k3a, k3b }, \
|
||||||
{ k06, k07, k08, k09, k0a, k0b }, \
|
{ k06, k07, k08, k09, k0a, k0b }, \
|
||||||
{ k16, k17, k18, k19, k1a, k1b }, \
|
{ k16, k17, k18, k19, k1a, k1b }, \
|
||||||
{ k26, k27, k28, k29, k2a, k2b }, \
|
{ k26, k27, k28, k29, k2a, k2b }, \
|
||||||
{ k36, k37, k38, k39, k3a, k3b } \
|
{ k36, k37, k38, k33, k34, k35 } \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define KEYMAP LAYOUT_planck_grid
|
#define KEYMAP LAYOUT_planck_grid
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "matrix.h"
|
#include "matrix.h"
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
#include "keycode.h"
|
#include "keycode.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* col: { B11, B10, B2, B1, A7, B0 }
|
* col: { B11, B10, B2, B1, A7, B0 }
|
||||||
|
@ -22,7 +23,7 @@ static uint16_t debouncing_time = 0;
|
||||||
|
|
||||||
static uint8_t encoder_state = 0;
|
static uint8_t encoder_state = 0;
|
||||||
static int8_t encoder_value = 0;
|
static int8_t encoder_value = 0;
|
||||||
static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 };
|
static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 };
|
||||||
|
|
||||||
static bool dip_switch[4] = {0, 0, 0, 0};
|
static bool dip_switch[4] = {0, 0, 0, 0};
|
||||||
|
|
||||||
|
@ -83,26 +84,37 @@ void matrix_init(void) {
|
||||||
matrix_init_quantum();
|
matrix_init_quantum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void dip_update(uint8_t index, bool value) { }
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void encoder_update(bool direction) { }
|
||||||
|
|
||||||
|
bool last_dip_switch[4] = {0};
|
||||||
|
|
||||||
uint8_t matrix_scan(void) {
|
uint8_t matrix_scan(void) {
|
||||||
// dip switch
|
// dip switch
|
||||||
dip_switch[0] = palReadPad(GPIOB, 14);
|
dip_switch[0] = palReadPad(GPIOB, 14);
|
||||||
dip_switch[1] = palReadPad(GPIOA, 15);
|
dip_switch[1] = palReadPad(GPIOA, 15);
|
||||||
dip_switch[2] = palReadPad(GPIOA, 10);
|
dip_switch[2] = palReadPad(GPIOA, 10);
|
||||||
dip_switch[3] = palReadPad(GPIOB, 9);
|
dip_switch[3] = palReadPad(GPIOB, 9);
|
||||||
|
for (uint8_t i = 0; i < 4; i++) {
|
||||||
|
if (last_dip_switch[i] ^ dip_switch[i])
|
||||||
|
dip_update(i, dip_switch[i]);
|
||||||
|
}
|
||||||
|
memcpy(last_dip_switch, dip_switch, sizeof(&dip_switch));
|
||||||
|
|
||||||
// encoder on B12 and B13
|
// encoder on B12 and B13
|
||||||
encoder_state <<= 2;
|
encoder_state <<= 2;
|
||||||
encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1);
|
encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1);
|
||||||
encoder_value += encoder_LUT[encoder_state & 0xF];
|
encoder_value += encoder_LUT[encoder_state & 0xF];
|
||||||
if (encoder_value >= 4) {
|
if (encoder_value >= ENCODER_RESOLUTION) {
|
||||||
register_code(KC_MS_WH_UP);
|
encoder_update(1);
|
||||||
unregister_code(KC_MS_WH_UP);
|
|
||||||
}
|
}
|
||||||
if (encoder_value <= -4) {
|
if (encoder_value <= -ENCODER_RESOLUTION) {
|
||||||
register_code(KC_MS_WH_DOWN);
|
encoder_update(0);
|
||||||
unregister_code(KC_MS_WH_DOWN);
|
|
||||||
}
|
}
|
||||||
encoder_value %= 4;
|
encoder_value %= ENCODER_RESOLUTION;
|
||||||
|
|
||||||
// actual matrix
|
// actual matrix
|
||||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||||
|
@ -186,4 +198,4 @@ void matrix_print(void) {
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue