14 #include <boost/exception/errinfo_errno.hpp> 15 #include <boost/exception/errinfo_file_name.hpp> 17 #include <sys/ioctl.h> 18 #include <linux/i2c.h> 19 #include <linux/i2c-dev.h> 21 namespace duds {
namespace hardware {
namespace interface {
namespace linux {
24 dev(devname), addr(devaddr) {
25 fd = open(
dev.c_str(), O_RDWR);
31 if ((
addr > 127) && (ioctl(
fd, I2C_TENBIT, 1) < 0)) {
44 if (ioctl(
fd, I2C_RDWR, &idat) < 0) {
49 boost::errinfo_file_name(
dev) <<
57 boost::errinfo_file_name(
dev) <<
58 boost::errinfo_errno(res) <<
63 boost::errinfo_file_name(
dev) <<
68 boost::errinfo_file_name(
dev) <<
73 boost::errinfo_file_name(
dev) <<
78 boost::errinfo_file_name(
dev) <<
79 boost::errinfo_errno(res) <<
90 #ifdef I2C_RDWR_IOCTL_MAX_MSGS 91 #define I2C_MAX_MSGS I2C_RDWR_IOCTL_MAX_MSGS 92 #elif defined(I2C_RDRW_IOCTL_MAX_MSGS) 93 #define I2C_MAX_MSGS I2C_RDRW_IOCTL_MAX_MSGS 95 #error Neither I2C_RDWR_IOCTL_MAX_MSGS nor I2C_RDRW_IOCTL_MAX_MSGS is defined. 104 i2c_msg iparts[(conv.
size() > I2C_MAX_MSGS) ? I2C_MAX_MSGS : conv.
size()];
105 i2c_rdwr_ioctl_data idat = {
110 Conversation::PartVector::iterator iter = conv.
begin();
111 for (
int idx = 0; iter != conv.
end(); ++iter, ++idx) {
119 }
else if (idat.nmsgs == (I2C_MAX_MSGS - 1)) {
143 flags |= I2C_M_RECV_LEN;
145 iparts[idat.nmsgs].flags = I2C_M_RD;
153 iparts[idat.nmsgs].addr =
addr;
154 iparts[idat.nmsgs].flags = flags;
155 iparts[idat.nmsgs].len = cp.
length();
156 iparts[idat.nmsgs].buf = (__u8*)cp.
start();
static constexpr Flags MpfBreak
True/set to indicate that any kind of selection signal should be toggled, or a stop condition should ...
std::size_t size() const
Returns the number of parts within this conversation.
boost::error_info< struct Info_i2cdevaddr, int > I2cDeviceAddr
Provides the device (slave) address along with an error.
DevI2c(const std::string &devname, int devaddr)
Opens the device file for the bus.
bool varyingLength() const
True if this part is flagged as having a variable length.
The number of conversation parts is too great for the implementation to handle.
The device did not respond to its address (NACK).
Represents a section of a half-duplex conversation with a device.
A ConversationPart of an invalid length was specified.
virtual void converse(Conversation &conv)
Conducts I2C communication with a device using the Linux i2c-dev driver.
void io(i2c_rdwr_ioctl_data &idat)
Calls ioctl to request the kernel do the I2C communication, the check for error conditions and throw ...
static std::wstring_convert< std::codecvt_utf8< char32_t >, char32_t > conv
String converter; UTF-8 to/from UTF-32.
Base class for all errors specific to I2C communications and used for very general errors...
Flags flags() const
Returns the flags.
virtual std::size_t length() const =0
Returns the length of the buffer following the start pointer.
virtual char * start() const =0
Returns a pointer to the begining of the conversation part's buffer.
An attempt was made to use a non-existent I2C bus.
The operation took too long.
Header for Conversarion; includes ConversationVector.hpp and ConversationExternal.hpp.
PartVector::iterator begin()
An iterator to the first ConversationPart that allows modification.
The device has failed to conform to the protocol.
int addr
The device (slave) address.
~DevI2c()
Closes the device file.
The attempted operation is not supported by the bus master.
PartVector::iterator end()
An iterator to the end of ConversationPart vector.
A timeout occured while waiting to use the bus.
virtual int address() const
Returns the address of the device that this object will attempt to communicate with.
int fd
The file descriptor for the open device.
std::string dev
Stores the device file name for later error reporting.
bool input() const
True if this part is flagged for input use.
bool empty() const
Returns true if the conversation has no parts.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
Represents a two-way conversation with a device.
boost::error_info< struct Info_ConversationPartIndex, int > ConversationPartIndex
An attribute for errors when using Conversation objects that references the ConversationPart by index...