You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.0 KiB
97 lines
3.0 KiB
8 years ago
|
/* -*- mode: c++ -*-
|
||
|
* Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope.
|
||
6 years ago
|
* Copyright (C) 2017, 2018, 2019 Keyboard.io, Inc
|
||
8 years ago
|
*
|
||
6 years ago
|
* This program is free software: you can redistribute it and/or modify it under
|
||
|
* the terms of the GNU General Public License as published by the Free Software
|
||
|
* Foundation, version 3.
|
||
8 years ago
|
*
|
||
6 years ago
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
|
* details.
|
||
8 years ago
|
*
|
||
6 years ago
|
* You should have received a copy of the GNU General Public License along with
|
||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||
8 years ago
|
*/
|
||
|
|
||
8 years ago
|
#pragma once
|
||
|
|
||
5 years ago
|
#include "kaleidoscope/Runtime.h"
|
||
8 years ago
|
|
||
8 years ago
|
namespace kaleidoscope {
|
||
6 years ago
|
namespace plugin {
|
||
7 years ago
|
class EEPROMSettings : public kaleidoscope::Plugin {
|
||
8 years ago
|
public:
|
||
7 years ago
|
EEPROMSettings(void) {}
|
||
8 years ago
|
|
||
7 years ago
|
EventHandlerResult onSetup();
|
||
6 years ago
|
EventHandlerResult beforeEachCycle();
|
||
8 years ago
|
|
||
6 years ago
|
/* EEPROM is filled with 0xff when uninitialized, so a version with that value
|
||
|
* means we do not have an EEPROM version defined yet. */
|
||
|
static constexpr uint8_t VERSION_UNDEFINED = 0xff;
|
||
|
/* A version set to zero is likely some kind of corruption, we do not normally
|
||
|
* clear the byte. */
|
||
|
static constexpr uint8_t VERSION_IMPOSSIBLE_ZERO = 0x00;
|
||
|
/* Our current version. Whenever we change the layout of the settings, this
|
||
|
* needs to be increased too. If the version stored in EEPROM does not match
|
||
|
* this version, EEPROM use should be considered unsafe, and plugins should
|
||
|
* fall back to not using it. */
|
||
|
static constexpr uint8_t VERSION_CURRENT = 0x01;
|
||
|
|
||
8 years ago
|
static void update(void);
|
||
|
static bool isValid(void);
|
||
|
static void invalidate(void);
|
||
6 years ago
|
static uint8_t version(void) {
|
||
|
return settings_.version;
|
||
|
}
|
||
8 years ago
|
|
||
|
static uint16_t requestSlice(uint16_t size);
|
||
|
static void seal(void);
|
||
|
static uint16_t crc(void);
|
||
|
static uint16_t used(void);
|
||
|
|
||
6 years ago
|
static uint8_t default_layer(uint8_t layer);
|
||
|
static uint8_t default_layer() {
|
||
|
return settings_.default_layer;
|
||
|
}
|
||
6 years ago
|
static void ignoreHardcodedLayers(bool value);
|
||
|
static bool ignoreHardcodedLayers() {
|
||
|
return settings_.ignore_hardcoded_layers;
|
||
|
}
|
||
6 years ago
|
|
||
8 years ago
|
private:
|
||
6 years ago
|
static constexpr uint8_t IGNORE_HARDCODED_LAYER = 0x7e;
|
||
8 years ago
|
static uint16_t next_start_;
|
||
|
static bool is_valid_;
|
||
|
static bool sealed_;
|
||
8 years ago
|
|
||
|
static struct settings {
|
||
6 years ago
|
uint8_t default_layer: 7;
|
||
|
bool ignore_hardcoded_layers: 1;
|
||
8 years ago
|
uint8_t version;
|
||
|
uint16_t crc;
|
||
8 years ago
|
} settings_;
|
||
8 years ago
|
};
|
||
6 years ago
|
|
||
|
class FocusSettingsCommand : public kaleidoscope::Plugin {
|
||
|
public:
|
||
|
FocusSettingsCommand() {}
|
||
|
|
||
|
EventHandlerResult onFocusEvent(const char *command);
|
||
|
};
|
||
|
|
||
|
class FocusEEPROMCommand : public kaleidoscope::Plugin {
|
||
|
public:
|
||
|
FocusEEPROMCommand() {}
|
||
|
|
||
|
EventHandlerResult onFocusEvent(const char *command);
|
||
|
};
|
||
6 years ago
|
}
|
||
|
}
|
||
8 years ago
|
|
||
6 years ago
|
extern kaleidoscope::plugin::EEPROMSettings EEPROMSettings;
|
||
6 years ago
|
extern kaleidoscope::plugin::FocusSettingsCommand FocusSettingsCommand;
|
||
|
extern kaleidoscope::plugin::FocusEEPROMCommand FocusEEPROMCommand;
|