Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajSadel committed Mar 31, 2023
1 parent f75207f commit 619772c
Show file tree
Hide file tree
Showing 203 changed files with 1,585 additions and 327 deletions.
9 changes: 7 additions & 2 deletions esp-hal-common/src/sha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use core::convert::Infallible;

use crate::{
peripheral::{Peripheral, PeripheralRef},
peripherals::SHA, system::PeripheralClockControl,
peripherals::SHA,
system::PeripheralClockControl,
};

// All the hash algorithms introduced in FIPS PUB 180-4 Spec.
Expand Down Expand Up @@ -227,7 +228,11 @@ fn mode_as_bits(mode: ShaMode) -> u8 {
// This implementation might fail after u32::MAX/8 bytes, to increase please see
// ::finish() length/self.cursor usage
impl<'d> Sha<'d> {
pub fn new(sha: impl Peripheral<P = SHA> + 'd, mode: ShaMode, peripheral_clock_control: &mut PeripheralClockControl) -> Self {
pub fn new(
sha: impl Peripheral<P = SHA> + 'd,
mode: ShaMode,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
crate::into_ref!(sha);
peripheral_clock_control.enable(crate::system::Peripheral::Sha);

Expand Down
44 changes: 30 additions & 14 deletions esp-hal-common/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub enum Peripheral {
Uart0,
Uart1,
#[cfg(uart2)]
Uart2
Uart2,
}

/// Controls the enablement of peripheral clocks.
Expand Down Expand Up @@ -342,45 +342,61 @@ impl PeripheralClockControl {
}
#[cfg(timg0)]
Peripheral::Timg0 => {
system.timergroup0_timer_clk_conf
system
.timergroup0_timer_clk_conf
.write(|w| w.tg0_timer_clk_en().set_bit());
system.timergroup0_timer_clk_conf
system
.timergroup0_timer_clk_conf
.write(|w| unsafe { w.tg0_timer_clk_sel().bits(1) });
}
#[cfg(timg1)]
Peripheral::Timg1 => {
system.timergroup1_timer_clk_conf
system
.timergroup1_timer_clk_conf
.write(|w| w.tg1_timer_clk_en().set_bit());
system.timergroup1_timer_clk_conf
system
.timergroup1_timer_clk_conf
.write(|w| unsafe { w.tg1_timer_clk_sel().bits(1) });
}
#[cfg(lp_wdt)]
Peripheral::Wdt => {
system.timergroup0_wdt_clk_conf
system
.timergroup0_wdt_clk_conf
.write(|w| w.tg0_wdt_clk_en().set_bit());
system.timergroup0_wdt_clk_conf
.write(|w| unsafe { w.tg0_wdt_clk_sel().bits(1) });
system
.timergroup0_wdt_clk_conf
.write(|w| unsafe { w.tg0_wdt_clk_sel().bits(1) });

system.timergroup1_timer_clk_conf
system
.timergroup1_timer_clk_conf
.write(|w| w.tg1_timer_clk_en().set_bit());
system.timergroup1_timer_clk_conf
system
.timergroup1_timer_clk_conf
.write(|w| unsafe { w.tg1_timer_clk_sel().bits(1) });
}
Peripheral::Sha => {
system.sha_conf.modify(|_, w| w.sha_clk_en().set_bit());
system.sha_conf.modify(|_, w| w.sha_rst_en().clear_bit());
}
Peripheral::UsbDevice => {
system.usb_device_conf.modify(|_, w| w.usb_device_clk_en().set_bit());
system.usb_device_conf.modify(|_, w| w.usb_device_rst_en().clear_bit());
system
.usb_device_conf
.modify(|_, w| w.usb_device_clk_en().set_bit());
system
.usb_device_conf
.modify(|_, w| w.usb_device_rst_en().clear_bit());
}
Peripheral::Uart0 => {
system.uart0_conf.modify(|_, w| w.uart0_clk_en().set_bit());
system.uart0_conf.modify(|_, w| w.uart0_rst_en().clear_bit());
system
.uart0_conf
.modify(|_, w| w.uart0_rst_en().clear_bit());
}
Peripheral::Uart1 => {
system.uart1_conf.modify(|_, w| w.uart1_clk_en().set_bit());
system.uart1_conf.modify(|_, w| w.uart1_rst_en().clear_bit());
system
.uart1_conf
.modify(|_, w| w.uart1_rst_en().clear_bit());
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions esp-hal-common/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ impl<'d, T> TimerGroup<'d, T>
where
T: TimerGroupInstance,
{
pub fn new(timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks, peripheral_clock_control: &mut PeripheralClockControl) -> Self {
pub fn new(
timer_group: impl Peripheral<P = T> + 'd,
clocks: &Clocks,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
crate::into_ref!(timer_group);

let timer0 = Timer::new(
Timer0 {
phantom: PhantomData::default(),
},
clocks.apb_clock,
peripheral_clock_control
peripheral_clock_control,
);

#[cfg(not(any(esp32c2, esp32c3, esp32c6)))]
Expand All @@ -82,7 +86,7 @@ where
phantom: PhantomData::default(),
},
clocks.apb_clock,
peripheral_clock_control
peripheral_clock_control,
);

let wdt = Wdt::new(peripheral_clock_control);
Expand All @@ -109,7 +113,11 @@ where
T: Instance,
{
/// Create a new timer instance
pub fn new(timg: T, apb_clk_freq: HertzU32, peripheral_clock_control: &mut PeripheralClockControl) -> Self {
pub fn new(
timg: T,
apb_clk_freq: HertzU32,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
// TODO: this currently assumes APB_CLK is being used, as we don't yet have a
// way to select the XTAL_CLK.
timg.enable_peripheral(peripheral_clock_control);
Expand Down
5 changes: 4 additions & 1 deletion esp-hal-common/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ where
}

/// Create a new UART instance with defaults
pub fn new(uart: impl Peripheral<P = T> + 'd, peripheral_clock_control: &mut PeripheralClockControl) -> Self {
pub fn new(
uart: impl Peripheral<P = T> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
crate::into_ref!(uart);
uart.enable_peripheral(peripheral_clock_control);
let mut serial = Uart { uart };
Expand Down
5 changes: 4 additions & 1 deletion esp-hal-common/src/usb_serial_jtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ where
T: Instance,
{
/// Create a new USB serial/JTAG instance with defaults
pub fn new(usb_serial: impl Peripheral<P = T> + 'd, peripheral_clock_control: &mut PeripheralClockControl) -> Self {
pub fn new(
usb_serial: impl Peripheral<P = T> + 'd,
peripheral_clock_control: &mut PeripheralClockControl,
) -> Self {
crate::into_ref!(usb_serial);
// #[cfg(usb_device)]
peripheral_clock_control.enable(crate::system::Peripheral::Sha);
Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

Expand Down
14 changes: 12 additions & 2 deletions esp32-hal/examples/advanced_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

Expand All @@ -51,7 +55,13 @@ fn main() -> ! {
io.pins.gpio17.into_floating_input(),
);

let mut serial1 = Uart::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks, &mut system.peripheral_clock_control);
let mut serial1 = Uart::new_with_config(
peripherals.UART1,
Some(config),
Some(pins),
&clocks,
&mut system.peripheral_clock_control,
);

let mut delay = Delay::new(&clocks);

Expand Down
12 changes: 10 additions & 2 deletions esp32-hal/examples/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ fn main() -> ! {

// Disable the RTC and TIMG watchdog timers
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks, &mut system.peripheral_clock_control);
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;

rtc.rwdt.disable();
Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/blinky_erased_pins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

Expand Down
12 changes: 10 additions & 2 deletions esp32-hal/examples/embassy_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks, &mut system.peripheral_clock_control);
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;

// Disable watchdog timers
Expand Down
12 changes: 10 additions & 2 deletions esp32-hal/examples/embassy_spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,17 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks, &mut system.peripheral_clock_control);
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;

// Disable watchdog timers
Expand Down
12 changes: 10 additions & 2 deletions esp32-hal/examples/embassy_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks, &mut system.peripheral_clock_control);
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;

// Disable watchdog timers
Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/gpio_interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;

let mut rtc = Rtc::new(peripherals.RTC_CNTL);
Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/hello_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);

Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut timer0 = timer_group0.timer0;
let mut wdt = timer_group0.wdt;
let mut serial0 = Uart::new(peripherals.UART0, &mut system.peripheral_clock_control);
Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/i2c_bmp180_calibration_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);

Expand Down
6 changes: 5 additions & 1 deletion esp32-hal/examples/i2c_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ fn main() -> ! {
let mut system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks, &mut system.peripheral_clock_control);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut timer0 = timer_group0.timer0;
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
Expand Down
Loading

0 comments on commit 619772c

Please sign in to comment.