aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lazy.mk7
-rw-r--r--main/CMakeLists.txt2
-rw-r--r--main/config.def.h69
-rw-r--r--main/init.c8
-rw-r--r--main/main.c8
-rw-r--r--main/readme.md24
-rw-r--r--main/sock.c4
-rw-r--r--puzzle/readme.md13
-rw-r--r--readme.md49
9 files changed, 124 insertions, 60 deletions
diff --git a/lazy.mk b/lazy.mk
index 3b9813a..236aef7 100644
--- a/lazy.mk
+++ b/lazy.mk
@@ -1,4 +1,6 @@
-# this file is for lazy people (loek)
+# NOTE: CMAKE IS THE PRIMARY BUILD SYSTEM FOR SUBFOLDERS/LIBRARIES IN THIS
+# REPOSITORY. THIS FILE IS PROVIDED PURELY FOR CONVENIENCE, AND SHOULD NOT
+# BECOME AN ESSENTIAL PART OF THE BUILD SYSTEM!
BUILD_DIR ?= build
TARGET ?= $(BUILD_DIR)/main
@@ -17,12 +19,11 @@ $(BUILD_DIR)/build.ninja: CMakeLists.txt
$(TARGET): $(BUILD_DIR)/build.ninja FORCE
@ninja -C $(BUILD_DIR)
-# ninja automatically builds in parallel, so is preferred
clean: FORCE
$(RM) -r $(BUILD_DIR)
-# forward other targets to cmake
+# Forward any unknown targets to Ninja
ifneq ($(MAKECMDGOALS),)
%::
@ninja -C $(BUILD_DIR) $@
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)
diff --git a/puzzle/readme.md b/puzzle/readme.md
index 97acaf7..59c10b1 100644
--- a/puzzle/readme.md
+++ b/puzzle/readme.md
@@ -16,3 +16,16 @@ these subfolders, make sure you have done the following:
- Install the "Arduino AVR Boards" package (1.8.6 works at the time of writing)
[arduino-cmake]: https://github.com/a9183756-gh/Arduino-CMake-Toolchain
+
+## ESP-based puzzle modules
+
+### ESP-IDF SDK Setup instructions
+
+1. Install ESP-IDF extension in Visual Studio Code
+2. Install using 'express' option
+3. Install ESP-IDF v5.2.1 (release version)
+
+ Additional help:
+ - [For windows](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/windows-setup.html#get-started-windows-first-steps)
+ - [For Linux](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/linux-macos-setup.html#get-started-linux-macos-first-steps)
+
diff --git a/readme.md b/readme.md
index ac703b7..457ffaa 100644
--- a/readme.md
+++ b/readme.md
@@ -17,16 +17,18 @@ Please keep this repository tidy by being aware of the following conventions!
### Folder structure
-|folder|contains|
-|-|-|
-|`/client`|Desktop PC application for controlling the puzzle box
-|`/docs`|Project documentation in AsciiDoc(tor) format
-|`/i2ctcp`|I<sup>2</sup>C over TCP protocol functions (used by main and client)
-|`/lib`|Libraries (tracked as [submodules](#submodules))
-|`/main`|Main controller (RPi pico) software
-|`/puzzle/<name>`|Puzzle sources, each puzzle has its own subdirectory
-|`/shared`|Shared code
-|`/test`|Unit test framework (currently unutilized)
+```
+/client desktop PC application for controlling the puzzle box
+/docs project documentation in AsciiDoc(tor) format
+/lib custom libraries and submodules
+├───/i2ctcp I2C over TCP protocol functions (used by main and client)
+├───/mpack MsgPack CMake configuration and extension
+└───/pbdrv puzzle bus driver (module driver + (de)serializing functions)
+/main main controller (RPi pico) software
+/puzzle/<name> puzzle sources, each puzzle has its own subdirectory
+/shared (unused) shared code
+/test unit tests
+```
### Code style
@@ -49,25 +51,12 @@ git submodule update --init --recursive --depth 1
until your problems go away.
-<!--
-## Tests
-
-```
-mkdir -p test/build
-cd test/build
-cmake ..
-make
-make test
-```
--->
-
-## ESP SDK setup
-
-1. Install ESP-IDF extension in Visual Studio Code
-2. Install using 'express' option
-3. Install ESP-IDF v5.2.1 (release version)
+## lazy\.mk
- Additional help:
- - [For windows](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/windows-setup.html#get-started-windows-first-steps)
- - [For Linux](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/linux-macos-setup.html#get-started-linux-macos-first-steps)
+[`lazy.mk`](./lazy.mk) is a file made by Loek, and includes some rules for
+forwarding `make` calls to `cmake` and `ninja`. **This is purely for
+convenience, and should not become an essential part of the build system**.
+This file should be included at the end of a regular makefile. Any targets
+defined in a makefile can be used as-is, while targets that would otherwise be
+unknown will be forwarded to Ninja.