Skip to content

Commit b440d72

Browse files
committed
Changed I2C default instance to use placement new
1 parent ffcc850 commit b440d72

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

I2CEEBlockDevice.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ I2CEEBlockDevice::I2CEEBlockDevice(
2323
bd_size_t size, bd_size_t block, int freq)
2424
: _i2c_addr(addr), _size(size), _block(block)
2525
{
26-
_i2c = new I2C(sda, scl);
26+
_i2c = new (_i2c_buffer) I2C(sda, scl);
2727
_i2c->frequency(freq);
2828
}
2929

@@ -36,7 +36,9 @@ I2CEEBlockDevice::I2CEEBlockDevice(
3636
}
3737
I2CEEBlockDevice::~I2CEEBlockDevice()
3838
{
39-
_i2c->~I2C();
39+
if (_i2c == (I2C*)_i2c_buffer) {
40+
_i2c->~I2C();
41+
}
4042
}
4143

4244
int I2CEEBlockDevice::init()

I2CEEBlockDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class I2CEEBlockDevice : public BlockDevice {
159159

160160
private:
161161
I2C * _i2c;
162+
uint32_t _i2c_buffer[sizeof(I2C) / sizeof(uint32_t)];
162163
uint8_t _i2c_addr;
163164
uint32_t _size;
164165
uint32_t _block;

0 commit comments

Comments
 (0)