#ifndef I2C_H
#define I2C_H

#define I2C_BUS_PORT  0

#include <driver/i2c_master.h>
#include "soc/gpio_num.h"

static const char *TAG = "lcd-panel";

struct I2C {
  I2C(gpio_num_t sda, gpio_num_t scl, int rst = -1) :
      i2c_bus_(nullptr),
      rst_num_(rst),
      bus_config_(
          (i2c_master_bus_config_t) {
              .i2c_port = I2C_BUS_PORT,
              .sda_io_num = sda,
              .scl_io_num = scl,
              .clk_source = I2C_CLK_SRC_DEFAULT,
              .glitch_ignore_cnt = 7,
              .flags {
                  .enable_internal_pullup = true,
              },
          }
      )
  {
    ESP_LOGI(TAG, "Initialize I2C bus");
    ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config_, &i2c_bus_));
  }

  ~I2C() = default;

  i2c_master_bus_handle_t i2c_bus_;

  int rst_num_;
private:
  i2c_master_bus_config_t bus_config_;
};

#endif //I2C_H
