pub struct SerialPort { /* private fields */ }
Expand description

A serial port and its various data and control registers.

TODO: use PortReadOnly and PortWriteOnly to set permissions for each register.

Implementations§

source§

impl SerialPort

source

pub fn new(base_port: u16) -> SerialPort

Creates and returns a new serial port structure, and initializes that port using standard configuration parameters.

The configuration parameters used in this function are:

  • A baud rate of 38400.
  • “8N1” mode: data word length of 8 bits, with no parity and one stop bit.
  • FIFO buffer enabled with a threshold of 14 bytes.
  • Interrupts enabled for receiving bytes only (not transmitting).
Arguments

Note: if you are experiencing problems with serial port behavior, try enabling the loopback test part of this function to see if that passes.

source

pub fn enable_interrupt( &mut self, event: SerialPortInterruptEvent, enable: bool )

Enable or disable interrupts on this serial port for various events.

source

pub fn acknowledge_interrupt(&mut self, _event: SerialPortInterruptEvent)

Clears an interrupt in the serial port controller

source

pub fn out_str(&mut self, s: &str)

Write the given string to the serial port, blocking until data can be transmitted.

Special characters

Because this function writes strings, it will transmit a carriage return '\r' after transmitting a line feed (new line) '\n' to ensure a proper new line.

source

pub fn out_byte(&mut self, byte: u8)

Write the given byte to the serial port, blocking until data can be transmitted.

This writes the byte directly with no special cases, e.g., new lines.

source

pub fn out_bytes(&mut self, bytes: &[u8])

Write the given bytes to the serial port, blocking until data can be transmitted.

This writes the bytes directly with no special cases, e.g., new lines.

source

pub fn in_byte(&mut self) -> u8

Read one byte from the serial port, blocking until data is available.

source

pub fn in_bytes(&mut self, buffer: &mut [u8]) -> usize

Reads multiple bytes from the serial port into the given buffer, non-blocking.

The buffer will be filled with as many bytes as are available in the serial port. Once data is no longer available to be read, the read operation will stop.

If no data is immediately available on the serial port, this will read nothing and return 0.

Returns the number of bytes read into the given buffer.

source

pub fn ready_to_transmit(&self) -> bool

Returns true if the serial port is ready to transmit a byte.

source

pub fn data_available(&self) -> bool

Returns true if the serial port has data available to read.

source

pub fn base_port_address(&self) -> SerialPortAddress

Trait Implementations§

source§

impl Drop for SerialPort

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Write for SerialPort

source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.