blob: d7622fa5540f5ce572511ad60278e84729574213 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#ifndef UART_H_
#define UART_H_
#include "main.h"
#include "remote.h"
#if (DEBUG || USE_REMOTE) && IS_ATMEGAx8
# define USE_UART 1
# define IF_UART(...) __VA_ARGS__
#else
# define USE_UART 0
# define IF_UART(...) /* nothing */
#endif
#define BAUDRATE 19200ul
#define USE_2X (((uint64_t)F_CPU % (8ull * BAUDRATE)) < \
((uint64_t)F_CPU % (16ull * BAUDRATE)))
#define UBRRVAL ((uint64_t)F_CPU / ((USE_2X ? 8ull : 16ull) * BAUDRATE))
enum uart_chan {
UART_CHAN_8BIT_0, /* 8 bit communication channel 0 */
#if 0
UART_CHAN_8BIT_1, /* 8 bit communication channel 1 */
UART_CHAN_8BIT_2, /* 8 bit communication channel 2 */
UART_CHAN_8BIT_3, /* 8 bit communication channel 3 */
#endif
UART_CHAN_7BIT, /* 7 bit communication channel */
UART_NR_CHAN,
};
typedef void (*uart_txready_cb_t)(void);
typedef void (*uart_rx_cb_t)(uint8_t data, bool error);
bool uart_tx_is_ready(enum uart_chan chan);
void uart_tx_byte(uint8_t data, enum uart_chan chan);
void uart_tx_enable(bool enable, enum uart_chan chan);
void uart_register_callbacks(uart_txready_cb_t tx_ready,
uart_rx_cb_t rx,
enum uart_chan chan);
void uart_enter_deep_sleep(void);
void uart_handle_deep_sleep_wakeup(void);
void uart_handle_watchdog_interrupt(void);
void uart_init(void);
#endif /* UART_H_ */
|