mirror of
https://github.com/esphome/esphome.git
synced 2026-03-04 03:38:20 -07:00
Replace runtime powf() calls in light gamma correction with pre-computed uint16[256] PROGMEM lookup tables generated at Python codegen time. The gamma value is a compile-time constant, so the tables can be computed once and shared across all lights with the same gamma value. This eliminates powf/ieee754_powf (~2.3KB) from the binary. Two 512-byte PROGMEM tables (forward + reverse) are shared per unique gamma value, for a net savings of ~1.3KB flash and zero RAM impact. The LUT uses linear interpolation between table entries, achieving zero PWM errors at both 8-bit and 16-bit resolution compared to the old powf-based approach. Breaking change: gamma parameter removed from LightColorValues::as_*() methods since gamma correction is now applied externally via LightState::gamma_correct_lut(). gamma_correct() and gamma_uncorrect() in helpers.h are deprecated (removal in 2026.12.0).
47 lines
897 B
C++
47 lines
897 B
C++
#pragma once
|
|
#include <string>
|
|
#include <cstdint>
|
|
#include "gpio.h"
|
|
|
|
#if defined(USE_ESP32)
|
|
#include <esp_attr.h>
|
|
#ifndef PROGMEM
|
|
#define PROGMEM
|
|
#endif
|
|
|
|
#elif defined(USE_ESP8266)
|
|
|
|
#include <c_types.h>
|
|
#ifndef PROGMEM
|
|
#define PROGMEM ICACHE_RODATA_ATTR
|
|
#endif
|
|
|
|
#elif defined(USE_RP2040)
|
|
|
|
#define IRAM_ATTR __attribute__((noinline, long_call, section(".time_critical")))
|
|
#define PROGMEM
|
|
|
|
#else
|
|
|
|
#define IRAM_ATTR
|
|
#define PROGMEM
|
|
|
|
#endif
|
|
|
|
namespace esphome {
|
|
|
|
void yield();
|
|
uint32_t millis();
|
|
uint32_t micros();
|
|
void delay(uint32_t ms);
|
|
void delayMicroseconds(uint32_t us); // NOLINT(readability-identifier-naming)
|
|
void __attribute__((noreturn)) arch_restart();
|
|
void arch_init();
|
|
void arch_feed_wdt();
|
|
uint32_t arch_get_cpu_cycle_count();
|
|
uint32_t arch_get_cpu_freq_hz();
|
|
uint8_t progmem_read_byte(const uint8_t *addr);
|
|
uint16_t progmem_read_uint16(const uint16_t *addr);
|
|
|
|
} // namespace esphome
|