#ifndef I2C_ISR_H #define I2C_ISR_H #include #include /** States for the I2C ISR. */ #define I2C_MASTER_STATE_ERROR -2 #define I2C_MASTER_STATE_DONE -1 #define I2C_MASTER_STATE_WSTART 0 #define I2C_MASTER_STATE_WADDRESS_READ 1 #define I2C_MASTER_STATE_WADDRESS_WRITE 4 #define I2C_MASTER_STATE_WDATA 3 #define I2C_MASTER_STATE_W_SDATA 5 /** Data structure for communication between ISR and main program. */ struct i2c_master_struct { /** Finite state machine state. */ volatile int8_t state; /** Number of bytes to receive. */ volatile uint8_t size_in; /** Number of bytes to send. */ volatile uint8_t size_out; /** Address of slave device. */ volatile uint8_t address; /** Number of bytes sent so far. */ uint8_t counter; /** Copy of the I2C status register. */ volatile uint8_t status; }; // Defined by i2c_isr.c extern BUFFER* i2c_buffer_out; extern BUFFER* i2c_buffer_in; extern struct i2c_master_struct master; extern void i2c_master_init(uint8_t size_in, uint8_t size_out); extern void i2c_wait_for_completion(void); extern uint8_t i2c_initiate_transmit_receive(uint8_t address, uint8_t size_out, uint8_t size_in); #endif