37#ifndef _FREERTOS_DRIVERS_ESP32_ESP32HARDWAREI2C_HXX_
38#define _FREERTOS_DRIVERS_ESP32_ESP32HARDWAREI2C_HXX_
43#include <driver/i2c.h>
44#include <hal/gpio_types.h>
48namespace openmrn_arduino
105 void hw_init(
const gpio_num_t sda,
const gpio_num_t scl,
106 const uint32_t bus_speed,
const i2c_port_t port = I2C_NUM_0);
114 void scan(
const i2c_port_t port);
128 ssize_t
write(
int fd,
const void *buf,
size_t size);
137 ssize_t
read(
int fd,
void *buf,
size_t size);
149 int open(
const char *path,
int flags,
int mode);
168 int ioctl(
int fd,
int cmd, va_list args);
Lightweight locking class for protecting small critical sections.
The ESP32 has one or two built-in I2C controller interfaces, this code provides a VFS interface that ...
bool vfsInitialized_
Internal tracking for the VFS adapter layer.
int transfer_messages(const i2c_port_t port, struct i2c_msg *msgs, int num)
Transfers multiple payloads to I2C devices.
static constexpr size_t I2C_SLAVE_RX_BUF_SIZE
I2C "Slave" RX buffer size, we do not use/support this feature so it is set to zero.
~Esp32HardwareI2C()
Destructor.
static constexpr int I2C_ISR_FLAGS
ISR flags to use for I2C, this defaults to allowing usage of a shared interupt.
const char *const path_
VFS Mount point.
static constexpr TickType_t I2C_SCAN_TIMEOUT
Timeout to use for I2C device scanning, default is 50 milliseconds.
void hw_init(const gpio_num_t sda, const gpio_num_t scl, const uint32_t bus_speed, const i2c_port_t port=I2C_NUM_0)
Initializes the underlying I2C controller hardware and VFS interface.
ssize_t read(int fd, void *buf, size_t size)
VFS implementation of read(fd, buf, size)
int ioctl(int fd, int cmd, va_list args)
VFS implementation of ioctl.
int open(const char *path, int flags, int mode)
VFS implementation of open(path, flags, mode).
bool i2cInitialized_[SOC_I2C_NUM]
Internal tracking for initialization of the underlying I2C hardware.
int close(int fd)
VFS implementation of close(fd).
void scan(const i2c_port_t port)
Utility method to perform a scan for all devices on the I2C bus.
Esp32HardwareI2C(const char *const path="/dev/i2c")
Constructor.
std::vector< i2c_device_t > devices_
Collection of I2C devices that have been opened.
ssize_t write(int fd, const void *buf, size_t size)
VFS implementation of write(fd, buf, size)
static constexpr size_t I2C_SLAVE_TX_BUF_SIZE
I2C "Slave" TX buffer size, we do not use/support this feature so it is set to zero.
static constexpr TickType_t I2C_OP_TIMEOUT
Timeout to use for I2C operations, default is one second.
Tracking structure used to map file handles to an I2C controller and address.
i2c_port_t port
I2C Controller that this file handle will use.
int fd
Assigned file handle for this entry.
int address
I2C address to use when greater than zero.