Run rustfmt.

This commit is contained in:
Dario Nieuwenhuis
2022-06-12 22:15:44 +02:00
parent 6199bdea71
commit a8703b7598
340 changed files with 1326 additions and 3020 deletions

View File

@ -47,11 +47,9 @@ pub unsafe fn init() {
start_xosc();
// Before we touch PLLs, switch sys and ref cleanly away from their aux sources.
c.clk_sys_ctrl()
.modify(|w| w.set_src(ClkSysCtrlSrc::CLK_REF));
c.clk_sys_ctrl().modify(|w| w.set_src(ClkSysCtrlSrc::CLK_REF));
while c.clk_sys_selected().read() != 1 {}
c.clk_ref_ctrl()
.modify(|w| w.set_src(ClkRefCtrlSrc::ROSC_CLKSRC_PH));
c.clk_ref_ctrl().modify(|w| w.set_src(ClkRefCtrlSrc::ROSC_CLKSRC_PH));
while c.clk_ref_selected().read() != 1 {}
// Configure PLLs
@ -135,9 +133,7 @@ unsafe fn start_xosc() {
.write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ));
let startup_delay = (((XOSC_MHZ * 1_000_000) / 1000) + 128) / 256;
pac::XOSC
.startup()
.write(|w| w.set_delay(startup_delay as u16));
pac::XOSC.startup().write(|w| w.set_delay(startup_delay as u16));
pac::XOSC.ctrl().write(|w| {
w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ);
w.set_enable(pac::xosc::vals::Enable::ENABLE);
@ -145,13 +141,7 @@ unsafe fn start_xosc() {
while !pac::XOSC.status().read().stable() {}
}
unsafe fn configure_pll(
p: pac::pll::Pll,
refdiv: u32,
vco_freq: u32,
post_div1: u8,
post_div2: u8,
) {
unsafe fn configure_pll(p: pac::pll::Pll, refdiv: u32, vco_freq: u32, post_div1: u8, post_div2: u8) {
let ref_freq = XOSC_MHZ * 1_000_000 / refdiv;
let fbdiv = vco_freq / ref_freq;

View File

@ -1,13 +1,11 @@
use core::convert::Infallible;
use core::marker::PhantomData;
use crate::pac;
use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
use crate::pac::common::{Reg, RW};
use crate::pac::SIO;
use crate::peripherals;
use crate::Unborrow;
use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
use crate::{pac, peripherals, Unborrow};
/// Represents a digital input or output level.
#[derive(Debug, Eq, PartialEq)]
@ -195,10 +193,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
pub fn set_high(&mut self) {
// For Open Drain High, disable the output pin.
unsafe {
self.pin
.sio_oe()
.value_clr()
.write_value(1 << self.pin.pin());
self.pin.sio_oe().value_clr().write_value(1 << self.pin.pin());
}
}
@ -207,10 +202,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
pub fn set_low(&mut self) {
// For Open Drain Low, enable the output pin.
unsafe {
self.pin
.sio_oe()
.value_set()
.write_value(1 << self.pin.pin());
self.pin.sio_oe().value_set().write_value(1 << self.pin.pin());
}
}

View File

@ -5,9 +5,9 @@
// Re-exports
pub use embassy_cortex_m::interrupt::*;
use embassy_macros::cortex_m_interrupt_declare as declare;
use crate::pac::Interrupt as InterruptEnum;
use embassy_macros::cortex_m_interrupt_declare as declare;
declare!(TIMER_IRQ_0);
declare!(TIMER_IRQ_1);
declare!(TIMER_IRQ_2);

View File

@ -17,15 +17,14 @@ mod reset;
// Reexports
pub use embassy_cortex_m::executor;
pub use embassy_hal_common::{unborrow, Unborrow};
pub use embassy_macros::cortex_m_interrupt as interrupt;
#[cfg(feature = "unstable-pac")]
pub use rp2040_pac2 as pac;
#[cfg(not(feature = "unstable-pac"))]
pub(crate) use rp2040_pac2 as pac;
pub use embassy_cortex_m::executor;
pub use embassy_hal_common::{unborrow, Unborrow};
pub use embassy_macros::cortex_m_interrupt as interrupt;
embassy_hal_common::peripherals! {
PIN_0,
PIN_1,

View File

@ -1,7 +1,7 @@
use crate::pac;
pub use pac::resets::regs::Peripherals;
use crate::pac;
pub const ALL_PERIPHERALS: Peripherals = Peripherals(0x01ffffff);
pub unsafe fn reset(peris: Peripherals) {
@ -10,8 +10,6 @@ pub unsafe fn reset(peris: Peripherals) {
pub unsafe fn unreset_wait(peris: Peripherals) {
// TODO use the "atomic clear" register version
pac::RESETS
.reset()
.modify(|v| *v = Peripherals(v.0 & !peris.0));
pac::RESETS.reset().modify(|v| *v = Peripherals(v.0 & !peris.0));
while ((!pac::RESETS.reset_done().read().0) & peris.0) != 0 {}
}

View File

@ -1,13 +1,11 @@
use core::marker::PhantomData;
use crate::Unborrow;
use embassy_hal_common::unborrow;
pub use embedded_hal_02::spi::{Phase, Polarity};
use crate::gpio::sealed::Pin as _;
use crate::gpio::{AnyPin, Pin as GpioPin};
use crate::{pac, peripherals};
pub use embedded_hal_02::spi::{Phase, Polarity};
use crate::{pac, peripherals, Unborrow};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@ -56,11 +54,7 @@ fn calc_prescs(freq: u32) -> (u8, u8) {
}
let presc = div_roundup(ratio, 256);
let postdiv = if presc == 1 {
ratio
} else {
div_roundup(ratio, presc)
};
let postdiv = if presc == 1 { ratio } else { div_roundup(ratio, presc) };
((presc * 2) as u8, (postdiv - 1) as u8)
}
@ -91,14 +85,7 @@ impl<'d, T: Instance> Spi<'d, T> {
config: Config,
) -> Self {
unborrow!(clk, mosi);
Self::new_inner(
inner,
Some(clk.degrade()),
Some(mosi.degrade()),
None,
None,
config,
)
Self::new_inner(inner, Some(clk.degrade()), Some(mosi.degrade()), None, None, config)
}
pub fn new_rxonly(
@ -108,14 +95,7 @@ impl<'d, T: Instance> Spi<'d, T> {
config: Config,
) -> Self {
unborrow!(clk, miso);
Self::new_inner(
inner,
Some(clk.degrade()),
None,
Some(miso.degrade()),
None,
config,
)
Self::new_inner(inner, Some(clk.degrade()), None, Some(miso.degrade()), None, config)
}
fn new_inner(

View File

@ -1,11 +1,12 @@
use crate::interrupt::{Interrupt, InterruptExt};
use atomic_polyfill::{AtomicU8, Ordering};
use core::cell::Cell;
use atomic_polyfill::{AtomicU8, Ordering};
use critical_section::CriticalSection;
use embassy::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy::blocking_mutex::Mutex;
use embassy::time::driver::{AlarmHandle, Driver};
use crate::interrupt::{Interrupt, InterruptExt};
use crate::{interrupt, pac};
struct AlarmState {
@ -45,15 +46,13 @@ impl Driver for TimerDriver {
}
unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
let id = self
.next_alarm
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
if x < ALARM_COUNT as u8 {
Some(x + 1)
} else {
None
}
});
let id = self.next_alarm.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
if x < ALARM_COUNT as u8 {
Some(x + 1)
} else {
None
}
});
match id {
Ok(id) => Some(AlarmHandle::new(id)),

View File

@ -1,10 +1,9 @@
use core::marker::PhantomData;
use crate::Unborrow;
use embassy_hal_common::unborrow;
use gpio::Pin;
use crate::{gpio, pac, peripherals};
use crate::{gpio, pac, peripherals, Unborrow};
#[non_exhaustive]
pub struct Config {
@ -57,10 +56,8 @@ impl<'d, T: Instance> Uart<'d, T> {
}
// Load PL011's baud divisor registers
p.uartibrd()
.write_value(pac::uart::regs::Uartibrd(baud_ibrd));
p.uartfbrd()
.write_value(pac::uart::regs::Uartfbrd(baud_fbrd));
p.uartibrd().write_value(pac::uart::regs::Uartibrd(baud_ibrd));
p.uartfbrd().write_value(pac::uart::regs::Uartfbrd(baud_fbrd));
p.uartlcr_h().write(|w| {
w.set_wlen(config.data_bits - 5);