Дописал циклическую запись и чтение
This commit is contained in:
1 parent
690acb404c
commit
c9f5563111
2 files changed
+31
-128
No files matched your search
@@ -19,12 +19,14 @@ void EEPROMClass:: begin()
|
||||
uint8_t EEPROMClass:: read( int idx )
|
||||
{
|
||||
// Проверка адекватности адреса idx
|
||||
if (((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) || (idx < 0))
|
||||
return 0x0; // #TODO Добавить сообщение об ошибке
|
||||
if (idx < 0)
|
||||
idx = -idx;
|
||||
if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT)
|
||||
idx = (int)((uint32_t)idx % EEPROM_LENGHT);
|
||||
|
||||
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, (uint16_t)addr, read_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT);
|
||||
@@ -41,12 +43,14 @@ uint8_t EEPROMClass:: read( int idx )
|
||||
void EEPROMClass:: write( int idx, uint8_t val )
|
||||
{
|
||||
// Проверка адекватности адреса idx
|
||||
if (((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) || (idx < 0))
|
||||
return; // #TODO Добавить сообщение об ошибке
|
||||
if (idx < 0)
|
||||
idx = -idx;
|
||||
if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT)
|
||||
idx = (int)((uint32_t)idx % EEPROM_LENGHT);
|
||||
|
||||
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, (uint16_t)addr, write_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT);
|
||||
@@ -71,12 +75,14 @@ void EEPROMClass:: write( int idx, uint8_t val )
|
||||
void EEPROMClass:: update( int idx, uint8_t val )
|
||||
{
|
||||
// Проверка адекватности адреса idx
|
||||
if (((uint32_t)idx >= (uint32_t)EEPROM_LENGHT) || (idx < 0))
|
||||
return; // #TODO Добавить сообщение об ошибке
|
||||
if (idx < 0)
|
||||
idx = -idx;
|
||||
if ((uint32_t)idx >= (uint32_t)EEPROM_LENGHT)
|
||||
idx = (int)((uint32_t)idx % EEPROM_LENGHT);
|
||||
|
||||
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, (uint16_t)addr, write_data_buf, EEPROM_PAGE_WORDS, EEPROM_OP_TIMEOUT);
|
||||
|
||||
Reference in new issue
Block a user