FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
eeprom::EEPROM Class Reference

Collection of static methods to read or write the AVR EEPROM. More...

#include <fastarduino/eeprom.h>

Inheritance diagram for eeprom::EEPROM:

Public Member Functions

 EEPROM (const EEPROM &)=delete
 
EEPROMoperator= (const EEPROM &)=delete
 

Static Public Member Functions

template<typename T >
static bool read (const T *address, T &value)
 Read value of type T stored in EEPROM at address. More...
 
template<typename T >
static bool read (uint16_t address, T &value)
 Read value of type T stored in EEPROM at address. More...
 
template<typename T >
static bool read (const T *address, T *value, uint16_t count)
 Read an array of count values of type T stored in EEPROM at address. More...
 
template<typename T >
static bool read (uint16_t address, T *value, uint16_t count)
 Read an array of count values of type T stored in EEPROM at address. More...
 
static bool read (const uint8_t *address, uint8_t &value)
 Read one byte stored in EEPROM at address. More...
 
static bool read (uint16_t address, uint8_t &value)
 Read one byte stored in EEPROM at address. More...
 
template<typename T >
static bool write (const T *address, const T &value)
 Write the content of value of type T to the EEPROM at address. More...
 
template<typename T >
static bool write (uint16_t address, const T &value)
 Write the content of value of type T to the EEPROM at address. More...
 
template<typename T >
static bool write (const T *address, const T *value, uint16_t count)
 Write value, an array of count values of type T to the EEPROM at address. More...
 
template<typename T >
static bool write (uint16_t address, const T *value, uint16_t count)
 Write value, an array of count values of type T to the EEPROM at address. More...
 
static bool write (const uint8_t *address, uint8_t value)
 Write one byte to the EEPROM at address. More...
 
static bool write (uint16_t address, uint8_t value)
 Write one byte to the EEPROM at address. More...
 
static void erase ()
 Erase the full EEPROM content. More...
 
static constexpr uint16_t size ()
 Return the size (in bytes) of the embedded EEPROM. More...
 
