2.6 KiB
2.6 KiB
NVM-Konfiguration
Dateien:
config/nvm_config.hconfig/nvm_config.cpp
Flash-Layout
| Bereich | Adresse | Groesse | Inhalt |
|---|---|---|---|
| Macro Row 0 | 0x1FB00 |
256 B | SMacroTable Bytes 0..255 |
| Macro Row 1 | 0x1FC00 |
256 B | SMacroTable Bytes 256..511 |
| Config Row 0 | 0x1FD00 |
256 B | Header + Profil 0 Anfang |
| Config Row 1 | 0x1FE00 |
256 B | Profil 0 Rest + Profil 1 Anfang |
| Config Row 2 | 0x1FF00 |
256 B | Profil 1 Rest + Profil 2 + Reserve |
Makros und Config sind komplett getrennt.
SDeviceConfig
Aktueller Stand:
- Magic:
0x56503203 - Version:
3 - Groesse:
740Byte - auf 3 Config-Rows verteilt
Header
| Offset | Groesse | Feld |
|---|---|---|
0 |
4 | magic |
4 |
1 | version |
5 |
2 | crc |
7 |
1 | active_profile |
8 |
1 | global_brightness |
9 |
4 | enc_sensitivity[4] |
13 |
19 | Reserve |
Pro Profil
Jedes Profil belegt 236 Byte:
| Offset im Profil | Groesse | Feld |
|---|---|---|
0 |
60 | mx_actions[20] |
60 |
36 | enc_actions[4][3] |
96 |
20 | led_r[20] |
116 |
20 | led_g[20] |
136 |
20 | led_b[20] |
156 |
20 | led_brightness[20] |
176 |
20 | led_anim[20] |
196 |
40 | led_period_ms[20] |
Gesamtrechnung:
32 Byte Header + 3 * 236 Byte Profile = 740 Byte
CRC
CRC16-CCITT:
- Polynom
0x1021 - Init
0xFFFF - Bereich: Bytes
7..739
Damit sind auch active_profile und globale Helligkeit abgesichert.
Defaults
nvm_config_defaults() setzt:
active_profile = 0global_brightness = 255enc_sensitivity[*] = 1- alle Actions auf
NONE - alle
led_brightness[*] = 255 - Base-Farbe
R=80, G=40, B=0 led_anim = COLOR_CYCLEled_period_ms = 4000
Praktisch sichtbares Ergebnis:
- alle MX-LEDs laufen wieder im Regenbogenmodus
Laden
nvm_config_load():
- 740 Byte aus NVM kopieren
- Magic pruefen
- Version pruefen
- CRC pruefen
- bei Fehlern Defaults laden und
falsezurueckgeben
Die Firmware faellt also immer auf einen gueltigen Zustand zurueck.
Speichern
nvm_config_save():
- 740-Byte-Config in einen 768-Byte-Row-Puffer kopieren
- Rest mit
0xFFfuellen MANW = 1- 3 Rows loeschen
- 12 Pages zu je 64 Byte schreiben
Rueckgabewert:
truebei Erfolgfalsebei NVM-Timeout
Wichtig:
- der Schreibpuffer muss 4-Byte-aligned sein
packedallein reicht dafuer nicht
Zusammenhang mit Werksreset
Der Werksreset nutzt denselben Pfad:
nvm_config_defaults(cfg)nvm_config_save(cfg)
Dadurch werden auch kaputte, aber formal noch vorhandene Alt-Daten im NVM wirklich ueberschrieben.