4#include <linux/i2c-dev.h>
8#include "yahal_assert.h"
11enum i2c_mode { READ = 0x01, WRITE = 0x00 };
14i2c_BBB::i2c_BBB(
const char * dev) {
16 _fd = open (dev, O_RDWR);
18 ret = ioctl (_fd, I2C_TIMEOUT, 300);
23 int ret = close( _fd );
24 yahal_assert(ret != -1);
28int16_t i2c_BBB::i2cRead (uint16_t addr, uint8_t *rxbuf, uint16_t len,
bool sendStop) {
29 yahal_assert(sendStop);
30 yahal_assert(ioctl(_fd, I2C_SLAVE, addr) != -1);
31 int n = ::read(_fd, rxbuf, len);
32 yahal_assert(n == len);
37int16_t i2c_BBB::i2cWrite(uint16_t addr, uint8_t *txbuf, uint16_t len,
bool sendStop) {
38 yahal_assert(sendStop);
40 i2c_rdwr_ioctl_data data;
46 messages[0].addr = addr;
47 messages[0].flags = I2C::WRITE;
48 messages[0].len = len;
49 messages[0].buf = txbuf;
51 int ret = ioctl(_fd, I2C_RDWR, &data);
52 yahal_assert(ret != -1);
62void i2c_BBB::setSpeed(uint32_t Hz) {