|
VSF Documented
|
#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. | |
| #define __I2C_MAX_DEVS_PER_BUS 16 |
| #define __I2C_MASTER_IRQ_ALL |
| #define __I2C_MASTER_IRQ_ERR |
|
extern |
| 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.
| [in] | bus_config | Bus configuration. |
| [out] | ret_bus_handle | Returned bus handle on success. |
| 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.
| 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.
| [in] | bus_handle | Master bus handle. |
| [in] | dev_config | Per-device configuration. |
| [out] | ret_handle | Returned device handle on success. |
| 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).
| [in] | i2c_dev | Device handle. |
| [in] | write_buffer | Data to transmit. |
| [in] | write_size | Number of bytes to write. |
| [in] | xfer_timeout_ms | Timeout in ms (-1 = wait forever). |
| 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).
| [in] | i2c_dev | Device handle. |
| [out] | read_buffer | Receive buffer. |
| [in] | read_size | Number of bytes to read. |
| [in] | xfer_timeout_ms | Timeout in ms (-1 = wait forever). |
| 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.
| [in] | i2c_dev | Device handle. |
| [in] | write_buffer | Data to transmit (register address, etc.). |
| [in] | write_size | Write byte count. |
| [out] | read_buffer | Receive buffer. |
| [in] | read_size | Read byte count. |
| [in] | xfer_timeout_ms | Timeout in ms (-1 = wait forever). |
| 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.
Since all transfers in this shim are synchronous, this is always an immediate success.
| bool is_inited |
| vsf_i2c_t* const* pool |
| uint16_t pool_count |
| i2c_master_bus_t* buses |
heap array [pool_count]