]> git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/fnordlicht-firmware/storage.h
add initialization of node address via eeprom
[fnordlicht-mini] / firmware / fnordlicht-firmware / storage.h
1 /* vim:ts=4 sts=4 et tw=80
2 *
3 * fnordlicht firmware
4 *
5 * for additional information please
6 * see http://lochraster.org/fnordlichtmini
7 *
8 * (c) by Alexander Neumann <alexander@bumpern.de>
9 *
10 * This program is free software: you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 3 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 *
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23 #ifndef __STORAGE_H
24 #define __STORAGE_H
25
26 #include "color.h"
27 #include "remote-proto.h"
28 #include <avr/eeprom.h>
29 #include <stdint.h>
30 #include <stdbool.h>
31
32 /* store a color configuration in EEPROM
33 * size: 8 byte
34 *
35 * use union color_t here, check rgb_marker! */
36 struct storage_color_t
37 {
38 uint8_t step;
39 uint8_t delay;
40 uint16_t pause;
41 union color_t color;
42 };
43
44 #define EEPROM_MAGIC_BYTE 0x23
45
46 /* store the startup configuration in EEPROM
47 * size: 14 bytes */
48 struct storage_config_t
49 {
50 /* magic byte, must match EEPROM_MAGIC_BYTE to mark a valid configuration */
51 uint8_t magic;
52 /* initial node address to use at startup */
53 uint8_t startup_addr;
54 /* startup parameters, defined in remote_proto.h, size: 12 bytes */
55 struct startup_parameters_t params;
56 };
57
58 /* storage structure for EEPROM
59 * size: 496 bytes
60 * (means: 16 bytes left) */
61 struct storage_t
62 {
63 /* startup configuration, size: 14 bytes */
64 struct storage_config_t config;
65
66 /* color storage, size: 60*8 == 480 bytes */
67 struct storage_color_t color[CONFIG_EEPROM_COLORS];
68
69 /* crc16 checksum over config and color[], size: 2 bytes */
70 uint16_t checksum;
71 };
72
73 /* global structures */
74 extern struct storage_config_t startup_config;
75 extern EEMEM struct storage_t eeprom_storage;
76
77 /* initialize storage */
78 void storage_init(void);
79 /* poll storage */
80 void storage_poll(void);
81
82 /* save storage config cfg to eeprom */
83 void storage_save_config(void);
84 /* load storage config cfg from eeprom */
85 void storage_load_config(void);
86
87 void storage_save_color(uint8_t position, struct storage_color_t *color);
88 void storage_load_color(uint8_t position, struct storage_color_t *color);
89
90 /* return true if configuration has been loaded and is valid */
91 bool storage_valid_config(void);
92
93 #endif
Impressum, Datenschutz