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. --- tmk_core/common/command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tmk_core/common') 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-24-g4f1b From 508eddf8ba8548d3f71e1c09a404839beb49f45c Mon Sep 17 00:00:00 2001 From: IBNobody Date: Fri, 28 Oct 2016 14:21:38 -0500 Subject: Fixing Debounce - WIP --- tmk_core/common/matrix.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tmk_core/common') 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< Date: Fri, 28 Oct 2016 16:24:20 -0500 Subject: Refactoring Matrix scanning --- tmk_core/common/matrix.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'tmk_core/common') 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< Date: Mon, 21 Nov 2016 20:14:16 -0500 Subject: cleaning up midid --- tmk_core/common/host_driver.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/host_driver.h b/tmk_core/common/host_driver.h index edb9e5dd9..588d1c0be 100644 --- a/tmk_core/common/host_driver.h +++ b/tmk_core/common/host_driver.h @@ -20,7 +20,9 @@ along with this program. If not, see . #include #include "report.h" - +#ifdef MIDI_ENABLE + #include "midi.h" +#endif typedef struct { uint8_t (*keyboard_leds)(void); @@ -28,6 +30,11 @@ typedef struct { void (*send_mouse)(report_mouse_t *); void (*send_system)(uint16_t); void (*send_consumer)(uint16_t); +#ifdef MIDI_ENABLE + void (*usb_send_func)(MidiDevice *, uint16_t, uint8_t, uint8_t, uint8_t); + void (*usb_get_midi)(MidiDevice *); + void (*midi_usb_init)(MidiDevice *); +#endif } host_driver_t; #endif -- cgit v1.2.3-24-g4f1b From d37becc0a9203c4c7d52aca6190b4b3d9fb69a59 Mon Sep 17 00:00:00 2001 From: PureSpider Date: Tue, 22 Nov 2016 22:12:57 +0100 Subject: Set backlight status to on if it's at maximum brightness already and the brightness increase keybind is used Before it was turned on but the status wasn't set to on, so you had to push the backlight toggle bind twice to turn it off again --- tmk_core/common/backlight.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/backlight.c b/tmk_core/common/backlight.c index c9e8fd3fd..0e0ad2d15 100644 --- a/tmk_core/common/backlight.c +++ b/tmk_core/common/backlight.c @@ -36,9 +36,9 @@ void backlight_increase(void) if(backlight_config.level < BACKLIGHT_LEVELS) { backlight_config.level++; - backlight_config.enable = 1; - eeconfig_update_backlight(backlight_config.raw); } + backlight_config.enable = 1; + eeconfig_update_backlight(backlight_config.raw); dprintf("backlight increase: %u\n", backlight_config.level); backlight_set(backlight_config.level); } -- cgit v1.2.3-24-g4f1b From 5893f0fa1fcecfface25ce570f37e51031a14489 Mon Sep 17 00:00:00 2001 From: Wilba6582 Date: Wed, 23 Nov 2016 16:22:57 +1100 Subject: Fixed NO_SUSPEND_POWER_DOWN handling --- tmk_core/common/avr/suspend.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 8a7272bbc..939bda15e 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -47,6 +47,7 @@ void suspend_idle(uint8_t time) sleep_disable(); } +#ifndef NO_SUSPEND_POWER_DOWN /* Power down MCU with watchdog timer * wdto: watchdog timer timeout defined in * WDTO_15MS @@ -61,6 +62,7 @@ void suspend_idle(uint8_t time) * WDTO_8S */ static uint8_t wdt_timeout = 0; + static void power_down(uint8_t wdto) { #ifdef PROTOCOL_LUFA @@ -98,10 +100,13 @@ static void power_down(uint8_t wdto) // Disable watchdog after sleep wdt_disable(); } +#endif void suspend_power_down(void) { +#ifndef NO_SUSPEND_POWER_DOWN power_down(WDTO_15MS); +#endif } __attribute__ ((weak)) void matrix_power_up(void) {} @@ -109,7 +114,9 @@ __attribute__ ((weak)) void matrix_power_down(void) {} bool suspend_wakeup_condition(void) { #ifdef BACKLIGHT_ENABLE +#ifndef NO_SUSPEND_POWER_DOWN backlight_set(0); +#endif #endif matrix_power_up(); matrix_scan(); @@ -126,7 +133,6 @@ void suspend_wakeup_init(void) // clear keyboard state clear_keyboard(); #ifdef BACKLIGHT_ENABLE - backlight_set(0); backlight_init(); #endif led_set(host_keyboard_leds()); -- cgit v1.2.3-24-g4f1b From cf3926a8e13edb76193b8af25b497f9ef61161fd Mon Sep 17 00:00:00 2001 From: Wilba6582 Date: Wed, 23 Nov 2016 19:45:50 +1100 Subject: Fixed NO_SUSPEND_POWER_DOWN handling --- tmk_core/common/avr/suspend.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 939bda15e..0c81e8361 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -113,11 +113,6 @@ __attribute__ ((weak)) void matrix_power_up(void) {} __attribute__ ((weak)) void matrix_power_down(void) {} bool suspend_wakeup_condition(void) { -#ifdef BACKLIGHT_ENABLE -#ifndef NO_SUSPEND_POWER_DOWN - backlight_set(0); -#endif -#endif matrix_power_up(); matrix_scan(); matrix_power_down(); @@ -135,7 +130,7 @@ void suspend_wakeup_init(void) #ifdef BACKLIGHT_ENABLE backlight_init(); #endif -led_set(host_keyboard_leds()); + led_set(host_keyboard_leds()); } #ifndef NO_SUSPEND_POWER_DOWN -- cgit v1.2.3-24-g4f1b From be4e75423a232d9d328bb23835e0fa5152292c95 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 27 Nov 2016 22:41:22 -0800 Subject: Tidy up atomicity in timer.c and ring_buffer.h Adopt the macros for saving/restoring the interrupt state that are provided by the avr gcc environment. Removing intialization of the timer value; this shaves off a few bytes because globals are default initialized to zero. --- tmk_core/common/avr/timer.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c index 292b41c3a..84af44488 100644 --- a/tmk_core/common/avr/timer.c +++ b/tmk_core/common/avr/timer.c @@ -17,6 +17,7 @@ along with this program. If not, see . #include #include +#include #include #include "timer_avr.h" #include "timer.h" @@ -24,7 +25,7 @@ along with this program. If not, see . // counter resolution 1ms // NOTE: union { uint32_t timer32; struct { uint16_t dummy; uint16_t timer16; }} -volatile uint32_t timer_count = 0; +volatile uint32_t timer_count; void timer_init(void) { @@ -52,10 +53,9 @@ void timer_init(void) inline void timer_clear(void) { - uint8_t sreg = SREG; - cli(); + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { timer_count = 0; - SREG = sreg; + } } inline @@ -63,10 +63,9 @@ uint16_t timer_read(void) { uint32_t t; - uint8_t sreg = SREG; - cli(); - t = timer_count; - SREG = sreg; + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { + t = timer_count; + } return (t & 0xFFFF); } @@ -76,10 +75,9 @@ uint32_t timer_read32(void) { uint32_t t; - uint8_t sreg = SREG; - cli(); - t = timer_count; - SREG = sreg; + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { + t = timer_count; + } return t; } @@ -89,10 +87,9 @@ uint16_t timer_elapsed(uint16_t last) { uint32_t t; - uint8_t sreg = SREG; - cli(); - t = timer_count; - SREG = sreg; + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { + t = timer_count; + } return TIMER_DIFF_16((t & 0xFFFF), last); } @@ -102,10 +99,9 @@ uint32_t timer_elapsed32(uint32_t last) { uint32_t t; - uint8_t sreg = SREG; - cli(); - t = timer_count; - SREG = sreg; + ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { + t = timer_count; + } return TIMER_DIFF_32(t, last); } -- cgit v1.2.3-24-g4f1b From fe001d46fd06924bb81fe8d506f5be8894db3df0 Mon Sep 17 00:00:00 2001 From: Wilba6582 Date: Mon, 28 Nov 2016 18:31:16 +1100 Subject: Initial version of Raw HID interface --- tmk_core/common/raw_hid.h | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tmk_core/common/raw_hid.h (limited to 'tmk_core/common') diff --git a/tmk_core/common/raw_hid.h b/tmk_core/common/raw_hid.h new file mode 100644 index 000000000..86da02fd1 --- /dev/null +++ b/tmk_core/common/raw_hid.h @@ -0,0 +1,8 @@ +#ifndef _RAW_HID_H_ +#define _RAW_HID_H_ + +void raw_hid_receive( uint8_t *data, uint8_t length ); + +void raw_hid_send( uint8_t *data, uint8_t length ); + +#endif -- cgit v1.2.3-24-g4f1b From d8a608f3ff4cb4d73cd57be500fd9881e230099d Mon Sep 17 00:00:00 2001 From: Wilba6582 Date: Thu, 29 Dec 2016 18:28:48 +1100 Subject: Keycode refactor --- tmk_core/common/keycode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h index 2f208c54e..54e9c322c 100644 --- a/tmk_core/common/keycode.h +++ b/tmk_core/common/keycode.h @@ -85,7 +85,7 @@ along with this program. If not, see . #define KC_LCAP KC_LOCKING_CAPS #define KC_LNUM KC_LOCKING_NUM #define KC_LSCR KC_LOCKING_SCROLL -#define KC_ERAS KC_ALT_ERASE, +#define KC_ERAS KC_ALT_ERASE #define KC_CLR KC_CLEAR /* Japanese specific */ #define KC_ZKHK KC_GRAVE -- cgit v1.2.3-24-g4f1b From 6f44ca7a59d60e20c1d35e8edc916571f5fe40ef Mon Sep 17 00:00:00 2001 From: SjB Date: Sun, 15 Jan 2017 23:12:42 -0500 Subject: oneshot timeout would only timeout after an event. After setting a ONESHOT_TIMEOUT value, the oneshot layer state would not expire without an event being triggered (key pressed). The reason was that in the process_record function we would return priort to execute the process_action function if it detected a NOEVENT cycle. The process_action contained the codes to timeout the oneshot layer state. The codes to clear the oneshot layer state have been move just in front of where we check for the NOEVENT cycle in the process_record function. --- tmk_core/common/action.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index d485b46c7..a77177240 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -102,6 +102,13 @@ bool process_record_quantum(keyrecord_t *record) { void process_record(keyrecord_t *record) { +#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) + if (has_oneshot_layer_timed_out()) { + dprintf("Oneshot layer: timeout\n"); + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); + } +#endif + if (IS_NOEVENT(record->event)) { return; } if(!process_record_quantum(record)) @@ -126,13 +133,6 @@ void process_action(keyrecord_t *record, action_t action) uint8_t tap_count = record->tap.count; #endif -#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) - if (has_oneshot_layer_timed_out()) { - dprintf("Oneshot layer: timeout\n"); - clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); - } -#endif - if (event.pressed) { // clear the potential weak mods left by previously pressed keys clear_weak_mods(); -- cgit v1.2.3-24-g4f1b From 9eb8d05246fba4f46c04b8fa1884b8f2d2ee0664 Mon Sep 17 00:00:00 2001 From: SjB Date: Tue, 17 Jan 2017 21:47:07 -0500 Subject: added mods status bit to visualizer. Since we can't read the real_mods and oneshot_mods static variable directly within the update_user_visualizer_state function (Threading and serial link). We are know storing the mods states in the visualizer_keyboard_status_t structure. We can now display the status of the modifier keys on the LCD display. --- tmk_core/common/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 371d93f3e..765350792 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -188,7 +188,7 @@ MATRIX_LOOP_END: #endif #ifdef VISUALIZER_ENABLE - visualizer_update(default_layer_state, layer_state, host_keyboard_leds()); + visualizer_update(default_layer_state, layer_state, visualizer_get_mods(), host_keyboard_leds()); #endif // update LED -- cgit v1.2.3-24-g4f1b From f7462aaa613a08ba4b86dbb912ce26722cfccaff Mon Sep 17 00:00:00 2001 From: Luiz Ribeiro Date: Sat, 21 Jan 2017 12:30:06 -0500 Subject: Got ps2avrGB to work with the V-USB protocol --- tmk_core/common/avr/bootloader.c | 10 ++++++++++ tmk_core/common/avr/suspend.c | 2 ++ tmk_core/common/avr/timer.c | 33 ++++++++++++++++++++++++--------- tmk_core/common/command.c | 2 ++ 4 files changed, 38 insertions(+), 9 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c index ad547b985..98a24d178 100644 --- a/tmk_core/common/avr/bootloader.c +++ b/tmk_core/common/avr/bootloader.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -89,6 +90,10 @@ void bootloader_jump(void) { _delay_ms(5); #endif + #ifdef EEPROM_BOOTLOADER_START + eeprom_write_byte((uint8_t *)EEPROM_BOOTLOADER_START, 0x00); + #endif + // watchdog reset reset_key = BOOTLOADER_RESET_KEY; wdt_enable(WDTO_250MS); @@ -114,6 +119,11 @@ void bootloader_jump(void) { #endif } +#ifdef __AVR_ATmega32A__ +// MCUSR is actually called MCUCSR in ATmega32A +#define MCUSR MCUCSR +#endif + /* this runs before main() */ void bootloader_jump_after_watchdog_reset(void) __attribute__ ((used, naked, section (".init3"))); void bootloader_jump_after_watchdog_reset(void) diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 0c81e8361..0e97892d9 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -65,6 +65,7 @@ static uint8_t wdt_timeout = 0; static void power_down(uint8_t wdto) { +#ifndef __AVR_ATmega32A__ #ifdef PROTOCOL_LUFA if (USB_DeviceState == DEVICE_STATE_Configured) return; #endif @@ -99,6 +100,7 @@ static void power_down(uint8_t wdto) // Disable watchdog after sleep wdt_disable(); +#endif } #endif diff --git a/tmk_core/common/avr/timer.c b/tmk_core/common/avr/timer.c index 84af44488..369015200 100644 --- a/tmk_core/common/avr/timer.c +++ b/tmk_core/common/avr/timer.c @@ -29,25 +29,35 @@ volatile uint32_t timer_count; void timer_init(void) { - // Timer0 CTC mode - TCCR0A = 0x02; - #if TIMER_PRESCALER == 1 - TCCR0B = 0x01; + uint8_t prescaler = 0x01; #elif TIMER_PRESCALER == 8 - TCCR0B = 0x02; + uint8_t prescaler = 0x02; #elif TIMER_PRESCALER == 64 - TCCR0B = 0x03; + uint8_t prescaler = 0x03; #elif TIMER_PRESCALER == 256 - TCCR0B = 0x04; + uint8_t prescaler = 0x04; #elif TIMER_PRESCALER == 1024 - TCCR0B = 0x05; + uint8_t prescaler = 0x05; #else # error "Timer prescaler value is NOT vaild." #endif +#ifndef __AVR_ATmega32A__ + // Timer0 CTC mode + TCCR0A = 0x02; + + TCCR0B = prescaler; + OCR0A = TIMER_RAW_TOP; TIMSK0 = (1< Date: Sat, 21 Jan 2017 17:09:17 -0500 Subject: Simplified and polished a bit the code changes on tmk_core --- tmk_core/common/avr/bootloader.c | 6 ++++-- tmk_core/common/avr/suspend.c | 2 -- tmk_core/common/command.c | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/avr/bootloader.c b/tmk_core/common/avr/bootloader.c index 98a24d178..34db8d0b0 100644 --- a/tmk_core/common/avr/bootloader.c +++ b/tmk_core/common/avr/bootloader.c @@ -90,8 +90,10 @@ void bootloader_jump(void) { _delay_ms(5); #endif - #ifdef EEPROM_BOOTLOADER_START - eeprom_write_byte((uint8_t *)EEPROM_BOOTLOADER_START, 0x00); + #ifdef BOOTLOADHID_BOOTLOADER + // force bootloadHID to stay in bootloader mode, so that it waits + // for a new firmware to be flashed + eeprom_write_byte((uint8_t *)1, 0x00); #endif // watchdog reset diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index 0e97892d9..0c81e8361 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -65,7 +65,6 @@ static uint8_t wdt_timeout = 0; static void power_down(uint8_t wdto) { -#ifndef __AVR_ATmega32A__ #ifdef PROTOCOL_LUFA if (USB_DeviceState == DEVICE_STATE_Configured) return; #endif @@ -100,7 +99,6 @@ static void power_down(uint8_t wdto) // Disable watchdog after sleep wdt_disable(); -#endif } #endif diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index beba768ec..f79d5a257 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c @@ -236,6 +236,7 @@ static void print_status(void) print_val_hex8(host_keyboard_leds()); #ifndef PROTOCOL_VUSB + // these aren't set on the V-USB protocol, so we just ignore them for now print_val_hex8(keyboard_protocol); print_val_hex8(keyboard_idle); #endif -- cgit v1.2.3-24-g4f1b From 87bc36253dd915c51571e1972b771f49db9673d3 Mon Sep 17 00:00:00 2001 From: Luke Silva Date: Thu, 26 Jan 2017 22:44:22 +1100 Subject: Fix documentation for TMK actions --- tmk_core/common/action_code.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h index 33da35f35..b15aaa0eb 100644 --- a/tmk_core/common/action_code.h +++ b/tmk_core/common/action_code.h @@ -47,10 +47,15 @@ along with this program. If not, see . * 0100|10| usage(10) (reserved) * 0100|11| usage(10) (reserved) * - * ACT_MOUSEKEY(0110): TODO: Not needed? + * + * ACT_MOUSEKEY(0101): TODO: Merge these two actions to conserve space? * 0101|xxxx| keycode Mouse key * - * 011x|xxxx xxxx xxxx (reseved) + * ACT_SWAP_HANDS(0110): + * 0110|xxxx| keycode Swap hands (keycode on tap, or options) + * + * + * 0111|xxxx xxxx xxxx (reserved) * * * Layer Actions(10xx) @@ -67,7 +72,6 @@ along with this program. If not, see . * ee: on event(01:press, 10:release, 11:both) * * 1001|xxxx|xxxx xxxx (reserved) - * 1001|oopp|BBBB BBBB 8-bit Bitwise Operation??? * * ACT_LAYER_TAP(101x): * 101E|LLLL| keycode On/Off with tap key (0x00-DF)[TAP] -- cgit v1.2.3-24-g4f1b From a3357d078ee80123040679a357f63e93ff24c4c6 Mon Sep 17 00:00:00 2001 From: Luke Silva Date: Sat, 28 Jan 2017 18:42:35 +1100 Subject: Add support for various tapping macros A macro key can now be easily set to act as a modifier on hold, and press a shifted key when tapped. Or to switch layers when held, and again press a shifted key when tapped. Various other helper defines have been created which send macros when the key is pressed, released and tapped, cleaning up the action_get_macro function inside keymap definitions. The layer switching macros require a GCC extension - 'compound statements enclosed within parentheses'. The use of this extension is already present within the macro subsystem of this project, so its use in this commit should not cause any additional issues. MACRO_NONE had to be cast to a (macro_t*) to suppress compiler warnings within some tapping macros. --- tmk_core/common/action_macro.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_macro.h b/tmk_core/common/action_macro.h index aedc32ec6..f373f5068 100644 --- a/tmk_core/common/action_macro.h +++ b/tmk_core/common/action_macro.h @@ -20,11 +20,33 @@ along with this program. If not, see . #include "progmem.h" -#define MACRO_NONE 0 + +typedef uint8_t macro_t; + +#define MACRO_NONE (macro_t*)0 #define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) #define MACRO_GET(p) pgm_read_byte(p) -typedef uint8_t macro_t; +// Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped +#define MACRO_TAP_HOLD(record, press, release, tap_macro) ( ((record)->event.pressed) ? \ + ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE ) : \ + ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release) ) ) + +// Holds down the modifier mod when the macro key is held, or sends macro instead when tapped +#define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro) + +// Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #) +#define MACRO_TAP_SHFT_KEY_HOLD_MOD(record, key, mod) MACRO_TAP_HOLD_MOD(record, (MACRO(I(10), D(LSFT), T(key), U(LSFT), END)), mod) + + +// Momentary switch layer when held, sends macro if tapped +#define MACRO_TAP_HOLD_LAYER(record, macro, layer) ( ((record)->event.pressed) ? \ + ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({layer_on((layer)); MACRO_NONE; }) : MACRO_NONE ) : \ + ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({layer_off((layer)); MACRO_NONE; }) ) ) + +// Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #) +#define MACRO_TAP_SHFT_KEY_HOLD_LAYER(record, key, layer) MACRO_TAP_HOLD_LAYER(record, MACRO(I(10), D(LSFT), T(key), U(LSFT), END), layer) + #ifndef NO_ACTION_MACRO -- cgit v1.2.3-24-g4f1b From 45e0d09414c09c626d2349b6a5036a29fe03b1c6 Mon Sep 17 00:00:00 2001 From: SjB Date: Sun, 29 Jan 2017 12:56:20 -0500 Subject: moved oneshot cancellation code outside of process_record. The oneshot cancellation code do not depend on the action_tapping_process and since process_record get called via the action_tapping_process logic moved the oneshot cancellation code into the action_exec function just before the action_tapping_process call --- tmk_core/common/action.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index a77177240..f03670a7f 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -49,6 +49,13 @@ void action_exec(keyevent_t event) keyrecord_t record = { .event = event }; +#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) + if (has_oneshot_layer_timed_out()) { + dprintf("Oneshot layer: timeout\n"); + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); + } +#endif + #ifndef NO_ACTION_TAPPING action_tapping_process(record); #else @@ -100,15 +107,8 @@ bool process_record_quantum(keyrecord_t *record) { return true; } -void process_record(keyrecord_t *record) +void process_record(keyrecord_t *record) { -#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) - if (has_oneshot_layer_timed_out()) { - dprintf("Oneshot layer: timeout\n"); - clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); - } -#endif - if (IS_NOEVENT(record->event)) { return; } if(!process_record_quantum(record)) -- cgit v1.2.3-24-g4f1b From 06d21009b2198a2941f4c341807ad2290b5967f6 Mon Sep 17 00:00:00 2001 From: Nikolaus Wittenstein Date: Sun, 5 Feb 2017 19:55:08 -0500 Subject: Minor cleanup --- tmk_core/common/keyboard.c | 1 + tmk_core/common/matrix.h | 2 +- tmk_core/common/report.h | 7 ------- 3 files changed, 2 insertions(+), 8 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 765350792..3aa82231b 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -14,6 +14,7 @@ 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 #include "keyboard.h" #include "matrix.h" diff --git a/tmk_core/common/matrix.h b/tmk_core/common/matrix.h index cee3593ee..2543f5abc 100644 --- a/tmk_core/common/matrix.h +++ b/tmk_core/common/matrix.h @@ -50,7 +50,7 @@ void matrix_init(void); uint8_t matrix_scan(void); /* whether modified from previous scan. used after matrix_scan. */ bool matrix_is_modified(void) __attribute__ ((deprecated)); -/* whether a swtich is on */ +/* whether a switch is on */ bool matrix_is_on(uint8_t row, uint8_t col); /* matrix state on row */ matrix_row_t matrix_get_row(uint8_t row); diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h index 0c799eca3..8fb28b6ce 100644 --- a/tmk_core/common/report.h +++ b/tmk_core/common/report.h @@ -134,13 +134,6 @@ typedef union { } nkro; #endif } __attribute__ ((packed)) report_keyboard_t; -/* -typedef struct { - uint8_t mods; - uint8_t reserved; - uint8_t keys[REPORT_KEYS]; -} __attribute__ ((packed)) report_keyboard_t; -*/ typedef struct { uint8_t buttons; -- cgit v1.2.3-24-g4f1b From c68e596f32c5d450a714627871408407e9988ef7 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Mon, 13 Feb 2017 08:03:07 +0700 Subject: Implement faux-clicky feature --- tmk_core/common/action.c | 13 +++++++++++++ tmk_core/common/keyboard.c | 6 ++++++ 2 files changed, 19 insertions(+) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index f03670a7f..94de36918 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -33,6 +33,9 @@ along with this program. If not, see . #include "nodebug.h" #endif +#ifdef FAUXCLICKY_ENABLE +#include +#endif void action_exec(keyevent_t event) { @@ -41,6 +44,16 @@ void action_exec(keyevent_t event) dprint("EVENT: "); debug_event(event); dprintln(); } +#ifdef FAUXCLICKY_ENABLE + if (IS_PRESSED(event)) { + FAUXCLICKY_ACTION_PRESS; + } + if (IS_RELEASED(event)) { + FAUXCLICKY_ACTION_RELEASE; + } + fauxclicky_check(); +#endif + #ifdef ONEHAND_ENABLE if (!IS_NOEVENT(event)) { process_hand_swap(&event); diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 3aa82231b..eac1f1dd8 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -51,6 +51,9 @@ along with this program. If not, see . #ifdef RGBLIGHT_ENABLE # include "rgblight.h" #endif +#ifdef FAUXCLICKY_ENABLE +# include "fauxclicky.h" +#endif #ifdef SERIAL_LINK_ENABLE # include "serial_link/system/serial_link.h" #endif @@ -108,6 +111,9 @@ void keyboard_init(void) { #ifdef RGBLIGHT_ENABLE rgblight_init(); #endif +#ifdef FAUXCLICKY_ENABLE + fauxclicky_init(); +#endif #if defined(NKRO_ENABLE) && defined(FORCE_NKRO) keymap_config.nkro = 1; #endif -- cgit v1.2.3-24-g4f1b From 64f9779fe54facecdef9d1a6a7c1d893f79ca20e Mon Sep 17 00:00:00 2001 From: lambdalisue Date: Tue, 14 Feb 2017 14:12:54 +0900 Subject: Add TAPPING_FORCE_HOLD to regulate behaviour See #889 for the detail. --- tmk_core/common/action_tapping.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c index e16e11be7..66044d8bc 100644 --- a/tmk_core/common/action_tapping.c +++ b/tmk_core/common/action_tapping.c @@ -228,6 +228,7 @@ bool process_tapping(keyrecord_t *keyp) if (WITHIN_TAPPING_TERM(event)) { if (event.pressed) { if (IS_TAPPING_KEY(event.key)) { +#ifndef TAPPING_FORCE_HOLD if (!tapping_key.tap.interrupted && tapping_key.tap.count > 0) { // sequential tap. keyp->tap = tapping_key.tap; @@ -237,11 +238,11 @@ bool process_tapping(keyrecord_t *keyp) tapping_key = *keyp; debug_tapping_key(); return true; - } else { - // FIX: start new tap again - tapping_key = *keyp; - return true; } +#endif + // FIX: start new tap again + tapping_key = *keyp; + return true; } else if (is_tap_key(event.key)) { // Sequential tap can be interfered with other tap key. debug("Tapping: Start with interfering other tap.\n"); -- cgit v1.2.3-24-g4f1b From d369bfb83a74d94ed0fbb13f8ee3a8a1146da770 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Wed, 15 Feb 2017 05:02:15 +0700 Subject: Add layer_state_set_kb hook --- tmk_core/common/action_layer.c | 6 ++++++ tmk_core/common/action_layer.h | 2 ++ 2 files changed, 8 insertions(+) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index a3c757964..3363a2e53 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -57,8 +57,14 @@ void default_layer_xor(uint32_t state) */ uint32_t layer_state = 0; +__attribute__((weak)) +uint32_t layer_state_set_kb(uint32_t state) { + return state; +} + static void layer_state_set(uint32_t state) { + state = layer_state_set_kb(state); dprint("layer_state: "); layer_debug(); dprint(" to "); layer_state = state; diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index 025cf5420..fc714700d 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h @@ -69,6 +69,8 @@ void layer_xor(uint32_t state); #define layer_xor(state) #define layer_debug() +__attribute__((weak)) +void layer_state_set_kb(uint32_t oldstate, uint32_t newstate); #endif /* pressed actions cache */ -- cgit v1.2.3-24-g4f1b From d96175937bfa9f700d9ee54c20e5d963c12d02df Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Wed, 15 Feb 2017 05:19:31 +0700 Subject: Bug fix & added default_layer_state_set_kb --- tmk_core/common/action_layer.c | 6 ++++++ tmk_core/common/action_layer.h | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 3363a2e53..58d919a04 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -16,8 +16,14 @@ */ uint32_t default_layer_state = 0; +__attribute__((weak)) +uint32_t default_layer_state_set_kb(uint32_t state) { + return state; +} + static void default_layer_state_set(uint32_t state) { + state = default_layer_state_set_kb(state); debug("default_layer_state: "); default_layer_debug(); debug(" to "); default_layer_state = state; diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index fc714700d..785bb5be4 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h @@ -27,7 +27,10 @@ along with this program. If not, see . */ extern uint32_t default_layer_state; void default_layer_debug(void); -void default_layer_set(uint32_t state); +uint32_t default_layer_set(uint32_t state); + +__attribute__((weak)) +void default_layer_state_set_kb(uint32_t state); #ifndef NO_ACTION_LAYER /* bitwise operation */ @@ -70,7 +73,7 @@ void layer_xor(uint32_t state); #define layer_debug() __attribute__((weak)) -void layer_state_set_kb(uint32_t oldstate, uint32_t newstate); +uint32_t layer_state_set_kb(uint32_t state); #endif /* pressed actions cache */ -- cgit v1.2.3-24-g4f1b From bd8d717f1ff2eef42dfef490374a8cee61be5d87 Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo Date: Wed, 15 Feb 2017 05:25:08 +0700 Subject: Fix bug fix attempt --- tmk_core/common/action_layer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index 785bb5be4..d89ed6e5c 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h @@ -27,10 +27,10 @@ along with this program. If not, see . */ extern uint32_t default_layer_state; void default_layer_debug(void); -uint32_t default_layer_set(uint32_t state); +void default_layer_set(uint32_t state); __attribute__((weak)) -void default_layer_state_set_kb(uint32_t state); +uint32_t default_layer_state_set_kb(uint32_t state); #ifndef NO_ACTION_LAYER /* bitwise operation */ -- cgit v1.2.3-24-g4f1b From d0b4dcc82ce1dd8549c2f7416bf79f4d0c0f23a7 Mon Sep 17 00:00:00 2001 From: Phong Nguyen Date: Sat, 25 Feb 2017 19:49:03 +0700 Subject: Removes redundant {} which cause build failure when DEBUG_ACTION is set --- tmk_core/common/action_tapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tmk_core/common') diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c index e16e11be7..ff78d7f2a 100644 --- a/tmk_core/common/action_tapping.c +++ b/tmk_core/common/action_tapping.c @@ -257,7 +257,7 @@ bool process_tapping(keyrecord_t *keyp) return true; } } else { - if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n") {}; + if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n"); process_record(keyp); return true; } -- cgit v1.2.3-24-g4f1b