Deal with NAKs in the I2C callback while the EEPROM is busy persisting the data.
This commit is contained in:
@@ -14,6 +14,7 @@ static i2c_master_transfer_t i2cTransfer;
|
||||
static uint8_t *sourceBuffer;
|
||||
static uint16_t sourceOffset;
|
||||
static uint16_t sourceLength;
|
||||
static uint8_t writeLength;
|
||||
|
||||
static status_t i2cAsyncWrite(uint8_t *data, size_t dataSize)
|
||||
{
|
||||
@@ -38,19 +39,15 @@ static status_t writePage()
|
||||
static uint8_t buffer[EEPROM_BUFFER_SIZE];
|
||||
buffer[0] = sourceOffset & 0xff;
|
||||
buffer[1] = sourceOffset >> 8;
|
||||
uint8_t writeLength = MIN(sourceLength - sourceOffset, EEPROM_PAGE_SIZE);
|
||||
writeLength = MIN(sourceLength - sourceOffset, EEPROM_PAGE_SIZE);
|
||||
memcpy(buffer+EEPROM_ADDRESS_LENGTH, sourceBuffer+sourceOffset, writeLength);
|
||||
status_t status = i2cAsyncWrite(buffer, writeLength+EEPROM_ADDRESS_LENGTH);
|
||||
sourceOffset += writeLength;
|
||||
return status;
|
||||
}
|
||||
|
||||
static void i2cCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t status, void *userData)
|
||||
{
|
||||
LastEepromTransferStatus = status;
|
||||
if (status != kStatus_Success) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool isHardwareConfig = CurrentEepromTransfer == EepromTransfer_ReadHardwareConfiguration;
|
||||
switch (CurrentEepromTransfer) {
|
||||
@@ -64,6 +61,9 @@ static void i2cCallback(I2C_Type *base, i2c_master_handle_t *handle, status_t st
|
||||
break;
|
||||
case EepromTransfer_WriteHardwareConfiguration:
|
||||
case EepromTransfer_WriteUserConfiguration:
|
||||
if (status == kStatus_Success) {
|
||||
sourceOffset += writeLength;
|
||||
}
|
||||
IsEepromBusy = sourceOffset < sourceLength;
|
||||
if (!IsEepromBusy) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user