VSF Documented
Data Structures | Macros | Functions
driver_i2c_port.c File Reference
#include "../vsf_espidf_cfg.h"
#include "driver/i2c_master.h"
#include "../vsf_espidf.h"
#include "kernel/vsf_kernel.h"
#include "hal/driver/driver.h"
#include "service/heap/vsf_heap.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#include <string.h>

Data Structures

struct  i2c_master_bus_t
 
struct  i2c_master_dev_t
 

Macros

#define __I2C_MAX_DEVS_PER_BUS   16
 
#define __I2C_MASTER_IRQ_ALL
 
#define __I2C_MASTER_IRQ_ERR
 

Functions

void vsf_espidf_i2c_init (const vsf_espidf_i2c_cfg_t *cfg)
 
esp_err_t i2c_new_master_bus (const i2c_master_bus_config_t *bus_config, i2c_master_bus_handle_t *ret_bus_handle)
 Create a new I2C master bus.
 
esp_err_t i2c_del_master_bus (i2c_master_bus_handle_t bus_handle)
 Delete the I2C master bus and release the port.
 
esp_err_t i2c_master_bus_add_device (i2c_master_bus_handle_t bus_handle, const i2c_device_config_t *dev_config, i2c_master_dev_handle_t *ret_handle)
 Attach a device to the master bus.
 
esp_err_t i2c_master_bus_rm_device (i2c_master_dev_handle_t handle)
 Remove a device from the master bus.
 
esp_err_t i2c_master_transmit (i2c_master_dev_handle_t i2c_dev, const uint8_t *write_buffer, size_t write_size, int xfer_timeout_ms)
 Master write (START + addr/W + data + STOP).
 
esp_err_t i2c_master_receive (i2c_master_dev_handle_t i2c_dev, uint8_t *read_buffer, size_t read_size, int xfer_timeout_ms)
 Master read (START + addr/R + data + STOP).
 
esp_err_t i2c_master_transmit_receive (i2c_master_dev_handle_t i2c_dev, const uint8_t *write_buffer, size_t write_size, uint8_t *read_buffer, size_t read_size, int xfer_timeout_ms)
 Combined write-then-read with repeated START.
 
esp_err_t i2c_master_probe (i2c_master_bus_handle_t bus_handle, uint16_t address, int xfer_timeout_ms)
 Probe a device on the bus (write 0 bytes).
 
esp_err_t i2c_master_bus_reset (i2c_master_bus_handle_t bus_handle)
 Reset the I2C bus (toggle SCL to release SDA).
 
esp_err_t i2c_master_bus_wait_all_done (i2c_master_bus_handle_t bus_handle, int timeout_ms)
 Wait until all queued transfers are complete.
 

Macro Definition Documentation

◆ __I2C_MAX_DEVS_PER_BUS

#define __I2C_MAX_DEVS_PER_BUS   16

◆ __I2C_MASTER_IRQ_ALL

#define __I2C_MASTER_IRQ_ALL
Value:
( \
)
@ VSF_I2C_IRQ_MASK_MASTER_TRANSFER_COMPLETE
Definition i2c.h:109
@ VSF_I2C_IRQ_MASK_MASTER_ADDRESS_NACK
Definition i2c.h:113
@ VSF_I2C_IRQ_MASK_MASTER_ARBITRATION_LOST
Definition i2c.h:111
@ VSF_I2C_IRQ_MASK_MASTER_TX_NACK_DETECT
Definition i2c.h:115

◆ __I2C_MASTER_IRQ_ERR

#define __I2C_MASTER_IRQ_ERR

Function Documentation

◆ vsf_espidf_i2c_init()

void vsf_espidf_i2c_init ( const vsf_espidf_i2c_cfg_t cfg)
extern

◆ i2c_new_master_bus()

esp_err_t i2c_new_master_bus ( const i2c_master_bus_config_t bus_config,
i2c_master_bus_handle_t ret_bus_handle 
)

Create a new I2C master bus.

Allocates a bus handle from the injected pool. The underlying vsf_i2c_t is NOT initialised until the first transfer (lazy init on first device use), because the clock speed is a per-device property in this API.

