82 lines
1.9 KiB
C
82 lines
1.9 KiB
C
#include <stdio.h>
|
|
|
|
#include "driver/gpio.h"
|
|
#include "driver/i2c.h"
|
|
#include "esp_sntp.h"
|
|
#include "esp_spi_flash.h"
|
|
#include "esp_system.h"
|
|
#include "nvs_flash.h"
|
|
#include "sdkconfig.h"
|
|
//
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
//
|
|
#include "if_standby.h"
|
|
#include "impl_lvgl.h"
|
|
#include "service_clock.h"
|
|
#include "service_dht.h"
|
|
#include "service_wifi.h"
|
|
|
|
#define APP_I2C_MASTER_NUM 0
|
|
#define APP_I2C_SDA_NUM GPIO_NUM_39
|
|
#define APP_I2C_SCL_NUM GPIO_NUM_40
|
|
#define APP_I2C_HZ 400000
|
|
|
|
static esp_err_t app_init_nvs(void) {
|
|
esp_err_t ret = nvs_flash_init();
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static esp_err_t app_init_gpio(void) {
|
|
//
|
|
return gpio_install_isr_service(0);
|
|
}
|
|
|
|
static esp_err_t app_init_i2c(void) {
|
|
i2c_config_t cfg = {
|
|
.mode = I2C_MODE_MASTER,
|
|
.sda_io_num = APP_I2C_SDA_NUM,
|
|
.scl_io_num = APP_I2C_SCL_NUM,
|
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
|
.master.clk_speed = APP_I2C_HZ,
|
|
};
|
|
|
|
i2c_param_config(APP_I2C_MASTER_NUM, &cfg);
|
|
|
|
return i2c_driver_install(APP_I2C_MASTER_NUM, cfg.mode, 0, 0, 0);
|
|
}
|
|
|
|
static esp_err_t app_init_sntp(void) {
|
|
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
|
sntp_setservername(0, "pool.ntp.org");
|
|
sntp_init();
|
|
|
|
return ESP_OK;
|
|
}
|
|
|
|
void app_main(void) {
|
|
ESP_ERROR_CHECK(app_init_nvs());
|
|
ESP_ERROR_CHECK(app_init_gpio());
|
|
ESP_ERROR_CHECK(app_init_i2c());
|
|
ESP_ERROR_CHECK(app_init_sntp());
|
|
|
|
ESP_ERROR_CHECK(impl_lvgl_init());
|
|
|
|
ESP_ERROR_CHECK(if_standby_init());
|
|
|
|
ESP_ERROR_CHECK(service_dht_init());
|
|
ESP_ERROR_CHECK(service_clock_init());
|
|
ESP_ERROR_CHECK(service_wifi_init());
|
|
|
|
/* Dead loop */
|
|
for (;;) {
|
|
vTaskSuspend(NULL);
|
|
}
|
|
}
|