#ifndef UART_H
#define UART_H

#include "config.h"

/* Init */
void uart_init(int uart, int32_t rate);

/* Blocking sends */
void uart_put(int uart, uint8_t x);
void uart_put_string(int uart, const char *s);
void uart_crlf(int uart);
void uart_put_hex(int uart, uint8_t x);
void uart_put_hex16(int uart, uint16_t x);
void uart_put_hex32(int uart, uint32_t x);
void uart_put_bin(int uart, uint8_t x);
void uart_put_dec(int uart, int32_t x);

/* Blocking receives */
uint8_t uart_get(int uart);

/* Return true if get/put would not block */
int uart_can_get(int uart);
int uart_can_put(int uart);

/* Helpers to work with a specific uart */
#define uart1_init(x) 		uart_init(1, x)
#define uart1_can_get() 	uart_can_get(1)
#define uart1_get() 		uart_get(1)
#define uart1_put(x) 		uart_put(1,x)
#define uart1_put_string(x) uart_put_string(1,x)
#define uart1_crlf()		uart_crlf(1)
#define uart1_put_hex(x)	uart_put_hex(1,x)
#define uart1_put_hex16(x)	uart_put_hex16(1,x)
#define uart1_put_hex32(x)	uart_put_hex32(1,x)
#define uart1_put_bin(x)	uart_put_bin(1,x)
#define uart1_put_dec(x)	uart_put_dec(1,x)

#define uart2_init(x) 		uart_init(2, x)
#define uart2_can_get() 	uart_can_get(2)
#define uart2_get() 		uart_get(2)
#define uart2_put(x) 		uart_put(2,x)
#define uart2_put_string(x) uart_put_string(2,x)
#define uart2_crlf()		uart_crlf(2)
#define uart2_put_hex(x)	uart_put_hex(2,x)
#define uart2_put_hex16(x)	uart_put_hex16(2,x)
#define uart2_put_hex32(x)	uart_put_hex32(2,x)
#define uart2_put_bin(x)	uart_put_bin(2,x)
#define uart2_put_dec(x)	uart_put_dec(2,x)

#endif
