Serial

Struct Serial 

Source
pub struct Serial<USART: Instance, Otype = PushPull, PULL = Floating> {
    pub tx: Tx<USART>,
    pub rx: Rx<USART>,
    pub token: ReleaseToken<USART, (Option<USART::Tx<Otype>>, Option<USART::Rx<PULL>>)>,
}
Expand description

Serial abstraction

Fields§

§tx: Tx<USART>§rx: Rx<USART>§token: ReleaseToken<USART, (Option<USART::Tx<Otype>>, Option<USART::Rx<PULL>>)>

Implementations§

Source§

impl<USART: Instance, Otype> Serial<USART, Otype, Floating>

Source

pub fn tx<const R: u8>( usart: impl Into<Rmp<USART, R>>, tx_pin: impl RInto<USART::Tx<Otype>, R>, config: impl Into<Config>, rcc: &mut Rcc, ) -> Tx<USART>

Source§

impl<USART: Instance, PULL: UpMode> Serial<USART, PushPull, PULL>

Source

pub fn rx<const R: u8>( usart: impl Into<Rmp<USART, R>>, rx_pin: impl RInto<USART::Rx<PULL>, R>, config: impl Into<Config>, rcc: &mut Rcc, ) -> Rx<USART>

Source§

impl<USART: Instance, Otype, PULL: UpMode> Serial<USART, Otype, PULL>

Source

pub fn new<const R: u8>( usart: impl Into<Rmp<USART, R>>, pins: (impl RInto<USART::Tx<Otype>, R>, impl RInto<USART::Rx<PULL>, R>), config: impl Into<Config>, rcc: &mut Rcc, ) -> Self

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§

impl<USART: Instance, Otype, PULL> Serial<USART, Otype, PULL>

Source

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

Reconfigure the USART instance.

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

Source

pub fn release( self, ) -> (USART, (Option<USART::Tx<Otype>>, Option<USART::Rx<PULL>>))

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(), &mut rcc);

// 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, Otype, PULL> Serial<USART, Otype, PULL>

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, Otype, PULL> ErrorType for Serial<USART, Otype, PULL>

Source§

type Error = Error

Error type
Source§

impl<USART: Instance, Otype, PULL> ErrorType for Serial<USART, Otype, PULL>

Source§

type Error = Error

Error type of all the IO operations on this type.
Source§

impl<USART: Instance, Otype, PULL> Read<u16> for Serial<USART, Otype, PULL>

Source§

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

Reads a single word from the serial interface
Source§

impl<USART: Instance, Otype, PULL> Read for Serial<USART, Otype, PULL>

Source§

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

Reads a single word from the serial interface
Source§

impl<USART: Instance, Otype, PULL> Write<u16> for Serial<USART, Otype, PULL>

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, Otype, PULL> Write for Serial<USART, Otype, PULL>

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

impl<USART: Instance, Otype, PULL> Write for Serial<USART, Otype, PULL>
where Tx<USART>: Write<Error = Error>,

Source§

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

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

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

Flush this output stream, blocking until all intermediately buffered contents reach their destination.
Source§

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

Write an entire buffer into this writer. Read more
Source§

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

Write a formatted string into this writer, returning any error encountered. Read more
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, Otype, PULL> Write<u16> for Serial<USART, Otype, PULL>

Source§

type Error = Error

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, Otype, PULL> Write<u8> for Serial<USART, Otype, PULL>

Source§

type Error = Error

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, Otype, PULL> Read<u16> for Serial<USART, Otype, PULL>

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, Otype, PULL> Read<u8> for Serial<USART, Otype, PULL>

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, Otype, PULL> Write<u16> for Serial<USART, Otype, PULL>

Source§

type Error = Error

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, Otype, PULL> Write<u8> for Serial<USART, Otype, PULL>

Source§

type Error = Error

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, Otype, PULL> Freeze for Serial<USART, Otype, PULL>
where USART: Freeze, <USART as SerialAsync>::Tx<Otype>: Freeze, <USART as SerialAsync>::Rx<PULL>: Freeze,

§

impl<USART, Otype, PULL> RefUnwindSafe for Serial<USART, Otype, PULL>
where USART: RefUnwindSafe, <USART as SerialAsync>::Tx<Otype>: RefUnwindSafe, <USART as SerialAsync>::Rx<PULL>: RefUnwindSafe,

§

impl<USART, Otype, PULL> Send for Serial<USART, Otype, PULL>
where USART: Send, <USART as SerialAsync>::Tx<Otype>: Send, <USART as SerialAsync>::Rx<PULL>: Send,

§

impl<USART, Otype, PULL> Sync for Serial<USART, Otype, PULL>
where USART: Sync, <USART as SerialAsync>::Tx<Otype>: Sync, <USART as SerialAsync>::Rx<PULL>: Sync,

§

impl<USART, Otype, PULL> Unpin for Serial<USART, Otype, PULL>
where USART: Unpin, <USART as SerialAsync>::Tx<Otype>: Unpin, <USART as SerialAsync>::Rx<PULL>: Unpin,

§

impl<USART, Otype, PULL> UnwindSafe for Serial<USART, Otype, PULL>
where USART: UnwindSafe, <USART as SerialAsync>::Tx<Otype>: UnwindSafe, <USART as SerialAsync>::Rx<PULL>: 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, const R: u8> RFrom<T, R> for T

Source§

fn rfrom(value: T) -> T

Source§

impl<S, T, const R: u8> RInto<T, R> for S
where T: RFrom<S, R>,

Source§

fn rinto(self) -> T

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.