示例#1
0
文件: i2c.c 项目: AmirAbrams/haiku
//!	Combined i2c send+receive format
status_t
i2c_send_receive(const i2c_bus *bus, int slaveAddress, const uint8 *writeBuffer,
	size_t writeLength, uint8 *readBuffer, size_t readLength)
{
	status_t status = send_start_condition(bus);
	if (status != B_OK)
		return status;

	status = send_slave_address(bus, slaveAddress, true);
	if (status != B_OK)
		goto err;

	status = send_bytes(bus, writeBuffer, writeLength);
	if (status != B_OK)
		goto err;

	status = send_start_condition(bus);
	if (status != B_OK)
		return status;

	status = send_slave_address(bus, slaveAddress, false);
	if (status != B_OK)
		goto err;

	status = receive_bytes(bus, readBuffer, readLength);
	if (status != B_OK)
		goto err;

	return send_stop_condition(bus);

err:
	TRACE("%s: Cancelling transmission\n", __func__);
	send_stop_condition(bus);
	return status;
}
示例#2
0
static void stop_transfer(struct twi_transfer *xfer,
			  enum twi_status new_status)
{
	send_stop_condition();

	transfer_set_status(xfer, new_status);

	twi.first_xfer = xfer->next;
	if (twi.first_xfer)
		send_start_condition();
	else
		twi.last_xfer = NULL;

	if (xfer->callback)
		xfer->callback(xfer, new_status);
}