diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/CMakeLists.txt | 2 | ||||
-rw-r--r-- | main/config.def.h | 69 | ||||
-rw-r--r-- | main/init.c | 8 | ||||
-rw-r--r-- | main/main.c | 8 | ||||
-rw-r--r-- | main/readme.md | 24 | ||||
-rw-r--r-- | main/sock.c | 4 |
6 files changed, 88 insertions, 27 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 70cd901..4c17fba 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -9,6 +9,7 @@ include(lib/pico-sdk/pico_sdk_init.cmake) include(lib/FreeRTOS-Kernel/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake) add_subdirectory(lib/mpack) add_subdirectory(lib/i2ctcp) +add_subdirectory(lib/pbdrv) project(puzzlebox_main C CXX ASM) @@ -36,5 +37,6 @@ target_link_libraries(main FreeRTOS-Kernel-Heap4 i2ctcp mpack + pbdrv-mod ) diff --git a/main/config.def.h b/main/config.def.h index 7fcaed9..11612eb 100644 --- a/main/config.def.h +++ b/main/config.def.h @@ -1,17 +1,66 @@ #pragma once #include <pico/cyw43_arch.h> +#include <cyw43_country.h> -// wifi credentials -#define CONF_NET_SSID "network name" -#define CONF_NET_PASS "network password" -#define CONF_NET_AUTH CYW43_AUTH_WPA2_AES_PSK -// max duration (milliseconds) for establishing wifi connection -#define CONF_NET_CONN_TIMEOUT 10e3 +/** + * \name Network (Wi-Fi) configuration + * \{ + */ +#ifndef CFG_NET_DISABLE -#include <cyw43_country.h> -#define CONF_NET_COUNTRY CYW43_COUNTRY_NETHERLANDS +#ifndef CFG_NET_SSID +//! network name (SSID) +#define CFG_NET_SSID "" +//! disable network communication +#define CFG_NET_DISABLE +#warning No SSID defined! Disabling network communication! +#endif + +#ifndef CFG_NET_PASS +//! network password +#define CFG_NET_PASS "" +#endif + +#ifndef CFG_NET_AUTH +//! network security type +#define CFG_NET_AUTH CYW43_AUTH_OPEN +#endif + +#ifndef CFG_NET_CONN_TIMEOUT +//! max duration (milliseconds) for establishing wifi connection +#define CFG_NET_CONN_TIMEOUT 10e3 +#endif + +#ifndef CFG_NET_COUNTRY +//! radio communications country +#define CFG_NET_COUNTRY CYW43_COUNTRY_NETHERLANDS +#endif + +#else // ifndef CFG_NET_DISABLE + +#undef CFG_NET_COUNTRY +#define CFG_NET_COUNTRY CYW43_COUNTRY_WORLDWIDE + +#endif // ifndef CFG_NET_DISABLE +/** \} */ + +/** + * \name i2ctcp server configuration + * \{ + */ +#ifndef CFG_SRV_PORT +//! i2ctcp server port +#define CFG_SRV_PORT 9191 +#endif -#define CONF_SRV_PORT 9191 +#ifndef CFG_NET_DISABLE +//! disable the i2ctcp server +#define CFG_SRV_DISABLE +#endif +/** \} */ -#define LED_PIN CYW43_WL_GPIO_LED_PIN +#ifndef CFG_LED_PIN +//! status LED pin +#define CFG_LED_PIN CYW43_WL_GPIO_LED_PIN +#endif diff --git a/main/init.c b/main/init.c index 08177c7..90f0b1e 100644 --- a/main/init.c +++ b/main/init.c @@ -16,7 +16,7 @@ static void init_stdio() { } static void init_cyw34() { - if (cyw43_arch_init_with_country(CONF_NET_COUNTRY)) + if (cyw43_arch_init_with_country(CFG_NET_COUNTRY)) panic("cyw43_arch_init_with_country failed\n"); } @@ -24,8 +24,8 @@ 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, CONF_NET_AUTH, CONF_NET_CONN_TIMEOUT)) - // panic("cyw43_arch_wifi_connect failed\n"); + if (cyw43_arch_wifi_connect_timeout_ms(CFG_NET_SSID, CFG_NET_PASS, CFG_NET_AUTH, CFG_NET_CONN_TIMEOUT)) + panic("cyw43_arch_wifi_connect failed\n"); printf("connected to Wi-Fi\n"); @@ -35,7 +35,9 @@ static void init_wifi() { static void async_init() { init_cyw34(); init_i2c(); +#ifndef CFG_NET_DISABLE init_wifi(); +#endif xEventGroupSetBits(init_complete, 1); diff --git a/main/main.c b/main/main.c index 19dd3cd..9fefed5 100644 --- a/main/main.c +++ b/main/main.c @@ -13,9 +13,9 @@ void blink_task() { await_init(); // `blink_task` uses GPIO while (true) { - cyw43_arch_gpio_put(LED_PIN, 0); + cyw43_arch_gpio_put(CFG_LED_PIN, 0); vTaskDelay(250 / portTICK_PERIOD_MS); - cyw43_arch_gpio_put(LED_PIN, 1); + cyw43_arch_gpio_put(CFG_LED_PIN, 1); vTaskDelay(250 / portTICK_PERIOD_MS); } } @@ -24,7 +24,9 @@ int main() { init(); xTaskCreate((TaskFunction_t) blink_task, "blink", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL); - //xTaskCreate((TaskFunction_t) serve_task, "serve", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL); +#ifndef CFG_SRV_DISABLE + xTaskCreate((TaskFunction_t) serve_task, "serve", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL); +#endif xTaskCreate((TaskFunction_t) bus_task, "bus", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL); vTaskStartScheduler(); diff --git a/main/readme.md b/main/readme.md index 425a00b..28fcfad 100644 --- a/main/readme.md +++ b/main/readme.md @@ -5,17 +5,23 @@ This directory contains the software for the main controller of the Puzzle Box. ## building 1. make sure the submodules are initialized -2. copy [`config.def.h`](./config.def.h) to `config.h` and edit the defaults -3. `mkdir build` -4. `cmake -B build` -5. `make -C build` or `ninja -C build` (choose your preference) +2. create a `config.h` file and define some options (see `config.def.h` for all + options): + ```c + #pragma once -alternatively, a makefile is provided for convenience + #define CFG_NET_SSID "network name" + #define CFG_NET_PASS "network password" + #define CFG_NET_AUTH CYW43_AUTH_WPA2_AES_PSK -## "flashing" + #include "config.def.h" + ``` +3. use CMake to build -1. [build](#building) -2. (re)connect the raspberry pi pico while holding the BOOTSEL button (this is - the only button) +## flashing + +1. build +2. hold the BOOTSEL button while resetting the pico (by power cycling or + pulling pin 30 (RUN) to GND) 3. `picotool load build/main.uf2` diff --git a/main/sock.c b/main/sock.c index fe932bb..dc3d7ea 100644 --- a/main/sock.c +++ b/main/sock.c @@ -83,10 +83,10 @@ void serve_task() { printf("starting server...\n"); struct netconn* conn = netconn_new(NETCONN_TCP); - netconn_bind(conn, IP_ADDR_ANY, CONF_SRV_PORT); + netconn_bind(conn, IP_ADDR_ANY, CFG_SRV_PORT); netconn_listen(conn); - printf("listening on %s:%d\n", ip4addr_ntoa(netif_ip4_addr(netif_list)), CONF_SRV_PORT); + printf("listening on %s:%d\n", ip4addr_ntoa(netif_ip4_addr(netif_list)), CFG_SRV_PORT); while (1) { struct netconn* incoming; if (netconn_accept(conn, &incoming) == ERR_OK) |