Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

Commit af8d82b

Browse files
ridhaosWi6labsVVESTM
authored andcommitted
Update EEPROM library for STM8 architecture
1 parent acf6fab commit af8d82b

File tree

5 files changed

+81
-66
lines changed

5 files changed

+81
-66
lines changed

libraries/EEPROM/EEPROM.h

Lines changed: 75 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -25,120 +25,131 @@
2525

2626
/***
2727
EERef class.
28-
28+
2929
This object references an EEPROM cell.
3030
Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM.
3131
This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
3232
***/
3333

34-
struct EERef{
34+
struct EERef
35+
{
36+
37+
EERef(const int index)
38+
: index(index) {}
3539

36-
EERef( const int index )
37-
: index( index ) {}
38-
3940
//Access/read members.
40-
uint8_t operator*() const { return eeprom_read_byte( /*(uint8_t*)*/ index ); }
41-
operator const uint8_t() const { return **this; }
42-
41+
uint8_t operator*() const { return eeprom_read_byte(/*(uint8_t*)*/ index); }
42+
operator uint8_t() const { return **this; }
43+
4344
//Assignment/write members.
44-
EERef &operator=( const EERef &ref ) { return *this = *ref; }
45-
EERef &operator=( uint8_t in ) { return eeprom_write_byte( /*(uint8_t*)*/ index, in ), *this; }
46-
EERef &operator +=( uint8_t in ) { return *this = **this + in; }
47-
EERef &operator -=( uint8_t in ) { return *this = **this - in; }
48-
EERef &operator *=( uint8_t in ) { return *this = **this * in; }
49-
EERef &operator /=( uint8_t in ) { return *this = **this / in; }
50-
EERef &operator ^=( uint8_t in ) { return *this = **this ^ in; }
51-
EERef &operator %=( uint8_t in ) { return *this = **this % in; }
52-
EERef &operator &=( uint8_t in ) { return *this = **this & in; }
53-
EERef &operator |=( uint8_t in ) { return *this = **this | in; }
54-
EERef &operator <<=( uint8_t in ) { return *this = **this << in; }
55-
EERef &operator >>=( uint8_t in ) { return *this = **this >> in; }
56-
57-
EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; }
58-
45+
EERef &operator=(const EERef &ref) { return *this = *ref; }
46+
EERef &operator=(uint8_t in) { return eeprom_write_byte(/*(uint8_t*)*/ index, in), *this; }
47+
EERef &operator+=(uint8_t in) { return *this = **this + in; }
48+
EERef &operator-=(uint8_t in) { return *this = **this - in; }
49+
EERef &operator*=(uint8_t in) { return *this = **this * in; }
50+
EERef &operator/=(uint8_t in) { return *this = **this / in; }
51+
EERef &operator^=(uint8_t in) { return *this = **this ^ in; }
52+
EERef &operator%=(uint8_t in) { return *this = **this % in; }
53+
EERef &operator&=(uint8_t in) { return *this = **this & in; }
54+
EERef &operator|=(uint8_t in) { return *this = **this | in; }
55+
EERef &operator<<=(uint8_t in) { return *this = **this << in; }
56+
EERef &operator>>=(uint8_t in) { return *this = **this >> in; }
57+
58+
EERef &update(uint8_t in) { return in != *this ? *this = in : *this; }
59+
5960
/** Prefix increment/decrement **/
60-
EERef& operator++() { return *this += 1; }
61-
EERef& operator--() { return *this -= 1; }
62-
61+
EERef &operator++() { return *this += 1; }
62+
EERef &operator--() { return *this -= 1; }
63+
6364
/** Postfix increment/decrement **/
64-
uint8_t operator++ (int){
65+
uint8_t operator++(int)
66+
{
6567
uint8_t ret = **this;
6668
return ++(*this), ret;
6769
}
6870

69-
uint8_t operator-- (int){
71+
uint8_t operator--(int)
72+
{
7073
uint8_t ret = **this;
7174
return --(*this), ret;
7275
}
73-
76+
7477
int index; //Index of current EEPROM cell.
7578
};
7679

7780
/***
7881
EEPtr class.
79-
82+
8083
This object is a bidirectional pointer to EEPROM cells represented by EERef objects.
81-
Just like a normal pointer type, this can be dereferenced and repositioned using
84+
Just like a normal pointer type, this can be dereferenced and repositioned using
8285
increment/decrement operators.
8386
***/
8487

85-
struct EEPtr{
88+
struct EEPtr
89+
{
90+
91+
EEPtr(const int index)
92+
: index(index) {}
93+
94+
operator int() const { return index; }
95+
EEPtr &operator=(int in) { return index = in, *this; }
8696

87-
EEPtr( const int index )
88-
: index( index ) {}
89-
90-
operator const int() const { return index; }
91-
EEPtr &operator=( int in ) { return index = in, *this; }
92-
9397
//Iterator functionality.
94-
bool operator!=( const EEPtr &ptr ) { return index != ptr.index; }
95-
EERef operator*() { return index; }
96-
98+
bool operator!=(const EEPtr &ptr) { return index != ptr.index; }
99+
EERef operator*() { return index; }
100+
97101
/** Prefix & Postfix increment/decrement **/
98-
EEPtr& operator++() { return ++index, *this; }
99-
EEPtr& operator--() { return --index, *this; }
100-
EEPtr operator++ (int) { return index++; }
101-
EEPtr operator-- (int) { return index--; }
102+
EEPtr &operator++() { return ++index, *this; }
103+
EEPtr &operator--() { return --index, *this; }
104+
EEPtr operator++(int) { return index++; }
105+
EEPtr operator--(int) { return index--; }
102106

103107
int index; //Index of current EEPROM cell.
104108
};
105109

106110
/***
107111
EEPROMClass class.
108-
112+
109113
This object represents the entire EEPROM space.
110114
It wraps the functionality of EEPtr and EERef into a basic interface.
111115
This class is also 100% backwards compatible with earlier Arduino core releases.
112116
***/
113117

114-
struct EEPROMClass{
118+
struct EEPROMClass
119+
{
115120

116121
//Basic user access methods.
117-
EERef operator[]( const int idx ) { return idx; }
118-
uint8_t read( int idx ) { return EERef( idx ); }
119-
void write( int idx, uint8_t val ) { (EERef( idx )) = val; }
120-
void update( int idx, uint8_t val ) { EERef( idx ).update( val ); }
121-
122+
EERef operator[](const int idx) { return idx; }
123+
uint8_t read(int idx) { return EERef(idx); }
124+
void write(int idx, uint8_t val) { (EERef(idx)) = val; }
125+
void update(int idx, uint8_t val) { EERef(idx).update(val); }
126+
122127
//STL and C++11 iteration capability.
123-
EEPtr begin() { return 0x00; }
124-
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
125-
uint16_t length() { return E2END; }
126-
128+
EEPtr begin() { return 0x00; }
129+
EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
130+
uint16_t length() { return E2END; }
131+
127132
//Functionality to 'get' and 'put' objects to and from EEPROM.
128-
template< typename T > T &get( int idx, T &t ){
133+
template <typename T>
134+
T &get(int idx, T &t)
135+
{
129136
EEPtr e = idx;
130-
uint8_t *ptr = (uint8_t*) &t;
131-
for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
137+
uint8_t *ptr = (uint8_t *)&t;
138+
for (int count = sizeof(T); count; --count, ++e)
139+
*ptr++ = *e;
132140
return t;
133141
}
134-
135-
template< typename T > const T &put( int idx, const T &t ){
142+
143+
template <typename T>
144+
const T &put(int idx, const T &t)
145+
{
136146
EEPtr e = idx;
137-
const uint8_t *ptr = (const uint8_t*) &t;
138-
for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
147+
const uint8_t *ptr = (const uint8_t *)&t;
148+
for (int count = sizeof(T); count; --count, ++e)
149+
(*e).update(*ptr++);
139150
return t;
140151
}
141152
};
142153

143-
static EEPROMClass EEPROM;
154+
EEPROMClass EEPROM;
144155
#endif

libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <Arduino.h>
1111
#include <EEPROM.h>
1212

13+
unsigned long eeprom_crc(void);
14+
1315
void setup() {
1416

1517
//Start serial

libraries/EEPROM/examples/eeprom_get/eeprom_get.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#include <EEPROM.h>
1919

20+
void secondTest();
21+
2022
void setup() {
2123

2224
float f = 0.00f; //Variable to store data read from EEPROM.

libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ void setup() {
5454

5555
} //End of setup function.
5656

57-
void loop() {}
57+
void loop() {}

libraries/EEPROM/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ sentence=Enables reading and writing to the permanent board storage. For all Ard
66
paragraph=
77
category=Data Storage
88
url=http://www.arduino.cc/en/Reference/EEPROM
9-
architectures=stm32
9+
architectures=stm8

0 commit comments

Comments
 (0)