-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathi_tiny_buffered_uart.h
62 lines (48 loc) · 1.61 KB
/
i_tiny_buffered_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
51
52
53
54
55
56
57
58
59
60
61
62
/*!
* @file
* @brief Abstract buffered UART.
*
* A buffered UART sends and receives chunks of bytes instead of sending and receiving
* byte-by-byte. This can be used to abstract over a free-running UART with DMA.
*/
#ifndef i_tiny_buffered_uart_h
#define i_tiny_buffered_uart_h
#include <stdint.h>
#include "i_tiny_event.h"
typedef struct {
const void* buffer;
uint16_t buffer_size;
} tiny_buffered_uart_on_receive_args_t;
struct i_tiny_buffered_uart_api_t;
typedef struct {
const struct i_tiny_buffered_uart_api_t* api;
} i_tiny_buffered_uart_t;
typedef struct i_tiny_buffered_uart_api_t {
/*!
* Sends a buffer. The buffer must remain valid until the send completes.
*/
void (*send)(i_tiny_buffered_uart_t* self, const void* buffer, uint16_t buffer_size);
/*!
* Event raised when a buffer is finished being sent. This is raised only
* during a call to run().
*/
i_tiny_event_t* (*on_send_complete)(i_tiny_buffered_uart_t* self);
/*!
* Event raised when bytes are received. This is raised only during a call
* to run().
*/
i_tiny_event_t* (*on_receive)(i_tiny_buffered_uart_t* self);
/*!
* Raises receive and send complete events as necessary.
*/
void (*run)(i_tiny_buffered_uart_t* self);
} i_tiny_buffered_uart_api_t;
#define tiny_buffered_uart_send(self, buffer, buffer_size) \
(self)->api->send((self), (buffer), (buffer_size))
#define tiny_buffered_uart_on_send_complete(self) \
(self)->api->on_send_complete((self))
#define tiny_buffered_uart_on_receive(self) \
(self)->api->on_receive((self))
#define tiny_buffered_uart_run(self) \
(self)->api->run((self))
#endif