7 /** I2C Clock Generation **/
10 #define TWI_BR_VAL -(16*F_SCL-F_CPU)/(2*F_SCL)
13 // Slave Address(s) for device 0b7654321
14 #define I2C_SLAVE_ADDR 0b0011100
15 #define I2C_SLAVE_ADDR_MSK 0b0000000
16 // Respond to General Call in Slave mode?
17 #define I2C_GENERAL_CALL_EN 0
20 typedef enum { I2C_IDLE
= 0,
30 /** TWCR Control Values **/
31 // Enabe TWI, Clear INT flag, Enable Ack, Enable Interupt
32 #define TWCR_NACK ( (1<<TWEN)|(1<<TWINT)|(1<<TWIE) )
33 #define TWCR_BASE ( TWCR_NACK|(1<<TWEA) )
34 #define TWCR_START ( TWCR_BASE|(1<<TWSTA) )
35 #define TWCR_STOP ( TWCR_BASE|(1<<TWSTO) )
36 #define TWCR_RESET ( TWCR_BASE|(1<<TWSTO)|(1<<TWSTA) )
39 /** Transfer Control & Queue **/
49 uint8_t (*callback)(void);
55 #define I2C_MSG_BUF_LEN 5
56 i2c_msg_t i2c_msg_buffer[I2C_MSG_BUF_LEN];
60 int i2c_add_msg(uint8_t addr,
65 uint8_t (*callback)(void);
66 int i2c_rem_msg(int msg_num);
69 /** Static Bus Operation **/
73 uint8_t w_data_buf_len
;
75 volatile uint8_t w_data_buf_pos
;
77 uint8_t r_data_buf_len
;
78 volatile uint8_t * r_data_buf
;
79 volatile uint8_t r_data_buf_pos
;
81 uint8_t (*xfer_complete_cb
)(void);
86 int i2c_reset_xfer(void);
87 int i2c_start_xfer(void);