use encoders for thk
This commit is contained in:
parent
44e7bdf52b
commit
3a64a9c55e
4 changed files with 14 additions and 53 deletions
|
@ -19,11 +19,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include "config_common.h"
|
||||
|
||||
// #define MATRIX_ROW_PINS { A7, A6, A5, A4 }
|
||||
// #define MATRIX_COL_PINS { D7, C2, C3, C4, C5, C6, C7, A3, A2, A1, A0, B0 }
|
||||
#undef MATRIX_ROW_PINS
|
||||
#undef MATRIX_COL_PINS
|
||||
|
||||
#define MATRIX_ROW_PINS { A7, A6, A5, A4 }
|
||||
#define MATRIX_COL_PINS { D7, C2, C3, C4, C5, C6, C7, A3, A2, A1, A0, B0 }
|
||||
|
||||
// #define DIODE_DIRECTION COL2ROW
|
||||
|
||||
|
||||
#define NUMBER_OF_ENCODERS 2
|
||||
#define ENCODERS_PAD_A { B4, B2 }
|
||||
#define ENCODERS_PAD_B { B3, B1 }
|
||||
|
||||
#define TAPPING_TOGGLE 3
|
||||
|
||||
#define NO_UART 1
|
||||
|
|
|
@ -33,10 +33,6 @@ static uint8_t debouncing = DEBOUNCE;
|
|||
static matrix_row_t matrix[MATRIX_ROWS];
|
||||
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||
|
||||
static uint8_t encoder_state[2] = {0};
|
||||
static int8_t encoder_value[2] = {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};
|
||||
|
||||
__attribute__ ((weak))
|
||||
|
@ -45,29 +41,8 @@ void dip_update(uint8_t index, bool active) { }
|
|||
__attribute__ ((weak))
|
||||
void dip_update_kb(uint8_t index, bool active) { }
|
||||
|
||||
__attribute__ ((weak))
|
||||
void encoder_update(uint8_t index, bool clockwise) { }
|
||||
|
||||
bool last_dip_switch[4] = {0};
|
||||
|
||||
#ifndef ENCODER_RESOLUTION
|
||||
#define ENCODER_RESOLUTION 4
|
||||
#endif
|
||||
|
||||
#define NUMBER_OF_ENCODERS 2
|
||||
|
||||
uint8_t read_encoder_state(uint8_t index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return (((PINB & (1 << 4)) << 0) ? 1 : 0) | ((((PINB & (1 << 3)) << 0) ? 1 : 0) << 1);
|
||||
break;
|
||||
case 1:
|
||||
return (((PINB & (1 << 2)) << 0) ? 1 : 0) | ((((PINB & (1 << 1)) << 0) ? 1 : 0) << 1);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void matrix_init(void) {
|
||||
|
||||
// disables JTAG so we can use them as columns
|
||||
|
@ -78,13 +53,6 @@ void matrix_init(void) {
|
|||
DDRD &= ~((1 << 0) | (1 << 1) | (1 << 4) | (1 << 6));
|
||||
PORTD |= ((1 << 0) | (1 << 1) | (1 << 4) | (1 << 6));
|
||||
|
||||
// encoder setup (input, pull-up)
|
||||
DDRB &= ~((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
|
||||
PORTB |= ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
|
||||
|
||||
encoder_state[0] = read_encoder_state(0);
|
||||
encoder_state[1] = read_encoder_state(1);
|
||||
|
||||
// rows (output)
|
||||
DDRA |= ((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
|
||||
PORTA |= ((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4));
|
||||
|
@ -124,23 +92,6 @@ uint8_t matrix_scan(void) {
|
|||
}
|
||||
memcpy(last_dip_switch, dip_switch, sizeof(&dip_switch));
|
||||
|
||||
|
||||
// encoders
|
||||
for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) {
|
||||
encoder_state[i] <<= 2;
|
||||
|
||||
encoder_state[i] |= read_encoder_state(i);
|
||||
|
||||
encoder_value[i] += encoder_LUT[encoder_state[i] & 0xF];
|
||||
if (encoder_value[i] >= ENCODER_RESOLUTION) {
|
||||
encoder_update(i, 0);
|
||||
}
|
||||
if (encoder_value[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
|
||||
encoder_update(i, 1);
|
||||
}
|
||||
encoder_value[i] %= ENCODER_RESOLUTION;
|
||||
}
|
||||
|
||||
// actual matrix scan
|
||||
for (uint8_t c = 0; c < MATRIX_ROWS; c++) {
|
||||
switch (c) {
|
||||
|
|
|
@ -36,7 +36,7 @@ MOUSEKEY_ENABLE = yes
|
|||
EXTRAKEY_ENABLE = yes
|
||||
CONSOLE_ENABLE = no
|
||||
COMMAND_ENABLE = yes
|
||||
KEY_LOCK_ENABLE = yes
|
||||
KEY_LOCK_ENABLE = no
|
||||
NKRO_ENABLE = no # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||
AUDIO_ENABLE = yes
|
||||
|
||||
|
@ -53,3 +53,5 @@ SRC = matrix.c
|
|||
PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex
|
||||
|
||||
LAYOUTS = ortho_4x12 planck_mit planck_grid
|
||||
|
||||
ENCODER_ENABLE = yes
|
||||
|
|
|
@ -161,7 +161,7 @@ extern uint32_t default_layer_state;
|
|||
}
|
||||
}
|
||||
|
||||
#define readPin(pin) (PIN_ADDRESS(pin, 0) & _BV(pin & 0xF))
|
||||
#define readPin(pin) ((PIN_ADDRESS(pin, 0) & _BV(pin & 0xF)) != 0)
|
||||
#elif defined(PROTOCOL_CHIBIOS)
|
||||
#define pin_t ioline_t
|
||||
#define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
|
||||
|
|
Loading…
Reference in a new issue