From 27e2ec8a95e9de227e1cd1ef599cffed5b8e28b3 Mon Sep 17 00:00:00 2001 From: Tim Lin Date: Mon, 12 Dec 2022 15:46:25 +0800 Subject: [PATCH] drivers/i2c: Add callback functions to support buffer mode in header file Add buf_write_received and buf_read_requested callback functions to support buffer mode. Signed-off-by: Tim Lin --- drivers/i2c/target/Kconfig | 6 +++++ include/zephyr/drivers/i2c.h | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/drivers/i2c/target/Kconfig b/drivers/i2c/target/Kconfig index 679bdc98f4..6894d12bef 100644 --- a/drivers/i2c/target/Kconfig +++ b/drivers/i2c/target/Kconfig @@ -19,6 +19,12 @@ config I2C_TARGET_INIT_PRIORITY help I2C Target device driver initialization priority. +config I2C_TARGET_BUFFER_MODE + bool "I2C target driver for buffer mode [EXPERIMENTAL]" + select EXPERIMENTAL + help + This is an option to enable buffer mode. + source "drivers/i2c/target/Kconfig.eeprom" endif # I2C_TARGET diff --git a/include/zephyr/drivers/i2c.h b/include/zephyr/drivers/i2c.h index ecb1eaa7c2..ef96c2ee17 100644 --- a/include/zephyr/drivers/i2c.h +++ b/include/zephyr/drivers/i2c.h @@ -352,6 +352,49 @@ typedef int (*i2c_target_read_requested_cb_t)( typedef int (*i2c_target_read_processed_cb_t)( struct i2c_target_config *config, uint8_t *val); +#ifdef CONFIG_I2C_TARGET_BUFFER_MODE +/** @brief Function called when a write to the device is completed. + * + * This function is invoked by the controller when it completes + * reception of data from the source buffer to the destination + * buffer in an ongoing write operation to the device. + * + * @param config the configuration structure associated with the + * device to which the operation is addressed. + * + * @param ptr pointer to the buffer that contains the data to be transferred. + * + * @param len the length of the data to be transferred. + */ +typedef void (*i2c_target_buf_write_received_cb_t)( + struct i2c_target_config *config, uint8_t *ptr, uint32_t len); + +/** @brief Function called when a read from the device is initiated. + * + * This function is invoked by the controller when the bus is ready to + * provide additional data by buffer for a read operation from the address + * associated with the device. + * + * The value returned in @p **ptr and @p *len will be transmitted. A success + * return shall cause the controller to react to additional read operations. + * An error return shall cause the controller to ignore bus operations until + * a new start condition is received. + * + * @param config the configuration structure associated with the + * device to which the operation is addressed. + * + * @param ptr pointer to storage for the address of data buffer to return + * for the read request. + * + * @param len pointer to storage for the length of the data to be transferred + * for the read request. + * + * @return 0 if data has been provided, or a negative error code. + */ +typedef int (*i2c_target_buf_read_requested_cb_t)( + struct i2c_target_config *config, uint8_t **ptr, uint32_t *len); +#endif + /** @brief Function called when a stop condition is observed after a * start condition addressed to a particular device. * @@ -379,6 +422,10 @@ struct i2c_target_callbacks { i2c_target_read_requested_cb_t read_requested; i2c_target_write_received_cb_t write_received; i2c_target_read_processed_cb_t read_processed; +#ifdef CONFIG_I2C_TARGET_BUFFER_MODE + i2c_target_buf_write_received_cb_t buf_write_received; + i2c_target_buf_read_requested_cb_t buf_read_requested; +#endif i2c_target_stop_cb_t stop; };