Skip to content

Commit 35688fe

Browse files
committed
Improve Readme and crate documentation
Show `SerialPort` example on all architectures, but only try to compile it on `x86_64`.
1 parent c1578b3 commit 35688fe

File tree

2 files changed

+56
-31
lines changed

2 files changed

+56
-31
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
[![Build Status](https://github.com/rust-osdev/uart_16550/workflows/Build/badge.svg)](https://github.com/rust-osdev/uart_16550/actions?query=workflow%3ABuild) [![Docs.rs Badge](https://docs.rs/uart_16550/badge.svg)](https://docs.rs/uart_16550/)
44

5-
Minimal support for uart_16550 serial and memory mapped I/O.
5+
Minimal support for [serial communication](https://en.wikipedia.org/wiki/Asynchronous_serial_communication) through [UART](https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter) devices, which are compatible to the [16550 UART](https://en.wikipedia.org/wiki/16550_UART). This crate supports port-mapped and memory mapped UARTS.
66

77
## Usage
88

9-
### With usual serial port
9+
Depending on the system architecture, the UART can be either accessed through [port-mapped I/O](https://wiki.osdev.org/Port_IO) or [memory-mapped I/O](https://en.wikipedia.org/wiki/Memory-mapped_I/O).
10+
11+
### With port-mappd I/O
12+
13+
The UART is accessed through port-mapped I/O on architectures such as `x86_64`. On these architectures, the [`SerialPort`](https://docs.rs/uart_16550/~0.2/uart_16550/struct.SerialPort.html) type can be used:
14+
1015

1116
```rust
1217
use uart_16550::SerialPort;
@@ -25,6 +30,8 @@ let data = serial_port.receive();
2530

2631
### With memory mapped serial port
2732

33+
Most other architectures, such as [RISC-V](https://en.wikipedia.org/wiki/RISC-V), use memory-mapped I/O for accessing the UARTs. On these architectures, the [`MmioSerialPort`](https://docs.rs/uart_16550/~0.2/uart_16550/struct.MmioSerialPort.html) type can be used:
34+
2835
```rust
2936
use uart_16550::MmioSerialPort;
3037

@@ -40,10 +47,6 @@ serial_port.send(42);
4047
let data = serial_port.receive();
4148
```
4249

43-
## License
44-
45-
Licensed under the MIT license ([LICENSE](LICENSE) or <http://opensource.org/licenses/MIT>).
46-
4750
## Crate Feature Flags
4851

4952
* `nightly`: This is the default.
@@ -53,3 +56,7 @@ Licensed under the MIT license ([LICENSE](LICENSE) or <http://opensource.org/lic
5356

5457
This needs to have the [compile-time requirements](https://github.com/alexcrichton/cc-rs#compile-time-requirements) of the `cc` crate installed on your system.
5558
It was currently only tested on Linux and MacOS.
59+
60+
## License
61+
62+
Licensed under the MIT license ([LICENSE](LICENSE) or <http://opensource.org/licenses/MIT>).

src/lib.rs

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
1-
//! Minimal support for uart_16550 serial I/O.
1+
//! Minimal support for
2+
//! [serial communication](https://en.wikipedia.org/wiki/Asynchronous_serial_communication)
3+
//! through [UART](https://en.wikipedia.org/wiki/Universal_asynchronous_receiver-transmitter)
4+
//! devices, which are compatible to the [16550 UART](https://en.wikipedia.org/wiki/16550_UART).
25
//!
3-
//! # Usage
4-
5-
#![cfg_attr(
6-
target_arch = "x86_64",
7-
doc = "
8-
## With usual serial port
9-
```no_run
10-
use uart_16550::SerialPort;
11-
12-
const SERIAL_IO_PORT: u16 = 0x3F8;
13-
14-
let mut serial_port = unsafe { SerialPort::new(SERIAL_IO_PORT) };
15-
serial_port.init();
16-
17-
// Now the serial port is ready to be used. To send a byte:
18-
serial_port.send(42);
19-
20-
// To receive a byte:
21-
let data = serial_port.receive();
22-
```
23-
"
24-
)]
25-
26-
//! ## With memory mapped serial port
6+
//! This crate supports port-mapped and memory mapped UARTS.
7+
//!
8+
//! ## Usage
9+
//!
10+
//! Depending on the system architecture, the UART can be either accessed through
11+
//! [port-mapped I/O](https://wiki.osdev.org/Port_IO) or
12+
//! [memory-mapped I/O](https://en.wikipedia.org/wiki/Memory-mapped_I/O).
13+
//!
14+
//! ### With port-mappd I/O
15+
//!
16+
//! The UART is accessed through port-mapped I/O on architectures such as `x86_64`.
17+
//! On these architectures, the [`SerialPort`] type can be used:
18+
//!
19+
//!
20+
//! ```no_run
21+
//! # #[cfg(target_arch = "x86_64")]
22+
//! # fn main() {
23+
//! use uart_16550::SerialPort;
24+
//!
25+
//! const SERIAL_IO_PORT: u16 = 0x3F8;
26+
//!
27+
//! let mut serial_port = unsafe { SerialPort::new(SERIAL_IO_PORT) };
28+
//! serial_port.init();
29+
//!
30+
//! // Now the serial port is ready to be used. To send a byte:
31+
//! serial_port.send(42);
32+
//!
33+
//! // To receive a byte:
34+
//! let data = serial_port.receive();
35+
//! # }
36+
//! # #[cfg(not(target_arch = "x86_64"))]
37+
//! # fn main() {}
38+
//! ```
39+
//!
40+
//! ### With memory mapped serial port
41+
//!
42+
//! Most other architectures, such as [RISC-V](https://en.wikipedia.org/wiki/RISC-V), use
43+
//! memory-mapped I/O for accessing the UARTs. On these architectures, the [`MmioSerialPort`]
44+
//! type can be used:
2745
//!
2846
//! ```no_run
2947
//! use uart_16550::MmioSerialPort;

0 commit comments

Comments
 (0)