Module avr_oxide::stdout

source ·
Expand description

Simple macros and container for a static reference to a global SerialPort instance, so we can use print!()/println!() style macros.

format!() style printing is provided by the wonderful ufmt crate, and we provide a couple of print!/println! macros that use this, so you can write your code in a familar Rusty way.

Note that these macros are infallible - any errors will be swallowed whole and ignored.

§Usage

Before you can use the print!/println! macros, you need to use the set_stdout (or set_stdout_wrapped) function to pass a reference to the serial port you wish to use. (Actually, anything that implements Write will do, but this will typically be a serial port.)

#![no_std]
#![no_main]
use avr_oxide::hal::generic::serial::{BaudRate, DataBits, Parity, SerialPortMode, StopBits};
use avr_oxide::devices::{UsesPin, OxideSerialPort };
use avr_oxide::{boards::board, print, println};
use avr_oxide::StaticWrap;

#[avr_oxide::main(chip="atmega4809")]
pub fn main() -> ! {
  let supervisor = avr_oxide::oxide::instance();

  let mut serial= StaticWrap::new(OxideSerialPort::using_port_and_pins(board::usb_serial(),
                                                                   board::usb_serial_pins().0,
                                                                   board::usb_serial_pins().1).mode(SerialPortMode::Asynch(BaudRate::Baud9600, DataBits::Bits8, Parity::None, StopBits::Bits1)));

  // Set the serial port to use for STDOUT
  avr_oxide::stdout::set_stdio(serial.borrow_mut());

  println!("Welcome to AVRoxide");

  supervisor.run();
}

Statics§

Functions§

  • Get a reference to the global STDOUT output device.
  • Set a global reference that can be used by the print!/println! macros for easy output to serial ports.

Type Aliases§