#include "iic.h"

static const char *TAG = "IIC";

i2c_master_bus_handle_t bus_handle; // I2C 总线句柄



void iic_init()
{
    ESP_LOGI(TAG, "init");

    i2c_master_bus_config_t bus_config = {
    .clk_source        = I2C_CLK_SRC_DEFAULT, // 时钟源（默认）
    .i2c_port          = I2C_BUS_PORT,
    .sda_io_num        = SDA_PIN,
    .scl_io_num        = SCL_PIN,
    .glitch_ignore_cnt = 7,                    // 毛刺过滤，一般默认7
    .flags.enable_internal_pullup = true,      // 启用内部上拉电阻
    };

    esp_err_t err=i2c_new_master_bus(&bus_config, &bus_handle);

    if(err!=ESP_OK)
    {
        ESP_LOGE(TAG, "init _error: %d",err);
    }

}