summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common/avr/suspend.c6
-rw-r--r--tmk_core/common/chibios/timer.c42
-rw-r--r--tmk_core/common/keyboard.c7
-rw-r--r--tmk_core/common/mousekey.c2
4 files changed, 39 insertions, 18 deletions
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index dfa1af273c..3d4a48439b 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -19,7 +19,7 @@
#include "audio.h"
#endif /* AUDIO_ENABLE */
-#ifdef RGBLIGHT_SLEEP
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
#include "rgblight.h"
#endif
@@ -112,7 +112,7 @@ static void power_down(uint8_t wdto)
// This sometimes disables the start-up noise, so it's been disabled
// stop_all_notes();
#endif /* AUDIO_ENABLE */
-#ifdef RGBLIGHT_SLEEP
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_disable();
#endif
@@ -188,7 +188,7 @@ void suspend_wakeup_init(void)
backlight_init();
#endif
led_set(host_keyboard_leds());
-#ifdef RGBLIGHT_SLEEP
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
rgblight_enable_noeeprom();
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_enable();
diff --git a/tmk_core/common/chibios/timer.c b/tmk_core/common/chibios/timer.c
index 3de4cc368b..473e533caa 100644
--- a/tmk_core/common/chibios/timer.c
+++ b/tmk_core/common/chibios/timer.c
@@ -2,26 +2,40 @@
#include "timer.h"
-void timer_init(void) {}
+static systime_t last_systime = 0;
+static systime_t overflow = 0;
+static uint32_t current_time_ms = 0;
-void timer_clear(void) {}
+void timer_init(void) {
+ timer_clear();
+}
+
+void timer_clear(void) {
+ last_systime = chVTGetSystemTime();
+ overflow = 0;
+ current_time_ms = 0;
+}
-uint16_t timer_read(void)
-{
- return (uint16_t)ST2MS(chVTGetSystemTime());
+uint16_t timer_read(void) {
+ return (uint16_t)timer_read32();
}
-uint32_t timer_read32(void)
-{
- return ST2MS(chVTGetSystemTime());
+uint32_t timer_read32(void) {
+ // Note: We assume that the timer update is called at least once betweeen every wrap around of the system time
+ systime_t current_systime = chVTGetSystemTime();
+ systime_t elapsed = current_systime - last_systime + overflow;
+ uint32_t elapsed_ms = ST2MS(elapsed);
+ current_time_ms += elapsed_ms;
+ overflow = elapsed - MS2ST(elapsed_ms);
+ last_systime = current_systime;
+
+ return current_time_ms;
}
-uint16_t timer_elapsed(uint16_t last)
-{
- return (uint16_t)(ST2MS(chVTTimeElapsedSinceX(MS2ST(last))));
+uint16_t timer_elapsed(uint16_t last) {
+ return timer_read() - last;
}
-uint32_t timer_elapsed32(uint32_t last)
-{
- return ST2MS(chVTTimeElapsedSinceX(MS2ST(last)));
+uint32_t timer_elapsed32(uint32_t last) {
+ return timer_read32() - last;
}
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 4eff764e2d..d3fbe2d879 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -148,6 +148,11 @@ bool is_keyboard_master(void) {
*/
void keyboard_init(void) {
timer_init();
+// To use PORTF disable JTAG with writing JTD bit twice within four cycles.
+#if (defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1287__) || defined(__AVR_ATmega32U4__))
+ MCUCR |= _BV(JTD);
+ MCUCR |= _BV(JTD);
+#endif
matrix_init();
#ifdef PS2_MOUSE_ENABLE
ps2_mouse_init();
@@ -185,7 +190,7 @@ void keyboard_init(void) {
/** \brief Keyboard task: Do keyboard routine jobs
*
- * Do routine keyboard jobs:
+ * Do routine keyboard jobs:
*
* * scan matrix
* * handle mouse movements
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index aa128f0e87..581e7b8a07 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -122,7 +122,9 @@ void mousekey_task(void)
/* diagonal move [1/sqrt(2)] */
if (mouse_report.x && mouse_report.y) {
mouse_report.x = times_inv_sqrt2(mouse_report.x);
+ mouse_report.x = mouse_report.x == 0 ? 1 : mouse_report.x;
mouse_report.y = times_inv_sqrt2(mouse_report.y);
+ mouse_report.y = mouse_report.y == 0 ? 1 : mouse_report.y;
}
if (mouse_report.v > 0) mouse_report.v = wheel_unit();