diff options
Diffstat (limited to 'tmk_core/common')
-rw-r--r-- | tmk_core/common/action.c | 10 | ||||
-rw-r--r-- | tmk_core/common/action.h | 1 | ||||
-rw-r--r-- | tmk_core/common/action_layer.c | 303 | ||||
-rw-r--r-- | tmk_core/common/action_util.c | 4 | ||||
-rw-r--r-- | tmk_core/common/arm_atsam/timer.c | 20 | ||||
-rw-r--r-- | tmk_core/common/host.h | 11 | ||||
-rw-r--r-- | tmk_core/common/keyboard.h | 2 | ||||
-rw-r--r-- | tmk_core/common/keycode.h | 20 | ||||
-rw-r--r-- | tmk_core/common/progmem.h | 6 | ||||
-rw-r--r-- | tmk_core/common/wait.h | 4 |
10 files changed, 195 insertions, 186 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index b99c2acaa..ec8d6ed7b 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -653,7 +653,7 @@ void process_action(keyrecord_t *record, action_t action) #ifndef NO_ACTION_TAPPING #ifdef RETRO_TAPPING - if (!is_tap_key(record->event.key)) { + if (!is_tap_action(action)) { retro_tapping_counter = 0; } else { if (event.pressed) { @@ -929,7 +929,15 @@ void clear_keyboard_but_mods_and_keys() bool is_tap_key(keypos_t key) { action_t action = layer_switch_get_action(key); + return is_tap_action(action); +} +/** \brief Utilities for actions. (FIXME: Needs better description) + * + * FIXME: Needs documentation. + */ +bool is_tap_action(action_t action) +{ switch (action.kind.id) { case ACT_LMODS_TAP: case ACT_RMODS_TAP: diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index 8e47e5339..799e3bb0e 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h @@ -97,6 +97,7 @@ void clear_keyboard_but_mods(void); void clear_keyboard_but_mods_and_keys(void); void layer_switch(uint8_t new_layer); bool is_tap_key(keypos_t key); +bool is_tap_action(action_t action); #ifndef NO_ACTION_TAPPING void process_record_tap_hint(keyrecord_t *record); diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 120ce3f51..6ff8c5549 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -17,82 +17,76 @@ uint32_t default_layer_state = 0; /** \brief Default Layer State Set At user Level * - * FIXME: Needs docs + * Run user code on default layer state change */ __attribute__((weak)) uint32_t default_layer_state_set_user(uint32_t state) { - return state; + return state; } /** \brief Default Layer State Set At Keyboard Level * - * FIXME: Needs docs + * Run keyboard code on default layer state change */ __attribute__((weak)) uint32_t default_layer_state_set_kb(uint32_t state) { - return default_layer_state_set_user(state); + return default_layer_state_set_user(state); } /** \brief Default Layer State Set * - * FIXME: Needs docs + * Static function to set the default layer state, prints debug info and clears keys */ -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; - default_layer_debug(); debug("\n"); +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; + default_layer_debug(); debug("\n"); #ifdef STRICT_LAYER_RELEASE - clear_keyboard_but_mods(); // To avoid stuck keys + clear_keyboard_but_mods(); // To avoid stuck keys #else - clear_keyboard_but_mods_and_keys(); // Don't reset held keys + clear_keyboard_but_mods_and_keys(); // Don't reset held keys #endif } /** \brief Default Layer Print * - * FIXME: Needs docs + * Print out the hex value of the 32-bit default layer state, as well as the value of the highest bit. */ -void default_layer_debug(void) -{ - dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); +void default_layer_debug(void) { + dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); } /** \brief Default Layer Set * - * FIXME: Needs docs + * Sets the default layer state. */ -void default_layer_set(uint32_t state) -{ - default_layer_state_set(state); +void default_layer_set(uint32_t state) { + default_layer_state_set(state); } #ifndef NO_ACTION_LAYER /** \brief Default Layer Or * - * FIXME: Needs docs + * Turns on the default layer based on matching bits between specifed layer and existing layer state */ -void default_layer_or(uint32_t state) -{ - default_layer_state_set(default_layer_state | state); +void default_layer_or(uint32_t state) { + default_layer_state_set(default_layer_state | state); } /** \brief Default Layer And * - * FIXME: Needs docs + * Turns on default layer based on matching enabled bits between specifed layer and existing layer state */ -void default_layer_and(uint32_t state) -{ - default_layer_state_set(default_layer_state & state); +void default_layer_and(uint32_t state) { + default_layer_state_set(default_layer_state & state); } /** \brief Default Layer Xor * - * FIXME: Needs docs + * Turns on default layer based on non-matching bits between specifed layer and existing layer state */ -void default_layer_xor(uint32_t state) -{ - default_layer_state_set(default_layer_state ^ state); +void default_layer_xor(uint32_t state) { + default_layer_state_set(default_layer_state ^ state); } #endif @@ -104,170 +98,168 @@ uint32_t layer_state = 0; /** \brief Layer state set user * - * FIXME: Needs docs + * Runs user code on layer state change */ __attribute__((weak)) uint32_t layer_state_set_user(uint32_t state) { - return state; + return state; } /** \brief Layer state set keyboard * - * FIXME: Needs docs + * Runs keyboard code on layer state change */ __attribute__((weak)) uint32_t layer_state_set_kb(uint32_t state) { - return layer_state_set_user(state); + return layer_state_set_user(state); } /** \brief Layer state set * - * FIXME: Needs docs + * Sets the layer to match the specifed state (a bitmask) */ -void layer_state_set(uint32_t state) -{ - state = layer_state_set_kb(state); - dprint("layer_state: "); - layer_debug(); dprint(" to "); - layer_state = state; - layer_debug(); dprintln(); +void layer_state_set(uint32_t state) { + state = layer_state_set_kb(state); + dprint("layer_state: "); + layer_debug(); dprint(" to "); + layer_state = state; + layer_debug(); dprintln(); #ifdef STRICT_LAYER_RELEASE - clear_keyboard_but_mods(); // To avoid stuck keys + clear_keyboard_but_mods(); // To avoid stuck keys #else - clear_keyboard_but_mods_and_keys(); // Don't reset held keys + clear_keyboard_but_mods_and_keys(); // Don't reset held keys #endif } /** \brief Layer clear * - * FIXME: Needs docs + * Turn off all layers */ -void layer_clear(void) -{ - layer_state_set(0); +void layer_clear(void) { + layer_state_set(0); } /** \brief Layer state is * - * FIXME: Needs docs + * Return whether the given state is on (it might still be shadowed by a higher state, though) */ -bool layer_state_is(uint8_t layer) -{ - return layer_state_cmp(layer_state, layer); +bool layer_state_is(uint8_t layer) { + return layer_state_cmp(layer_state, layer); } /** \brief Layer state compare * - * FIXME: Needs docs + * Used for comparing layers {mostly used for unit testing} */ bool layer_state_cmp(uint32_t cmp_layer_state, uint8_t layer) { - if (!cmp_layer_state) { return layer == 0; } - return (cmp_layer_state & (1UL<<layer)) != 0; + if (!cmp_layer_state) { return layer == 0; } + return (cmp_layer_state & (1UL<<layer)) != 0; } /** \brief Layer move * - * FIXME: Needs docs + * Turns on the given layer and turn off all other layers */ -void layer_move(uint8_t layer) -{ - layer_state_set(1UL<<layer); +void layer_move(uint8_t layer) { + layer_state_set(1UL<<layer); } /** \brief Layer on * - * FIXME: Needs docs + * Turns on given layer */ -void layer_on(uint8_t layer) -{ - layer_state_set(layer_state | (1UL<<layer)); +void layer_on(uint8_t layer) { + layer_state_set(layer_state | (1UL<<layer)); } /** \brief Layer off * - * FIXME: Needs docs + * Turns off given layer */ -void layer_off(uint8_t layer) -{ - layer_state_set(layer_state & ~(1UL<<layer)); +void layer_off(uint8_t layer) { + layer_state_set(layer_state & ~(1UL<<layer)); } /** \brief Layer invert * - * FIXME: Needs docs + * Toggle the given layer (set it if it's unset, or unset it if it's set) */ -void layer_invert(uint8_t layer) -{ - layer_state_set(layer_state ^ (1UL<<layer)); +void layer_invert(uint8_t layer) { + layer_state_set(layer_state ^ (1UL<<layer)); } /** \brief Layer or * - * FIXME: Needs docs + * Turns on layers based on matching bits between specifed layer and existing layer state */ -void layer_or(uint32_t state) -{ - layer_state_set(layer_state | state); +void layer_or(uint32_t state) { + layer_state_set(layer_state | state); } /** \brief Layer and * - * FIXME: Needs docs + * Turns on layers based on matching enabled bits between specifed layer and existing layer state */ -void layer_and(uint32_t state) -{ - layer_state_set(layer_state & state); +void layer_and(uint32_t state) { + layer_state_set(layer_state & state); } /** \brief Layer xor * - * FIXME: Needs docs + * Turns on layers based on non-matching bits between specifed layer and existing layer state */ -void layer_xor(uint32_t state) -{ - layer_state_set(layer_state ^ state); +void layer_xor(uint32_t state) { + layer_state_set(layer_state ^ state); } /** \brief Layer debug printing * - * FIXME: Needs docs + * Print out the hex value of the 32-bit layer state, as well as the value of the highest bit. */ -void layer_debug(void) -{ - dprintf("%08lX(%u)", layer_state, biton32(layer_state)); +void layer_debug(void) { + dprintf("%08lX(%u)", layer_state, biton32(layer_state)); } #endif #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) +/** \brief source layer cache + */ + uint8_t source_layers_cache[(MATRIX_ROWS * MATRIX_COLS + 7) / 8][MAX_LAYER_BITS] = {{0}}; -void update_source_layers_cache(keypos_t key, uint8_t layer) -{ - const uint8_t key_number = key.col + (key.row * MATRIX_COLS); - const uint8_t storage_row = key_number / 8; - const uint8_t storage_bit = key_number % 8; - - for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { - source_layers_cache[storage_row][bit_number] ^= - (-((layer & (1U << bit_number)) != 0) - ^ source_layers_cache[storage_row][bit_number]) - & (1U << storage_bit); - } +/** \brief update source layers cache + * + * Updates the cached keys when changing layers + */ +void update_source_layers_cache(keypos_t key, uint8_t layer) { + const uint8_t key_number = key.col + (key.row * MATRIX_COLS); + const uint8_t storage_row = key_number / 8; + const uint8_t storage_bit = key_number % 8; + + for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { + source_layers_cache[storage_row][bit_number] ^= + (-((layer & (1U << bit_number)) != 0) + ^ source_layers_cache[storage_row][bit_number]) + & (1U << storage_bit); + } } -uint8_t read_source_layers_cache(keypos_t key) -{ - const uint8_t key_number = key.col + (key.row * MATRIX_COLS); - const uint8_t storage_row = key_number / 8; - const uint8_t storage_bit = key_number % 8; - uint8_t layer = 0; - - for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { - layer |= - ((source_layers_cache[storage_row][bit_number] - & (1U << storage_bit)) != 0) - << bit_number; - } - - return layer; +/** \brief read source layers cache + * + * reads the cached keys stored when the layer was changed + */ +uint8_t read_source_layers_cache(keypos_t key) { + const uint8_t key_number = key.col + (key.row * MATRIX_COLS); + const uint8_t storage_row = key_number / 8; + const uint8_t storage_bit = key_number % 8; + uint8_t layer = 0; + + for (uint8_t bit_number = 0; bit_number < MAX_LAYER_BITS; bit_number++) { + layer |= + ((source_layers_cache[storage_row][bit_number] + & (1U << storage_bit)) != 0) + << bit_number; + } + + return layer; } #endif @@ -278,61 +270,58 @@ uint8_t read_source_layers_cache(keypos_t key) * when the layer is switched after the down event but before the up * event as they may get stuck otherwise. */ -action_t store_or_get_action(bool pressed, keypos_t key) -{ +action_t store_or_get_action(bool pressed, keypos_t key) { #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) - if (disable_action_cache) { - return layer_switch_get_action(key); - } - - uint8_t layer; - - if (pressed) { - layer = layer_switch_get_layer(key); - update_source_layers_cache(key, layer); - } - else { - layer = read_source_layers_cache(key); - } - return action_for_key(layer, key); -#else + if (disable_action_cache) { return layer_switch_get_action(key); + } + + uint8_t layer; + + if (pressed) { + layer = layer_switch_get_layer(key); + update_source_layers_cache(key, layer); + } + else { + layer = read_source_layers_cache(key); + } + return action_for_key(layer, key); +#else + return layer_switch_get_action(key); #endif } /** \brief Layer switch get layer * - * FIXME: Needs docs + * Gets the layer based on key info */ -int8_t layer_switch_get_layer(keypos_t key) -{ +int8_t layer_switch_get_layer(keypos_t key) { #ifndef NO_ACTION_LAYER - action_t action; - action.code = ACTION_TRANSPARENT; - - uint32_t layers = layer_state | default_layer_state; - /* check top layer first */ - for (int8_t i = 31; i >= 0; i--) { - if (layers & (1UL<<i)) { - action = action_for_key(i, key); - if (action.code != ACTION_TRANSPARENT) { - return i; - } - } + action_t action; + action.code = ACTION_TRANSPARENT; + + uint32_t layers = layer_state | default_layer_state; + /* check top layer first */ + for (int8_t i = 31; i >= 0; i--) { + if (layers & (1UL<<i)) { + action = action_for_key(i, key); + if (action.code != ACTION_TRANSPARENT) { + return i; + } } - /* fall back to layer 0 */ - return 0; + } + /* fall back to layer 0 */ + return 0; #else - return biton32(default_layer_state); + return biton32(default_layer_state); #endif } /** \brief Layer switch get layer * - * FIXME: Needs docs + * Gets action code based on key position */ -action_t layer_switch_get_action(keypos_t key) -{ - return action_for_key(layer_switch_get_layer(key), key); +action_t layer_switch_get_action(keypos_t key) { + return action_for_key(layer_switch_get_layer(key), key); } diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index afd4ae8b2..58401ace5 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -54,7 +54,7 @@ int8_t get_oneshot_locked_mods(void) { return oneshot_locked_mods; } void set_oneshot_locked_mods(int8_t mods) { oneshot_locked_mods = mods; } void clear_oneshot_locked_mods(void) { oneshot_locked_mods = 0; } #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) -static int16_t oneshot_time = 0; +static uint16_t oneshot_time = 0; bool has_oneshot_mods_timed_out(void) { return TIMER_DIFF_16(timer_read(), oneshot_time) >= ONESHOT_TIMEOUT; } @@ -79,7 +79,7 @@ inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) -static int16_t oneshot_layer_time = 0; +static uint16_t oneshot_layer_time = 0; inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); diff --git a/tmk_core/common/arm_atsam/timer.c b/tmk_core/common/arm_atsam/timer.c index bcfe5002c..6c3905e30 100644 --- a/tmk_core/common/arm_atsam/timer.c +++ b/tmk_core/common/arm_atsam/timer.c @@ -9,7 +9,7 @@ void set_time(uint64_t tset) void timer_init(void) { - ms_clk = 0; + timer_clear(); } uint16_t timer_read(void) @@ -37,23 +37,7 @@ uint32_t timer_elapsed32(uint32_t tlast) return TIMER_DIFF_32(timer_read32(), tlast); } -uint32_t timer_elapsed64(uint32_t tlast) -{ - uint64_t tnow = timer_read64(); - return (tnow >= tlast ? tnow - tlast : UINT64_MAX - tlast + tnow); -} - void timer_clear(void) { - ms_clk = 0; -} - -void wait_ms(uint64_t msec) -{ - CLK_delay_ms(msec); -} - -void wait_us(uint16_t usec) -{ - CLK_delay_us(usec); + set_time(0); } diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h index aeabba710..3d172eed6 100644 --- a/tmk_core/common/host.h +++ b/tmk_core/common/host.h @@ -15,14 +15,18 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef HOST_H -#define HOST_H +#pragma once #include <stdint.h> #include <stdbool.h> #include "report.h" #include "host_driver.h" +#define IS_LED_ON(leds, led_name) ( (leds) & (1 << (led_name))) +#define IS_LED_OFF(leds, led_name) (~(leds) & (1 << (led_name))) + +#define IS_HOST_LED_ON(led_name) IS_LED_ON(host_keyboard_leds(), led_name) +#define IS_HOST_LED_OFF(led_name) IS_LED_OFF(host_keyboard_leds(), led_name) #ifdef __cplusplus extern "C" { @@ -31,7 +35,6 @@ extern "C" { extern uint8_t keyboard_idle; extern uint8_t keyboard_protocol; - /* host driver */ void host_set_driver(host_driver_t *driver); host_driver_t *host_get_driver(void); @@ -49,5 +52,3 @@ uint16_t host_last_consumer_report(void); #ifdef __cplusplus } #endif - -#endif diff --git a/tmk_core/common/keyboard.h b/tmk_core/common/keyboard.h index 71e594a89..ea2f336e9 100644 --- a/tmk_core/common/keyboard.h +++ b/tmk_core/common/keyboard.h @@ -67,6 +67,8 @@ void keyboard_init(void); void keyboard_task(void); /* it runs when host LED status is updated */ void keyboard_set_leds(uint8_t leds); +/* it runs whenever code has to behave differently on a slave */ +bool is_keyboard_master(void); #ifdef __cplusplus } diff --git a/tmk_core/common/keycode.h b/tmk_core/common/keycode.h index ac3edbd21..d5904276e 100644 --- a/tmk_core/common/keycode.h +++ b/tmk_core/common/keycode.h @@ -46,6 +46,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define MOD_BIT(code) (1 << MOD_INDEX(code)) #define MOD_INDEX(code) ((code) & 0x07) +#define MOD_MASK_CTRL (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RCTRL)) +#define MOD_MASK_SHIFT (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) +#define MOD_MASK_ALT (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) +#define MOD_MASK_GUI (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) +#define MOD_MASK_CS (MOD_MASK_CTRL | MOD_MASK_SHIFT) +#define MOD_MASK_CA (MOD_MASK_CTRL | MOD_MASK_ALT) +#define MOD_MASK_CG (MOD_MASK_CTRL | MOD_MASK_GUI) +#define MOD_MASK_SA (MOD_MASK_SHIFT | MOD_MASK_ALT) +#define MOD_MASK_SG (MOD_MASK_SHIFT | MOD_MASK_GUI) +#define MOD_MASK_AG (MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_CSA (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT) +#define MOD_MASK_CSG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_GUI) +#define MOD_MASK_CAG (MOD_MASK_CTRL | MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_SAG (MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) +#define MOD_MASK_CSAG (MOD_MASK_CTRL | MOD_MASK_SHIFT | MOD_MASK_ALT | MOD_MASK_GUI) + #define FN_BIT(code) (1 << FN_INDEX(code)) #define FN_INDEX(code) ((code) - KC_FN0) #define FN_MIN KC_FN0 @@ -174,6 +190,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define KC_BRIU KC_BRIGHTNESS_UP #define KC_BRID KC_BRIGHTNESS_DOWN +/* System Specific */ +#define KC_BRMU KC_PAUSE +#define KC_BRMD KC_SCROLLLOCK + /* Mouse Keys */ #define KC_MS_U KC_MS_UP #define KC_MS_D KC_MS_DOWN diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h index dcc9efb3c..de9313839 100644 --- a/tmk_core/common/progmem.h +++ b/tmk_core/common/progmem.h @@ -5,9 +5,9 @@ # include <avr/pgmspace.h> #else # define PROGMEM -# define pgm_read_byte(p) *((unsigned char*)p) -# define pgm_read_word(p) *((uint16_t*)p) -# define pgm_read_dword(p) *((uint32_t*)p) +# define pgm_read_byte(p) *((unsigned char*)(p)) +# define pgm_read_word(p) *((uint16_t*)(p)) +# define pgm_read_dword(p) *((uint32_t*)(p)) #endif #endif diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index a7cded942..a77840bce 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h @@ -15,6 +15,10 @@ extern "C" { # include "ch.h" # define wait_ms(ms) chThdSleepMilliseconds(ms) # define wait_us(us) chThdSleepMicroseconds(us) +#elif defined PROTOCOL_ARM_ATSAM +# 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 |