mirror of
https://github.com/StuckAtPrototype/Racer.git
synced 2024-10-20 22:49:48 +03:00
33 lines
1017 B
C
33 lines
1017 B
C
#include "i2c_config.h"
|
|
#include "esp_log.h"
|
|
|
|
static const char *TAG = "i2c_config";
|
|
|
|
esp_err_t i2c_master_init(void)
|
|
{
|
|
int i2c_master_port = I2C_MASTER_NUM;
|
|
i2c_config_t conf = {
|
|
.mode = I2C_MODE_MASTER,
|
|
.sda_io_num = I2C_MASTER_SDA_IO,
|
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
|
.scl_io_num = I2C_MASTER_SCL_IO,
|
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
|
.master.clk_speed = I2C_MASTER_FREQ_HZ,
|
|
};
|
|
|
|
esp_err_t err = i2c_param_config(i2c_master_port, &conf);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "I2C parameter configuration failed. Error: %s", esp_err_to_name(err));
|
|
return err;
|
|
}
|
|
|
|
err = i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "I2C driver installation failed. Error: %s", esp_err_to_name(err));
|
|
return err;
|
|
}
|
|
|
|
ESP_LOGI(TAG, "I2C master initialized successfully");
|
|
return ESP_OK;
|
|
}
|