From 3abb9bbbe471d3b3d3045235caf27cfb04dddd03 Mon Sep 17 00:00:00 2001 From: Karl Shea Date: Sun, 28 Nov 2021 15:15:16 -0600 Subject: [PATCH] Use the right types --- quantum/backlight/backlight_avr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantum/backlight/backlight_avr.c b/quantum/backlight/backlight_avr.c index e1de11d8cdf..9f80da271ed 100644 --- a/quantum/backlight/backlight_avr.c +++ b/quantum/backlight/backlight_avr.c @@ -232,12 +232,12 @@ ISR(TIMERx_OVF_vect) { // See http://jared.geek.nz/2013/feb/linear-led-pwm static uint16_t cie_lightness(uint16_t v) { - if (v <= (unsigned long)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 + (unsigned long)ICRx / 6) << 5) / ((unsigned long)ICRx / 6 + ICRx); // If above 8%, add ~16% of max, and normalize with (max + ~16% max) + 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