summaryrefslogtreecommitdiff
path: root/tmk_core/common/keyboard.c
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2021-06-29 12:23:03 -0700
committerDrashna Jael're <drashna@live.com>2021-06-29 12:24:07 -0700
commitacf2c323e2927f6007b17ded577cf49fd86fec6c (patch)
tree8334dc5c71e6ab9bf33c76143eac7bb0e60159b0 /tmk_core/common/keyboard.c
parentec7a7beeed3046e9144d4c4ce0ef3b2c4f9e4341 (diff)
parentf55e39e8a2246f6f96fd5d4a84a866e2615cde7b (diff)
Merge upstream QMK Firmware at '0.12.52~1'
Diffstat (limited to 'tmk_core/common/keyboard.c')
-rw-r--r--tmk_core/common/keyboard.c122
1 files changed, 81 insertions, 41 deletions
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 0932a1d21b..ce3255c069 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "led.h"
#include "keycode.h"
#include "timer.h"
+#include "sync_timer.h"
#include "print.h"
#include "debug.h"
#include "command.h"
@@ -53,15 +54,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef RGBLIGHT_ENABLE
# include "rgblight.h"
#endif
+#ifdef RGB_MATRIX_ENABLE
+# include "rgb_matrix.h"
+#endif
#ifdef ENCODER_ENABLE
# include "encoder.h"
#endif
#ifdef STENO_ENABLE
# include "process_steno.h"
#endif
-#ifdef FAUXCLICKY_ENABLE
-# include "fauxclicky.h"
-#endif
#ifdef SERIAL_LINK_ENABLE
# include "serial_link/system/serial_link.h"
#endif
@@ -96,10 +97,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "dip_switch.h"
#endif
+static uint32_t last_input_modification_time = 0;
+uint32_t last_input_activity_time(void) { return last_input_modification_time; }
+uint32_t last_input_activity_elapsed(void) { return timer_elapsed32(last_input_modification_time); }
+
+static uint32_t last_matrix_modification_time = 0;
+uint32_t last_matrix_activity_time(void) { return last_matrix_modification_time; }
+uint32_t last_matrix_activity_elapsed(void) { return timer_elapsed32(last_matrix_modification_time); }
+void last_matrix_activity_trigger(void) { last_matrix_modification_time = last_input_modification_time = timer_read32(); }
+
+static uint32_t last_encoder_modification_time = 0;
+uint32_t last_encoder_activity_time(void) { return last_encoder_modification_time; }
+uint32_t last_encoder_activity_elapsed(void) { return timer_elapsed32(last_encoder_modification_time); }
+void last_encoder_activity_trigger(void) { last_encoder_modification_time = last_input_modification_time = timer_read32(); }
+
// Only enable this if console is enabled to print to
#if defined(DEBUG_MATRIX_SCAN_RATE)
-static uint32_t matrix_timer = 0;
-static uint32_t matrix_scan_count = 0;
+static uint32_t matrix_timer = 0;
+static uint32_t matrix_scan_count = 0;
static uint32_t last_matrix_scan_count = 0;
void matrix_scan_perf_task(void) {
@@ -108,17 +123,15 @@ void matrix_scan_perf_task(void) {
uint32_t timer_now = timer_read32();
if (TIMER_DIFF_32(timer_now, matrix_timer) > 1000) {
# if defined(CONSOLE_ENABLE)
- dprintf("matrix scan frequency: %d\n", matrix_scan_count);
+ dprintf("matrix scan frequency: %lu\n", matrix_scan_count);
# endif
last_matrix_scan_count = matrix_scan_count;
- matrix_timer = timer_now;
- matrix_scan_count = 0;
+ matrix_timer = timer_now;
+ matrix_scan_count = 0;
}
}
-uint32_t get_matrix_scan_rate(void) {
- return last_matrix_scan_count;
-}
+uint32_t get_matrix_scan_rate(void) { return last_matrix_scan_count; }
#else
# define matrix_scan_perf_task()
#endif
@@ -173,6 +186,9 @@ void disable_jtag(void) {
#if (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega16U4__) || defined(__AVR_ATmega32U4__))
MCUCR |= _BV(JTD);
MCUCR |= _BV(JTD);
+#elif defined(__AVR_ATmega32A__)
+ MCUCSR |= _BV(JTD);
+ MCUCSR |= _BV(JTD);
#endif
}
@@ -213,7 +229,10 @@ __attribute__((weak)) void keyboard_post_init_kb(void) { keyboard_post_init_user
* FIXME: needs doc
*/
void keyboard_setup(void) {
+#ifndef NO_JTAG_DISABLE
disable_jtag();
+#endif
+ print_set_sendchar(sendchar);
matrix_setup();
keyboard_pre_init_kb();
}
@@ -257,6 +276,7 @@ __attribute__((weak)) void housekeeping_task_user(void) {}
*/
void keyboard_init(void) {
timer_init();
+ sync_timer_init();
matrix_init();
#ifdef VIA_ENABLE
via_init();
@@ -293,9 +313,6 @@ void keyboard_init(void) {
#ifdef STENO_ENABLE
steno_init();
#endif
-#ifdef FAUXCLICKY_ENABLE
- fauxclicky_init();
-#endif
#ifdef POINTING_DEVICE_ENABLE
pointing_device_init();
#endif
@@ -314,6 +331,17 @@ void keyboard_init(void) {
keyboard_post_init_kb(); /* Always keep this last */
}
+/** \brief key_event_task
+ *
+ * This function is responsible for calling into other systems when they need to respond to electrical switch press events.
+ * This is differnet than keycode events as no layer processing, or filtering occurs.
+ */
+void switch_events(uint8_t row, uint8_t col, bool pressed) {
+#if defined(RGB_MATRIX_ENABLE)
+ process_rgb_matrix(row, col, pressed);
+#endif
+}
+
/** \brief Keyboard task: Do keyboard routine jobs
*
* Do routine keyboard jobs:
@@ -334,42 +362,45 @@ void keyboard_task(void) {
#ifdef QMK_KEYS_PER_SCAN
uint8_t keys_processed = 0;
#endif
+#ifdef ENCODER_ENABLE
+ bool encoders_changed = false;
+#endif
housekeeping_task_kb();
housekeeping_task_user();
-#if defined(OLED_DRIVER_ENABLE) && !defined(OLED_DISABLE_TIMEOUT)
- uint8_t ret = matrix_scan();
-#else
- matrix_scan();
-#endif
+ uint8_t matrix_changed = matrix_scan();
+ if (matrix_changed) last_matrix_activity_trigger();
- if (should_process_keypress()) {
- for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
- matrix_row = matrix_get_row(r);
- matrix_change = matrix_row ^ matrix_prev[r];
- if (matrix_change) {
+ for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
+ matrix_row = matrix_get_row(r);
+ matrix_change = matrix_row ^ matrix_prev[r];
+ if (matrix_change) {
#ifdef MATRIX_HAS_GHOST
- if (has_ghost_in_row(r, matrix_row)) {
- continue;
- }
+ if (has_ghost_in_row(r, matrix_row)) {
+ continue;
+ }
#endif
- if (debug_matrix) matrix_print();
- matrix_row_t col_mask = 1;
- for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) {
- if (matrix_change & col_mask) {
+ if (debug_matrix) matrix_print();
+ matrix_row_t col_mask = 1;
+ for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) {
+ if (matrix_change & col_mask) {
+ if (should_process_keypress()) {
action_exec((keyevent_t){
.key = (keypos_t){.row = r, .col = c}, .pressed = (matrix_row & col_mask), .time = (timer_read() | 1) /* time should not be 0 */
});
- // record a processed key
- matrix_prev[r] ^= col_mask;
+ }
+ // record a processed key
+ matrix_prev[r] ^= col_mask;
+
+ switch_events(r, c, (matrix_row & col_mask));
+
#ifdef QMK_KEYS_PER_SCAN
- // only jump out if we have processed "enough" keys.
- if (++keys_processed >= QMK_KEYS_PER_SCAN)
+ // only jump out if we have processed "enough" keys.
+ if (++keys_processed >= QMK_KEYS_PER_SCAN)
#endif
- // process a key per task call
- goto MATRIX_LOOP_END;
- }
+ // process a key per task call
+ goto MATRIX_LOOP_END;
}
}
}
@@ -391,6 +422,10 @@ MATRIX_LOOP_END:
rgblight_task();
#endif
+#ifdef RGB_MATRIX_ENABLE
+ rgb_matrix_task();
+#endif
+
#if defined(BACKLIGHT_ENABLE)
# if defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS)
backlight_task();
@@ -398,7 +433,8 @@ MATRIX_LOOP_END:
#endif
#ifdef ENCODER_ENABLE
- encoder_read();
+ encoders_changed = encoder_read();
+ if (encoders_changed) last_encoder_activity_trigger();
#endif
#ifdef QWIIC_ENABLE
@@ -408,8 +444,12 @@ MATRIX_LOOP_END:
#ifdef OLED_DRIVER_ENABLE
oled_task();
# ifndef OLED_DISABLE_TIMEOUT
- // Wake up oled if user is using those fabulous keys!
- if (ret) oled_on();
+ // Wake up oled if user is using those fabulous keys or spinning those encoders!
+# ifdef ENCODER_ENABLE
+ if (matrix_changed || encoders_changed) oled_on();
+# else
+ if (matrix_changed) oled_on();
+# endif
# endif
#endif