/*
 * Copyright (c) 2010 by Oleg Trifonov <otrifonow@gmail.com>
 * http://trol.0fees.net
 *
 * This file is free software; you can redistribute it and/or modify
 * it under the terms of either the GNU General Public License version 2
 * or the GNU Lesser General Public License version 2.1, both as
 * published by the Free Software Foundation.
 */

#ifndef _DEBUG_H_
#define _DEBUG_H_

#include "config.h"

#if DEBUG

#include <stdint.h>
#include <avr/pgmspace.h>



#define BAUDRATE 600

#define UART_RATE_VALUE  (F_CPU/16/BAUDRATE-1)			// значение скорости порта
/******************
f = 11.059 MHz
2400   UBRR=287
4800   UBRR=143
9600   UBRR=71
14400  UBRR=47
19200  UBRR=35
28800  UBRR=23
38400  UBRR=17
57600  UBRR=11
76800  UBRR=8
115200 UBRR=5 
*****************/


void uart_init();

void uart_putc(uint8_t c);

void uart_putc_hex(uint8_t b);
void uart_putw_hex(uint16_t w);
void uart_putdw_hex(uint32_t dw);

void uart_putw_dec(uint16_t w);
void uart_putdw_dec(uint32_t dw);

void uart_puts(const char* str);
void uart_puts_p(PGM_P str);

uint8_t uart_getc();

void MSG_(char *str);

void MSG_HEX_(char *str, uint32_t val, uint8_t bytes);

void MSG_DEC_(char *str, uint32_t val);

#else
	inline void uart_init() {}
	inline void MSG_(char *str) {}
	inline void MSG_HEX_(char *str, uint32_t val, uint8_t bytes) {}
	inline void MSG_DEC_(char *str, uint32_t val) {}
#endif // DEBUG




#define MSG(str)								MSG_(PSTR(str))
#define MSG_HEX(str, val, bytes)			MSG_HEX_(PSTR(str), (val), bytes)
#define MSG_DEC(str, val)					MSG_DEC_(PSTR(str), (val))


#endif // _DEBUG_H_
