Xyris  0.5
rs232.hpp
Go to the documentation of this file.
1 /**
2  * @file rs232.hpp
3  * @author Keeton Feavel ([email protected])
4  * @brief A simple, write-only driver for the RS232 serial
5  * device standard. Code mostly ported from Panix-Archive (v2).
6  * @version 0.3
7  * @date 2020-06-29
8  *
9  * @copyright Copyright the Xyris Contributors (c) 2020
10  *
11  */
12 #pragma once
13 
14 #include <stdarg.h>
15 #include <stdint.h>
16 #include <stddef.h>
17 
18 #define RS_232_COM1 0x3F8
19 #define RS_232_COM2 0x2F8
20 #define RS_232_COM3 0x3E8
21 #define RS_232_COM4 0x2E8
22 
23 namespace RS232 {
24 
25 /**
26  * @brief Activates the RS232 serial driver
27  *
28  */
29 void init(uint16_t com_id);
30 
31 /**
32  * @brief Reads bytes from the serial buffer
33  *
34  * @param buf Buffer to hold the serial input
35  * @param count Number of bytes to read
36  * @return char* Returns the number of bytes read.
37  */
38 size_t read(char* buf, size_t count);
39 
40 /**
41  * @brief Write bytes to the serial device
42  *
43  * @param buf Buffer containing bytes to write
44  * @param count Number of bytes to write
45  * @return size_t Returns number of bytes written
46  */
47 size_t write(const char* buf, size_t count);
48 
49 /**
50  * @brief Prints a formatted string to serial output
51  *
52  * @param format Format string
53  * @param ... Arguments
54  * @return int Number of characters printed
55  */
56 [[gnu::format (printf, 1, 2)]]
57 int printf(const char *format, ...);
58 
59 /**
60  * @brief Prints a formatted string to serial output using
61  * a va_list of arguments
62  *
63  * @param fmt Format string
64  * @param args Arguments list
65  * @return int Number of characters printed
66  */
67 [[gnu::format (printf, 1, 0)]]
68 int vprintf(const char* fmt, va_list args);
69 
70 /**
71  * @brief Closes the serial input buffer and frees all of
72  * the data contained within.
73  *
74  * @return int Returns 0 on success and -1 on error. Errno
75  * is set appropriately.
76  */
77 int close();
78 
79 } // !namespace RS232
RS232::write
size_t write(const char *buf, size_t count)
Write bytes to the serial device.
Definition: rs232.cpp:156
RS232::read
size_t read(char *buf, size_t count)
Reads bytes from the serial buffer.
Definition: rs232.cpp:144
RS232::vprintf
int vprintf(const char *fmt, va_list args)
Prints a formatted string to serial output using a va_list of arguments.
Definition: rs232.cpp:79
RS232::close
int close()
Closes the serial input buffer and frees all of the data contained within.
Definition: rs232.cpp:168
RS232::init
void init(uint16_t com_id)
Activates the RS232 serial driver.
Definition: rs232.cpp:112
RS232
Definition: rs232.cpp:39
RS232::printf
int printf(const char *format,...)
Prints a formatted string to serial output.
Definition: rs232.cpp:86