diff --git a/boards/rp-pico/examples/pico_i2c_pio.rs b/boards/rp-pico/examples/pico_i2c_pio.rs index dad70a8..0ee03b0 100644 --- a/boards/rp-pico/examples/pico_i2c_pio.rs +++ b/boards/rp-pico/examples/pico_i2c_pio.rs @@ -38,6 +38,9 @@ use rp_pico::hal::pac; // higher-level drivers. use rp_pico::hal; +// UART related types +use hal::uart::{DataBits, StopBits, UartConfig}; + /// Prints the temperature received from the sensor fn print_temperature(serial: &mut impl FmtWrite, temp: [u8; 2]) { let temp_i16 = i16::from_be_bytes(temp) >> 5; @@ -97,7 +100,7 @@ fn main() -> ! { let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( - hal::uart::common_configs::_115200_8_N_1, + UartConfig::new(115_200.Hz(), DataBits::Eight, None, StopBits::One), clocks.peripheral_clock.freq(), ) .unwrap(); diff --git a/boards/rp-pico/examples/pico_uart_irq_buffer.rs b/boards/rp-pico/examples/pico_uart_irq_buffer.rs index f8114c9..685f9f8 100644 --- a/boards/rp-pico/examples/pico_uart_irq_buffer.rs +++ b/boards/rp-pico/examples/pico_uart_irq_buffer.rs @@ -30,6 +30,9 @@ use rp2040_hal::Clock; // The macro for our start-up function use rp_pico::entry; +// Time handling traits +use fugit::RateExtU32; + // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) use panic_halt as _; @@ -52,6 +55,9 @@ use heapless::spsc::Queue; /// Import the GPIO pins we use use hal::gpio::pin::bank0::{Gpio0, Gpio1}; +// UART related types +use hal::uart::{DataBits, StopBits, UartConfig}; + /// Alias the type for our UART pins to make things clearer. type UartPins = ( hal::gpio::Pin>, @@ -134,7 +140,7 @@ fn main() -> ! { // Make a UART on the given pins let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( - hal::uart::common_configs::_9600_8_N_1, + UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One), clocks.peripheral_clock.freq(), ) .unwrap(); diff --git a/boards/rp-pico/examples/pico_uart_irq_echo.rs b/boards/rp-pico/examples/pico_uart_irq_echo.rs index 8de2206..6835d22 100644 --- a/boards/rp-pico/examples/pico_uart_irq_echo.rs +++ b/boards/rp-pico/examples/pico_uart_irq_echo.rs @@ -28,6 +28,9 @@ use rp2040_hal::Clock; // The macro for our start-up function use rp_pico::entry; +// Time handling traits +use fugit::RateExtU32; + // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) use panic_halt as _; @@ -49,6 +52,9 @@ use critical_section::Mutex; /// Import the GPIO pins we use use hal::gpio::pin::bank0::{Gpio0, Gpio1}; +// UART related types +use hal::uart::{DataBits, StopBits, UartConfig}; + /// Alias the type for our UART pins to make things clearer. type UartPins = ( hal::gpio::Pin>, @@ -118,7 +124,7 @@ fn main() -> ! { // Make a UART on the given pins let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( - hal::uart::common_configs::_9600_8_N_1, + UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One), clocks.peripheral_clock.freq(), ) .unwrap(); diff --git a/rp2040-hal/examples/adc.rs b/rp2040-hal/examples/adc.rs index a9ddae4..38530eb 100644 --- a/rp2040-hal/examples/adc.rs +++ b/rp2040-hal/examples/adc.rs @@ -20,8 +20,12 @@ use rp2040_hal as hal; // Some traits we need use core::fmt::Write; use embedded_hal::adc::OneShot; +use fugit::RateExtU32; use rp2040_hal::Clock; +// UART related types +use hal::uart::{DataBits, StopBits, UartConfig}; + // A shorter alias for the Peripheral Access Crate, which provides low-level // register access use hal::pac; @@ -91,7 +95,7 @@ fn main() -> ! { // Create a UART driver let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( - hal::uart::common_configs::_9600_8_N_1, + UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One), clocks.peripheral_clock.freq(), ) .unwrap(); diff --git a/rp2040-hal/examples/rom_funcs.rs b/rp2040-hal/examples/rom_funcs.rs index c801aba..281025d 100644 --- a/rp2040-hal/examples/rom_funcs.rs +++ b/rp2040-hal/examples/rom_funcs.rs @@ -22,8 +22,12 @@ use hal::pac; // Some traits we need use core::fmt::Write; +use fugit::RateExtU32; use hal::Clock; +// UART related types +use hal::uart::{DataBits, StopBits, UartConfig}; + /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. /// Note: This boot block is not necessary when using a rp-hal based BSP @@ -88,7 +92,7 @@ fn main() -> ! { ); let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( - hal::uart::common_configs::_9600_8_N_1, + UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One), clocks.peripheral_clock.freq(), ) .unwrap(); diff --git a/rp2040-hal/examples/uart.rs b/rp2040-hal/examples/uart.rs index 56de75e..ec4d010 100644 --- a/rp2040-hal/examples/uart.rs +++ b/rp2040-hal/examples/uart.rs @@ -24,8 +24,12 @@ use hal::pac; // Some traits we need use core::fmt::Write; +use fugit::RateExtU32; use rp2040_hal::clocks::Clock; +// UART related types +use hal::uart::{DataBits, StopBits, UartConfig}; + /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. /// Note: This boot block is not necessary when using a rp-hal based BSP @@ -88,7 +92,7 @@ fn main() -> ! { ); let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( - hal::uart::common_configs::_9600_8_N_1, + UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One), clocks.peripheral_clock.freq(), ) .unwrap(); diff --git a/rp2040-hal/src/uart/mod.rs b/rp2040-hal/src/uart/mod.rs index d0ddc57..fb3aa45 100644 --- a/rp2040-hal/src/uart/mod.rs +++ b/rp2040-hal/src/uart/mod.rs @@ -6,7 +6,8 @@ //! //! See [examples/uart.rs](https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal/examples/uart.rs) for a more complete example //! ```no_run -//! use rp2040_hal::{Clock, clocks::init_clocks_and_plls, gpio::{Pins, FunctionUart}, pac, sio::Sio, uart::{self, UartPeripheral}, watchdog::Watchdog}; +//! use rp2040_hal::{Clock, clocks::init_clocks_and_plls, gpio::{Pins, FunctionUart}, pac, sio::Sio, uart::{self, DataBits, StopBits, UartConfig, UartPeripheral}, watchdog::Watchdog}; +//! use fugit::RateExtU32; //! //! const XOSC_CRYSTAL_FREQ: u32 = 12_000_000; // Typically found in BSP crates //! @@ -24,7 +25,7 @@ //! // Need to perform clock init before using UART or it will freeze. //! let uart = UartPeripheral::new(peripherals.UART0, pins, &mut peripherals.RESETS) //! .enable( -//! uart::common_configs::_9600_8_N_1, +//! UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One), //! clocks.peripheral_clock.freq(), //! ).unwrap(); //!