aboutsummaryrefslogtreecommitdiff
path: root/quantum/backlight/backlight_avr.c
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2020-01-13 01:30:56 +0000
committerGitHub <noreply@github.com>2020-01-13 01:30:56 +0000
commitb89e35bdd33b3953711de8b0be64c76b64e9701b (patch)
treea597dafbaf6dfe50f94a70eade9954d78b84acd6 /quantum/backlight/backlight_avr.c
parent2ce3025be2fd28c7ea3f2fd33c7aba7277ff668b (diff)
downloadqmk_firmware-b89e35bdd33b3953711de8b0be64c76b64e9701b.tar.gz
qmk_firmware-b89e35bdd33b3953711de8b0be64c76b64e9701b.zip
Relocate common backlight functionally (#7273)
Diffstat (limited to 'quantum/backlight/backlight_avr.c')
-rw-r--r--quantum/backlight/backlight_avr.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c
index edda6ea0b..7cf1e0fb3 100644
--- a/quantum/backlight/backlight_avr.c
+++ b/quantum/backlight/backlight_avr.c
@@ -206,7 +206,7 @@ static const pin_t backlight_pin = BACKLIGHT_PIN;
206# endif 206# endif
207 207
208# ifdef NO_HARDWARE_PWM 208# ifdef NO_HARDWARE_PWM
209__attribute__((weak)) void backlight_init_ports(void) { 209void backlight_init_ports(void) {
210 // Setup backlight pin as output and output to on state. 210 // Setup backlight pin as output and output to on state.
211 FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) 211 FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);)
212 212
@@ -217,8 +217,6 @@ __attribute__((weak)) void backlight_init_ports(void) {
217# endif 217# endif
218} 218}
219 219
220__attribute__((weak)) void backlight_set(uint8_t level) {}
221
222uint8_t backlight_tick = 0; 220uint8_t backlight_tick = 0;
223 221
224# ifndef BACKLIGHT_CUSTOM_DRIVER 222# ifndef BACKLIGHT_CUSTOM_DRIVER
@@ -303,7 +301,7 @@ static uint16_t cie_lightness(uint16_t v) {
303static inline void set_pwm(uint16_t val) { OCRxx = val; } 301static inline void set_pwm(uint16_t val) { OCRxx = val; }
304 302
305# ifndef BACKLIGHT_CUSTOM_DRIVER 303# ifndef BACKLIGHT_CUSTOM_DRIVER
306__attribute__((weak)) void backlight_set(uint8_t level) { 304void backlight_set(uint8_t level) {
307 if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS; 305 if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS;
308 306
309 if (level == 0) { 307 if (level == 0) {
@@ -342,7 +340,6 @@ void backlight_task(void) {}
342# define BREATHING_HALT_ON 2 340# define BREATHING_HALT_ON 2
343# define BREATHING_STEPS 128 341# define BREATHING_STEPS 128
344 342
345static uint8_t breathing_period = BREATHING_PERIOD;
346static uint8_t breathing_halt = BREATHING_NO_HALT; 343static uint8_t breathing_halt = BREATHING_NO_HALT;
347static uint16_t breathing_counter = 0; 344static uint16_t breathing_counter = 0;
348 345
@@ -377,9 +374,9 @@ bool is_breathing(void) { return !!(TIMSKx & _BV(TOIEx)); }
377 do { \ 374 do { \
378 breathing_counter = 0; \ 375 breathing_counter = 0; \
379 } while (0) 376 } while (0)
380# define breathing_max() \ 377# define breathing_max() \
381 do { \ 378 do { \
382 breathing_counter = breathing_period * 244 / 2; \ 379 breathing_counter = get_breathing_period() * 244 / 2; \
383 } while (0) 380 } while (0)
384 381
385void breathing_enable(void) { 382void breathing_enable(void) {
@@ -417,17 +414,6 @@ void breathing_toggle(void) {
417 breathing_enable(); 414 breathing_enable();
418} 415}
419 416
420void breathing_period_set(uint8_t value) {
421 if (!value) value = 1;
422 breathing_period = value;
423}
424
425void breathing_period_default(void) { breathing_period_set(BREATHING_PERIOD); }
426
427void breathing_period_inc(void) { breathing_period_set(breathing_period + 1); }
428
429void breathing_period_dec(void) { breathing_period_set(breathing_period - 1); }
430
431/* To generate breathing curve in python: 417/* To generate breathing curve in python:
432 * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)] 418 * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
433 */ 419 */
@@ -445,6 +431,7 @@ void breathing_task(void)
445ISR(TIMERx_OVF_vect) 431ISR(TIMERx_OVF_vect)
446# endif 432# endif
447{ 433{
434 uint8_t breathing_period = get_breathing_period();
448 uint16_t interval = (uint16_t)breathing_period * 244 / BREATHING_STEPS; 435 uint16_t interval = (uint16_t)breathing_period * 244 / BREATHING_STEPS;
449 // resetting after one period to prevent ugly reset at overflow. 436 // resetting after one period to prevent ugly reset at overflow.
450 breathing_counter = (breathing_counter + 1) % (breathing_period * 244); 437 breathing_counter = (breathing_counter + 1) % (breathing_period * 244);
@@ -459,7 +446,7 @@ ISR(TIMERx_OVF_vect)
459 446
460# endif // BACKLIGHT_BREATHING 447# endif // BACKLIGHT_BREATHING
461 448
462__attribute__((weak)) void backlight_init_ports(void) { 449void backlight_init_ports(void) {
463 // Setup backlight pin as output and output to on state. 450 // Setup backlight pin as output and output to on state.
464 FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);) 451 FOR_EACH_LED(setPinOutput(backlight_pin); backlight_on(backlight_pin);)
465 452
@@ -500,10 +487,4 @@ __attribute__((weak)) void backlight_init_ports(void) {
500 487
501# endif // hardware backlight 488# endif // hardware backlight
502 489
503#else // no backlight 490#endif // backlight
504
505__attribute__((weak)) void backlight_init_ports(void) {}
506
507__attribute__((weak)) void backlight_set(uint8_t level) {}
508
509#endif // backlight \ No newline at end of file