20 #ifndef MBED_I2C_API_H 21 #define MBED_I2C_API_H 25 #include "hal/buffer.h" 28 #include "hal/dma_api.h" 38 #define I2C_EVENT_ERROR (1 << 1) 39 #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2) 40 #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3) 41 #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4) 42 #define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK) 58 typedef struct i2c_s
i2c_t;
63 I2C_ERROR_NO_SLAVE = -1,
64 I2C_ERROR_BUS_BUSY = -2
199 int i2c_read(
i2c_t *obj,
int address,
char *data,
int length,
int stop);
212 int i2c_write(
i2c_t *obj,
int address,
const char *data,
int length,
int stop);
323 #if DEVICE_I2C_ASYNCH 343 void i2c_transfer_asynch(
i2c_t *obj,
const void *tx,
size_t tx_length,
void *rx,
size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint);
void i2c_abort_asynch(i2c_t *obj)
Abort asynchronous transfer.
const PinMap * i2c_master_scl_pinmap(void)
Get the pins that support I2C SCL.
void i2c_slave_mode(i2c_t *obj, int enable_slave)
Configure I2C as slave or master.
const PinMap * i2c_master_sda_pinmap(void)
Get the pins that support I2C SDA.
void i2c_init(i2c_t *obj, PinName sda, PinName scl)
Initialize the I2C peripheral.
Generic buffer structure.
int i2c_slave_read(i2c_t *obj, char *data, int length)
Configure I2C as slave or master.
uint8_t i2c_active(i2c_t *obj)
Attempts to determine if the I2C peripheral is already in use.
void i2c_transfer_asynch(i2c_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint)
Start I2C asynchronous transfer.
const PinMap * i2c_slave_sda_pinmap(void)
Get the pins that support I2C SDA.
const PinMap * i2c_slave_scl_pinmap(void)
Get the pins that support I2C SCL.
Asynch I2C HAL structure.
int i2c_byte_read(i2c_t *obj, int last)
Read one byte.
int i2c_slave_receive(i2c_t *obj)
Check to see if the I2C slave has been addressed.
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
Blocking sending data.
int i2c_byte_write(i2c_t *obj, int data)
Write one byte.
uint32_t i2c_irq_handler_asynch(i2c_t *obj)
The asynchronous IRQ handler.
int i2c_stop(i2c_t *obj)
Send STOP command.
int i2c_start(i2c_t *obj)
Send START command.
void i2c_reset(i2c_t *obj)
Reset I2C peripheral.
void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask)
Configure I2C address.
void i2c_frequency(i2c_t *obj, int hz)
Configure the I2C frequency.
int i2c_slave_write(i2c_t *obj, const char *data, int length)
Configure I2C as slave or master.
void i2c_free(i2c_t *obj)
Release a I2C object.
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
Blocking reading data.
void i2c_init_direct(i2c_t *obj, const i2c_pinmap_t *pinmap)
Initialize the I2C peripheral.