Skip to content

Commit f3272ad

Browse files
committed
Updated to match API changes in mbed OS
1 parent ec88f78 commit f3272ad

File tree

3 files changed

+28
-37
lines changed

3 files changed

+28
-37
lines changed

I2CEEBlockDevice.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,20 @@ I2CEEBlockDevice::I2CEEBlockDevice(
2626
_i2c.frequency(freq);
2727
}
2828

29-
bd_error_t I2CEEBlockDevice::init()
29+
int I2CEEBlockDevice::init()
3030
{
3131
return _sync();
3232
}
3333

34-
bd_error_t I2CEEBlockDevice::deinit()
34+
int I2CEEBlockDevice::deinit()
3535
{
3636
return 0;
3737
}
3838

39-
bd_error_t I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
39+
int I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
4040
{
4141
// Check the address and size fit onto the chip.
42-
if (!is_valid_read(addr, size)) {
43-
return BD_ERROR_PARAMETER;
44-
}
42+
MBED_ASSERT(is_valid_read(addr, size));
4543

4644
_i2c.start();
4745
if (!_i2c.write(_i2c_addr | 0) ||
@@ -58,12 +56,10 @@ bd_error_t I2CEEBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
5856
return 0;
5957
}
6058

61-
bd_error_t I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
59+
int I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
6260
{
6361
// Check the addr and size fit onto the chip.
64-
if (!is_valid_program(addr, size)) {
65-
return BD_ERROR_PARAMETER;
66-
}
62+
MBED_ASSERT(is_valid_program(addr, size));
6763

6864
// While we have some more data to write.
6965
while (size > 0) {
@@ -82,7 +78,7 @@ bd_error_t I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size
8278
}
8379
_i2c.stop();
8480

85-
bd_error_t err = _sync();
81+
int err = _sync();
8682
if (err) {
8783
return err;
8884
}
@@ -95,13 +91,13 @@ bd_error_t I2CEEBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size
9591
return 0;
9692
}
9793

98-
bd_error_t I2CEEBlockDevice::erase(bd_addr_t addr, bd_size_t size)
94+
int I2CEEBlockDevice::erase(bd_addr_t addr, bd_size_t size)
9995
{
10096
// No erase needed
10197
return 0;
10298
}
10399

104-
bd_error_t I2CEEBlockDevice::_sync()
100+
int I2CEEBlockDevice::_sync()
105101
{
106102
// The chip doesn't ACK while writing to the actual EEPROM
107103
// so loop trying to do a zero byte write until it is ACKed
@@ -117,22 +113,22 @@ bd_error_t I2CEEBlockDevice::_sync()
117113
return BD_ERROR_DEVICE_ERROR;
118114
}
119115

120-
bd_size_t I2CEEBlockDevice::get_read_size()
116+
bd_size_t I2CEEBlockDevice::get_read_size() const
121117
{
122118
return 1;
123119
}
124120

125-
bd_size_t I2CEEBlockDevice::get_program_size()
121+
bd_size_t I2CEEBlockDevice::get_program_size() const
126122
{
127123
return 1;
128124
}
129125

130-
bd_size_t I2CEEBlockDevice::get_erase_size()
126+
bd_size_t I2CEEBlockDevice::get_erase_size() const
131127
{
132128
return 1;
133129
}
134130

135-
bd_size_t I2CEEBlockDevice::size()
131+
bd_size_t I2CEEBlockDevice::size() const
136132
{
137133
return _size;
138134
}

I2CEEBlockDevice.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
#ifndef MBED_I2CEEPROM_BLOCK_DEVICE_H
1717
#define MBED_I2CEEPROM_BLOCK_DEVICE_H
18-
19-
/* If the target has no I2C support then I2CEEPROM is not supported */
20-
#ifdef DEVICE_I2C
2118

2219
#include <mbed.h>
2320
#include "BlockDevice.h"
@@ -71,13 +68,13 @@ class I2CEEBlockDevice : public BlockDevice {
7168
*
7269
* @return 0 on success or a negative error code on failure
7370
*/
74-
virtual bd_error_t init();
71+
virtual int init();
7572

7673
/** Deinitialize a block device
7774
*
7875
* @return 0 on success or a negative error code on failure
7976
*/
80-
virtual bd_error_t deinit();
77+
virtual int deinit();
8178

8279
/** Read blocks from a block device
8380
*
@@ -86,7 +83,7 @@ class I2CEEBlockDevice : public BlockDevice {
8683
* @param size Size to read in bytes, must be a multiple of read block size
8784
* @return 0 on success, negative error code on failure
8885
*/
89-
virtual bd_error_t read(void *buffer, bd_addr_t addr, bd_size_t size);
86+
virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
9087

9188
/** Program blocks to a block device
9289
*
@@ -97,7 +94,7 @@ class I2CEEBlockDevice : public BlockDevice {
9794
* @param size Size to write in bytes, must be a multiple of program block size
9895
* @return 0 on success, negative error code on failure
9996
*/
100-
virtual bd_error_t program(const void *buffer, bd_addr_t addr, bd_size_t size);
97+
virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
10198

10299
/** Erase blocks on a block device
103100
*
@@ -107,43 +104,42 @@ class I2CEEBlockDevice : public BlockDevice {
107104
* @param size Size to erase in bytes, must be a multiple of erase block size
108105
* @return 0 on success, negative error code on failure
109106
*/
110-
virtual bd_error_t erase(bd_addr_t addr, bd_size_t size);
107+
virtual int erase(bd_addr_t addr, bd_size_t size);
111108

112109
/** Get the size of a readable block
113110
*
114111
* @return Size of a readable block in bytes
115112
*/
116-
virtual bd_size_t get_read_size();
113+
virtual bd_size_t get_read_size() const;
117114

118115
/** Get the size of a programable block
119116
*
120117
* @return Size of a programable block in bytes
121118
* @note Must be a multiple of the read size
122119
*/
123-
virtual bd_size_t get_program_size();
120+
virtual bd_size_t get_program_size() const;
124121

125122
/** Get the size of a eraseable block
126123
*
127124
* @return Size of a eraseable block in bytes
128125
* @note Must be a multiple of the program size
129126
*/
130-
virtual bd_size_t get_erase_size();
127+
virtual bd_size_t get_erase_size() const;
131128

132129
/** Get the total size of the underlying device
133130
*
134131
* @return Size of the underlying device in bytes
135132
*/
136-
virtual bd_size_t size();
133+
virtual bd_size_t size() const;
137134

138135
private:
139136
I2C _i2c;
140137
uint8_t _i2c_addr;
141138
uint32_t _size;
142139
uint32_t _block;
143140

144-
bd_error_t _sync();
141+
int _sync();
145142
};
146143

147-
#endif /* DEVICE_SPI */
148144

149145
#endif /* MBED_SD_BLOCK_DEVICE_H */

TESTS/block_device/i2cee/main.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
using namespace utest::v1;
1010

11-
//#if !I2CEE_INSTALLED
12-
//#error [NOT_SUPPORTED] I2CEE Required
13-
//#endif
14-
1511
#define TEST_PINS D14, D15
1612
#define TEST_ADDR 0xa0
1713
#define TEST_SIZE 32*1024
@@ -22,7 +18,7 @@ using namespace utest::v1;
2218

2319
const struct {
2420
const char *name;
25-
bd_size_t (BlockDevice::*method)();
21+
bd_size_t (BlockDevice::*method)() const;
2622
} ATTRS[] = {
2723
{"read size", &BlockDevice::get_read_size},
2824
{"program size", &BlockDevice::get_program_size},
@@ -73,7 +69,10 @@ void test_read_write() {
7369
// Write, sync, and read the block
7470
printf("test %0*llx:%llu...\n", addrwidth, block, block_size);
7571

76-
err = bd.write(write_block, block, block_size);
72+
err = bd.erase(block, block_size);
73+
TEST_ASSERT_EQUAL(0, err);
74+
75+
err = bd.program(write_block, block, block_size);
7776
TEST_ASSERT_EQUAL(0, err);
7877

7978
printf("write %0*llx:%llu ", addrwidth, block, block_size);

0 commit comments

Comments
 (0)