#pragma once #include #include "action.h" // ── NVM-Config-Layout (512 Bytes, ab 0x1FE00) ──────────────────────────────── // // Offset Size Inhalt // 0 4 Magic (0x56503202 = 'VP2\x02') // 4 1 Version // 5 2 CRC16 über Bytes 7–222 // 7 60 mx_actions[20] – 20 × 3B (SAction packed) // 67 36 enc_actions[4][3] – 12 × 3B // 103 20 led_r[20] // 123 20 led_g[20] // 143 20 led_b[20] // 163 20 led_anim[20] – LEDAnim-Typ pro Button (uint8_t) // 183 40 led_period_ms[20] – Animationsperiode in ms (uint16_t, little-endian) // 223 33 Padding bis 256 Bytes (erste Row voll) // 256 256 Reserviert für zukünftige Erweiterungen (zweite Row) // // Gesamt genutzt: 223 Bytes (sizeof SDeviceConfig mit packed SAction) #define NVM_CONFIG_MAGIC 0x56503202UL #define NVM_CONFIG_VERSION 2 // Version 2: led_anim + led_period_ms hinzugefügt // Encoder-Aktions-Indizes (in SDeviceConfig.enc_actions[]) // Reihenfolge: [enc][0]=SW, [enc][1]=CW, [enc][2]=CCW #define ENC_ACTION_SW 0 #define ENC_ACTION_CW 1 #define ENC_ACTION_CCW 2 struct __attribute__((packed)) SDeviceConfig { uint32_t magic; uint8_t version; uint16_t crc; // Aktionen SAction mx_actions[20]; // MX-Buttons 0–19 (key_id 5–24) SAction enc_actions[4][3]; // [Encoder 0–3][SW/CW/CCW] // Base-LED Farben uint8_t led_r[20]; uint8_t led_g[20]; uint8_t led_b[20]; // LED-Animationen pro MX-Button uint8_t led_anim[20]; // LEDAnim-Typ (0=STATIC, 1=BLINK, 2=PULSE, 5=COLOR_CYCLE) uint16_t led_period_ms[20]; // Animationsperiode in ms (0 = Firmware-Default verwenden) }; // Standardwerte wenn keine gültige Config im NVM void nvm_config_defaults(SDeviceConfig& cfg); // Config aus NVM lesen. Gibt false zurück wenn Magic/CRC ungültig → Defaults geladen. bool nvm_config_load(SDeviceConfig& cfg); // Config in NVM schreiben (löscht 2 Rows, schreibt neu). void nvm_config_save(const SDeviceConfig& cfg); // CRC16 über die Nutzdaten der Config uint16_t nvm_config_crc(const SDeviceConfig& cfg);