Skip to content

Commit 52aed22

Browse files
committed
Refactor paged_handler to directly give the paged device address.
1 parent 8d1978e commit 52aed22

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ int I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
6464

6565
auto *charBuffer = reinterpret_cast<char *>(buffer);
6666

67-
auto const handler = [&](const bd_addr_t &pagedStart, const bd_size_t &pagedLength, const uint8_t &page) -> int
67+
auto const handler = [&](const bd_addr_t &pagedStart, const bd_size_t &pagedLength,
68+
const uint8_t &pagedDeviceAddress) -> int
6869
{
6970
_i2c->start();
7071

@@ -108,7 +109,8 @@ int I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
108109

109110
auto const *charBuffer = reinterpret_cast<char const *>(buffer);
110111

111-
auto const handler = [&](const bd_addr_t &pagedStart, const bd_size_t &pagedLength, const uint8_t &page) -> int
112+
auto const handler = [&](const bd_addr_t &pagedStart, const bd_size_t &pagedLength,
113+
const uint8_t &pagedDeviceAddress) -> int
112114
{
113115
// While we have some more data to write.
114116
while (size > 0) {
@@ -207,7 +209,7 @@ int I2CEEBlockDevice::do_paged(const bd_addr_t &startAddress,
207209
{
208210
// This helper is only used for eight bit mode.
209211
if (!this->_address_is_eight_bit) {
210-
return handler(startAddress, length, 0);
212+
return handler(startAddress, length, get_paged_device_address(0));
211213
}
212214

213215
auto currentStartAddress = startAddress;
@@ -222,8 +224,9 @@ int I2CEEBlockDevice::do_paged(const bd_addr_t &startAddress,
222224
bd_addr_t const currentReadEndAddressExclusive = std::min(nextPageBegin, startAddress + length);
223225
bd_size_t const currentLength = currentReadEndAddressExclusive - currentStartAddress;
224226
bd_addr_t const pagedBegin = currentStartAddress - (currentPage * pageSize);
227+
uint8_t const pagedDeviceAddress = get_paged_device_address(currentPage);
225228

226-
auto const handlerReturn = handler(pagedBegin, currentLength, currentPage);
229+
auto const handlerReturn = handler(pagedBegin, currentLength, pagedDeviceAddress);
227230
if (handlerReturn != BD_ERROR_OK)
228231
{
229232
return handlerReturn;

components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ class I2CEEBlockDevice : public BlockDevice {
181181

182182
int _sync();
183183

184-
using paged_handler = std::function<int(const bd_addr_t &address, const bd_size_t &length, const uint8_t &page)>;
184+
using paged_handler = std::function<
185+
int(const bd_addr_t &address, const bd_size_t &length, const uint8_t &deviceAddress)>;
185186

186187
/**
187188
* Executes a handler across page boundaries for eight bit mode.

0 commit comments

Comments
 (0)