1
0
This commit is contained in:
Jesse Vincent 2019-12-05 11:41:40 -08:00
parent fd1e397a3e
commit 2997644d22
No known key found for this signature in database
GPG Key ID: CC228463465E40BC
2 changed files with 129 additions and 82 deletions

View File

@ -33,49 +33,84 @@
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 )
: 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;
}
EERef(const int index)
: index(index) {}
uint8_t operator-- (int){
uint8_t ret = **this;
return --(*this), ret;
}
int index; //Index of current EEPROM cell.
static uint8_t eeprom_[];
//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;
}
uint8_t operator-- (int) {
uint8_t ret = **this;
return --(*this), ret;
}
int index; //Index of current EEPROM cell.
static uint8_t eeprom_[];
};
/***
@ -131,33 +166,45 @@ struct EEPtr {
This class is also 100% backwards compatible with earlier Arduino core releases.
***/
struct EEPROMClass{
struct EEPROMClass {
//Basic user access methods.
EERef operator[]( const int idx ) { return idx; }
uint8_t read( int idx ) { return EERef( idx ); }
void write( int idx, uint8_t val ) { (EERef( idx )) = val; }
void update( int idx, uint8_t val ) { EERef( idx ).update( val ); }
//STL and C++11 iteration capability.
EEPtr begin() { return 0x00; }
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
uint16_t length();
//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;
}
//Basic user access methods.
EERef operator[](const int idx) {
return idx;
}
uint8_t read(int idx) {
return EERef(idx);
}
void write(int idx, uint8_t val) {
(EERef(idx)) = val;
}
void update(int idx, uint8_t val) {
EERef(idx).update(val);
}
//STL and C++11 iteration capability.
EEPtr begin() {
return 0x00;
}
EEPtr end() {
return length(); //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
}
uint16_t length();
//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;

View File

@ -63,21 +63,21 @@ class PluggableUSBModule {
};
class PluggableUSB_ {
public:
PluggableUSB_() {}
bool plug(PluggableUSBModule *node) {
return true;
}
int getInterface(uint8_t *interfaceCount) {
return 1;
}
int getDescriptor(USBSetup &setup) {
return 1;
}
bool setup(USBSetup &setup) {
return true;
}
void getShortName(char *iSerialNum) {}
public:
PluggableUSB_() {}
bool plug(PluggableUSBModule *node) {
return true;
}
int getInterface(uint8_t *interfaceCount) {
return 1;
}
int getDescriptor(USBSetup &setup) {
return 1;
}
bool setup(USBSetup &setup) {
return true;
}
void getShortName(char *iSerialNum) {}
};
// Replacement for global singleton.