Allows other plugins to request a slice of EEPROM, and returns the starting location of their area. Makes a CRC out of the slice sizes, so that it can detect when the EEPROM and the Sketch become out of sync. Handling that case is left up to the user. As a consequence, we no longer reserve a big chunk of EEPROM for the keymap, that just becomes another slice of it, which can be anywhere. This makes it a bit harder to adjust the size of it, but as far as this plugin goes, playing with the EEPROM layout will usually mean having to update its contents from scratch, anyway. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>pull/365/head
parent
496cff414b
commit
c0d2c51730
@ -0,0 +1,71 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope.
|
||||||
|
* Copyright (C) 2017 Gergely Nagy
|
||||||
|
*
|
||||||
|
* 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, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Originally generated by pycrc v0.9, https://pycrc.org
|
||||||
|
*
|
||||||
|
* using the configuration:
|
||||||
|
* Width = 16
|
||||||
|
* Poly = 0x8005
|
||||||
|
* Xor_In = 0x0000
|
||||||
|
* ReflectIn = True
|
||||||
|
* Xor_Out = 0x0000
|
||||||
|
* ReflectOut = True
|
||||||
|
* Algorithm = bit-by-bit-fast
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "crc.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
CRC_::reflect (uint8_t len) {
|
||||||
|
uint8_t i;
|
||||||
|
uint16_t newCRC;
|
||||||
|
|
||||||
|
newCRC = crc & 0x01;
|
||||||
|
for (i = 1; i < len; i++) {
|
||||||
|
crc >>= 1;
|
||||||
|
newCRC = (newCRC << 1) | (crc & 0x01);
|
||||||
|
}
|
||||||
|
|
||||||
|
crc = newCRC;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CRC_::update (const void *data, uint8_t len)
|
||||||
|
{
|
||||||
|
const uint8_t *d = (const uint8_t *)data;
|
||||||
|
uint8_t i;
|
||||||
|
bool bit;
|
||||||
|
uint8_t c;
|
||||||
|
|
||||||
|
while (len--) {
|
||||||
|
c = *d++;
|
||||||
|
for (i = 0x01; i & 0xff; i <<= 1) {
|
||||||
|
bit = crc & 0x8000;
|
||||||
|
if (c & i) {
|
||||||
|
bit = !bit;
|
||||||
|
}
|
||||||
|
crc <<= 1;
|
||||||
|
if (bit) {
|
||||||
|
crc ^= 0x8005;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
crc &= 0xffff;
|
||||||
|
}
|
||||||
|
crc &= 0xffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
CRC_ CRC;
|
@ -0,0 +1,45 @@
|
|||||||
|
/* -*- mode: c++ -*-
|
||||||
|
* Kaleidoscope-EEPROM-Settings -- Basic EEPROM settings plugin for Kaleidoscope.
|
||||||
|
* Copyright (C) 2017 Gergely Nagy
|
||||||
|
*
|
||||||
|
* 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, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Originally generated by pycrc v0.9, https://pycrc.org
|
||||||
|
*
|
||||||
|
* using the configuration:
|
||||||
|
* Width = 16
|
||||||
|
* Poly = 0x8005
|
||||||
|
* Xor_In = 0x0000
|
||||||
|
* ReflectIn = True
|
||||||
|
* Xor_Out = 0x0000
|
||||||
|
* ReflectOut = True
|
||||||
|
* Algorithm = bit-by-bit-fast
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
class CRC_ {
|
||||||
|
public:
|
||||||
|
uint16_t crc = 0;
|
||||||
|
|
||||||
|
CRC_ (void) {};
|
||||||
|
|
||||||
|
void update (const void *data, uint8_t len);
|
||||||
|
void finalize (void) { reflect (16); };
|
||||||
|
void reflect (uint8_t len);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern CRC_ CRC;
|
Loading…
Reference in new issue