|
|
|
@ -1,16 +1,22 @@ |
|
|
|
|
#include "i2c.hpp" |
|
|
|
|
#include <cstdint> |
|
|
|
|
|
|
|
|
|
#include "assert.h" |
|
|
|
|
#include "driver/i2c.h" |
|
|
|
|
|
|
|
|
|
namespace gay_ipod { |
|
|
|
|
|
|
|
|
|
I2CTransaction::I2CTransaction() { |
|
|
|
|
handle_ = i2c_cmd_link_create(); |
|
|
|
|
// Use a fixed size buffer to avoid many many tiny allocations.
|
|
|
|
|
// TODO: make this static and tune the size. possibly make it optional too?
|
|
|
|
|
// threading.
|
|
|
|
|
buffer_ = (uint8_t*) calloc(sizeof(uint8_t), I2C_LINK_RECOMMENDED_SIZE(10)); |
|
|
|
|
handle_ = i2c_cmd_link_create_static(buffer_, I2C_LINK_RECOMMENDED_SIZE(10)); |
|
|
|
|
assert(handle_ != NULL && "failed to create command link"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
I2CTransaction::~I2CTransaction() { |
|
|
|
|
i2c_cmd_link_delete(handle_); |
|
|
|
|
free(buffer_); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
esp_err_t I2CTransaction::Execute() { |
|
|
|
|