vex_sdk/serial.rs
1//! USB Serial Communication
2
3use core::ffi::{c_char, VaList};
4
5use crate::map_jump_table;
6
7map_jump_table! {
8 0x898 =>
9 /// Writes a single byte to the serial FIFO output buffer.
10 ///
11 /// # Arguments
12 ///
13 /// - `channel`: The serial communications channel to write to. Use `1` for stdio.
14 /// - `c`: The byte to write.
15 ///
16 /// # Return
17 ///
18 /// The number of bytes written, or -1 if an internal error occurred.
19 pub fn vexSerialWriteChar(channel: u32, c: u8) -> i32,
20 0x89c =>
21 /// Writes an arbitrary buffer to the serial FIFO output buffer, returning how
22 /// many bytes were written. The output buffer has a maximum size of 2048 bytes,
23 /// meaning that a larger buffer may be truncated.
24 ///
25 /// # Arguments
26 ///
27 /// - `channel`: The serial communications channel to write to. Use `1` for stdio.
28 /// - `data`: A buffer of bytes to write.
29 /// - `data_len`: The length of the specified buffer.
30 ///
31 /// # Return
32 ///
33 /// The number of bytes written, or -1 if an internal error occurred.
34 pub fn vexSerialWriteBuffer(channel: u32, data: *const u8, data_len: u32) -> i32,
35 0x8a0 =>
36 /// Reads a single byte from the input buffer.
37 ///
38 /// # Arguments
39 ///
40 /// - `channel`: The serial communications channel to read from. Use `1` for stdio.
41 ///
42 /// # Return
43 ///
44 /// The next byte in the input buffer, or -1 if no character is available to be read.
45 pub fn vexSerialReadChar(channel: u32) -> i32,
46 0x8a4 =>
47 /// Returns the next available byte to be read in the input buffer without removing
48 /// it from the buffer.
49 ///
50 /// # Arguments
51 ///
52 /// - `channel`: The serial communications channel to read from. Use `1` for stdio.
53 ///
54 /// # Return
55 ///
56 /// The next byte in the input buffer, or -1 if no character is available to be read.
57 pub fn vexSerialPeekChar(channel: u32) -> i32,
58 0x8ac =>
59 /// Returns the number of free bytes (out of `2048`) remaining in the serial output
60 /// buffer.
61 ///
62 /// # Arguments
63 ///
64 /// - `channel`: The serial communications channel to read from. Use `1` for stdio.
65 ///
66 /// # Return
67 ///
68 /// The number of remaining available bytes.
69 pub fn vexSerialWriteFree(channel: u32) -> i32,
70 0x0f0 => pub fn vex_vprintf(format: *const c_char, args: VaList) -> i32,
71 0x0f4 => pub fn vex_vsprintf(out: *mut c_char, format: *const c_char, args: VaList) -> i32,
72 0x0f8 => pub fn vex_vsnprintf(out: *mut c_char, max_len: u32, format: *const c_char, args: VaList) -> i32,
73}
74
75pub unsafe extern "C" fn vex_printf(format: *const c_char, mut args: ...) -> i32 {
76 unsafe { vex_vprintf(format, args.as_va_list()) }
77}
78
79pub unsafe extern "C" fn vex_sprintf(
80 out: *mut c_char,
81 format: *const c_char,
82 mut args: ...
83) -> i32 {
84 unsafe { vex_vsprintf(out, format, args.as_va_list()) }
85}
86
87pub unsafe extern "C" fn vex_snprintf(
88 out: *mut c_char,
89 max_len: u32,
90 format: *const c_char,
91 mut args: ...
92) -> i32 {
93 unsafe { vex_vsnprintf(out, max_len, format, args.as_va_list()) }
94}