Skip to content

Commit 7d49350

Browse files
authored
Merge pull request #16 from josephlr/nightly
SerialPort::new() no longer requires nightly
2 parents 8f5ef49 + 34ec64b commit 7d49350

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

src/lib.rs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use bitflags::bitflags;
2424
use core::fmt;
25-
use x86_64::instructions::port::Port;
25+
use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly};
2626

2727
macro_rules! wait_for {
2828
($cond:expr) => {
@@ -56,43 +56,26 @@ bitflags! {
5656
/// An interface to a serial port that allows sending out individual bytes.
5757
pub struct SerialPort {
5858
data: Port<u8>,
59-
int_en: Port<u8>,
60-
fifo_ctrl: Port<u8>,
61-
line_ctrl: Port<u8>,
62-
modem_ctrl: Port<u8>,
63-
line_sts: Port<u8>,
59+
int_en: PortWriteOnly<u8>,
60+
fifo_ctrl: PortWriteOnly<u8>,
61+
line_ctrl: PortWriteOnly<u8>,
62+
modem_ctrl: PortWriteOnly<u8>,
63+
line_sts: PortReadOnly<u8>,
6464
}
6565

6666
impl SerialPort {
6767
/// Creates a new serial port interface on the given I/O port.
6868
///
6969
/// This function is unsafe because the caller must ensure that the given base address
7070
/// really points to a serial port device.
71-
#[cfg(feature = "nightly")]
7271
pub const unsafe fn new(base: u16) -> SerialPort {
7372
SerialPort {
7473
data: Port::new(base),
75-
int_en: Port::new(base + 1),
76-
fifo_ctrl: Port::new(base + 2),
77-
line_ctrl: Port::new(base + 3),
78-
modem_ctrl: Port::new(base + 4),
79-
line_sts: Port::new(base + 5),
80-
}
81-
}
82-
83-
/// Creates a new serial port interface on the given I/O port.
84-
///
85-
/// This function is unsafe because the caller must ensure that the given base address
86-
/// really points to a serial port device.
87-
#[cfg(not(feature = "nightly"))]
88-
pub unsafe fn new(base: u16) -> SerialPort {
89-
SerialPort {
90-
data: Port::new(base),
91-
int_en: Port::new(base + 1),
92-
fifo_ctrl: Port::new(base + 2),
93-
line_ctrl: Port::new(base + 3),
94-
modem_ctrl: Port::new(base + 4),
95-
line_sts: Port::new(base + 5),
74+
int_en: PortWriteOnly::new(base + 1),
75+
fifo_ctrl: PortWriteOnly::new(base + 2),
76+
line_ctrl: PortWriteOnly::new(base + 3),
77+
modem_ctrl: PortWriteOnly::new(base + 4),
78+
line_sts: PortReadOnly::new(base + 5),
9679
}
9780
}
9881

0 commit comments

Comments
 (0)