Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 237 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/rt685s-evk/src/bin/power_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async fn main(spawner: Spawner) {
// Create a power button instance
let button_a = Input::new(p.PIO1_1, Pull::Up, Inverter::Disabled);
// Create a debouncer instance
let debouncer = Debouncer::new(3, Duration::from_millis(10), ActiveState::ActiveLow);
let debouncer = Debouncer::new(3, 10, ActiveState::ActiveLow);
// Create a custom button configuration instance
let config_a = ButtonConfig::new(debouncer, Duration::from_millis(1000), Duration::from_millis(2000));

Expand Down
4 changes: 4 additions & 0 deletions power-button-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ embassy-time.workspace = true
embedded-hal-async.workspace = true
embedded-hal.workspace = true
log = { workspace = true, optional = true }

[dev-dependencies]
embedded-hal-mock = { version = "0.11.1", features = ["eh1", "embedded-hal-async"] }
tokio = { version = "1.45.0", features = ["rt", "macros"] }
6 changes: 4 additions & 2 deletions power-button-service/src/button.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Button Service Definitions

use embassy_time::{with_timeout, Duration, Instant, TimeoutError, Timer};
use embassy_time::{with_timeout, Delay, Duration, Instant, TimeoutError, Timer};
use embedded_hal::digital::InputPin;
use embedded_hal_async::digital::Wait;

Expand Down Expand Up @@ -48,7 +48,9 @@ impl<I: InputPin + Wait> Button<I> {

/// Checks button state.
pub async fn get_button_state(&mut self) -> ButtonState {
match self.config.debouncer.debounce(&mut self.gpio).await {
let mut delay = Delay;

match self.config.debouncer.debounce(&mut self.gpio, &mut delay).await {
true => ButtonState::ButtonPressed(Instant::now()),
false => ButtonState::ButtonReleased(Instant::now()),
}
Expand Down
Loading