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 /shared/pb/moddrv.h | |
parent | d1f5291f82f5e13db756adc919883e310cc537de (diff) |
more client i2c shuffling
Diffstat (limited to 'shared/pb/moddrv.h')
-rw-r--r-- | shared/pb/moddrv.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/shared/pb/moddrv.h b/shared/pb/moddrv.h new file mode 100644 index 0000000..c4e1167 --- /dev/null +++ b/shared/pb/moddrv.h @@ -0,0 +1,62 @@ +#pragma once + +/** + * \file puzzle bus driver implementation + * + * Most \c pbdrv_* functions have a weak implementation, which may be + * overwritten by a custom implementation. This allows you to use the default + * implementation where possible, and only implement extensions required for + * your puzzle module. Please see spec.adoc for more information about how to + * use the puzzle bus driver library. + */ + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> + +#include "types.h" + +#ifndef PBDRV_MOD_NAME +#define PBDRV_MOD_NAME "???" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +void pbdrv_i2c_recv(uint16_t i2c_addr, const char * buf, size_t sz); +void pbdrv_i2c_send(uint16_t i2c_addr, const char * buf, size_t sz); + +pb_state_t pbdrv_hook_mod_state_read(); +void pbdrv_hook_mod_state_write(pb_state_t state); +void pbdrv_hook_main_state_update(pb_state_t state); + +/** + * \name hooks + * + * Implementing this function allows you to use the weak implementation of \c + * pbdrv_i2c_recv() while being able to implement custom command handlers. + * + * \return true if the cmd was recognized, or false to forward the command to + * the default handlers + * + * \{ + */ + +/** \brief cmd receive hook */ +bool pbdrv_hook_cmd(uint16_t i2c_addr, pb_cmd_t cmd, const char * buf, size_t sz); +/** \brief read cmd hook */ +bool pbdrv_hook_read(uint16_t i2c_addr, uint8_t addr); +/** \brief write cmd hook */ +bool pbdrv_hook_write(uint16_t i2c_addr, uint8_t addr, const char * buf, size_t sz); +//! \} + +void pbdrv_handle_read(uint16_t i2c_addr, const char * buf, size_t sz); +void pbdrv_handle_write(uint16_t i2c_addr, const char * buf, size_t sz); +void pbdrv_handle_magic(uint16_t i2c_addr, const char * buf, size_t sz); +void pbdrv_handle_sex(uint16_t i2c_addr, const char * buf, size_t sz); + +#ifdef __cplusplus +} +#endif + |