summaryrefslogtreecommitdiff
path: root/quantum/rgblight
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2022-05-29 15:38:33 -0700
committerDrashna Jael're <drashna@live.com>2022-05-29 15:38:33 -0700
commit30aac80d5a6d8c6f7c06efb49189d748e70edc4a (patch)
treeceb11968ae41228e4b110c07467cdca7cc9cff22 /quantum/rgblight
parent67f4e5f34489abf986dedb4984b256692086c615 (diff)
parente22a183329fd05d39f88bb9dfebe98cfa7cd8402 (diff)
Merge remote-tracking branch 'qmk 0.17.0' into firmware21
Diffstat (limited to 'quantum/rgblight')
-rw-r--r--quantum/rgblight/rgblight.c42
-rw-r--r--quantum/rgblight/rgblight.h26
2 files changed, 55 insertions, 13 deletions
diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c
index 8f933a6e51..e5d3a98bea 100644
--- a/quantum/rgblight/rgblight.c
+++ b/quantum/rgblight/rgblight.c
@@ -559,12 +559,8 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w
// static gradient
uint8_t delta = rgblight_config.mode - rgblight_status.base_mode;
bool direction = (delta % 2) == 0;
-# ifdef __AVR__
- // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line
- uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]);
-# else
- uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2];
-# endif
+
+ uint8_t range = pgm_read_byte(&RGBLED_GRADIENT_RANGES[delta / 2]);
for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) {
uint8_t _hue = ((uint16_t)i * (uint16_t)range) / rgblight_ranges.effect_num_leds;
if (direction) {
@@ -813,6 +809,10 @@ void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms) {
}
void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times) {
+ if (times > UINT8_MAX / 2) {
+ times = UINT8_MAX / 2;
+ }
+
_times_remaining = times * 2;
_dur = duration_ms;
@@ -822,21 +822,37 @@ void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t ti
_repeat_timer = sync_timer_read() + duration_ms;
}
+void rgblight_unblink_layer(uint8_t layer) {
+ rgblight_set_layer_state(layer, false);
+ _blinking_layer_mask &= ~((rgblight_layer_mask_t)1 << layer);
+}
+
+void rgblight_unblink_all_but_layer(uint8_t layer) {
+ for (uint8_t i = 0; i < RGBLIGHT_MAX_LAYERS; i++) {
+ if (i != layer) {
+ if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << i) != 0) {
+ rgblight_unblink_layer(i);
+ }
+ }
+ }
+}
+
void rgblight_blink_layer_repeat_helper(void) {
if (_blinking_layer_mask != 0 && timer_expired(sync_timer_read(), _repeat_timer)) {
for (uint8_t layer = 0; layer < RGBLIGHT_MAX_LAYERS; layer++) {
- if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0 && _times_remaining > 0) {
+ if ((_blinking_layer_mask & (rgblight_layer_mask_t)1 << layer) != 0) {
if (_times_remaining % 2 == 1) {
rgblight_set_layer_state(layer, false);
} else {
rgblight_set_layer_state(layer, true);
}
- _times_remaining--;
- _repeat_timer = sync_timer_read() + _dur;
}
}
+ _times_remaining--;
if (_times_remaining <= 0) {
_blinking_layer_mask = 0;
+ } else {
+ _repeat_timer = sync_timer_read() + _dur;
}
}
}
@@ -1254,19 +1270,19 @@ void rgblight_effect_snake(animation_status_t *anim) {
}
rgblight_set();
if (increment == 1) {
- if (pos - 1 < 0) {
+ if (pos - RGBLIGHT_EFFECT_SNAKE_INCREMENT < 0) {
pos = rgblight_ranges.effect_num_leds - 1;
# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
anim->pos = 0;
# endif
} else {
- pos -= 1;
+ pos -= RGBLIGHT_EFFECT_SNAKE_INCREMENT;
# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
anim->pos = 1;
# endif
}
} else {
- pos = (pos + 1) % rgblight_ranges.effect_num_leds;
+ pos = (pos + RGBLIGHT_EFFECT_SNAKE_INCREMENT) % rgblight_ranges.effect_num_leds;
# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
anim->pos = pos;
# endif
@@ -1280,7 +1296,7 @@ __attribute__((weak)) const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63
void rgblight_effect_knight(animation_status_t *anim) {
static int8_t low_bound = 0;
static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
- static int8_t increment = 1;
+ static int8_t increment = RGBLIGHT_EFFECT_KNIGHT_INCREMENT;
uint8_t i, cur;
# if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC)
diff --git a/quantum/rgblight/rgblight.h b/quantum/rgblight/rgblight.h
index 7076dc41ac..a08b9a7b6b 100644
--- a/quantum/rgblight/rgblight.h
+++ b/quantum/rgblight/rgblight.h
@@ -126,10 +126,18 @@ enum RGBLIGHT_EFFECT_MODE {
# define RGBLIGHT_EFFECT_SNAKE_LENGTH 4
#endif
+#ifndef RGBLIGHT_EFFECT_SNAKE_INCREMENT
+# define RGBLIGHT_EFFECT_SNAKE_INCREMENT 1
+#endif
+
#ifndef RGBLIGHT_EFFECT_KNIGHT_LENGTH
# define RGBLIGHT_EFFECT_KNIGHT_LENGTH 3
#endif
+#ifndef RGBLIGHT_EFFECT_KNIGHT_INCREMENT
+# define RGBLIGHT_EFFECT_KNIGHT_INCREMENT 1
+#endif
+
#ifndef RGBLIGHT_EFFECT_KNIGHT_OFFSET
# define RGBLIGHT_EFFECT_KNIGHT_OFFSET 0
#endif
@@ -217,6 +225,24 @@ extern const rgblight_segment_t *const *rgblight_layers;
# define RGBLIGHT_USE_TIMER
void rgblight_blink_layer(uint8_t layer, uint16_t duration_ms);
void rgblight_blink_layer_repeat(uint8_t layer, uint16_t duration_ms, uint8_t times);
+/**
+ * \brief Stop blinking on one layer.
+ *
+ * Stop a layer that is blinking. If the layer is not blinking it will
+ * be unaffected.
+ *
+ * \param layer Layer number to stop blinking.
+ */
+void rgblight_unblink_layer(uint8_t layer);
+/**
+ * \brief Stop blinking all layers except one.
+ *
+ * Stop all layers that are blinking except for one specific layer.
+ * Layers that are not blinking are unaffected.
+ *
+ * \param layer Layer number to keep blinking.
+ */
+void rgblight_unblink_all_but_layer(uint8_t layer);
# endif
#endif