summaryrefslogtreecommitdiffstats
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action_layer.c2
-rw-r--r--tmk_core/common/action_layer.h2
-rw-r--r--tmk_core/common/arm_atsam/suspend.c3
-rw-r--r--tmk_core/common/chibios/suspend.c26
-rw-r--r--tmk_core/common/eeconfig.c6
-rw-r--r--tmk_core/common/host.c6
-rw-r--r--tmk_core/common/host.h2
-rw-r--r--tmk_core/common/keyboard.c10
-rw-r--r--tmk_core/common/keycode.h1
-rw-r--r--tmk_core/common/led.h13
-rw-r--r--tmk_core/common/mbed/bootloader.c3
-rw-r--r--tmk_core/common/mbed/suspend.c5
-rw-r--r--tmk_core/common/mbed/timer.c23
-rw-r--r--tmk_core/common/mbed/xprintf.cpp50
-rw-r--r--tmk_core/common/mbed/xprintf.h16
-rw-r--r--tmk_core/common/print.h33
-rw-r--r--tmk_core/common/wait.h2
17 files changed, 61 insertions, 142 deletions
diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c
index 07d78c56d4..4c7d15cd50 100644
--- a/tmk_core/common/action_layer.c
+++ b/tmk_core/common/action_layer.c
@@ -268,7 +268,7 @@ uint8_t layer_switch_get_layer(keypos_t key) {
/* fall back to layer 0 */
return 0;
#else
- return biton32(default_layer_state);
+ return get_highest_layer(default_layer_state);
#endif
}
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index fee9b244df..b8562f5a46 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -23,7 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if defined(LAYER_STATE_8BIT)
typedef uint8_t layer_state_t;
-# define get_highest_layer(state) biton8(state)
+# define get_highest_layer(state) biton(state)
#elif defined(LAYER_STATE_16BIT)
typedef uint16_t layer_state_t;
# define get_highest_layer(state) biton16(state)
diff --git a/tmk_core/common/arm_atsam/suspend.c b/tmk_core/common/arm_atsam/suspend.c
index 2dad005706..d1077be4c2 100644
--- a/tmk_core/common/arm_atsam/suspend.c
+++ b/tmk_core/common/arm_atsam/suspend.c
@@ -7,7 +7,8 @@
*
* FIXME: needs doc
*/
-void suspend_idle(uint8_t time) { /* Note: Not used anywhere currently */ }
+void suspend_idle(uint8_t time) { /* Note: Not used anywhere currently */
+}
/** \brief Run user level Power down
*
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index c0f9c28d44..5be1b76777 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -15,6 +15,13 @@
# include "backlight.h"
#endif
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+# include "rgblight.h"
+extern rgblight_config_t rgblight_config;
+static bool rgblight_enabled;
+static bool is_suspended;
+#endif
+
/** \brief suspend idle
*
* FIXME: needs doc
@@ -43,6 +50,16 @@ void suspend_power_down(void) {
// TODO: figure out what to power down and how
// shouldn't power down TPM/FTM if we want a breathing LED
// also shouldn't power down USB
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+# ifdef RGBLIGHT_ANIMATIONS
+ rgblight_timer_disable();
+# endif
+ if (!is_suspended) {
+ is_suspended = true;
+ rgblight_enabled = rgblight_config.enable;
+ rgblight_disable_noeeprom();
+ }
+#endif
suspend_power_down_kb();
// on AVR, this enables the watchdog for 15ms (max), and goes to
@@ -104,5 +121,14 @@ void suspend_wakeup_init(void) {
#ifdef BACKLIGHT_ENABLE
backlight_init();
#endif /* BACKLIGHT_ENABLE */
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+ is_suspended = false;
+ if (rgblight_enabled) {
+ rgblight_enable_noeeprom();
+ }
+# ifdef RGBLIGHT_ANIMATIONS
+ rgblight_timer_enable();
+# endif
+#endif
suspend_wakeup_init_kb();
}
diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c
index 4cf4ca3ace..7cec4bd7df 100644
--- a/tmk_core/common/eeconfig.c
+++ b/tmk_core/common/eeconfig.c
@@ -2,13 +2,13 @@
#include <stdbool.h>
#include "eeprom.h"
#include "eeconfig.h"
+#include "action_layer.h"
#ifdef STM32_EEPROM_ENABLE
# include "hal.h"
# include "eeprom_stm32.h"
#endif
-extern uint32_t default_layer_state;
/** \brief eeconfig enable
*
* FIXME: needs doc
@@ -51,10 +51,10 @@ void eeconfig_init_quantum(void) {
// TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS
// within the emulated eeprom via dfu-util or another tool
#if defined INIT_EE_HANDS_LEFT
- #pragma message "Faking EE_HANDS for left hand"
+# pragma message "Faking EE_HANDS for left hand"
eeprom_update_byte(EECONFIG_HANDEDNESS, 1);
#elif defined INIT_EE_HANDS_RIGHT
- #pragma message "Faking EE_HANDS for right hand"
+# pragma message "Faking EE_HANDS for right hand"
eeprom_update_byte(EECONFIG_HANDEDNESS, 0);
#endif
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c
index ce39760a5b..e7d92cfac6 100644
--- a/tmk_core/common/host.c
+++ b/tmk_core/common/host.c
@@ -39,6 +39,12 @@ uint8_t host_keyboard_leds(void) {
if (!driver) return 0;
return (*driver->keyboard_leds)();
}
+
+led_t host_keyboard_led_state(void) {
+ if (!driver) return (led_t){0};
+ return (led_t)((*driver->keyboard_leds)());
+}
+
/* send report */
void host_keyboard_send(report_keyboard_t *report) {
if (!driver) return;
diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h
index b2a7f98427..2cffef6e15 100644
--- a/tmk_core/common/host.h
+++ b/tmk_core/common/host.h
@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h>
#include "report.h"
#include "host_driver.h"
+#include "led.h"
#define IS_LED_ON(leds, led_name) ((leds) & (1 << (led_name)))
#define IS_LED_OFF(leds, led_name) (~(leds) & (1 << (led_name)))
@@ -41,6 +42,7 @@ host_driver_t *host_get_driver(void);
/* host driver interface */
uint8_t host_keyboard_leds(void);
+led_t host_keyboard_led_state(void);
void host_keyboard_send(report_keyboard_t *report);
void host_mouse_send(report_mouse_t *report);
void host_system_send(uint16_t data);
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 63ace9793c..af2b2fd48b 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -254,6 +254,7 @@ void keyboard_init(void) {
#endif
#if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
keymap_config.nkro = 1;
+ eeconfig_update_keymap(keymap_config.raw);
#endif
keyboard_post_init_kb(); /* Always keep this last */
}
@@ -296,13 +297,14 @@ void keyboard_task(void) {
}
#endif
if (debug_matrix) matrix_print();
- for (uint8_t c = 0; c < MATRIX_COLS; c++) {
- if (matrix_change & ((matrix_row_t)1 << c)) {
+ matrix_row_t col_mask = 1;
+ for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) {
+ if (matrix_change & col_mask) {
action_exec((keyevent_t){
- .key = (keypos_t){.row = r, .col = c}, .pressed = (matrix_row & ((matrix_row_t)1 << c)), .time = (timer_read() | 1) /* time should not be 0 */
+ .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] ^= ((matrix_row_t)1 << c);
+ matrix_prev[r] ^= col_mask;
#ifdef QMK_KEYS_PER_SCAN
// only jump out if we have processed "enough" keys.
if (++keys_processed >= QMK_KEYS_PER_SCAN)
diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h
index fd5d606805..e1059fadf0 100644
--- a/tmk_core/common/keycode.h
+++ b/tmk_core/common/keycode.h
@@ -175,7 +175,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KC_MPLY KC_MEDIA_PLAY_PAUSE
#define KC_MSEL KC_MEDIA_SELECT
#define KC_EJCT KC_MEDIA_EJECT
-#define KC_MAIL KC_MAIL
#define KC_CALC KC_CALCULATOR
#define KC_MYCM KC_MY_COMPUTER
#define KC_WSCH KC_WWW_SEARCH
diff --git a/tmk_core/common/led.h b/tmk_core/common/led.h
index 2c28fe5401..990282862b 100644
--- a/tmk_core/common/led.h
+++ b/tmk_core/common/led.h
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LED_H
#define LED_H
#include "stdint.h"
+#include "stdbool.h"
/* FIXME: Add doxygen comments here. */
@@ -32,6 +33,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" {
#endif
+typedef union {
+ uint8_t raw;
+ struct {
+ bool num_lock : 1;
+ bool caps_lock : 1;
+ bool scroll_lock : 1;
+ bool compose : 1;
+ bool kana : 1;
+ uint8_t reserved : 3;
+ };
+} led_t;
+
void led_set(uint8_t usb_led);
void led_init_ports(void);
diff --git a/tmk_core/common/mbed/bootloader.c b/tmk_core/common/mbed/bootloader.c
deleted file mode 100644
index 88945eb050..0000000000
--- a/tmk_core/common/mbed/bootloader.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#include "bootloader.h"
-
-void bootloader_jump(void) {}
diff --git a/tmk_core/common/mbed/suspend.c b/tmk_core/common/mbed/suspend.c
deleted file mode 100644
index 3d0554f87b..0000000000
--- a/tmk_core/common/mbed/suspend.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include <stdbool.h>
-
-void suspend_power_down(void) {}
-bool suspend_wakeup_condition(void) { return true; }
-void suspend_wakeup_init(void) {}
diff --git a/tmk_core/common/mbed/timer.c b/tmk_core/common/mbed/timer.c
deleted file mode 100644
index 7e4070af29..0000000000
--- a/tmk_core/common/mbed/timer.c
+++ /dev/null
@@ -1,23 +0,0 @@
-#include "cmsis.h"
-#include "timer.h"
-
-/* Mill second tick count */
-volatile uint32_t timer_count = 0;
-
-/* Timer interrupt handler */
-void SysTick_Handler(void) { timer_count++; }
-
-void timer_init(void) {
- timer_count = 0;
- SysTick_Config(SystemCoreClock / 1000); /* 1ms tick */
-}
-
-void timer_clear(void) { timer_count = 0; }
-
-uint16_t timer_read(void) { return (uint16_t)(timer_count & 0xFFFF); }
-
-uint32_t timer_read32(void) { return timer_count; }
-
-uint16_t timer_elapsed(uint16_t last) { return TIMER_DIFF_16(timer_read(), last); }
-
-uint32_t timer_elapsed32(uint32_t last) { return TIMER_DIFF_32(timer_read32(), last); }
diff --git a/tmk_core/common/mbed/xprintf.cpp b/tmk_core/common/mbed/xprintf.cpp
deleted file mode 100644
index 184b7fa7a0..0000000000
--- a/tmk_core/common/mbed/xprintf.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-#include <cstdarg>
-//#include <stdarg.h>
-#include "mbed.h"
-#include "mbed/xprintf.h"
-
-#define STRING_STACK_LIMIT 120
-
-// TODO
-int __xprintf(const char* format, ...) { return 0; }
-
-#if 0
-/* mbed Serial */
-Serial ser(UART_TX, UART_RX);
-
-/* TODO: Need small implementation for embedded */
-int xprintf(const char* format, ...)
-{
- /* copy from mbed/common/RawSerial.cpp */
- std::va_list arg;
- va_start(arg, format);
- int len = vsnprintf(NULL, 0, format, arg);
- if (len < STRING_STACK_LIMIT) {
- char temp[STRING_STACK_LIMIT];
- vsprintf(temp, format, arg);
- ser.puts(temp);
- } else {
- char *temp = new char[len + 1];
- vsprintf(temp, format, arg);
- ser.puts(temp);
- delete[] temp;
- }
- va_end(arg);
- return len;
-
-/* Fail: __builtin_va_arg_pack?
- * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
- void *arg = __builtin_apply_args();
- void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
- __builtin_return(ret)
-*/
-/* Fail: varargs can not be passed to printf
- //int r = ser.printf("test %i\r\n", 123);
- va_list arg;
- va_start(arg, format);
- int r = ser.printf(format, arg);
- va_end(arg);
- return r;
-*/
-}
-#endif
diff --git a/tmk_core/common/mbed/xprintf.h b/tmk_core/common/mbed/xprintf.h
deleted file mode 100644
index e27822d3a8..0000000000
--- a/tmk_core/common/mbed/xprintf.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef XPRINTF_H
-#define XPRINTF_H
-
-//#define xprintf(format, ...) __xprintf(format, ##__VA_ARGS__)
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int __xprintf(const char *format, ...);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h
index 20189838fe..04ca558109 100644
--- a/tmk_core/common/print.h
+++ b/tmk_core/common/print.h
@@ -128,38 +128,7 @@ extern "C"
# endif /* USER_PRINT / NORMAL PRINT */
-# elif defined(__arm__) /* __arm__ */
-
-# include "mbed/xprintf.h"
-
-# ifdef USER_PRINT /* USER_PRINT */
-
-// Remove normal print defines
-# define print(s)
-# define println(s)
-# define xprintf(fmt, ...)
-
-// Create user print defines
-# define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)
-# define uprint(s) xprintf(s)
-# define uprintln(s) xprintf(s "\r\n")
-
-# else /* NORMAL PRINT */
-
-// Create user & normal print defines
-# define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)
-# define print(s) xprintf(s)
-# define println(s) xprintf(s "\r\n")
-# define uprint(s) print(s)
-# define uprintln(s) println(s)
-# define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__)
-
-# endif /* USER_PRINT / NORMAL PRINT */
-
-/* TODO: to select output destinations: UART/USBSerial */
-# define print_set_sendchar(func)
-
-# endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM / __arm__ */
+# endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM */
// User print disables the normal print messages in the body of QMK/TMK code and
// is meant as a lightweight alternative to NOPRINT. Use it when you only want to do
diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h
index cb1f386a61..c82cd2d65a 100644
--- a/tmk_core/common/wait.h
+++ b/tmk_core/common/wait.h
@@ -33,8 +33,6 @@ extern "C" {
# include "clks.h"
# define wait_ms(ms) CLK_delay_ms(ms)
# define wait_us(us) CLK_delay_us(us)
-#elif defined(__arm__)
-# include "wait_api.h"
#else // Unit tests
void wait_ms(uint32_t ms);
# define wait_us(us) wait_ms(us / 1000)