Skip to content

Update EEPROM library #334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libraries/EEPROM/library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=EEPROM
version=2.0
version=2.0.1
author=Arduino, Christopher Andrews
maintainer=Arduino <[email protected]>
sentence=Enables reading and writing to the permanent board storage. For all Arduino boards BUT Arduino DUE and Arduino ZERO.
paragraph=
maintainer=stm32duino
sentence=Enables reading and writing to the permanent board storage.
paragraph=This library allows to read and write data in a memory type, the EEPROM, that keeps its content also when the board is powered off. The amount of EEPROM available depends on the microcontroller type.
category=Data Storage
url=http://www.arduino.cc/en/Reference/EEPROM
architectures=stm32
40 changes: 20 additions & 20 deletions libraries/EEPROM/EEPROM.h → libraries/EEPROM/src/EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/***
EERef class.

This object references an EEPROM cell.
Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM.
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
Expand All @@ -35,11 +35,11 @@ struct EERef{

EERef( const int index )
: index( index ) {}

//Access/read members.
uint8_t operator*() const { return eeprom_read_byte( /*(uint8_t*)*/ index ); }
operator const uint8_t() const { return **this; }
operator uint8_t() const { return **this; }

//Assignment/write members.
EERef &operator=( const EERef &ref ) { return *this = *ref; }
EERef &operator=( uint8_t in ) { return eeprom_write_byte( /*(uint8_t*)*/ index, in ), *this; }
Expand All @@ -53,47 +53,47 @@ struct EERef{
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 operator++ (int){
uint8_t ret = **this;
return ++(*this), ret;
}

uint8_t operator-- (int){
uint8_t operator-- (int){
uint8_t ret = **this;
return --(*this), ret;
}

int index; //Index of current EEPROM cell.
};

/***
EEPtr class.

This object is a bidirectional pointer to EEPROM cells represented by EERef objects.
Just like a normal pointer type, this can be dereferenced and repositioned using
Just like a normal pointer type, this can be dereferenced and repositioned using
increment/decrement operators.
***/

struct EEPtr{

EEPtr( const int index )
: index( index ) {}
operator const int() const { return index; }

operator int() const { return index; }
EEPtr &operator=( int in ) { return index = in, *this; }

//Iterator functionality.
bool operator!=( const EEPtr &ptr ) { return index != ptr.index; }
EERef operator*() { return index; }

/** Prefix & Postfix increment/decrement **/
EEPtr& operator++() { return ++index, *this; }
EEPtr& operator--() { return --index, *this; }
Expand All @@ -105,7 +105,7 @@ struct EEPtr{

/***
EEPROMClass class.

This object represents the entire EEPROM space.
It wraps the functionality of EEPtr and EERef into a basic interface.
This class is also 100% backwards compatible with earlier Arduino core releases.
Expand All @@ -118,20 +118,20 @@ struct EEPROMClass{
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() { return E2END; }

//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;
Expand Down