diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c6f3b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/*.hex +/*.eep +/*.cof +/*.elf +/*.map +/*.sym +/*.lss +/.dep +/obj_kc60_lufa diff --git a/Makefile b/Makefile index eaa179f..e58a5ce 100644 --- a/Makefile +++ b/Makefile @@ -48,8 +48,7 @@ TMK_DIR = ./tmk_core/tmk_core TARGET_DIR = . # project specific files -SRC = keymap_common.c \ - matrix.c \ +SRC = matrix.c \ led.c ifdef KEYMAP @@ -119,8 +118,9 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450) #CONSOLE_ENABLE = yes # Console for debug(+400) #COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend -NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA -#BACKLIGHT_ENABLE = yes +NKRO_ENABLE = yes # USB Nkey Rollover +#BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality + # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/README.md b/README.md index 2a9355b..65b4e65 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ DIY compact keyboard by Massdrop. ## Build Move to this directory then just run `make` like: - $ git submodule update tmk_core + $ git submodule update --init --recursive $ make Use `make -f Makefile.pjrc` if you want to use PJRC stack but I find no reason to do so now. diff --git a/keymap_common.c b/keymap_common.c deleted file mode 100644 index fdb1769..0000000 --- a/keymap_common.c +++ /dev/null @@ -1,30 +0,0 @@ -/* -Copyright 2012,2013 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ -#include "keymap_common.h" - - -/* translates key to keycode */ -uint8_t keymap_key_to_keycode(uint8_t layer, keypos_t key) -{ - return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); -} - -/* translates Fn keycode to action */ -action_t keymap_fn_to_action(uint8_t keycode) -{ - return (action_t){ .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) }; -} diff --git a/keymap_common.h b/keymap_common.h index c9423df..5f4352b 100644 --- a/keymap_common.h +++ b/keymap_common.h @@ -19,7 +19,6 @@ along with this program. If not, see . #include #include -#include #include "keycode.h" #include "action.h" #include "action_macro.h" @@ -30,10 +29,6 @@ along with this program. If not, see . #include "keymap.h" -extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; -extern const uint16_t fn_actions[]; - - /* KC60 keymap definition macro * K2C, K31 and K3C are extra keys for ISO */ @@ -51,7 +46,7 @@ extern const uint16_t fn_actions[]; { KC_##K40, KC_##K41, KC_##K42, KC_NO, KC_NO, KC_##K45, KC_NO, KC_NO, KC_NO, KC_##K49, KC_##K4A, KC_##K4B, KC_##K4C, KC_##K4D } \ } -/* ANSI valiant. No extra keys for ISO */ +/* ANSI variant. No extra keys for ISO */ #define KEYMAP_ANSI( \ K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, K0B, K0C, K0D, \ K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, \ diff --git a/keymap_default.c b/keymap_default.c index da005fd..3403924 100644 --- a/keymap_default.c +++ b/keymap_default.c @@ -62,7 +62,7 @@ const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* * Fn action definition */ -const uint16_t PROGMEM fn_actions[] = { +const action_t PROGMEM fn_actions[] = { [0] = ACTION_LAYER_MOMENTARY(1), /* Monentary layout 1 */ [1] = ACTION_LAYER_TOGGLE(1), /* Toggle layout */ [2] = ACTION_MODS_KEY(MOD_LSFT, KC_DEL), /* Cut */ diff --git a/keymap_spacefn.c b/keymap_spacefn.c index 6e1e898..b15995e 100644 --- a/keymap_spacefn.c +++ b/keymap_spacefn.c @@ -62,7 +62,7 @@ const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* * Fn action definition */ -const uint16_t PROGMEM fn_actions[] = { +const action_t PROGMEM fn_actions[] = { [0] = ACTION_LAYER_TAP_KEY(1, KC_SPACE), /* SpaceFn layout 1 */ [1] = ACTION_LAYER_MOMENTARY(1), /* Momentary layout 1 */ [2] = ACTION_MODS_KEY(MOD_LSFT, KC_DEL), /* Cut */ diff --git a/matrix.c b/matrix.c index aee299a..de64f07 100644 --- a/matrix.c +++ b/matrix.c @@ -25,13 +25,16 @@ along with this program. If not, see . #include "print.h" #include "debug.h" #include "util.h" +#include "timer.h" #include "matrix.h" #ifndef DEBOUNCE -# define DEBOUNCE 5 +# define DEBOUNCE 5 #endif -static uint8_t debouncing = DEBOUNCE; +static bool debouncing = false; +static uint16_t debouncing_time = 0; + /* matrix state(1:on, 0:off) */ static matrix_row_t matrix[MATRIX_ROWS]; @@ -43,18 +46,6 @@ static void unselect_rows(void); static void select_row(uint8_t row); -inline -uint8_t matrix_rows(void) -{ - return MATRIX_ROWS; -} - -inline -uint8_t matrix_cols(void) -{ - return MATRIX_COLS; -} - void matrix_init(void) { // disable JTAG @@ -76,76 +67,41 @@ uint8_t matrix_scan(void) { for (uint8_t i = 0; i < MATRIX_ROWS; i++) { select_row(i); - _delay_us(30); // without this wait read unstable value. + _delay_us(1); // delay for settling matrix_row_t cols = read_cols(); if (matrix_debouncing[i] != cols) { - matrix_debouncing[i] = cols; if (debouncing) { - debug("bounce!: "); debug_hex(debouncing); debug("\n"); + dprintf("bounce: %d %d@%02X\n", timer_elapsed(debouncing_time), i, matrix_debouncing[i]^cols); } - debouncing = DEBOUNCE; + matrix_debouncing[i] = cols; + debouncing = true; + debouncing_time = timer_read(); } unselect_rows(); } - if (debouncing) { - if (--debouncing) { - _delay_ms(1); - } else { - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - matrix[i] = matrix_debouncing[i]; - } + if (debouncing && timer_elapsed(debouncing_time) >= DEBOUNCE) { + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + matrix[i] = matrix_debouncing[i]; } + debouncing = false; } return 1; } -bool matrix_is_modified(void) -{ - if (debouncing) return false; - return true; -} - -inline -bool matrix_is_on(uint8_t row, uint8_t col) -{ - return (matrix[row] & ((matrix_row_t)1<