mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-11 04:51:31 +11:00
Use UartConfig::new constructor instead of common_configs in examples
This commit is contained in:
parent
0a86dad34c
commit
b81ad6f599
|
@ -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();
|
||||
|
|
|
@ -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<Gpio0, hal::gpio::Function<hal::gpio::Uart>>,
|
||||
|
@ -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();
|
||||
|
|
|
@ -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<Gpio0, hal::gpio::Function<hal::gpio::Uart>>,
|
||||
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
//!
|
||||
|
|
Loading…
Reference in a new issue