]> git.zerfleddert.de Git - fnordlicht-mini/blob - firmware/fnordlicht-firmware/storage.h
09e293d9c9e969b221d3265182a6bf370fce6037
[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: 13 byte */
48 struct storage_config_t
49 {
50 /* magic byte, must match EEPROM_MAGIC_BYTE to mark a valid configuration */
51 uint8_t magic;
52 /* startup parameters, defined in remote_proto.h, size: 12 byte */
53 struct startup_parameters_t params;
54 };
55
56 /* storage structure for EEPROM
57 * size: 494 byte
58 * (means: 18 byte left) */
59 struct storage_t
60 {
61 /* startup configuration, size: 12 byte */
62 struct storage_config_t config;
63
64 /* color storage, size: 60*8 == 480 byte */
65 struct storage_color_t color[CONFIG_EEPROM_COLORS];
66
67 /* crc16 checksum over config and color[], size: 2 byte */
68 uint16_t checksum;
69 };
70
71 /* global structures */
72 extern struct storage_config_t startup_config;
73 extern EEMEM struct storage_t eeprom_storage;
74
75 /* initialize storage */
76 void storage_init(void);
77 /* poll storage */
78 void storage_poll(void);
79
80 /* save storage config cfg to eeprom */
81 void storage_save_config(void);
82 /* load storage config cfg from eeprom */
83 void storage_load_config(void);
84
85 void storage_save_color(uint8_t position, struct storage_color_t *color);
86 void storage_load_color(uint8_t position, struct storage_color_t *color);
87
88 /* return true if configuration has been loaded and is valid */
89 bool storage_valid_config(void);
90
91 #endif
Impressum, Datenschutz