Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitadf061ff7688ae5fcf23e5ec0eda3822f0328350 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-05-20 14:11:06 +0300
Committer
 Syndamia <kamen@syndamia.com>
2024-05-20 14:11:06 +0300
Files4f708b01c6524f8e59bfdd499854b4788170fa04
uni-projects-adf061ff7688ae5fcf23e5ec0eda3822f0328350.tar
uni-projects-adf061ff7688ae5fcf23e5ec0eda3822f0328350.tar.gz
uni-projects-adf061ff7688ae5fcf23e5ec0eda3822f0328350.zip
Parente0aacc71d8b4764dd856872d23e2c355621412a4 (diff)
[iot/goam] Moved nvs setup out of wifi and made camera init in it's own task
diff --git a/Year 3/Internet of things/goam/main/CMakeLists.txt b/Year 3/Internet of things/goam/main/CMakeLists.txt
index fdaee6e..5b77e8c 100644
--- a/Year 3/Internet of things/goam/main/CMakeLists.txt
+++ b/Year 3/Internet of things/goam/main/CMakeLists.txt
@@ -5,5 +5,6 @@ idf_component_register(SRCS "main.c"
"wifi.c"
"webserver.c"
"spiffs.c"
+ "nvs.c"
EMBED_FILES "../webserver-src/index.html"
INCLUDE_DIRS "")
diff --git a/Year 3/Internet of things/goam/main/main.c b/Year 3/Internet of things/goam/main/main.c
index 3f3d46b..95ba622 100644
--- a/Year 3/Internet of things/goam/main/main.c
+++ b/Year 3/Internet of things/goam/main/main.c
@@ -11,15 +11,19 @@
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
-
#include "driver/gpio.h"
#include "driver/uart.h"
+#include "esp_log.h"
+
#include "ptc06.h"
#include "buttons.h"
#include "display.h"
#include "wifi.h"
#include "webserver.h"
#include "spiffs.h"
+#include "nvs.h"
+
+static const char *TAG = "main";
void print_chip_data() {
/* Print chip information */
@@ -48,6 +52,10 @@ void print_chip_data() {
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
}
+/*
+ * On button press
+ */
+
#define BTN_SHOOT_PIN 13
void debug_serial_print_image(const char* image, size_t length) {
@@ -71,21 +79,49 @@ void take_photo() {
free(image);
}
+/*
+ * On boot
+ */
+
+static TaskHandle_t main_handle = NULL;
+
+#define INIT_CAMERA_BIT 0x01
+
+static void init_camera(void*) {
+ ptc06_init();
+
+ if (xTaskNotify(main_handle, INIT_CAMERA_BIT, eSetBits) != pdPASS) {
+ ESP_LOGE(TAG, "Couldnt't notify main of camera init, software will hang");
+ }
+
+ vTaskDelete(NULL);
+}
+
void app_main(void)
{
- vTaskDelay(1000 / portTICK_PERIOD_MS);
- printf("Starting up!\n");
+ main_handle = xTaskGetHandle("main");
+
+ nvs_init(); // A whole lotta stuff depend on this
+
+ // Minor performance improvement, since we always have to wait 2.5 seconds
+ xTaskCreate(init_camera, "init_camera", 2048, NULL, 10, NULL);
+
+ // These inits are really fast, it doesnt make a difference if
+ // they're in a task or not
+ spiffs_init();
+ buttons_init();
+ add_push_button(BTN_SHOOT_PIN, take_photo, NULL);
wifi_init();
webserver_init();
wifi_start(); // Automatically starts server too
- spiffs_init();
-
- ptc06_init();
+ int notification = 0;
+ while (!(notification & INIT_CAMERA_BIT)) {
+ xTaskNotifyWait(0, 0, &notification, 50 / portTICK_PERIOD_MS);
+ }
- buttons_init();
- add_push_button(BTN_SHOOT_PIN, take_photo, NULL);
+ // TODO: move before notification wait
display_init();
for (int i = 0; true; i++) {
diff --git a/Year 3/Internet of things/goam/main/nvs.c b/Year 3/Internet of things/goam/main/nvs.c
new file mode 100644
index 0000000..add6e69
--- /dev/null
+++ b/Year 3/Internet of things/goam/main/nvs.c
@@ -0,0 +1,18 @@
+#include "nvs_flash.h"
+#include "esp_log.h"
+
+#include "nvs.h"
+
+static const char *TAG = "nvs";
+
+void nvs_init() {
+ 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();
+ }
+
+ ESP_ERROR_CHECK(ret);
+ ESP_LOGI(TAG, "NVS initialized");
+}
diff --git a/Year 3/Internet of things/goam/main/nvs.h b/Year 3/Internet of things/goam/main/nvs.h
new file mode 100644
index 0000000..b6058a2
--- /dev/null
+++ b/Year 3/Internet of things/goam/main/nvs.h
@@ -0,0 +1,3 @@
+#pragma once
+
+void nvs_init();
diff --git a/Year 3/Internet of things/goam/main/wifi.c b/Year 3/Internet of things/goam/main/wifi.c
index 3a049e5..ef94490 100644
--- a/Year 3/Internet of things/goam/main/wifi.c
+++ b/Year 3/Internet of things/goam/main/wifi.c
@@ -1,7 +1,6 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
-#include "nvs_flash.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
@@ -16,22 +15,6 @@
static const char *TAG = "wifi_station";
/*
- * NVS
- */
-
-static void nvs_init() {
- 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();
- }
-
- ESP_ERROR_CHECK(ret);
- ESP_LOGI(TAG, "NVS initialized");
-}
-
-/*
* NetIF
*/
@@ -120,8 +103,6 @@ static void wifi_init_static_station() {
*/
void wifi_init() {
- nvs_init();
-
ESP_ERROR_CHECK(esp_event_loop_create_default());
netif_init();