Changed I2C default instance to use placement new

pull/10711/head
Christopher Haster 2018-07-25 11:40:00 -05:00
parent ffcc850104
commit b440d72114
2 changed files with 5 additions and 2 deletions

View File

@ -23,7 +23,7 @@ I2CEEBlockDevice::I2CEEBlockDevice(
bd_size_t size, bd_size_t block, int freq)
: _i2c_addr(addr), _size(size), _block(block)
{
_i2c = new I2C(sda, scl);
_i2c = new (_i2c_buffer) I2C(sda, scl);
_i2c->frequency(freq);
}
@ -36,7 +36,9 @@ I2CEEBlockDevice::I2CEEBlockDevice(
}
I2CEEBlockDevice::~I2CEEBlockDevice()
{
_i2c->~I2C();
if (_i2c == (I2C*)_i2c_buffer) {
_i2c->~I2C();
}
}
int I2CEEBlockDevice::init()

View File

@ -159,6 +159,7 @@ public:
private:
I2C * _i2c;
uint32_t _i2c_buffer[sizeof(I2C) / sizeof(uint32_t)];
uint8_t _i2c_addr;
uint32_t _size;
uint32_t _block;