drivers: i2c: rtio

extend i2c library to create rtio sqes for reading and writing bytes

Signed-off-by: Florian Weber <Florian.Weber@live.de>
This commit is contained in:
Florian Weber 2025-01-10 10:25:00 +01:00 committed by Carles Cufí
parent 1c50c3a12b
commit 4e9bd00dfb
2 changed files with 70 additions and 0 deletions

View File

@ -52,6 +52,47 @@ struct rtio_sqe *i2c_rtio_copy(struct rtio *r, struct rtio_iodev *iodev, const s
return sqe;
}
struct rtio_sqe *i2c_rtio_copy_reg_write_byte(struct rtio *r, struct rtio_iodev *iodev,
uint8_t reg_addr, uint8_t data)
{
uint8_t msg[2];
struct rtio_sqe *sqe = rtio_sqe_acquire(r);
if (sqe == NULL) {
rtio_sqe_drop_all(r);
return NULL;
}
msg[0] = reg_addr;
msg[1] = data;
rtio_sqe_prep_tiny_write(sqe, iodev, RTIO_PRIO_NORM, msg, sizeof(msg), NULL);
sqe->iodev_flags = RTIO_IODEV_I2C_STOP;
return sqe;
}
struct rtio_sqe *i2c_rtio_copy_reg_burst_read(struct rtio *r, struct rtio_iodev *iodev,
uint8_t start_addr, void *buf, size_t num_bytes)
{
struct rtio_sqe *sqe = rtio_sqe_acquire(r);
if (sqe == NULL) {
rtio_sqe_drop_all(r);
return NULL;
}
rtio_sqe_prep_tiny_write(sqe, iodev, RTIO_PRIO_NORM, &start_addr, 1, NULL);
sqe->flags |= RTIO_SQE_TRANSACTION;
sqe = rtio_sqe_acquire(r);
if (sqe == NULL) {
rtio_sqe_drop_all(r);
return NULL;
}
rtio_sqe_prep_read(sqe, iodev, RTIO_PRIO_NORM, buf, num_bytes, NULL);
sqe->iodev_flags |= RTIO_IODEV_I2C_STOP | RTIO_IODEV_I2C_RESTART;
return sqe;
}
void i2c_rtio_init(struct i2c_rtio *ctx, const struct device *dev)
{
k_sem_init(&ctx->lock, 1, 1);

View File

@ -1092,6 +1092,35 @@ struct rtio_sqe *i2c_rtio_copy(struct rtio *r,
const struct i2c_msg *msgs,
uint8_t num_msgs);
/**
* @brief Copy the register address and data to a SQE
*
* @param r RTIO context
* @param iodev RTIO IODev to target for the submissions
* @param reg_addr target register address
* @param data data to be written
*
* @retval sqe Last submission in the queue added
* @retval NULL Not enough memory in the context to copy the requests
*/
struct rtio_sqe *i2c_rtio_copy_reg_write_byte(struct rtio *r, struct rtio_iodev *iodev,
uint8_t reg_addr, uint8_t data);
/**
* @brief acquire and configure a i2c burst read transmission
*
* @param r RTIO context
* @param iodev RTIO IODev to target for the submissions
* @param start_addr target register address
* @param buf Memory pool that stores the retrieved data.
* @param num_bytes Number of bytes to read.
*
* @retval sqe Last submission in the queue added
* @retval NULL Not enough memory in the context to copy the requests
*/
struct rtio_sqe *i2c_rtio_copy_reg_burst_read(struct rtio *r, struct rtio_iodev *iodev,
uint8_t start_addr, void *buf, size_t num_bytes);
#endif /* CONFIG_I2C_RTIO */
/**