src.nth.io/

summaryrefslogtreecommitdiff
path: root/main/display.c
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2026-07-17 18:56:03 -0500
committerLuke Hoersten <[email protected]>2026-07-17 18:56:03 -0500
commit9d94f710f7b00d109bf6f6ee57996f43bce5c67f (patch)
treeb86320353884536d2d1b342efa27600b19c845de /main/display.c
parent866015678918560a0d0519be8a2549e4fc23b2cd (diff)
main: code-review fixes — brightness units, OTA stall cap, stats + locking
- display: s_last_pwm cached the raw 0-100 percentage at init but display_wake writes it straight to REG_PWM (0-255 duty) — first wake ran visibly dim until a /config brightness change. Shared pct_to_duty helper now converts in both paths. - http_api: cap consecutive OTA recv timeouts (a stalled client spun forever holding s_ota_in_progress, wedging OTA until reboot); cap viewport name at 54 chars so viewport-<name> fits the 63-byte mDNS label; log mdns_service_refresh failures; /state builds JSON from a snapshot instead of holding the state lock across ~25 cJSON allocs; respond_400 delegates to respond_status. - stream_server: bytes_in_window now counts painted frames only (frames discarded while asleep inflated the first post-wake window's MB/s, avg-jpeg and chunk/wire averages; recv_bytes folded in); so_rcvbuf carried into the stats snapshot under the mux; drop dead HEADER_BYTES; merge read_body_instrumented into read_n. - state_machine: transition mutex serializes concurrent wake/sleep (display side-effects ran after the state lock dropped, so racing callers could leave the backlight contradicting st->state); wake-path placeholder paint now takes the decoder lock like the stream path (concurrent esp_lcd_panel_draw_bitmap from two tasks isn't safe). - local_screens: overlay paint takes the decoder lock too; check the overlay timer create; panel dims from viewport_state.h. - jpeg_decoder: try_lock before init returns busy instead of passing a NULL semaphore to xSemaphoreTake. - net_eth: clear cached IP string on link down (stale /state + info). - dead code: display_present_bgr888, TOUCH_FT5426_ADDR, touch s_task, JPEG_DECODER_MAX_OUTPUT_BYTES; doc drift in nvs_config.h / jpeg_decoder.h / app_main flag legend.
Diffstat (limited to 'main/display.c')
-rw-r--r--main/display.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/main/display.c b/main/display.c
index 7441200..8b86812 100644
--- a/main/display.c
+++ b/main/display.c
@@ -32,7 +32,6 @@ static const char *TAG = "display";
#define I2C_FREQ_HZ 400000
#define PANEL_MCU_ADDR 0x45 // ATTINY88 on the Pi 7" panel architecture
-#define TOUCH_FT5426_ADDR 0x38
// ATTINY88 register map. Source:
// linux/drivers/regulator/rpi-panel-attiny-regulator.c (rpi-6.6.y)
@@ -63,8 +62,8 @@ enum {
// ESP32-P4. The Linux upstream modeline differs in HFP/VSW; if pixels look
// shifted left/right these are the first knobs to revisit.
// ============================================================================
-#define PANEL_H_ACTIVE 800
-#define PANEL_V_ACTIVE 480
+#define PANEL_H_ACTIVE VIEWPORT_PANEL_WIDTH
+#define PANEL_V_ACTIVE VIEWPORT_PANEL_HEIGHT
#define RPI_HSW 2
#define RPI_HBP 46
#define RPI_HFP 210
@@ -428,6 +427,18 @@ static esp_err_t dsi_bring_up(void)
// ============================================================================
// Public API
// ============================================================================
+
+// 0-100 user percentage → gamma-corrected 0-255 PWM duty. s_last_pwm
+// always holds a DUTY, never a raw percentage — display_wake() writes it
+// straight to REG_PWM.
+static uint8_t pct_to_duty(uint8_t pct)
+{
+ if (pct > 100) pct = 100;
+ float frac = (float)pct / 100.0f;
+ float gamma = powf(frac, 2.2f);
+ return (uint8_t)(gamma * 255.0f + 0.5f);
+}
+
esp_err_t display_init(void)
{
if (s_up) return ESP_OK;
@@ -448,8 +459,9 @@ esp_err_t display_init(void)
// Cache configured brightness, leave backlight off — first wake applies it.
viewport_state_lock();
- s_last_pwm = viewport_state_get()->brightness;
+ uint8_t pct = viewport_state_get()->brightness;
viewport_state_unlock();
+ s_last_pwm = pct_to_duty(pct);
mcu_write_u8(REG_PWM, 0);
return ESP_OK;
@@ -461,10 +473,7 @@ i2c_master_bus_handle_t display_i2c_bus(void) { return s_i2c_bus; }
esp_err_t display_set_brightness(uint8_t pct)
{
- if (pct > 100) pct = 100;
- float frac = (float)pct / 100.0f;
- float gamma = powf(frac, 2.2f);
- uint8_t duty = (uint8_t)(gamma * 255.0f + 0.5f);
+ uint8_t duty = pct_to_duty(pct);
s_last_pwm = duty;
if (!s_up) return ESP_ERR_INVALID_STATE;
@@ -497,14 +506,6 @@ static inline void rgb565_to_rgb888(uint16_t px, uint8_t *out)
out[2] = (uint8_t)(((px >> 11) & 0x1F) * 255 / 31); // R
}
-esp_err_t display_present_bgr888(const void *bgr888)
-{
- if (!s_up) return ESP_ERR_INVALID_STATE;
- return esp_lcd_panel_draw_bitmap(s_panel, 0, 0,
- PANEL_H_ACTIVE, PANEL_V_ACTIVE,
- bgr888);
-}
-
void *display_back_buffer(size_t *out_size)
{
if (!s_up) return NULL;