Skip to content

Commit 7753d54

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 7753d54

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

uefi/src/proto/console/serial.rs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
//! Abstraction over byte stream devices, also known as serial I/O devices.
44
5+
#[cfg(doc)]
6+
use crate::Status;
57
use crate::proto::unsafe_protocol;
68
use crate::{Result, StatusExt};
79
use core::fmt::Write;
@@ -14,10 +16,34 @@ pub use uefi_raw::protocol::console::serial::{
1416
/// Serial IO [`Protocol`]. Provides access to a serial I/O device.
1517
///
1618
/// This can include standard UART devices, serial ports over a USB interface,
17-
/// or any other character-based communication device.
19+
/// or any other character-based communication device. The protocol is
20+
/// typically used to connect to a terminal.
1821
///
19-
/// Since UEFI drivers are implemented through polling, if you fail to regularly
20-
/// check for input/output, some data might be lost.
22+
/// # Connection Properties and I/O Hints
23+
///
24+
/// ## General
25+
///
26+
/// Special care must be taken if a significant amount of data is going to be
27+
/// read from a serial device. Since UEFI drivers are polled mode drivers,
28+
/// characters received on a serial device might be missed. It is the
29+
/// responsibility of the software that uses the protocol to check for new data
30+
/// often enough to guarantee that no characters will be missed. The required
31+
/// polling frequency depends on the baud rate of the connection and the depth
32+
/// of the receive FIFO.
33+
///
34+
/// ## UART
35+
///
36+
/// The default attributes for all UART-style serial device interfaces are:
37+
/// 115,200 baud, a 1 byte receive FIFO, a 1,000,000 microsecond (1s) timeout
38+
/// per character, no parity, 8 data bits, and 1 stop bit.
39+
///
40+
/// Flow control is the responsibility of the software that uses the protocol.
41+
/// Hardware flow control can be implemented through the use of the
42+
/// [`Serial::get_control_bits`] and [`Serial::set_control_bits`] functions
43+
/// to monitor and assert the flow control signals.
44+
///
45+
/// The XON/XOFF flow control algorithm can be implemented in software by
46+
/// inserting XON and XOFF characters into the serial data stream as required.
2147
///
2248
/// [`Protocol`]: uefi::proto::Protocol
2349
#[derive(Debug)]
@@ -27,6 +53,10 @@ pub struct Serial(SerialIoProtocol);
2753

2854
impl Serial {
2955
/// Reset the device.
56+
///
57+
/// # Errors
58+
///
59+
/// - [`Status::DEVICE_ERROR`]: serial device could not be reset.
3060
pub fn reset(&mut self) -> Result {
3161
unsafe { (self.0.reset)(&mut self.0) }.to_result()
3262
}
@@ -39,7 +69,7 @@ impl Serial {
3969

4070
/// Sets the device's new attributes.
4171
///
42-
/// The given `IoMode` will become the device's new `IoMode`,
72+
/// The given [`IoMode`] will become the device's new [`IoMode`],
4373
/// with some exceptions:
4474
///
4575
/// - `control_mask` is ignored, since it's a read-only field;
@@ -49,7 +79,13 @@ impl Serial {
4979
///
5080
/// - if either `baud_rate` or `receive_fifo_depth` is less than
5181
/// the device's minimum, an error will be returned;
52-
/// this value will be rounded down to the nearest value supported by the device;
82+
/// this value will be rounded down to the nearest value supported by the device
83+
///
84+
/// # Errors
85+
///
86+
/// - [`Status::INVALID_PARAMETER`]: one or more of the attributes has an
87+
/// unsupported value
88+
/// - [`Status::DEVICE_ERROR`]: serial device is not functioning correctly
5389
pub fn set_attributes(&mut self, mode: &IoMode) -> Result {
5490
unsafe {
5591
(self.0.set_attributes)(
@@ -66,6 +102,10 @@ impl Serial {
66102
}
67103

68104
/// Retrieve the device's current control bits.
105+
///
106+
/// # Errors
107+
///
108+
/// - [`Status::DEVICE_ERROR`]: serial device is not functioning correctly
69109
pub fn get_control_bits(&self) -> Result<ControlBits> {
70110
let mut bits = ControlBits::empty();
71111
unsafe { (self.0.get_control_bits)(&self.0, &mut bits) }.to_result_with_val(|| bits)
@@ -75,6 +115,11 @@ impl Serial {
75115
///
76116
/// Not all bits can be modified with this function. A mask of the allowed
77117
/// bits is stored in the [`ControlBits::SETTABLE`] constant.
118+
///
119+
/// # Errors
120+
///
121+
/// - [`Status::UNSUPPORTED`]: serial device does not support this operation
122+
/// - [`Status::DEVICE_ERROR`]: serial device is not functioning correctly
78123
pub fn set_control_bits(&mut self, bits: ControlBits) -> Result {
79124
unsafe { (self.0.set_control_bits)(&mut self.0, bits) }.to_result()
80125
}

0 commit comments

Comments
 (0)