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 <tim2.lin@ite.corp-partner.google.com>
This commit is contained in:
Tim Lin
2022-12-12 15:46:25 +08:00
committed by Carles Cufí
parent f4aeafd288
commit 27e2ec8a95
2 changed files with 53 additions and 0 deletions

View File

@@ -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

View File

@@ -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;
};