Air quality sensor
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
esp-airsensor/main/periph_init.c

33 lines
886 B

#include <esp_log.h>
#include "periph_init.h"
#include "driver/i2c.h"
static const char *TAG = "periph_init";
esp_err_t periph_init() {
esp_err_t rv;
ESP_LOGI(TAG, "Init I2C");
int i2c_master_port = I2C_NUM_0;
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = CONFIG_PIN_I2C_SDA0,
.sda_pullup_en = GPIO_PULLUP_ENABLE, // is this enough?
.scl_io_num = CONFIG_PIN_I2C_SCL0,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 100000,
};
rv = i2c_param_config(i2c_master_port, &conf);
if (rv != ESP_OK) {
ESP_LOGE(TAG, "Err in i2c_param_config");
return rv;
}
rv = i2c_driver_install(i2c_master_port, conf.mode, 0, 0, 0);
if (rv != ESP_OK) {
ESP_LOGE(TAG, "Err in i2c_driver_install");
return rv;
}
return ESP_OK;
}