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.
51 lines
1.4 KiB
51 lines
1.4 KiB
#include <esp_log.h>
|
|
#include "periph_init.h"
|
|
#include "driver/i2c.h"
|
|
#include "data_report.h"
|
|
|
|
static const char *TAG = "periph_init";
|
|
|
|
SemaphoreHandle_t g_mux_i2c;
|
|
|
|
esp_err_t periph_init() {
|
|
esp_err_t rv;
|
|
|
|
g_mux_i2c = xSemaphoreCreateMutex();
|
|
assert(g_mux_i2c);
|
|
|
|
g_mux_data_report = xSemaphoreCreateMutex(); // XXX move elsewhere
|
|
assert(g_mux_data_report);
|
|
|
|
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;
|
|
}
|
|
|
|
gpio_config_t gconf = {
|
|
.pin_bit_mask = (1 << CONFIG_PIN_SENSEAIR_NRDY),
|
|
.mode = GPIO_MODE_INPUT,
|
|
.pull_up_en = GPIO_PULLUP_ENABLE,
|
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
|
.intr_type = GPIO_INTR_DISABLE, // TODO
|
|
};
|
|
gpio_config(&gconf);
|
|
|
|
return ESP_OK;
|
|
}
|
|
|