Struct serial_port::SerialPort

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

A serial port abstraction with support for interrupt-based data receival.

Implementations§

source§

impl SerialPort

source

pub fn new(serial_port: SerialPortBasic) -> SerialPort

Initialize this serial port by giving it ownership and control of the given basic serial_port.

source

pub fn register_interrupt_handler( serial_port: Arc<IrqSafeMutex<SerialPort>>, interrupt_number: InterruptNumber, interrupt_handler: InterruptHandler ) -> Result<(), &'static str>

Register the interrupt handler for this serial port and spawn a deferrent interrupt task to handle its data receival.

source

pub fn set_data_sender( &mut self, sender: Sender<DataChunk> ) -> Result<(), DataSenderAlreadyExists>

Tells this SerialPort to push received data bytes onto the given sender channel.

If a sender already exists for this serial port, the existing sender is not replaced and an error is returned.

Methods from Deref<Target = SerialPortBasic>§

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

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

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

Clears an interrupt in the serial port controller

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.

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.

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.

pub fn in_byte(&mut self) -> u8

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

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.

pub fn ready_to_transmit(&self) -> bool

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

pub fn data_available(&self) -> bool

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

pub fn base_port_address(&self) -> SerialPortAddress

Trait Implementations§

source§

impl Deref for SerialPort

§

type Target = SerialPort

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for SerialPort

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl Read for SerialPort

A non-blocking implementation of [core2::io::Read] that will read bytes into the given buf so long as more bytes are available. The read operation will be completed when there are no more bytes to be read, or when the buf is filled, whichever comes first.

Because it’s non-blocking, a [core2::io::ErrorKind::WouldBlock] error is returned if there are no bytes available to be read, indicating that the read would block.

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
§

fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
§

unsafe fn initializer(&self) -> Initializer

Determines if this Reader can work with buffers of uninitialized memory. Read more
§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
§

fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
§

fn bytes(self) -> Bytes<Self>where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
§

fn chain<R>(self, next: R) -> Chain<Self, R>where R: Read, Self: Sized,

Creates an adaptor which will chain this stream with another. Read more
§

fn take(self, limit: u64) -> Take<Self>where Self: Sized,

Creates an adaptor which will read at most limit bytes from it. Read more
source§

impl Write for SerialPort

A blocking implementation of [core2::io::Write] that will write bytes from the given buf to the SerialPort, waiting until it is ready to transfer all bytes.

The flush() function is a no-op, since the SerialPort does not have buffering.

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
§

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

Writes a formatted string into this writer, returning any error encountered. Read more
§

fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,

Creates a “by reference” adaptor for this instance of Write. Read more
source§

impl Write for SerialPort

Forward the implementation of core::fmt::Write to the inner SerialPortBasic.

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.