fan: Use u8 for array access

The index will never be negative and will never exceed 255. Change them
from i16 to u8 so SDCC will generate more efficient code.

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford
2021-08-02 11:56:47 -06:00
committed by Jeremy Soller
parent 99af8a35f5
commit 784202383e

View File

@ -26,7 +26,7 @@ void fan_reset(void) {
// Get duty cycle based on temperature, adapted from // Get duty cycle based on temperature, adapted from
// https://github.com/pop-os/system76-power/blob/master/src/fan.rs // https://github.com/pop-os/system76-power/blob/master/src/fan.rs
uint8_t fan_duty(const struct Fan * fan, int16_t temp) __reentrant { uint8_t fan_duty(const struct Fan * fan, int16_t temp) __reentrant {
for (int16_t i = 0; i < fan->points_size; i++) { for (uint8_t i = 0; i < fan->points_size; i++) {
const struct FanPoint * cur = &fan->points[i]; const struct FanPoint * cur = &fan->points[i];
// If exactly the current temp, return the current duty // If exactly the current temp, return the current duty
@ -86,7 +86,7 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant {
uint8_t fan_heatup(const struct Fan * fan, uint8_t duty) __reentrant { uint8_t fan_heatup(const struct Fan * fan, uint8_t duty) __reentrant {
uint8_t lowest = duty; uint8_t lowest = duty;
int16_t i; uint8_t i;
for (i = 0; (i + 1) < fan->heatup_size; i++) { for (i = 0; (i + 1) < fan->heatup_size; i++) {
uint8_t value = fan->heatup[i + 1]; uint8_t value = fan->heatup[i + 1];
if (value < lowest) { if (value < lowest) {
@ -102,7 +102,7 @@ uint8_t fan_heatup(const struct Fan * fan, uint8_t duty) __reentrant {
uint8_t fan_cooldown(const struct Fan * fan, uint8_t duty) __reentrant { uint8_t fan_cooldown(const struct Fan * fan, uint8_t duty) __reentrant {
uint8_t highest = duty; uint8_t highest = duty;
int16_t i; uint8_t i;
for (i = 0; (i + 1) < fan->cooldown_size; i++) { for (i = 0; (i + 1) < fan->cooldown_size; i++) {
uint8_t value = fan->cooldown[i + 1]; uint8_t value = fan->cooldown[i + 1];
if (value > highest) { if (value > highest) {