Struct serial_port_basic::SerialPort
source · 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
impl SerialPort
sourcepub fn new(base_port: u16) -> SerialPort
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
base_port
: the port number (port I/O address) of the serial port. This should generally be one of the known serial ports, e.g., on x86,SerialPortAddress::COM1
throughSerialPortAddress::COM4
.
Note: if you are experiencing problems with serial port behavior, try enabling the loopback test part of this function to see if that passes.
sourcepub fn enable_interrupt(
&mut self,
event: SerialPortInterruptEvent,
enable: bool
)
pub fn enable_interrupt( &mut self, event: SerialPortInterruptEvent, enable: bool )
Enable or disable interrupts on this serial port for various events.
sourcepub fn acknowledge_interrupt(&mut self, _event: SerialPortInterruptEvent)
pub fn acknowledge_interrupt(&mut self, _event: SerialPortInterruptEvent)
Clears an interrupt in the serial port controller
sourcepub fn out_str(&mut self, s: &str)
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.
sourcepub fn out_byte(&mut self, byte: u8)
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.
sourcepub fn out_bytes(&mut self, bytes: &[u8])
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.
sourcepub fn in_byte(&mut self) -> u8
pub fn in_byte(&mut self) -> u8
Read one byte from the serial port, blocking until data is available.
sourcepub fn in_bytes(&mut self, buffer: &mut [u8]) -> usize
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
.
sourcepub fn ready_to_transmit(&self) -> bool
pub fn ready_to_transmit(&self) -> bool
Returns true
if the serial port is ready to transmit a byte.
sourcepub fn data_available(&self) -> bool
pub fn data_available(&self) -> bool
Returns true
if the serial port has data available to read.