hollyhock
Loading...
Searching...
No Matches
serial.h
Go to the documentation of this file.
1
6// This works exactly the same as the calls on the cg50. Read more here:
7// https://prizm.cemetech.net/index.php?title=Category:Syscalls:Serial
8// These implementations are similar to:
9// https://github.com/Jonimoose/libfxcg/blob/master/include/fxcg/serial.h
10
11#pragma once
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#ifndef __clang__
18#define ro(...) __attribute__((access(read_only, __VA_ARGS__)))
19#define rw(...) __attribute__((access(read_write, __VA_ARGS__)))
20#define wo(...) __attribute__((access(write_only, __VA_ARGS__)))
21#else
22#define ro(...)
23#define rw(...)
24#define wo(...)
25#endif
26
27#include <stdint.h>
28#include <stdbool.h>
29
30enum Serial_Bitrate {
31 SERIAL_BITRATE_300 = 0,
32 SERIAL_BITRATE_1200 = 1,
33 SERIAL_BITRATE_2400 = 2,
34 SERIAL_BITRATE_4800 = 3,
35 SERIAL_BITRATE_9600 = 5,
36 SERIAL_BITRATE_19200 = 6,
37 SERIAL_BITRATE_38400 = 7,
38 SERIAL_BITRATE_57600 = 8,
39 SERIAL_BITRATE_115200 = 9
40};
41
42enum Serial_Parity {
43 SERIAL_PARITY_NONE = 0,
44 SERIAL_PARITY_ODD = 1,
45 SERIAL_PARITY_EVEN = 2
46};
47
48enum Serial_Data_Length {
49 SERIAL_DATA_LENGTH_8BIT = 0,
50 SERIAL_DATA_LENGTH_7BIT = 1
51};
52
53enum Serial_Stop_Bits {
54 SERIAL_STOP_BITS_1 = 0,
55 SERIAL_STOP_BITS_2 = 1
56};
57
58struct __attribute__((packed)) Serial_Settings {
59 uint8_t zero;
60 enum Serial_Bitrate bitrate : 8;
61 enum Serial_Parity parity : 8;
62 enum Serial_Data_Length data_length : 8;
63 enum Serial_Stop_Bits stop_bits : 8;
64 uint8_t zero2;
65};
66
83extern int (*Serial_Open)(const struct Serial_Settings *mode) ro(1);
84
85extern int (*Serial_IsOpen)(void);
86
87extern int (*Serial_Close)(bool abortPending);
88
89extern int (*Serial_Read)(unsigned char *out, int sz, short *count) wo(1, 2) wo(3);
90
91extern int (*Serial_ReadSingle)(unsigned char *out) wo(1);
92
93extern int (*Serial_Peek)(int idx, unsigned char *out) wo(1);
94
95extern int (*Serial_PollRX)(void);
96
97extern int (*Serial_ClearRX)(void);
98
106extern int (*Serial_Write)(const unsigned char *buf, int count) ro(1, 2);
107
108extern int (*Serial_WriteSingle)(unsigned char x);
109
110extern int (*Serial_WriteUnbuffered)(unsigned char x);
111
112extern int (*Serial_PollTX)(void);
113
114extern int (*Serial_ClearTX)(void);
115
116#undef ro
117#undef rw
118#undef wo
119
120#ifdef __cplusplus
121}
122#endif
int(* Serial_Write)(const unsigned char *buf, int count) ro(1
int(* Serial_Open)(const struct Serial_Settings *mode) ro(1)