-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathi_tiny_uart.h
50 lines (38 loc) · 1.03 KB
/
i_tiny_uart.h
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
50
/*!
* @file
* @brief Abstract UART peripheral.
*/
#ifndef i_tiny_uart_h
#define i_tiny_uart_h
#include <stdint.h>
#include "i_tiny_event.h"
typedef struct {
uint8_t byte;
} tiny_uart_on_receive_args_t;
struct i_tiny_uart_api_t;
typedef struct {
const struct i_tiny_uart_api_t* api;
} i_tiny_uart_t;
typedef struct i_tiny_uart_api_t {
/*!
* Sends a byte.
*/
void (*send)(i_tiny_uart_t* self, uint8_t byte);
/*!
* Event raised when a byte is finished being sent. Clients must assume
* that this is raised from an interrupt.
*/
i_tiny_event_t* (*on_send_complete)(i_tiny_uart_t* self);
/*!
* Event raised when a byte is received. Clients must assume that this is
* raised from an interrupt.
*/
i_tiny_event_t* (*on_receive)(i_tiny_uart_t* self);
} i_tiny_uart_api_t;
#define tiny_uart_send(self, byte) \
(self)->api->send((self), (byte))
#define tiny_uart_on_send_complete(self) \
(self)->api->on_send_complete((self))
#define tiny_uart_on_receive(self) \
(self)->api->on_receive((self))
#endif