diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-05-30 15:51:08 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-05-30 15:51:08 +0200 |
commit | b231e9d808f40aef0895787ea09624787b10addd (patch) | |
tree | 6ee2a4550e1c4a6384dd22e9967464b7766dc9cc | |
parent | d1f5291f82f5e13db756adc919883e310cc537de (diff) |
more client i2c shuffling
-rw-r--r-- | client/CMakeLists.txt | 2 | ||||
-rw-r--r-- | client/cmd.cpp | 3 | ||||
-rw-r--r-- | client/i2c.cpp | 37 | ||||
-rw-r--r-- | client/i2c.h | 8 | ||||
-rw-r--r-- | client/sock.cpp | 31 | ||||
-rw-r--r-- | client/sock.h | 3 | ||||
-rw-r--r-- | shared/include.cmake | 2 | ||||
-rw-r--r-- | shared/pb/moddrv.c (renamed from shared/pb/driver.c) | 19 | ||||
-rw-r--r-- | shared/pb/moddrv.h (renamed from shared/pb/driver.h) | 0 |
9 files changed, 61 insertions, 44 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 50d3cd7..cb891a6 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -20,11 +20,11 @@ add_executable(pbc cmd.cpp parse.cpp xxd.c + i2c.cpp ) target_link_libraries(pbc i2ctcp - puzbus mpack readline # this is such a common library that I did not bother adding it as a submodule ) diff --git a/client/cmd.cpp b/client/cmd.cpp index e3c9eb9..5ac2ff3 100644 --- a/client/cmd.cpp +++ b/client/cmd.cpp @@ -4,10 +4,9 @@ #include <string.h> #include "cmd.h" -#include "i2ctcpv1.h" #include "pb/types.h" #include "rl.h" -#include "sock.h" +#include "i2c.h" #include "parse.h" #include "pb/bus.h" diff --git a/client/i2c.cpp b/client/i2c.cpp new file mode 100644 index 0000000..fd29e1e --- /dev/null +++ b/client/i2c.cpp @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "i2ctcpv1.h" +#include "sock.h" +#include "xxd.h" + +bool i2c_dump_send = false; +bool i2c_dump_recv = true; + +void i2c_send(uint16_t addr, const char * data, size_t data_size) { + i2ctcp_msg_t msg = { + .addr = addr, + .data = (char *) data, + .length = data_size, + }; + + char* packed; + size_t size; + if (!i2ctcp_write(&msg, &packed, &size)) return; + + sock->send(packed, size); + if (i2c_dump_send) { + printf("[%s] addr(0x%02x) data(0x%02lx):\n", __FUNCTION__, addr, data_size); + xxd(data, data_size); + } + + free(packed); +} + +void i2c_recv(uint16_t addr, const char * data, size_t data_size) { + if (i2c_dump_recv) { + printf("[%s] addr(0x%02x) data(0x%02lx):\n", __FUNCTION__, addr, data_size); + xxd(data, data_size); + } +} + diff --git a/client/i2c.h b/client/i2c.h new file mode 100644 index 0000000..f9f58f9 --- /dev/null +++ b/client/i2c.h @@ -0,0 +1,8 @@ +#pragma once + +#include <stdint.h> +#include <stddef.h> + +void i2c_send(uint16_t addr, const char * data, size_t data_size); +void i2c_recv(uint16_t addr, const char * data, size_t data_size); + diff --git a/client/sock.cpp b/client/sock.cpp index f5bd564..638bf9d 100644 --- a/client/sock.cpp +++ b/client/sock.cpp @@ -7,13 +7,12 @@ #include <sys/socket.h> #include <netinet/in.h> #include <errno.h> - #include <thread> #include "i2ctcpv1.h" #include "sock.h" #include "rl.h" -#include "xxd.h" +#include "i2c.h" using std::logic_error; using std::thread; @@ -106,31 +105,3 @@ void PBSocket::sock_task() { sock_close(); } -bool i2c_dump_send = false; -bool i2c_dump_recv = true; - -void i2c_send(uint16_t addr, const char * data, size_t data_size) { - i2ctcp_msg_t msg = { - .addr = addr, - .data = (char *) data, - .length = data_size, - }; - - char* packed; - size_t size; - if (!i2ctcp_write(&msg, &packed, &size)) return; - - sock->send(packed, size); - if (i2c_dump_send) { - printf("[i2c send] data(0x%02lx):\n", data_size); - xxd(data, data_size); - } -} - -void i2c_recv(uint16_t addr, const char * data, size_t data_size) { - if (i2c_dump_recv) { - printf("[i2c recv] data(0x%02lx):\n", data_size); - xxd(data, data_size); - } -} - diff --git a/client/sock.h b/client/sock.h index 42eba3b..0dee09e 100644 --- a/client/sock.h +++ b/client/sock.h @@ -29,6 +29,3 @@ private: extern PBSocket* sock; -void i2c_send(uint16_t addr, const char * data, size_t data_size); -void i2c_recv(uint16_t addr, const char * data, size_t data_size); - diff --git a/shared/include.cmake b/shared/include.cmake index f07a78b..c4b01c2 100644 --- a/shared/include.cmake +++ b/shared/include.cmake @@ -1,5 +1,5 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}) add_library(puzbus STATIC - ${CMAKE_CURRENT_LIST_DIR}/pb/driver.c + ${CMAKE_CURRENT_LIST_DIR}/pb/moddrv.c ) diff --git a/shared/pb/driver.c b/shared/pb/moddrv.c index f43d5c1..4c897e0 100644 --- a/shared/pb/driver.c +++ b/shared/pb/moddrv.c @@ -1,7 +1,7 @@ #include <memory.h> #include "types.h" -#include "driver.h" +#include "moddrv.h" /** \brief [private] placeholder global state variable */ static pb_state_t _global_state = PB_GS_NOINIT; @@ -17,12 +17,6 @@ __weak void pbdrv_hook_mod_state_write(pb_state_t state) { _global_state = state; } -__weak void pbdrv_hook_main_state_update(pb_state_t state) { } - -__weak bool pbdrv_hook_cmd(uint16_t i2c_addr, pb_cmd_t cmd, const char * buf, size_t sz) { - return false; -} - __weak void pbdrv_i2c_recv(uint16_t i2c_addr, const char * buf, size_t sz) { if (sz == 0) return; pb_cmd_t cmd = (enum pb_cmd) buf[0]; @@ -111,3 +105,14 @@ __weak void pbdrv_handle_sex(uint16_t i2c_addr, const char * buf, size_t sz) { pbdrv_hook_main_state_update(_main_state); } +__weak void pbdrv_hook_main_state_update(pb_state_t state) { } +__weak bool pbdrv_hook_cmd(uint16_t i2c_addr, pb_cmd_t cmd, const char * buf, size_t sz) { + return false; +} +__weak bool pbdrv_hook_read(uint16_t i2c_addr, uint8_t addr) { + return false; +} +__weak bool pbdrv_hook_write(uint16_t i2c_addr, uint8_t addr, const char * buf, size_t sz) { + return false; +} + diff --git a/shared/pb/driver.h b/shared/pb/moddrv.h index c4e1167..c4e1167 100644 --- a/shared/pb/driver.h +++ b/shared/pb/moddrv.h |