diff options
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/quantum.h | 1 | ||||
| -rw-r--r-- | quantum/rgb_matrix.c | 6 | ||||
| -rw-r--r-- | quantum/rgblight.c | 21 | ||||
| -rw-r--r-- | quantum/split_common/transport.c | 95 |
4 files changed, 107 insertions, 16 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h index 3e09df4f8..9b2b9dee6 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | #include "eeconfig.h" | 53 | #include "eeconfig.h" |
| 54 | #include "bootloader.h" | 54 | #include "bootloader.h" |
| 55 | #include "timer.h" | 55 | #include "timer.h" |
| 56 | #include "sync_timer.h" | ||
| 56 | #include "config_common.h" | 57 | #include "config_common.h" |
| 57 | #include "led.h" | 58 | #include "led.h" |
| 58 | #include "action_util.h" | 59 | #include "action_util.h" |
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index c756857ae..fd04adc27 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c | |||
| @@ -266,9 +266,9 @@ static bool rgb_matrix_none(effect_params_t *params) { | |||
| 266 | 266 | ||
| 267 | static void rgb_task_timers(void) { | 267 | static void rgb_task_timers(void) { |
| 268 | #if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 | 268 | #if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 |
| 269 | uint32_t deltaTime = timer_elapsed32(rgb_timer_buffer); | 269 | uint32_t deltaTime = sync_timer_elapsed32(rgb_timer_buffer); |
| 270 | #endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 | 270 | #endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0 |
| 271 | rgb_timer_buffer = timer_read32(); | 271 | rgb_timer_buffer = sync_timer_read32(); |
| 272 | 272 | ||
| 273 | // Update double buffer timers | 273 | // Update double buffer timers |
| 274 | #if RGB_DISABLE_TIMEOUT > 0 | 274 | #if RGB_DISABLE_TIMEOUT > 0 |
| @@ -296,7 +296,7 @@ static void rgb_task_timers(void) { | |||
| 296 | 296 | ||
| 297 | static void rgb_task_sync(void) { | 297 | static void rgb_task_sync(void) { |
| 298 | // next task | 298 | // next task |
| 299 | if (timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; | 299 | if (sync_timer_elapsed32(g_rgb_timer) >= RGB_MATRIX_LED_FLUSH_LIMIT) rgb_task_state = STARTING; |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | static void rgb_task_start(void) { | 302 | static void rgb_task_start(void) { |
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index db725301c..3297f3a71 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -29,7 +29,7 @@ | |||
| 29 | #endif | 29 | #endif |
| 30 | #include "wait.h" | 30 | #include "wait.h" |
| 31 | #include "progmem.h" | 31 | #include "progmem.h" |
| 32 | #include "timer.h" | 32 | #include "sync_timer.h" |
| 33 | #include "rgblight.h" | 33 | #include "rgblight.h" |
| 34 | #include "color.h" | 34 | #include "color.h" |
| 35 | #include "debug.h" | 35 | #include "debug.h" |
| @@ -684,18 +684,16 @@ static void rgblight_layers_write(void) { | |||
| 684 | 684 | ||
| 685 | # ifdef RGBLIGHT_LAYER_BLINK | 685 | # ifdef RGBLIGHT_LAYER_BLINK |
| 686 | rgblight_layer_mask_t _blinked_layer_mask = 0; | 686 | rgblight_layer_mask_t _blinked_layer_mask = 0; |
| 687 | uint16_t _blink_duration = 0; | ||
| 688 | static uint16_t _blink_timer; | 687 | static uint16_t _blink_timer; |
| 689 | 688 | ||
| 690 | void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { | 689 | void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) { |
| 691 | rgblight_set_layer_state(layer, true); | 690 | rgblight_set_layer_state(layer, true); |
| 692 | _blinked_layer_mask |= 1 << layer; | 691 | _blinked_layer_mask |= 1 << layer; |
| 693 | _blink_timer = timer_read(); | 692 | _blink_timer = sync_timer_read() + duration_ms; |
| 694 | _blink_duration = duration_ms; | ||
| 695 | } | 693 | } |
| 696 | 694 | ||
| 697 | void rgblight_unblink_layers(void) { | 695 | void rgblight_unblink_layers(void) { |
| 698 | if (_blinked_layer_mask != 0 && timer_elapsed(_blink_timer) > _blink_duration) { | 696 | if (_blinked_layer_mask != 0 && timer_expired(sync_timer_read(), _blink_timer)) { |
| 699 | for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { | 697 | for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) { |
| 700 | if ((_blinked_layer_mask & 1 << layer) != 0) { | 698 | if ((_blinked_layer_mask & 1 << layer) != 0) { |
| 701 | rgblight_set_layer_state(layer, false); | 699 | rgblight_set_layer_state(layer, false); |
| @@ -799,7 +797,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { | |||
| 799 | animation_status.restart = true; | 797 | animation_status.restart = true; |
| 800 | } | 798 | } |
| 801 | # endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ | 799 | # endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ |
| 802 | # endif /* RGBLIGHT_USE_TIMER */ | 800 | # endif /* RGBLIGHT_USE_TIMER */ |
| 803 | } | 801 | } |
| 804 | #endif /* RGBLIGHT_SPLIT */ | 802 | #endif /* RGBLIGHT_SPLIT */ |
| 805 | 803 | ||
| @@ -832,7 +830,7 @@ void rgblight_timer_enable(void) { | |||
| 832 | if (!is_static_effect(rgblight_config.mode)) { | 830 | if (!is_static_effect(rgblight_config.mode)) { |
| 833 | rgblight_status.timer_enabled = true; | 831 | rgblight_status.timer_enabled = true; |
| 834 | } | 832 | } |
| 835 | animation_status.last_timer = timer_read(); | 833 | animation_status.last_timer = sync_timer_read(); |
| 836 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; | 834 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; |
| 837 | dprintf("rgblight timer enabled.\n"); | 835 | dprintf("rgblight timer enabled.\n"); |
| 838 | } | 836 | } |
| @@ -941,18 +939,19 @@ void rgblight_task(void) { | |||
| 941 | # endif | 939 | # endif |
| 942 | if (animation_status.restart) { | 940 | if (animation_status.restart) { |
| 943 | animation_status.restart = false; | 941 | animation_status.restart = false; |
| 944 | animation_status.last_timer = timer_read() - interval_time - 1; | 942 | animation_status.last_timer = sync_timer_read(); |
| 945 | animation_status.pos16 = 0; // restart signal to local each effect | 943 | animation_status.pos16 = 0; // restart signal to local each effect |
| 946 | } | 944 | } |
| 947 | if (timer_elapsed(animation_status.last_timer) >= interval_time) { | 945 | uint16_t now = sync_timer_read(); |
| 946 | if (timer_expired(now, animation_status.last_timer)) { | ||
| 948 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 947 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) |
| 949 | static uint16_t report_last_timer = 0; | 948 | static uint16_t report_last_timer = 0; |
| 950 | static bool tick_flag = false; | 949 | static bool tick_flag = false; |
| 951 | uint16_t oldpos16; | 950 | uint16_t oldpos16; |
| 952 | if (tick_flag) { | 951 | if (tick_flag) { |
| 953 | tick_flag = false; | 952 | tick_flag = false; |
| 954 | if (timer_elapsed(report_last_timer) >= 30000) { | 953 | if (timer_expired(now, report_last_timer)) { |
| 955 | report_last_timer = timer_read(); | 954 | report_last_timer += 30000; |
| 956 | dprintf("rgblight animation tick report to slave\n"); | 955 | dprintf("rgblight animation tick report to slave\n"); |
| 957 | RGBLIGHT_SPLIT_ANIMATION_TICK; | 956 | RGBLIGHT_SPLIT_ANIMATION_TICK; |
| 958 | } | 957 | } |
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index 467ff81a9..e601fb4df 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include "quantum.h" | 6 | #include "quantum.h" |
| 7 | 7 | ||
| 8 | #define ROWS_PER_HAND (MATRIX_ROWS / 2) | 8 | #define ROWS_PER_HAND (MATRIX_ROWS / 2) |
| 9 | #define SYNC_TIMER_OFFSET 2 | ||
| 9 | 10 | ||
| 10 | #ifdef RGBLIGHT_ENABLE | 11 | #ifdef RGBLIGHT_ENABLE |
| 11 | # include "rgblight.h" | 12 | # include "rgblight.h" |
| @@ -27,8 +28,20 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A; | |||
| 27 | # include "i2c_slave.h" | 28 | # include "i2c_slave.h" |
| 28 | 29 | ||
| 29 | typedef struct _I2C_slave_buffer_t { | 30 | typedef struct _I2C_slave_buffer_t { |
| 31 | # ifndef DISABLE_SYNC_TIMER | ||
| 32 | uint32_t sync_timer; | ||
| 33 | # endif | ||
| 30 | matrix_row_t smatrix[ROWS_PER_HAND]; | 34 | matrix_row_t smatrix[ROWS_PER_HAND]; |
| 35 | # ifdef SPLIT_MODS_ENABLE | ||
| 36 | uint8_t real_mods; | ||
| 37 | uint8_t weak_mods; | ||
| 38 | # ifndef NO_ACTION_ONESHOT | ||
| 39 | uint8_t oneshot_mods; | ||
| 40 | # endif | ||
| 41 | # endif | ||
| 42 | # ifdef BACKLIGHT_ENABLE | ||
| 31 | uint8_t backlight_level; | 43 | uint8_t backlight_level; |
| 44 | # endif | ||
| 32 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) | 45 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) |
| 33 | rgblight_syncinfo_t rgblight_sync; | 46 | rgblight_syncinfo_t rgblight_sync; |
| 34 | # endif | 47 | # endif |
| @@ -42,9 +55,13 @@ typedef struct _I2C_slave_buffer_t { | |||
| 42 | 55 | ||
| 43 | static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; | 56 | static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; |
| 44 | 57 | ||
| 58 | # define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) | ||
| 59 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) | ||
| 60 | # define I2C_REAL_MODS_START offsetof(I2C_slave_buffer_t, real_mods) | ||
| 61 | # define I2C_WEAK_MODS_START offsetof(I2C_slave_buffer_t, weak_mods) | ||
| 62 | # define I2C_ONESHOT_MODS_START offsetof(I2C_slave_buffer_t, oneshot_mods) | ||
| 45 | # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) | 63 | # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) |
| 46 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) | 64 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) |
| 47 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) | ||
| 48 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) | 65 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) |
| 49 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) | 66 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) |
| 50 | 67 | ||
| @@ -91,10 +108,43 @@ bool transport_master(matrix_row_t matrix[]) { | |||
| 91 | } | 108 | } |
| 92 | } | 109 | } |
| 93 | # endif | 110 | # endif |
| 111 | |||
| 112 | # ifdef SPLIT_MODS_ENABLE | ||
| 113 | uint8_t real_mods = get_mods(); | ||
| 114 | if (real_mods != i2c_buffer->real_mods) { | ||
| 115 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_REAL_MODS_START, (void *)&real_mods, sizeof(real_mods), TIMEOUT) >= 0) { | ||
| 116 | i2c_buffer->real_mods = real_mods; | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | uint8_t weak_mods = get_weak_mods(); | ||
| 121 | if (weak_mods != i2c_buffer->weak_mods) { | ||
| 122 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_WEAK_MODS_START, (void *)&weak_mods, sizeof(weak_mods), TIMEOUT) >= 0) { | ||
| 123 | i2c_buffer->weak_mods = weak_mods; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | # ifndef NO_ACTION_ONESHOT | ||
| 128 | uint8_t oneshot_mods = get_oneshot_mods(); | ||
| 129 | if (oneshot_mods != i2c_buffer->oneshot_mods) { | ||
| 130 | if (i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_ONESHOT_MODS_START, (void *)&oneshot_mods, sizeof(oneshot_mods), TIMEOUT) >= 0) { | ||
| 131 | i2c_buffer->oneshot_mods = oneshot_mods; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | # endif | ||
| 135 | # endif | ||
| 136 | |||
| 137 | # ifndef DISABLE_SYNC_TIMER | ||
| 138 | i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | ||
| 139 | i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); | ||
| 140 | # endif | ||
| 94 | return true; | 141 | return true; |
| 95 | } | 142 | } |
| 96 | 143 | ||
| 97 | void transport_slave(matrix_row_t matrix[]) { | 144 | void transport_slave(matrix_row_t matrix[]) { |
| 145 | # ifndef DISABLE_SYNC_TIMER | ||
| 146 | sync_timer_update(i2c_buffer->sync_timer); | ||
| 147 | # endif | ||
| 98 | // Copy matrix to I2C buffer | 148 | // Copy matrix to I2C buffer |
| 99 | memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); | 149 | memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); |
| 100 | 150 | ||
| @@ -118,6 +168,14 @@ void transport_slave(matrix_row_t matrix[]) { | |||
| 118 | # ifdef WPM_ENABLE | 168 | # ifdef WPM_ENABLE |
| 119 | set_current_wpm(i2c_buffer->current_wpm); | 169 | set_current_wpm(i2c_buffer->current_wpm); |
| 120 | # endif | 170 | # endif |
| 171 | |||
| 172 | # ifdef SPLIT_MODS_ENABLE | ||
| 173 | set_mods(i2c_buffer->real_mods); | ||
| 174 | set_weak_mods(i2c_buffer->weak_mods); | ||
| 175 | # ifndef NO_ACTION_ONESHOT | ||
| 176 | set_oneshot_mods(i2c_buffer->oneshot_mods); | ||
| 177 | # endif | ||
| 178 | # endif | ||
| 121 | } | 179 | } |
| 122 | 180 | ||
| 123 | void transport_master_init(void) { i2c_init(); } | 181 | void transport_master_init(void) { i2c_init(); } |
| @@ -133,12 +191,22 @@ typedef struct _Serial_s2m_buffer_t { | |||
| 133 | matrix_row_t smatrix[ROWS_PER_HAND]; | 191 | matrix_row_t smatrix[ROWS_PER_HAND]; |
| 134 | 192 | ||
| 135 | # ifdef ENCODER_ENABLE | 193 | # ifdef ENCODER_ENABLE |
| 136 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; | 194 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; |
| 137 | # endif | 195 | # endif |
| 138 | 196 | ||
| 139 | } Serial_s2m_buffer_t; | 197 | } Serial_s2m_buffer_t; |
| 140 | 198 | ||
| 141 | typedef struct _Serial_m2s_buffer_t { | 199 | typedef struct _Serial_m2s_buffer_t { |
| 200 | # ifdef SPLIT_MODS_ENABLE | ||
| 201 | uint8_t real_mods; | ||
| 202 | uint8_t weak_mods; | ||
| 203 | # ifndef NO_ACTION_ONESHOT | ||
| 204 | uint8_t oneshot_mods; | ||
| 205 | # endif | ||
| 206 | # endif | ||
| 207 | # ifndef DISABLE_SYNC_TIMER | ||
| 208 | uint32_t sync_timer; | ||
| 209 | # endif | ||
| 142 | # ifdef BACKLIGHT_ENABLE | 210 | # ifdef BACKLIGHT_ENABLE |
| 143 | uint8_t backlight_level; | 211 | uint8_t backlight_level; |
| 144 | # endif | 212 | # endif |
| @@ -251,11 +319,26 @@ bool transport_master(matrix_row_t matrix[]) { | |||
| 251 | // Write wpm to slave | 319 | // Write wpm to slave |
| 252 | serial_m2s_buffer.current_wpm = get_current_wpm(); | 320 | serial_m2s_buffer.current_wpm = get_current_wpm(); |
| 253 | # endif | 321 | # endif |
| 322 | |||
| 323 | # ifdef SPLIT_MODS_ENABLE | ||
| 324 | serial_m2s_buffer.real_mods = get_mods(); | ||
| 325 | serial_m2s_buffer.weak_mods = get_weak_mods(); | ||
| 326 | # ifndef NO_ACTION_ONESHOT | ||
| 327 | serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); | ||
| 328 | # endif | ||
| 329 | # endif | ||
| 330 | # ifndef DISABLE_SYNC_TIMER | ||
| 331 | serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | ||
| 332 | # endif | ||
| 254 | return true; | 333 | return true; |
| 255 | } | 334 | } |
| 256 | 335 | ||
| 257 | void transport_slave(matrix_row_t matrix[]) { | 336 | void transport_slave(matrix_row_t matrix[]) { |
| 258 | transport_rgblight_slave(); | 337 | transport_rgblight_slave(); |
| 338 | # ifndef DISABLE_SYNC_TIMER | ||
| 339 | sync_timer_update(serial_m2s_buffer.sync_timer); | ||
| 340 | # endif | ||
| 341 | |||
| 259 | // TODO: if MATRIX_COLS > 8 change to pack() | 342 | // TODO: if MATRIX_COLS > 8 change to pack() |
| 260 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 343 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
| 261 | serial_s2m_buffer.smatrix[i] = matrix[i]; | 344 | serial_s2m_buffer.smatrix[i] = matrix[i]; |
| @@ -271,6 +354,14 @@ void transport_slave(matrix_row_t matrix[]) { | |||
| 271 | # ifdef WPM_ENABLE | 354 | # ifdef WPM_ENABLE |
| 272 | set_current_wpm(serial_m2s_buffer.current_wpm); | 355 | set_current_wpm(serial_m2s_buffer.current_wpm); |
| 273 | # endif | 356 | # endif |
| 357 | |||
| 358 | # ifdef SPLIT_MODS_ENABLE | ||
| 359 | set_mods(serial_m2s_buffer.real_mods); | ||
| 360 | set_weak_mods(serial_m2s_buffer.weak_mods); | ||
| 361 | # ifndef NO_ACTION_ONESHOT | ||
| 362 | set_oneshot_mods(serial_m2s_buffer.oneshot_mods); | ||
| 363 | # endif | ||
| 364 | # endif | ||
| 274 | } | 365 | } |
| 275 | 366 | ||
| 276 | #endif | 367 | #endif |
