

#ifndef USART_H_
#define USART_H_
#include <avr/io.h>
#include <avr/pgmspace.h>
#ifndef USART_BUFFER_SIZE
#define USART_BUFFER_SIZE 10
#endif

#ifndef F_CPU
#warning "F_CPU is used to calculate baud rate and should be defined!"
#define F_CPU 1000000UL
#endif

class USART{
	public:
	USART(uint32_t baud_rate);
	void send(uint8_t b);
	void send(void*ptr, size_t count);
	void send(char * string);
	void send_P(const char * string);
	void sendFloat(float f, uint8_t p);
    void sendInt(int64_t i, int radix);

#ifdef USART_READING
	uint8_t read();
	static void fillBuffer(uint8_t byte);
	int available();
	void reset();
#endif
	
	private:
#ifdef USART_READING
	static uint8_t buffer[USART_BUFFER_SIZE];
	static int bufferReadIndex;
	static int bufferWriteIndex;
	static int incomingBytes;
#endif
	void waitForBufferBeFree();
};
#endif