00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00047 #ifndef _I2C_H_
00048 #define _I2C_H_
00049
00050 #include <aversive.h>
00051 #include <i2c_config.h>
00052
00053 #define I2C_DEBUG 1
00054
00055 #define I2C_ADD_GENCALL 0x00
00056
00057
00058
00059 #define I2C_ADD_MASTER 0x80
00060
00061
00062
00063
00064
00065 typedef enum { I2C_MODE_UNINIT,
00066 I2C_MODE_SLAVE,
00067 #ifdef CONFIG_MODULE_I2C_MASTER
00068 I2C_MODE_MASTER,
00069 #endif
00070 #ifdef CONFIG_MODULE_I2C_MULTIMASTER
00071 I2C_MODE_MULTIMASTER,
00072 #endif
00073 } i2c_mode_t ;
00074
00075
00076 #define I2C_CTRL_GENERIC 0x00
00077
00083 #define I2C_CTRL_SYNC 0x01
00084
00089 #define I2C_CTRL_DONT_RELEASE_BUS 0x02
00090
00091
00092
00093 #define I2C_STATUS_READY 0x00
00094 #define I2C_STATUS_MASTER_XMIT 0x01
00095 #define I2C_STATUS_MASTER_RECV 0x02
00096 #define I2C_STATUS_SLAVE_XMIT_WAIT 0x04
00097 #define I2C_STATUS_SLAVE_XMIT 0x08
00098 #define I2C_STATUS_SLAVE_RECV 0x10
00099 #define I2C_STATUS_OP_FINISHED 0x20
00100 #define I2C_STATUS_NEED_XMIT_EVT 0x40
00101 #define I2C_STATUS_NEED_RECV_EVT 0x80
00102
00103
00111 void i2c_init(i2c_mode_t mode, uint8_t add);
00112
00113
00125 void i2c_register_recv_event(void (*event)(uint8_t *, int8_t));
00126
00134 void i2c_register_recv_byte_event(void (*event)(uint8_t, uint8_t, uint8_t));
00135
00136
00149 void i2c_register_send_event(void (*event)(int8_t));
00150
00151
00168 int8_t i2c_send(uint8_t dest_add, uint8_t *buf, uint8_t size, uint8_t ctrl);
00169
00175 int8_t i2c_resend(void);
00176
00180 int8_t i2c_rerecv(void);
00181
00185 void i2c_release_bus(void);
00186
00195 int8_t i2c_recv(uint8_t dest_add, uint8_t size, uint8_t ctrl);
00196
00197
00204 int8_t i2c_flush(void);
00205
00217 uint8_t i2c_set_recv_size(uint8_t size);
00218
00222 i2c_mode_t i2c_mode(void);
00223
00227 uint8_t i2c_status(void);
00228
00233 uint8_t i2c_get_recv_buffer(uint8_t *buf, uint8_t size);
00234
00238 void i2c_reset(void);
00239
00240 #if I2C_DEBUG == 1
00241
00244 void i2c_debug(void);
00245 #endif
00246
00247
00248 #endif