Module zio :: Class I2C

Class I2C

object --+    
         |    
    Module --+
             |
            I2C

I2C class is used to access devices over the I2C bus.
Instance Methods
 
__init__(self, agent)
Constructs an I2C object.
int
config(self, freq)
Configure the I2C bus clock frequency.
list
read(self, dev_addr, rlen)
Reads and returns specified no.
 
write(self, dev_addr, wlist)
Writes the specified bytes to the device at address dev_addr.
list
write_read(self, dev_addr, wlist, rlen)
Writes the specified bytes to the device, and reads rlen bytes from the device, at address dev_addr.

Inherited from Module: do_op

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties

Inherited from object: __class__

Method Details

__init__(self, agent)
(Constructor)

 
Constructs an I2C object.
Parameters:
  • agent (Agent) - the agent interface object
Overrides: object.__init__

config(self, freq)

 
Configure the I2C bus clock frequency. Returns the actual frequency set. The actual frequency set is the nearest available frequency.
Parameters:
  • freq (int) - the requested bus clock frequency.
Returns: int
the bus clock frequency actually set.
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted

read(self, dev_addr, rlen)

 
Reads and returns specified no. of bytes from the device at address dev_addr.
Parameters:
  • dev_addr (int) - the I2C device address
Returns: list
the bytes read from the device
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted
  • I2CNoAckError - If I2C device did not acknowledge a write

write(self, dev_addr, wlist)

 
Writes the specified bytes to the device at address dev_addr.
Parameters:
  • dev_addr (int) - the I2C device address
  • wlist (list) - the bytes to be written
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted
  • I2CNoAckError - If I2C device did not acknowledge a write

write_read(self, dev_addr, wlist, rlen)

 
Writes the specified bytes to the device, and reads rlen bytes from the device, at address dev_addr.
Parameters:
  • dev_addr (int) - the I2C device address
  • wlist (list) - the bytes to be written
  • rlen (int) - the no. of bytes to read from the device
Returns: list
the bytes read from the device
Raises:
  • ProtocolError - If communication with agent fails or if data sent or received is corrupted
  • I2CNoAckError - If I2C device did not acknowledge a write