From 8d99140d1b80bf497b2198138d3f481e93b0fbab Mon Sep 17 00:00:00 2001 From: Adam Gausmann Date: Thu, 29 Sep 2016 14:46:10 -0500 Subject: Missing ifdef statement --- quantum/process_keycode/process_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'quantum') diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c index 8784e64f3..577dad43a 100644 --- a/quantum/process_keycode/process_midi.c +++ b/quantum/process_keycode/process_midi.c @@ -7,7 +7,9 @@ int midi_offset = 7; bool process_midi(uint16_t keycode, keyrecord_t *record) { if (keycode == MI_ON && record->event.pressed) { midi_activated = true; +#ifdef AUDIO_ENABLE music_scale_user(); +#endif return false; } @@ -63,4 +65,4 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) { return false; } return true; -} \ No newline at end of file +} -- cgit v1.2.3 From a3f5a4cf5839fe29dd37400d72c5e353812002f8 Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 2 Oct 2016 10:35:09 +0200 Subject: Declare Unicode method hex_to_keycode() as “weak” Declare Unicode method hex_to_keycode() as “weak” to be able to override it in keymaps. --- quantum/process_keycode/process_unicode.c | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum') diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index a5d7dca21..6a30afe29 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -2,6 +2,7 @@ static uint8_t input_mode; +__attribute__((weak)) uint16_t hex_to_keycode(uint8_t hex) { if (hex == 0x0) { -- cgit v1.2.3 From 1048a588c750e27ff0f900cd6aaf670e034086d0 Mon Sep 17 00:00:00 2001 From: npoirey Date: Fri, 7 Oct 2016 17:15:11 +0200 Subject: Add Altgr combination for non US layouts --- quantum/keymap.h | 1 + 1 file changed, 1 insertion(+) (limited to 'quantum') diff --git a/quantum/keymap.h b/quantum/keymap.h index 98ddfd0c5..4b2192cb2 100644 --- a/quantum/keymap.h +++ b/quantum/keymap.h @@ -191,6 +191,7 @@ enum quantum_keycodes { #define HYPR(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT | QK_LGUI) #define MEH(kc) (kc | QK_LCTL | QK_LSFT | QK_LALT) #define LCAG(kc) (kc | QK_LCTL | QK_LALT | QK_LGUI) +#define ALTG(kc) (kc | QK_RCTL | QK_RALT) #define MOD_HYPR 0xf #define MOD_MEH 0x7 -- cgit v1.2.3 From 70f32842e5d94f14d05c1f9adcb1b1144a25a132 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 9 Oct 2016 12:52:39 +0200 Subject: Reduce the default dynamic macro buffer There have been reports of it leaving not enough free memory preventing the keyboard from working properly. --- quantum/dynamic_macro.h | 9 +++++++-- readme.md | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'quantum') diff --git a/quantum/dynamic_macro.h b/quantum/dynamic_macro.h index a3ad61bc7..e6dbc5b9c 100644 --- a/quantum/dynamic_macro.h +++ b/quantum/dynamic_macro.h @@ -8,8 +8,13 @@ /* May be overridden with a custom value. Be aware that the effective * macro length is half of this value: each keypress is recorded twice * because of the down-event and up-event. This is not a bug, it's the - * intended behavior. */ -#define DYNAMIC_MACRO_SIZE 256 + * intended behavior. + * + * Usually it should be fine to set the macro size to at least 256 but + * there have been reports of it being too much in some users' cases, + * so 128 is considered a safe default. + */ +#define DYNAMIC_MACRO_SIZE 128 #endif /* DYNAMIC_MACRO_RANGE must be set as the last element of user's diff --git a/readme.md b/readme.md index a7320202b..d28d7c3ff 100644 --- a/readme.md +++ b/readme.md @@ -823,7 +823,7 @@ And then, to assign this macro to a key on your keyboard layout, you just use `M ## Dynamic macros: record and replay macros in runtime -In addition to the static macros described above, you may enable the dynamic macros which you may record while writing. They are forgotten as soon as the keyboard is unplugged. Only two such macros may be stored at the same time, with the total length of 128 keypresses. +In addition to the static macros described above, you may enable the dynamic macros which you may record while writing. They are forgotten as soon as the keyboard is unplugged. Only two such macros may be stored at the same time, with the total length of 64 keypresses (by default). To enable them, first add a new element to the `planck_keycodes` enum -- `DYNAMIC_MACRO_RANGE`: @@ -864,7 +864,7 @@ Add the following code to the very beginning of your `process_record_user()` fun To start recording the macro, press either `DYN_REC_START1` or `DYN_REC_START2`. To finish the recording, press the `_DYN` layer button. The handler awaits specifically for the `MO(_DYN)` keycode as the "stop signal" so please don't use any fancy ways to access this layer, use the regular `MO()` modifier. To replay the macro, press either `DYN_MACRO_PLAY1` or `DYN_MACRO_PLAY2`. -If the LED-s start blinking during the recording with each keypress, it means there is no more space for the macro in the macro buffer. To fit the macro in, either make the other macro shorter (they share the same buffer) or increase the buffer size by setting the `DYNAMIC_MACRO_SIZE` preprocessor macro (default value: 256; please read the comments for it in the header). +If the LED-s start blinking during the recording with each keypress, it means there is no more space for the macro in the macro buffer. To fit the macro in, either make the other macro shorter (they share the same buffer) or increase the buffer size by setting the `DYNAMIC_MACRO_SIZE` preprocessor macro (default value: 128; please read the comments for it in the header). For the details about the internals of the dynamic macros, please read the comments in the `dynamic_macro.h` header. -- cgit v1.2.3 From 9b0e21f87f446935f29254bb623c2cfe29472b6e Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 9 Oct 2016 19:26:16 +0300 Subject: Tunable RGB light intervals --- quantum/rgblight.c | 6 ++++++ quantum/rgblight.h | 6 ++++++ 2 files changed, 12 insertions(+) (limited to 'quantum') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index f82e3ec55..9eac87a20 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -42,10 +42,16 @@ const uint8_t RGBLED_BREATHING_TABLE[] PROGMEM = { 37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11, 10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0 }; + +__attribute__ ((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; +__attribute__ ((weak)) const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; +__attribute__ ((weak)) const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; +__attribute__ ((weak)) const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; +__attribute__ ((weak)) const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {100, 50, 20}; rgblight_config_t rgblight_config; diff --git a/quantum/rgblight.h b/quantum/rgblight.h index def26c428..17f04ffcf 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -40,6 +40,12 @@ #include "eeconfig.h" #include "light_ws2812.h" +extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM; +extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM; +extern const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM; +extern const uint8_t RGBLED_SNAKE_INTERVALS[3] PROGMEM; +extern const uint8_t RGBLED_KNIGHT_INTERVALS[3] PROGMEM; + typedef union { uint32_t raw; struct { -- cgit v1.2.3 From 92a3a96849aee708753a6623b0db228023e3baf8 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 9 Oct 2016 19:47:05 +0300 Subject: Apply the dim curve to the RGB output Just like it's supposed to be used. It now looks much better. --- quantum/rgblight.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'quantum') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index f82e3ec55..b36a1fda0 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -55,13 +55,8 @@ uint8_t rgblight_inited = 0; void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) { - // Convert hue, saturation, and value (HSV/HSB) to RGB. DIM_CURVE is used only - // on value and saturation (inverted). This looks the most natural. uint8_t r = 0, g = 0, b = 0, base, color; - val = pgm_read_byte(&DIM_CURVE[val]); - sat = 255 - pgm_read_byte(&DIM_CURVE[255 - sat]); - if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. r = val; g = val; @@ -103,6 +98,9 @@ void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) { break; } } + r = pgm_read_byte(&DIM_CURVE[r]); + g = pgm_read_byte(&DIM_CURVE[g]); + b = pgm_read_byte(&DIM_CURVE[b]); setrgb(r, g, b, led1); } -- cgit v1.2.3 From ffae9d84c5279b463da112ee15568d536649b819 Mon Sep 17 00:00:00 2001 From: Fred Sundvik Date: Sun, 9 Oct 2016 19:53:41 +0300 Subject: CIE 1931 dim curve --- quantum/rgblight.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'quantum') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index b36a1fda0..9ddc243b2 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -6,24 +6,37 @@ #include "rgblight.h" #include "debug.h" +// Lightness curve using the CIE 1931 lightness formula +//Generated by the python script provided in http://jared.geek.nz/2013/feb/linear-led-pwm const uint8_t DIM_CURVE[] PROGMEM = { - 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, - 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, - 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11, - 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15, - 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20, - 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26, - 27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35, - 36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47, - 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, - 63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82, - 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109, - 110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144, - 146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190, - 193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255 -}; + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, + 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, + 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, + 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, + 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, + 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, + 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, + 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, + 28, 28, 29, 29, 30, 31, 31, 32, 32, 33, + 34, 34, 35, 36, 37, 37, 38, 39, 39, 40, + 41, 42, 43, 43, 44, 45, 46, 47, 47, 48, + 49, 50, 51, 52, 53, 54, 54, 55, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 70, 71, 72, 73, 74, 75, 76, 77, 79, + 80, 81, 82, 83, 85, 86, 87, 88, 90, 91, + 92, 94, 95, 96, 98, 99, 100, 102, 103, 105, + 106, 108, 109, 110, 112, 113, 115, 116, 118, 120, + 121, 123, 124, 126, 128, 129, 131, 132, 134, 136, + 138, 139, 141, 143, 145, 146, 148, 150, 152, 154, + 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, + 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, + 196, 198, 200, 202, 204, 207, 209, 211, 214, 216, + 218, 220, 223, 225, 228, 230, 232, 235, 237, 240, + 242, 245, 247, 250, 252, 255, + }; + const uint8_t RGBLED_BREATHING_TABLE[] PROGMEM = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9, 10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35, -- cgit v1.2.3 From 5b2e455d3b71bfb90754930d1f22d3e8ce98b927 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Mon, 10 Oct 2016 00:46:20 +0700 Subject: Unicode map framework. Allow unicode up to 0xFFFFF using separate mapping table --- build_keyboard.mk | 5 +++++ quantum/keymap.h | 7 +++++++ quantum/process_keycode/process_unicode.c | 26 ++++++++++++++++++++++++++ quantum/process_keycode/process_unicode.h | 4 ++++ quantum/quantum.c | 3 +++ readme.md | 6 ++++++ 6 files changed, 51 insertions(+) (limited to 'quantum') diff --git a/build_keyboard.mk b/build_keyboard.mk index 03a69b146..282adcb11 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk @@ -153,6 +153,11 @@ ifeq ($(strip $(UCIS_ENABLE)), yes) UNICODE_ENABLE = yes endif +ifeq ($(strip $(UNICODEMAP_ENABLE)), yes) + OPT_DEFS += -DUNICODEMAP_ENABLE + UNICODE_ENABLE = yes +endif + ifeq ($(strip $(UNICODE_ENABLE)), yes) OPT_DEFS += -DUNICODE_ENABLE SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c diff --git a/quantum/keymap.h b/quantum/keymap.h index 98ddfd0c5..0daa00120 100644 --- a/quantum/keymap.h +++ b/quantum/keymap.h @@ -84,6 +84,10 @@ enum quantum_keycodes { QK_MOD_TAP_MAX = 0x6FFF, QK_TAP_DANCE = 0x7100, QK_TAP_DANCE_MAX = 0x71FF, +#ifdef UNICODEMAP_ENABLE + QK_UNICODE_MAP = 0x7800, + QK_UNICODE_MAP_MAX = 0x7FFF, +#endif #ifdef UNICODE_ENABLE QK_UNICODE = 0x8000, QK_UNICODE_MAX = 0xFFFF, @@ -335,5 +339,8 @@ enum quantum_keycodes { #define UC(n) UNICODE(n) #endif +#ifdef UNICODEMAP_ENABLE + #define X(n) (n | QK_UNICODE_MAP) +#endif #endif diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 6a30afe29..37dd471ff 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -78,6 +78,32 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) { return true; } +#ifdef UNICODEMAP_ENABLE +__attribute__((weak)) +const uint32_t PROGMEM unicode_map[] = { +}; + +// 5 digit max because of linux limitation +void register_hex32(uint32_t hex) { + for(int i = 4; i >= 0; i--) { + uint8_t digit = ((hex >> (i*4)) & 0xF); + register_code(hex_to_keycode(digit)); + unregister_code(hex_to_keycode(digit)); + } +} + +bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { + if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { + const uint32_t* map = unicode_map; + uint16_t index = keycode & 0x7FF; + unicode_input_start(); + register_hex32(pgm_read_dword_far(&map[index])); + unicode_input_finish(); + } + return true; +} +#endif + #ifdef UCIS_ENABLE qk_ucis_state_t qk_ucis_state; diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index 27f8072ee..a6c7e4584 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h @@ -20,6 +20,10 @@ void register_hex(uint16_t hex); bool process_unicode(uint16_t keycode, keyrecord_t *record); +#ifdef UNICODEMAP_ENABLE +bool process_unicode_map(uint16_t keycode, keyrecord_t *record); +#endif + #ifdef UCIS_ENABLE #ifndef UCIS_MAX_SYMBOL_LENGTH #define UCIS_MAX_SYMBOL_LENGTH 32 diff --git a/quantum/quantum.c b/quantum/quantum.c index a16bd5443..098312e6e 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -128,6 +128,9 @@ bool process_record_quantum(keyrecord_t *record) { #endif #ifdef UCIS_ENABLE process_ucis(keycode, record) && + #endif + #ifdef UNICODEMAP_ENABLE + process_unicode_map(keycode, record) && #endif true)) { return false; diff --git a/readme.md b/readme.md index a7320202b..2653ab2ea 100644 --- a/readme.md +++ b/readme.md @@ -320,6 +320,12 @@ This enables MIDI sending and receiving with your keyboard. To enter MIDI send m This allows you to send unicode symbols via `UC()` in your keymap. Only codes up to 0x7FFF are currently supported. +`UNICODEMAP_ENABLE` + +This allows sending unicode symbols using `X()` in your keymap. Codes +up to 0xFFFFF are supported, including emojis. But you need to maintain a +separate mapping table in your keymap file. + `BLUETOOTH_ENABLE` This allows you to interface with a Bluefruit EZ-key to send keycodes wirelessly. It uses the D2 and D3 pins. -- cgit v1.2.3 From e27a754b70434de88a37c4a572e4ca5f7730ff58 Mon Sep 17 00:00:00 2001 From: Jack & Erez Date: Wed, 12 Oct 2016 22:18:27 -0400 Subject: [Jack & Erez] Simplifies and documents TO --- keyboards/ergodox/keymaps/dave/keymap.c | 12 ++++++------ quantum/keymap.h | 5 ++++- readme.md | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'quantum') diff --git a/keyboards/ergodox/keymaps/dave/keymap.c b/keyboards/ergodox/keymaps/dave/keymap.c index 32c70097b..23c4e0490 100644 --- a/keyboards/ergodox/keymaps/dave/keymap.c +++ b/keyboards/ergodox/keymaps/dave/keymap.c @@ -38,7 +38,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_H, CTL_T(KC_GRV),KC_NUBS,KC_NO, KC_NO, KC_LALT, KC_PSCREEN, KC_PSCREEN, - TO(PROG, ON_PRESS), + TO(PROG), KC_SPC, MO(NAVI), KC_LGUI, // right hand KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_BSPC, @@ -47,7 +47,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, KC_RALT,KC_LBRC,KC_RBRC,KC_NO, CTL_T(KC_QUOT), MT(0x5, KC_NO), MT(0x5, KC_NO), - TO(PROG, ON_PRESS), + TO(PROG), KC_RGUI, MO(PROG), KC_SPC ), @@ -81,7 +81,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - TO(NAVI, ON_PRESS), + TO(NAVI), KC_TRNS, KC_TRNS, KC_TRNS, // right hand KC_TRNS, KC_TRNS, KC_NO, KC_PSLS, KC_PAST, KC_PMNS, KC_EQUAL, @@ -90,7 +90,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_TRNS, KC_P1, KC_P2, KC_P3, KC_PENT, KC_TRNS, KC_P0, KC_P0, KC_PDOT, KC_PENT, KC_TRNS, KC_TRNS, KC_TRNS, - TO(NAVI, ON_PRESS), + TO(NAVI), KC_TRNS, KC_TRNS, KC_TRNS ), @@ -123,7 +123,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_BTN1, KC_MS_U, KC_BTN2, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_R, KC_TRNS, KC_TRNS, KC_TRNS, - TO(BASE, ON_PRESS), + TO(BASE), KC_TRNS, KC_TRNS, KC_TRNS, // right hand KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_TRNS, @@ -132,7 +132,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_TRNS, KC_MPRV, KC_MPLY, KC_MNXT, KC_TRNS, KC_TRNS, KC_VOLD, KC_MUTE, KC_VOLU, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, - TO(BASE, ON_PRESS), + TO(BASE), KC_TRNS, KC_TRNS, KC_TRNS ), }; diff --git a/quantum/keymap.h b/quantum/keymap.h index 4b2192cb2..85c090972 100644 --- a/quantum/keymap.h +++ b/quantum/keymap.h @@ -296,7 +296,10 @@ enum quantum_keycodes { // ON_PRESS = 1 // ON_RELEASE = 2 // Unless you have a good reason not to do so, prefer ON_PRESS (1) as your default. -#define TO(layer, when) (layer | QK_TO | (when << 0x4)) +// In fact, we changed it to assume ON_PRESS for sanity/simplicity. If needed, you can add your own +// keycode modeled after the old version, kept below for this. +/* #define TO(layer, when) (layer | QK_TO | (when << 0x4)) */ +#define TO(layer) (layer | QK_TO | (ON_PRESS << 0x4)) // Momentary switch layer - 256 layer max #define MO(layer) (layer | QK_MOMENTARY) diff --git a/readme.md b/readme.md index f20ab41b1..80f0a3ab2 100644 --- a/readme.md +++ b/readme.md @@ -379,6 +379,8 @@ Instead of using `FNx` when defining `ACTION_*` functions, you can use `F(x)` - `TG(layer)` - toggles a layer on or off. As with `MO()`, you should set this key as `KC_TRNS` in the destination layer so that tapping it again actually toggles back to the original layer. Only works upwards in the layer stack. +`TO(layer)` - Goes to a layer. This code is special, because it lets you go either up or down the stack -- just goes directly to the layer you want. So while other codes only let you go _up_ the stack (from layer 0 to layer 3, for example), `TO(2)` is going to get you to layer 2, no matter where you activate it from -- even if you're currently on layer 5. This gets activated on keydown (as soon as the key is pressed). + ### Fun with modifier keys -- cgit v1.2.3 From 6e003b1e3fa844cfde0069004e755aae7a9539f3 Mon Sep 17 00:00:00 2001 From: Artyom Mironov Date: Wed, 19 Oct 2016 23:45:55 +0300 Subject: add programmer dvorak keymap --- quantum/keymap_extras/keymap_dvp.h | 82 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 quantum/keymap_extras/keymap_dvp.h (limited to 'quantum') diff --git a/quantum/keymap_extras/keymap_dvp.h b/quantum/keymap_extras/keymap_dvp.h new file mode 100644 index 000000000..83f49a52b --- /dev/null +++ b/quantum/keymap_extras/keymap_dvp.h @@ -0,0 +1,82 @@ +#ifndef KEYMAP_DVP_H +#define KEYMAP_DVP_H + +#include "keymap.h" + +// Normal characters +#define DP_DLR KC_GRV +#define DP_AMPR KC_1 +#define DP_LBRC KC_2 +#define DP_LCBR KC_3 +#define DP_RCBR KC_4 +#define DP_LPRN KC_5 +#define DP_EQL KC_6 +#define DP_ASTR KC_7 +#define DP_RPRN KC_8 +#define DP_PLUS KC_9 +#define DP_RBRC KC_0 +#define DP_EXLM KC_MINS +#define DP_HASH KC_EQL + +#define DP_SCLN KC_Q +#define DP_COMM KC_W +#define DP_DOT KC_E +#define DP_P KC_R +#define DP_Y KC_T +#define DP_F KC_Y +#define DP_G KC_U +#define DP_C KC_I +#define DP_R KC_O +#define DP_L KC_P +#define DP_SLSH KC_LBRC +#define DP_AT KC_RBRC +#define DP_BSLS KC_BSLS + +#define DP_A KC_A +#define DP_O KC_S +#define DP_E KC_D +#define DP_U KC_F +#define DP_I KC_G +#define DP_D KC_H +#define DP_H KC_J +#define DP_T KC_K +#define DP_N KC_L +#define DP_S KC_SCLN +#define DP_MINS KC_QUOT + +#define DP_QUOT KC_Z +#define DP_Q KC_X +#define DP_J KC_C +#define DP_K KC_V +#define DP_X KC_B +#define DP_B KC_N +#define DP_M KC_M +#define DP_W KC_COMM +#define DP_V KC_DOT +#define DP_Z KC_SLSH + +// Shifted characters +#define DP_TILD LSFT(DP_DLR) +#define DP_PERC LSFT(DP_AMPR) +#define DP_7 LSFT(DP_LBRC) +#define DP_5 LSFT(DP_LCBR) +#define DP_3 LSFT(DP_RCBR) +#define DP_1 LSFT(DP_LPRN) +#define DP_9 LSFT(DP_EQL) +#define DP_0 LSFT(DP_ASTR) +#define DP_2 LSFT(DP_RPRN) +#define DP_4 LSFT(DP_PLUS) +#define DP_6 LSFT(DP_RBRC) +#define DP_8 LSFT(DP_EXLM) +#define DP_GRV LSFT(DP_HASH) + +#define DP_COLN LSFT(DP_SCLN) +#define DP_LABK LSFT(DP_COMM) +#define DP_RABK LSFT(DP_DOT) +#define DP_QUES LSFT(DP_SLSH) +#define DP_CIRC LSFT(DP_AT) +#define DP_PIPE LSFT(DP_BSLS) +#define DP_UNDS LSFT(DP_MINS) +#define DP_DQUO LSFT(DP_QUOT) + +#endif -- cgit v1.2.3 From e7d5dc89f2890007d776f6b613dc9deb473cff22 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Sun, 23 Oct 2016 05:36:26 +0700 Subject: UNICODE_MAP: remove 5 char limit; ignore leading zeroes; handle OS limitations --- quantum/process_keycode/process_unicode.c | 34 ++++++++++++++++++++++++------- readme.md | 10 +++++++-- 2 files changed, 35 insertions(+), 9 deletions(-) (limited to 'quantum') diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 37dd471ff..a71af5437 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -83,22 +83,42 @@ __attribute__((weak)) const uint32_t PROGMEM unicode_map[] = { }; -// 5 digit max because of linux limitation void register_hex32(uint32_t hex) { - for(int i = 4; i >= 0; i--) { + uint8_t onzerostart = 1; + for(int i = 7; i >= 0; i--) { + if (i <= 3) { + onzerostart = 0; + } uint8_t digit = ((hex >> (i*4)) & 0xF); - register_code(hex_to_keycode(digit)); - unregister_code(hex_to_keycode(digit)); + if (digit == 0) { + if (onzerostart == 0) { + register_code(hex_to_keycode(digit)); + unregister_code(hex_to_keycode(digit)); + } + } else { + register_code(hex_to_keycode(digit)); + unregister_code(hex_to_keycode(digit)); + onzerostart = 0; + } } } +__attribute__((weak)) +void unicode_map_input_error() {} + bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { const uint32_t* map = unicode_map; uint16_t index = keycode & 0x7FF; - unicode_input_start(); - register_hex32(pgm_read_dword_far(&map[index])); - unicode_input_finish(); + uint32_t code = pgm_read_dword_far(&map[index]); + if ((code > 0xFFFF && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { + // when character is out of range supported by the OS + unicode_map_input_error(); + } else { + unicode_input_start(); + register_hex32(code); + unicode_input_finish(); + } } return true; } diff --git a/readme.md b/readme.md index 62d479ff1..9264f9376 100644 --- a/readme.md +++ b/readme.md @@ -326,8 +326,14 @@ This allows you to send unicode symbols via `UC()` in your keymap. Only `UNICODEMAP_ENABLE` This allows sending unicode symbols using `X()` in your keymap. Codes -up to 0xFFFFF are supported, including emojis. But you need to maintain a -separate mapping table in your keymap file. +up to 0xFFFFFFFF are supported, including emojis. You will need to maintain +a separate mapping table in your keymap file. + +Known limitations: +- Under Mac OS, only codes up to 0xFFFF are supported. +- Under Linux ibus, only codes up to 0xFFFFF are supported (but anything important is still under this limit for now). + +Characters out of range supported by the OS will be ignored. `BLUETOOTH_ENABLE` -- cgit v1.2.3 From 4a666c201007eacf13a9031e3c9b156e2e04afe6 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Sun, 23 Oct 2016 19:15:33 +0700 Subject: Unicode WinCompose input method --- quantum/process_keycode/process_unicode.c | 5 +++++ quantum/process_keycode/process_unicode.h | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'quantum') diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 37dd471ff..2a991cb39 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -42,6 +42,11 @@ void unicode_input_start (void) { register_code(KC_PPLS); unregister_code(KC_PPLS); break; + case UC_WINC: + register_code(KC_RALT); + unregister_code(KC_RALT); + register_code(KC_U); + unregister_code(KC_U); } wait_ms(UNICODE_TYPE_DELAY); } diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index a6c7e4584..065eeb5f6 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h @@ -3,10 +3,11 @@ #include "quantum.h" -#define UC_OSX 0 -#define UC_LNX 1 -#define UC_WIN 2 -#define UC_BSD 3 +#define UC_OSX 0 // Mac OS X +#define UC_LNX 1 // Linux +#define UC_WIN 2 // Windows 'HexNumpad' +#define UC_BSD 3 // BSD (not implemented) +#define UC_WINC 4 // WinCompose https://github.com/samhocevar/wincompose #ifndef UNICODE_TYPE_DELAY #define UNICODE_TYPE_DELAY 10 -- cgit v1.2.3 From 17170ba76d3c94edcf1ab263520238fdb0384774 Mon Sep 17 00:00:00 2001 From: IBNobody Date: Sun, 23 Oct 2016 23:00:43 -0500 Subject: Fixed some large keyboard bugs Fixed some bugs relating to keyboards with more than 16 columns. Also added the ability to mask off keyboard matrix bits. --- keyboards/vision_division/config.h | 2 ++ keyboards/vision_division/keymaps/default/keymap.c | 11 +++++++ quantum/matrix.c | 37 +++++++++++++++++++--- readme.md | 1 + tmk_core/common/command.c | 6 ++-- 5 files changed, 50 insertions(+), 7 deletions(-) (limited to 'quantum') diff --git a/keyboards/vision_division/config.h b/keyboards/vision_division/config.h index 1f8466a54..93c960671 100644 --- a/keyboards/vision_division/config.h +++ b/keyboards/vision_division/config.h @@ -33,6 +33,8 @@ along with this program. If not, see . /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ #define DEBOUNCING_DELAY 5 +#define MATRIX_MASKED + /* define if matrix has ghost (lacks anti-ghosting diodes) */ //#define MATRIX_HAS_GHOST diff --git a/keyboards/vision_division/keymaps/default/keymap.c b/keyboards/vision_division/keymaps/default/keymap.c index 8622ee521..3282761c0 100644 --- a/keyboards/vision_division/keymaps/default/keymap.c +++ b/keyboards/vision_division/keymaps/default/keymap.c @@ -142,6 +142,17 @@ enum keyboard_macros { #define ________________ _______, _______ #define XXXXXXXXXXXXXXXX XXXXXXX, XXXXXXX +const matrix_row_t matrix_mask[MATRIX_ROWS] = +{ +// 1098765432109876543210987654321 + 0b0000000001111111101111011111111, + 0b0000000001111111111111111111111, + 0b0000000001111111111111111111111, + 0b0000000001111111111111111111111, + 0b0000000001010111111111111111111, + 0b0000000001111101111111101011111, +}; + const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* LAYER = LAYER_QWERTY diff --git a/quantum/matrix.c b/quantum/matrix.c index 3174e0739..ac81794e5 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -26,6 +26,10 @@ along with this program. If not, see . #include "util.h" #include "matrix.h" +#ifdef MATRIX_MASKED +extern const matrix_row_t matrix_mask[]; +#endif + /* Set 0 if debouncing isn't needed */ #ifndef DEBOUNCING_DELAY @@ -218,15 +222,34 @@ bool matrix_is_on(uint8_t row, uint8_t col) inline matrix_row_t matrix_get_row(uint8_t row) { + // Matrix mask lets you disable switches in the returned matrix data. For example, if you have a + // switch blocker installed and the switch is always pressed. +#ifdef MATRIX_MASKED + return matrix[row] & matrix_mask[row]; +#else return matrix[row]; +#endif } void matrix_print(void) { +#if (MATRIX_COLS <= 8) + print("\nr/c 01234567\n"); +#elif (MATRIX_COLS <= 16) print("\nr/c 0123456789ABCDEF\n"); +#elif (MATRIX_COLS <= 32) + print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n"); +#endif + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { phex(row); print(": "); - pbin_reverse16(matrix_get_row(row)); +#if (MATRIX_COLS <= 8) + print_bin_reverse8(matrix_get_row(row)); +#elif (MATRIX_COLS <= 16) + print_bin_reverse16(matrix_get_row(row)); +#elif (MATRIX_COLS <= 32) + print_bin_reverse32(matrix_get_row(row)); +#endif print("\n"); } } @@ -235,7 +258,13 @@ uint8_t matrix_key_count(void) { uint8_t count = 0; for (uint8_t i = 0; i < MATRIX_ROWS; i++) { +#if (MATRIX_COLS <= 8) + count += bitpop(matrix[i]); +#elif (MATRIX_COLS <= 16) count += bitpop16(matrix[i]); +#elif (MATRIX_COLS <= 32) + count += bitpop32(matrix[i]); +#endif } return count; } @@ -259,7 +288,7 @@ static matrix_row_t read_cols(void) matrix_row_t result = 0; #if DIODE_DIRECTION == COL2ROW - for(int x = 0; x < MATRIX_COLS; x++) { + for(int x = 0; x < MATRIX_COLS; x++) { int pin = col_pins[x]; #else for(int x = 0; x < MATRIX_ROWS; x++) { @@ -273,10 +302,10 @@ static matrix_row_t read_cols(void) static void unselect_rows(void) { #if DIODE_DIRECTION == COL2ROW - for(int x = 0; x < MATRIX_ROWS; x++) { + for(int x = 0; x < MATRIX_ROWS; x++) { int pin = row_pins[x]; #else - for(int x = 0; x < MATRIX_COLS; x++) { + for(int x = 0; x < MATRIX_COLS; x++) { int pin = col_pins[x]; #endif _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); diff --git a/readme.md b/readme.md index 62d479ff1..c460933a7 100644 --- a/readme.md +++ b/readme.md @@ -241,6 +241,7 @@ You can also add extra options at the end of the make command line, after the ta * `make COLOR=false` - turns off color output * `make SILENT=true` - turns off output besides errors/warnings * `make VERBOSE=true` - outputs all of the gcc stuff (not interesting, unless you need to debug) +* `make EXTRAFLAGS=-E` - Preprocess the code without doing any compiling (useful if you are trying to debug #define commands) The make command itself also has some additional options, type `make --help` for more information. The most useful is probably `-jx`, which specifies that you want to compile using more than one CPU, the `x` represents the number of CPUs that you want to use. Setting that can greatly reduce the compile times, especially if you are compiling many keyboards/keymaps. I usually set it to one less than the number of CPUs that I have, so that I have some left for doing other things while it's compiling. Note that not all operating systems and make versions supports that option. diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index f3e1bf623..5f29bc0b4 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c @@ -379,11 +379,11 @@ static bool command_common(uint8_t code) debug_enable = !debug_enable; if (debug_enable) { print("\ndebug: on\n"); - debug_matrix = true; - debug_keyboard = true; - debug_mouse = true; } else { print("\ndebug: off\n"); + debug_matrix = false; + debug_keyboard = false; + debug_mouse = false; } break; -- cgit v1.2.3 From 508eddf8ba8548d3f71e1c09a404839beb49f45c Mon Sep 17 00:00:00 2001 From: IBNobody Date: Fri, 28 Oct 2016 14:21:38 -0500 Subject: Fixing Debounce - WIP --- keyboards/vision_division/config.h | 2 +- quantum/matrix.c | 246 ++++++++++++++++++++++++------------- tmk_core/common/matrix.h | 10 ++ 3 files changed, 174 insertions(+), 84 deletions(-) (limited to 'quantum') diff --git a/keyboards/vision_division/config.h b/keyboards/vision_division/config.h index 93c960671..5798d91ad 100644 --- a/keyboards/vision_division/config.h +++ b/keyboards/vision_division/config.h @@ -31,7 +31,7 @@ along with this program. If not, see . #define BACKLIGHT_LEVELS 3 /* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */ -#define DEBOUNCING_DELAY 5 +#define DEBOUNCING_DELAY 0 #define MATRIX_MASKED diff --git a/quantum/matrix.c b/quantum/matrix.c index ac81794e5..a7dab0987 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c @@ -26,6 +26,33 @@ along with this program. If not, see . #include "util.h" #include "matrix.h" +#if (MATRIX_COLS <= 8) +# define print_matrix_header() print("\nr/c 01234567\n") +# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop(matrix[i]) +# define ROW_SHIFTER ((uint8_t)1) +#elif (MATRIX_COLS <= 16) +# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n") +# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop16(matrix[i]) +# define ROW_SHIFTER ((uint16_t)1) +#elif (MATRIX_COLS <= 32) +# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n") +# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row)) +# define matrix_bitpop(i) bitpop32(matrix[i]) +# define ROW_SHIFTER ((uint32_t)1) +#endif + +#if (MATRIX_ROWS <= 8) +# define COL_SHIFTER ((uint8_t)1) +#elif (MATRIX_ROWS <= 16) +# define COL_SHIFTER ((uint16_t)1) +#elif (MATRIX_ROWS <= 32) +# define COL_SHIFTER ((uint32_t)1) +#endif + + + #ifdef MATRIX_MASKED extern const matrix_row_t matrix_mask[]; #endif @@ -42,24 +69,28 @@ static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; /* matrix state(1:on, 0:off) */ static matrix_row_t matrix[MATRIX_ROWS]; -static matrix_row_t matrix_debouncing[MATRIX_ROWS]; -#if DIODE_DIRECTION == ROW2COL - static matrix_row_t matrix_reversed[MATRIX_COLS]; - static matrix_row_t matrix_reversed_debouncing[MATRIX_COLS]; +#if DIODE_DIRECTION == COL2ROW + static matrix_row_t matrix_debouncing[MATRIX_ROWS]; +#else // ROW2COL + static matrix_col_t matrix_transposed[MATRIX_COLS]; + static matrix_col_t matrix_transposed_debouncing[MATRIX_COLS]; #endif -#if MATRIX_COLS > 16 - #define SHIFTER 1UL -#else - #define SHIFTER 1 +#if (DIODE_DIRECTION == COL2ROW) + static void init_cols(void); + static matrix_row_t read_cols(void); + static void unselect_rows(void); + static void select_row(uint8_t row); + static void unselect_row(uint8_t row); +#else // ROW2COL + static void init_rows(void); + static matrix_col_t read_rows(void); + static void unselect_cols(void); + static void unselect_col(uint8_t col); + static void select_col(uint8_t col); #endif -static matrix_row_t read_cols(void); -static void init_cols(void); -static void unselect_rows(void); -static void select_row(uint8_t row); - __attribute__ ((weak)) void matrix_init_quantum(void) { matrix_init_kb(); @@ -99,7 +130,7 @@ uint8_t matrix_cols(void) { } // void matrix_power_up(void) { -// #if DIODE_DIRECTION == COL2ROW +// #if (DIODE_DIRECTION == COL2ROW) // for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) { // /* DDRxn */ // _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF); @@ -123,13 +154,15 @@ uint8_t matrix_cols(void) { // } void matrix_init(void) { + // To use PORTF disable JTAG with writing JTD bit twice within four cycles. - #ifdef __AVR_ATmega32U4__ + #if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__)) MCUCR |= _BV(JTD); MCUCR |= _BV(JTD); #endif // initialize row and col +#if (DIODE_DIRECTION == COL2ROW) unselect_rows(); init_cols(); @@ -139,25 +172,43 @@ void matrix_init(void) { matrix_debouncing[i] = 0; } +#else // ROW2COL + unselect_cols(); + init_rows(); + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix[i] = 0; + } + + // initialize matrix state: all keys off + for (uint8_t i=0; i < MATRIX_COLS; i++) { + matrix_transposed_debouncing[i] = 0; + } +#endif + matrix_init_quantum(); } uint8_t matrix_scan(void) { -#if DIODE_DIRECTION == COL2ROW +#if (DIODE_DIRECTION == COL2ROW) + + // Set row, read cols + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { select_row(i); wait_us(30); // without this wait read unstable value. - matrix_row_t cols = read_cols(); - if (matrix_debouncing[i] != cols) { - matrix_debouncing[i] = cols; + matrix_row_t current_row = read_cols(); + if (matrix_debouncing[i] != current_row) { + matrix_debouncing[i] = current_row; if (debouncing) { debug("bounce!: "); debug_hex(debouncing); debug("\n"); } debouncing = DEBOUNCING_DELAY; } - unselect_rows(); + unselect_row(i); } if (debouncing) { @@ -169,19 +220,23 @@ uint8_t matrix_scan(void) } } } -#else + +#else // ROW2COL + + // Set col, read rows + for (uint8_t i = 0; i < MATRIX_COLS; i++) { - select_row(i); + select_col(i); wait_us(30); // without this wait read unstable value. - matrix_row_t rows = read_cols(); - if (matrix_reversed_debouncing[i] != rows) { - matrix_reversed_debouncing[i] = rows; + matrix_col_t current_col = read_rows(); + if (matrix_transposed_debouncing[i] != current_col) { + matrix_transposed_debouncing[i] = current_col; if (debouncing) { debug("bounce!: "); debug_hex(debouncing); debug("\n"); } debouncing = DEBOUNCING_DELAY; } - unselect_rows(); + unselect_col(i); } if (debouncing) { @@ -189,17 +244,20 @@ uint8_t matrix_scan(void) wait_ms(1); } else { for (uint8_t i = 0; i < MATRIX_COLS; i++) { - matrix_reversed[i] = matrix_reversed_debouncing[i]; + matrix_transposed[i] = matrix_transposed_debouncing[i]; } } } + + // Untranspose matrix for (uint8_t y = 0; y < MATRIX_ROWS; y++) { matrix_row_t row = 0; for (uint8_t x = 0; x < MATRIX_COLS; x++) { - row |= ((matrix_reversed[x] & (1<> y) << x; + row |= ((matrix_transposed[x] & (1<> y) << x; } matrix[y] = row; } + #endif matrix_scan_quantum(); @@ -233,23 +291,11 @@ matrix_row_t matrix_get_row(uint8_t row) void matrix_print(void) { -#if (MATRIX_COLS <= 8) - print("\nr/c 01234567\n"); -#elif (MATRIX_COLS <= 16) - print("\nr/c 0123456789ABCDEF\n"); -#elif (MATRIX_COLS <= 32) - print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n"); -#endif + print_matrix_header(); for (uint8_t row = 0; row < MATRIX_ROWS; row++) { phex(row); print(": "); -#if (MATRIX_COLS <= 8) - print_bin_reverse8(matrix_get_row(row)); -#elif (MATRIX_COLS <= 16) - print_bin_reverse16(matrix_get_row(row)); -#elif (MATRIX_COLS <= 32) - print_bin_reverse32(matrix_get_row(row)); -#endif + print_matrix_row(row); print("\n"); } } @@ -258,28 +304,21 @@ uint8_t matrix_key_count(void) { uint8_t count = 0; for (uint8_t i = 0; i < MATRIX_ROWS; i++) { -#if (MATRIX_COLS <= 8) - count += bitpop(matrix[i]); -#elif (MATRIX_COLS <= 16) - count += bitpop16(matrix[i]); -#elif (MATRIX_COLS <= 32) - count += bitpop32(matrix[i]); -#endif + count += matrix_bitpop(i); } return count; } + + +#if (DIODE_DIRECTION == COL2ROW) + static void init_cols(void) { -#if DIODE_DIRECTION == COL2ROW - for(int x = 0; x < MATRIX_COLS; x++) { - int pin = col_pins[x]; -#else - for(int x = 0; x < MATRIX_ROWS; x++) { - int pin = row_pins[x]; -#endif - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); + for(uint8_t x = 0; x < MATRIX_COLS; x++) { + uint8_t pin = col_pins[x]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI } } @@ -287,40 +326,81 @@ static matrix_row_t read_cols(void) { matrix_row_t result = 0; -#if DIODE_DIRECTION == COL2ROW - for(int x = 0; x < MATRIX_COLS; x++) { - int pin = col_pins[x]; -#else - for(int x = 0; x < MATRIX_ROWS; x++) { - int pin = row_pins[x]; -#endif - result |= (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) ? 0 : (SHIFTER << x); + for(uint8_t x = 0; x < MATRIX_COLS; x++) { + uint8_t pin = col_pins[x]; + result |= (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) ? 0 : (ROW_SHIFTER << x); } + return result; } +static void select_row(uint8_t row) +{ + uint8_t pin = row_pins[row]; + _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT + _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW +} + +static void unselect_row(uint8_t row) +{ + uint8_t pin = row_pins[row]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI +} + static void unselect_rows(void) { -#if DIODE_DIRECTION == COL2ROW - for(int x = 0; x < MATRIX_ROWS; x++) { - int pin = row_pins[x]; -#else - for(int x = 0; x < MATRIX_COLS; x++) { - int pin = col_pins[x]; -#endif - _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); - _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); + for(uint8_t x = 0; x < MATRIX_ROWS; x++) { + uint8_t pin = row_pins[x]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI } } -static void select_row(uint8_t row) +#else // ROW2COL + +static void init_rows(void) { + for(uint8_t x = 0; x < MATRIX_ROWS; x++) { + uint8_t pin = row_pins[x]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + } +} -#if DIODE_DIRECTION == COL2ROW - int pin = row_pins[row]; -#else - int pin = col_pins[row]; -#endif - _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); - _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); +static matrix_col_t read_rows(void) +{ + matrix_col_t result = 0; + + for(uint8_t x = 0; x < MATRIX_ROWS; x++) { + uint8_t pin = row_pins[x]; + result |= (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) ? 0 : (COL_SHIFTER << x); + } + + return result; +} + +static void select_col(uint8_t col) +{ + uint8_t pin = col_pins[col]; + _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT + _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW +} + +static void unselect_col(uint8_t col) +{ + uint8_t pin = col_pins[col]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI } + +static void unselect_cols(void) +{ + for(uint8_t x = 0; x < MATRIX_COLS; x++) { + uint8_t pin = col_pins[x]; + _SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI + } +} + +#endif diff --git a/tmk_core/common/matrix.h b/tmk_core/common/matrix.h index cee3593ee..84e066c67 100644 --- a/tmk_core/common/matrix.h +++ b/tmk_core/common/matrix.h @@ -31,6 +31,16 @@ typedef uint32_t matrix_row_t; #error "MATRIX_COLS: invalid value" #endif +#if (MATRIX_ROWS <= 8) +typedef uint8_t matrix_col_t; +#elif (MATRIX_ROWS <= 16) +typedef uint16_t matrix_col_t; +#elif (MATRIX_ROWS <= 32) +typedef uint32_t matrix_col_t; +#else +#error "MATRIX_COLS: invalid value" +#endif + #define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<. # define ROW_SHIFTER ((uint32_t)1) #endif -#if (MATRIX_ROWS <= 8) -# define COL_SHIFTER ((uint8_t)1) -#elif (MATRIX_ROWS <= 16) -# define COL_SHIFTER ((uint16_t)1) -#elif (MATRIX_ROWS <= 32) -# define COL_SHIFTER ((uint32_t)1) -#endif - - - #ifdef MATRIX_MASKED extern const matrix_row_t matrix_mask[]; #endif @@ -70,6 +60,9 @@ static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; /* matrix state(1:on, 0:off) */ static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_raw[MATRIX_ROWS]; + + #if DIODE_DIRECTION == COL2ROW static matrix_row_t matrix_debouncing[MATRIX_ROWS]; #else // ROW2COL @@ -79,13 +72,13 @@ static matrix_row_t matrix[MATRIX_ROWS]; #if (DIODE_DIRECTION == COL2ROW) static void init_cols(void); - static matrix_row_t read_cols(void); + static void read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) static void unselect_rows(void); static void select_row(uint8_t row); static void unselect_row(uint8_t row); #else // ROW2COL static void init_rows(void); - static matrix_col_t read_rows(void); + static void read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) static void unselect_cols(void); static void unselect_col(uint8_t col); static void select_col(uint8_t col); @@ -169,6 +162,7 @@ void matrix_init(void) { // initialize matrix state: all keys off for (uint8_t i=0; i < MATRIX_ROWS; i++) { matrix[i] = 0; + matrix_raw[i] = 0; matrix_debouncing[i] = 0; } @@ -178,6 +172,7 @@ void matrix_init(void) { // initialize matrix state: all keys off for (uint8_t i=0; i < MATRIX_ROWS; i++) { + matrix_raw[i] = 0; matrix[i] = 0; } @@ -196,67 +191,73 @@ uint8_t matrix_scan(void) #if (DIODE_DIRECTION == COL2ROW) // Set row, read cols - - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - select_row(i); - wait_us(30); // without this wait read unstable value. - matrix_row_t current_row = read_cols(); - if (matrix_debouncing[i] != current_row) { - matrix_debouncing[i] = current_row; - if (debouncing) { - debug("bounce!: "); debug_hex(debouncing); debug("\n"); - } - debouncing = DEBOUNCING_DELAY; - } - unselect_row(i); + for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { + read_cols_on_row(matrix, current_row); } - if (debouncing) { - if (--debouncing) { - wait_ms(1); - } else { - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - matrix[i] = matrix_debouncing[i]; - } - } - } + // select_row(i); + // wait_us(30); // without this wait read unstable value. + // matrix_row_t current_row = read_cols(); + // if (matrix_debouncing[i] != current_row) { + // matrix_debouncing[i] = current_row; + // if (debouncing) { + // debug("bounce!: "); debug_hex(debouncing); debug("\n"); + // } + // debouncing = DEBOUNCING_DELAY; + // } + // unselect_row(i); + // } + + // if (debouncing) { + // if (--debouncing) { + // wait_ms(1); + // } else { + // for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + // matrix[i] = matrix_debouncing[i]; + // } + // } + // } #else // ROW2COL // Set col, read rows - - for (uint8_t i = 0; i < MATRIX_COLS; i++) { - select_col(i); - wait_us(30); // without this wait read unstable value. - matrix_col_t current_col = read_rows(); - if (matrix_transposed_debouncing[i] != current_col) { - matrix_transposed_debouncing[i] = current_col; - if (debouncing) { - debug("bounce!: "); debug_hex(debouncing); debug("\n"); - } - debouncing = DEBOUNCING_DELAY; - } - unselect_col(i); + for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { + read_rows_on_col(matrix, current_col); } - if (debouncing) { - if (--debouncing) { - wait_ms(1); - } else { - for (uint8_t i = 0; i < MATRIX_COLS; i++) { - matrix_transposed[i] = matrix_transposed_debouncing[i]; - } - } - } - // Untranspose matrix - for (uint8_t y = 0; y < MATRIX_ROWS; y++) { - matrix_row_t row = 0; - for (uint8_t x = 0; x < MATRIX_COLS; x++) { - row |= ((matrix_transposed[x] & (1<> y) << x; - } - matrix[y] = row; - } + // for (uint8_t i = 0; i < MATRIX_COLS; i++) { + // select_col(i); + // wait_us(30); // without this wait read unstable value. + // matrix_col_t current_col = read_rows(); + // if (matrix_transposed_debouncing[i] != current_col) { + // matrix_transposed_debouncing[i] = current_col; + // if (debouncing) { + // debug("bounce!: "); debug_hex(debouncing); debug("\n"); + // } + // debouncing = DEBOUNCING_DELAY; + // } + // unselect_col(i); + // } + + // if (debouncing) { + // if (--debouncing) { + // wait_ms(1); + // } else { + // for (uint8_t i = 0; i < MATRIX_COLS; i++) { + // matrix_transposed[i] = matrix_transposed_debouncing[i]; + // } + // } + // } + + // // Untranspose matrix + // for (uint8_t y = 0; y < MATRIX_ROWS; y++) { + // matrix_row_t row = 0; + // for (uint8_t x = 0; x < MATRIX_COLS; x++) { + // row |= ((matrix_transposed[x] & (1<> y) << x; + // } + // matrix[y] = row; + // } #endif @@ -322,16 +323,25 @@ static void init_cols(void) } } -static matrix_row_t read_cols(void) +static void read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { - matrix_row_t result = 0; + // Clear data in matrix row + current_matrix[current_row] = 0; - for(uint8_t x = 0; x < MATRIX_COLS; x++) { - uint8_t pin = col_pins[x]; - result |= (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) ? 0 : (ROW_SHIFTER << x); - } + // Select row and wait for row selecton to stabilize + select_row(current_row); + wait_us(30); - return result; + // For each col... + for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { + + // Select the col pin to read (active low) + uint8_t pin = col_pins[col_index]; + uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)); + + // Populate the matrix row with the state of the col pin + current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index); + } } static void select_row(uint8_t row) @@ -368,16 +378,23 @@ static void init_rows(void) } } -static matrix_col_t read_rows(void) +static void read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { - matrix_col_t result = 0; - for(uint8_t x = 0; x < MATRIX_ROWS; x++) { - uint8_t pin = row_pins[x]; - result |= (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) ? 0 : (COL_SHIFTER << x); - } + // Select col and wait for col selecton to stabilize + select_col(current_col); + wait_us(30); - return result; + // For each row... + for(uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++) { + + // Select the row pin to read (active low) + uint8_t pin = row_pins[row_index]; + uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)); + + // Populate the matrix row with the state of the col pin + current_matrix[row_index] &= pin_state ? ~(ROW_SHIFTER << current_col) : 0; + } } static void select_col(uint8_t col) diff --git a/tmk_core/common/matrix.h b/tmk_core/common/matrix.h index 84e066c67..cee3593ee 100644 --- a/tmk_core/common/matrix.h +++ b/tmk_core/common/matrix.h @@ -31,16 +31,6 @@ typedef uint32_t matrix_row_t; #error "MATRIX_COLS: invalid value" #endif -#if (MATRIX_ROWS <= 8) -typedef uint8_t matrix_col_t; -#elif (MATRIX_ROWS <= 16) -typedef uint16_t matrix_col_t; -#elif (MATRIX_ROWS <= 32) -typedef uint32_t matrix_col_t; -#else -#error "MATRIX_COLS: invalid value" -#endif - #define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<> 4) & _BV(pin & 0xF)); - - // Populate the matrix row with the state of the col pin - current_matrix[row_index] &= pin_state ? ~(ROW_SHIFTER << current_col) : 0; + // Check row pin state + if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0) + { + // Pin LO, set col bit + current_matrix[row_index] |= (ROW_SHIFTER << current_col); + } + else + { + // Pin HI, clear col bit + current_matrix[row_index] &= ~(ROW_SHIFTER << current_col); + } } + + // Unselect col + unselect_col(current_col); } static void select_col(uint8_t col) -- cgit v1.2.3