Virtual EEPROM implementation moved over to virtual device
Only the virtual device knows about the size of its EEPROM storage. Including device headers in the virtual core is not intended (and technical not possible). Signed-off-by: Florian Fleissner <florian.fleissner@inpartik.de>
This commit is contained in:
parent
638306d7b3
commit
fb9b1bdff9
@ -1,22 +0,0 @@
|
|||||||
/* -*- mode: c++ -*-
|
|
||||||
* Kaleidoscope
|
|
||||||
*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "EEPROM.h"
|
|
||||||
|
|
||||||
uint8_t EERef::eeprom_[kaleidoscope::hardware::mcu::eeprom_size];
|
|
||||||
|
|
||||||
EEPROMClass EEPROM;
|
|
@ -25,8 +25,6 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#include KALEIDOSCOPE_MCU_H
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
EERef class.
|
EERef class.
|
||||||
|
|
||||||
@ -35,84 +33,49 @@
|
|||||||
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
|
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
struct EERef {
|
struct EERef{
|
||||||
|
|
||||||
EERef(const int index)
|
EERef( const int index )
|
||||||
: index(index) {}
|
: index( index ) {}
|
||||||
|
|
||||||
|
//Access/read members.
|
||||||
|
uint8_t operator*() const { return eeprom_[index]; }
|
||||||
|
operator uint8_t() const { return **this; }
|
||||||
|
|
||||||
|
//Assignment/write members.
|
||||||
|
EERef &operator=( const EERef &ref ) { return *this = *ref; }
|
||||||
|
EERef &operator=( uint8_t in ) { eeprom_[index] = in; return *this; }
|
||||||
|
EERef &operator +=( uint8_t in ) { return *this = **this + in; }
|
||||||
|
EERef &operator -=( uint8_t in ) { return *this = **this - in; }
|
||||||
|
EERef &operator *=( uint8_t in ) { return *this = **this * in; }
|
||||||
|
EERef &operator /=( uint8_t in ) { return *this = **this / in; }
|
||||||
|
EERef &operator ^=( uint8_t in ) { return *this = **this ^ in; }
|
||||||
|
EERef &operator %=( uint8_t in ) { return *this = **this % in; }
|
||||||
|
EERef &operator &=( uint8_t in ) { return *this = **this & in; }
|
||||||
|
EERef &operator |=( uint8_t in ) { return *this = **this | in; }
|
||||||
|
EERef &operator <<=( uint8_t in ) { return *this = **this << in; }
|
||||||
|
EERef &operator >>=( uint8_t in ) { return *this = **this >> in; }
|
||||||
|
|
||||||
|
EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; }
|
||||||
|
|
||||||
|
/** Prefix increment/decrement **/
|
||||||
|
EERef& operator++() { return *this += 1; }
|
||||||
|
EERef& operator--() { return *this -= 1; }
|
||||||
|
|
||||||
|
/** Postfix increment/decrement **/
|
||||||
|
uint8_t operator++ (int){
|
||||||
|
uint8_t ret = **this;
|
||||||
|
return ++(*this), ret;
|
||||||
|
}
|
||||||
|
|
||||||
//Access/read members.
|
uint8_t operator-- (int){
|
||||||
uint8_t operator*() const {
|
uint8_t ret = **this;
|
||||||
return eeprom_[index];
|
return --(*this), ret;
|
||||||
}
|
}
|
||||||
operator uint8_t() const {
|
|
||||||
return **this;
|
int index; //Index of current EEPROM cell.
|
||||||
}
|
|
||||||
|
static uint8_t eeprom_[];
|
||||||
//Assignment/write members.
|
|
||||||
EERef &operator=(const EERef &ref) {
|
|
||||||
return *this = *ref;
|
|
||||||
}
|
|
||||||
EERef &operator=(uint8_t in) {
|
|
||||||
eeprom_[index] = in;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
EERef &operator +=(uint8_t in) {
|
|
||||||
return *this = **this + in;
|
|
||||||
}
|
|
||||||
EERef &operator -=(uint8_t in) {
|
|
||||||
return *this = **this - in;
|
|
||||||
}
|
|
||||||
EERef &operator *=(uint8_t in) {
|
|
||||||
return *this = **this * in;
|
|
||||||
}
|
|
||||||
EERef &operator /=(uint8_t in) {
|
|
||||||
return *this = **this / in;
|
|
||||||
}
|
|
||||||
EERef &operator ^=(uint8_t in) {
|
|
||||||
return *this = **this ^ in;
|
|
||||||
}
|
|
||||||
EERef &operator %=(uint8_t in) {
|
|
||||||
return *this = **this % in;
|
|
||||||
}
|
|
||||||
EERef &operator &=(uint8_t in) {
|
|
||||||
return *this = **this & in;
|
|
||||||
}
|
|
||||||
EERef &operator |=(uint8_t in) {
|
|
||||||
return *this = **this | in;
|
|
||||||
}
|
|
||||||
EERef &operator <<=(uint8_t in) {
|
|
||||||
return *this = **this << in;
|
|
||||||
}
|
|
||||||
EERef &operator >>=(uint8_t in) {
|
|
||||||
return *this = **this >> in;
|
|
||||||
}
|
|
||||||
|
|
||||||
EERef &update(uint8_t in) {
|
|
||||||
return in != *this ? *this = in : *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prefix increment/decrement **/
|
|
||||||
EERef& operator++() {
|
|
||||||
return *this += 1;
|
|
||||||
}
|
|
||||||
EERef& operator--() {
|
|
||||||
return *this -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Postfix increment/decrement **/
|
|
||||||
uint8_t operator++ (int) {
|
|
||||||
uint8_t ret = **this;
|
|
||||||
return ++(*this), ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t operator-- (int) {
|
|
||||||
uint8_t ret = **this;
|
|
||||||
return --(*this), ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int index; //Index of current EEPROM cell.
|
|
||||||
|
|
||||||
static uint8_t eeprom_[kaleidoscope::hardware::mcu::eeprom_size];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@ -168,47 +131,33 @@ struct EEPtr {
|
|||||||
This class is also 100% backwards compatible with earlier Arduino core releases.
|
This class is also 100% backwards compatible with earlier Arduino core releases.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
struct EEPROMClass {
|
struct EEPROMClass{
|
||||||
|
|
||||||
//Basic user access methods.
|
//Basic user access methods.
|
||||||
EERef operator[](const int idx) {
|
EERef operator[]( const int idx ) { return idx; }
|
||||||
return idx;
|
uint8_t read( int idx ) { return EERef( idx ); }
|
||||||
}
|
void write( int idx, uint8_t val ) { (EERef( idx )) = val; }
|
||||||
uint8_t read(int idx) {
|
void update( int idx, uint8_t val ) { EERef( idx ).update( val ); }
|
||||||
return EERef(idx);
|
|
||||||
}
|
//STL and C++11 iteration capability.
|
||||||
void write(int idx, uint8_t val) {
|
EEPtr begin() { return 0x00; }
|
||||||
(EERef(idx)) = val;
|
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
|
||||||
}
|
uint16_t length();
|
||||||
void update(int idx, uint8_t val) {
|
|
||||||
EERef(idx).update(val);
|
//Functionality to 'get' and 'put' objects to and from EEPROM.
|
||||||
}
|
template< typename T > T &get( int idx, T &t ){
|
||||||
|
EEPtr e = idx;
|
||||||
//STL and C++11 iteration capability.
|
uint8_t *ptr = (uint8_t*) &t;
|
||||||
EEPtr begin() {
|
for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
|
||||||
return 0x00;
|
return t;
|
||||||
}
|
}
|
||||||
EEPtr end() {
|
|
||||||
return length(); //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
|
template< typename T > const T &put( int idx, const T &t ){
|
||||||
}
|
EEPtr e = idx;
|
||||||
uint16_t length() {
|
const uint8_t *ptr = (const uint8_t*) &t;
|
||||||
return kaleidoscope::hardware::mcu::eeprom_size;
|
for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
|
||||||
}
|
return t;
|
||||||
|
}
|
||||||
//Functionality to 'get' and 'put' objects to and from EEPROM.
|
|
||||||
template< typename T > T &get(int idx, T &t) {
|
|
||||||
EEPtr e = idx;
|
|
||||||
uint8_t *ptr = (uint8_t*) &t;
|
|
||||||
for (int count = sizeof(T) ; count ; --count, ++e) *ptr++ = *e;
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename T > const T &put(int idx, const T &t) {
|
|
||||||
EEPtr e = idx;
|
|
||||||
const uint8_t *ptr = (const uint8_t*) &t;
|
|
||||||
for (int count = sizeof(T) ; count ; --count, ++e)(*e).update(*ptr++);
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern EEPROMClass EEPROM;
|
extern EEPROMClass EEPROM;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user