Skip to content

Commit

Permalink
Remove paging and sync from I2CEEBlockDevice::read(), as it is not ne…
Browse files Browse the repository at this point in the history
…eded
  • Loading branch information
boomer41 committed Feb 19, 2020
1 parent 4d0c346 commit 440fa49
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,24 @@ int I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)

auto *pBuffer = static_cast<char *>(buffer);

while (size > 0) {
uint32_t off = addr % _block;
uint32_t chunk = (off + size < _block) ? size : (_block - off);

_i2c->start();
_i2c->start();

if (1 != _i2c->write(get_paged_device_address(addr))) {
return BD_ERROR_DEVICE_ERROR;
}

if (!_address_is_eight_bit && 1 != _i2c->write((char)(addr >> 8u))) {
return BD_ERROR_DEVICE_ERROR;
}

if (1 != _i2c->write((char)(addr & 0xffu))) {
return BD_ERROR_DEVICE_ERROR;
}

_i2c->stop();
if (1 != _i2c->write(get_paged_device_address(addr))) {
return BD_ERROR_DEVICE_ERROR;
}

auto err = _sync();
if (!_address_is_eight_bit && 1 != _i2c->write((char)(addr >> 8u))) {
return BD_ERROR_DEVICE_ERROR;
}

if (err) {
return err;
}
if (1 != _i2c->write((char)(addr & 0xffu))) {
return BD_ERROR_DEVICE_ERROR;
}

if (0 != _i2c->read(_i2c_addr, pBuffer, chunk)) {
return BD_ERROR_DEVICE_ERROR;
}
_i2c->stop();

addr += chunk;
size -= chunk;
pBuffer += chunk;
if (0 != _i2c->read(_i2c_addr, pBuffer, size)) {
return BD_ERROR_DEVICE_ERROR;
}

return BD_ERROR_OK;
Expand Down

0 comments on commit 440fa49

Please sign in to comment.