aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/FreeRTOSConfig.h1
-rw-r--r--main/blink.c3
-rw-r--r--main/config.def.h3
-rw-r--r--main/i2c.c32
-rw-r--r--main/i2c.h1
-rw-r--r--main/init.c15
-rw-r--r--main/lwipopts.h1
-rw-r--r--main/main.c1
-rw-r--r--main/mod.c3
-rw-r--r--main/sock.c43
-rw-r--r--main/sock.h1
-rw-r--r--main/tasks.c9
12 files changed, 52 insertions, 61 deletions
diff --git a/main/FreeRTOSConfig.h b/main/FreeRTOSConfig.h
index c811296..546780d 100644
--- a/main/FreeRTOSConfig.h
+++ b/main/FreeRTOSConfig.h
@@ -66,4 +66,3 @@
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_xTaskResumeFromISR 1
#define INCLUDE_xQueueGetMutexHolder 1
-
diff --git a/main/blink.c b/main/blink.c
index 956e910..1a7c205 100644
--- a/main/blink.c
+++ b/main/blink.c
@@ -1,6 +1,6 @@
#include <FreeRTOS.h>
-#include <task.h>
#include <pico/cyw43_arch.h>
+#include <task.h>
#include "blink.h"
#include "config.h"
@@ -13,4 +13,3 @@ void blink_task() {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
-
diff --git a/main/config.def.h b/main/config.def.h
index 1ec8a5c..2639c40 100644
--- a/main/config.def.h
+++ b/main/config.def.h
@@ -1,6 +1,6 @@
#pragma once
-#include <pico/cyw43_arch.h>
#include <cyw43_country.h>
+#include <pico/cyw43_arch.h>
/**
* \ingroup main
@@ -130,4 +130,3 @@
/// \}
/// \}
-
diff --git a/main/i2c.c b/main/i2c.c
index b68d0e0..b0ac1d3 100644
--- a/main/i2c.c
+++ b/main/i2c.c
@@ -1,15 +1,15 @@
#include <FreeRTOS.h>
-#include <task.h>
-#include <stdio.h>
+#include <hardware/i2c.h>
+#include <pico/stdlib.h>
#include <stddef.h>
#include <stdint.h>
-#include <pico/stdlib.h>
-#include <hardware/i2c.h>
+#include <stdio.h>
+#include <task.h>
-#include "i2c.h"
-#include "pb-mod.h"
#include "config.h"
+#include "i2c.h"
#include "pb-buf.h"
+#include "pb-mod.h"
#include "pb-send.h"
//! Puzzle module handle
@@ -21,7 +21,8 @@ typedef struct {
static pb_global_state_t _global_state = PB_GS_IDLE;
puzzle_module_t modules[CFG_PB_MOD_MAX];
// stolen from lib/pico-sdk/src/rp2_common/hardware_i2c/i2c.c
-#define i2c_reserved_addr(addr) (((addr) & 0x78) == 0 || ((addr) & 0x78) == 0x78)
+#define i2c_reserved_addr(addr) \
+ (((addr) & 0x78) == 0 || ((addr) & 0x78) == 0x78)
size_t modules_size = 0;
static void bus_scan() {
@@ -63,11 +64,11 @@ static void update_state() {
for (size_t i = 0; i < modules_size; i++) {
// find first module that is idle
- pb_global_state_t module_state = modules[i].state;
+ pb_global_state_t module_state = modules[i].state;
if (module_state != PB_GS_IDLE) continue;
pb_buf_t buff = pb_send_state_set(PB_GS_PLAYING);
- pb_i2c_send(modules[i].sender, (uint8_t*)buff.data, buff.size);
+ pb_i2c_send(modules[i].sender, (uint8_t *) buff.data, buff.size);
pb_buf_free(&buff);
}
}
@@ -84,7 +85,7 @@ void bus_task() {
// do a scan of the bus
bus_scan();
- while(1) {
+ while (1) {
// send my state to all puzzle modules
state_exchange();
@@ -106,7 +107,7 @@ void bus_task() {
*/
void pb_route_cmd_magic_res(pb_msg_t * msg) {
if (modules_size == CFG_PB_MOD_MAX) return;
- modules[modules_size++] = (puzzle_module_t) {
+ modules[modules_size++] = (puzzle_module_t){
.sender = msg->sender,
.state = PB_GS_NOINIT,
};
@@ -123,11 +124,6 @@ void pb_route_cmd_state_res(pb_msg_t * msg) {
}
}
-pb_global_state_t pb_hook_mod_state_read() {
- return _global_state;
-}
-
-void pb_hook_mod_state_write(pb_global_state_t state) {
- _global_state = state;
-}
+pb_global_state_t pb_hook_mod_state_read() { return _global_state; }
+void pb_hook_mod_state_write(pb_global_state_t state) { _global_state = state; }
diff --git a/main/i2c.h b/main/i2c.h
index 27c0b02..107a04d 100644
--- a/main/i2c.h
+++ b/main/i2c.h
@@ -15,4 +15,3 @@
void bus_task();
/// \}
-
diff --git a/main/init.c b/main/init.c
index 25fa5e3..6105c0d 100644
--- a/main/init.c
+++ b/main/init.c
@@ -1,17 +1,15 @@
#include <FreeRTOS.h>
#include <task.h>
-#include <pico/stdio.h>
#include <pico/cyw43_arch.h>
+#include <pico/stdio.h>
#include "config.h"
#include "init.h"
-#include "tasks.h"
#include "pb-mod.h"
+#include "tasks.h"
-static void init_stdio() {
- stdio_init_all();
-}
+static void init_stdio() { stdio_init_all(); }
static void init_cyw34() {
if (cyw43_arch_init_with_country(CFG_NET_COUNTRY))
@@ -22,7 +20,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(CFG_NET_SSID, CFG_NET_PASS, CFG_NET_AUTH, CFG_NET_CONN_TIMEOUT))
+ 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");
// TODO: announce hostname(?)
@@ -59,6 +58,6 @@ void init() {
init_stdio();
// defer other initialization until the task scheduler is running (important)
- xTaskCreate((TaskFunction_t) async_init, "init", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 4, NULL);
+ xTaskCreate((TaskFunction_t) async_init, "init", configMINIMAL_STACK_SIZE,
+ NULL, tskIDLE_PRIORITY + 4, NULL);
}
-
diff --git a/main/lwipopts.h b/main/lwipopts.h
index b2b6e76..eb000d8 100644
--- a/main/lwipopts.h
+++ b/main/lwipopts.h
@@ -89,4 +89,3 @@
#define LWIP_TIMEVAL_PRIVATE 0
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
-
diff --git a/main/main.c b/main/main.c
index 1c615fc..3e69de0 100644
--- a/main/main.c
+++ b/main/main.c
@@ -7,4 +7,3 @@ int main() {
init();
vTaskStartScheduler();
}
-
diff --git a/main/mod.c b/main/mod.c
index 8650861..fbb7209 100644
--- a/main/mod.c
+++ b/main/mod.c
@@ -1,9 +1,8 @@
#include <FreeRTOS.h>
#include <task.h>
-#include "pb.h"
#include "pb-mod.h"
+#include "pb.h"
const char * PB_MOD_NAME = "main controller";
const i2c_addr_t PB_MOD_ADDR = PB_ADDR_MOD_MAIN;
-
diff --git a/main/sock.c b/main/sock.c
index c97ad04..69c1341 100644
--- a/main/sock.c
+++ b/main/sock.c
@@ -1,20 +1,21 @@
#include <pico/stdio.h>
+#include <lwip/api.h>
#include <lwip/opt.h>
#include <lwip/sys.h>
-#include <lwip/api.h>
#include <string.h>
-#include "init.h"
#include "config.h"
#include "i2ctcpv1.h"
-#include "sock.h"
+#include "init.h"
#include "pb-mod.h"
+#include "sock.h"
-struct netconn* current_connection = NULL;
+struct netconn * current_connection = NULL;
i2ctcp_msg_t recv_msg;
-static void sock_dump_msg(i2c_addr_t addr, const uint8_t * data, size_t data_size) {
+static void sock_dump_msg(i2c_addr_t addr, const uint8_t * data,
+ size_t data_size) {
if (current_connection == NULL) return;
i2ctcp_msg_t send_msg = {
@@ -37,7 +38,8 @@ static void sock_dump_msg(i2c_addr_t addr, const uint8_t * data, size_t data_siz
bool pb_hook_i2c_send(i2c_addr_t addr, const uint8_t * data, size_t data_size) {
sock_dump_msg(addr, data, data_size);
- return addr == PB_MOD_ADDR; // stop processing message if it is sent to myself
+ return addr
+ == PB_MOD_ADDR; // stop processing message if it is sent to myself
}
bool pb_hook_i2c_recv(const uint8_t * data, size_t data_size) {
@@ -45,7 +47,8 @@ bool pb_hook_i2c_recv(const uint8_t * data, size_t data_size) {
return false;
}
-static void sock_fwd_msg(i2c_addr_t addr, const uint8_t * data, size_t data_size) {
+static void sock_fwd_msg(i2c_addr_t addr, const uint8_t * data,
+ size_t data_size) {
if (addr == PB_MOD_ADDR) {
// addressed to me = act as recieved
pb_i2c_recv(data, data_size);
@@ -55,14 +58,14 @@ static void sock_fwd_msg(i2c_addr_t addr, const uint8_t * data, size_t data_size
}
}
-void recv_handler(struct netconn* conn, struct netbuf* buf) {
+void recv_handler(struct netconn * conn, struct netbuf * buf) {
i2ctcp_read_reset(&recv_msg);
do {
- char* data;
+ char * data;
uint16_t len;
- netbuf_data(buf, (void**)&data, &len);
-
+ netbuf_data(buf, (void **) &data, &len);
+
// continue early if more data is needed to complete message
if (i2ctcp_read(&recv_msg, data, len) != 0) continue;
@@ -74,12 +77,11 @@ void recv_handler(struct netconn* conn, struct netbuf* buf) {
netbuf_delete(buf);
}
-void accept_handler(struct netconn* conn) {
+void accept_handler(struct netconn * conn) {
current_connection = conn;
- struct netbuf* buf;
- while (netconn_recv(conn, &buf) == ERR_OK)
- recv_handler(conn, buf);
+ struct netbuf * buf;
+ while (netconn_recv(conn, &buf) == ERR_OK) recv_handler(conn, buf);
netconn_close(conn);
netconn_delete(conn);
@@ -89,15 +91,14 @@ void accept_handler(struct netconn* conn) {
void serve_task() {
printf("starting server...\n");
- struct netconn* conn = netconn_new(NETCONN_TCP);
+ struct netconn * conn = netconn_new(NETCONN_TCP);
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)), CFG_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)
- accept_handler(incoming);
+ struct netconn * incoming;
+ if (netconn_accept(conn, &incoming) == ERR_OK) accept_handler(incoming);
}
}
-
diff --git a/main/sock.h b/main/sock.h
index a151973..5abc87f 100644
--- a/main/sock.h
+++ b/main/sock.h
@@ -14,4 +14,3 @@
void serve_task();
/// \}
-
diff --git a/main/tasks.c b/main/tasks.c
index 253c47b..d83525d 100644
--- a/main/tasks.c
+++ b/main/tasks.c
@@ -9,9 +9,12 @@
#include "sock.h"
void init_tasks() {
- xTaskCreate((TaskFunction_t) blink_task, "blink", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, NULL);
+ xTaskCreate((TaskFunction_t) blink_task, "blink", 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);
+ 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);
+ xTaskCreate((TaskFunction_t) bus_task, "bus", configMINIMAL_STACK_SIZE,
+ NULL, tskIDLE_PRIORITY + 2, NULL);
}