123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #ifndef ZEPHYR_INCLUDE_DRIVERS_I2CMT_H_
- #define ZEPHYR_INCLUDE_DRIVERS_I2CMT_H_
- #include <kernel.h>
- #include <device.h>
- #include <drivers/ppi.h>
- #include <drivers/i2c.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- enum i2c_xfer_stat {
- I2C_XFER_OK = 0,
- I2C_XFER_BUS_ERR = -1,
- I2C_XFER_NACK = -2,
- I2C_XFER_NO_TCB = -3,
- I2C_XFER_START_FAILED = -4,
- I2C_XFER_STOP_FAILED = -5,
- };
- #define I2C_TASK_NUM (4)
- enum i2c_task_irq_type {
- I2C_TASK_IRQ_CMPLT = (1 << 0),
- I2C_TASK_IRQ_HALF_CMPLT = (1 << 1),
- I2C_TASK_IRQ_NACK = (1 << 2),
- I2C_TASK_IRQ_BUS_ERROR = (1 << 3),
- };
- typedef struct i2c_xfer_s {
- unsigned short dev;
- unsigned short flag;
- unsigned char *cmd_buf;
- unsigned char *dat_buf;
- unsigned short cmd_len;
- unsigned short dat_len;
- } i2c_xfer_t;
- typedef struct i2c_task_ctl {
- unsigned int rwsel : 1;
- unsigned int sdevaddr : 7;
- unsigned int sdataddr : 8;
- unsigned int rdlen_wsdat : 12;
- unsigned int tdataddr : 1;
- unsigned int swen : 1;
- unsigned int abort : 1;
- unsigned int soft : 1;
- } i2c_task_ctl_t;
- typedef struct i2c_task_dma {
- unsigned int start : 1;
- unsigned int reload : 1;
- unsigned int addr;
- unsigned int len;
- } i2c_task_dma_t;
- typedef struct i2c_task {
- unsigned int irq_type;
- i2c_task_ctl_t ctl;
- i2c_task_dma_t dma;
- task_trig_t trig;
- } i2c_task_t;
- typedef void (*i2c_task_callback_t) (unsigned char *buf, int len, void *context);
- typedef void (*i2c_register_callback_t)(struct device *dev,
- int task_id, i2c_task_callback_t cb, void *cb_context);
- typedef int (*i2c_task_start_t) (struct device *dev, int task_id,
- const i2c_task_t *attr);
- typedef int (*i2c_task_stop_t) (struct device *dev, int task_id);
- struct i2cmt_driver_api {
- struct i2c_driver_api i2c_api;
- i2c_register_callback_t register_callback;
- i2c_task_start_t task_start;
- i2c_task_stop_t task_stop;
- };
- static inline void i2c_register_callback(struct device *dev,
- int task_id, i2c_task_callback_t cb, void *context)
- {
- const struct i2cmt_driver_api *api =
- (const struct i2cmt_driver_api *)dev->api;
- api->register_callback(dev, task_id, cb, context);
- }
- static inline int i2c_task_start(struct device *dev, int task_id,
- const i2c_task_t *attr)
- {
- const struct i2cmt_driver_api *api =
- (const struct i2cmt_driver_api *)dev->api;
- return api->task_start(dev, task_id, attr);
- }
- static inline int i2c_task_stop(struct device *dev, int task_id)
- {
- const struct i2cmt_driver_api *api =
- (const struct i2cmt_driver_api *)dev->api;
- return api->task_stop(dev, task_id);
- }
- uint8_t* i2c_task_get_data(int bus_id, int task_id, int trig, int *plen);
- #ifdef __cplusplus
- }
- #endif
- #endif
|