Дописал get и put, починил

This commit is contained in:
EgorShin committed 2024-10-08 12:31:18 +07:00
1 parent 55c17cf2b6
commit 577171f58f
2 files changed
+15 -64

No files matched your search

+5 -2
View File
@@ -87,14 +87,17 @@ void EEPROMClass:: update( 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);
// uint8_t oldVal = (uint8_t)(( write_data_buf[word_idx] & (((uint32_t)0xFF) << ((EEPROM_WORD_SIZE - byte_idx - 1) * 8)) ) >> ((EEPROM_WORD_SIZE - byte_idx - 1) * 8));
uint8_t oldVal = (uint8_t)(*((uint8_t*)write_data_buf + word_idx + (EEPROM_WORD_SIZE - byte_idx - 1)));
// Проверка того, что записанный байт отличается от нового
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)
if( oldVal != 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, (uint16_t)addr, write_data_buf, EEPROM_PAGE_WORDS, HAL_EEPROM_WRITE_SINGLE, EEPROM_OP_TIMEOUT);
}
}