From c19a8d0246814f2c662a0409f6068208cf95ebac Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 26 Sep 2016 03:17:59 +0800 Subject: [PATCH] Migrate startup code from cpu_start into the application --- main/app_main.c | 17 ----------------- main/main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 17 deletions(-) delete mode 100644 main/app_main.c create mode 100644 main/main.c diff --git a/main/app_main.c b/main/app_main.c deleted file mode 100644 index 1fac2d1..0000000 --- a/main/app_main.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" - - -void pingTask(void *pvParameters) -{ - while (1) { - vTaskDelay(1000 / portTICK_PERIOD_MS); - printf("ping\n"); - } -} - -void app_main() -{ - xTaskCreatePinnedToCore(&pingTask, "pingTask", 2048, NULL, 5, NULL, 0); -} diff --git a/main/main.c b/main/main.c new file mode 100644 index 0000000..4c58df9 --- /dev/null +++ b/main/main.c @@ -0,0 +1,45 @@ +#include "freertos/FreeRTOS.h" +#include "esp_wifi.h" +#include "esp_system.h" +#include "esp_event.h" +#include "esp_event_loop.h" +#include "nvs_flash.h" +#include "driver/gpio.h" + +esp_err_t event_handler(void *ctx, system_event_t *event) +{ + return ESP_OK; +} + +int app_main(void) +{ + nvs_flash_init(6, 3); + system_init(); + tcpip_adapter_init(); + ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(esp_event_loop_get_queue() ); + ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); + ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); + ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); + wifi_config_t sta_config = { + .sta = { + .ssid = "access_point_name", + .password = "password", + .bssid_set = false + } + }; + ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) ); + ESP_ERROR_CHECK( esp_wifi_start() ); + ESP_ERROR_CHECK( esp_wifi_connect() ); + + gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); + int level = 0; + while (true) { + gpio_set_level(GPIO_NUM_4, level); + level = !level; + vTaskDelay(300 / portTICK_PERIOD_MS); + } + + return 0; +} +