Simplify eeprom.c
This commit is contained in:
@@ -10,7 +10,7 @@ bool IsEepromBusy;
|
|||||||
static eeprom_operation_t CurrentEepromOperation;
|
static eeprom_operation_t CurrentEepromOperation;
|
||||||
static config_buffer_id_t CurrentConfigBufferId;
|
static config_buffer_id_t CurrentConfigBufferId;
|
||||||
status_t LastEepromTransferStatus;
|
status_t LastEepromTransferStatus;
|
||||||
void (*SuccessCallback)();
|
void (*SuccessCallback)(void);
|
||||||
|
|
||||||
static i2c_master_handle_t i2cHandle;
|
static i2c_master_handle_t i2cHandle;
|
||||||
static i2c_master_transfer_t i2cTransfer;
|
static i2c_master_transfer_t i2cTransfer;
|
||||||
@@ -21,7 +21,6 @@ static uint16_t eepromStartAddress;
|
|||||||
static uint16_t sourceLength;
|
static uint16_t sourceLength;
|
||||||
static uint8_t writeLength;
|
static uint8_t writeLength;
|
||||||
static bool isReadSent;
|
static bool isReadSent;
|
||||||
static uint8_t addressBuffer[EEPROM_ADDRESS_LENGTH];
|
|
||||||
|
|
||||||
static status_t i2cAsyncWrite(uint8_t *data, size_t dataSize)
|
static status_t i2cAsyncWrite(uint8_t *data, size_t dataSize)
|
||||||
{
|
{
|
||||||
@@ -44,8 +43,7 @@ static status_t i2cAsyncRead(uint8_t *data, size_t dataSize)
|
|||||||
static status_t writePage(void)
|
static status_t writePage(void)
|
||||||
{
|
{
|
||||||
static uint8_t buffer[EEPROM_BUFFER_SIZE];
|
static uint8_t buffer[EEPROM_BUFFER_SIZE];
|
||||||
uint16_t targetEepromOffset = sourceOffset + eepromStartAddress;
|
SetBufferUint16Be(buffer, 0, eepromStartAddress + sourceOffset);
|
||||||
SetBufferUint16Be(buffer, 0, targetEepromOffset);
|
|
||||||
writeLength = MIN(sourceLength - sourceOffset, EEPROM_PAGE_SIZE);
|
writeLength = MIN(sourceLength - sourceOffset, EEPROM_PAGE_SIZE);
|
||||||
memcpy(buffer+EEPROM_ADDRESS_LENGTH, sourceBuffer+sourceOffset, writeLength);
|
memcpy(buffer+EEPROM_ADDRESS_LENGTH, sourceBuffer+sourceOffset, writeLength);
|
||||||
status_t status = i2cAsyncWrite(buffer, writeLength+EEPROM_ADDRESS_LENGTH);
|
status_t status = i2cAsyncWrite(buffer, writeLength+EEPROM_ADDRESS_LENGTH);
|
||||||
@@ -104,15 +102,16 @@ status_t EEPROM_LaunchTransfer(eeprom_operation_t operation, config_buffer_id_t
|
|||||||
|
|
||||||
CurrentEepromOperation = operation;
|
CurrentEepromOperation = operation;
|
||||||
CurrentConfigBufferId = config_buffer_id;
|
CurrentConfigBufferId = config_buffer_id;
|
||||||
|
|
||||||
SuccessCallback = successCallback;
|
SuccessCallback = successCallback;
|
||||||
|
|
||||||
bool isHardwareConfig = CurrentConfigBufferId == ConfigBufferId_HardwareConfig;
|
bool isHardwareConfig = CurrentConfigBufferId == ConfigBufferId_HardwareConfig;
|
||||||
eepromStartAddress = isHardwareConfig ? 0 : HARDWARE_CONFIG_SIZE;
|
eepromStartAddress = isHardwareConfig ? 0 : HARDWARE_CONFIG_SIZE;
|
||||||
SetBufferUint16Be(addressBuffer, 0, eepromStartAddress);
|
|
||||||
|
|
||||||
switch (CurrentEepromOperation) {
|
switch (CurrentEepromOperation) {
|
||||||
case EepromOperation_Read:
|
case EepromOperation_Read:
|
||||||
isReadSent = false;
|
isReadSent = false;
|
||||||
|
uint8_t addressBuffer[EEPROM_ADDRESS_LENGTH];
|
||||||
|
SetBufferUint16Be(addressBuffer, 0, eepromStartAddress);
|
||||||
LastEepromTransferStatus = i2cAsyncWrite(addressBuffer, EEPROM_ADDRESS_LENGTH);
|
LastEepromTransferStatus = i2cAsyncWrite(addressBuffer, EEPROM_ADDRESS_LENGTH);
|
||||||
break;
|
break;
|
||||||
case EepromOperation_Write:
|
case EepromOperation_Write:
|
||||||
|
|||||||
Reference in New Issue
Block a user