From a9cf53a001b6a0a237d3d1bda01153ec8a1b4eef Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Mon, 10 Jan 2022 10:21:40 -0800 Subject: [PATCH] Clean up imports/exports, normalize/update examples --- esp32-hal/examples/blinky.rs | 8 +++--- .../examples/{serial.rs => hello_world.rs} | 6 +++-- esp32-hal/src/gpio.rs | 4 +-- esp32-hal/src/lib.rs | 4 ++- esp32c3-hal/examples/blinky.rs | 8 +++--- .../examples/{serial.rs => hello_world.rs} | 9 ++++--- esp32c3-hal/examples/serial_echo.rs | 25 ------------------- esp32c3-hal/src/gpio.rs | 4 +-- esp32c3-hal/src/lib.rs | 7 +++--- 9 files changed, 26 insertions(+), 49 deletions(-) rename esp32-hal/examples/{serial.rs => hello_world.rs} (74%) rename esp32c3-hal/examples/{serial.rs => hello_world.rs} (70%) delete mode 100644 esp32c3-hal/examples/serial_echo.rs diff --git a/esp32-hal/examples/blinky.rs b/esp32-hal/examples/blinky.rs index d12d92f72..04a0fac92 100644 --- a/esp32-hal/examples/blinky.rs +++ b/esp32-hal/examples/blinky.rs @@ -1,23 +1,23 @@ #![no_std] #![no_main] -use esp32_hal::{gpio::IO, pac, prelude::*, Timer}; +use esp32_hal::{gpio::IO, pac::Peripherals, prelude::*, Timer}; use nb::block; use panic_halt as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = pac::Peripherals::take().unwrap(); + let peripherals = Peripherals::take().unwrap(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + let mut led = io.pins.gpio15.into_push_pull_output(); let mut timer0 = Timer::new(peripherals.TIMG0); + // Disable watchdog timer timer0.disable(); - let mut led = io.pins.gpio15.into_push_pull_output(); led.set_high().unwrap(); - timer0.start(10_000_000u64); loop { diff --git a/esp32-hal/examples/serial.rs b/esp32-hal/examples/hello_world.rs similarity index 74% rename from esp32-hal/examples/serial.rs rename to esp32-hal/examples/hello_world.rs index 103178120..3171bf247 100644 --- a/esp32-hal/examples/serial.rs +++ b/esp32-hal/examples/hello_world.rs @@ -3,19 +3,21 @@ use core::fmt::Write; -use esp32_hal::{pac, prelude::*, Serial, Timer}; +use esp32_hal::{pac::Peripherals, prelude::*, Serial, Timer}; use nb::block; use panic_halt as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = pac::Peripherals::take().unwrap(); + let peripherals = Peripherals::take().unwrap(); let mut timer0 = Timer::new(peripherals.TIMG0); let mut serial0 = Serial::new(peripherals.UART0).unwrap(); + // Disable watchdog timer timer0.disable(); + timer0.start(10_000_000u64); loop { diff --git a/esp32-hal/src/gpio.rs b/esp32-hal/src/gpio.rs index ac9b3066a..18f93681a 100644 --- a/esp32-hal/src/gpio.rs +++ b/esp32-hal/src/gpio.rs @@ -1,6 +1,4 @@ -use esp_hal_common::gpio::gpio; - -use crate::hal_gpio::*; +use esp_hal_common::gpio::*; type OutputSignalType = u16; const OUTPUT_SIGNAL_MAX: u16 = 548; diff --git a/esp32-hal/src/lib.rs b/esp32-hal/src/lib.rs index 5acbee4f9..d87d17d67 100644 --- a/esp32-hal/src/lib.rs +++ b/esp32-hal/src/lib.rs @@ -1,7 +1,9 @@ #![no_std] pub use embedded_hal as ehal; -pub use esp_hal_common::{gpio as hal_gpio, pac, prelude, Serial, Timer}; +pub use esp_hal_common::{pac, prelude, Serial, Timer}; + +pub use self::gpio::IO; pub mod gpio; diff --git a/esp32c3-hal/examples/blinky.rs b/esp32c3-hal/examples/blinky.rs index 4bf842497..f48cd7ec9 100644 --- a/esp32c3-hal/examples/blinky.rs +++ b/esp32c3-hal/examples/blinky.rs @@ -1,28 +1,28 @@ #![no_std] #![no_main] -use esp32c3_hal::{gpio::IO, pac, prelude::*, RtcCntl, Timer}; +use esp32c3_hal::{gpio::IO, pac::Peripherals, prelude::*, RtcCntl, Timer}; use nb::block; use panic_halt as _; use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = pac::Peripherals::take().unwrap(); + let peripherals = Peripherals::take().unwrap(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + let mut led = io.pins.gpio5.into_push_pull_output(); let rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL); let mut timer0 = Timer::new(peripherals.TIMG0); let mut timer1 = Timer::new(peripherals.TIMG1); + // Disable watchdog timers rtc_cntl.set_super_wdt_enable(false); rtc_cntl.set_wdt_enable(false); timer0.disable(); timer1.disable(); - let mut led = io.pins.gpio5.into_push_pull_output(); led.set_high().unwrap(); - timer0.start(10_000_000u64); loop { diff --git a/esp32c3-hal/examples/serial.rs b/esp32c3-hal/examples/hello_world.rs similarity index 70% rename from esp32c3-hal/examples/serial.rs rename to esp32c3-hal/examples/hello_world.rs index 963f0eb95..e38ebaaf3 100644 --- a/esp32c3-hal/examples/serial.rs +++ b/esp32c3-hal/examples/hello_world.rs @@ -3,22 +3,25 @@ use core::fmt::Write; -use esp32c3_hal::{pac, prelude::*, RtcCntl, Serial, Timer}; +use esp32c3_hal::{pac::Peripherals, prelude::*, RtcCntl, Serial, Timer}; use nb::block; use panic_halt as _; use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = pac::Peripherals::take().unwrap(); + let peripherals = Peripherals::take().unwrap(); let rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL); - let mut timer0 = Timer::new(peripherals.TIMG0); let mut serial0 = Serial::new(peripherals.UART0).unwrap(); + let mut timer0 = Timer::new(peripherals.TIMG0); + let mut timer1 = Timer::new(peripherals.TIMG1); + // Disable watchdog timers rtc_cntl.set_super_wdt_enable(false); rtc_cntl.set_wdt_enable(false); timer0.disable(); + timer1.disable(); timer0.start(10_000_000u64); diff --git a/esp32c3-hal/examples/serial_echo.rs b/esp32c3-hal/examples/serial_echo.rs deleted file mode 100644 index 0eb32bcec..000000000 --- a/esp32c3-hal/examples/serial_echo.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![no_std] -#![no_main] - -use esp32c3_hal::{pac, prelude::*, RtcCntl, Serial, Timer}; -use nb::block; -use panic_halt as _; -use riscv_rt::entry; - -#[entry] -fn main() -> ! { - let peripherals = pac::Peripherals::take().unwrap(); - - let rtccntl = RtcCntl::new(peripherals.RTC_CNTL); - let mut serial0 = Serial::new(peripherals.UART0).unwrap(); - let mut timer0 = Timer::new(peripherals.TIMG0); - - rtccntl.set_super_wdt_enable(false); - rtccntl.set_wdt_enable(false); - timer0.disable(); - - loop { - let byte = block!(serial0.read()).unwrap(); - block!(serial0.write(byte)).unwrap(); - } -} diff --git a/esp32c3-hal/src/gpio.rs b/esp32c3-hal/src/gpio.rs index af82e9c76..8971eec27 100644 --- a/esp32c3-hal/src/gpio.rs +++ b/esp32c3-hal/src/gpio.rs @@ -1,6 +1,4 @@ -use esp_hal_common::gpio::gpio; - -use crate::hal_gpio::*; +use esp_hal_common::gpio::*; type OutputSignalType = u8; const OUTPUT_SIGNAL_MAX: u8 = 128; diff --git a/esp32c3-hal/src/lib.rs b/esp32c3-hal/src/lib.rs index e9edbce5d..159df9618 100644 --- a/esp32c3-hal/src/lib.rs +++ b/esp32c3-hal/src/lib.rs @@ -1,10 +1,9 @@ #![no_std] pub use embedded_hal as ehal; -pub use esp_hal_common::{gpio as hal_gpio, pac, prelude, Serial, Timer}; - -pub mod rtc_cntl; +pub use esp_hal_common::{pac, prelude, Serial, Timer}; pub mod gpio; +pub mod rtc_cntl; -pub use rtc_cntl::RtcCntl; +pub use self::{gpio::IO, rtc_cntl::RtcCntl};