Package io.helins.linux.i2c
Class SMBus
- java.lang.Object
-
- io.helins.linux.i2c.SMBus
-
public class SMBus extends Object
SMBus is more or less a subset of I2C and has its own standard.As such, the Linux kernel provides utilities for executing SMBus operations on an I2C bus.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSMBus.BlockClass representing a block of bytes for SMBus operations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intblockProcessCall(int command, SMBus.Block block)SMBus RPC-like operation, writing several bytes after specifying a command and then reading several bytes as an answer.intblockProcessCall(int command, SMBus.Block blockWrite, SMBus.Block blockRead)SMBus RPC-like operation, writing several bytes after specifying a command and then reading several bytes as an answer.intprocessCall(int command, int word)SMBus RPC-like operation, writing a short after specifying a command and then reading the answer.voidquick(boolean isWrite)SMBus operation sending only the READ or WRITE bit, no data is carried.intreadBlock(int command, SMBus.Block block)SMBus operation reading several bytes after specifying a command.intreadByte(int command)SMBus operation reading a byte after specifying a command.intreadByteDirectly()SMBus operation reading a byte without a command.voidreadI2CBlock(int command, SMBus.Block block, int length)SMBus-like operation reading several bytes after specifying a command where the length is part of the message.intreadWord(int command)SMBus operation reading a short after specifying a command.voidusePEC(boolean usePEC)Enables or disables packet error checking for SMBus commands.voidwriteBlock(int command, SMBus.Block block)SMBus operation writing several bytes after specifying a command.voidwriteByte(int command, int b)SMBus operation writing a byte after specifying a command.voidwriteByteDirectly(int b)SMBus operation writing a byte without a command.voidwriteI2CBlock(int command, SMBus.Block block)SMBus-like operation writing several bytes after specifying a command where the length is part of the message.voidwriteWord(int command, int word)SMBus operation writing a short after specifying a command.
-
-
-
Method Detail
-
usePEC
public void usePEC(boolean usePEC) throws IOExceptionEnables or disables packet error checking for SMBus commands.Is ignored unless the underlying driver provides this
functionality.Slave devices do not necessarely support this feature either.
- Parameters:
usePEC- Should PEC be enabled ?- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
quick
public void quick(boolean isWrite) throws IOExceptionSMBus operation sending only the READ or WRITE bit, no data is carried.- Parameters:
isWrite- True if the WRITE bit must be set.- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
readByteDirectly
public int readByteDirectly() throws IOExceptionSMBus operation reading a byte without a command.- Returns:
- Unsigned byte received from the slave.
- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
readByte
public int readByte(int command) throws IOExceptionSMBus operation reading a byte after specifying a command.- Parameters:
command- AKA "register".- Returns:
- Unsigned byte received from the slave.
- Throws:
IllegalStateException- When thelbus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
readWord
public int readWord(int command) throws IOExceptionSMBus operation reading a short after specifying a command.- Parameters:
command- AKA "register".- Returns:
- Unsigned short received from the slave.
- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
readBlock
public int readBlock(int command, SMBus.Block block) throws IOExceptionSMBus operation reading several bytes after specifying a command.- Parameters:
command- AKA "register".block- Block of bytes the answer will be written to.- Returns:
- Number of bytes read.
- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
readI2CBlock
public void readI2CBlock(int command, SMBus.Block block, int length) throws IOExceptionSMBus-like operation reading several bytes after specifying a command where the length is part of the message.This operation is not in the SMBus standard but is often supported nonetheless.
- Parameters:
command- AKA "register".block- Block of bytes the answer will be written to.length- How many bytes should be read.- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
writeByteDirectly
public void writeByteDirectly(int b) throws IOExceptionSMBus operation writing a byte without a command.- Parameters:
b- Unsigned byte that needs to be sent.- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
writeByte
public void writeByte(int command, int b) throws IOExceptionSMBus operation writing a byte after specifying a command.- Parameters:
command- AKA "register".b- Unsigned byte that needs to be sent.- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
writeWord
public void writeWord(int command, int word) throws IOExceptionSMBus operation writing a short after specifying a command.- Parameters:
command- AKA "register".word- Unsigned short that needs to be sent.- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
writeBlock
public void writeBlock(int command, SMBus.Block block) throws IOExceptionSMBus operation writing several bytes after specifying a command.After the command byte, the master also sends a byte count, how many bytes will be written.
- Parameters:
command- AKA "register".block- Block of bytes to write.- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
writeI2CBlock
public void writeI2CBlock(int command, SMBus.Block block) throws IOExceptionSMBus-like operation writing several bytes after specifying a command where the length is part of the message.This operation is not in the SMBus standard but is often supported nonetheless.
Unlike
writeBlock, this operation does not send a byte count after the command.- Parameters:
command- AKA "register".block- Block of bytes to write.- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
processCall
public int processCall(int command, int word) throws IOExceptionSMBus RPC-like operation, writing a short after specifying a command and then reading the answer.- Parameters:
command- AKA "register".word- Unsigned short to be sent.- Returns:
- Unsigned short given back by the slave.
- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
blockProcessCall
public int blockProcessCall(int command, SMBus.Block block) throws IOExceptionSMBus RPC-like operation, writing several bytes after specifying a command and then reading several bytes as an answer.- Parameters:
command- AKA "register".block- Block of bytes to write, also where the answer will be written to.- Returns:
- Number of bytes read.
- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
blockProcessCall
public int blockProcessCall(int command, SMBus.Block blockWrite, SMBus.Block blockRead) throws IOExceptionSMBus RPC-like operation, writing several bytes after specifying a command and then reading several bytes as an answer.- Parameters:
command- AKA "register".blockWrite- Block of bytes to write.blockRead- Block of bytes the answer will be written to (can be the same as blockWrite if it can be overwritten).- Returns:
- Number of bytes read.
- Throws:
IllegalStateException- When the underlying I2C bus has been closed.IOException- When the bus is not a proper I2C bus or an unplanned error occured.
-
-