Parameters
[in]bus_configBus configuration.
[out]ret_bus_handleReturned bus handle on success.
Returns
ESP_OK / ESP_ERR_INVALID_ARG / ESP_ERR_NOT_FOUND / ESP_ERR_INVALID_STATE (port already in use).

◆ i2c_del_master_bus()

esp_err_t i2c_del_master_bus ( i2c_master_bus_handle_t  bus_handle)

Delete the I2C master bus and release the port.

All devices attached to this bus must be removed first via i2c_master_bus_rm_device(); otherwise ESP_ERR_INVALID_STATE is returned.

◆ i2c_master_bus_add_device()

esp_err_t i2c_master_bus_add_device ( i2c_master_bus_handle_t  bus_handle,
const i2c_device_config_t dev_config,
i2c_master_dev_handle_t ret_handle 
)

Attach a device to the master bus.

The returned handle is used for all subsequent transfer calls. Multiple devices with different addresses / speeds may share one bus.

Parameters
[in]bus_handleMaster bus handle.
[in]dev_configPer-device configuration.
[out]ret_handleReturned device handle on success.

◆ i2c_master_bus_rm_device()

esp_err_t i2c_master_bus_rm_device ( i2c_master_dev_handle_t  handle)

Remove a device from the master bus.

◆ i2c_master_transmit()

esp_err_t i2c_master_transmit ( i2c_master_dev_handle_t  i2c_dev,
const uint8_t write_buffer,
size_t  write_size,
int  xfer_timeout_ms 
)

Master write (START + addr/W + data + STOP).

Parameters
[in]i2c_devDevice handle.
[in]write_bufferData to transmit.
[in]write_sizeNumber of bytes to write.
[in]xfer_timeout_msTimeout in ms (-1 = wait forever).

◆ i2c_master_receive()

esp_err_t i2c_master_receive ( i2c_master_dev_handle_t  i2c_dev,
uint8_t read_buffer,
size_t  read_size,
int  xfer_timeout_ms 
)

Master read (START + addr/R + data + STOP).

Parameters
[in]i2c_devDevice handle.
[out]read_bufferReceive buffer.
[in]read_sizeNumber of bytes to read.
[in]xfer_timeout_msTimeout in ms (-1 = wait forever).

◆ i2c_master_transmit_receive()

esp_err_t i2c_master_transmit_receive ( i2c_master_dev_handle_t  i2c_dev,
const uint8_t write_buffer,
size_t  write_size,
uint8_t read_buffer,
size_t  read_size,
int  xfer_timeout_ms 
)

Combined write-then-read with repeated START.

Sequence: START + addr/W + write_data + Sr + addr/R + read_data + STOP.

Parameters
[in]i2c_devDevice handle.
[in]write_bufferData to transmit (register address, etc.).
[in]write_sizeWrite byte count.
[out]read_bufferReceive buffer.
[in]read_sizeRead byte count.
[in]xfer_timeout_msTimeout in ms (-1 = wait forever).

◆ i2c_master_probe()

esp_err_t i2c_master_probe ( i2c_master_bus_handle_t  bus_handle,
uint16_t  address,
int  xfer_timeout_ms 
)

Probe a device on the bus (write 0 bytes).

Returns
ESP_OK if the device ACKed its address, ESP_ERR_NOT_FOUND if not.

◆ i2c_master_bus_reset()

esp_err_t i2c_master_bus_reset ( i2c_master_bus_handle_t  bus_handle)

Reset the I2C bus (toggle SCL to release SDA).

◆ i2c_master_bus_wait_all_done()

esp_err_t i2c_master_bus_wait_all_done ( i2c_master_bus_handle_t  bus_handle,
int  timeout_ms 
)

Wait until all queued transfers are complete.

Since all transfers in this shim are synchronous, this is always an immediate success.

Variable Documentation

◆ is_inited

bool is_inited

◆ pool

vsf_i2c_t* const* pool

◆ pool_count

uint16_t pool_count

◆ buses

heap array [pool_count]

Generated from commit: vsfteam/vsf@015f4d1