aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/pbdrv/drv/rp2040/mod.c2
-rw-r--r--lib/pbdrv/mpack-config.h2
-rw-r--r--lib/pbdrv/pb-mod.c5
-rw-r--r--lib/pbdrv/pb-mod.h16
-rw-r--r--main/i2c.c1
-rw-r--r--main/sock.c4
-rw-r--r--puzzle/dummy/FreeRTOSConfig.h2
7 files changed, 25 insertions, 7 deletions
diff --git a/lib/pbdrv/drv/rp2040/mod.c b/lib/pbdrv/drv/rp2040/mod.c
index 1535da9..bc20927 100644
--- a/lib/pbdrv/drv/rp2040/mod.c
+++ b/lib/pbdrv/drv/rp2040/mod.c
@@ -43,6 +43,8 @@ void pb_setup() {
}
__weak void pb_i2c_send(i2c_addr_t addr, const uint8_t * buf, size_t sz) {
+ pb_hook_i2c_send(addr, buf, 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/mpack-config.h b/lib/pbdrv/mpack-config.h
index 994d9b7..5b1215c 100644
--- a/lib/pbdrv/mpack-config.h
+++ b/lib/pbdrv/mpack-config.h
@@ -13,7 +13,7 @@
#define MPACK_MEMCMP pb_memcmp
// more reasonable buffer size (all messages are small)
-#define MPACK_BUFFER_SIZE 256
+#define MPACK_BUFFER_SIZE 64
#define MPACK_STACK_SIZE MPACK_BUFFER_SIZE
#define MPACK_PAGE_SIZE MPACK_BUFFER_SIZE
diff --git a/lib/pbdrv/pb-mod.c b/lib/pbdrv/pb-mod.c
index c27194e..6b23b04 100644
--- a/lib/pbdrv/pb-mod.c
+++ b/lib/pbdrv/pb-mod.c
@@ -18,7 +18,10 @@ __weak void pb_hook_mod_state_write(pb_global_state_t state) {
_global_state = state;
}
+__weak void pb_hook_i2c_recv(const uint8_t * data, size_t sz) { }
__weak void pb_i2c_recv(const uint8_t * data, size_t sz) {
+ pb_hook_i2c_recv(data, sz);
+
pb_buf_t buf = {
.data = (char *) data,
.size = sz,
@@ -32,3 +35,5 @@ __weak void pb_i2c_recv(const uint8_t * data, size_t sz) {
pb_msg_free(msg);
}
+__weak void pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * data, size_t sz) { }
+
diff --git a/lib/pbdrv/pb-mod.h b/lib/pbdrv/pb-mod.h
index 91e1d1f..e7b7832 100644
--- a/lib/pbdrv/pb-mod.h
+++ b/lib/pbdrv/pb-mod.h
@@ -62,10 +62,8 @@ void pb_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz);
/// \}
-/// \ingroup pb_hook
-/// \{
-
/**
+ * \ingroup pb_hook
* \defgroup pb_hook_mod_state State
* \brief Provide your own global state variable
*
@@ -94,6 +92,18 @@ pb_global_state_t pb_hook_mod_state_read();
void pb_hook_mod_state_write(pb_global_state_t state);
/// \}
+
+/**
+ * \ingroup pb_hook
+ * \defgroup pb_hook_i2c I2C
+ * \brief Intercept incoming/outgoing I2C messages
+ *
+ * \{
+ */
+
+void pb_hook_i2c_recv(const uint8_t * buf, size_t sz);
+void pb_hook_i2c_send(i2c_addr_t i2c_addr, const uint8_t * buf, size_t sz);
+
/// \}
#ifdef __cplusplus
diff --git a/main/i2c.c b/main/i2c.c
index e1563a0..3dfa7cb 100644
--- a/main/i2c.c
+++ b/main/i2c.c
@@ -122,3 +122,4 @@ pb_global_state_t pb_hook_mod_state_read() {
void pb_hook_mod_state_write(pb_global_state_t state) {
_global_state = state;
}
+
diff --git a/main/sock.c b/main/sock.c
index 33a6111..07db6af 100644
--- a/main/sock.c
+++ b/main/sock.c
@@ -14,7 +14,7 @@
struct netconn* current_connection = NULL;
i2ctcp_msg_t recv_msg;
-void i2c_send(uint16_t addr, const char * data, size_t data_size) {
+void pb_hook_i2c_send(i2c_addr_t addr, const uint8_t * data, size_t data_size) {
if (current_connection == NULL) return;
i2ctcp_msg_t send_msg = {
@@ -35,7 +35,7 @@ void i2c_send(uint16_t addr, const char * data, size_t data_size) {
free(buf);
}
-static void i2c_recv_fwd(uint16_t addr, const uint8_t * data, size_t data_size) {
+static void i2c_recv_fwd(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);
diff --git a/puzzle/dummy/FreeRTOSConfig.h b/puzzle/dummy/FreeRTOSConfig.h
index 1d98f78..072fdf7 100644
--- a/puzzle/dummy/FreeRTOSConfig.h
+++ b/puzzle/dummy/FreeRTOSConfig.h
@@ -17,7 +17,7 @@
#define configSTACK_DEPTH_TYPE uint16_t
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
-#define configTOTAL_HEAP_SIZE (1024)
+#define configTOTAL_HEAP_SIZE (1224)
// #define configTOTAL_HEAP_SIZE (7 * 1024)
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0