Skip to content

Commit a72afa8

Browse files
committed
make fit on Atreus
Adapt previous to fit on the Atreus example sketch. Notably, this makes `EEPROMKeymap::max_layers()` private so that it can be inlined. Therefore, sketches like the `EEPROM-Keymap-Programmer` example sketch that used that method needed to be adjusted. That method seemed obsolete anyway, because it doesn't do some error checking that `EEPROMKeymap::setup()` does. Also, it removes the `settings.acceptInvalid` command, replacing it with an optional argument to `settings.valid?`. Unfortunately, this means that Chrysalis has no direct way to detect the presence of this capability. Signed-off-by: Taylor Yu <[email protected]>
1 parent 9430888 commit a72afa8

File tree

7 files changed

+31
-51
lines changed

7 files changed

+31
-51
lines changed

examples/Features/EEPROM/EEPROM-Keymap-Programmer/EEPROM-Keymap-Programmer.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void setup() {
6262

6363
Layer.getKey = EEPROMKeymap.getKey;
6464

65-
EEPROMKeymap.max_layers(1);
65+
EEPROMKeymap.setup(1);
6666
EEPROMSettings.seal();
6767
}
6868

plugins/Kaleidoscope-EEPROM-Keymap-Programmer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void setup() {
7474

7575
Layer.getKey = EEPROMKeymap.getKey;
7676

77-
EEPROMKeymap.max_layers(1);
77+
EEPROMKeymap.setup(1);
7878
EEPROMSettings.seal();
7979
}
8080
```

plugins/Kaleidoscope-EEPROM-Keymap/src/kaleidoscope/plugin/EEPROM-Keymap.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ namespace plugin {
3434
uint16_t EEPROMKeymap::keymap_base_;
3535
uint8_t EEPROMKeymap::max_layers_;
3636
uint8_t EEPROMKeymap::progmem_layers_;
37-
bool EEPROMKeymap::ignore_hardcoded_;
3837

3938
EventHandlerResult EEPROMKeymap::onSetup() {
40-
::EEPROMSettings.onSetup();
4139
progmem_layers_ = layer_count;
4240
return EventHandlerResult::OK;
4341
}
@@ -46,7 +44,7 @@ EventHandlerResult EEPROMKeymap::onNameQuery() {
4644
return ::Focus.sendName(F("EEPROMKeymap"));
4745
}
4846

49-
void EEPROMKeymap::set_layers(bool ignore_hardcoded) {
47+
inline void EEPROMKeymap::set_layers(bool ignore_hardcoded) {
5048
layer_count = max_layers_;
5149
if (ignore_hardcoded) {
5250
Layer.getKey = getKey;
@@ -58,11 +56,10 @@ void EEPROMKeymap::set_layers(bool ignore_hardcoded) {
5856

5957
void EEPROMKeymap::setup(uint8_t max) {
6058
max_layers(max);
61-
ignore_hardcoded_ = ::EEPROMSettings.ignoreHardcodedLayers();
62-
set_layers(ignore_hardcoded_);
59+
set_layers(::EEPROMSettings.ignoreHardcodedLayers());
6360
}
6461

65-
void EEPROMKeymap::max_layers(uint8_t max) {
62+
inline void EEPROMKeymap::max_layers(uint8_t max) {
6663
max_layers_ = max;
6764
keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * Runtime.device().numKeys() * 2);
6865
}
@@ -73,10 +70,8 @@ void EEPROMKeymap::max_layers(uint8_t max) {
7370
* to avoid scrambled keymaps in some firmware update situations.
7471
*/
7572
EventHandlerResult EEPROMKeymap::beforeEachCycle() {
76-
if (::EEPROMSettings.ignoreHardcodedLayers() != ignore_hardcoded_) {
77-
ignore_hardcoded_ = !ignore_hardcoded_;
78-
set_layers(ignore_hardcoded_);
79-
}
73+
set_layers(::EEPROMSettings.ignoreHardcodedLayers());
74+
return EventHandlerResult::OK;
8075
}
8176

8277
Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) {

plugins/Kaleidoscope-EEPROM-Keymap/src/kaleidoscope/plugin/EEPROM-Keymap.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
4040

4141
static void setup(uint8_t max);
4242

43-
static void max_layers(uint8_t max);
44-
4543
static uint16_t keymap_base();
4644

4745
static Key getKey(uint8_t layer, KeyAddr key_addr);
@@ -53,12 +51,12 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
5351
static uint16_t keymap_base_;
5452
static uint8_t max_layers_;
5553
static uint8_t progmem_layers_;
56-
static bool ignore_hardcoded_;
5754

5855
static Key parseKey();
5956
static void printKey(Key key);
6057
static void dumpKeymap(uint8_t layers, Key (*getkey)(uint8_t, KeyAddr));
61-
static void set_layers(bool ignore_hardcoded);
58+
static inline void max_layers(uint8_t max);
59+
static inline void set_layers(bool ignore_hardcoded);
6260
};
6361

6462
} // namespace plugin

plugins/Kaleidoscope-EEPROM-Settings/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,14 @@ following commands:
166166
167167
> Returns either `true` or `false`, depending on whether the sealed settings are
168168
> to be considered valid or not.
169+
>
170+
> When given an argument of `1`, accepts the current settings as valid, regardless of whether the settings layout matches.
171+
> Accepting also stores the current checksum, so it will be considered valid in the future.
169172
170173
### `settings.version`
171174
172175
> Returns the version of the settings.
173176
174-
### `settings.acceptInvalid 1`
175-
176-
> Accepts the current settings as valid, regardless of whether the settings layout matches.
177-
> Also stores the current checksum, so it will be considered valid in the future.
178-
> The argument of `1` is required, to prevent accidental activation.
179-
180177
### `eeprom.contents`
181178
182179
> Without argument, displays the full contents of the `EEPROM`, including the

plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.cpp

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
namespace kaleidoscope {
3131
namespace plugin {
3232

33-
void EEPROMSettings::fallback_layers() {
33+
inline void EEPROMSettings::fallback_layers() {
3434
settings_.ignore_hardcoded_layers = false;
3535
settings_.default_layer = 0;
3636
}
@@ -112,8 +112,7 @@ void EEPROMSettings::seal() {
112112
if (settings_.version != VERSION_CURRENT) {
113113
is_valid_ = false;
114114
} else if (settings_.crc == 0xffff) {
115-
settings_.crc = CRCCalculator.crc;
116-
update();
115+
accept_invalid();
117116
} else if (settings_.crc == CRCCalculator.crc) {
118117
is_valid_ = true;
119118
}
@@ -153,7 +152,6 @@ void EEPROMSettings::invalidate() {
153152

154153
// Accept possibly corrupt settings, hopefully after user review
155154
void EEPROMSettings::accept_invalid() {
156-
is_valid_ = true;
157155
settings_.crc = ::CRCCalculator.crc;
158156
update();
159157
}
@@ -175,17 +173,16 @@ EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *input) {
175173
IS_VALID,
176174
GET_VERSION,
177175
GET_CRC,
178-
ACCEPT_INVALID,
179176
} sub_command;
177+
uint8_t v;
180178

181-
const char *cmd_defaultLayer = PSTR("settings.defaultLayer");
182-
const char *cmd_isValid = PSTR("settings.valid?");
183-
const char *cmd_version = PSTR("settings.version");
184-
const char *cmd_crc = PSTR("settings.crc");
185-
const char *cmd_acceptInvalid = PSTR("settings.acceptInvalid");
179+
const char *cmd_defaultLayer = PSTR("settings.defaultLayer");
180+
const char *cmd_isValid = PSTR("settings.valid?");
181+
const char *cmd_version = PSTR("settings.version");
182+
const char *cmd_crc = PSTR("settings.crc");
186183

187184
if (::Focus.inputMatchesHelp(input))
188-
return ::Focus.printHelp(cmd_defaultLayer, cmd_isValid, cmd_version, cmd_crc, cmd_acceptInvalid);
185+
return ::Focus.printHelp(cmd_defaultLayer, cmd_isValid, cmd_version, cmd_crc);
189186

190187
if (::Focus.inputMatchesCommand(input, cmd_defaultLayer))
191188
sub_command = DEFAULT_LAYER;
@@ -195,8 +192,6 @@ EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *input) {
195192
sub_command = GET_VERSION;
196193
else if (::Focus.inputMatchesCommand(input, cmd_crc))
197194
sub_command = GET_CRC;
198-
else if (::Focus.inputMatchesCommand(input, cmd_acceptInvalid))
199-
sub_command = ACCEPT_INVALID;
200195
else
201196
return EventHandlerResult::OK;
202197

@@ -205,32 +200,27 @@ EventHandlerResult FocusSettingsCommand::onFocusEvent(const char *input) {
205200
if (::Focus.isEOL()) {
206201
::Focus.send(::EEPROMSettings.default_layer());
207202
} else {
208-
uint8_t layer;
209-
::Focus.read(layer);
210-
::EEPROMSettings.default_layer(layer);
203+
::Focus.read(v);
204+
::EEPROMSettings.default_layer(v);
211205
}
212206
break;
213207
}
214208
case IS_VALID:
215-
::Focus.send(::EEPROMSettings.isValid());
209+
// `isEOL()` not needed, because `read()` will store 0 on early EOL
210+
::Focus.read(v);
211+
if (v == 1) {
212+
// Accept possibly corrupt settings, hopefully after user review
213+
::EEPROMSettings.accept_invalid();
214+
} else {
215+
::Focus.send(::EEPROMSettings.isValid());
216+
}
216217
break;
217218
case GET_VERSION:
218219
::Focus.send(::EEPROMSettings.version());
219220
break;
220221
case GET_CRC:
221222
::Focus.sendRaw(::CRCCalculator.crc, F("/"), ::EEPROMSettings.crc());
222223
break;
223-
case ACCEPT_INVALID:
224-
if (::Focus.isEOL()) {
225-
break;
226-
} else {
227-
uint8_t v;
228-
::Focus.read(v);
229-
if (v == 1) {
230-
::EEPROMSettings.accept_invalid();
231-
}
232-
}
233-
break;
234224
}
235225

236226
return EventHandlerResult::EVENT_CONSUMED;

plugins/Kaleidoscope-EEPROM-Settings/src/kaleidoscope/plugin/EEPROM-Settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class EEPROMSettings : public kaleidoscope::Plugin {
8181
uint16_t next_start_ = sizeof(EEPROMSettings::Settings);
8282
bool is_valid_;
8383
bool sealed_;
84-
void fallback_layers();
84+
inline void fallback_layers();
8585

8686
Settings settings_;
8787
};

0 commit comments

Comments
 (0)