Struct Serial

Source
pub struct Serial<USART, PINS> {
    pub tx: Tx<USART>,
    pub rx: Rx<USART>,
    pub token: ReleaseToken<USART, PINS>,
}
Expand description

Serial abstraction

Fields§

§tx: Tx<USART>§rx: Rx<USART>§token: ReleaseToken<USART, PINS>

Implementations§

Source§

impl<USART: Instance, PINS> Serial<USART, PINS>

Source

pub fn new( usart: USART, pins: PINS, mapr: &mut MAPR, config: impl Into<Config>, clocks: &Clocks, ) -> Self
where PINS: Pins<USART>,

Configures the serial interface and creates the interface struct.

Bps is the baud rate of the interface.

Clocks passes information about the current frequencies of the clocks. The existence of the struct ensures that the clock settings are fixed.

The serial struct takes ownership over the USARTX device registers and the specified PINS

MAPR and APBX are register handles which are passed for configuration. (MAPR is used to map the USART to the corresponding pins. APBX is used to reset the USART.)

Source

pub fn reconfigure( &mut self, config: impl Into<Config>, clocks: &Clocks, ) -> Result<(), Infallible>

Reconfigure the USART instance.

If a transmission is currently in progress, this returns nb::Error::WouldBlock.

Source

pub fn release(self) -> (USART, PINS)

Returns ownership of the borrowed register handles

§Examples

Basic usage:

let mut serial = Serial::new(usart, (tx_pin, rx_pin), &mut afio.mapr, 9600.bps(), &clocks);

// You can split the `Serial`
let Serial { tx, rx, token } = serial;

// You can reunite the `Serial` back
let serial = Serial { tx, rx, token };

// Release `Serial`
let (usart, (tx_pin, rx_pin)) = serial.release();
Source

pub fn split(self) -> (Tx<USART>, Rx<USART>)

Separates the serial struct into separate channel objects for sending (Tx) and receiving (Rx)

If in the future it will be necessary to free up resources, then you need to use a different method of separation:

let Serial { tx, rx, token } = serial;
Source§

impl<USART: Instance, PINS> Serial<USART, PINS>

Source

pub fn listen(&mut self, event: Event)

Starts listening to the USART by enabling the Received data ready to be read (RXNE) interrupt and Transmit data register empty (TXE) interrupt

Source

pub fn unlisten(&mut self, event: Event)

Stops listening to the USART by disabling the Received data ready to be read (RXNE) interrupt and Transmit data register empty (TXE) interrupt

Source

pub fn is_idle(&self) -> bool

Returns true if the line idle status is set

Source

pub fn is_tx_empty(&self) -> bool

Returns true if the tx register is empty (and can accept data)

Source

pub fn is_rx_not_empty(&self) -> bool

Returns true if the rx register is not empty (and can be read)

Source

pub fn clear_idle_interrupt(&self)

Clear idle line interrupt flag

Trait Implementations§

Source§

impl<USART: Instance, PINS> Write for Serial<USART, PINS>

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
Source§

impl<USART: Instance, PINS> Write<u16> for Serial<USART, PINS>

Source§

type Error = Infallible

The type of error that can occur when writing
Source§

fn bwrite_all(&mut self, buffer: &[u16]) -> Result<(), Self::Error>

Writes a slice, blocking until everything has been written Read more
Source§

fn bflush(&mut self) -> Result<(), Self::Error>

Block until the serial interface has sent all buffered words
Source§

impl<USART: Instance, PINS> Write<u8> for Serial<USART, PINS>

Source§

type Error = Infallible

The type of error that can occur when writing
Source§

fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error>

Writes a slice, blocking until everything has been written Read more
Source§

fn bflush(&mut self) -> Result<(), Self::Error>

Block until the serial interface has sent all buffered words
Source§

impl<USART: Instance, PINS> Read<u16> for Serial<USART, PINS>

Source§

type Error = Error

Read error
Source§

fn read(&mut self) -> Result<u16, Error>

Reads a single word from the serial interface
Source§

impl<USART: Instance, PINS> Read<u8> for Serial<USART, PINS>

Source§

type Error = Error

Read error
Source§

fn read(&mut self) -> Result<u8, Error>

Reads a single word from the serial interface
Source§

impl<USART: Instance, PINS> Write<u16> for Serial<USART, PINS>

Source§

type Error = Infallible

Write error
Source§

fn write(&mut self, word: u16) -> Result<(), Self::Error>

Writes a single word to the serial interface
Source§

fn flush(&mut self) -> Result<(), Self::Error>

Ensures that none of the previously written words are still buffered
Source§

impl<USART: Instance, PINS> Write<u8> for Serial<USART, PINS>

Source§

type Error = Infallible

Write error
Source§

fn write(&mut self, word: u8) -> Result<(), Self::Error>

Writes a single word to the serial interface
Source§

fn flush(&mut self) -> Result<(), Self::Error>

Ensures that none of the previously written words are still buffered

Auto Trait Implementations§

§

impl<USART, PINS> Freeze for Serial<USART, PINS>
where USART: Freeze, PINS: Freeze,

§

impl<USART, PINS> RefUnwindSafe for Serial<USART, PINS>
where USART: RefUnwindSafe, PINS: RefUnwindSafe,

§

impl<USART, PINS> Send for Serial<USART, PINS>
where USART: Send, PINS: Send,

§

impl<USART, PINS> Sync for Serial<USART, PINS>
where USART: Sync, PINS: Sync,

§

impl<USART, PINS> Unpin for Serial<USART, PINS>
where USART: Unpin, PINS: Unpin,

§

impl<USART, PINS> UnwindSafe for Serial<USART, PINS>
where USART: UnwindSafe, PINS: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.