Commit 4e9bd00d authored by Florian Weber's avatar Florian Weber Committed by Carles Cufi
Browse files

drivers: i2c: rtio



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

Signed-off-by: default avatarFlorian Weber <Florian.Weber@live.de>
parent 1c50c3a1
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -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);
+29 −0
Original line number Diff line number Diff line
@@ -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 */

/**