aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/CMakeLists.txt1
-rw-r--r--main/config.def.h8
-rw-r--r--main/init.cpp32
-rw-r--r--main/init.h5
-rw-r--r--main/main.cpp27
5 files changed, 48 insertions, 25 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 29afb84..7c18f56 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -14,6 +14,7 @@ pico_sdk_init()
add_executable(main
main.cpp
+ init.cpp
)
pico_enable_stdio_usb(main 1)
diff --git a/main/config.def.h b/main/config.def.h
index 48de559..376c58a 100644
--- a/main/config.def.h
+++ b/main/config.def.h
@@ -1,8 +1,14 @@
#pragma once
+#include <pico/cyw43_arch.h>
+// wifi credentials
#define CONF_NET_SSID "network name"
#define CONF_NET_PASS "network password"
+// max duration (milliseconds) for establishing wifi connection
+#define CONF_NET_CONN_TIMEOUT 10000
-#include "cyw43_country.h"
+#include <cyw43_country.h>
#define CONF_NET_COUNTRY CYW43_COUNTRY_NETHERLANDS
+#define LED_PIN CYW43_WL_GPIO_LED_PIN
+
diff --git a/main/init.cpp b/main/init.cpp
new file mode 100644
index 0000000..425f591
--- /dev/null
+++ b/main/init.cpp
@@ -0,0 +1,32 @@
+#include "config.h"
+#include "init.h"
+
+#include <pico/stdio.h>
+#include <pico/cyw43_arch.h>
+
+static void init_stdio() {
+ stdio_init_all();
+}
+
+static void init_cyw34() {
+ if (cyw43_arch_init_with_country(CONF_NET_COUNTRY))
+ panic("cyw43_arch_init_with_country failed\n");
+}
+
+static void init_wifi() {
+ // enable 'station' mode (connect to an access point instead of acting like one)
+ cyw43_arch_enable_sta_mode();
+
+ if (cyw43_arch_wifi_connect_timeout_ms(CONF_NET_SSID, CONF_NET_PASS, CYW43_AUTH_WPA2_AES_PSK, CONF_NET_CONN_TIMEOUT))
+ panic("cyw43_arch_wifi_connect failed\n");
+
+ // TODO: announce hostname
+}
+
+void init() {
+ init_stdio();
+ init_cyw34();
+ init_wifi();
+ // TODO: initialize i2c
+}
+
diff --git a/main/init.h b/main/init.h
new file mode 100644
index 0000000..1f931dc
--- /dev/null
+++ b/main/init.h
@@ -0,0 +1,5 @@
+#pragma once
+
+/** @brief initialize all peripherals on the pico */
+void init();
+
diff --git a/main/main.cpp b/main/main.cpp
index 8b3504c..d85c76e 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1,13 +1,10 @@
-#include "config.h"
-
#include <FreeRTOS.h>
#include <task.h>
#include <pico/stdlib.h>
-#include <pico/stdio.h>
-#include <pico/cyw43_arch.h>
-const unsigned int LED_PIN = CYW43_WL_GPIO_LED_PIN;
+#include "config.h"
+#include "init.h"
void blink_task() {
while (true) {
@@ -19,25 +16,7 @@ void blink_task() {
}
int main() {
- stdio_init_all();
- sleep_ms(2000);
-
- if (cyw43_arch_init_with_country(CONF_NET_COUNTRY)) {
- printf("failed to initialize\n");
- return 1;
- }
- cyw43_arch_gpio_put(LED_PIN, 1);
-
-
- printf("initialised\n");
-
- cyw43_arch_enable_sta_mode();
-
- if (cyw43_arch_wifi_connect_timeout_ms(CONF_NET_SSID, CONF_NET_PASS, CYW43_AUTH_WPA2_AES_PSK, 10000)) {
- printf("failed to connect\n");
- return 1;
- }
- printf("connected\n");
+ init();
xTaskCreate((TaskFunction_t) blink_task, "blink", 128, NULL, 1, NULL);
vTaskStartScheduler();