1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//! A device abstraction for buttons with debouncing and press duration detection.
//!
//! This module provides two ways to monitor button presses:
//!
//! - [`ButtonRp`] — Simple button monitoring. Each call to `wait_for_press()`, etc. starts fresh
//! button monitoring.
//! - [`button_watch!`](crate::button_watch!) — Monitors a button in a background task
//! so that it works even in a fast loop/select.
//!
// Must be public for macro expansion in downstream crates, but not user-facing API.
pub use ;
// Must be public for macro expansion in downstream crates, but not user-facing API.
pub use button_watch_task;
pub use __ButtonMonitor;
pub use Button;
pub use ;
// Public for compatibility; hidden from end-user docs.
pub use ;
use Peri;
use ;
// ============================================================================
// Button Virtual Device
// ============================================================================
/// A device abstraction for a button with debouncing and press duration detection.
///
/// # Hardware Requirements
///
/// The button can be wired in two ways:
/// - [`PressedTo::Voltage`]: Button connects pin to 3.3V when pressed (uses pull-down)
/// - [`PressedTo::Ground`]: Button connects pin to GND when pressed (uses pull-up)
///
/// **Important**: Pico 2 (RP2350) has a known silicon bug (erratum E9) with pull-down
/// resistors that can leave the pin reading HIGH after release. Wire buttons to GND and
/// use [`PressedTo::Ground`] on Pico 2.
///
/// # Usage
///
/// Use [`Button::wait_for_press`] when you only need a debounced
/// press event. It returns on the down edge and does not wait for release.
///
/// Use [`Button::wait_for_press_duration`] when you need to
/// distinguish short vs. long presses. It returns as soon as it can decide, so long
/// presses are reported before the button is released.
///
/// # Example
///
/// ```rust,no_run
/// # #![no_std]
/// # #![no_main]
///
/// use device_envoy_rp::button::{Button as _, ButtonRp, PressDuration, PressedTo};
/// # #[panic_handler]
/// # fn panic(_info: &core::panic::PanicInfo) -> ! { loop {} }
///
/// async fn example(p: embassy_rp::Peripherals) {
/// let mut button = ButtonRp::new(p.PIN_13, PressedTo::Ground);
///
/// // Wait for a press without measuring duration.
/// button.wait_for_press().await;
///
/// // Measure press durations in a loop
/// loop {
/// match button.wait_for_press_duration().await {
/// PressDuration::Short => {
/// // Handle short press
/// }
/// PressDuration::Long => {
/// // Handle long press (fires before button is released)
/// }
/// }
/// }
/// }
/// ```
pub use cratebutton_watch;