21 #ifndef MBED_I2C_API_H    22 #define MBED_I2C_API_H    26 #include "hal/buffer.h"    29 #include "hal/dma_api.h"   110 #define I2C_EVENT_ERROR               (1 << 1)   111 #define I2C_EVENT_ERROR_NO_SLAVE      (1 << 2)   112 #define I2C_EVENT_TRANSFER_COMPLETE   (1 << 3)   113 #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)   114 #define I2C_EVENT_ARBITRATION_LOST    (1 << 5)   115 #define I2C_EVENT_ALL                 (I2C_EVENT_ERROR |  \   116                                        I2C_EVENT_TRANSFER_COMPLETE | \   117                                        I2C_EVENT_ERROR_NO_SLAVE | \   118                                        I2C_EVENT_TRANSFER_EARLY_NACK | \   119                                        I2C_EVENT_ARBITRATION_LOST)   125 #if DEVICE_I2C_ASYNCH   129     uint32_t received_bytes;
   130     int32_t error_status; 
   148 #if DEVICE_I2C_ASYNCH   158     I2C_ERROR_NO_SLAVE = -1,
   159     I2C_ERROR_BUS_BUSY = -2,
   160     I2C_ERROR_TIMEOUT  = -3,
   161     I2C_ERROR_ARBITRATION_LOST = -4
   180     bool        supports_clock_stretching;
   269 void i2c_init(
i2c_t *obj, PinName sda, PinName scl, 
bool is_slave);
   365 int32_t 
i2c_write(
i2c_t *obj, uint16_t address, 
const uint8_t *data,
   366                   uint32_t length, 
bool stop);
   405 int32_t 
i2c_read(
i2c_t *obj, uint16_t address, uint8_t *data, uint32_t length,
   485 #if DEVICE_I2C_ASYNCH   506                         uint8_t *rx, uint32_t rx_length, uint16_t address,
 bool supports_slave_mode
If true, supports 10-bit addressing. 
const PinMap * i2c_master_scl_pinmap(void)
Get the pins that support I2C SCL. 
bool supports_multi_master
If true, supports configuring clock stretching. 
const PinMap * i2c_master_sda_pinmap(void)
Get the pins that support I2C SDA. 
Generic buffer structure. 
bool supports_10bit_addressing
If true, the device handle multimaster collisions and arbitration safely. 
void i2c_set_clock_stretching(i2c_t *obj, bool enabled)
Enable or disable clock stretching for the I2C peripheral. 
uint32_t maximum_frequency
If true, the device can handle I2C slave mode. 
void i2c_init(i2c_t *obj, PinName sda, PinName scl, bool is_slave)
Initialize the I2C peripheral. 
bool i2c_transfer_async(i2c_t *obj, const uint8_t *tx, uint32_t tx_length, uint8_t *rx, uint32_t rx_length, uint16_t address, bool stop, i2c_async_handler_f handler, void *ctx)
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. 
void i2c_get_capabilities(i2c_capabilities_t *capabilities)
Fills structure indicating supported features and frequencies on the current platform. 
void i2c_slave_address(i2c_t *obj, uint16_t address)
Configure I2C address. 
void i2c_stop(i2c_t *obj)
Send STOP command. 
void(* i2c_async_handler_f)(i2c_t *obj, i2c_async_event_t *event, void *ctx)
Asynchronous transfer callback. 
Structure describing the status of async transfer. 
uint32_t i2c_frequency(i2c_t *obj, uint32_t frequency)
Configure the frequency in Hz at which the I2C peripheral should operate. 
i2c_slave_status_t
Slave status. 
void i2c_timeout(i2c_t *obj, uint32_t timeout)
Configure the timeout duration in microseconds for blocking transmission. 
void i2c_abort_async(i2c_t *obj)
Abort asynchronous transfer. 
struct i2c_async_event i2c_async_event_t
Structure describing the status of async transfer. 
i2c_slave_status_t i2c_slave_status(i2c_t *obj)
Check to see if the I2C slave has been addressed. 
void i2c_free(i2c_t *obj)
Release the I2C object. 
int32_t i2c_write(i2c_t *obj, uint16_t address, const uint8_t *data, uint32_t length, bool stop)
Blocking sending data. 
int32_t i2c_read(i2c_t *obj, uint16_t address, uint8_t *data, uint32_t length, bool stop)
Blocking reading data. 
void i2c_start(i2c_t *obj)
Send START command. 
uint32_t minimum_frequency
< Minimum frequency supported must be set by target device