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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
//! A device abstraction for a 4-digit, 7-segment LED display for text with optional animation and blinking.
//!
//! See [`Led4Rp`] for the primary text/blinking example and [`Led4`] for trait methods.
//!
//! **Limations**: You can create up to two concurrent `Led4Rp` instances per program; a third is expected to fail at runtime because the `led4` task pool uses `pool_size = 2`. Animation APIs support up to 16 steps per animation (`ANIMATION_MAX_FRAMES`).
//!
//! This module provides device abstraction for controlling common-cathode
//! 4-digit 7-segment LED displays. Supports displaying text and numbers with
//! optional blinking.
use Spawner;
use crate::;
use ;
use info;
// ============================================================================
// Led4Simple Submodule (internal helper)
// ============================================================================
pub
use ;
// ============================================================================
// OutputArray Submodule
// ============================================================================
pub use ;
pub use OutputArray;
/// Frame buffer type used by led4 text animations.
pub type Animation = Animation;
/// Creates a circular outline animation that chases around display edges.
// ============================================================================
// Constants
// ============================================================================
/// The number of cells (digits) in the display.
pub const CELL_COUNT_U8: u8 = 4;
pub const CELL_COUNT: usize = CELL_COUNT_U8 as usize;
/// The number of segments per digit in the display.
pub const SEGMENT_COUNT: usize = 8;
// ============================================================================
// Led4 Virtual Device
// ============================================================================
/// A device abstraction for a 4-digit, 7-segment LED display with blinking support.
///
/// # Hardware Requirements
///
/// This abstraction is designed for common-cathode 7-segment displays where:
/// - Cell pins control which digit is active (LOW = on, HIGH = off)
/// - Segment pins control which segments light up (HIGH = on, LOW = off)
///
/// # Example
///
/// ```rust,no_run
/// # #![no_std]
/// # #![no_main]
/// # use core::future::pending;
/// use embassy_time::{Duration, Timer};
/// use device_envoy_rp::{Error, led4::{BlinkState, Led4 as _, Led4Rp, Led4RpStatic, OutputArray, circular_outline_animation}};
/// # #[panic_handler]
/// # fn panic(_info: &core::panic::PanicInfo) -> ! { loop {} }
///
/// async fn example(p: embassy_rp::Peripherals, spawner: embassy_executor::Spawner) -> Result<(), Error> {
/// // Set up cell pins (control which digit is active)
/// let cells = OutputArray::new([
/// embassy_rp::gpio::Output::new(p.PIN_1, embassy_rp::gpio::Level::High),
/// embassy_rp::gpio::Output::new(p.PIN_2, embassy_rp::gpio::Level::High),
/// embassy_rp::gpio::Output::new(p.PIN_3, embassy_rp::gpio::Level::High),
/// embassy_rp::gpio::Output::new(p.PIN_4, embassy_rp::gpio::Level::High),
/// ]);
///
/// // Set up segment pins (control which segments light up)
/// let segments = OutputArray::new([
/// embassy_rp::gpio::Output::new(p.PIN_5, embassy_rp::gpio::Level::Low), // Segment A
/// embassy_rp::gpio::Output::new(p.PIN_6, embassy_rp::gpio::Level::Low), // Segment B
/// embassy_rp::gpio::Output::new(p.PIN_7, embassy_rp::gpio::Level::Low), // Segment C
/// embassy_rp::gpio::Output::new(p.PIN_8, embassy_rp::gpio::Level::Low), // Segment D
/// embassy_rp::gpio::Output::new(p.PIN_9, embassy_rp::gpio::Level::Low), // Segment E
/// embassy_rp::gpio::Output::new(p.PIN_10, embassy_rp::gpio::Level::Low), // Segment F
/// embassy_rp::gpio::Output::new(p.PIN_11, embassy_rp::gpio::Level::Low), // Segment G
/// embassy_rp::gpio::Output::new(p.PIN_12, embassy_rp::gpio::Level::Low), // Decimal point
/// ]);
///
/// // Create the display
/// static LED4_STATIC: Led4RpStatic = Led4Rp::new_static();
/// let display = Led4Rp::new(&LED4_STATIC, cells, segments, spawner)?;
///
/// // Blink "1234" for three seconds.
/// display.write_text(['1', '2', '3', '4'], BlinkState::BlinkingAndOn);
/// Timer::after(Duration::from_secs(3)).await;
///
/// // Run the circular outline animation for three seconds.
/// display.animate_text(circular_outline_animation(true));
/// Timer::after(Duration::from_secs(3)).await;
///
/// // Show "rUSt" solid forever.
/// display.write_text(['r', 'U', 'S', 't'], BlinkState::Solid);
/// pending().await
/// }
/// ```
///
/// Beyond simple text, the driver can loop animations via [`Led4::animate_text`].
/// The struct owns the background task and signal wiring; create it once with
/// [`Led4Rp::new`] and use the returned handle for all display updates.
;
/// Signal for sending display commands to the [`Led4Rp`] device.
pub type Led4RpOuterStatic = Led4CommandSignal;
/// Static for the [`Led4Rp`] device.
async !