-
Notifications
You must be signed in to change notification settings - Fork 5
/
fe-eeprom.ino
133 lines (102 loc) · 3.38 KB
/
fe-eeprom.ino
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/******************************************************************************
*
* This file is part of the Arduino-Arcs project, see
* https://github.com/pavelmc/arduino-arcs
*
* Copyright (C) 2016...2017 Pavel Milanes (CO7WT) <pavelmc@gmail.com>
*
* This program is free software under the GNU GPL v3.0
*
* ***************************************************************************/
/*
EEPROM amount vary from board to board, a simple list here:
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage. (ATMega 168)
- Arduino Uno: 1kb EEPROM storage. (ATMega 328)
- Arduino Mega: 4kb EEPROM storage. (ATMega 2560)
Rather than hard-coding the length, you should use the pre-provided length
function. This will make your code portable to all AVR processors.
EEPROM.length()
*/
// check if the EEPROM is initialized
boolean checkInitEEPROM() {
byte t;
bool flag = true; // true if eeprom is initialized and match
// check the firmware version
t = EEPROM.read(0);
if (t != FMW_VER) flag = false;
// check the eeprom version
t = EEPROM.read(1);
if (t != EEP_VER) flag = false;
// return it
return flag;
}
// initialize the EEPROM mem, also used to store the values in the setup mode
// this procedure has a protection for the EEPROM life using update semantics
// it actually only write a cell if it has changed
void saveEEPROM() {
// write it
EEPROM.put(0, u);
}
// load the eprom contents
void loadEEPROMConfig() {
// get it
EEPROM.get(0, u);
// force to operation
CXTAL = XTAL + u.ppm;
updateAllFreq();
// force a reset
Si5351_resets();
}
#ifdef MEMORIES
// save memory location
void saveMEM(word memItem, boolean configured) {
// real or empty
if (!configured) {
// default values
memo.configured = false;
memo.vfo = 7110000;
memo.vfoMode = MODE_LSB;
} else {
// ok, real ones, set the values
memo.configured = true;
memo.vfo = *ptrVFO;
memo.vfoMode = *ptrMode;
}
// write it
EEPROM.put(MEMSTART + (sizeof(mmem) * memItem), memo);
}
// load memory location
boolean loadMEM(word memItem) {
// get the values
EEPROM.get(MEMSTART + (sizeof(mmem) * memItem), memo);
// is the mem valid?
if (!memo.configured) return false;
// load it
*ptrVFO = memo.vfo;
*ptrMode = memo.vfoMode;
// return true
return true;
}
// wipe mem, this is loaded in the init process of the eeprom.
void wipeMEM() {
// run for the entire mem area writing the defaults to it,
// with no-go flag on it
for (word i = 0; i <= memCount; i++ ) saveMEM(i, 0);
}
#ifdef MEM_SCAN
// check memscan
void checkMemScan() {
// check timer until the next mem jump
if ((mscan == true) and (scanTime < millis())) {
// move to the next mem
do {// increase the mem & check it
mem += 1;
if (mem >= memCount) mem = 0;
} while(!loadMEM(mem));
// reset timer
scanTime = millis() + MEM_SCAN_INTERVAL;
}
}
#endif // mem scan
#endif // memories