Use a fixed transaction buffer size

custom
jacqueline 3 years ago
parent dab6533ae0
commit e0b68536a5
  1. 10
      main/i2c.cpp
  2. 1
      main/i2c.hpp

@ -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() {

@ -78,6 +78,7 @@ class I2CTransaction {
private:
i2c_cmd_handle_t handle_;
uint8_t *buffer_;
};
} // namespace gay_ipod

Loading…
Cancel
Save