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 | 26 |
4 files changed, 39 insertions, 15 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h index cb0af306a..59c3dd490 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 f239bd582..a3dd51f7b 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 7f9e330d3..65308572d 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..6856b6055 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,6 +28,9 @@ 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]; |
31 | uint8_t backlight_level; | 35 | uint8_t backlight_level; |
32 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) | 36 | # if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) |
@@ -44,6 +48,7 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re | |||
44 | 48 | ||
45 | # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) | 49 | # define I2C_BACKLIGHT_START offsetof(I2C_slave_buffer_t, backlight_level) |
46 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) | 50 | # define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) |
51 | # define I2C_SYNC_TIME_START offsetof(I2C_slave_buffer_t, sync_timer) | ||
47 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) | 52 | # define I2C_KEYMAP_START offsetof(I2C_slave_buffer_t, smatrix) |
48 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) | 53 | # define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) |
49 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) | 54 | # define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) |
@@ -91,10 +96,18 @@ bool transport_master(matrix_row_t matrix[]) { | |||
91 | } | 96 | } |
92 | } | 97 | } |
93 | # endif | 98 | # endif |
99 | |||
100 | # ifndef DISABLE_SYNC_TIMER | ||
101 | i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | ||
102 | i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); | ||
103 | # endif | ||
94 | return true; | 104 | return true; |
95 | } | 105 | } |
96 | 106 | ||
97 | void transport_slave(matrix_row_t matrix[]) { | 107 | void transport_slave(matrix_row_t matrix[]) { |
108 | # ifndef DISABLE_SYNC_TIMER | ||
109 | sync_timer_update(i2c_buffer->sync_timer); | ||
110 | # endif | ||
98 | // Copy matrix to I2C buffer | 111 | // Copy matrix to I2C buffer |
99 | memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); | 112 | memcpy((void *)i2c_buffer->smatrix, (void *)matrix, sizeof(i2c_buffer->smatrix)); |
100 | 113 | ||
@@ -133,12 +146,15 @@ typedef struct _Serial_s2m_buffer_t { | |||
133 | matrix_row_t smatrix[ROWS_PER_HAND]; | 146 | matrix_row_t smatrix[ROWS_PER_HAND]; |
134 | 147 | ||
135 | # ifdef ENCODER_ENABLE | 148 | # ifdef ENCODER_ENABLE |
136 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; | 149 | uint8_t encoder_state[NUMBER_OF_ENCODERS]; |
137 | # endif | 150 | # endif |
138 | 151 | ||
139 | } Serial_s2m_buffer_t; | 152 | } Serial_s2m_buffer_t; |
140 | 153 | ||
141 | typedef struct _Serial_m2s_buffer_t { | 154 | typedef struct _Serial_m2s_buffer_t { |
155 | # ifndef DISABLE_SYNC_TIMER | ||
156 | uint32_t sync_timer; | ||
157 | # endif | ||
142 | # ifdef BACKLIGHT_ENABLE | 158 | # ifdef BACKLIGHT_ENABLE |
143 | uint8_t backlight_level; | 159 | uint8_t backlight_level; |
144 | # endif | 160 | # endif |
@@ -251,11 +267,19 @@ bool transport_master(matrix_row_t matrix[]) { | |||
251 | // Write wpm to slave | 267 | // Write wpm to slave |
252 | serial_m2s_buffer.current_wpm = get_current_wpm(); | 268 | serial_m2s_buffer.current_wpm = get_current_wpm(); |
253 | # endif | 269 | # endif |
270 | |||
271 | # ifndef DISABLE_SYNC_TIMER | ||
272 | serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; | ||
273 | # endif | ||
254 | return true; | 274 | return true; |
255 | } | 275 | } |
256 | 276 | ||
257 | void transport_slave(matrix_row_t matrix[]) { | 277 | void transport_slave(matrix_row_t matrix[]) { |
258 | transport_rgblight_slave(); | 278 | transport_rgblight_slave(); |
279 | # ifndef DISABLE_SYNC_TIMER | ||
280 | sync_timer_update(serial_m2s_buffer.sync_timer); | ||
281 | # endif | ||
282 | |||
259 | // TODO: if MATRIX_COLS > 8 change to pack() | 283 | // TODO: if MATRIX_COLS > 8 change to pack() |
260 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 284 | for (int i = 0; i < ROWS_PER_HAND; ++i) { |
261 | serial_s2m_buffer.smatrix[i] = matrix[i]; | 285 | serial_s2m_buffer.smatrix[i] = matrix[i]; |