diff options
author | QMK Bot <hello@qmk.fm> | 2021-11-29 15:08:12 +0000 |
---|---|---|
committer | QMK Bot <hello@qmk.fm> | 2021-11-29 15:08:12 +0000 |
commit | 5ebeb32ec09e0c4ad4221a88bb21e79619f2091e (patch) | |
tree | c0b59f9a23093b71df618263afd60972345310b1 /quantum | |
parent | bee48ced71c97a712e3758d69836ebe4b81b112c (diff) | |
parent | 84b8cdc1a43245d24b232bc8e28cca7f1183d676 (diff) |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/backlight/backlight_avr.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c index 67b551dc3c..9c972ae02e 100644 --- a/quantum/backlight/backlight_avr.c +++ b/quantum/backlight/backlight_avr.c @@ -232,19 +232,19 @@ ISR(TIMERx_OVF_vect) { // See http://jared.geek.nz/2013/feb/linear-led-pwm static uint16_t cie_lightness(uint16_t v) { - if (v <= ICRx / 12) // If the value is less than or equal to ~8% of max + if (v <= (uint32_t)ICRx / 12) // If the value is less than or equal to ~8% of max { return v / 9; // Same as dividing by 900% } else { // In the next two lines values are bit-shifted. This is to avoid loosing decimals in integer math. - uint32_t y = (((uint32_t)v + ICRx / 6) << 5) / (ICRx / 6 + ICRx); // If above 8%, add ~16% of max, and normalize with (max + ~16% max) - uint32_t out = (y * y * y * ICRx) >> 15; // Cube it and undo the bit-shifting. (which is now three times as much due to the cubing) + uint32_t y = (((uint32_t)v + (uint32_t)ICRx / 6) << 5) / ((uint32_t)ICRx / 6 + ICRx); // If above 8%, add ~16% of max, and normalize with (max + ~16% max) + uint32_t out = (y * y * y * ICRx) >> 15; // Cube it and undo the bit-shifting. (which is now three times as much due to the cubing) if (out > ICRx) // Avoid overflows { out = ICRx; } - return out; + return (uint16_t)out; } } |