Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerialPort::new() no longer requires nightly #16

Merged
merged 1 commit into from
May 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use bitflags::bitflags;
use core::fmt;
use x86_64::instructions::port::Port;
use x86_64::instructions::port::{Port, PortReadOnly, PortWriteOnly};

macro_rules! wait_for {
($cond:expr) => {
Expand Down Expand Up @@ -56,43 +56,26 @@ bitflags! {
/// An interface to a serial port that allows sending out individual bytes.
pub struct SerialPort {
data: Port<u8>,
int_en: Port<u8>,
fifo_ctrl: Port<u8>,
line_ctrl: Port<u8>,
modem_ctrl: Port<u8>,
line_sts: Port<u8>,
int_en: PortWriteOnly<u8>,
fifo_ctrl: PortWriteOnly<u8>,
line_ctrl: PortWriteOnly<u8>,
modem_ctrl: PortWriteOnly<u8>,
line_sts: PortReadOnly<u8>,
}

impl SerialPort {
/// Creates a new serial port interface on the given I/O port.
///
/// This function is unsafe because the caller must ensure that the given base address
/// really points to a serial port device.
#[cfg(feature = "nightly")]
pub const unsafe fn new(base: u16) -> SerialPort {
SerialPort {
data: Port::new(base),
int_en: Port::new(base + 1),
fifo_ctrl: Port::new(base + 2),
line_ctrl: Port::new(base + 3),
modem_ctrl: Port::new(base + 4),
line_sts: Port::new(base + 5),
}
}

/// Creates a new serial port interface on the given I/O port.
///
/// This function is unsafe because the caller must ensure that the given base address
/// really points to a serial port device.
#[cfg(not(feature = "nightly"))]
pub unsafe fn new(base: u16) -> SerialPort {
SerialPort {
data: Port::new(base),
int_en: Port::new(base + 1),
fifo_ctrl: Port::new(base + 2),
line_ctrl: Port::new(base + 3),
modem_ctrl: Port::new(base + 4),
line_sts: Port::new(base + 5),
int_en: PortWriteOnly::new(base + 1),
fifo_ctrl: PortWriteOnly::new(base + 2),
line_ctrl: PortWriteOnly::new(base + 3),
modem_ctrl: PortWriteOnly::new(base + 4),
line_sts: PortReadOnly::new(base + 5),
}
}

Expand Down