diff options
Diffstat (limited to 'tmk_core/common')
30 files changed, 297 insertions, 500 deletions
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index bd41d28b6..d19fd2a04 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c | |||
| @@ -55,6 +55,8 @@ __attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrec | |||
| 55 | __attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return false; } | 55 | __attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) { return false; } |
| 56 | #endif | 56 | #endif |
| 57 | 57 | ||
| 58 | __attribute__((weak)) bool pre_process_record_quantum(keyrecord_t *record) { return true; } | ||
| 59 | |||
| 58 | #ifndef TAP_CODE_DELAY | 60 | #ifndef TAP_CODE_DELAY |
| 59 | # define TAP_CODE_DELAY 0 | 61 | # define TAP_CODE_DELAY 0 |
| 60 | #endif | 62 | #endif |
| @@ -106,9 +108,13 @@ void action_exec(keyevent_t event) { | |||
| 106 | #endif | 108 | #endif |
| 107 | 109 | ||
| 108 | #ifndef NO_ACTION_TAPPING | 110 | #ifndef NO_ACTION_TAPPING |
| 109 | action_tapping_process(record); | 111 | if (IS_NOEVENT(record.event) || pre_process_record_quantum(&record)) { |
| 112 | action_tapping_process(record); | ||
| 113 | } | ||
| 110 | #else | 114 | #else |
| 111 | process_record(&record); | 115 | if (IS_NOEVENT(record.event) || pre_process_record_quantum(&record)) { |
| 116 | process_record(&record); | ||
| 117 | } | ||
| 112 | if (!IS_NOEVENT(record.event)) { | 118 | if (!IS_NOEVENT(record.event)) { |
| 113 | dprint("processed: "); | 119 | dprint("processed: "); |
| 114 | debug_record(record); | 120 | debug_record(record); |
| @@ -206,7 +212,16 @@ void process_record(keyrecord_t *record) { | |||
| 206 | } | 212 | } |
| 207 | 213 | ||
| 208 | void process_record_handler(keyrecord_t *record) { | 214 | void process_record_handler(keyrecord_t *record) { |
| 215 | #ifdef COMBO_ENABLE | ||
| 216 | action_t action; | ||
| 217 | if (record->keycode) { | ||
| 218 | action = action_for_keycode(record->keycode); | ||
| 219 | } else { | ||
| 220 | action = store_or_get_action(record->event.pressed, record->event.key); | ||
| 221 | } | ||
| 222 | #else | ||
| 209 | action_t action = store_or_get_action(record->event.pressed, record->event.key); | 223 | action_t action = store_or_get_action(record->event.pressed, record->event.key); |
| 224 | #endif | ||
| 210 | dprint("ACTION: "); | 225 | dprint("ACTION: "); |
| 211 | debug_action(action); | 226 | debug_action(action); |
| 212 | #ifndef NO_ACTION_LAYER | 227 | #ifndef NO_ACTION_LAYER |
| @@ -994,6 +1009,24 @@ bool is_tap_key(keypos_t key) { | |||
| 994 | * | 1009 | * |
| 995 | * FIXME: Needs documentation. | 1010 | * FIXME: Needs documentation. |
| 996 | */ | 1011 | */ |
| 1012 | bool is_tap_record(keyrecord_t *record) { | ||
| 1013 | #ifdef COMBO_ENABLE | ||
| 1014 | action_t action; | ||
| 1015 | if (record->keycode) { | ||
| 1016 | action = action_for_keycode(record->keycode); | ||
| 1017 | } else { | ||
| 1018 | action = layer_switch_get_action(record->event.key); | ||
| 1019 | } | ||
| 1020 | #else | ||
| 1021 | action_t action = layer_switch_get_action(record->event.key); | ||
| 1022 | #endif | ||
| 1023 | return is_tap_action(action); | ||
| 1024 | } | ||
| 1025 | |||
| 1026 | /** \brief Utilities for actions. (FIXME: Needs better description) | ||
| 1027 | * | ||
| 1028 | * FIXME: Needs documentation. | ||
| 1029 | */ | ||
| 997 | bool is_tap_action(action_t action) { | 1030 | bool is_tap_action(action_t action) { |
| 998 | switch (action.kind.id) { | 1031 | switch (action.kind.id) { |
| 999 | case ACT_LMODS_TAP: | 1032 | case ACT_LMODS_TAP: |
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h index 8cb4722c6..3d357b33b 100644 --- a/tmk_core/common/action.h +++ b/tmk_core/common/action.h | |||
| @@ -53,6 +53,9 @@ typedef struct { | |||
| 53 | #ifndef NO_ACTION_TAPPING | 53 | #ifndef NO_ACTION_TAPPING |
| 54 | tap_t tap; | 54 | tap_t tap; |
| 55 | #endif | 55 | #endif |
| 56 | #ifdef COMBO_ENABLE | ||
| 57 | uint16_t keycode; | ||
| 58 | #endif | ||
| 56 | } keyrecord_t; | 59 | } keyrecord_t; |
| 57 | 60 | ||
| 58 | /* Execute action per keyevent */ | 61 | /* Execute action per keyevent */ |
| @@ -60,6 +63,7 @@ void action_exec(keyevent_t event); | |||
| 60 | 63 | ||
| 61 | /* action for key */ | 64 | /* action for key */ |
| 62 | action_t action_for_key(uint8_t layer, keypos_t key); | 65 | action_t action_for_key(uint8_t layer, keypos_t key); |
| 66 | action_t action_for_keycode(uint16_t keycode); | ||
| 63 | 67 | ||
| 64 | /* macro */ | 68 | /* macro */ |
| 65 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); | 69 | const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt); |
| @@ -111,6 +115,7 @@ void clear_keyboard_but_mods(void); | |||
| 111 | void clear_keyboard_but_mods_and_keys(void); | 115 | void clear_keyboard_but_mods_and_keys(void); |
| 112 | void layer_switch(uint8_t new_layer); | 116 | void layer_switch(uint8_t new_layer); |
| 113 | bool is_tap_key(keypos_t key); | 117 | bool is_tap_key(keypos_t key); |
| 118 | bool is_tap_record(keyrecord_t *record); | ||
| 114 | bool is_tap_action(action_t action); | 119 | bool is_tap_action(action_t action); |
| 115 | 120 | ||
| 116 | #ifndef NO_ACTION_TAPPING | 121 | #ifndef NO_ACTION_TAPPING |
diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index af2d7d964..ed1a4bd20 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c | |||
| @@ -131,32 +131,32 @@ bool layer_state_cmp(layer_state_t cmp_layer_state, uint8_t layer) { | |||
| 131 | if (!cmp_layer_state) { | 131 | if (!cmp_layer_state) { |
| 132 | return layer == 0; | 132 | return layer == 0; |
| 133 | } | 133 | } |
| 134 | return (cmp_layer_state & (1UL << layer)) != 0; | 134 | return (cmp_layer_state & ((layer_state_t)1 << layer)) != 0; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | /** \brief Layer move | 137 | /** \brief Layer move |
| 138 | * | 138 | * |
| 139 | * Turns on the given layer and turn off all other layers | 139 | * Turns on the given layer and turn off all other layers |
| 140 | */ | 140 | */ |
| 141 | void layer_move(uint8_t layer) { layer_state_set(1UL << layer); } | 141 | void layer_move(uint8_t layer) { layer_state_set((layer_state_t)1 << layer); } |
| 142 | 142 | ||
| 143 | /** \brief Layer on | 143 | /** \brief Layer on |
| 144 | * | 144 | * |
| 145 | * Turns on given layer | 145 | * Turns on given layer |
| 146 | */ | 146 | */ |
| 147 | void layer_on(uint8_t layer) { layer_state_set(layer_state | (1UL << layer)); } | 147 | void layer_on(uint8_t layer) { layer_state_set(layer_state | ((layer_state_t)1 << layer)); } |
| 148 | 148 | ||
| 149 | /** \brief Layer off | 149 | /** \brief Layer off |
| 150 | * | 150 | * |
| 151 | * Turns off given layer | 151 | * Turns off given layer |
| 152 | */ | 152 | */ |
| 153 | void layer_off(uint8_t layer) { layer_state_set(layer_state & ~(1UL << layer)); } | 153 | void layer_off(uint8_t layer) { layer_state_set(layer_state & ~((layer_state_t)1 << layer)); } |
| 154 | 154 | ||
| 155 | /** \brief Layer invert | 155 | /** \brief Layer invert |
| 156 | * | 156 | * |
| 157 | * Toggle the given layer (set it if it's unset, or unset it if it's set) | 157 | * Toggle the given layer (set it if it's unset, or unset it if it's set) |
| 158 | */ | 158 | */ |
| 159 | void layer_invert(uint8_t layer) { layer_state_set(layer_state ^ (1UL << layer)); } | 159 | void layer_invert(uint8_t layer) { layer_state_set(layer_state ^ ((layer_state_t)1 << layer)); } |
| 160 | 160 | ||
| 161 | /** \brief Layer or | 161 | /** \brief Layer or |
| 162 | * | 162 | * |
| @@ -258,7 +258,7 @@ uint8_t layer_switch_get_layer(keypos_t key) { | |||
| 258 | layer_state_t layers = layer_state | default_layer_state; | 258 | layer_state_t layers = layer_state | default_layer_state; |
| 259 | /* check top layer first */ | 259 | /* check top layer first */ |
| 260 | for (int8_t i = MAX_LAYER - 1; i >= 0; i--) { | 260 | for (int8_t i = MAX_LAYER - 1; i >= 0; i--) { |
| 261 | if (layers & (1UL << i)) { | 261 | if (layers & ((layer_state_t)1 << i)) { |
| 262 | action = action_for_key(i, key); | 262 | action = action_for_key(i, key); |
| 263 | if (action.code != ACTION_TRANSPARENT) { | 263 | if (action.code != ACTION_TRANSPARENT) { |
| 264 | return i; | 264 | return i; |
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index d72cd3e3a..b87d096ee 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h | |||
| @@ -21,6 +21,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 21 | #include "keyboard.h" | 21 | #include "keyboard.h" |
| 22 | #include "action.h" | 22 | #include "action.h" |
| 23 | 23 | ||
| 24 | #ifdef DYNAMIC_KEYMAP_ENABLE | ||
| 25 | # ifndef DYNAMIC_KEYMAP_LAYER_COUNT | ||
| 26 | # define DYNAMIC_KEYMAP_LAYER_COUNT 4 | ||
| 27 | # endif | ||
| 28 | # if DYNAMIC_KEYMAP_LAYER_COUNT <= 8 | ||
| 29 | # ifndef LAYER_STATE_8BIT | ||
| 30 | # define LAYER_STATE_8BIT | ||
| 31 | # endif | ||
| 32 | # elif DYNAMIC_KEYMAP_LAYER_COUNT <= 16 | ||
| 33 | # ifndef LAYER_STATE_16BIT | ||
| 34 | # define LAYER_STATE_16BIT | ||
| 35 | # endif | ||
| 36 | # else | ||
| 37 | # ifndef LAYER_STATE_32BIT | ||
| 38 | # define LAYER_STATE_32BIT | ||
| 39 | # endif | ||
| 40 | # endif | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #if !defined(LAYER_STATE_8BIT) && !defined(LAYER_STATE_16BIT) && !defined(LAYER_STATE_32BIT) | ||
| 44 | # define LAYER_STATE_32BIT | ||
| 45 | #endif | ||
| 46 | |||
| 24 | #if defined(LAYER_STATE_8BIT) | 47 | #if defined(LAYER_STATE_8BIT) |
| 25 | typedef uint8_t layer_state_t; | 48 | typedef uint8_t layer_state_t; |
| 26 | # define MAX_LAYER_BITS 3 | 49 | # define MAX_LAYER_BITS 3 |
| @@ -35,13 +58,15 @@ typedef uint16_t layer_state_t; | |||
| 35 | # define MAX_LAYER 16 | 58 | # define MAX_LAYER 16 |
| 36 | # endif | 59 | # endif |
| 37 | # define get_highest_layer(state) biton16(state) | 60 | # define get_highest_layer(state) biton16(state) |
| 38 | #else | 61 | #elif defined(LAYER_STATE_32BIT) |
| 39 | typedef uint32_t layer_state_t; | 62 | typedef uint32_t layer_state_t; |
| 40 | # define MAX_LAYER_BITS 5 | 63 | # define MAX_LAYER_BITS 5 |
| 41 | # ifndef MAX_LAYER | 64 | # ifndef MAX_LAYER |
| 42 | # define MAX_LAYER 32 | 65 | # define MAX_LAYER 32 |
| 43 | # endif | 66 | # endif |
| 44 | # define get_highest_layer(state) biton32(state) | 67 | # define get_highest_layer(state) biton32(state) |
| 68 | #else | ||
| 69 | # error Layer Mask size not specified. HOW?! | ||
| 45 | #endif | 70 | #endif |
| 46 | 71 | ||
| 47 | /* | 72 | /* |
| @@ -92,7 +117,7 @@ layer_state_t layer_state_set_kb(layer_state_t state); | |||
| 92 | 117 | ||
| 93 | # define layer_state_set(layer) | 118 | # define layer_state_set(layer) |
| 94 | # define layer_state_is(layer) (layer == 0) | 119 | # define layer_state_is(layer) (layer == 0) |
| 95 | # define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & 1UL << layer) != 0) | 120 | # define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & (layer_state_t)1 << layer) != 0) |
| 96 | 121 | ||
| 97 | # define layer_debug() | 122 | # define layer_debug() |
| 98 | # define layer_clear() | 123 | # define layer_clear() |
diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c index 56044e096..36839f9fa 100644 --- a/tmk_core/common/action_tapping.c +++ b/tmk_core/common/action_tapping.c | |||
| @@ -18,11 +18,16 @@ | |||
| 18 | # define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed) | 18 | # define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed) |
| 19 | # define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) | 19 | # define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) |
| 20 | # define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) | 20 | # define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) |
| 21 | #ifndef COMBO_ENABLE | ||
| 22 | # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key))) | ||
| 23 | #else | ||
| 24 | # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) | ||
| 25 | #endif | ||
| 21 | 26 | ||
| 22 | __attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; } | 27 | __attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; } |
| 23 | 28 | ||
| 24 | # ifdef TAPPING_TERM_PER_KEY | 29 | # ifdef TAPPING_TERM_PER_KEY |
| 25 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event, false), &tapping_key)) | 30 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_record_keycode(&tapping_key, false), &tapping_key)) |
| 26 | # else | 31 | # else |
| 27 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) | 32 | # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) |
| 28 | # endif | 33 | # endif |
| @@ -35,6 +40,10 @@ __attribute__((weak)) bool get_tapping_force_hold(uint16_t keycode, keyrecord_t | |||
| 35 | __attribute__((weak)) bool get_permissive_hold(uint16_t keycode, keyrecord_t *record) { return false; } | 40 | __attribute__((weak)) bool get_permissive_hold(uint16_t keycode, keyrecord_t *record) { return false; } |
| 36 | # endif | 41 | # endif |
| 37 | 42 | ||
| 43 | # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY | ||
| 44 | __attribute__((weak)) bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) { return false; } | ||
| 45 | # endif | ||
| 46 | |||
| 38 | static keyrecord_t tapping_key = {}; | 47 | static keyrecord_t tapping_key = {}; |
| 39 | static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {}; | 48 | static keyrecord_t waiting_buffer[WAITING_BUFFER_SIZE] = {}; |
| 40 | static uint8_t waiting_buffer_head = 0; | 49 | static uint8_t waiting_buffer_head = 0; |
| @@ -103,7 +112,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 103 | if (IS_TAPPING_PRESSED()) { | 112 | if (IS_TAPPING_PRESSED()) { |
| 104 | if (WITHIN_TAPPING_TERM(event)) { | 113 | if (WITHIN_TAPPING_TERM(event)) { |
| 105 | if (tapping_key.tap.count == 0) { | 114 | if (tapping_key.tap.count == 0) { |
| 106 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 115 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { |
| 107 | // first tap! | 116 | // first tap! |
| 108 | debug("Tapping: First tap(0->1).\n"); | 117 | debug("Tapping: First tap(0->1).\n"); |
| 109 | tapping_key.tap.count = 1; | 118 | tapping_key.tap.count = 1; |
| @@ -122,14 +131,14 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 122 | # if defined(TAPPING_TERM_PER_KEY) || (TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) || defined(PERMISSIVE_HOLD_PER_KEY) | 131 | # if defined(TAPPING_TERM_PER_KEY) || (TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) || defined(PERMISSIVE_HOLD_PER_KEY) |
| 123 | else if ((( | 132 | else if ((( |
| 124 | # ifdef TAPPING_TERM_PER_KEY | 133 | # ifdef TAPPING_TERM_PER_KEY |
| 125 | get_tapping_term(get_event_keycode(tapping_key.event, false), keyp) | 134 | get_tapping_term(get_record_keycode(&tapping_key, false), keyp) |
| 126 | # else | 135 | # else |
| 127 | TAPPING_TERM | 136 | TAPPING_TERM |
| 128 | # endif | 137 | # endif |
| 129 | >= 500) | 138 | >= 500) |
| 130 | 139 | ||
| 131 | # ifdef PERMISSIVE_HOLD_PER_KEY | 140 | # ifdef PERMISSIVE_HOLD_PER_KEY |
| 132 | || get_permissive_hold(get_event_keycode(tapping_key.event, false), keyp) | 141 | || get_permissive_hold(get_record_keycode(&tapping_key, false), keyp) |
| 133 | # elif defined(PERMISSIVE_HOLD) | 142 | # elif defined(PERMISSIVE_HOLD) |
| 134 | || true | 143 | || true |
| 135 | # endif | 144 | # endif |
| @@ -170,6 +179,19 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 170 | // set interrupted flag when other key preesed during tapping | 179 | // set interrupted flag when other key preesed during tapping |
| 171 | if (event.pressed) { | 180 | if (event.pressed) { |
| 172 | tapping_key.tap.interrupted = true; | 181 | tapping_key.tap.interrupted = true; |
| 182 | # if defined(HOLD_ON_OTHER_KEY_PRESS) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) | ||
| 183 | # if defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) | ||
| 184 | if (get_hold_on_other_key_press(get_record_keycode(&tapping_key, false), keyp)) | ||
| 185 | # endif | ||
| 186 | { | ||
| 187 | debug("Tapping: End. No tap. Interfered by pressed key\n"); | ||
| 188 | process_record(&tapping_key); | ||
| 189 | tapping_key = (keyrecord_t){}; | ||
| 190 | debug_tapping_key(); | ||
| 191 | // enqueue | ||
| 192 | return false; | ||
| 193 | } | ||
| 194 | # endif | ||
| 173 | } | 195 | } |
| 174 | // enqueue | 196 | // enqueue |
| 175 | return false; | 197 | return false; |
| @@ -177,7 +199,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 177 | } | 199 | } |
| 178 | // tap_count > 0 | 200 | // tap_count > 0 |
| 179 | else { | 201 | else { |
| 180 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 202 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { |
| 181 | debug("Tapping: Tap release("); | 203 | debug("Tapping: Tap release("); |
| 182 | debug_dec(tapping_key.tap.count); | 204 | debug_dec(tapping_key.tap.count); |
| 183 | debug(")\n"); | 205 | debug(")\n"); |
| @@ -186,11 +208,15 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 186 | tapping_key = *keyp; | 208 | tapping_key = *keyp; |
| 187 | debug_tapping_key(); | 209 | debug_tapping_key(); |
| 188 | return true; | 210 | return true; |
| 189 | } else if (is_tap_key(event.key) && event.pressed) { | 211 | } else if (is_tap_record(keyp) && event.pressed) { |
| 190 | if (tapping_key.tap.count > 1) { | 212 | if (tapping_key.tap.count > 1) { |
| 191 | debug("Tapping: Start new tap with releasing last tap(>1).\n"); | 213 | debug("Tapping: Start new tap with releasing last tap(>1).\n"); |
| 192 | // unregister key | 214 | // unregister key |
| 193 | process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false}); | 215 | process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false, |
| 216 | #ifdef COMBO_ENABLE | ||
| 217 | .keycode = tapping_key.keycode, | ||
| 218 | #endif | ||
| 219 | }); | ||
| 194 | } else { | 220 | } else { |
| 195 | debug("Tapping: Start while last tap(1).\n"); | 221 | debug("Tapping: Start while last tap(1).\n"); |
| 196 | } | 222 | } |
| @@ -218,17 +244,21 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 218 | debug_tapping_key(); | 244 | debug_tapping_key(); |
| 219 | return false; | 245 | return false; |
| 220 | } else { | 246 | } else { |
| 221 | if (IS_TAPPING_KEY(event.key) && !event.pressed) { | 247 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { |
| 222 | debug("Tapping: End. last timeout tap release(>0)."); | 248 | debug("Tapping: End. last timeout tap release(>0)."); |
| 223 | keyp->tap = tapping_key.tap; | 249 | keyp->tap = tapping_key.tap; |
| 224 | process_record(keyp); | 250 | process_record(keyp); |
| 225 | tapping_key = (keyrecord_t){}; | 251 | tapping_key = (keyrecord_t){}; |
| 226 | return true; | 252 | return true; |
| 227 | } else if (is_tap_key(event.key) && event.pressed) { | 253 | } else if (is_tap_record(keyp) && event.pressed) { |
| 228 | if (tapping_key.tap.count > 1) { | 254 | if (tapping_key.tap.count > 1) { |
| 229 | debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); | 255 | debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); |
| 230 | // unregister key | 256 | // unregister key |
| 231 | process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false}); | 257 | process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false, |
| 258 | #ifdef COMBO_ENABLE | ||
| 259 | .keycode = tapping_key.keycode, | ||
| 260 | #endif | ||
| 261 | }); | ||
| 232 | } else { | 262 | } else { |
| 233 | debug("Tapping: Start while last timeout tap(1).\n"); | 263 | debug("Tapping: Start while last timeout tap(1).\n"); |
| 234 | } | 264 | } |
| @@ -248,12 +278,12 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 248 | } else if (IS_TAPPING_RELEASED()) { | 278 | } else if (IS_TAPPING_RELEASED()) { |
| 249 | if (WITHIN_TAPPING_TERM(event)) { | 279 | if (WITHIN_TAPPING_TERM(event)) { |
| 250 | if (event.pressed) { | 280 | if (event.pressed) { |
| 251 | if (IS_TAPPING_KEY(event.key)) { | 281 | if (IS_TAPPING_RECORD(keyp)) { |
| 252 | //# ifndef TAPPING_FORCE_HOLD | 282 | //# ifndef TAPPING_FORCE_HOLD |
| 253 | # if !defined(TAPPING_FORCE_HOLD) || defined(TAPPING_FORCE_HOLD_PER_KEY) | 283 | # if !defined(TAPPING_FORCE_HOLD) || defined(TAPPING_FORCE_HOLD_PER_KEY) |
| 254 | if ( | 284 | if ( |
| 255 | # ifdef TAPPING_FORCE_HOLD_PER_KEY | 285 | # ifdef TAPPING_FORCE_HOLD_PER_KEY |
| 256 | !get_tapping_force_hold(get_event_keycode(tapping_key.event, false), keyp) && | 286 | !get_tapping_force_hold(get_record_keycode(&tapping_key, false), keyp) && |
| 257 | # endif | 287 | # endif |
| 258 | !tapping_key.tap.interrupted && tapping_key.tap.count > 0) { | 288 | !tapping_key.tap.interrupted && tapping_key.tap.count > 0) { |
| 259 | // sequential tap. | 289 | // sequential tap. |
| @@ -271,7 +301,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 271 | // FIX: start new tap again | 301 | // FIX: start new tap again |
| 272 | tapping_key = *keyp; | 302 | tapping_key = *keyp; |
| 273 | return true; | 303 | return true; |
| 274 | } else if (is_tap_key(event.key)) { | 304 | } else if (is_tap_record(keyp)) { |
| 275 | // Sequential tap can be interfered with other tap key. | 305 | // Sequential tap can be interfered with other tap key. |
| 276 | debug("Tapping: Start with interfering other tap.\n"); | 306 | debug("Tapping: Start with interfering other tap.\n"); |
| 277 | tapping_key = *keyp; | 307 | tapping_key = *keyp; |
| @@ -303,7 +333,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 303 | } | 333 | } |
| 304 | // not tapping state | 334 | // not tapping state |
| 305 | else { | 335 | else { |
| 306 | if (event.pressed && is_tap_key(event.key)) { | 336 | if (event.pressed && is_tap_record(keyp)) { |
| 307 | debug("Tapping: Start(Press tap key).\n"); | 337 | debug("Tapping: Start(Press tap key).\n"); |
| 308 | tapping_key = *keyp; | 338 | tapping_key = *keyp; |
| 309 | process_record_tap_hint(&tapping_key); | 339 | process_record_tap_hint(&tapping_key); |
diff --git a/tmk_core/common/action_tapping.h b/tmk_core/common/action_tapping.h index 893ccb1ce..7de8049c7 100644 --- a/tmk_core/common/action_tapping.h +++ b/tmk_core/common/action_tapping.h | |||
| @@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 30 | #define WAITING_BUFFER_SIZE 8 | 30 | #define WAITING_BUFFER_SIZE 8 |
| 31 | 31 | ||
| 32 | #ifndef NO_ACTION_TAPPING | 32 | #ifndef NO_ACTION_TAPPING |
| 33 | uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache); | ||
| 33 | uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache); | 34 | uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache); |
| 34 | void action_tapping_process(keyrecord_t record); | 35 | void action_tapping_process(keyrecord_t record); |
| 35 | 36 | ||
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index a57c8bf66..2b3c00cba 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c | |||
| @@ -27,6 +27,10 @@ extern keymap_config_t keymap_config; | |||
| 27 | static uint8_t real_mods = 0; | 27 | static uint8_t real_mods = 0; |
| 28 | static uint8_t weak_mods = 0; | 28 | static uint8_t weak_mods = 0; |
| 29 | static uint8_t macro_mods = 0; | 29 | static uint8_t macro_mods = 0; |
| 30 | #ifdef KEY_OVERRIDE_ENABLE | ||
| 31 | static uint8_t weak_override_mods = 0; | ||
| 32 | static uint8_t suppressed_mods = 0; | ||
| 33 | #endif | ||
| 30 | 34 | ||
| 31 | #ifdef USB_6KRO_ENABLE | 35 | #ifdef USB_6KRO_ENABLE |
| 32 | # define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) | 36 | # define RO_ADD(a, b) ((a + b) % KEYBOARD_REPORT_KEYS) |
| @@ -229,6 +233,7 @@ void send_keyboard_report(void) { | |||
| 229 | keyboard_report->mods = real_mods; | 233 | keyboard_report->mods = real_mods; |
| 230 | keyboard_report->mods |= weak_mods; | 234 | keyboard_report->mods |= weak_mods; |
| 231 | keyboard_report->mods |= macro_mods; | 235 | keyboard_report->mods |= macro_mods; |
| 236 | |||
| 232 | #ifndef NO_ACTION_ONESHOT | 237 | #ifndef NO_ACTION_ONESHOT |
| 233 | if (oneshot_mods) { | 238 | if (oneshot_mods) { |
| 234 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) | 239 | # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) |
| @@ -244,6 +249,13 @@ void send_keyboard_report(void) { | |||
| 244 | } | 249 | } |
| 245 | 250 | ||
| 246 | #endif | 251 | #endif |
| 252 | |||
| 253 | #ifdef KEY_OVERRIDE_ENABLE | ||
| 254 | // These need to be last to be able to properly control key overrides | ||
| 255 | keyboard_report->mods &= ~suppressed_mods; | ||
| 256 | keyboard_report->mods |= weak_override_mods; | ||
| 257 | #endif | ||
| 258 | |||
| 247 | host_keyboard_send(keyboard_report); | 259 | host_keyboard_send(keyboard_report); |
| 248 | } | 260 | } |
| 249 | 261 | ||
| @@ -299,6 +311,22 @@ void set_weak_mods(uint8_t mods) { weak_mods = mods; } | |||
| 299 | */ | 311 | */ |
| 300 | void clear_weak_mods(void) { weak_mods = 0; } | 312 | void clear_weak_mods(void) { weak_mods = 0; } |
| 301 | 313 | ||
| 314 | #ifdef KEY_OVERRIDE_ENABLE | ||
| 315 | /** \brief set weak mods used by key overrides. DO not call this manually | ||
| 316 | */ | ||
| 317 | void set_weak_override_mods(uint8_t mods) { weak_override_mods = mods; } | ||
| 318 | /** \brief clear weak mods used by key overrides. DO not call this manually | ||
| 319 | */ | ||
| 320 | void clear_weak_override_mods(void) { weak_override_mods = 0; } | ||
| 321 | |||
| 322 | /** \brief set suppressed mods used by key overrides. DO not call this manually | ||
| 323 | */ | ||
| 324 | void set_suppressed_override_mods(uint8_t mods) { suppressed_mods = mods; } | ||
| 325 | /** \brief clear suppressed mods used by key overrides. DO not call this manually | ||
| 326 | */ | ||
| 327 | void clear_suppressed_override_mods(void) { suppressed_mods = 0; } | ||
| 328 | #endif | ||
| 329 | |||
| 302 | /* macro modifier */ | 330 | /* macro modifier */ |
| 303 | /** \brief get macro mods | 331 | /** \brief get macro mods |
| 304 | * | 332 | * |
diff --git a/tmk_core/common/arm_atsam/_timer.h b/tmk_core/common/arm_atsam/_timer.h new file mode 100644 index 000000000..77402b612 --- /dev/null +++ b/tmk_core/common/arm_atsam/_timer.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* Copyright 2021 Simon Arlott | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | // The platform is 32-bit, so prefer 32-bit timers to avoid overflow | ||
| 19 | #define FAST_TIMER_T_SIZE 32 | ||
diff --git a/tmk_core/common/avr/_timer.h b/tmk_core/common/avr/_timer.h new file mode 100644 index 000000000..b81e0f68b --- /dev/null +++ b/tmk_core/common/avr/_timer.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* Copyright 2021 Simon Arlott | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | // The platform is 8-bit, so prefer 16-bit timers to reduce code size | ||
| 19 | #define FAST_TIMER_T_SIZE 16 | ||
diff --git a/tmk_core/common/avr/gpio.h b/tmk_core/common/avr/gpio.h index 231556c29..e9be68491 100644 --- a/tmk_core/common/avr/gpio.h +++ b/tmk_core/common/avr/gpio.h | |||
| @@ -20,6 +20,8 @@ | |||
| 20 | 20 | ||
| 21 | typedef uint8_t pin_t; | 21 | typedef uint8_t pin_t; |
| 22 | 22 | ||
| 23 | /* Operation of GPIO by pin. */ | ||
| 24 | |||
| 23 | #define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) | 25 | #define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) |
| 24 | #define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) | 26 | #define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) |
| 25 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") | 27 | #define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") |
| @@ -32,3 +34,16 @@ typedef uint8_t pin_t; | |||
| 32 | #define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) | 34 | #define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) |
| 33 | 35 | ||
| 34 | #define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) | 36 | #define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) |
| 37 | |||
| 38 | /* Operation of GPIO by port. */ | ||
| 39 | |||
| 40 | typedef uint8_t port_data_t; | ||
| 41 | |||
| 42 | #define readPort(port) PINx_ADDRESS(port) | ||
| 43 | |||
| 44 | #define setPortBitInput(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) &= ~_BV((bit)&0xF)) | ||
| 45 | #define setPortBitInputHigh(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) |= _BV((bit)&0xF)) | ||
| 46 | #define setPortBitOutput(port, bit) (DDRx_ADDRESS(port) |= _BV((bit)&0xF)) | ||
| 47 | |||
| 48 | #define writePortBitLow(port, bit) (PORTx_ADDRESS(port) &= ~_BV((bit)&0xF)) | ||
| 49 | #define writePortBitHigh(port, bit) (PORTx_ADDRESS(port) |= _BV((bit)&0xF)) | ||
diff --git a/tmk_core/common/chibios/_timer.h b/tmk_core/common/chibios/_timer.h new file mode 100644 index 000000000..77402b612 --- /dev/null +++ b/tmk_core/common/chibios/_timer.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* Copyright 2021 Simon Arlott | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 2 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | // The platform is 32-bit, so prefer 32-bit timers to avoid overflow | ||
| 19 | #define FAST_TIMER_T_SIZE 32 | ||
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c index 11f7abf43..f9514ee5f 100644 --- a/tmk_core/common/chibios/bootloader.c +++ b/tmk_core/common/chibios/bootloader.c | |||
| @@ -95,7 +95,7 @@ void enter_bootloader_mode_if_requested(void) { | |||
| 95 | } | 95 | } |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | #elif defined(KL2x) || defined(K20x) || defined(MK66F18) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS | 98 | #elif defined(KL2x) || defined(K20x) || defined(MK66F18) || defined(MIMXRT1062) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS |
| 99 | /* Kinetis */ | 99 | /* Kinetis */ |
| 100 | 100 | ||
| 101 | # if defined(BOOTLOADER_KIIBOHD) | 101 | # if defined(BOOTLOADER_KIIBOHD) |
| @@ -103,7 +103,8 @@ void enter_bootloader_mode_if_requested(void) { | |||
| 103 | # define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000 | 103 | # define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000 |
| 104 | const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; | 104 | const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff"; |
| 105 | __attribute__((weak)) void bootloader_jump(void) { | 105 | __attribute__((weak)) void bootloader_jump(void) { |
| 106 | __builtin_memcpy((void *)VBAT, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic)); | 106 | void *volatile vbat = (void *)VBAT; |
| 107 | __builtin_memcpy(vbat, (const void *)sys_reset_to_loader_magic, sizeof(sys_reset_to_loader_magic)); | ||
| 107 | // request reset | 108 | // request reset |
| 108 | SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk; | 109 | SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk; |
| 109 | } | 110 | } |
diff --git a/tmk_core/common/chibios/gpio.h b/tmk_core/common/chibios/gpio.h index 5d0e142ab..4d057f1ca 100644 --- a/tmk_core/common/chibios/gpio.h +++ b/tmk_core/common/chibios/gpio.h | |||
| @@ -20,6 +20,8 @@ | |||
| 20 | 20 | ||
| 21 | typedef ioline_t pin_t; | 21 | typedef ioline_t pin_t; |
| 22 | 22 | ||
| 23 | /* Operation of GPIO by pin. */ | ||
| 24 | |||
| 23 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) | 25 | #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) |
| 24 | #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) | 26 | #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) |
| 25 | #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) | 27 | #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) |
| @@ -32,3 +34,17 @@ typedef ioline_t pin_t; | |||
| 32 | #define readPin(pin) palReadLine(pin) | 34 | #define readPin(pin) palReadLine(pin) |
| 33 | 35 | ||
| 34 | #define togglePin(pin) palToggleLine(pin) | 36 | #define togglePin(pin) palToggleLine(pin) |
| 37 | |||
| 38 | /* Operation of GPIO by port. */ | ||
| 39 | |||
| 40 | typedef uint16_t port_data_t; | ||
| 41 | |||
| 42 | #define readPort(pin) palReadPort(PAL_PORT(pin)) | ||
| 43 | |||
| 44 | #define setPortBitInput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT) | ||
| 45 | #define setPortBitInputHigh(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLUP) | ||
| 46 | #define setPortBitInputLow(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLDOWN) | ||
| 47 | #define setPortBitOutput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_OUTPUT_PUSHPULL) | ||
| 48 | |||
| 49 | #define writePortBitLow(pin, bit) palClearLine(PAL_LINE(PAL_PORT(pin), bit)) | ||
| 50 | #define writePortBitHigh(pin, bit) palSetLine(PAL_LINE(PAL_PORT(pin), bit)) | ||
diff --git a/tmk_core/common/debug.c b/tmk_core/common/debug.c deleted file mode 100644 index ea62deaa8..000000000 --- a/tmk_core/common/debug.c +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include "debug.h" | ||
| 18 | |||
| 19 | debug_config_t debug_config = { | ||
| 20 | .enable = false, // | ||
| 21 | .matrix = false, // | ||
| 22 | .keyboard = false, // | ||
| 23 | .mouse = false, // | ||
| 24 | .reserved = 0 // | ||
| 25 | }; | ||
diff --git a/tmk_core/common/debug.h b/tmk_core/common/debug.h deleted file mode 100644 index 3d2e2315e..000000000 --- a/tmk_core/common/debug.h +++ /dev/null | |||
| @@ -1,169 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #pragma once | ||
| 19 | |||
| 20 | #include <stdbool.h> | ||
| 21 | #include "print.h" | ||
| 22 | |||
| 23 | #ifdef __cplusplus | ||
| 24 | extern "C" { | ||
| 25 | #endif | ||
| 26 | |||
| 27 | /* | ||
| 28 | * Debug output control | ||
| 29 | */ | ||
| 30 | typedef union { | ||
| 31 | struct { | ||
| 32 | bool enable : 1; | ||
| 33 | bool matrix : 1; | ||
| 34 | bool keyboard : 1; | ||
| 35 | bool mouse : 1; | ||
| 36 | uint8_t reserved : 4; | ||
| 37 | }; | ||
| 38 | uint8_t raw; | ||
| 39 | } debug_config_t; | ||
| 40 | |||
| 41 | extern debug_config_t debug_config; | ||
| 42 | |||
| 43 | #ifdef __cplusplus | ||
| 44 | } | ||
| 45 | #endif | ||
| 46 | |||
| 47 | /* for backward compatibility */ | ||
| 48 | #define debug_enable (debug_config.enable) | ||
| 49 | #define debug_matrix (debug_config.matrix) | ||
| 50 | #define debug_keyboard (debug_config.keyboard) | ||
| 51 | #define debug_mouse (debug_config.mouse) | ||
| 52 | |||
| 53 | /* | ||
| 54 | * Debug print utils | ||
| 55 | */ | ||
| 56 | #ifndef NO_DEBUG | ||
| 57 | |||
| 58 | # define dprint(s) \ | ||
| 59 | do { \ | ||
| 60 | if (debug_enable) print(s); \ | ||
| 61 | } while (0) | ||
| 62 | # define dprintln(s) \ | ||
| 63 | do { \ | ||
| 64 | if (debug_enable) println(s); \ | ||
| 65 | } while (0) | ||
| 66 | # define dprintf(fmt, ...) \ | ||
| 67 | do { \ | ||
| 68 | if (debug_enable) xprintf(fmt, ##__VA_ARGS__); \ | ||
| 69 | } while (0) | ||
| 70 | # define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s)) | ||
| 71 | |||
| 72 | /* Deprecated. DO NOT USE these anymore, use dprintf instead. */ | ||
| 73 | # define debug(s) \ | ||
| 74 | do { \ | ||
| 75 | if (debug_enable) print(s); \ | ||
| 76 | } while (0) | ||
| 77 | # define debugln(s) \ | ||
| 78 | do { \ | ||
| 79 | if (debug_enable) println(s); \ | ||
| 80 | } while (0) | ||
| 81 | # define debug_msg(s) \ | ||
| 82 | do { \ | ||
| 83 | if (debug_enable) { \ | ||
| 84 | print(__FILE__); \ | ||
| 85 | print(" at "); \ | ||
| 86 | print_dec(__LINE__); \ | ||
| 87 | print(" in "); \ | ||
| 88 | print(": "); \ | ||
| 89 | print(s); \ | ||
| 90 | } \ | ||
| 91 | } while (0) | ||
| 92 | # define debug_dec(data) \ | ||
| 93 | do { \ | ||
| 94 | if (debug_enable) print_dec(data); \ | ||
| 95 | } while (0) | ||
| 96 | # define debug_decs(data) \ | ||
| 97 | do { \ | ||
| 98 | if (debug_enable) print_decs(data); \ | ||
| 99 | } while (0) | ||
| 100 | # define debug_hex4(data) \ | ||
| 101 | do { \ | ||
| 102 | if (debug_enable) print_hex4(data); \ | ||
| 103 | } while (0) | ||
| 104 | # define debug_hex8(data) \ | ||
| 105 | do { \ | ||
| 106 | if (debug_enable) print_hex8(data); \ | ||
| 107 | } while (0) | ||
| 108 | # define debug_hex16(data) \ | ||
| 109 | do { \ | ||
| 110 | if (debug_enable) print_hex16(data); \ | ||
| 111 | } while (0) | ||
| 112 | # define debug_hex32(data) \ | ||
| 113 | do { \ | ||
| 114 | if (debug_enable) print_hex32(data); \ | ||
| 115 | } while (0) | ||
| 116 | # define debug_bin8(data) \ | ||
| 117 | do { \ | ||
| 118 | if (debug_enable) print_bin8(data); \ | ||
| 119 | } while (0) | ||
| 120 | # define debug_bin16(data) \ | ||
| 121 | do { \ | ||
| 122 | if (debug_enable) print_bin16(data); \ | ||
| 123 | } while (0) | ||
| 124 | # define debug_bin32(data) \ | ||
| 125 | do { \ | ||
| 126 | if (debug_enable) print_bin32(data); \ | ||
| 127 | } while (0) | ||
| 128 | # define debug_bin_reverse8(data) \ | ||
| 129 | do { \ | ||
| 130 | if (debug_enable) print_bin_reverse8(data); \ | ||
| 131 | } while (0) | ||
| 132 | # define debug_bin_reverse16(data) \ | ||
| 133 | do { \ | ||
| 134 | if (debug_enable) print_bin_reverse16(data); \ | ||
| 135 | } while (0) | ||
| 136 | # define debug_bin_reverse32(data) \ | ||
| 137 | do { \ | ||
| 138 | if (debug_enable) print_bin_reverse32(data); \ | ||
| 139 | } while (0) | ||
| 140 | # define debug_hex(data) debug_hex8(data) | ||
| 141 | # define debug_bin(data) debug_bin8(data) | ||
| 142 | # define debug_bin_reverse(data) debug_bin8(data) | ||
| 143 | |||
| 144 | #else /* NO_DEBUG */ | ||
| 145 | |||
| 146 | # define dprint(s) | ||
| 147 | # define dprintln(s) | ||
| 148 | # define dprintf(fmt, ...) | ||
| 149 | # define dmsg(s) | ||
| 150 | # define debug(s) | ||
| 151 | # define debugln(s) | ||
| 152 | # define debug_msg(s) | ||
| 153 | # define debug_dec(data) | ||
| 154 | # define debug_decs(data) | ||
| 155 | # define debug_hex4(data) | ||
| 156 | # define debug_hex8(data) | ||
| 157 | # define debug_hex16(data) | ||
| 158 | # define debug_hex32(data) | ||
| 159 | # define debug_bin8(data) | ||
| 160 | # define debug_bin16(data) | ||
| 161 | # define debug_bin32(data) | ||
| 162 | # define debug_bin_reverse8(data) | ||
| 163 | # define debug_bin_reverse16(data) | ||
| 164 | # define debug_bin_reverse32(data) | ||
| 165 | # define debug_hex(data) | ||
| 166 | # define debug_bin(data) | ||
| 167 | # define debug_bin_reverse(data) | ||
| 168 | |||
| 169 | #endif /* NO_DEBUG */ | ||
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c index e7d92cfac..a8b391e89 100644 --- a/tmk_core/common/host.c +++ b/tmk_core/common/host.c | |||
| @@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 17 | 17 | ||
| 18 | #include <stdint.h> | 18 | #include <stdint.h> |
| 19 | //#include <avr/interrupt.h> | 19 | //#include <avr/interrupt.h> |
| 20 | #include "keyboard.h" | ||
| 20 | #include "keycode.h" | 21 | #include "keycode.h" |
| 21 | #include "host.h" | 22 | #include "host.h" |
| 22 | #include "util.h" | 23 | #include "util.h" |
| @@ -35,15 +36,20 @@ void host_set_driver(host_driver_t *d) { driver = d; } | |||
| 35 | 36 | ||
| 36 | host_driver_t *host_get_driver(void) { return driver; } | 37 | host_driver_t *host_get_driver(void) { return driver; } |
| 37 | 38 | ||
| 39 | #ifdef SPLIT_KEYBOARD | ||
| 40 | uint8_t split_led_state = 0; | ||
| 41 | void set_split_host_keyboard_leds(uint8_t led_state) { split_led_state = led_state; } | ||
| 42 | #endif | ||
| 43 | |||
| 38 | uint8_t host_keyboard_leds(void) { | 44 | uint8_t host_keyboard_leds(void) { |
| 45 | #ifdef SPLIT_KEYBOARD | ||
| 46 | if (!is_keyboard_master()) return split_led_state; | ||
| 47 | #endif | ||
| 39 | if (!driver) return 0; | 48 | if (!driver) return 0; |
| 40 | return (*driver->keyboard_leds)(); | 49 | return (*driver->keyboard_leds)(); |
| 41 | } | 50 | } |
| 42 | 51 | ||
| 43 | led_t host_keyboard_led_state(void) { | 52 | led_t host_keyboard_led_state(void) { return (led_t)host_keyboard_leds(); } |
| 44 | if (!driver) return (led_t){0}; | ||
| 45 | return (led_t)((*driver->keyboard_leds)()); | ||
| 46 | } | ||
| 47 | 53 | ||
| 48 | /* send report */ | 54 | /* send report */ |
| 49 | void host_keyboard_send(report_keyboard_t *report) { | 55 | void host_keyboard_send(report_keyboard_t *report) { |
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index 3d6092e71..28fa97bc8 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c | |||
| @@ -85,6 +85,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 85 | #ifdef OLED_DRIVER_ENABLE | 85 | #ifdef OLED_DRIVER_ENABLE |
| 86 | # include "oled_driver.h" | 86 | # include "oled_driver.h" |
| 87 | #endif | 87 | #endif |
| 88 | #ifdef ST7565_ENABLE | ||
| 89 | # include "st7565.h" | ||
| 90 | #endif | ||
| 88 | #ifdef VELOCIKEY_ENABLE | 91 | #ifdef VELOCIKEY_ENABLE |
| 89 | # include "velocikey.h" | 92 | # include "velocikey.h" |
| 90 | #endif | 93 | #endif |
| @@ -100,6 +103,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 100 | #ifdef EEPROM_DRIVER | 103 | #ifdef EEPROM_DRIVER |
| 101 | # include "eeprom_driver.h" | 104 | # include "eeprom_driver.h" |
| 102 | #endif | 105 | #endif |
| 106 | #if defined(CRC_ENABLE) | ||
| 107 | # include "crc.h" | ||
| 108 | #endif | ||
| 103 | 109 | ||
| 104 | static uint32_t last_input_modification_time = 0; | 110 | static uint32_t last_input_modification_time = 0; |
| 105 | uint32_t last_input_activity_time(void) { return last_input_modification_time; } | 111 | uint32_t last_input_activity_time(void) { return last_input_modification_time; } |
| @@ -297,6 +303,9 @@ void keyboard_init(void) { | |||
| 297 | timer_init(); | 303 | timer_init(); |
| 298 | sync_timer_init(); | 304 | sync_timer_init(); |
| 299 | matrix_init(); | 305 | matrix_init(); |
| 306 | #if defined(CRC_ENABLE) | ||
| 307 | crc_init(); | ||
| 308 | #endif | ||
| 300 | #ifdef VIA_ENABLE | 309 | #ifdef VIA_ENABLE |
| 301 | via_init(); | 310 | via_init(); |
| 302 | #endif | 311 | #endif |
| @@ -306,6 +315,9 @@ void keyboard_init(void) { | |||
| 306 | #ifdef OLED_DRIVER_ENABLE | 315 | #ifdef OLED_DRIVER_ENABLE |
| 307 | oled_init(OLED_ROTATION_0); | 316 | oled_init(OLED_ROTATION_0); |
| 308 | #endif | 317 | #endif |
| 318 | #ifdef ST7565_ENABLE | ||
| 319 | st7565_init(DISPLAY_ROTATION_0); | ||
| 320 | #endif | ||
| 309 | #ifdef PS2_MOUSE_ENABLE | 321 | #ifdef PS2_MOUSE_ENABLE |
| 310 | ps2_mouse_init(); | 322 | ps2_mouse_init(); |
| 311 | #endif | 323 | #endif |
| @@ -470,6 +482,18 @@ MATRIX_LOOP_END: | |||
| 470 | # endif | 482 | # endif |
| 471 | #endif | 483 | #endif |
| 472 | 484 | ||
| 485 | #ifdef ST7565_ENABLE | ||
| 486 | st7565_task(); | ||
| 487 | # ifndef ST7565_DISABLE_TIMEOUT | ||
| 488 | // Wake up display if user is using those fabulous keys or spinning those encoders! | ||
| 489 | # ifdef ENCODER_ENABLE | ||
| 490 | if (matrix_changed || encoders_changed) st7565_on(); | ||
| 491 | # else | ||
| 492 | if (matrix_changed) st7565_on(); | ||
| 493 | # endif | ||
| 494 | # endif | ||
| 495 | #endif | ||
| 496 | |||
| 473 | #ifdef MOUSEKEY_ENABLE | 497 | #ifdef MOUSEKEY_ENABLE |
| 474 | // mousekey repeat & acceleration | 498 | // mousekey repeat & acceleration |
| 475 | mousekey_task(); | 499 | mousekey_task(); |
diff --git a/tmk_core/common/lib_printf.mk b/tmk_core/common/lib_printf.mk deleted file mode 100644 index 10d2d8468..000000000 --- a/tmk_core/common/lib_printf.mk +++ /dev/null | |||
| @@ -1,9 +0,0 @@ | |||
| 1 | PRINTF_PATH = $(LIB_PATH)/printf | ||
| 2 | |||
| 3 | TMK_COMMON_SRC += $(PRINTF_PATH)/printf.c | ||
| 4 | TMK_COMMON_SRC += $(COMMON_DIR)/printf.c | ||
| 5 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_FLOAT | ||
| 6 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_EXPONENTIAL | ||
| 7 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_LONG_LONG | ||
| 8 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T | ||
| 9 | VPATH += $(PRINTF_PATH) | ||
diff --git a/tmk_core/common/nodebug.h b/tmk_core/common/nodebug.h deleted file mode 100644 index 0b176684b..000000000 --- a/tmk_core/common/nodebug.h +++ /dev/null | |||
| @@ -1,26 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2013 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #pragma once | ||
| 19 | |||
| 20 | #ifndef NO_DEBUG | ||
| 21 | # define NO_DEBUG | ||
| 22 | # include "debug.h" | ||
| 23 | # undef NO_DEBUG | ||
| 24 | #else | ||
| 25 | # include "debug.h" | ||
| 26 | #endif | ||
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h deleted file mode 100644 index 8c055f549..000000000 --- a/tmk_core/common/print.h +++ /dev/null | |||
| @@ -1,135 +0,0 @@ | |||
| 1 | /* Copyright 2012 Jun Wako <wakojun@gmail.com> */ | ||
| 2 | /* Very basic print functions, intended to be used with usb_debug_only.c | ||
| 3 | * http://www.pjrc.com/teensy/ | ||
| 4 | * Copyright (c) 2008 PJRC.COM, LLC | ||
| 5 | * | ||
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | * of this software and associated documentation files (the "Software"), to deal | ||
| 8 | * in the Software without restriction, including without limitation the rights | ||
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | * copies of the Software, and to permit persons to whom the Software is | ||
| 11 | * furnished to do so, subject to the following conditions: | ||
| 12 | * | ||
| 13 | * The above copyright notice and this permission notice shall be included in | ||
| 14 | * all copies or substantial portions of the Software. | ||
| 15 | * | ||
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 22 | * THE SOFTWARE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #pragma once | ||
| 26 | |||
| 27 | #include <stdint.h> | ||
| 28 | #include <stdbool.h> | ||
| 29 | #include "util.h" | ||
| 30 | #include "sendchar.h" | ||
| 31 | #include "progmem.h" | ||
| 32 | |||
| 33 | void print_set_sendchar(sendchar_func_t func); | ||
| 34 | |||
| 35 | #ifndef NO_PRINT | ||
| 36 | # if __has_include_next("_print.h") | ||
| 37 | # include_next "_print.h" /* Include the platforms print.h */ | ||
| 38 | # else | ||
| 39 | // Fall back to lib/printf | ||
| 40 | # include "printf.h" // lib/printf/printf.h | ||
| 41 | |||
| 42 | // Create user & normal print defines | ||
| 43 | # define print(s) printf(s) | ||
| 44 | # define println(s) printf(s "\r\n") | ||
| 45 | # define xprintf printf | ||
| 46 | # define uprint(s) printf(s) | ||
| 47 | # define uprintln(s) printf(s "\r\n") | ||
| 48 | # define uprintf printf | ||
| 49 | |||
| 50 | # endif /* __has_include_next("_print.h") */ | ||
| 51 | #else /* NO_PRINT */ | ||
| 52 | # undef xprintf | ||
| 53 | // Remove print defines | ||
| 54 | # define print(s) | ||
| 55 | # define println(s) | ||
| 56 | # define xprintf(fmt, ...) | ||
| 57 | # define uprintf(fmt, ...) | ||
| 58 | # define uprint(s) | ||
| 59 | # define uprintln(s) | ||
| 60 | |||
| 61 | #endif /* NO_PRINT */ | ||
| 62 | |||
| 63 | #ifdef USER_PRINT | ||
| 64 | // Remove normal print defines | ||
| 65 | # undef print | ||
| 66 | # undef println | ||
| 67 | # undef xprintf | ||
| 68 | # define print(s) | ||
| 69 | # define println(s) | ||
| 70 | # define xprintf(fmt, ...) | ||
| 71 | #endif | ||
| 72 | |||
| 73 | #define print_dec(i) xprintf("%u", i) | ||
| 74 | #define print_decs(i) xprintf("%d", i) | ||
| 75 | /* hex */ | ||
| 76 | #define print_hex4(i) xprintf("%X", i) | ||
| 77 | #define print_hex8(i) xprintf("%02X", i) | ||
| 78 | #define print_hex16(i) xprintf("%04X", i) | ||
| 79 | #define print_hex32(i) xprintf("%08lX", i) | ||
| 80 | /* binary */ | ||
| 81 | #define print_bin4(i) xprintf("%04b", i) | ||
| 82 | #define print_bin8(i) xprintf("%08b", i) | ||
| 83 | #define print_bin16(i) xprintf("%016b", i) | ||
| 84 | #define print_bin32(i) xprintf("%032lb", i) | ||
| 85 | #define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) | ||
| 86 | #define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) | ||
| 87 | #define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) | ||
| 88 | /* print value utility */ | ||
| 89 | #define print_val_dec(v) xprintf(#v ": %u\n", v) | ||
| 90 | #define print_val_decs(v) xprintf(#v ": %d\n", v) | ||
| 91 | #define print_val_hex8(v) xprintf(#v ": %X\n", v) | ||
| 92 | #define print_val_hex16(v) xprintf(#v ": %02X\n", v) | ||
| 93 | #define print_val_hex32(v) xprintf(#v ": %04lX\n", v) | ||
| 94 | #define print_val_bin8(v) xprintf(#v ": %08b\n", v) | ||
| 95 | #define print_val_bin16(v) xprintf(#v ": %016b\n", v) | ||
| 96 | #define print_val_bin32(v) xprintf(#v ": %032lb\n", v) | ||
| 97 | #define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v)) | ||
| 98 | #define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v)) | ||
| 99 | #define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v)) | ||
| 100 | |||
| 101 | // User print disables the normal print messages in the body of QMK/TMK code and | ||
| 102 | // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do | ||
| 103 | // a spot of debugging but lack flash resources for allowing all of the codebase to | ||
| 104 | // print (and store their wasteful strings). | ||
| 105 | // | ||
| 106 | // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! | ||
| 107 | |||
| 108 | /* decimal */ | ||
| 109 | #define uprint_dec(i) uprintf("%u", i) | ||
| 110 | #define uprint_decs(i) uprintf("%d", i) | ||
| 111 | /* hex */ | ||
| 112 | #define uprint_hex4(i) uprintf("%X", i) | ||
| 113 | #define uprint_hex8(i) uprintf("%02X", i) | ||
| 114 | #define uprint_hex16(i) uprintf("%04X", i) | ||
| 115 | #define uprint_hex32(i) uprintf("%08lX", i) | ||
| 116 | /* binary */ | ||
| 117 | #define uprint_bin4(i) uprintf("%04b", i) | ||
| 118 | #define uprint_bin8(i) uprintf("%08b", i) | ||
| 119 | #define uprint_bin16(i) uprintf("%016b", i) | ||
| 120 | #define uprint_bin32(i) uprintf("%032lb", i) | ||
| 121 | #define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) | ||
| 122 | #define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) | ||
| 123 | #define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) | ||
| 124 | /* print value utility */ | ||
| 125 | #define uprint_val_dec(v) uprintf(#v ": %u\n", v) | ||
| 126 | #define uprint_val_decs(v) uprintf(#v ": %d\n", v) | ||
| 127 | #define uprint_val_hex8(v) uprintf(#v ": %X\n", v) | ||
| 128 | #define uprint_val_hex16(v) uprintf(#v ": %02X\n", v) | ||
| 129 | #define uprint_val_hex32(v) uprintf(#v ": %04lX\n", v) | ||
| 130 | #define uprint_val_bin8(v) uprintf(#v ": %08b\n", v) | ||
| 131 | #define uprint_val_bin16(v) uprintf(#v ": %016b\n", v) | ||
| 132 | #define uprint_val_bin32(v) uprintf(#v ": %032lb\n", v) | ||
| 133 | #define uprint_val_bin_reverse8(v) uprintf(#v ": %08b\n", bitrev(v)) | ||
| 134 | #define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v)) | ||
| 135 | #define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v)) | ||
diff --git a/tmk_core/common/printf.c b/tmk_core/common/printf.c deleted file mode 100644 index e8440e55e..000000000 --- a/tmk_core/common/printf.c +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include <stddef.h> | ||
| 18 | #include "sendchar.h" | ||
| 19 | |||
| 20 | // bind lib/printf to console interface - sendchar | ||
| 21 | |||
| 22 | static int8_t null_sendchar_func(uint8_t c) { return 0; } | ||
| 23 | static sendchar_func_t func = null_sendchar_func; | ||
| 24 | |||
| 25 | void print_set_sendchar(sendchar_func_t send) { func = send; } | ||
| 26 | |||
| 27 | void _putchar(char character) { func(character); } | ||
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h index 4e4771e52..a70d8e299 100644 --- a/tmk_core/common/progmem.h +++ b/tmk_core/common/progmem.h | |||
| @@ -3,7 +3,9 @@ | |||
| 3 | #if defined(__AVR__) | 3 | #if defined(__AVR__) |
| 4 | # include <avr/pgmspace.h> | 4 | # include <avr/pgmspace.h> |
| 5 | #else | 5 | #else |
| 6 | # include <string.h> | ||
| 6 | # define PROGMEM | 7 | # define PROGMEM |
| 8 | # define __flash | ||
| 7 | # define PSTR(x) x | 9 | # define PSTR(x) x |
| 8 | # define PGM_P const char* | 10 | # define PGM_P const char* |
| 9 | # define memcpy_P(dest, src, n) memcpy(dest, src, n) | 11 | # define memcpy_P(dest, src, n) memcpy(dest, src, n) |
diff --git a/tmk_core/common/sendchar.h b/tmk_core/common/sendchar.h deleted file mode 100644 index edcddaa6b..000000000 --- a/tmk_core/common/sendchar.h +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #pragma once | ||
| 19 | |||
| 20 | #include <stdint.h> | ||
| 21 | |||
| 22 | #ifdef __cplusplus | ||
| 23 | extern "C" { | ||
| 24 | #endif | ||
| 25 | |||
| 26 | typedef int8_t (*sendchar_func_t)(uint8_t c); | ||
| 27 | |||
| 28 | /* transmit a character. return 0 on success, -1 on error. */ | ||
| 29 | int8_t sendchar(uint8_t c); | ||
| 30 | |||
| 31 | #ifdef __cplusplus | ||
| 32 | } | ||
| 33 | #endif | ||
diff --git a/tmk_core/common/sendchar_null.c b/tmk_core/common/sendchar_null.c deleted file mode 100644 index fb67f7086..000000000 --- a/tmk_core/common/sendchar_null.c +++ /dev/null | |||
| @@ -1,19 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include "sendchar.h" | ||
| 18 | |||
| 19 | __attribute__((weak)) int8_t sendchar(uint8_t c) { return 0; } | ||
diff --git a/tmk_core/common/sendchar_uart.c b/tmk_core/common/sendchar_uart.c deleted file mode 100644 index 2fc48baff..000000000 --- a/tmk_core/common/sendchar_uart.c +++ /dev/null | |||
| @@ -1,23 +0,0 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | #include "uart.h" | ||
| 18 | #include "sendchar.h" | ||
| 19 | |||
| 20 | int8_t sendchar(uint8_t c) { | ||
| 21 | uart_putchar(c); | ||
| 22 | return 0; | ||
| 23 | } | ||
diff --git a/tmk_core/common/sync_timer.c b/tmk_core/common/sync_timer.c index de24b463b..68b92d8b4 100644 --- a/tmk_core/common/sync_timer.c +++ b/tmk_core/common/sync_timer.c | |||
| @@ -26,7 +26,7 @@ SOFTWARE. | |||
| 26 | #include "sync_timer.h" | 26 | #include "sync_timer.h" |
| 27 | #include "keyboard.h" | 27 | #include "keyboard.h" |
| 28 | 28 | ||
| 29 | #if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) | 29 | #if (defined(SPLIT_KEYBOARD) || defined(SERIAL_LINK_ENABLE)) && !defined(DISABLE_SYNC_TIMER) |
| 30 | volatile int32_t sync_timer_ms; | 30 | volatile int32_t sync_timer_ms; |
| 31 | 31 | ||
| 32 | void sync_timer_init(void) { sync_timer_ms = 0; } | 32 | void sync_timer_init(void) { sync_timer_ms = 0; } |
diff --git a/tmk_core/common/sync_timer.h b/tmk_core/common/sync_timer.h index 9ddef45bb..744e2b50d 100644 --- a/tmk_core/common/sync_timer.h +++ b/tmk_core/common/sync_timer.h | |||
| @@ -32,7 +32,7 @@ SOFTWARE. | |||
| 32 | extern "C" { | 32 | extern "C" { |
| 33 | #endif | 33 | #endif |
| 34 | 34 | ||
| 35 | #if defined(SPLIT_KEYBOARD) && !defined(DISABLE_SYNC_TIMER) | 35 | #if (defined(SPLIT_KEYBOARD) || defined(SERIAL_LINK_ENABLE)) && !defined(DISABLE_SYNC_TIMER) |
| 36 | void sync_timer_init(void); | 36 | void sync_timer_init(void); |
| 37 | void sync_timer_update(uint32_t time); | 37 | void sync_timer_update(uint32_t time); |
| 38 | uint16_t sync_timer_read(void); | 38 | uint16_t sync_timer_read(void); |
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h index abddcea85..02e39e79e 100644 --- a/tmk_core/common/timer.h +++ b/tmk_core/common/timer.h | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> |
| 3 | Copyright 2021 Simon Arlott | ||
| 3 | 4 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 5 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
| @@ -17,6 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 17 | 18 | ||
| 18 | #pragma once | 19 | #pragma once |
| 19 | 20 | ||
| 21 | #if __has_include_next("_timer.h") | ||
| 22 | # include_next "_timer.h" /* Include the platform's _timer.h */ | ||
| 23 | #endif | ||
| 24 | |||
| 20 | #include <stdint.h> | 25 | #include <stdint.h> |
| 21 | 26 | ||
| 22 | #define TIMER_DIFF(a, b, max) ((max == UINT8_MAX) ? ((uint8_t)((a) - (b))) : ((max == UINT16_MAX) ? ((uint16_t)((a) - (b))) : ((max == UINT32_MAX) ? ((uint32_t)((a) - (b))) : ((a) >= (b) ? (a) - (b) : (max) + 1 - (b) + (a))))) | 27 | #define TIMER_DIFF(a, b, max) ((max == UINT8_MAX) ? ((uint8_t)((a) - (b))) : ((max == UINT16_MAX) ? ((uint16_t)((a) - (b))) : ((max == UINT32_MAX) ? ((uint32_t)((a) - (b))) : ((a) >= (b) ? (a) - (b) : (max) + 1 - (b) + (a))))) |
| @@ -42,6 +47,21 @@ uint32_t timer_elapsed32(uint32_t last); | |||
| 42 | #define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2) | 47 | #define timer_expired(current, future) ((uint16_t)(current - future) < UINT16_MAX / 2) |
| 43 | #define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2) | 48 | #define timer_expired32(current, future) ((uint32_t)(current - future) < UINT32_MAX / 2) |
| 44 | 49 | ||
| 50 | // Use an appropriate timer integer size based on architecture (16-bit will overflow sooner) | ||
| 51 | #if FAST_TIMER_T_SIZE < 32 | ||
| 52 | # define TIMER_DIFF_FAST(a, b) TIMER_DIFF_16(a, b) | ||
| 53 | # define timer_expired_fast(current, future) timer_expired(current, future) | ||
| 54 | typedef uint16_t fast_timer_t; | ||
| 55 | fast_timer_t inline timer_read_fast(void) { return timer_read(); } | ||
| 56 | fast_timer_t inline timer_elapsed_fast(fast_timer_t last) { return timer_elapsed(last); } | ||
| 57 | #else | ||
| 58 | # define TIMER_DIFF_FAST(a, b) TIMER_DIFF_32(a, b) | ||
| 59 | # define timer_expired_fast(current, future) timer_expired32(current, future) | ||
| 60 | typedef uint32_t fast_timer_t; | ||
| 61 | fast_timer_t inline timer_read_fast(void) { return timer_read32(); } | ||
| 62 | fast_timer_t inline timer_elapsed_fast(fast_timer_t last) { return timer_elapsed32(last); } | ||
| 63 | #endif | ||
| 64 | |||
| 45 | #ifdef __cplusplus | 65 | #ifdef __cplusplus |
| 46 | } | 66 | } |
| 47 | #endif | 67 | #endif |
diff --git a/tmk_core/common/usb_util.c b/tmk_core/common/usb_util.c index d4134a044..dd1deeaa1 100644 --- a/tmk_core/common/usb_util.c +++ b/tmk_core/common/usb_util.c | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | #include "quantum.h" | 16 | #include "quantum.h" |
| 17 | #include "usb_util.h" | 17 | #include "usb_util.h" |
| 18 | 18 | ||
| 19 | __attribute__((weak)) void usb_disable(void) {} | 19 | __attribute__((weak)) void usb_disconnect(void) {} |
| 20 | __attribute__((weak)) bool usb_connected_state(void) { return true; } | 20 | __attribute__((weak)) bool usb_connected_state(void) { return true; } |
| 21 | __attribute__((weak)) bool usb_vbus_state(void) { | 21 | __attribute__((weak)) bool usb_vbus_state(void) { |
| 22 | #ifdef USB_VBUS_PIN | 22 | #ifdef USB_VBUS_PIN |
diff --git a/tmk_core/common/usb_util.h b/tmk_core/common/usb_util.h index 4ebedb1e7..13db9fbfb 100644 --- a/tmk_core/common/usb_util.h +++ b/tmk_core/common/usb_util.h | |||
| @@ -17,6 +17,6 @@ | |||
| 17 | 17 | ||
| 18 | #include <stdbool.h> | 18 | #include <stdbool.h> |
| 19 | 19 | ||
| 20 | void usb_disable(void); | 20 | void usb_disconnect(void); |
| 21 | bool usb_connected_state(void); | 21 | bool usb_connected_state(void); |
| 22 | bool usb_vbus_state(void); | 22 | bool usb_vbus_state(void); |
