Skip to content

Commit

Permalink
fixing nits
Browse files Browse the repository at this point in the history
will squash later
  • Loading branch information
oyvindnetland committed Sep 6, 2023
1 parent 9520127 commit 7295d01
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//! code.
//!
//! Deep sleep is similar to light sleep, but the CPU is also powered down. Only RTC and
//! possibly ULP co processor is running. When woking up, the CPU does not keep its state,
//! possibly ULP coprocessor is running. When woking up, the CPU does not keep its state,
//! and the program starts from the beginning.
//!
//! When enter either light or deep sleep, one or more wakeup sources must be enabled.
//! When entering either light or deep sleep, one or more wakeup sources must be enabled.
//! In this driver, the various wakeup sources are defined as different structs, which
//! can be added to a light or deep sleep struct. This struct can then be used to perform
//! a sleep operation with the given wakeup sources.
Expand Down Expand Up @@ -37,11 +37,11 @@ pub struct TimerWakeup {
}

impl TimerWakeup {
pub fn new(duration: Duration) -> Self {
pub const fn new(duration: Duration) -> Self {
Self { duration }
}

pub fn apply(&self) -> Result<(), EspError> {
fn apply(&self) -> Result<(), EspError> {
esp!(unsafe { esp_sleep_enable_timer_wakeup(self.duration.as_micros() as u64) })?;
Ok(())
}
Expand All @@ -59,7 +59,7 @@ pub struct RtcWakeup<'a> {

#[cfg(any(esp32, esp32s2, esp32s3))]
impl<'a> RtcWakeup<'a> {
pub fn new(pins: &'a [RtcWakeupPin], wake_level: RtcWakeLevel) -> Self {
pub const fn new(pins: &'a [RtcWakeupPin], wake_level: RtcWakeLevel) -> Self {
Self { pins, wake_level }
}
}
Expand All @@ -74,7 +74,7 @@ impl<'a> RtcWakeup<'a> {
m
}

pub fn apply(&self) -> Result<(), EspError> {
fn apply(&self) -> Result<(), EspError> {
#[cfg(any(esp32, esp32s3))]
for pin in self.pins {
if pin.pullup || pin.pulldown {
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<'a> fmt::Debug for RtcWakeup<'a> {
}

#[cfg(any(esp32, esp32s2, esp32s3))]
#[derive(Debug)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum RtcWakeLevel {
AllLow,
AnyHigh,
Expand All @@ -146,7 +146,7 @@ pub struct RtcWakeupPin {

#[cfg(any(esp32, esp32s2, esp32s3))]
impl RtcWakeupPin {
pub fn new(pin: AnyInputPin, pullup: bool, pulldown: bool) -> Self {
pub const fn new(pin: AnyInputPin, pullup: bool, pulldown: bool) -> Self {
Self {
pin,
pullup,
Expand Down Expand Up @@ -177,13 +177,13 @@ pub struct GpioWakeup<'a> {
}

impl<'a> GpioWakeup<'a> {
pub fn new(pins: &'a [GpioWakeupPin<'a>]) -> Self {
pub const fn new(pins: &'a [GpioWakeupPin<'a>]) -> Self {
Self { pins }
}
}

impl<'a> GpioWakeup<'a> {
pub fn apply(&self) -> Result<(), EspError> {
fn apply(&self) -> Result<(), EspError> {
for pin in self.pins.iter() {
let intr_level = match pin.wake_level {
Level::Low => gpio_int_type_t_GPIO_INTR_LOW_LEVEL,
Expand All @@ -202,7 +202,7 @@ pub struct GpioWakeupPin<'a> {
}

impl<'a> GpioWakeupPin<'a> {
pub fn new(
pub const fn new(
pin: PinDriver<'a, AnyInputPin, Input>,
wake_level: Level,
) -> Result<Self, EspError> {
Expand All @@ -229,11 +229,11 @@ pub struct UartWakeup<'a> {
}

impl<'a> UartWakeup<'a> {
pub fn new(uart: &'a UartDriver<'a>, threshold: i32) -> Self {
pub const fn new(uart: &'a UartDriver<'a>, threshold: i32) -> Self {
Self { uart, threshold }
}

pub fn apply(&self) -> Result<(), EspError> {
fn apply(&self) -> Result<(), EspError> {
esp!(unsafe { uart_set_wakeup_threshold(self.uart.port(), self.threshold) })?;
esp!(unsafe { esp_sleep_enable_uart_wakeup(self.uart.port()) })?;
Ok(())
Expand All @@ -249,11 +249,11 @@ impl<'a> fmt::Debug for UartWakeup<'a> {
/// Will wake up the CPU when a touchpad is touched.
#[cfg(any(esp32, esp32s2, esp32s3))]
#[derive(Debug)]
pub struct TouchWakeup {}
pub struct TouchWakeup;

#[cfg(any(esp32, esp32s2, esp32s3))]
impl TouchWakeup {
pub fn apply(&self) -> Result<(), EspError> {
fn apply(&self) -> Result<(), EspError> {
esp!(unsafe { esp_sleep_enable_touchpad_wakeup() })?;
Ok(())
}
Expand All @@ -262,11 +262,11 @@ impl TouchWakeup {
/// Will let the ULP co-processor wake up the CPU. Requires that the ULP is started.
#[cfg(any(esp32, esp32s2, esp32s3))]
#[derive(Debug)]
pub struct UlpWakeup {}
pub struct UlpWakeup;

#[cfg(any(esp32, esp32s2, esp32s3))]
impl UlpWakeup {
pub fn apply(&self) -> Result<(), EspError> {
fn apply(&self) -> Result<(), EspError> {
esp!(unsafe { esp_sleep_enable_ulp_wakeup() })?;
Ok(())
}
Expand Down

0 comments on commit 7295d01

Please sign in to comment.