aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pbdrv')
-rw-r--r--lib/pbdrv/drv/arduino/mod.cpp17
-rw-r--r--lib/pbdrv/drv/rp2040/mod.c14
-rw-r--r--lib/pbdrv/drv/rp2040/pb-mod.h1
-rw-r--r--lib/pbdrv/ext/freertos/pb-mem.c13
-rw-r--r--lib/pbdrv/ext/stdlib/pb-mem.c13
-rw-r--r--lib/pbdrv/mpack-config.h1
-rw-r--r--lib/pbdrv/pb-buf.c1
-rw-r--r--lib/pbdrv/pb-buf.h1
-rw-r--r--lib/pbdrv/pb-mem.h1
-rw-r--r--lib/pbdrv/pb-mod.c18
-rw-r--r--lib/pbdrv/pb-mod.h1
-rw-r--r--lib/pbdrv/pb-msg.c5
-rw-r--r--lib/pbdrv/pb-msg.h3
-rw-r--r--lib/pbdrv/pb-route.c57
-rw-r--r--lib/pbdrv/pb-route.h1
-rw-r--r--lib/pbdrv/pb-send.c1
-rw-r--r--lib/pbdrv/pb-send.h3
-rw-r--r--lib/pbdrv/pb-serial.c37
-rw-r--r--lib/pbdrv/pb-serial.h1
-rw-r--r--lib/pbdrv/pb-types.h7
20 files changed, 95 insertions, 101 deletions
diff --git a/lib/pbdrv/drv/arduino/mod.cpp b/lib/pbdrv/drv/arduino/mod.cpp
index 27237d2..500edfa 100644
--- a/lib/pbdrv/drv/arduino/mod.cpp
+++ b/lib/pbdrv/drv/arduino/mod.cpp
@@ -3,14 +3,14 @@
#include <avr/delay.h>
#include <FreeRTOS.h>
-#include <timers.h>
#include <task.h>
+#include <timers.h>
-#include "../../pb.h"
-#include "../../pb-mod.h"
-#include "../../pb-types.h"
#include "../../pb-buf.h"
#include "../../pb-mem.h"
+#include "../../pb-mod.h"
+#include "../../pb-types.h"
+#include "../../pb.h"
static void async_pb_i2c_recv(void * _msg, uint32_t _) {
pb_buf_t * msg = (pb_buf_t *) _msg;
@@ -23,8 +23,7 @@ static void recv_event(int bytes) {
pb_buf_t * msg = (pb_buf_t *) pb_malloc(sizeof(pb_buf_t));
msg->data = (char *) pb_malloc(bytes);
msg->size = 0;
- while (Wire.available())
- msg->data[msg->size++] = Wire.read();
+ while (Wire.available()) msg->data[msg->size++] = Wire.read();
// defer pb_i2c_recv call
xTimerPendFunctionCallFromISR(async_pb_i2c_recv, msg, 0, NULL);
@@ -66,7 +65,7 @@ void init(void);
//! FreeRTOS loop task
void loop_task() {
- for(;;) {
+ for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
@@ -90,8 +89,8 @@ int main(void) {
init(); // call arduino internal setup
setup(); // call regular arduino setup
pb_setup(); // call pbdrv-mod setup
- xTaskCreate((TaskFunction_t) loop_task, "loop", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
+ xTaskCreate((TaskFunction_t) loop_task, "loop", configMINIMAL_STACK_SIZE,
+ NULL, tskIDLE_PRIORITY + 1, NULL);
vTaskStartScheduler(); // start freertos scheduler
return 0;
}
-
diff --git a/lib/pbdrv/drv/rp2040/mod.c b/lib/pbdrv/drv/rp2040/mod.c
index bca38d0..b031af9 100644
--- a/lib/pbdrv/drv/rp2040/mod.c
+++ b/lib/pbdrv/drv/rp2040/mod.c
@@ -1,11 +1,11 @@
-#include "../../pb.h"
-#include "../../pb-types.h"
+#include "../../pb-buf.h"
#include "../../pb-mod.h"
#include "../../pb-send.h"
-#include "../../pb-buf.h"
+#include "../../pb-types.h"
+#include "../../pb.h"
-#include <hardware/i2c.h>
#include <hardware/gpio.h>
+#include <hardware/i2c.h>
#include <pico/i2c_slave.h>
#define PB_I2C_S i2c0
@@ -17,7 +17,7 @@ uint8_t i2c_msg_buf[BUF_SIZE];
size_t i2c_msg_buf_sz = 0;
// This function is called from the I2C ISR
-static void recv_event(i2c_inst_t *i2c, i2c_slave_event_t event) {
+static void recv_event(i2c_inst_t * i2c, i2c_slave_event_t event) {
switch (event) {
case I2C_SLAVE_RECEIVE: {
if (i2c_msg_buf_sz == BUF_SIZE) return;
@@ -29,7 +29,8 @@ static void recv_event(i2c_inst_t *i2c, i2c_slave_event_t event) {
i2c_msg_buf_sz = 0;
break;
}
- default: break;
+ default:
+ break;
}
}
@@ -46,4 +47,3 @@ __weak void pb_i2c_send(i2c_addr_t addr, const uint8_t * buf, size_t sz) {
// false to write stop condition to i2c bus
i2c_write_timeout_us(PB_I2C_M, addr, buf, sz, false, PB_TIMEOUT_US);
}
-
diff --git a/lib/pbdrv/drv/rp2040/pb-mod.h b/lib/pbdrv/drv/rp2040/pb-mod.h
index 96edc70..7a4399e 100644
--- a/lib/pbdrv/drv/rp2040/pb-mod.h
+++ b/lib/pbdrv/drv/rp2040/pb-mod.h
@@ -18,4 +18,3 @@ void pb_setup();
#endif
#include "../../pb-mod.h"
-
diff --git a/lib/pbdrv/ext/freertos/pb-mem.c b/lib/pbdrv/ext/freertos/pb-mem.c
index 6647f05..d5e615a 100644
--- a/lib/pbdrv/ext/freertos/pb-mem.c
+++ b/lib/pbdrv/ext/freertos/pb-mem.c
@@ -4,14 +4,10 @@
#include "../../pb-types.h"
/// \ingroup pb_ext_freertos
-inline void * pb_malloc(size_t sz) {
- return pvPortMalloc(sz);
-}
+inline void * pb_malloc(size_t sz) { return pvPortMalloc(sz); }
/// \ingroup pb_ext_freertos
-inline void pb_free(void * ptr) {
- vPortFree(ptr);
-}
+inline void pb_free(void * ptr) { vPortFree(ptr); }
/// \ingroup pb_ext_freertos
__weak inline void * pb_realloc(void * ptr, size_t sz) {
@@ -21,16 +17,15 @@ __weak inline void * pb_realloc(void * ptr, size_t sz) {
/// \ingroup pb_ext_freertos
__weak void * pb_memcpy(void * dest, const void * src, size_t sz) {
for (size_t offset = 0; offset < sz; offset++)
- *((char*) dest + offset) = *((char*) src + offset);
+ *((char *) dest + offset) = *((char *) src + offset);
return dest;
}
/// \ingroup pb_ext_freertos
__weak int pb_memcmp(const void * a, const void * b, size_t sz) {
for (size_t offset = 0; offset < sz; offset++) {
- int diff = *((char*) a + offset) - *((char*) b + offset);
+ int diff = *((char *) a + offset) - *((char *) b + offset);
if (diff != 0) return diff;
}
return 0;
}
-
diff --git a/lib/pbdrv/ext/stdlib/pb-mem.c b/lib/pbdrv/ext/stdlib/pb-mem.c
index 328efbb..1b0b6e6 100644
--- a/lib/pbdrv/ext/stdlib/pb-mem.c
+++ b/lib/pbdrv/ext/stdlib/pb-mem.c
@@ -4,19 +4,13 @@
#include "../../pb-mem.h"
/// \ingroup pb_ext_stdlib
-inline void * pb_malloc(size_t sz) {
- return malloc(sz);
-}
+inline void * pb_malloc(size_t sz) { return malloc(sz); }
/// \ingroup pb_ext_stdlib
-inline void pb_free(void * ptr) {
- free(ptr);
-}
+inline void pb_free(void * ptr) { free(ptr); }
/// \ingroup pb_ext_stdlib
-inline void * pb_realloc(void * ptr, size_t sz) {
- return realloc(ptr, sz);
-}
+inline void * pb_realloc(void * ptr, size_t sz) { return realloc(ptr, sz); }
/// \ingroup pb_ext_stdlib
void * pb_memcpy(void * dest, const void * src, size_t sz) {
@@ -27,4 +21,3 @@ void * pb_memcpy(void * dest, const void * src, size_t sz) {
int pb_memcmp(const void * a, const void * b, size_t sz) {
return memcmp(a, b, sz);
}
-
diff --git a/lib/pbdrv/mpack-config.h b/lib/pbdrv/mpack-config.h
index 5b1215c..f08dd3b 100644
--- a/lib/pbdrv/mpack-config.h
+++ b/lib/pbdrv/mpack-config.h
@@ -20,4 +20,3 @@
// disable unused features (causes errors?)
#define MPACK_NODE 0
#define MPACK_BUILDER 0
-
diff --git a/lib/pbdrv/pb-buf.c b/lib/pbdrv/pb-buf.c
index 3d6cb8a..44befa4 100644
--- a/lib/pbdrv/pb-buf.c
+++ b/lib/pbdrv/pb-buf.c
@@ -6,4 +6,3 @@ void pb_buf_free(pb_buf_t * buf) {
pb_free(buf->data);
buf->data = NULL;
}
-
diff --git a/lib/pbdrv/pb-buf.h b/lib/pbdrv/pb-buf.h
index 8b4bb10..403f420 100644
--- a/lib/pbdrv/pb-buf.h
+++ b/lib/pbdrv/pb-buf.h
@@ -33,4 +33,3 @@ void pb_buf_free(pb_buf_t * buf);
#ifdef __cplusplus
}
#endif
-
diff --git a/lib/pbdrv/pb-mem.h b/lib/pbdrv/pb-mem.h
index 4d0f995..6dd15ea 100644
--- a/lib/pbdrv/pb-mem.h
+++ b/lib/pbdrv/pb-mem.h
@@ -71,4 +71,3 @@ int pb_memcmp(const void * a, const void * b, size_t sz);
#ifdef __cplusplus
}
#endif
-
diff --git a/lib/pbdrv/pb-mod.c b/lib/pbdrv/pb-mod.c
index 0342391..8375e9a 100644
--- a/lib/pbdrv/pb-mod.c
+++ b/lib/pbdrv/pb-mod.c
@@ -1,8 +1,8 @@
+#include "pb-mod.h"
#include "pb-buf.h"
#include "pb-msg.h"
-#include "pb-types.h"
-#include "pb-mod.h"
#include "pb-route.h"
+#include "pb-types.h"
//! fallback module name
__weak const char * PB_MOD_NAME = "???";
@@ -10,9 +10,7 @@ __weak const char * PB_MOD_NAME = "???";
//! [private] placeholder global state variable
static pb_global_state_t _global_state = PB_GS_NOINIT;
-__weak pb_global_state_t pb_hook_mod_state_read() {
- return _global_state;
-}
+__weak pb_global_state_t pb_hook_mod_state_read() { return _global_state; }
__weak void pb_hook_mod_state_write(pb_global_state_t state) {
_global_state = state;
@@ -28,17 +26,15 @@ __weak void pb_i2c_recv(const uint8_t * data, size_t sz) {
pb_msg_t * msg = pb_msg_read(&buf);
if (msg == NULL) return; // invalid message
if (msg->cmd == NULL) return; // invalid message
-
+
pb_route_msg(msg);
pb_msg_free(msg);
}
-__weak bool pb_hook_i2c_recv(const uint8_t * data, size_t sz) {
- return false;
-}
+__weak bool pb_hook_i2c_recv(const uint8_t * data, size_t sz) { return false; }
-__weak bool pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * data, size_t sz) {
+__weak bool pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * data,
+ size_t sz) {
return false;
}
-
diff --git a/lib/pbdrv/pb-mod.h b/lib/pbdrv/pb-mod.h
index 0050869..e1c4ca7 100644
--- a/lib/pbdrv/pb-mod.h
+++ b/lib/pbdrv/pb-mod.h
@@ -135,4 +135,3 @@ bool pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz);
#ifdef __cplusplus
}
#endif
-
diff --git a/lib/pbdrv/pb-msg.c b/lib/pbdrv/pb-msg.c
index 7fd6662..502beff 100644
--- a/lib/pbdrv/pb-msg.c
+++ b/lib/pbdrv/pb-msg.c
@@ -2,12 +2,12 @@
#include <mpack.h>
+#include "pb-mem.h"
#include "pb-msg.h"
#include "pb-serial.h"
-#include "pb-mem.h"
pb_buf_t pb_msg_write(const pb_msg_t * msg) {
- pb_buf_t buf = { 0 };
+ pb_buf_t buf = {0};
if (msg == NULL) return buf;
buf.data = pb_malloc(MPACK_BUFFER_SIZE);
@@ -43,4 +43,3 @@ void pb_msg_free(pb_msg_t * msg) {
// free message container that was created in \p pb_msg_read
pb_free(msg);
}
-
diff --git a/lib/pbdrv/pb-msg.h b/lib/pbdrv/pb-msg.h
index ff5bcde..12b908f 100644
--- a/lib/pbdrv/pb-msg.h
+++ b/lib/pbdrv/pb-msg.h
@@ -1,7 +1,7 @@
#pragma once
-#include "pb-types.h"
#include "pb-buf.h"
+#include "pb-types.h"
#ifdef __cplusplus
extern "C" {
@@ -57,4 +57,3 @@ void pb_msg_free(pb_msg_t * msg);
#ifdef __cplusplus
}
#endif
-
diff --git a/lib/pbdrv/pb-route.c b/lib/pbdrv/pb-route.c
index 5a7bd67..94d15d1 100644
--- a/lib/pbdrv/pb-route.c
+++ b/lib/pbdrv/pb-route.c
@@ -1,18 +1,22 @@
#include "pb-route.h"
+#include "pb-mem.h"
#include "pb-mod.h"
#include "pb-send.h"
#include "pb-types.h"
-#include "pb-mem.h"
__weak bool pb_hook_route_msg(pb_msg_t * msg) { return false; }
__weak void pb_route_msg(pb_msg_t * msg) {
if (pb_hook_route_msg(msg)) return;
switch (msg->type) {
- case PB_CMD_PROP: return pb_route_cmd_prop(msg);
- case PB_CMD_STATE: return pb_route_cmd_state(msg);
- case PB_CMD_MAGIC: return pb_route_cmd_magic(msg);
- default: return;
+ case PB_CMD_PROP:
+ return pb_route_cmd_prop(msg);
+ case PB_CMD_STATE:
+ return pb_route_cmd_state(msg);
+ case PB_CMD_MAGIC:
+ return pb_route_cmd_magic(msg);
+ default:
+ return;
}
}
@@ -21,10 +25,14 @@ __weak void pb_route_cmd_prop(pb_msg_t * msg) {
if (pb_hook_route_cmd_prop(msg)) return;
switch (msg->action) {
- case PB_ACTION_REQ: return pb_route_cmd_prop_req(msg);
- case PB_ACTION_RES: return pb_route_cmd_prop_res(msg);
- case PB_ACTION_SET: return pb_route_cmd_prop_set(msg);
- default: return;
+ case PB_ACTION_REQ:
+ return pb_route_cmd_prop_req(msg);
+ case PB_ACTION_RES:
+ return pb_route_cmd_prop_res(msg);
+ case PB_ACTION_SET:
+ return pb_route_cmd_prop_set(msg);
+ default:
+ return;
}
}
@@ -33,10 +41,14 @@ __weak void pb_route_cmd_state(pb_msg_t * msg) {
if (pb_hook_route_cmd_state(msg)) return;
switch (msg->action) {
- case PB_ACTION_REQ: return pb_route_cmd_state_req(msg);
- case PB_ACTION_RES: return pb_route_cmd_state_res(msg);
- case PB_ACTION_SET: return pb_route_cmd_state_set(msg);
- default: return;
+ case PB_ACTION_REQ:
+ return pb_route_cmd_state_req(msg);
+ case PB_ACTION_RES:
+ return pb_route_cmd_state_res(msg);
+ case PB_ACTION_SET:
+ return pb_route_cmd_state_set(msg);
+ default:
+ return;
}
}
@@ -45,9 +57,12 @@ __weak void pb_route_cmd_magic(pb_msg_t * msg) {
if (pb_hook_route_cmd_magic(msg)) return;
switch (msg->action) {
- case PB_ACTION_REQ: return pb_route_cmd_magic_req(msg);
- case PB_ACTION_RES: return pb_route_cmd_magic_res(msg);
- default: return;
+ case PB_ACTION_REQ:
+ return pb_route_cmd_magic_req(msg);
+ case PB_ACTION_RES:
+ return pb_route_cmd_magic_res(msg);
+ default:
+ return;
}
}
@@ -59,9 +74,7 @@ __weak void pb_route_cmd_prop_set(pb_msg_t * msg) {}
//! last known global state of last STATE REQ sender (i.e. main controller)
static pb_global_state_t _main_state = PB_GS_NOINIT;
__weak void pb_hook_ev_main_state_update(pb_global_state_t state) {}
-__weak void pb_hook_ev_module_init() {
- pb_hook_mod_state_write(PB_GS_IDLE);
-}
+__weak void pb_hook_ev_module_init() { pb_hook_mod_state_write(PB_GS_IDLE); }
__weak void pb_route_cmd_state_req(pb_msg_t * msg) {
pb_global_state_t own_state = pb_hook_mod_state_read();
@@ -91,12 +104,12 @@ __weak void pb_route_cmd_magic_req(pb_msg_t * msg) {
// return early if magic has wrong size
if (cmd->_magic_size != sizeof(pb_cmd_magic_req)) return;
// // return early if magic doesn't match
- if (pb_memcmp(cmd->magic, pb_cmd_magic_req, sizeof(pb_cmd_magic_req)) != 0) return;
+ if (pb_memcmp(cmd->magic, pb_cmd_magic_req, sizeof(pb_cmd_magic_req)) != 0)
+ return;
pb_buf_t buf = pb_send_magic_res();
pb_send_reply(msg, &buf);
pb_buf_free(&buf);
}
-__weak void pb_route_cmd_magic_res(pb_msg_t * msg) { }
-
+__weak void pb_route_cmd_magic_res(pb_msg_t * msg) {}
diff --git a/lib/pbdrv/pb-route.h b/lib/pbdrv/pb-route.h
index 5c28f4d..ac9672d 100644
--- a/lib/pbdrv/pb-route.h
+++ b/lib/pbdrv/pb-route.h
@@ -215,4 +215,3 @@ void pb_hook_ev_module_init();
#ifdef __cplusplus
}
#endif
-
diff --git a/lib/pbdrv/pb-send.c b/lib/pbdrv/pb-send.c
index dc34c44..b6efd3e 100644
--- a/lib/pbdrv/pb-send.c
+++ b/lib/pbdrv/pb-send.c
@@ -117,4 +117,3 @@ pb_buf_t pb_send_magic_res() {
};
return pb_msg_write(&msg);
}
-
diff --git a/lib/pbdrv/pb-send.h b/lib/pbdrv/pb-send.h
index 7e21eda..2b6afa0 100644
--- a/lib/pbdrv/pb-send.h
+++ b/lib/pbdrv/pb-send.h
@@ -1,7 +1,7 @@
#pragma once
-#include "pb-types.h"
#include "pb-buf.h"
+#include "pb-types.h"
#ifdef __cplusplus
extern "C" {
@@ -130,4 +130,3 @@ pb_buf_t pb_send_magic_res();
#ifdef __cplusplus
}
#endif
-
diff --git a/lib/pbdrv/pb-serial.c b/lib/pbdrv/pb-serial.c
index b9ee4b1..b1b48a3 100644
--- a/lib/pbdrv/pb-serial.c
+++ b/lib/pbdrv/pb-serial.c
@@ -13,10 +13,14 @@ void pb_ser_w(mpack_writer_t * writer, const pb_msg_t * cmd) {
if (cmd->cmd == NULL) return;
switch (cmd->type) {
- case PB_CMD_PROP: return pb_ser_w_cmd_prop(writer, cmd);
- case PB_CMD_STATE: return pb_ser_w_cmd_state(writer, cmd);
- case PB_CMD_MAGIC: return pb_ser_w_cmd_magic(writer, cmd);
- default: break;
+ case PB_CMD_PROP:
+ return pb_ser_w_cmd_prop(writer, cmd);
+ case PB_CMD_STATE:
+ return pb_ser_w_cmd_state(writer, cmd);
+ case PB_CMD_MAGIC:
+ return pb_ser_w_cmd_magic(writer, cmd);
+ default:
+ break;
}
}
void pb_ser_r(mpack_reader_t * reader, pb_msg_t * cmd) {
@@ -25,20 +29,28 @@ void pb_ser_r(mpack_reader_t * reader, pb_msg_t * cmd) {
cmd->sender = mpack_expect_u16(reader);
switch (cmd->type) {
- case PB_CMD_PROP: return pb_ser_r_cmd_prop(reader, cmd);
- case PB_CMD_STATE: return pb_ser_r_cmd_state(reader, cmd);
- case PB_CMD_MAGIC: return pb_ser_r_cmd_magic(reader, cmd);
- default: break;
+ case PB_CMD_PROP:
+ return pb_ser_r_cmd_prop(reader, cmd);
+ case PB_CMD_STATE:
+ return pb_ser_r_cmd_state(reader, cmd);
+ case PB_CMD_MAGIC:
+ return pb_ser_r_cmd_magic(reader, cmd);
+ default:
+ break;
}
}
void pb_ser_free(pb_msg_t * cmd) {
if (cmd == NULL) return;
switch (cmd->type) {
- case PB_CMD_PROP: return pb_ser_free_cmd_prop(cmd);
- case PB_CMD_STATE: return pb_ser_free_cmd_state(cmd);
- case PB_CMD_MAGIC: return pb_ser_free_cmd_magic(cmd);
- default: break;
+ case PB_CMD_PROP:
+ return pb_ser_free_cmd_prop(cmd);
+ case PB_CMD_STATE:
+ return pb_ser_free_cmd_state(cmd);
+ case PB_CMD_MAGIC:
+ return pb_ser_free_cmd_magic(cmd);
+ default:
+ break;
}
}
@@ -108,4 +120,3 @@ void pb_ser_free_cmd_magic(pb_msg_t * _msg) {
_msg->cmd = NULL;
}
}
-
diff --git a/lib/pbdrv/pb-serial.h b/lib/pbdrv/pb-serial.h
index 79f08d7..433a9a5 100644
--- a/lib/pbdrv/pb-serial.h
+++ b/lib/pbdrv/pb-serial.h
@@ -83,4 +83,3 @@ pb_ser_free_t pb_ser_free_cmd_magic;
#ifdef __cplusplus
}
#endif
-
diff --git a/lib/pbdrv/pb-types.h b/lib/pbdrv/pb-types.h
index ef3df54..686ec64 100644
--- a/lib/pbdrv/pb-types.h
+++ b/lib/pbdrv/pb-types.h
@@ -1,8 +1,8 @@
#pragma once
#include <stdbool.h>
-#include <stdint.h>
#include <stddef.h>
+#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@@ -82,13 +82,13 @@ typedef enum {
*
* The size of this array can be obtained by \c sizeof(pb_cmd_magic_req).
*/
-static const char pb_cmd_magic_req[] = { 0x70, 0x75, 0x7a, 0x62, 0x75, 0x73 };
+static const char pb_cmd_magic_req[] = {0x70, 0x75, 0x7a, 0x62, 0x75, 0x73};
/**
* \brief Magic reply from puzzle module back to main controller (="gaming")
*
* The size of this array can be obtained by \c sizeof(pb_cmd_magic_res).
*/
-static const char pb_cmd_magic_res[] = { 0x67, 0x61, 0x6d, 0x69, 0x6e, 0x67 };
+static const char pb_cmd_magic_res[] = {0x67, 0x61, 0x6d, 0x69, 0x6e, 0x67};
//! puzzle bus message header / container (shared by all commands)
typedef struct {
@@ -142,4 +142,3 @@ typedef struct {
#ifdef __cplusplus
}
#endif
-