1 #include "i2c.hpp" 2 3 #include <fcntl.h> 4 #include <sys/stat.h> 5 #include <unistd.h> 6 7 #include <cerrno> 8 9 namespace i2c 10 { 11 12 void I2CDevice::open() 13 { 14 fd = ::open(busStr.c_str(), O_RDWR); 15 if (fd == -1) 16 { 17 throw I2CException("Failed to open", busStr, devAddr, errno); 18 } 19 } 20 21 void I2CDevice::close() 22 { 23 ::close(fd); 24 } 25 26 void I2CDevice::read(uint8_t& data) 27 { 28 // TODO 29 (void)data; 30 } 31 32 void I2CDevice::read(uint8_t addr, uint8_t& data) 33 { 34 // TODO 35 (void)addr; 36 (void)data; 37 } 38 39 void I2CDevice::read(uint8_t addr, uint16_t& data) 40 { 41 // TODO 42 (void)addr; 43 (void)data; 44 } 45 46 void I2CDevice::read(uint8_t addr, uint8_t& size, uint8_t* data) 47 { 48 // TODO 49 (void)addr; 50 (void)size; 51 (void)data; 52 } 53 54 void I2CDevice::write(uint8_t data) 55 { 56 // TODO 57 (void)data; 58 } 59 60 void I2CDevice::write(uint8_t addr, uint8_t data) 61 { 62 // TODO 63 (void)addr; 64 (void)data; 65 } 66 67 void I2CDevice::write(uint8_t addr, uint16_t data) 68 { 69 // TODO 70 (void)addr; 71 (void)data; 72 } 73 74 void I2CDevice::write(uint8_t addr, uint8_t size, const uint8_t* data) 75 { 76 // TODO 77 (void)addr; 78 (void)size; 79 (void)data; 80 } 81 82 std::unique_ptr<I2CInterface> I2CDevice::create(uint8_t busId, uint8_t devAddr) 83 { 84 std::unique_ptr<I2CDevice> dev(new I2CDevice(busId, devAddr)); 85 return dev; 86 } 87 88 std::unique_ptr<I2CInterface> create(uint8_t busId, uint8_t devAddr) 89 { 90 return I2CDevice::create(busId, devAddr); 91 } 92 93 } // namespace i2c 94