diff --git a/cores/arduino/EEPROM.cpp b/cores/arduino/EEPROM.cpp deleted file mode 100644 index 500296b..0000000 --- a/cores/arduino/EEPROM.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "EEPROM.h" -#include "mik32_hal_eeprom.h" - -#define EEPROM_OP_TIMEOUT 100000 -#define EEPROM_PAGE_WORDS 32 -#define EEPROM_PAGE_COUNT 8 // КОличество страниц пользовательской EEPROM -#define EEPROM_START_ADDR 0x1C00 // Адрес начала пользовательской EEPROM -#define EEPROM_WORD_SIZE 4 // Слово занимает 4 байта -#define EEPROM_PAGE_SIZE ( EEPROM_PAGE_WORDS * EEPROM_PAGE_WORDS ) // Страница занимает 32*4 = 128 байт -#define EEPROM_END 0x1FFF -#define EEPROM_LENGHT (EEPROM_PAGE_SIZE * EEPROM_PAGE_COUNT) - -HAL_EEPROM_HandleTypeDef heeprom; - - -EEPtr EEPROMClass:: begin() -{ - heeprom.Instance = EEPROM_REGS; - heeprom.Mode = HAL_EEPROM_MODE_TWO_STAGE; - heeprom.ErrorCorrection = HAL_EEPROM_ECC_ENABLE; - heeprom.EnableInterrupt = HAL_EEPROM_SERR_DISABLE; - - HAL_EEPROM_Init(&heeprom); - HAL_EEPROM_CalculateTimings(&heeprom, OSC_SYSTEM_VALUE); - return 0x00; -} - -uint8_t EEPROMClass:: read( int idx ) -{ - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) - return 0x00; - - uint32_t read_data_buf[EEPROM_PAGE_WORDS] = {}; - - // Вычисление адресы начала нужной страницы - uint32_t addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_PAGE_SIZE) * EEPROM_PAGE_SIZE; - // Чтение нужной страницы - HAL_EEPROM_Read(&heeprom, addr, read_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); - // Адрес искомого слова в eeprom: EEPROM_START_ADDR + (uint32_t)idx - uint32_t word_addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_WORD_SIZE) * EEPROM_WORD_SIZE; - // Индекс искомого слова в массиве read_data_buf: адрес слова в eeprom за вычетом адреса начала страницы - uint32_t word_idx = (word_addr - addr) / EEPROM_WORD_SIZE; - // Номер байта в составе слова - uint32_t byte_idx = ((uint32_t)idx) % EEPROM_WORD_SIZE; - // Вычленение нужного байта из страницы - return (uint8_t)(( read_data_buf[word_idx] & ((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1)) * 8) ) >> ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)); -} - -void EEPROMClass:: write( int idx, uint8_t val ) -{ - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) - return; - - uint32_t write_data_buf[EEPROM_PAGE_WORDS] = {}; - - // Вычисление адресы начала нужной страницы - uint32_t addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_PAGE_SIZE) * EEPROM_PAGE_SIZE; - // Читаем нужную страницу - HAL_EEPROM_Read(&heeprom, addr, write_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); - // Адрес искомого слова в eeprom: EEPROM_START_ADDR + (uint32_t)idx - uint32_t word_addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_WORD_SIZE) * EEPROM_WORD_SIZE; - // Индекс искомого слова в массиве write_data_buf: адрес слова в eeprom за вычетом адреса начала страницы - uint32_t word_idx = (word_addr - addr) / EEPROM_WORD_SIZE; - // Номер байта в составе слова - uint32_t byte_idx = ((uint32_t)idx) % EEPROM_WORD_SIZE; - // Извлечение нужного байта - uint32_t byte = ((uint32_t)val) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8); - // Вычленение и замена нужного байта из страницы - write_data_buf[word_idx] = (write_data_buf[word_idx] & (~((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1)) * 8))) | byte; - - HAL_EEPROM_Write(&heeprom, EEPROM_START_ADDR, write_data_buf, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); -} - -// Делает то же, что и write, но записывает только если новый байт отличается от уже записанного -void EEPROMClass:: update( int idx, uint8_t val ) -{ - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) - return; - - uint32_t write_data_buf[EEPROM_PAGE_WORDS] = {}; - - // Вычисление адресы начала нужной страницы - uint32_t addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_PAGE_SIZE) * EEPROM_PAGE_SIZE; - // Читаем нужную страницу - HAL_EEPROM_Read(&heeprom, addr, write_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); - // Адрес искомого слова в eeprom: EEPROM_START_ADDR + (uint32_t)idx - uint32_t word_addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_WORD_SIZE) * EEPROM_WORD_SIZE; - // Индекс искомого слова в массиве write_data_buf: адрес слова в eeprom за вычетом адреса начала страницы - uint32_t word_idx = (word_addr - addr) / EEPROM_WORD_SIZE; - // Номер байта в составе слова - uint32_t byte_idx = ((uint32_t)idx) % EEPROM_WORD_SIZE; - // Извлечение нужного байта - uint32_t byte = ((uint32_t)val) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8); - // Проверка того, что записанный байт отличается от нового - if((write_data_buf[word_idx] & ((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1)) * 8)) != byte) - { - // Вычленение и замена нужного байта из страницы - write_data_buf[word_idx] = (write_data_buf[word_idx] & (~((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1)) * 8))) | byte; - HAL_EEPROM_Write(&heeprom, EEPROM_START_ADDR, write_data_buf, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); - } -} - -uint16_t EEPROMClass:: length( void ) -{ - return EEPROM_LENGHT; -} - -template< typename T > -const T& EEPROMClass:: put(int idx, const T &t) { - // Создание объекта EEPtr, который указывает на начальный адрес в EEPROM. - EEPtr e = idx; - - // Указатель на данные, которые нужно записать в EEPROM. - const uint8_t *ptr = (const uint8_t*) &t; - - // Количество байт данных для записи. - int count = sizeof(T); - - // Цикл для записи данных побайтно в EEPROM. - for(; count ; --count, ++e) { - // Запись текущего байта данных в EEPROM. - (*e).update( *ptr++ ); - } - - // Возврат ссылки на записанный объект. - return t; -} - -T& EEPROMClass:: get(int idx, T &t) { - EEPtr e = idx; // Указатель на адрес в EEPROM - uint8_t *ptr = (uint8_t*) &t; // Преобразуем ссылку на объект данных в указатель на байт - for (int count = sizeof(T); count; --count, ++e) { - *ptr++ = *e; // Читаем данные из EEPROM и записываем в объект - } - return t; // Возвращаем ссылку на переданный объект с прочитанными данными -} - - - -// uint32_t* EEPROM_Read(uint16_t index) -// { -// uint32_t read_data_buf[]; -// HAL_EEPROM_Read(&heeprom, 0x1C00 + index, read_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); -// return read_data_buf; -// } \ No newline at end of file diff --git a/cores/arduino/EEPROM.h b/cores/arduino/EEPROM.h deleted file mode 100644 index b8fb21a..0000000 --- a/cores/arduino/EEPROM.h +++ /dev/null @@ -1,150 +0,0 @@ -/* - EEPROM.h - EEPROM library - Original Copyright (c) 2006 David A. Mellis. All right reserved. - New version by Christopher Andrews 2015. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef EEPROM_h -#define EEPROM_h - -#include - -/*** - 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. -***/ - -struct EERef{ - - EERef( const int index ) - : index( index ) {} - - //Access/read members. - uint8_t operator*() const { return eeprom_read_byte( (uint8_t*) index ); } - 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; } - 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. -}; - -/*** - 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 - increment/decrement operators. -***/ - -struct EEPtr{ - - EEPtr( const int index ) - : index( 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; } - EEPtr operator++ (int) { return index++; } - EEPtr operator-- (int) { return index--; } - - int index; //Index of current EEPROM cell. -}; - -/*** - 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. -***/ - -struct EEPROMClass{ - - //Basic user access methods. - EERef operator[]( const int idx ) { return idx; } - uint8_t read( int idx ); - void write( int idx, uint8_t val ); - void update( int idx, uint8_t val ); - - //STL and C++11 iteration capability. - EEPtr begin(); - EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid. - uint16_t length(); - - template - const T& put(int address, const T& data); - - template - T& get(int address, T& data); - - //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; - // } -}; - -/*static*/ EEPROMClass EEPROM; -#endif diff --git a/cores/arduino/mik32/hal/peripherals/Include/mik32_hal_eeprom.h b/cores/arduino/mik32/hal/peripherals/Include/mik32_hal_eeprom.h index 86f8836..4a9b584 100644 --- a/cores/arduino/mik32/hal/peripherals/Include/mik32_hal_eeprom.h +++ b/cores/arduino/mik32/hal/peripherals/Include/mik32_hal_eeprom.h @@ -7,7 +7,7 @@ extern "C" { #include "mik32_hal_def.h" #include -#include +#include #include #ifndef HAL_EEPROM_TIMEOUT diff --git a/cores/arduino/mik32/shared/periphery/eeprom.h b/cores/arduino/mik32/shared/periphery/eeprom_def.h similarity index 100% rename from cores/arduino/mik32/shared/periphery/eeprom.h rename to cores/arduino/mik32/shared/periphery/eeprom_def.h diff --git a/libraries/EEPROM/src/EEPROM.cpp b/libraries/EEPROM/src/EEPROM.cpp index 500296b..c07e7a0 100644 --- a/libraries/EEPROM/src/EEPROM.cpp +++ b/libraries/EEPROM/src/EEPROM.cpp @@ -1,19 +1,20 @@ #include "EEPROM.h" #include "mik32_hal_eeprom.h" +#include "mik32_hal.h" #define EEPROM_OP_TIMEOUT 100000 -#define EEPROM_PAGE_WORDS 32 +#define EEPROM_PAGE_WORDS 32 // Количество слов на странице #define EEPROM_PAGE_COUNT 8 // КОличество страниц пользовательской EEPROM #define EEPROM_START_ADDR 0x1C00 // Адрес начала пользовательской EEPROM #define EEPROM_WORD_SIZE 4 // Слово занимает 4 байта -#define EEPROM_PAGE_SIZE ( EEPROM_PAGE_WORDS * EEPROM_PAGE_WORDS ) // Страница занимает 32*4 = 128 байт +#define EEPROM_PAGE_SIZE ( EEPROM_PAGE_WORDS * EEPROM_WORD_SIZE ) // Страница занимает 32*4 = 128 байт #define EEPROM_END 0x1FFF #define EEPROM_LENGHT (EEPROM_PAGE_SIZE * EEPROM_PAGE_COUNT) HAL_EEPROM_HandleTypeDef heeprom; -EEPtr EEPROMClass:: begin() +void EEPROMClass:: begin() { heeprom.Instance = EEPROM_REGS; heeprom.Mode = HAL_EEPROM_MODE_TWO_STAGE; @@ -22,20 +23,19 @@ EEPtr EEPROMClass:: begin() HAL_EEPROM_Init(&heeprom); HAL_EEPROM_CalculateTimings(&heeprom, OSC_SYSTEM_VALUE); - return 0x00; } uint8_t EEPROMClass:: read( int idx ) { - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) - return 0x00; + if (((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) || (idx < 0)) + return 0x0; uint32_t read_data_buf[EEPROM_PAGE_WORDS] = {}; // Вычисление адресы начала нужной страницы uint32_t addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_PAGE_SIZE) * EEPROM_PAGE_SIZE; // Чтение нужной страницы - HAL_EEPROM_Read(&heeprom, addr, read_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); + HAL_EEPROM_Read(&heeprom, (uint16_t)addr, read_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); // Адрес искомого слова в eeprom: EEPROM_START_ADDR + (uint32_t)idx uint32_t word_addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_WORD_SIZE) * EEPROM_WORD_SIZE; // Индекс искомого слова в массиве read_data_buf: адрес слова в eeprom за вычетом адреса начала страницы @@ -43,12 +43,12 @@ uint8_t EEPROMClass:: read( int idx ) // Номер байта в составе слова uint32_t byte_idx = ((uint32_t)idx) % EEPROM_WORD_SIZE; // Вычленение нужного байта из страницы - return (uint8_t)(( read_data_buf[word_idx] & ((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1)) * 8) ) >> ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)); + return (uint8_t)(( read_data_buf[word_idx] & (((uint32_t)0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)) ) >> ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)); } void EEPROMClass:: write( int idx, uint8_t val ) { - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) + if (((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) || (idx < 0)) return; uint32_t write_data_buf[EEPROM_PAGE_WORDS] = {}; @@ -56,7 +56,7 @@ void EEPROMClass:: write( int idx, uint8_t val ) // Вычисление адресы начала нужной страницы uint32_t addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_PAGE_SIZE) * EEPROM_PAGE_SIZE; // Читаем нужную страницу - HAL_EEPROM_Read(&heeprom, addr, write_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); + HAL_EEPROM_Read(&heeprom, (uint16_t)addr, write_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); // Адрес искомого слова в eeprom: EEPROM_START_ADDR + (uint32_t)idx uint32_t word_addr = EEPROM_START_ADDR + (((uint32_t)idx) / EEPROM_WORD_SIZE) * EEPROM_WORD_SIZE; // Индекс искомого слова в массиве write_data_buf: адрес слова в eeprom за вычетом адреса начала страницы @@ -64,17 +64,20 @@ void EEPROMClass:: write( int idx, uint8_t val ) // Номер байта в составе слова uint32_t byte_idx = ((uint32_t)idx) % EEPROM_WORD_SIZE; // Извлечение нужного байта - uint32_t byte = ((uint32_t)val) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8); + uint32_t byte = (((uint32_t)val) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)); // Вычленение и замена нужного байта из страницы - write_data_buf[word_idx] = (write_data_buf[word_idx] & (~((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1)) * 8))) | byte; + write_data_buf[word_idx] = (write_data_buf[word_idx] & (~(((uint32_t)0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)))) | byte; + + // Очистка нужной страницы + HAL_EEPROM_Erase(&heeprom, (uint16_t)addr, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); - HAL_EEPROM_Write(&heeprom, EEPROM_START_ADDR, write_data_buf, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); + HAL_EEPROM_Write(&heeprom, (uint16_t)addr, write_data_buf, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); } // Делает то же, что и write, но записывает только если новый байт отличается от уже записанного void EEPROMClass:: update( int idx, uint8_t val ) { - if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) + if (((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) || (idx < 0)) return; uint32_t write_data_buf[EEPROM_PAGE_WORDS] = {}; @@ -92,23 +95,24 @@ void EEPROMClass:: update( int idx, uint8_t val ) // Извлечение нужного байта uint32_t byte = ((uint32_t)val) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8); // Проверка того, что записанный байт отличается от нового - if((write_data_buf[word_idx] & ((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1)) * 8)) != byte) + if((uint8_t)(( write_data_buf[word_idx] & (((uint32_t)0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)) ) >> ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)) != val) { + // Очистка нужной страницы + HAL_EEPROM_Erase(&heeprom, (uint16_t)addr, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); // Вычленение и замена нужного байта из страницы - write_data_buf[word_idx] = (write_data_buf[word_idx] & (~((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1)) * 8))) | byte; - HAL_EEPROM_Write(&heeprom, EEPROM_START_ADDR, write_data_buf, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); + write_data_buf[word_idx] = (write_data_buf[word_idx] & (~((uint32_t)(0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)))) | byte; + HAL_EEPROM_Write(&heeprom, (uint16_t)addr, write_data_buf, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT); } } uint16_t EEPROMClass:: length( void ) { - return EEPROM_LENGHT; + return (uint16_t)EEPROM_LENGHT; } template< typename T > const T& EEPROMClass:: put(int idx, const T &t) { - // Создание объекта EEPtr, который указывает на начальный адрес в EEPROM. - EEPtr e = idx; + uint16_t ee_idx = (uint16_t)idx; // Указатель на данные, которые нужно записать в EEPROM. const uint8_t *ptr = (const uint8_t*) &t; @@ -117,29 +121,20 @@ const T& EEPROMClass:: put(int idx, const T &t) { int count = sizeof(T); // Цикл для записи данных побайтно в EEPROM. - for(; count ; --count, ++e) { + for(uint16_t i = 0; i < sizeof(T); i++) { // Запись текущего байта данных в EEPROM. - (*e).update( *ptr++ ); + EEPROM.update(ee_idx + i, *ptr++ ); } // Возврат ссылки на записанный объект. return t; } - +template< typename T > T& EEPROMClass:: get(int idx, T &t) { - EEPtr e = idx; // Указатель на адрес в EEPROM - uint8_t *ptr = (uint8_t*) &t; // Преобразуем ссылку на объект данных в указатель на байт - for (int count = sizeof(T); count; --count, ++e) { - *ptr++ = *e; // Читаем данные из EEPROM и записываем в объект - } + // EEPtr e = idx; // Указатель на адрес в EEPROM + // uint8_t *ptr = (uint8_t*) &t; // Преобразуем ссылку на объект данных в указатель на байт + // for (int count = sizeof(T); count; --count, ++e) { + // *ptr++ = *e; // Читаем данные из EEPROM и записываем в объект + // } return t; // Возвращаем ссылку на переданный объект с прочитанными данными -} - - - -// uint32_t* EEPROM_Read(uint16_t index) -// { -// uint32_t read_data_buf[]; -// HAL_EEPROM_Read(&heeprom, 0x1C00 + index, read_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT); -// return read_data_buf; -// } \ No newline at end of file +} \ No newline at end of file diff --git a/libraries/EEPROM/src/EEPROM.h b/libraries/EEPROM/src/EEPROM.h index f770fe5..bca64a2 100644 --- a/libraries/EEPROM/src/EEPROM.h +++ b/libraries/EEPROM/src/EEPROM.h @@ -31,48 +31,48 @@ 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 ) {} +// EERef( const int index ) +// : index( index ) {} - //Access/read members. - uint8_t operator*() const { return eeprom_read_byte( (uint8_t*) index ); } - operator uint8_t() const { return **this; } +// //Access/read members. +// uint8_t operator*() const { return eeprom_read_byte( (uint8_t*) index ); } +// 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; } - 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; } +// //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; } +// 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; } +// EERef &update( uint8_t in ) { return in != *this ? *this = in : *this; } - /** Prefix increment/decrement **/ - EERef& operator++() { return *this += 1; } - EERef& operator--() { return *this -= 1; } +// /** 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; - } +// /** 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; - } +// uint8_t operator-- (int){ +// uint8_t ret = **this; +// return --(*this), ret; +// } - int index; //Index of current EEPROM cell. -}; +// int index; //Index of current EEPROM cell. +// }; /*** EEPtr class. @@ -82,26 +82,26 @@ struct EERef{ increment/decrement operators. ***/ -struct EEPtr{ +// struct EEPtr{ - EEPtr( const int index ) - : index( index ) {} +// EEPtr( const int index ) +// : index( index ) {} - operator int() const { return index; } - EEPtr &operator=( int in ) { return index = in, *this; } +// 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; } +// //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; } - EEPtr operator++ (int) { return index++; } - EEPtr operator-- (int) { return index--; } +// /** Prefix & Postfix increment/decrement **/ +// EEPtr& operator++() { return ++index, *this; } +// EEPtr& operator--() { return --index, *this; } +// EEPtr operator++ (int) { return index++; } +// EEPtr operator-- (int) { return index--; } - int index; //Index of current EEPROM cell. -}; +// int index; //Index of current EEPROM cell. +// }; /*** EEPROMClass class. @@ -114,14 +114,14 @@ struct EEPtr{ struct EEPROMClass{ //Basic user access methods. - EERef operator[]( const int idx ) { return idx; } + // EERef operator[]( const int idx ) { return idx; } uint8_t read( int idx ); void write( int idx, uint8_t val ); void update( int idx, uint8_t val ); //STL and C++11 iteration capability. - EEPtr begin(); - EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid. + void begin(); + uint16_t end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid. uint16_t length(); template