Updating effect function api for future extensions

pull/5372/head
Ryan Caltabiano 5 years ago
parent 8073da5dea
commit 161c4b21dc

@ -211,8 +211,8 @@ void rgb_matrix_test(void) {
}
}
static bool rgb_matrix_none(bool init, uint8_t iter) {
if (!init) {
static bool rgb_matrix_none(effect_params_t* params) {
if (!params->init) {
return false;
}
@ -225,7 +225,7 @@ static bool rgb_matrix_none(bool init, uint8_t iter) {
static uint8_t rgb_last_enable = UINT8_MAX;
static uint8_t rgb_last_effect = UINT8_MAX;
static uint8_t rgb_anim_iter = 0;
static effect_params_t rgb_effect_params = { 0, 0 };
static rgb_task_states rgb_task_state = SYNCING;
static void rgb_task_timers(void) {
@ -261,7 +261,7 @@ static void rgb_task_sync(void) {
static void rgb_task_start(void) {
// reset iter
rgb_anim_iter = 0;
rgb_effect_params.iter = 0;
// update double buffers
g_rgb_counters.tick = rgb_counters_buffer;
@ -275,112 +275,112 @@ static void rgb_task_start(void) {
static void rgb_task_render(uint8_t effect) {
bool rendering = false;
bool initialize = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
// each effect can opt to do calculations
// and/or request PWM buffer updates.
switch (effect) {
case RGB_MATRIX_NONE:
rendering = rgb_matrix_none(initialize, rgb_anim_iter);
rendering = rgb_matrix_none(&rgb_effect_params);
break;
case RGB_MATRIX_SOLID_COLOR:
rendering = rgb_matrix_solid_color(initialize, rgb_anim_iter); // Max 1ms Avg 0ms
rendering = rgb_matrix_solid_color(&rgb_effect_params); // Max 1ms Avg 0ms
break;
#ifndef DISABLE_RGB_MATRIX_ALPHAS_MODS
case RGB_MATRIX_ALPHAS_MODS:
rendering = rgb_matrix_alphas_mods(initialize, rgb_anim_iter); // Max 2ms Avg 1ms
rendering = rgb_matrix_alphas_mods(&rgb_effect_params); // Max 2ms Avg 1ms
break;
#endif // DISABLE_RGB_MATRIX_ALPHAS_MODS
#ifndef DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
case RGB_MATRIX_GRADIENT_UP_DOWN:
rendering = rgb_matrix_gradient_up_down(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_gradient_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
#ifndef DISABLE_RGB_MATRIX_BREATHING
case RGB_MATRIX_BREATHING:
rendering = rgb_matrix_breathing(initialize, rgb_anim_iter); // Max 1ms Avg 0ms
rendering = rgb_matrix_breathing(&rgb_effect_params); // Max 1ms Avg 0ms
break;
#endif // DISABLE_RGB_MATRIX_BREATHING
#ifndef DISABLE_RGB_MATRIX_CYCLE_ALL
case RGB_MATRIX_CYCLE_ALL:
rendering = rgb_matrix_cycle_all(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_cycle_all(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_CYCLE_ALL
#ifndef DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
case RGB_MATRIX_CYCLE_LEFT_RIGHT:
rendering = rgb_matrix_cycle_left_right(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_cycle_left_right(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
#ifndef DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
case RGB_MATRIX_CYCLE_UP_DOWN:
rendering = rgb_matrix_cycle_up_down(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_cycle_up_down(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
#ifndef DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
case RGB_MATRIX_RAINBOW_MOVING_CHEVRON:
rendering = rgb_matrix_rainbow_moving_chevron(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_rainbow_moving_chevron(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
#ifndef DISABLE_RGB_MATRIX_DUAL_BEACON
case RGB_MATRIX_DUAL_BEACON:
rendering = rgb_matrix_dual_beacon(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_dual_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_DUAL_BEACON
#ifndef DISABLE_RGB_MATRIX_RAINBOW_BEACON
case RGB_MATRIX_RAINBOW_BEACON:
rendering = rgb_matrix_rainbow_beacon(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_rainbow_beacon(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_RAINBOW_BEACON
#ifndef DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
case RGB_MATRIX_RAINBOW_PINWHEELS:
rendering = rgb_matrix_rainbow_pinwheels(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_rainbow_pinwheels(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
#ifndef DISABLE_RGB_MATRIX_RAINDROPS
case RGB_MATRIX_RAINDROPS:
rendering = rgb_matrix_raindrops(initialize, rgb_anim_iter); // Max 1ms Avg 0ms
rendering = rgb_matrix_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
break;
#endif // DISABLE_RGB_MATRIX_RAINDROPS
#ifndef DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
case RGB_MATRIX_JELLYBEAN_RAINDROPS:
rendering = rgb_matrix_jellybean_raindrops(initialize, rgb_anim_iter); // Max 1ms Avg 0ms
rendering = rgb_matrix_jellybean_raindrops(&rgb_effect_params); // Max 1ms Avg 0ms
break;
#endif // DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
#ifndef DISABLE_RGB_MATRIX_DIGITAL_RAIN
case RGB_MATRIX_DIGITAL_RAIN:
rendering = rgb_matrix_digital_rain(initialize, rgb_anim_iter); // Max 9ms Avg 8ms | this is expensive, fix it
rendering = rgb_matrix_digital_rain(&rgb_effect_params); // Max 9ms Avg 8ms | this is expensive, fix it
break;
#endif // DISABLE_RGB_MATRIX_DIGITAL_RAIN
#if defined(RGB_MATRIX_KEYPRESSES) || defined(RGB_MATRIX_KEYRELEASES)
#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
case RGB_MATRIX_SOLID_REACTIVE_SIMPLE:
rendering = rgb_matrix_solid_reactive_simple(initialize, rgb_anim_iter);// Max 4ms Avg 3ms
rendering = rgb_matrix_solid_reactive_simple(&rgb_effect_params);// Max 4ms Avg 3ms
break;
#endif
#ifndef DISABLE_RGB_MATRIX_SOLID_REACTIVE
case RGB_MATRIX_SOLID_REACTIVE:
rendering = rgb_matrix_solid_reactive(initialize, rgb_anim_iter); // Max 4ms Avg 3ms
rendering = rgb_matrix_solid_reactive(&rgb_effect_params); // Max 4ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_SOLID_REACTIVE
#ifndef DISABLE_RGB_MATRIX_SPLASH
case RGB_MATRIX_SPLASH:
rendering = rgb_matrix_splash(initialize, rgb_anim_iter); // Max 5ms Avg 3ms
rendering = rgb_matrix_splash(&rgb_effect_params); // Max 5ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_SPLASH
#ifndef DISABLE_RGB_MATRIX_MULTISPLASH
case RGB_MATRIX_MULTISPLASH:
rendering = rgb_matrix_multisplash(initialize, rgb_anim_iter); // Max 10ms Avg 5ms
rendering = rgb_matrix_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
break;
#endif // DISABLE_RGB_MATRIX_MULTISPLASH
#ifndef DISABLE_RGB_MATRIX_SOLID_SPLASH
case RGB_MATRIX_SOLID_SPLASH:
rendering = rgb_matrix_solid_splash(initialize, rgb_anim_iter); // Max 5ms Avg 3ms
rendering = rgb_matrix_solid_splash(&rgb_effect_params); // Max 5ms Avg 3ms
break;
#endif // DISABLE_RGB_MATRIX_SOLID_SPLASH
#ifndef DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
case RGB_MATRIX_SOLID_MULTISPLASH:
rendering = rgb_matrix_solid_multisplash(initialize, rgb_anim_iter); // Max 10ms Avg 5ms
rendering = rgb_matrix_solid_multisplash(&rgb_effect_params); // Max 10ms Avg 5ms
break;
#endif // DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
#endif // defined(RGB_MATRIX_KEYPRESSES) || defined(RGB_MATRIX_KEYRELEASES)
@ -393,12 +393,12 @@ static void rgb_task_render(uint8_t effect) {
return;
}
rgb_anim_iter++;
rgb_effect_params.iter++;
// next task
if (!rendering) {
rgb_task_state = FLUSHING;
if (!initialize && effect == RGB_MATRIX_NONE) {
if (!rgb_effect_params.init && effect == RGB_MATRIX_NONE) {
// We only need to flush once if we are RGB_MATRIX_NONE
rgb_task_state = SYNCING;
}

@ -40,7 +40,7 @@
#endif
#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
#define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * iter; \
#define RGB_MATRIX_USE_LIMITS(min, max) uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
if (max > DRIVER_LED_TOTAL) \
max = DRIVER_LED_TOTAL;

@ -5,7 +5,7 @@ extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
// alphas = color1, mods = color2
bool rgb_matrix_alphas_mods(bool init, uint8_t iter) {
bool rgb_matrix_alphas_mods(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -3,7 +3,7 @@
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_breathing(bool init, uint8_t iter) {
bool rgb_matrix_breathing(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
uint16_t time = scale16by8(g_rgb_counters.tick, rgb_matrix_config.speed / 8);

@ -5,7 +5,7 @@ extern rgb_counters_t g_rgb_counters;
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_cycle_all(bool init, uint8_t iter) {
bool rgb_matrix_cycle_all(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -5,7 +5,7 @@ extern rgb_counters_t g_rgb_counters;
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_cycle_left_right(bool init, uint8_t iter) {
bool rgb_matrix_cycle_left_right(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -5,7 +5,7 @@ extern rgb_counters_t g_rgb_counters;
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_cycle_up_down(bool init, uint8_t iter) {
bool rgb_matrix_cycle_up_down(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -6,7 +6,7 @@
#define RGB_DIGITAL_RAIN_DROPS 24
#endif
bool rgb_matrix_digital_rain(bool init, uint8_t iter) {
bool rgb_matrix_digital_rain(effect_params_t* params) {
// algorithm ported from https://github.com/tremby/Kaleidoscope-LEDEffect-DigitalRain
const uint8_t drop_ticks = 28;
const uint8_t pure_green_intensity = 0xd0;
@ -16,7 +16,7 @@ bool rgb_matrix_digital_rain(bool init, uint8_t iter) {
static uint8_t map[MATRIX_COLS][MATRIX_ROWS] = {{0}};
static uint8_t drop = 0;
if (init) {
if (params->init) {
rgb_matrix_set_color_all(0, 0, 0);
memset(map, 0, sizeof map);
drop = 0;

@ -5,7 +5,7 @@ extern rgb_counters_t g_rgb_counters;
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_dual_beacon(bool init, uint8_t iter) {
bool rgb_matrix_dual_beacon(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -4,7 +4,7 @@
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_gradient_up_down(bool init, uint8_t iter) {
bool rgb_matrix_gradient_up_down(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -11,8 +11,8 @@ static void jellybean_raindrops_set_color(int i) {
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
bool rgb_matrix_jellybean_raindrops(bool init, uint8_t iter) {
if (!init) {
bool rgb_matrix_jellybean_raindrops(effect_params_t* params) {
if (!params->init) {
// Change one LED every tick, make sure speed is not 0
if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) {
jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL);

@ -5,7 +5,7 @@ extern rgb_counters_t g_rgb_counters;
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_rainbow_beacon(bool init, uint8_t iter) {
bool rgb_matrix_rainbow_beacon(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -5,7 +5,7 @@ extern rgb_counters_t g_rgb_counters;
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_rainbow_moving_chevron(bool init, uint8_t iter) {
bool rgb_matrix_rainbow_moving_chevron(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -5,7 +5,7 @@ extern rgb_counters_t g_rgb_counters;
extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_rainbow_pinwheels(bool init, uint8_t iter) {
bool rgb_matrix_rainbow_pinwheels(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -21,8 +21,8 @@ static void raindrops_set_color(int i) {
rgb_matrix_set_color(i, rgb.r, rgb.g, rgb.b);
}
bool rgb_matrix_raindrops(bool init, uint8_t iter) {
if (!init) {
bool rgb_matrix_raindrops(effect_params_t* params) {
if (!params->init) {
// Change one LED every tick, make sure speed is not 0
if (scale16by8(g_rgb_counters.tick, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) {
raindrops_set_color(rand() % DRIVER_LED_TOTAL);

@ -2,7 +2,7 @@
extern rgb_config_t rgb_matrix_config;
bool rgb_matrix_solid_color(bool init, uint8_t iter) {
bool rgb_matrix_solid_color(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, rgb_matrix_config.val };

@ -5,7 +5,7 @@
extern rgb_config_t rgb_matrix_config;
extern last_hit_t g_last_hit_tracker;
bool rgb_matrix_solid_reactive(bool init, uint8_t iter) {
bool rgb_matrix_solid_reactive(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { rgb_matrix_config.hue, 255, rgb_matrix_config.val };

@ -5,7 +5,7 @@
extern rgb_config_t rgb_matrix_config;
extern last_hit_t g_last_hit_tracker;
bool rgb_matrix_solid_reactive_simple(bool init, uint8_t iter) {
bool rgb_matrix_solid_reactive_simple(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };

@ -6,7 +6,7 @@ extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
extern last_hit_t g_last_hit_tracker;
static bool rgb_matrix_solid_multisplash_range(uint8_t start, uint8_t iter) {
static bool rgb_matrix_solid_multisplash_range(uint8_t start, effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { rgb_matrix_config.hue, rgb_matrix_config.sat, 0 };
@ -30,12 +30,12 @@ static bool rgb_matrix_solid_multisplash_range(uint8_t start, uint8_t iter) {
return led_max < DRIVER_LED_TOTAL;
}
bool rgb_matrix_solid_multisplash(bool init, uint8_t iter) {
return rgb_matrix_solid_multisplash_range(0, iter);
bool rgb_matrix_solid_multisplash(effect_params_t* params) {
return rgb_matrix_solid_multisplash_range(0, params);
}
bool rgb_matrix_solid_splash(bool init, uint8_t iter) {
return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), iter);
bool rgb_matrix_solid_splash(effect_params_t* params) {
return rgb_matrix_solid_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params);
}
#endif // !defined(DISABLE_RGB_MATRIX_SPLASH) && !defined(DISABLE_RGB_MATRIX_MULTISPLASH)

@ -6,7 +6,7 @@ extern const rgb_led g_rgb_leds[DRIVER_LED_TOTAL];
extern rgb_config_t rgb_matrix_config;
extern last_hit_t g_last_hit_tracker;
static bool rgb_matrix_multisplash_range(uint8_t start, uint8_t iter) {
static bool rgb_matrix_multisplash_range(uint8_t start, effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
HSV hsv = { 0, rgb_matrix_config.sat, 0 };
@ -32,12 +32,12 @@ static bool rgb_matrix_multisplash_range(uint8_t start, uint8_t iter) {
return led_max < DRIVER_LED_TOTAL;
}
bool rgb_matrix_multisplash(bool init, uint8_t iter) {
return rgb_matrix_multisplash_range(0, iter);
bool rgb_matrix_multisplash(effect_params_t* params) {
return rgb_matrix_multisplash_range(0, params);
}
bool rgb_matrix_splash(bool init, uint8_t iter) {
return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), iter);
bool rgb_matrix_splash(effect_params_t* params) {
return rgb_matrix_multisplash_range(qsub8(g_last_hit_tracker.count, 1), params);
}
#endif // !defined(DISABLE_RGB_MATRIX_SPLASH) || !defined(DISABLE_RGB_MATRIX_MULTISPLASH)

@ -35,6 +35,14 @@ typedef enum rgb_task_states {
SYNCING
} rgb_task_states;
typedef uint8_t led_flags_t;
typedef struct PACKED {
uint8_t iter;
led_flags_t flags;
bool init;
} effect_params_t;
typedef struct PACKED {
// Global tick at 20 Hz
uint32_t tick;
@ -61,16 +69,6 @@ typedef struct PACKED {
uint8_t modifier:1;
} rgb_led;
/*typedef union {
uint32_t raw; // 32 bits
struct {
bool enable :1; // 1 bit
uint8_t mode :7; // 7 bits
HSV hsv; // 24 bits
uint8_t speed; // 8 bits
}; // 40 bits =(
} rgb_config_t;*/
typedef union {
uint32_t raw;
struct PACKED {

Loading…
Cancel
Save