summaryrefslogtreecommitdiff
path: root/main/i2c.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2022-11-07 12:01:29 +1100
committerjacqueline <me@jacqueline.id.au>2022-11-07 12:01:29 +1100
commit28d73ad8660e27f9c7b20b6e978d3d0c412dec00 (patch)
treec50b739ae4712f5ddb9fb6e44e39e01e4c20356d /main/i2c.cpp
parentb13a9793e17e7e0e52ea08fa5fb69ca9b90ad56d (diff)
downloadtangara-fw-28d73ad8660e27f9c7b20b6e978d3d0c412dec00.tar.gz
Split driver-y things into a separate component
Diffstat (limited to 'main/i2c.cpp')
-rw-r--r--main/i2c.cpp51
1 files changed, 0 insertions, 51 deletions
diff --git a/main/i2c.cpp b/main/i2c.cpp
deleted file mode 100644
index d3bfaa59..00000000
--- a/main/i2c.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "i2c.hpp"
-#include <cstdint>
-
-#include "assert.h"
-#include "driver/i2c.h"
-
-namespace gay_ipod {
-
-static constexpr int kCmdLinkSize = I2C_LINK_RECOMMENDED_SIZE(12);
-
-I2CTransaction::I2CTransaction() {
- // Use a fixed size buffer to avoid many many tiny allocations.
- buffer_ = (uint8_t*)calloc(sizeof(uint8_t), kCmdLinkSize);
- handle_ = i2c_cmd_link_create_static(buffer_, kCmdLinkSize);
- assert(handle_ != NULL && "failed to create command link");
-}
-
-I2CTransaction::~I2CTransaction() {
- free(buffer_);
-}
-
-esp_err_t I2CTransaction::Execute() {
- return i2c_master_cmd_begin(I2C_NUM_0, handle_, kI2CTimeout);
-}
-
-I2CTransaction& I2CTransaction::start() {
- ESP_ERROR_CHECK(i2c_master_start(handle_));
- return *this;
-}
-
-I2CTransaction& I2CTransaction::stop() {
- ESP_ERROR_CHECK(i2c_master_stop(handle_));
- return *this;
-}
-
-I2CTransaction& I2CTransaction::write_addr(uint8_t addr, uint8_t op) {
- write_ack(addr << 1 | op);
- return *this;
-}
-
-I2CTransaction& I2CTransaction::write_ack(uint8_t data) {
- ESP_ERROR_CHECK(i2c_master_write_byte(handle_, data, true));
- return *this;
-}
-
-I2CTransaction& I2CTransaction::read(uint8_t* dest, i2c_ack_type_t ack) {
- ESP_ERROR_CHECK(i2c_master_read_byte(handle_, dest, ack));
- return *this;
-}
-
-} // namespace gay_ipod