Skip to content

Commit 8f00d07

Browse files
committed
uefi: serial: improve overall documentation
Improve the overall documentation of the Serial struct/protocol. This omits read() and write() as I improve them in a dedicated commit.
1 parent 997b03a commit 8f00d07

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

uefi/src/proto/console/serial.rs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,34 @@ pub use uefi_raw::protocol::console::serial::{
1414
/// Serial IO [`Protocol`]. Provides access to a serial I/O device.
1515
///
1616
/// This can include standard UART devices, serial ports over a USB interface,
17-
/// or any other character-based communication device.
17+
/// or any other character-based communication device. The protocol is
18+
/// typically used to connect to a terminal.
1819
///
19-
/// Since UEFI drivers are implemented through polling, if you fail to regularly
20-
/// check for input/output, some data might be lost.
20+
/// # Connection Properties and I/O Hints
21+
///
22+
/// ## General
23+
///
24+
/// Special care must be taken if a significant amount of data is going to be
25+
/// read from a serial device. Since UEFI drivers are polled mode drivers,
26+
/// characters received on a serial device might be missed. It is the
27+
/// responsibility of the software that uses the protocol to check for new data
28+
/// often enough to guarantee that no characters will be missed. The required
29+
/// polling frequency depends on the baud rate of the connection and the depth
30+
/// of the receive FIFO.
31+
///
32+
/// ## UART
33+
///
34+
/// The default attributes for all UART-style serial device interfaces are:
35+
/// 115,200 baud, a 1 byte receive FIFO, a 1,000,000 microsecond (1s) timeout
36+
/// per character, no parity, 8 data bits, and 1 stop bit.
37+
///
38+
/// Flow control is the responsibility of the software that uses the protocol.
39+
/// Hardware flow control can be implemented through the use of the
40+
/// [`Serial::get_control_bits`] and [`Serial::set_control_bits`] functions
41+
/// to monitor and assert the flow control signals.
42+
///
43+
/// The XON/XOFF flow control algorithm can be implemented in software by
44+
/// inserting XON and XOFF characters into the serial data stream as required.
2145
///
2246
/// [`Protocol`]: uefi::proto::Protocol
2347
#[derive(Debug)]
@@ -27,6 +51,10 @@ pub struct Serial(SerialIoProtocol);
2751

2852
impl Serial {
2953
/// Reset the device.
54+
///
55+
/// # Errors
56+
///
57+
/// - [`Status::DEVICE_ERROR`]: serial device could not be reset.
3058
pub fn reset(&mut self) -> Result {
3159
unsafe { (self.0.reset)(&mut self.0) }.to_result()
3260
}
@@ -39,7 +67,7 @@ impl Serial {
3967

4068
/// Sets the device's new attributes.
4169
///
42-
/// The given `IoMode` will become the device's new `IoMode`,
70+
/// The given [`IoMode`] will become the device's new [`IoMode`],
4371
/// with some exceptions:
4472
///
4573
/// - `control_mask` is ignored, since it's a read-only field;
@@ -49,7 +77,13 @@ impl Serial {
4977
///
5078
/// - if either `baud_rate` or `receive_fifo_depth` is less than
5179
/// the device's minimum, an error will be returned;
52-
/// this value will be rounded down to the nearest value supported by the device;
80+
/// this value will be rounded down to the nearest value supported by the device
81+
///
82+
/// # Errors
83+
///
84+
/// - [`Status::INVALID_PARAMETER`]: one or more of the attributes has an
85+
/// unsupported value
86+
/// - [`Status::DEVICE_ERROR`]: serial device is not functioning correctly
5387
pub fn set_attributes(&mut self, mode: &IoMode) -> Result {
5488
unsafe {
5589
(self.0.set_attributes)(
@@ -66,6 +100,10 @@ impl Serial {
66100
}
67101

68102
/// Retrieve the device's current control bits.
103+
///
104+
/// # Errors
105+
///
106+
/// - [`Status::DEVICE_ERROR`]: serial device is not functioning correctly
69107
pub fn get_control_bits(&self) -> Result<ControlBits> {
70108
let mut bits = ControlBits::empty();
71109
unsafe { (self.0.get_control_bits)(&self.0, &mut bits) }.to_result_with_val(|| bits)
@@ -75,6 +113,11 @@ impl Serial {
75113
///
76114
/// Not all bits can be modified with this function. A mask of the allowed
77115
/// bits is stored in the [`ControlBits::SETTABLE`] constant.
116+
///
117+
/// # Errors
118+
///
119+
/// - [`Status::UNSUPPORTED`]: serial device does not support this operation
120+
/// - [`Status::DEVICE_ERROR`]: serial device is not functioning correctly
78121
pub fn set_control_bits(&mut self, bits: ControlBits) -> Result {
79122
unsafe { (self.0.set_control_bits)(&mut self.0, bits) }.to_result()
80123
}

0 commit comments

Comments
 (0)