Add auto-sleep/wake functionality with timer-based dimming

- Added PWM brightness control to ST7796 driver (0-100%)
- Implemented hardware sleep mode for ST7796 (saves ~150mA)
- Added sleep/wake functions preserving framebuffer and settings
- Implemented timer-based inactivity detection (checks every 10s)
- Auto-sleep after 5 minutes of no user input
- Touch controller remains active during TFT sleep for instant wake
- E-ink display also sleeps after timeout, requires re-init on wake
- Added hardware_pwm library dependency to CMakeLists.txt
- Brightness and sleep/wake methods exposed through display abstraction layer
This commit is contained in:
Adolfo Reyna
2026-02-10 20:29:10 -05:00
parent b16211f148
commit 8cbb95b181
7 changed files with 384 additions and 7 deletions

View File

@@ -357,6 +357,93 @@ void st7796_draw_triangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, ui
*/
void st7796_fill_triangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
/**
* @brief Set display brightness using PWM on backlight pin
*
* Controls the backlight LED brightness using hardware PWM. The brightness
* is specified as a percentage (0-100), where:
* - 0 = Backlight completely off (minimum brightness)
* - 100 = Backlight fully on (maximum brightness)
* - Values in between = Proportional PWM duty cycle
*
* PWM Configuration:
* - Frequency: 1000 Hz (1 kHz) - high enough to avoid flicker
* - Resolution: 16-bit (0-65535 range internally)
* - Smooth transitions without visible flickering
*
* Use cases:
* - Power saving: Reduce brightness when idle
* - Auto-dimming: Lower brightness after timeout
* - Manual control: User brightness preferences
* - Night mode: Very low brightness for dark environments
*
* @param brightness Brightness level (0-100 percent)
* 0 = off, 100 = full brightness
*
* Performance: Instant - PWM is handled by hardware
*
* Note: Must be called after st7796_init() which configures the backlight pin
*/
void st7796_set_brightness(uint8_t brightness);
/**
* @brief Get current display brightness level
*
* Returns the currently configured brightness level as a percentage (0-100).
* This reflects the last value set by st7796_set_brightness() or the
* default value (100) if brightness was never explicitly set.
*
* @return Current brightness level (0-100 percent)
*/
uint8_t st7796_get_brightness(void);
/**
* @brief Put display into sleep mode (low power)
*
* Enters sleep mode to save power while keeping the controller initialized.
* In sleep mode:
* - Display is turned off (blank screen)
* - Internal oscillator is stopped
* - Framebuffer contents are preserved
* - Backlight is turned off (PWM set to 0)
* - Power consumption is minimized (~10μA typical)
*
* Touch controller remains active and functional since it's on a separate
* I2C bus. Touch interrupts can wake the system from sleep.
*
* Use st7796_wake() to exit sleep mode and restore display.
*
* Commands sent:
* - DISPOFF (0x28): Turn off display
* - SLPIN (0x10): Enter sleep mode
* - Backlight PWM set to 0
*
* Performance: ~120ms to enter sleep mode
*/
void st7796_sleep(void);
/**
* @brief Wake display from sleep mode
*
* Exits sleep mode and restores display to normal operation.
* After waking:
* - Internal oscillator restarts
* - Display controller becomes active
* - Framebuffer contents are preserved
* - Display is turned on
* - Backlight is restored to previous brightness
*
* Commands sent:
* - SLPOUT (0x11): Exit sleep mode
* - DISPON (0x29): Turn on display
* - Backlight PWM restored to saved level
*
* Performance: ~120ms to fully wake up
*
* Note: Must call st7796_init() before first use of sleep/wake
*/
void st7796_wake(void);
#ifdef __cplusplus
}
#endif