|
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). |
2 | 5 | //! |
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: |
27 | 45 | //! |
28 | 46 | //! ```no_run |
29 | 47 | //! use uart_16550::MmioSerialPort; |
|
0 commit comments