aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol
diff options
context:
space:
mode:
authorIan O'Dea <ianodea@gmail.com>2018-12-06 10:58:58 -0600
committerDrashna Jaelre <drashna@live.com>2018-12-06 08:58:58 -0800
commit21bc230dfdc29a03d6cf08b9c0ac438eadd3bf42 (patch)
treeca3db2a8cf13e20a354601dae722f7e50d605fbd /tmk_core/protocol
parent42c9fd262585c9ba46a726604d60eb6c42b3cda7 (diff)
downloadqmk_firmware-21bc230dfdc29a03d6cf08b9c0ac438eadd3bf42.tar.gz
qmk_firmware-21bc230dfdc29a03d6cf08b9c0ac438eadd3bf42.zip
Vertical animation support for arm_atsam led_matrix (#4538)
* Add initial support for vertically-oriented animations * DRY up vertical animation support * Fix animation code for arm_atsam led_matrix to work in all directions * Adjust py calculation to base off bottom rather than top
Diffstat (limited to 'tmk_core/protocol')
-rw-r--r--tmk_core/protocol/arm_atsam/led_matrix.c73
-rw-r--r--tmk_core/protocol/arm_atsam/led_matrix.h1
2 files changed, 43 insertions, 31 deletions
diff --git a/tmk_core/protocol/arm_atsam/led_matrix.c b/tmk_core/protocol/arm_atsam/led_matrix.c
index c328fdc4c..729e042a6 100644
--- a/tmk_core/protocol/arm_atsam/led_matrix.c
+++ b/tmk_core/protocol/arm_atsam/led_matrix.c
@@ -226,7 +226,7 @@ void disp_pixel_setup(void)
226 while (cur < lede) 226 while (cur < lede)
227 { 227 {
228 cur->px = (cur->x - disp.left) / disp.width * 100; 228 cur->px = (cur->x - disp.left) / disp.width * 100;
229 cur->py = (cur->y - disp.top) / disp.height * 100; 229 cur->py = (cur->y - disp.bottom) / disp.height * 100;
230 *cur->rgb.r = 0; 230 *cur->rgb.r = 0;
231 *cur->rgb.g = 0; 231 *cur->rgb.g = 0;
232 *cur->rgb.b = 0; 232 *cur->rgb.b = 0;
@@ -244,6 +244,7 @@ void led_matrix_prepare(void)
244uint8_t led_enabled; 244uint8_t led_enabled;
245float led_animation_speed; 245float led_animation_speed;
246uint8_t led_animation_direction; 246uint8_t led_animation_direction;
247uint8_t led_animation_orientation;
247uint8_t led_animation_breathing; 248uint8_t led_animation_breathing;
248uint8_t led_animation_breathe_cur; 249uint8_t led_animation_breathe_cur;
249uint8_t breathe_step; 250uint8_t breathe_step;
@@ -263,7 +264,7 @@ void led_matrix_run(void)
263 float ro; 264 float ro;
264 float go; 265 float go;
265 float bo; 266 float bo;
266 float px; 267 float po;
267 uint8_t led_this_run = 0; 268 uint8_t led_this_run = 0;
268 led_setup_t *f = (led_setup_t*)led_setups[led_animation_id]; 269 led_setup_t *f = (led_setup_t*)led_setups[led_animation_id];
269 270
@@ -325,59 +326,68 @@ void led_matrix_run(void)
325 //Act on LED 326 //Act on LED
326 for (fcur = 0; fcur < fmax; fcur++) 327 for (fcur = 0; fcur < fmax; fcur++)
327 { 328 {
328 px = led_cur->px; 329
329 float pxmod; 330 if (led_animation_orientation)
330 pxmod = (float)(disp.frame % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed; 331 {
332 po = led_cur->py;
333 }
334 else
335 {
336 po = led_cur->px;
337 }
338
339 float pomod;
340 pomod = (float)(disp.frame % (uint32_t)(1000.0f / led_animation_speed)) / 10.0f * led_animation_speed;
331 341
332 //Add in any moving effects 342 //Add in any moving effects
333 if ((!led_animation_direction && f[fcur].ef & EF_SCR_R) || (led_animation_direction && (f[fcur].ef & EF_SCR_L))) 343 if ((!led_animation_direction && f[fcur].ef & EF_SCR_R) || (led_animation_direction && (f[fcur].ef & EF_SCR_L)))
334 { 344 {
335 pxmod *= 100.0f; 345 pomod *= 100.0f;
336 pxmod = (uint32_t)pxmod % 10000; 346 pomod = (uint32_t)pomod % 10000;
337 pxmod /= 100.0f; 347 pomod /= 100.0f;
338 348
339 px -= pxmod; 349 po -= pomod;
340 350
341 if (px > 100) px -= 100; 351 if (po > 100) po -= 100;
342 else if (px < 0) px += 100; 352 else if (po < 0) po += 100;
343 } 353 }
344 else if ((!led_animation_direction && f[fcur].ef & EF_SCR_L) || (led_animation_direction && (f[fcur].ef & EF_SCR_R))) 354 else if ((!led_animation_direction && f[fcur].ef & EF_SCR_L) || (led_animation_direction && (f[fcur].ef & EF_SCR_R)))
345 { 355 {
346 pxmod *= 100.0f; 356 pomod *= 100.0f;
347 pxmod = (uint32_t)pxmod % 10000; 357 pomod = (uint32_t)pomod % 10000;
348 pxmod /= 100.0f; 358 pomod /= 100.0f;
349 px += pxmod; 359 po += pomod;
350 360
351 if (px > 100) px -= 100; 361 if (po > 100) po -= 100;
352 else if (px < 0) px += 100; 362 else if (po < 0) po += 100;
353 } 363 }
354 364
355 //Check if LED's px is in current frame 365 //Check if LED's po is in current frame
356 if (px < f[fcur].hs) continue; 366 if (po < f[fcur].hs) continue;
357 if (px > f[fcur].he) continue; 367 if (po > f[fcur].he) continue;
358 //note: < 0 or > 100 continue 368 //note: < 0 or > 100 continue
359 369
360 //Calculate the px within the start-stop percentage for color blending 370 //Calculate the po within the start-stop percentage for color blending
361 px = (px - f[fcur].hs) / (f[fcur].he - f[fcur].hs); 371 po = (po - f[fcur].hs) / (f[fcur].he - f[fcur].hs);
362 372
363 //Add in any color effects 373 //Add in any color effects
364 if (f[fcur].ef & EF_OVER) 374 if (f[fcur].ef & EF_OVER)
365 { 375 {
366 ro = (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5; 376 ro = (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
367 go = (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5; 377 go = (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
368 bo = (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5; 378 bo = (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
369 } 379 }
370 else if (f[fcur].ef & EF_SUBTRACT) 380 else if (f[fcur].ef & EF_SUBTRACT)
371 { 381 {
372 ro -= (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5; 382 ro -= (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
373 go -= (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5; 383 go -= (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
374 bo -= (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5; 384 bo -= (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
375 } 385 }
376 else 386 else
377 { 387 {
378 ro += (px * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5; 388 ro += (po * (f[fcur].re - f[fcur].rs)) + f[fcur].rs;// + 0.5;
379 go += (px * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5; 389 go += (po * (f[fcur].ge - f[fcur].gs)) + f[fcur].gs;// + 0.5;
380 bo += (px * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5; 390 bo += (po * (f[fcur].be - f[fcur].bs)) + f[fcur].bs;// + 0.5;
381 } 391 }
382 } 392 }
383 } 393 }
@@ -451,6 +461,7 @@ uint8_t led_matrix_init(void)
451 led_lighting_mode = LED_MODE_NORMAL; 461 led_lighting_mode = LED_MODE_NORMAL;
452 led_animation_speed = 4.0f; 462 led_animation_speed = 4.0f;
453 led_animation_direction = 0; 463 led_animation_direction = 0;
464 led_animation_orientation = 0;
454 led_animation_breathing = 0; 465 led_animation_breathing = 0;
455 led_animation_breathe_cur = BREATHE_MIN_STEP; 466 led_animation_breathe_cur = BREATHE_MIN_STEP;
456 breathe_step = 1; 467 breathe_step = 1;
diff --git a/tmk_core/protocol/arm_atsam/led_matrix.h b/tmk_core/protocol/arm_atsam/led_matrix.h
index 3f2b9cdb8..cedea8a85 100644
--- a/tmk_core/protocol/arm_atsam/led_matrix.h
+++ b/tmk_core/protocol/arm_atsam/led_matrix.h
@@ -125,6 +125,7 @@ extern uint8_t led_enabled;
125extern float led_animation_speed; 125extern float led_animation_speed;
126extern uint8_t led_lighting_mode; 126extern uint8_t led_lighting_mode;
127extern uint8_t led_animation_direction; 127extern uint8_t led_animation_direction;
128extern uint8_t led_animation_orientation;
128extern uint8_t led_animation_breathing; 129extern uint8_t led_animation_breathing;
129extern uint8_t led_animation_breathe_cur; 130extern uint8_t led_animation_breathe_cur;
130extern uint8_t breathe_dir; 131extern uint8_t breathe_dir;