mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-24 05:01:31 +11:00
Refactor Uart initialization
This commit is contained in:
parent
6ab9cd7ed3
commit
26fa532fa3
|
@ -94,9 +94,8 @@ fn main() -> ! {
|
||||||
&mut pac.RESETS,
|
&mut pac.RESETS,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut uart = hal::uart::UartPeripheral::<_, _>::enable(
|
let mut uart = hal::uart::UartPeripheral::<_, _>::new(pac.UART0, &mut pac.RESETS)
|
||||||
pac.UART0,
|
.enable(
|
||||||
&mut pac.RESETS,
|
|
||||||
hal::uart::common_configs::_115200_8_N_1,
|
hal::uart::common_configs::_115200_8_N_1,
|
||||||
clocks.peripheral_clock.into(),
|
clocks.peripheral_clock.into(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -85,9 +85,8 @@ fn main() -> ! {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create a UART driver
|
// Create a UART driver
|
||||||
let mut uart = hal::uart::UartPeripheral::<_, _>::enable(
|
let mut uart = hal::uart::UartPeripheral::<_, _>::new(pac.UART0, &mut pac.RESETS)
|
||||||
pac.UART0,
|
.enable(
|
||||||
&mut pac.RESETS,
|
|
||||||
hal::uart::common_configs::_9600_8_N_1,
|
hal::uart::common_configs::_9600_8_N_1,
|
||||||
clocks.peripheral_clock.into(),
|
clocks.peripheral_clock.into(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -80,9 +80,8 @@ fn main() -> ! {
|
||||||
&mut pac.RESETS,
|
&mut pac.RESETS,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut uart = hal::uart::UartPeripheral::<_, _>::enable(
|
let mut uart = hal::uart::UartPeripheral::<_, _>::new(pac.UART0, &mut pac.RESETS)
|
||||||
pac.UART0,
|
.enable(
|
||||||
&mut pac.RESETS,
|
|
||||||
hal::uart::common_configs::_9600_8_N_1,
|
hal::uart::common_configs::_9600_8_N_1,
|
||||||
clocks.peripheral_clock.into(),
|
clocks.peripheral_clock.into(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -82,9 +82,8 @@ fn main() -> ! {
|
||||||
&mut pac.RESETS,
|
&mut pac.RESETS,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut uart = hal::uart::UartPeripheral::<_, _>::enable(
|
let mut uart = hal::uart::UartPeripheral::<_, _>::new(pac.UART0, &mut pac.RESETS)
|
||||||
pac.UART0,
|
.enable(
|
||||||
&mut pac.RESETS,
|
|
||||||
hal::uart::common_configs::_9600_8_N_1,
|
hal::uart::common_configs::_9600_8_N_1,
|
||||||
clocks.peripheral_clock.into(),
|
clocks.peripheral_clock.into(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
//! let mut clocks = init_clocks_and_plls(XOSC_CRYSTAL_FREQ, peripherals.XOSC, peripherals.CLOCKS, peripherals.PLL_SYS, peripherals.PLL_USB, &mut peripherals.RESETS, &mut watchdog).ok().unwrap();
|
//! let mut clocks = init_clocks_and_plls(XOSC_CRYSTAL_FREQ, peripherals.XOSC, peripherals.CLOCKS, peripherals.PLL_SYS, peripherals.PLL_USB, &mut peripherals.RESETS, &mut watchdog).ok().unwrap();
|
||||||
//!
|
//!
|
||||||
//! // Need to perform clock init before using UART or it will freeze.
|
//! // Need to perform clock init before using UART or it will freeze.
|
||||||
//! let uart = UartPeripheral::<_, _>::enable(
|
//! let uart = UartPeripheral::<_, _>::new(peripherals.UART0, &mut peripherals.RESETS)
|
||||||
//! peripherals.UART0,
|
//! .enable(
|
||||||
//! &mut peripherals.RESETS,
|
|
||||||
//! uart::common_configs::_9600_8_N_1,
|
//! uart::common_configs::_9600_8_N_1,
|
||||||
//! clocks.peripheral_clock.into(),
|
//! clocks.peripheral_clock.into(),
|
||||||
//! ).unwrap();
|
//! )
|
||||||
|
//! .unwrap();
|
||||||
//!
|
//!
|
||||||
//! // Set up UART on GP0 and GP1 (Pico pins 1 and 2)
|
//! // Set up UART on GP0 and GP1 (Pico pins 1 and 2)
|
||||||
//! let _tx_pin = pins.gpio0.into_mode::<FunctionUart>();
|
//! let _tx_pin = pins.gpio0.into_mode::<FunctionUart>();
|
||||||
|
@ -222,15 +222,25 @@ impl<S: State, D: UartDevice> UartPeripheral<S, D> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<D: UartDevice> UartPeripheral<Disabled, D> {
|
impl<D: UartDevice> UartPeripheral<Disabled, D> {
|
||||||
|
/// Creates an UartPeripheral in Disabled state.
|
||||||
|
pub fn new(device: D, resets: &mut pac::RESETS) -> UartPeripheral<Disabled, D> {
|
||||||
|
device.reset_bring_up(resets);
|
||||||
|
|
||||||
|
UartPeripheral {
|
||||||
|
device,
|
||||||
|
config: common_configs::_9600_8_N_1, // placeholder
|
||||||
|
effective_baudrate: Baud(0),
|
||||||
|
_state: Disabled,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Enables the provided UART device with the given configuration.
|
/// Enables the provided UART device with the given configuration.
|
||||||
pub fn enable(
|
pub fn enable(
|
||||||
mut device: D,
|
self,
|
||||||
resets: &mut pac::RESETS,
|
|
||||||
config: UartConfig,
|
config: UartConfig,
|
||||||
frequency: Hertz,
|
frequency: Hertz,
|
||||||
) -> Result<UartPeripheral<Enabled, D>, Error> {
|
) -> Result<UartPeripheral<Enabled, D>, Error> {
|
||||||
device.reset_bring_up(resets);
|
let mut device = self.free();
|
||||||
|
|
||||||
let effective_baudrate = configure_baudrate(&mut device, &config.baudrate, &frequency)?;
|
let effective_baudrate = configure_baudrate(&mut device, &config.baudrate, &frequency)?;
|
||||||
|
|
||||||
device.uartlcr_h.write(|w| {
|
device.uartlcr_h.write(|w| {
|
||||||
|
|
Loading…
Reference in a new issue