package nl.nikhef.sfp.i2c;

import java.io.IOException;

/**
 * Generic I2C interface.
 * 
 * 
 * 
 * @author vincentb
 */
public interface I2CLink {

	/**
	 * Open the I2C link. Called before a batch of I2C transactions.
	 * 
	 * @throws IOException	If an I2C bus exception, or interface error occurs
	 */
	public void open() throws IOException;
	
	
	/**
	 * Close the I2C link. Called after a batch of I2C transactions.
	 * 
	 * Note: The 
	 * 
	 * @throws IOException	If an I2C bus exception, or interface error occurs
	 */
	public void close() throws IOException;
	
	/**
	 * Close the link and never open again.
	 * 
	 * @throws IOException
	 */
	public void shutdown() throws IOException;
	
	/**
	 * Write data to the I2C bus. 
	 * 
	 * @param addr		The I2C address without the r/w bit
	 * @param data		The data to write.
	 * 
	 * @throws IOException	If an I2C bus exception, or interface error occurs
	 */
	public void i2cWrite(int addr, byte[] data) throws IOException;
	
	/**
	 * Read from the I2C bus.
	 * 
	 * @param addr		The I2C address without the r/w bit
	 * @param len		Number of bytes to read
	 * @return			The data read.
	 * 
	 * @throws IOException	If an I2C bus exception, or interface error occurs
	 */
	public byte[] i2cRead(int addr, int len) throws IOException;
	
	/**
	 * Write then read from I2C bus.
	 * 
	 * @param addr		The I2C address
	 * @param dataWr	The data to write
	 * @param contRd	Whether or not to use continued read (advise)
	 * @param rdLen		No of bytes to read
	 * 
	 * @return			The data read.
	 * 
	 * @throws IOException	If an I2C bus exception, or interface error occurs
	 */
	public byte[] i2cWrRd(int addr, byte[] dataWr, boolean contRd, int rdLen) throws IOException;
}
