Skip to content

Commit 7295d01

Browse files
committed
fixing nits
will squash later
1 parent 9520127 commit 7295d01

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/sleep.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//! code.
77
//!
88
//! Deep sleep is similar to light sleep, but the CPU is also powered down. Only RTC and
9-
//! possibly ULP co processor is running. When woking up, the CPU does not keep its state,
9+
//! possibly ULP coprocessor is running. When woking up, the CPU does not keep its state,
1010
//! and the program starts from the beginning.
1111
//!
12-
//! When enter either light or deep sleep, one or more wakeup sources must be enabled.
12+
//! When entering either light or deep sleep, one or more wakeup sources must be enabled.
1313
//! In this driver, the various wakeup sources are defined as different structs, which
1414
//! can be added to a light or deep sleep struct. This struct can then be used to perform
1515
//! a sleep operation with the given wakeup sources.
@@ -37,11 +37,11 @@ pub struct TimerWakeup {
3737
}
3838

3939
impl TimerWakeup {
40-
pub fn new(duration: Duration) -> Self {
40+
pub const fn new(duration: Duration) -> Self {
4141
Self { duration }
4242
}
4343

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

6060
#[cfg(any(esp32, esp32s2, esp32s3))]
6161
impl<'a> RtcWakeup<'a> {
62-
pub fn new(pins: &'a [RtcWakeupPin], wake_level: RtcWakeLevel) -> Self {
62+
pub const fn new(pins: &'a [RtcWakeupPin], wake_level: RtcWakeLevel) -> Self {
6363
Self { pins, wake_level }
6464
}
6565
}
@@ -74,7 +74,7 @@ impl<'a> RtcWakeup<'a> {
7474
m
7575
}
7676

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

123123
#[cfg(any(esp32, esp32s2, esp32s3))]
124-
#[derive(Debug)]
124+
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
125125
pub enum RtcWakeLevel {
126126
AllLow,
127127
AnyHigh,
@@ -146,7 +146,7 @@ pub struct RtcWakeupPin {
146146

147147
#[cfg(any(esp32, esp32s2, esp32s3))]
148148
impl RtcWakeupPin {
149-
pub fn new(pin: AnyInputPin, pullup: bool, pulldown: bool) -> Self {
149+
pub const fn new(pin: AnyInputPin, pullup: bool, pulldown: bool) -> Self {
150150
Self {
151151
pin,
152152
pullup,
@@ -177,13 +177,13 @@ pub struct GpioWakeup<'a> {
177177
}
178178

179179
impl<'a> GpioWakeup<'a> {
180-
pub fn new(pins: &'a [GpioWakeupPin<'a>]) -> Self {
180+
pub const fn new(pins: &'a [GpioWakeupPin<'a>]) -> Self {
181181
Self { pins }
182182
}
183183
}
184184

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

204204
impl<'a> GpioWakeupPin<'a> {
205-
pub fn new(
205+
pub const fn new(
206206
pin: PinDriver<'a, AnyInputPin, Input>,
207207
wake_level: Level,
208208
) -> Result<Self, EspError> {
@@ -229,11 +229,11 @@ pub struct UartWakeup<'a> {
229229
}
230230

231231
impl<'a> UartWakeup<'a> {
232-
pub fn new(uart: &'a UartDriver<'a>, threshold: i32) -> Self {
232+
pub const fn new(uart: &'a UartDriver<'a>, threshold: i32) -> Self {
233233
Self { uart, threshold }
234234
}
235235

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

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

267267
#[cfg(any(esp32, esp32s2, esp32s3))]
268268
impl UlpWakeup {
269-
pub fn apply(&self) -> Result<(), EspError> {
269+
fn apply(&self) -> Result<(), EspError> {
270270
esp!(unsafe { esp_sleep_enable_ulp_wakeup() })?;
271271
Ok(())
272272
}

0 commit comments

Comments
 (0)