Skip to content

Commit b1eddb1

Browse files
authored
Merge pull request #25 from ithinuel/experiment-gpio-overhaul
Update to use the overhauled GPIO API
2 parents 2e85ade + 4120506 commit b1eddb1

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository = "https://github.com/rp-rs/ws2812-pio-rs/"
1010
[dependencies]
1111
embedded-hal = "0.2.5"
1212
fugit = "0.3.5"
13-
rp2040-hal = "0.9.0"
13+
rp2040-hal = "0.9.0-alpha.1"
1414
pio = "0.2.0"
1515
smart-leds-trait = "0.2.1"
1616
nb = "1.0.0"

src/lib.rs

+20-25
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use cortex_m;
1717
use embedded_hal::timer::CountDown;
1818
use fugit::{ExtU32, HertzU32};
1919
use rp2040_hal::{
20-
gpio::{Function, FunctionConfig, Pin, PinId, ValidPinMode},
20+
gpio::AnyPin,
2121
pio::{PIOExt, StateMachineIndex, Tx, UninitStateMachine, PIO},
2222
};
2323
use smart_leds_trait::SmartLedsWrite;
@@ -56,25 +56,23 @@ use smart_leds_trait::SmartLedsWrite;
5656
///```
5757
pub struct Ws2812Direct<P, SM, I>
5858
where
59-
I: PinId,
60-
P: PIOExt + FunctionConfig,
61-
Function<P>: ValidPinMode<I>,
59+
I: AnyPin<Function = P::PinFunction>,
60+
P: PIOExt,
6261
SM: StateMachineIndex,
6362
{
6463
tx: Tx<(P, SM)>,
65-
_pin: Pin<I, Function<P>>,
64+
_pin: I,
6665
}
6766

6867
impl<P, SM, I> Ws2812Direct<P, SM, I>
6968
where
70-
I: PinId,
71-
P: PIOExt + FunctionConfig,
72-
Function<P>: ValidPinMode<I>,
69+
I: AnyPin<Function = P::PinFunction>,
70+
P: PIOExt,
7371
SM: StateMachineIndex,
7472
{
7573
/// Creates a new instance of this driver.
7674
pub fn new(
77-
pin: Pin<I, Function<P>>,
75+
pin: I,
7876
pio: &mut PIO<P>,
7977
sm: UninitStateMachine<(P, SM)>,
8078
clock_freq: fugit::HertzU32,
@@ -127,11 +125,12 @@ where
127125
let int: u16 = int as u16;
128126
let frac: u8 = frac as u8;
129127

128+
let pin = pin.into();
130129
let (mut sm, _, tx) = rp2040_hal::pio::PIOBuilder::from_program(installed)
131130
// only use TX FIFO
132131
.buffers(rp2040_hal::pio::Buffers::OnlyTx)
133132
// Pin configuration
134-
.side_set_pin_base(I::DYN.num)
133+
.side_set_pin_base(pin.id().num)
135134
// OSR config
136135
.out_shift_direction(rp2040_hal::pio::ShiftDirection::Left)
137136
.autopull(true)
@@ -140,19 +139,18 @@ where
140139
.build(sm);
141140

142141
// Prepare pin's direction.
143-
sm.set_pindirs([(I::DYN.num, rp2040_hal::pio::PinDir::Output)]);
142+
sm.set_pindirs([(pin.id().num, rp2040_hal::pio::PinDir::Output)]);
144143

145144
sm.start();
146145

147-
Self { tx, _pin: pin }
146+
Self { tx, _pin: I::from(pin) }
148147
}
149148
}
150149

151150
impl<P, SM, I> SmartLedsWrite for Ws2812Direct<P, SM, I>
152151
where
153-
I: PinId,
154-
P: PIOExt + FunctionConfig,
155-
Function<P>: ValidPinMode<I>,
152+
I: AnyPin<Function = P::PinFunction>,
153+
P: PIOExt,
156154
SM: StateMachineIndex,
157155
{
158156
type Color = smart_leds_trait::RGB8;
@@ -214,10 +212,9 @@ where
214212
///```
215213
pub struct Ws2812<P, SM, C, I>
216214
where
217-
I: PinId,
218215
C: CountDown,
219-
P: PIOExt + FunctionConfig,
220-
Function<P>: ValidPinMode<I>,
216+
I: AnyPin<Function = P::PinFunction>,
217+
P: PIOExt,
221218
SM: StateMachineIndex,
222219
{
223220
driver: Ws2812Direct<P, SM, I>,
@@ -226,15 +223,14 @@ where
226223

227224
impl<P, SM, C, I> Ws2812<P, SM, C, I>
228225
where
229-
I: PinId,
230226
C: CountDown,
231-
P: PIOExt + FunctionConfig,
232-
Function<P>: ValidPinMode<I>,
227+
I: AnyPin<Function = P::PinFunction>,
228+
P: PIOExt,
233229
SM: StateMachineIndex,
234230
{
235231
/// Creates a new instance of this driver.
236232
pub fn new(
237-
pin: Pin<I, Function<P>>,
233+
pin: I,
238234
pio: &mut PIO<P>,
239235
sm: UninitStateMachine<(P, SM)>,
240236
clock_freq: fugit::HertzU32,
@@ -248,9 +244,8 @@ where
248244

249245
impl<'timer, P, SM, I> SmartLedsWrite for Ws2812<P, SM, rp2040_hal::timer::CountDown<'timer>, I>
250246
where
251-
I: PinId,
252-
P: PIOExt + FunctionConfig,
253-
Function<P>: ValidPinMode<I>,
247+
I: AnyPin<Function = P::PinFunction>,
248+
P: PIOExt,
254249
SM: StateMachineIndex,
255250
{
256251
type Color = smart_leds_trait::RGB8;

0 commit comments

Comments
 (0)