123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
-
- #ifndef MBED_I2C_API_H
- #define MBED_I2C_API_H
-
- #include "device.h"
- #include "buffer.h"
- #include "dma_api.h"
-
- #if DEVICE_I2C
-
-
- #define I2C_EVENT_ERROR (1 << 1)
- #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2)
- #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3)
- #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)
- #define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK)
-
-
-
- #if DEVICE_I2C_ASYNCH
-
- typedef struct {
- struct i2c_s i2c;
- struct buffer_s tx_buff;
- struct buffer_s rx_buff;
- } i2c_t;
-
- #else
-
- typedef struct i2c_s i2c_t;
-
- #endif
-
- enum {
- I2C_ERROR_NO_SLAVE = -1,
- I2C_ERROR_BUS_BUSY = -2
- };
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
-
-
- void i2c_init(i2c_t *obj, PinName sda, PinName scl);
-
-
- void i2c_frequency(i2c_t *obj, int hz);
-
-
- int i2c_start(i2c_t *obj);
-
-
- int i2c_stop(i2c_t *obj);
-
-
- int i2c_read(i2c_t *obj, int address, char *data, int length, int stop);
-
-
- int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop);
-
-
- void i2c_reset(i2c_t *obj);
-
-
- int i2c_byte_read(i2c_t *obj, int last);
-
-
- int i2c_byte_write(i2c_t *obj, int data);
-
-
-
- #if DEVICE_I2CSLAVE
-
-
-
-
- void i2c_slave_mode(i2c_t *obj, int enable_slave);
-
-
- int i2c_slave_receive(i2c_t *obj);
-
-
- int i2c_slave_read(i2c_t *obj, char *data, int length);
-
-
- int i2c_slave_write(i2c_t *obj, const char *data, int length);
-
-
- void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask);
-
- #endif
-
-
-
- #if DEVICE_I2C_ASYNCH
-
-
-
-
- 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);
-
-
- uint32_t i2c_irq_handler_asynch(i2c_t *obj);
-
-
- uint8_t i2c_active(i2c_t *obj);
-
-
- void i2c_abort_asynch(i2c_t *obj);
-
- #endif
-
-
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif
-
- #endif
|