@@ -64,34 +64,34 @@ int I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
64
64
65
65
auto *charBuffer = reinterpret_cast <char *>(buffer);
66
66
67
- auto const handler = [&](const bd_addr_t &pagedStart, const bd_size_t &pagedLength,
68
- const uint8_t &pagedDeviceAddress) -> int
69
- {
67
+ auto const handler = [&](const bd_addr_t &pagedStart, const bd_size_t &pagedLength, const uint8_t &pagedDeviceAddress) -> int {
70
68
_i2c->start ();
71
69
72
70
if (1 != _i2c->write (pagedDeviceAddress))
73
71
{
74
72
return BD_ERROR_DEVICE_ERROR;
75
73
}
76
74
77
- if (!_address_is_eight_bit && 1 != _i2c->write ((char ) (pagedStart >> 8u )))
75
+ if (!_address_is_eight_bit && 1 != _i2c->write ((char )(pagedStart >> 8u )))
78
76
{
79
77
return BD_ERROR_DEVICE_ERROR;
80
78
}
81
79
82
- if (1 != _i2c->write ((char ) (pagedStart & 0xffu )))
80
+ if (1 != _i2c->write ((char )(pagedStart & 0xffu )))
83
81
{
84
82
return BD_ERROR_DEVICE_ERROR;
85
83
}
86
84
87
85
_i2c->stop ();
88
86
89
87
auto err = _sync ();
90
- if (err) {
88
+ if (err)
89
+ {
91
90
return err;
92
91
}
93
92
94
- if (0 != _i2c->read (_i2c_addr, charBuffer, pagedLength)) {
93
+ if (0 != _i2c->read (_i2c_addr, charBuffer, pagedLength))
94
+ {
95
95
return BD_ERROR_DEVICE_ERROR;
96
96
}
97
97
@@ -110,9 +110,7 @@ int I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
110
110
111
111
auto const *charBuffer = reinterpret_cast <char const *>(buffer);
112
112
113
- auto const handler = [&](const bd_addr_t &pagedStart, const bd_size_t &pagedLength,
114
- const uint8_t &pagedDeviceAddress) -> int
115
- {
113
+ auto const handler = [&](const bd_addr_t &pagedStart, const bd_size_t &pagedLength, const uint8_t &pagedDeviceAddress) -> int {
116
114
// While we have some more data to write.
117
115
while (size > 0 )
118
116
{
@@ -121,25 +119,20 @@ int I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size
121
119
122
120
_i2c->start ();
123
121
124
- if (1 != _i2c->write (pagedDeviceAddress))
125
- {
122
+ if (1 != _i2c->write (pagedDeviceAddress)) {
126
123
return BD_ERROR_DEVICE_ERROR;
127
124
}
128
125
129
- if (!_address_is_eight_bit && 1 != _i2c->write ((char ) (pagedStart >> 8u )))
130
- {
126
+ if (!_address_is_eight_bit && 1 != _i2c->write ((char )(pagedStart >> 8u ))) {
131
127
return BD_ERROR_DEVICE_ERROR;
132
128
}
133
129
134
- if (1 != _i2c->write ((char ) (addr & 0xffu )))
135
- {
130
+ if (1 != _i2c->write ((char )(addr & 0xffu ))) {
136
131
return BD_ERROR_DEVICE_ERROR;
137
132
}
138
133
139
- for (unsigned i = 0 ; i < chunk; i++)
140
- {
141
- if (1 != _i2c->write (charBuffer[i]))
142
- {
134
+ for (unsigned i = 0 ; i < chunk; i++) {
135
+ if (1 != _i2c->write (charBuffer[i])) {
143
136
return BD_ERROR_DEVICE_ERROR;
144
137
}
145
138
}
@@ -224,8 +217,7 @@ int I2CEEBlockDevice::do_paged(const bd_addr_t &startAddress,
224
217
225
218
auto const pageSize = 256 ;
226
219
bd_size_t lengthDone = 0 ;
227
- while (lengthDone != length)
228
- {
220
+ while (lengthDone != length) {
229
221
/* Integer division => Round down */
230
222
uint8_t const currentPage = currentStartAddress / pageSize;
231
223
bd_addr_t const nextPageBegin = (currentPage + 1 ) * pageSize;
@@ -235,8 +227,7 @@ int I2CEEBlockDevice::do_paged(const bd_addr_t &startAddress,
235
227
uint8_t const pagedDeviceAddress = get_paged_device_address (currentPage);
236
228
237
229
auto const handlerReturn = handler (pagedBegin, currentLength, pagedDeviceAddress);
238
- if (handlerReturn != BD_ERROR_OK)
239
- {
230
+ if (handlerReturn != BD_ERROR_OK) {
240
231
return handlerReturn;
241
232
}
242
233
@@ -249,12 +240,9 @@ int I2CEEBlockDevice::do_paged(const bd_addr_t &startAddress,
249
240
250
241
uint8_t I2CEEBlockDevice::get_paged_device_address (const uint8_t &page)
251
242
{
252
- if (!this ->_address_is_eight_bit )
253
- {
243
+ if (!this ->_address_is_eight_bit ) {
254
244
return this ->_i2c_addr ;
255
- }
256
- else
257
- {
245
+ } else {
258
246
// This method uses a dynamically created bit mask for the page given.
259
247
// This ensures compatibility with all sizes of ICs.
260
248
// E. g. the 512K variants have two user address bits and one page bit.
@@ -265,8 +253,7 @@ uint8_t I2CEEBlockDevice::get_paged_device_address(const uint8_t &page)
265
253
uint8_t i = 1 ;
266
254
uint8_t addressMask = 0 ;
267
255
auto p = page;
268
- while (p != 0u )
269
- {
256
+ while (p != 0u ) {
270
257
addressMask |= (1u << i);
271
258
p >>= 1u ;
272
259
i++;
0 commit comments