Struct UsartDriver

Source
pub struct UsartDriver<'a> {
    regs: *mut RegisterBlock,
    _callback: Option<Box<dyn FnMut(Event) + 'a>>,
    config: Config,
    tx_count: u32,
    rx_count: u32,
}
Expand description

A polling-based USART driver for STM32F407.

Fields§

§regs: *mut RegisterBlock§_callback: Option<Box<dyn FnMut(Event) + 'a>>§config: Config§tx_count: u32§rx_count: u32

Implementations§

Source§

impl<'a> UsartDriver<'a>

Source

pub fn new(usart_base_addr: u32, config: Config) -> Self

Source

pub fn new_usart1(config: Config) -> Self

Create a new USART1 driver instance (APB2 clock)

Source

pub fn new_usart2(config: Config) -> Self

Create a new USART2 driver instance (APB1 clock)

Source

pub fn new_usart3(config: Config) -> Self

Create a new USART3 driver instance (APB1 clock)

Source

fn regs(&self) -> &mut RegisterBlock

Source

fn is_on_apb2(&self) -> bool

Source

fn compute_brr(&self, baudrate: u32) -> u32

Source

fn write_cr1(&mut self, f: impl FnOnce(u32) -> u32)

Source

fn write_cr2(&mut self, f: impl FnOnce(u32) -> u32)

Source

fn write_cr3(&mut self, f: impl FnOnce(u32) -> u32)

Source

fn wait_txe(&self)

Source

fn wait_rxne(&self)

Source

fn wait_tc(&self)

Trait Implementations§

Source§

impl<'a> Usart<'a> for UsartDriver<'a>

Source§

fn initialize(&mut self, callback: impl FnMut(Event) + 'a) -> Result<(), i32>

Initializes the USART peripheral. Read more
Source§

fn uninitialize(&mut self) -> Result<(), i32>

De-initializes the USART peripheral.
Source§

fn configure(&mut self, config: &Config) -> Result<(), i32>

Configures the USART peripheral.
Source§

fn send(&mut self, data: &[u8]) -> Result<(), i32>

Transmits data over the USART bus.
Source§

fn receive(&mut self, data: &mut [u8]) -> Result<(), i32>

Receives data from the USART bus.
Source§

fn transfer(&mut self, data_out: &[u8], data_in: &mut [u8]) -> Result<(), i32>

Simultaneously sends and receives data.
Source§

fn get_tx_count(&self) -> u32

Gets the number of bytes transmitted.
Source§

fn get_rx_count(&self) -> u32

Gets the number of bytes received.
Source§

fn get_status(&self) -> Status

Gets the current status of the USART peripheral.
Source§

fn set_modem_control(&mut self, control: ModemControl) -> Result<(), i32>

Controls the modem lines.
Source§

fn get_modem_status(&self) -> ModemStatus

Gets the status of the modem lines.
Source§

fn tx_enable(&mut self, enable: bool) -> Result<(), i32>

Enables or disables the transmitter.
Source§

fn rx_enable(&mut self, enable: bool) -> Result<(), i32>

Enables or disables the receiver.
Source§

fn control_break(&mut self, enable: bool) -> Result<(), i32>

Controls the generation of a break condition.
Source§

fn abort_send(&mut self) -> Result<(), i32>

Aborts an ongoing send operation.
Source§

fn abort_receive(&mut self) -> Result<(), i32>

Aborts an ongoing receive operation.
Source§

fn abort_transfer(&mut self) -> Result<(), i32>

Aborts an ongoing transfer operation.

Auto Trait Implementations§

§

impl<'a> Freeze for UsartDriver<'a>

§

impl<'a> !RefUnwindSafe for UsartDriver<'a>

§

impl<'a> !Send for UsartDriver<'a>

§

impl<'a> !Sync for UsartDriver<'a>

§

impl<'a> Unpin for UsartDriver<'a>

§

impl<'a> !UnwindSafe for UsartDriver<'a>

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.