
#ifndef I2C_H_QWERTY
#define I2C_H_QWERTY

#define PSC_I2C			1	  // I2C prescaler
#define F_I2C			400000UL  // I2C Clock
#define SET_TWBR		(F_CPU/F_I2C-16UL)/(PSC_I2C*2UL)

#include <stdio.h>
#include <avr/io.h>

extern uint8_t i2c_error;

#define I2C_ERR_START	        0 // Timeout start-condition
#define I2C_ERR_SENDADRESS	1 // Timeout device-adress
#define I2C_ERR_BYTE	        2 // Timeout byte-transmission
#define I2C_ERR_READACK	        3 // Timeout read acknowledge
#define I2C_ERR_READNACK	4 // Timeout read nacknowledge

void i2c_init(void);

void i2c_send_addr(uint8_t addr);
void i2c_send_data(uint8_t byte);

uint8_t i2c_read_ack(void);
uint8_t i2c_read_nack(void);

void i2c_stop(void);

#endif
