summaryrefslogtreecommitdiff
path: root/main/i2c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main/i2c.cpp')
-rw-r--r--main/i2c.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/main/i2c.cpp b/main/i2c.cpp
index 4ae3b267..9b218f3f 100644
--- a/main/i2c.cpp
+++ b/main/i2c.cpp
@@ -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() {