[][src]Struct ruspiro_uart::Uart1

pub struct Uart1 { /* fields omitted */ }

Uart1 (miniUART) peripheral representation

Implementations

impl Uart1[src]

pub const fn new() -> Self[src]

Get a new Uart1 instance, that needs to be initialized before it can be used.

Example

let _miniUart = Uart1::new();

pub fn initialize(
    &mut self,
    clock_rate: u32,
    baud_rate: u32
) -> Result<(), &'static str>
[src]

Initialize the Uart1 peripheral for usage. It takes the core clock rate and the baud rate to configure correct communication speed.

Example

let mut uart = Uart1::new();
assert_eq!(uart.initialize(250_000_000, 115_200), Ok(()));

pub fn send_char(&self, c: char)[src]

Send a single character to the uart peripheral

Example

uart.send_char('A');

pub fn send_string(&self, s: &str)[src]

Send a string to the uart peripheral

Example

uart.send_string("Test string with line break\r\n");

pub fn send_data(&self, d: &[u8])[src]

Send a byte buffer to the uart peripheral

Example

uart.send_data("SomeData".as_bytes());

pub fn send_hex(&self, value: u64)[src]

convert a given u64 into it's hex representation and send to uart

Example

uart.send_hex(12345);

pub fn try_receive_data(&self, buffer: &mut [u8]) -> Result<usize, &'static str>[src]

Try to recieve data from the Uart of the given size If the requested size could be read it returns a Ok(data: Vec<u8>) containing the data otherwise an Err(msg: &str).

Example

let mut buffer: [u8; 8] = [0; 8];
let rx_size = uart.try_receive_data(&mut buffer).expect("unable to receive data");

pub fn receive_data(&self, buffer: &mut [u8]) -> Result<usize, &'static str>[src]

Recieve data from the Uart of the given size, blocking the current execution until the requested amount if data has been received. If the requested size could be read it returns a Ok(size: usize) containing the data otherwise an Err(msg: &str).

Example

let mut buffer: [u8; 8] = [0; 8];
let rx_size = uart.receive_data(&mut buffer).expect("unable to receive data");

pub fn enable_interrupts(&self, i_type: InterruptType)[src]

Enable Interrupts to be triggered by the miniUart. The i_type specifies the interrupts that shall be triggered. To receive/handle the interrupts a corresponding interrupt handler need to be implemented, for example by using the ruspiro-interrupt crate.

Example

// enable the interrupt to be triggered when data is recieved by the miniUart
uart.enable_interrupts(InterruptType::Receive);

pub fn disable_interrupts(&self, i_type: InterruptType)[src]

Disable Interrupts from beeing triggered by the miniUart. The i_type specifies the interrupts that shall disbabled.

Example

// disable the interrupt to be triggered when data is recieved by the miniUart
uart.disable_interrupts(InterruptType::Receive);

pub fn get_interrupt_status(&self) -> u32[src]

Read the current interrupt status. Bit 0 -> is set to 0 if an interrupt is pending Bit [1:2] -> 01 = transmit register is empty 10 = recieve register holds valid data

Example

let irq_status = uart.get_interrupt_status();
if (irq_status & 0b010) != 0 {
    println!("transmit register empty raised");
}

Trait Implementations

impl ConsoleImpl for Uart1[src]

impl Drop for Uart1[src]

Auto Trait Implementations

impl Send for Uart1

impl Sync for Uart1

impl Unpin for Uart1

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.