aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/eeprom.h
blob: 242f4dd5104af60558b6ce932a7fef7b774f7179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef EEPROM_H_
#define EEPROM_H_

#include "main.h"
#include "remote.h"


#if FEAT_EEPROM
# if IS_ATMEGAx8
#  define USE_EEPROM	1
# else
#  warning "EEPROM storage not possible on this device."
#  define USE_EEPROM	0
# endif
#else
# define USE_EEPROM	0
#endif

#if USE_EEPROM
# define IF_EEPROM(...)	__VA_ARGS__
#else
# define IF_EEPROM(...)	/* nothing */
#endif

#define EEPROM_NR_SETPOINTS	3u

#define EEPROM_FLAG_DIS		0x01u
#define EEPROM_FLAG_ANADIS	0x02u
#define EEPROM_FLAG_SPHSL	0x04u

struct eeprom_data {
	uint8_t flags;
	uint16_t setpoints[EEPROM_NR_SETPOINTS];
	uint16_t pwmcorr_mul[EEPROM_NR_SETPOINTS];
	uint16_t pwmcorr_div[EEPROM_NR_SETPOINTS];

	/* Keep the serial number last.
	 * With the update of the serial number the data set becomes valid. */
	uint8_t serial;
};

static inline bool eeprom_enabled(const struct eeprom_data *d)
{
	return d && !(d->flags & EEPROM_FLAG_DIS);
}

struct eeprom_data * eeprom_get_data(void);
void eeprom_store_data(void);
void eeprom_handle_deep_sleep_wakeup(void);
void eeprom_handle_watchdog_interrupt(void);
void eeprom_init(void);

#endif /* EEPROM_H_ */
bues.ch cgit interface