45 #include "dev_fs_lib_i2c.h" 50 I2C::I2C(
const char *
name,
const char *devname,
const int bus,
const uint16_t address,
const uint32_t frequency) :
53 DEVICE_DEBUG(
"I2C::I2C name = %s devname = %s", name, devname);
55 _device_id.devid_s.bus_type = DeviceBusType_I2C;
56 _device_id.devid_s.bus = bus;
57 _device_id.devid_s.address = address;
59 _device_id.devid_s.devtype = 0;
86 snprintf(dev_path,
sizeof(dev_path),
"/dev/iic-%i", get_device_bus());
87 _fd = ::open(dev_path, O_RDWR);
90 PX4_ERR(
"could not open %s", dev_path);
99 I2C::transfer(
const uint8_t *
send,
const unsigned send_len, uint8_t *recv,
const unsigned recv_len)
101 dspal_i2c_ioctl_combined_write_read ioctl_write_read{};
103 ioctl_write_read.write_buf = (uint8_t *)send;
104 ioctl_write_read.write_buf_len = send_len;
105 ioctl_write_read.read_buf = recv;
106 ioctl_write_read.read_buf_len = recv_len;
108 int bytes_read = ::ioctl(
_fd, I2C_IOCTL_RDWR, &ioctl_write_read);
110 if (bytes_read != (ssize_t)recv_len) {
111 PX4_ERR(
"read register reports a read of %d bytes, but attempted to read %d bytes", bytes_read, recv_len);
int transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len)
Perform an I2C transaction to the device.
Namespace encapsulating all device framework classes, functions and data.
void init()
Activates/configures the hardware registers.
virtual int init() override
#define DEVICE_DEBUG(FMT,...)