static void wait_until_ready ()
 Block until the current EEPROM operation, whetever it is (e.g. More...
 

Detailed Description

Collection of static methods to read or write the AVR EEPROM.

All API here is blocking, i.e. will not return until read or write is complete.

All API here exists in 2 flavors, differing in how the EEPROM cell address is passed :

  • as an absolute uint16_t location, from 0 to max EEPROM size
  • as the address of a variable that was declared with EEMEM attribute

The second is generally more convenient as it allows you to:

  • not care about actual variable locations in EEPROM (if you have many distinct content to store, defined in different source files); location will be determined for you at compile-time
  • prepare initial values for EEPROM content, for which make will generate an .eep file that you can separately upload to EEPROM

The following snippet shows briefly how you can use the EEMEM flavor:

// Declare EEPROM stored content
static uint32_t eeprom_hash EEMEM = 0;
...
uint32_t read_hash()
{
uint32_t hash;
// Read uint32_t value located at "eeprom_hash" in EEPROM, and put it into hash variable
EEPROM::read(&eeprom_hash, hash);
return hash;
}
void write_hash(uint32_t hash)
{
EEPROM::write(&eeprom_hash, hash);
}
static bool read(const T *address, T &value)
Read value of type T stored in EEPROM at address.
Definition: eeprom.h:149
static bool write(const T *address, const T &value)
Write the content of value of type T to the EEPROM at address.
Definition: eeprom.h:278

Definition at line 126 of file eeprom.h.

Member Function Documentation

◆ read() [1/6]

template<typename T >
static bool eeprom::EEPROM::read ( const T *  address,
T &  value 
)
inlinestatic

Read value of type T stored in EEPROM at address.

Note
Whatever T type, this method never calls its assignment operator but simply copies, byte per byte, content from EEPROM to internal content of the type, no T code gets executed.
Template Parameters
Tthe type of content to be read (determines the number of bytes to read)
Parameters
addressthe location to be read in EEPROM; address is typically obtained as &variable where variable is a global variable that was declared with EEMEM attribute.
valuea reference to the variable that will be assigned the content read from EEPROM
Return values
trueif read was successful
falseif read failed, i.e. if address is outside EEPROM bounds
See also
read(uint16_t, T&)

Definition at line 149 of file eeprom.h.

◆ read() [2/6]

template<typename T >
static bool eeprom::EEPROM::read ( uint16_t  address,
T &  value 
)
inlinestatic

Read value of type T stored in EEPROM at address.

Note
Whatever T type, this method never calls its assignment operator but simply copies, byte per byte, content from EEPROM to internal content of the type, no T code gets executed.
Template Parameters
Tthe type of content to be read (determines the number of bytes to read)
Parameters
addressthe location to be read in EEPROM; address is provided as an absolute location, from 0 to the maximum EEPROM size
valuea reference to the variable that will be assigned the content read from EEPROM
Return values
trueif read was successful
falseif read failed, i.e. if address is outside EEPROM bounds
See also
read(const T*, T&)

Definition at line 169 of file eeprom.h.

◆ read() [3/6]

template<typename T >
static bool eeprom::EEPROM::read ( const T *  address,
T *  value,
uint16_t  count 
)
inlinestatic

Read an array of count values of type T stored in EEPROM at address.

Note
Whatever T type, this method never calls its assignment operator but simply copies, byte per byte, content from EEPROM to internal content of the type, no T code gets executed.
Template Parameters
Tthe type of content to be read (determines the number of bytes to read)
Parameters
addressthe location to be read in EEPROM; address is typically obtained as variable where variable is a global variable array that was declared with EEMEM attribute.
valuea pointer to the variable array that will be assigned the content read from EEPROM
countthe number of items of type T to be read
Return values
trueif read was successful
falseif read failed, i.e. if address is outside EEPROM bounds
See also
read(uint16_t, T*, uint16_t)

Definition at line 194 of file eeprom.h.

◆ read() [4/6]

template<typename T >
static bool eeprom::EEPROM::read ( uint16_t  address,
T *  value,
uint16_t  count 
)
inlinestatic

Read an array of count values of type T stored in EEPROM at address.

Note
Whatever T type, this method never calls its assignment operator but simply copies, byte per byte, content from EEPROM to internal content of the type, no T code gets executed.
Template Parameters
Tthe type of content to be read (determines the number of bytes to read)
Parameters
addressthe location to be read in EEPROM; address is provided as an absolute location, from 0 to the maximum EEPROM size
valuea pointer to the variable array that will be assigned the content read from EEPROM
countthe number of items of type T to be read
Return values
trueif read was successful
falseif read failed, i.e. if address is outside EEPROM bounds
See also
read(const T*, T*, uint16_t)

Definition at line 215 of file eeprom.h.

◆ read() [5/6]

static bool eeprom::EEPROM::read ( const uint8_t *  address,
uint8_t &  value 
)
inlinestatic

Read one byte stored in EEPROM at address.

Parameters
addressthe location to be read in EEPROM; address is typically obtained as &variable where variable is a global variable that was declared with EEMEM attribute.
valuea reference to the variable that will be assigned the content read from EEPROM
Return values
trueif read was successful
falseif read failed, i.e. if address is outside EEPROM bounds
See also
read(uint16_t, uint8_t&)

Definition at line 235 of file eeprom.h.

◆ read() [6/6]

static bool eeprom::EEPROM::read ( uint16_t  address,
uint8_t &  value 
)
inlinestatic

Read one byte stored in EEPROM at address.

Parameters
addressthe location to be read in EEPROM; address is provided as an absolute location, from 0 to the maximum EEPROM size
valuea reference to the variable that will be assigned the content read from EEPROM
Return values
trueif read was successful
falseif read failed, i.e. if address is outside EEPROM bounds
See also
read(const uint8_t*, uint8_t&)

Definition at line 251 of file eeprom.h.

◆ write() [1/6]

template<typename T >
static bool eeprom::EEPROM::write ( const T *  address,
const T &  value 
)
inlinestatic

Write the content of value of type T to the EEPROM at address.

Note
Whatever T type, this method never calls its assignment operator but simply copies, byte per byte, content from local variable content to EEPROM, no T code gets executed.
Template Parameters
Tthe type of content to be written (determines the number of bytes to write)
Parameters
addressthe location to be written in EEPROM; address is typically obtained as &variable where variable is a global variable that was declared with EEMEM attribute.
valuea reference to the variable which content will be copied to EEPROM
Return values
trueif write was successful
falseif write failed, i.e. if address is outside EEPROM bounds
See also
write(uint16_t, const T&)

Definition at line 278 of file eeprom.h.

◆ write() [2/6]

template<typename T >
static bool eeprom::EEPROM::write ( uint16_t  address,
const T &  value 
)
inlinestatic

Write the content of value of type T to the EEPROM at address.

Note
Whatever T type, this method never calls its assignment operator but simply copies, byte per byte, content from local variable content to EEPROM, no T code gets executed.
Template Parameters
Tthe type of content to be written (determines the number of bytes to write)
Parameters
addressthe location to be written in EEPROM; address is provided as an absolute location, from 0 to the maximum EEPROM size
valuea reference to the variable which content will be copied to EEPROM
Return values
trueif write was successful
falseif write failed, i.e. if address is outside EEPROM bounds
See also
write(uint16_t, const T&)

Definition at line 298 of file eeprom.h.

◆ write() [3/6]

template<typename T >
static bool eeprom::EEPROM::write ( const T *  address,
const T *  value,
uint16_t  count 
)
inlinestatic

Write value, an array of count values of type T to the EEPROM at address.

Note
Whatever T type, this method never calls its assignment operator but simply copies, byte per byte, content from local variable content to EEPROM, no T code gets executed.
Template Parameters
Tthe type of content to be written (determines the number of bytes to write)
Parameters
addressthe location to be written in EEPROM; address is typically obtained as variable where variable is a global variable array that was declared with EEMEM attribute.
valuea pointer to the variable array which content will be copied to EEPROM
countthe number of items of type T to be written
Return values
trueif write was successful
falseif write failed, i.e. if address is outside EEPROM bounds
See also
write(uint16_t, const T*, uint16_t)

Definition at line 323 of file eeprom.h.

◆ write() [4/6]

template<typename T >
static bool eeprom::EEPROM::write ( uint16_t  address,
const T *  value,
uint16_t  count 
)
inlinestatic

Write value, an array of count values of type T to the EEPROM at address.

Note
Whatever T type, this method never calls its assignment operator but simply copies, byte per byte, content from local variable content to EEPROM, no T code gets executed.
Template Parameters
Tthe type of content to be written (determines the number of bytes to write)
Parameters
addressthe location to be written in EEPROM; address is provided as an absolute location, from 0 to the maximum EEPROM size
valuea pointer to the variable array which content will be copied to EEPROM
countthe number of items of type T to be written
Return values
trueif write was successful
falseif write failed, i.e. if address is outside EEPROM bounds
See also
write(const T*, const T*, uint16_t)

Definition at line 344 of file eeprom.h.

◆ write() [5/6]

static bool eeprom::EEPROM::write ( const uint8_t *  address,
uint8_t  value 
)
inlinestatic

Write one byte to the EEPROM at address.

Parameters
addressthe location to be written in EEPROM; address is typically obtained as &variable where variable is a global variable that was declared with EEMEM attribute.
valuethe byte value that will be written to EEPROM
Return values
trueif write was successful
falseif write failed, i.e. if address is outside EEPROM bounds
See also
write(uint16_t, uint8_t)

Definition at line 363 of file eeprom.h.

◆ write() [6/6]

static bool eeprom::EEPROM::write ( uint16_t  address,
uint8_t  value 
)
inlinestatic

Write one byte to the EEPROM at address.

Parameters
addressthe location to be written in EEPROM; address is provided as an absolute location, from 0 to the maximum EEPROM size
valuethe byte value that will be written to EEPROM
Return values
trueif write was successful
falseif write failed, i.e. if address is outside EEPROM bounds
See also
write(const uint8_t*, uint8_t)

Definition at line 378 of file eeprom.h.

◆ erase()

static void eeprom::EEPROM::erase ( )
inlinestatic

Erase the full EEPROM content.

Note that "erasing" means setting all EEPROM cells to 0xFF. The method will block until all EEPROM content has been erased.

Definition at line 390 of file eeprom.h.

◆ size()

static constexpr uint16_t eeprom::EEPROM::size ( )
inlinestaticconstexpr

Return the size (in bytes) of the embedded EEPROM.

Definition at line 402 of file eeprom.h.

◆ wait_until_ready()

static void eeprom::EEPROM::wait_until_ready ( )
inlinestatic

Block until the current EEPROM operation, whetever it is (e.g.

read, write, erase), is complete. Normally, you would not need this method as any EEPROM method calls it before starting its operation.

Definition at line 413 of file eeprom.h.


The documentation for this class was generated from the following file: