diff options
| author | jacqueline <me@jacqueline.id.au> | 2022-10-14 14:38:12 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2022-10-14 14:38:12 +1100 |
| commit | e0b68536a5c405e8e028c65c3d4e22b5b99218bd (patch) | |
| tree | 91e5e03c72a39ae0ebed6618d83ddd015d07f9d2 /main | |
| parent | dab6533ae09fff3c9611f84c5897d7f7cbfd584f (diff) | |
| download | tangara-fw-e0b68536a5c405e8e028c65c3d4e22b5b99218bd.tar.gz | |
Use a fixed transaction buffer size
Diffstat (limited to 'main')
| -rw-r--r-- | main/i2c.cpp | 10 | ||||
| -rw-r--r-- | main/i2c.hpp | 1 |
2 files changed, 9 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() { diff --git a/main/i2c.hpp b/main/i2c.hpp index 6b2de577..0993a305 100644 --- a/main/i2c.hpp +++ b/main/i2c.hpp @@ -78,6 +78,7 @@ class I2CTransaction { private: i2c_cmd_handle_t handle_; + uint8_t *buffer_; }; } // namespace gay_ipod |
