示例#1
0
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)
{
	if (quantity > BUFFER_LENGTH)
		quantity = BUFFER_LENGTH;

	/* Set slave address via ioctl  */ 
	i2c_setslave(i2c_fd, address);

	// if(i2c_transfer) {
	// /* Need to perform a combined read/write operation
	//  */
	// 	i2c_transfer = 0;
	// 	if (sendStop == false)
	// 		return 0;
	// 	i2c_add_to_buf(address, 1, rxBuffer, quantity);
	// 	if (!i2c_readwrite(i2c_fd)) {
	// 		rxBufferIndex = 0;
	// 		rxBufferLength = quantity;
	// 		i2c_transfer = 0;
	// 		return quantity;
	// 	} else
	// 		return 0;
	// }
	if (i2c_readbytes(i2c_fd, rxBuffer, quantity) < 0)
		return 0;
	// set rx buffer iterator vars
	rxBufferIndex = 0;
	rxBufferLength = quantity;

	return quantity;
}
示例#2
0
void DFTwoWire::beginTransmission(uint8_t address)
{
	if (i2c_fd < 0 || adapter_nr < 0)
		return;
	/* set slave address via ioctl in case we need to perform terminating 
	 * write operation
	 */
	i2c_setslave(i2c_fd, address);
	// save address of target and empty buffer
	txAddress = address;
	txBufferLength = 0;
}