HHKB support.
This commit is contained in:
parent
2c453c7269
commit
958875247c
620
Makefile.hhkb
Normal file
620
Makefile.hhkb
Normal file
File diff suppressed because it is too large
Load Diff
133
keymap_hhkb.c
Normal file
133
keymap_hhkb.c
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* keymap for modified macway keyboarq
|
||||
*/
|
||||
#include <avr/pgmspace.h>
|
||||
#include "matrix.h"
|
||||
#include "keymap_hhkb.h"
|
||||
|
||||
int current_layer = 0;
|
||||
|
||||
/*
|
||||
* Layer0(Default Layer)
|
||||
* ,-----------------------------------------------------------.
|
||||
* |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
|
||||
* |-----------------------------------------------------------|
|
||||
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
|
||||
* |-----------------------------------------------------------|
|
||||
* |Contro| A| S| D| F| G| H| J| K| L| ;| '|Return |
|
||||
* |-----------------------------------------------------------|
|
||||
* |Shift | Z| X| C| V| B| N| M| ,| .| /|Fn2 |Fn1|
|
||||
* `-----------------------------------------------------------'
|
||||
* |Gui|Alt |Space |Fn3 |Gui|
|
||||
* `-------------------------------------------'
|
||||
*
|
||||
* Layer1(Fn1) HHKB mode
|
||||
* ,-----------------------------------------------------------.
|
||||
* |Pow| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
|
||||
* |-----------------------------------------------------------|
|
||||
* |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
|
||||
* |-----------------------------------------------------------|
|
||||
* |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
|
||||
* |-----------------------------------------------------------|
|
||||
* |Shift | | | | | | +| -|End|PgD|Dow|Shift | |
|
||||
* `-----------------------------------------------------------'
|
||||
* |Gui |Alt |Space |Alt |Gui|
|
||||
* `--------------------------------------------'
|
||||
*
|
||||
* Layer2(Fn2) HHKB mouse mode
|
||||
* ,-----------------------------------------------------------.
|
||||
* |Esc| | | | | | | | | | | | | | |
|
||||
* |-----------------------------------------------------------|
|
||||
* |Tab | | | | | | | | | | |McU| |Backs|
|
||||
* |-----------------------------------------------------------|
|
||||
* |Contro| | | | | | | |MwL|MwU|McL|McR|Return |
|
||||
* |-----------------------------------------------------------|
|
||||
* |Shift | | | | | | | |MwR|MwD|McD| | |
|
||||
* `-----------------------------------------------------------'
|
||||
* |Gui |Alt |Space |Mb1 |Mb2|
|
||||
* `--------------------------------------------'
|
||||
*
|
||||
* Layer3(Fn3) vi mode
|
||||
* ,-----------------------------------------------------------.
|
||||
* |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| | |
|
||||
* |-----------------------------------------------------------|
|
||||
* |Tab | | | | | |Hom|PgD|PgUlEnd| |MwD|MwU| |
|
||||
* |-----------------------------------------------------------|
|
||||
* |Contro| | | | | |Lef|Dow|Up |Rig| | |Return |
|
||||
* |-----------------------------------------------------------|
|
||||
* |Shift | | | | |Mb2|McL|McD|McU|McR|Mb1|Mb1 | |
|
||||
* `-----------------------------------------------------------'
|
||||
* |Gui|Alt |Space | |Mb2|
|
||||
* `-------------------------------------------'
|
||||
* Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
|
||||
*/
|
||||
static const uint8_t PROGMEM Keymap[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
// 0: default
|
||||
{
|
||||
{ KB_2, KB_Q, KB_W, KB_S, KB_A, KB_Z, KB_X, KB_C },
|
||||
{ KB_3, KB_4, KB_R, KB_E, KB_D, KB_F, KB_V, KB_B },
|
||||
{ KB_5, KB_6, KB_Y, KB_T, KB_G, KB_H, KB_N, KB_NO },
|
||||
{ KB_1, KB_ESCAPE, KB_TAB, KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_SPACE },
|
||||
{ KB_7, KB_8, KB_U, KB_I, KB_K, KB_J, KB_M, KB_NO },
|
||||
{ KB_BSLASH, KB_GRAVE, KB_BSPACE, KB_ENTER, FN_1, FN_2, KB_RGUI, FN_3 },
|
||||
{ KB_9, KB_0, KB_O, KB_P, KB_SCOLON, KB_L, KB_COMMA, KB_NO },
|
||||
{ KB_MINUS, KB_EQUAL, KB_RBRACKET,KB_LBRACKET,KB_QUOTE, KB_SLASH, KB_DOT, KB_NO },
|
||||
},
|
||||
// 1: FN_1(HHKB Fn) HHKB mode
|
||||
{
|
||||
{ KB_F2, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, },
|
||||
{ KB_F3, KB_F4, KB_NO, KB_NO, KB_MUTE, KB_F20, KB_NO, KB_NO, },
|
||||
{ KB_F5, KB_F6, KB_NO, KB_NO, KB_NO, KP_ASTERISK,KP_PLUS, KB_NO },
|
||||
{ KB_F1, KB_POWER, KB_CAPSLOCK,KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_SPACE },
|
||||
{ KB_F7, KB_F8, KB_NO, KB_PSCREEN, KB_HOME, KP_SLASH, KB_MINUS, KB_NO },
|
||||
{ KB_INSERT, KB_DELETE, KB_BSPACE, KP_ENTER, KB_NO, KB_RSHIFT, KB_RGUI, KB_RALT },
|
||||
{ KB_F9, KB_F10, KB_SCKLOCK, KB_BREAK, KB_LEFT, KB_PGUP, KB_END, KB_NO },
|
||||
{ KB_F11, KB_F12, KB_NO, KB_UP, KB_RIGHT, KB_DOWN, KB_PGDOWN, KB_NO },
|
||||
},
|
||||
// 2: FN_2(Right Shift) HHKB mouse mode
|
||||
{
|
||||
{ KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, },
|
||||
{ KB_NO, KB_NO, KB_NO, KB_NO, KB_MUTE, KB_NO, KB_NO, KB_NO, },
|
||||
{ KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO },
|
||||
{ KB_NO, KB_ESCAPE, KB_TAB, KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_SPACE },
|
||||
{ KB_NO, KB_NO, KB_NO, KB_NO, MS_WH_LEFT, KP_SLASH, KB_MINUS, KB_NO },
|
||||
{ KB_NO, KB_NO, KB_BSPACE, KB_ENTER, KB_NO, KB_NO, MS_BTN2, MS_BTN1 },
|
||||
{ KB_NO, KB_NO, KB_NO, KB_NO, MS_LEFT, MS_WH_DOWN, MS_WH_RIGHT,KB_NO },
|
||||
{ KB_NO, KB_NO, KB_NO, MS_UP, MS_RIGHT, MS_DOWN, MS_WH_UP, KB_NO },
|
||||
},
|
||||
// 3: FN_3(Right Alt) vi mode
|
||||
{
|
||||
{ KB_F2, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, },
|
||||
{ KB_F3, KB_F4, KB_NO, KB_NO, KB_NO, KB_F20, KB_NO, KB_NO, },
|
||||
{ KB_F5, KB_F6, KB_HOME, KB_NO, KB_NO, KB_LEFT, MS_LEFT, KB_NO },
|
||||
{ KB_F1, KB_ESCAPE, KB_TAB, KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_SPACE },
|
||||
{ KB_F7, KB_F8, KB_PGDOWN, KB_PGUP, KB_UP, KB_DOWN, MS_DOWN, KB_NO },
|
||||
{ KB_INSERT, KB_NO, KB_BSPACE, KB_ENTER, KB_NO, MS_BTN1, MS_BTN2, KB_NO },
|
||||
{ KB_F9, KB_F10, KB_END, KB_NO, KB_NO, KB_RIGHT, MS_UP, KB_NO },
|
||||
{ KB_F11, KB_F12, MS_WH_DOWN, MS_WH_UP, KB_NO, MS_BTN1, MS_RIGHT, KB_NO },
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
uint8_t get_keycode(int layer, int row, int col)
|
||||
{
|
||||
if (row >= MATRIX_ROWS)
|
||||
return KB_NO;
|
||||
if (col >= MATRIX_COLS)
|
||||
return KB_NO;
|
||||
return pgm_read_byte(&Keymap[layer][row][col]);
|
||||
}
|
||||
|
||||
int get_layer(void) {
|
||||
int layer = 0;
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (int col = 0; col < MATRIX_ROWS; col++) {
|
||||
if (matrix[row] & 1<<col) continue;
|
||||
if (get_keycode(0, row, col) == FN_1) layer = ((layer == 0 || layer > 1) ? 1 : layer);
|
||||
if (get_keycode(0, row, col) == FN_2) layer = ((layer == 0 || layer > 2) ? 2 : layer);
|
||||
if (get_keycode(0, row, col) == FN_3) layer = ((layer == 0 || layer > 3) ? 3 : layer);
|
||||
}
|
||||
}
|
||||
current_layer = layer;
|
||||
return current_layer;
|
||||
}
|
13
keymap_hhkb.h
Normal file
13
keymap_hhkb.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef KEYMAP_H
|
||||
#define KEYMAP_H 1
|
||||
|
||||
#include <stdint.h>
|
||||
#include "usb_keycodes.h"
|
||||
|
||||
int get_layer(void);
|
||||
uint8_t get_keycode(int layer, int row, int col);
|
||||
|
||||
#define MATRIX_ROWS 8
|
||||
#define MATRIX_COLS 8
|
||||
|
||||
#endif
|
94
matrix_hhkb.c
Normal file
94
matrix_hhkb.c
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* scan matrix
|
||||
*/
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
#include "keymap.h"
|
||||
#include "matrix.h"
|
||||
#include "print.h"
|
||||
|
||||
// matrix is active low. (key on: 0/key off: 1)
|
||||
//
|
||||
// HHKB has no ghost and no bounce.
|
||||
// row: HC4051 select input channel(0-8)
|
||||
// PB0, PB1, PB2(A, B, C)
|
||||
// col: LS145 select low output line(0-8)
|
||||
// PB3, PB4, PB5, PB6(A, B, C, D)
|
||||
// use D as ENABLE: (enable: 0/unenable: 1)
|
||||
// key: KEY: (on: 0/ off:1)
|
||||
// UNKNOWN: unknown whether input or output
|
||||
// PE6,PE7(KEY, UNKNOWN)
|
||||
#define COL_ENABLE (1<<6)
|
||||
#define KEY_SELELCT(ROW, COL) (PORTB = COL_ENABLE|(((COL)&0x07)<<3)|((ROW)&0x07))
|
||||
#define KEY_ENABLE (PORTB &= ~COL_ENABLE)
|
||||
#define KEY_UNABLE (PORTB |= COL_ENABLE)
|
||||
#define KEY_ON ((PINE&(1<<6)) ? false : true)
|
||||
|
||||
// matrix state buffer
|
||||
uint8_t *matrix;
|
||||
uint8_t *matrix_prev;
|
||||
static uint8_t _matrix0[MATRIX_ROWS];
|
||||
static uint8_t _matrix1[MATRIX_ROWS];
|
||||
|
||||
|
||||
// this must be called once before matrix_scan.
|
||||
void matrix_init(void)
|
||||
{
|
||||
// row & col output(PB0-6)
|
||||
DDRB = 0xFF;
|
||||
PORTB = KEY_SELELCT(0, 0);
|
||||
// key input(KEY/VALID)
|
||||
DDRE = 0x3F;
|
||||
PORTE = 0x00;
|
||||
|
||||
// initialize matrix state: all keys off
|
||||
for (int i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0xFF;
|
||||
for (int i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0xFF;
|
||||
matrix = _matrix0;
|
||||
matrix_prev = _matrix1;
|
||||
}
|
||||
|
||||
uint8_t matrix_scan(void)
|
||||
{
|
||||
uint8_t state;
|
||||
uint8_t *tmp;
|
||||
|
||||
tmp = matrix_prev;
|
||||
matrix_prev = matrix;
|
||||
matrix = tmp;
|
||||
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
for (int col = 0; col < MATRIX_COLS; col++) {
|
||||
//print("scan: "); phex(row); phex(col); print("\n");
|
||||
KEY_SELELCT(row, col);
|
||||
_delay_us(50); // from logic analyzer chart
|
||||
KEY_ENABLE;
|
||||
_delay_us(10); // from logic analyzer chart
|
||||
//print("PINE: "); phex(PINE); print("\n");
|
||||
if (KEY_ON) {
|
||||
matrix[row] &= ~(1<<col);
|
||||
} else {
|
||||
matrix[row] |= (1<<col);
|
||||
}
|
||||
KEY_UNABLE;
|
||||
_delay_us(150); // from logic analyzer chart
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool matrix_is_modified(void) {
|
||||
for (int i=0; i <MATRIX_ROWS; i++) {
|
||||
if (matrix[i] != matrix_prev[i])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool matrix_has_ghost(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool matrix_has_ghost_in_row(uint8_t row) {
|
||||
return false;
|
||||
}
|
21
tmk.c
21
tmk.c
@ -34,7 +34,7 @@
|
||||
#include "usb_mouse.h"
|
||||
#include "print.h"
|
||||
#include "matrix.h"
|
||||
#include "keymap.h"
|
||||
#include "keymap_hhkb.h"
|
||||
#include "jump_bootloader.h"
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@
|
||||
|
||||
#define MOUSE_MOVE_UNIT 10
|
||||
#define MOUSE_DELAY_MS 200
|
||||
#define MOUSE_DELAY_ACC 4
|
||||
#define MOUSE_DELAY_ACC 5
|
||||
|
||||
|
||||
static void print_matrix(void);
|
||||
@ -99,7 +99,7 @@ int main(void)
|
||||
int8_t mouse_hwheel = 0;
|
||||
int mouse_repeat = 0;
|
||||
|
||||
print("\nt.m.k. keyboard 1.0\n");
|
||||
print("\nt.m.k. keyboard 1.0 for hhkb\n");
|
||||
while (1) {
|
||||
matrix_scan();
|
||||
modified = matrix_is_modified();
|
||||
@ -110,12 +110,13 @@ int main(void)
|
||||
if (modified) {
|
||||
print_matrix();
|
||||
|
||||
// LED flash for debug
|
||||
LED_CONFIG;
|
||||
LED_ON;
|
||||
}
|
||||
|
||||
keyboard_modifier_keys = 0;
|
||||
for (int i = 0; i < 6; i++) keyboard_keys[i] = KB_NO;
|
||||
for (int i = 0; i < 3; i++) keyboard_keys[i] = KB_NO;
|
||||
key_index = 0;
|
||||
mouse_x = 0;
|
||||
mouse_y = 0;
|
||||
@ -136,10 +137,10 @@ int main(void)
|
||||
keyboard_modifier_keys |= 1<<(code & 0x07);
|
||||
} else if (code >= MS_UP) {
|
||||
// mouse
|
||||
if (code == MS_UP) mouse_y -= MOUSE_MOVE_UNIT;
|
||||
if (code == MS_DOWN) mouse_y += MOUSE_MOVE_UNIT;
|
||||
if (code == MS_LEFT) mouse_x -= MOUSE_MOVE_UNIT;
|
||||
if (code == MS_RIGHT) mouse_x += MOUSE_MOVE_UNIT;
|
||||
if (code == MS_UP) mouse_y -= MOUSE_MOVE_UNIT + (mouse_repeat < 50 ? mouse_repeat/5 : 10);
|
||||
if (code == MS_DOWN) mouse_y += MOUSE_MOVE_UNIT + (mouse_repeat < 50 ? mouse_repeat/5 : 10);
|
||||
if (code == MS_LEFT) mouse_x -= MOUSE_MOVE_UNIT + (mouse_repeat < 50 ? mouse_repeat/5 : 10);
|
||||
if (code == MS_RIGHT) mouse_x += MOUSE_MOVE_UNIT + (mouse_repeat < 50 ? mouse_repeat/5 : 10);
|
||||
if (code == MS_BTN1) mouse_btn |= 1<<0;
|
||||
if (code == MS_BTN2) mouse_btn |= 1<<1;
|
||||
if (code == MS_BTN3) mouse_btn |= 1<<2;
|
||||
@ -189,6 +190,10 @@ int main(void)
|
||||
//Rollover
|
||||
}
|
||||
usb_keyboard_send();
|
||||
|
||||
// LED flash for debug
|
||||
LED_CONFIG;
|
||||
LED_OFF;
|
||||
}
|
||||
}
|
||||
_delay_ms(2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user