| 
 | 1 | +#pragma once  | 
 | 2 | +#include <stdint.h>  | 
 | 3 | + | 
 | 4 | +// Settings protocol values (shared with I2C register interface in rw_i2c_emu.c)  | 
 | 5 | + | 
 | 6 | +// Auto power-off options while in sleep/idle  | 
 | 7 | +// Index mapping per spec: 0=Off, 1=15s, 2=30s, 3=1min, 4=5min, 5=10min, 6=30min, 7=60min  | 
 | 8 | +typedef enum {  | 
 | 9 | +  APOFF_OFF = 0,  | 
 | 10 | +  APOFF_15S = 1,  | 
 | 11 | +  APOFF_30S = 2,  | 
 | 12 | +  APOFF_1M  = 3,  | 
 | 13 | +  APOFF_5M  = 4,  | 
 | 14 | +  APOFF_10M = 5,  | 
 | 15 | +  APOFF_30M = 6,  | 
 | 16 | +  APOFF_60M = 7,  | 
 | 17 | +} kiisu_apoff_t;  | 
 | 18 | + | 
 | 19 | +// Startup LED color options  | 
 | 20 | +// 0=Purple (default), 1=Off, 2=Red, 3=Green, 4=Blue, 5=Yellow, 6=Cyan, 7=Magenta, 8=White  | 
 | 21 | +typedef enum {  | 
 | 22 | +  SC_PURPLE = 0,  | 
 | 23 | +  SC_OFF    = 1,  | 
 | 24 | +  SC_RED    = 2,  | 
 | 25 | +  SC_GREEN  = 3,  | 
 | 26 | +  SC_BLUE   = 4,  | 
 | 27 | +  SC_YELLOW = 5,  | 
 | 28 | +  SC_CYAN   = 6,  | 
 | 29 | +  SC_MAGENTA= 7,  | 
 | 30 | +  SC_WHITE  = 8,  | 
 | 31 | +} kiisu_start_color_t;  | 
 | 32 | + | 
 | 33 | +// Initialize defaults  | 
 | 34 | +void settings_init(void);  | 
 | 35 | + | 
 | 36 | +// Setters (invoked by I2C emu on register writes)  | 
 | 37 | +void settings_set_led_brightness_percent(uint8_t pct_or_0_auto, uint32_t now_ms);  | 
 | 38 | +void settings_set_auto_poweroff(kiisu_apoff_t v);  | 
 | 39 | +void settings_set_startup_color(kiisu_start_color_t v, uint32_t now_ms);  | 
 | 40 | +void settings_set_charge_rainbow(uint8_t on, uint32_t now_ms);  | 
 | 41 | + | 
 | 42 | +// Getters for application logic  | 
 | 43 | +uint8_t settings_is_led_brightness_auto(void);  | 
 | 44 | +// Return 0..255 backlight-equivalent for LED PWM; if auto, returns provided backlight  | 
 | 45 | +uint8_t settings_led_brightness_base255(uint8_t current_backlight);  | 
 | 46 | +// Map APOFF index to milliseconds (0 means disabled)  | 
 | 47 | +uint32_t settings_get_auto_poweroff_ms(void);  | 
 | 48 | +// Decode startup color to R,G,B enable flags (active-low LED pins are handled elsewhere)  | 
 | 49 | +void settings_get_startup_color_bits(uint8_t* r, uint8_t* g, uint8_t* b);  | 
 | 50 | +uint8_t settings_get_charge_rainbow_enabled(void);  | 
 | 51 | + | 
 | 52 | +// Preview helpers (one-shot windows set by setters). The main loop may use these  | 
 | 53 | +// to temporarily drive LEDs when otherwise off. These do NOT perform IO.  | 
 | 54 | +// Returns 1 and outputs duty 0..2000 when a brightness preview window is active.  | 
 | 55 | +uint8_t settings_get_brightness_preview(uint32_t now_ms, uint16_t* out_duty_0_2000);  | 
 | 56 | +// Returns 1 and outputs color bits when a startup color preview window is active.  | 
 | 57 | +uint8_t settings_get_startup_preview(uint32_t now_ms, uint8_t* r, uint8_t* g, uint8_t* b);  | 
 | 58 | +// Returns 1 if a rainbow-on preview should be started; 2 if rainbow-off showcase is requested; 0 otherwise.  | 
 | 59 | +// This is an edge-triggered fetch; it clears the pending request.  | 
 | 60 | +uint8_t settings_fetch_rainbow_preview_request(void);  | 
 | 61 | + | 
 | 62 | +// Raw getters for mirroring current values into I2C register snapshots (optional)  | 
 | 63 | +uint8_t settings_get_led_brightness_pct_raw(void);  | 
 | 64 | +kiisu_apoff_t settings_get_auto_poweroff_raw(void);  | 
 | 65 | +kiisu_start_color_t settings_get_startup_color_raw(void);  | 
 | 66 | +uint8_t settings_get_charge_rainbow_raw(void);  | 
 | 67 | + | 
 | 68 | +// Process any pending save to flash; call from main loop  | 
 | 69 | +void settings_process(uint32_t now_ms);  | 
0 commit comments