Skip to content

Commit 944494c

Browse files
authored
Merge pull request #28 from rp-rs/hal-0.9
Use rp2040-hal version 0.9.0 & bump version to 0.7.0
2 parents 0b0dbb0 + fa78c84 commit 944494c

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ws2812-pio"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "Driver implementation for the WS2812 smart LED using the RP2040's PIO peripheral."
@@ -10,11 +10,8 @@ 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.8.0"
13+
rp2040-hal = "0.9.0"
1414
pio = "0.2.0"
1515
smart-leds-trait = "0.2.1"
1616
nb = "1.0.0"
1717
cortex-m = "0.7.3"
18-
19-
[patch.crates-io]
20-
rp2040-hal = { git = "https://github.com/ithinuel/rp-hal" }

src/lib.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
//! Bear in mind that you will have to take care of timing requirements
1414
//! yourself then.
1515
16-
use cortex_m;
1716
use embedded_hal::timer::CountDown;
18-
use fugit::{ExtU32, HertzU32};
17+
use fugit::{ExtU32, HertzU32, MicrosDurationU32};
1918
use rp2040_hal::{
20-
gpio::{Function, FunctionConfig, Pin, PinId, ValidPinMode},
19+
gpio::AnyPin,
2120
pio::{PIOExt, StateMachineIndex, Tx, UninitStateMachine, PIO},
2221
};
2322
use smart_leds_trait::SmartLedsWrite;
@@ -56,25 +55,23 @@ use smart_leds_trait::SmartLedsWrite;
5655
///```
5756
pub struct Ws2812Direct<P, SM, I>
5857
where
59-
I: PinId,
60-
P: PIOExt + FunctionConfig,
61-
Function<P>: ValidPinMode<I>,
58+
I: AnyPin<Function = P::PinFunction>,
59+
P: PIOExt,
6260
SM: StateMachineIndex,
6361
{
6462
tx: Tx<(P, SM)>,
65-
_pin: Pin<I, Function<P>>,
63+
_pin: I,
6664
}
6765

6866
impl<P, SM, I> Ws2812Direct<P, SM, I>
6967
where
70-
I: PinId,
71-
P: PIOExt + FunctionConfig,
72-
Function<P>: ValidPinMode<I>,
68+
I: AnyPin<Function = P::PinFunction>,
69+
P: PIOExt,
7370
SM: StateMachineIndex,
7471
{
7572
/// Creates a new instance of this driver.
7673
pub fn new(
77-
pin: Pin<I, Function<P>>,
74+
pin: I,
7875
pio: &mut PIO<P>,
7976
sm: UninitStateMachine<(P, SM)>,
8077
clock_freq: fugit::HertzU32,
@@ -127,11 +124,12 @@ where
127124
let int: u16 = int as u16;
128125
let frac: u8 = frac as u8;
129126

127+
let pin = pin.into();
130128
let (mut sm, _, tx) = rp2040_hal::pio::PIOBuilder::from_program(installed)
131129
// only use TX FIFO
132130
.buffers(rp2040_hal::pio::Buffers::OnlyTx)
133131
// Pin configuration
134-
.side_set_pin_base(I::DYN.num)
132+
.side_set_pin_base(pin.id().num)
135133
// OSR config
136134
.out_shift_direction(rp2040_hal::pio::ShiftDirection::Left)
137135
.autopull(true)
@@ -140,19 +138,21 @@ where
140138
.build(sm);
141139

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

145143
sm.start();
146144

147-
Self { tx, _pin: pin }
145+
Self {
146+
tx,
147+
_pin: I::from(pin),
148+
}
148149
}
149150
}
150151

151152
impl<P, SM, I> SmartLedsWrite for Ws2812Direct<P, SM, I>
152153
where
153-
I: PinId,
154-
P: PIOExt + FunctionConfig,
155-
Function<P>: ValidPinMode<I>,
154+
I: AnyPin<Function = P::PinFunction>,
155+
P: PIOExt,
156156
SM: StateMachineIndex,
157157
{
158158
type Color = smart_leds_trait::RGB8;
@@ -214,10 +214,9 @@ where
214214
///```
215215
pub struct Ws2812<P, SM, C, I>
216216
where
217-
I: PinId,
218217
C: CountDown,
219-
P: PIOExt + FunctionConfig,
220-
Function<P>: ValidPinMode<I>,
218+
I: AnyPin<Function = P::PinFunction>,
219+
P: PIOExt,
221220
SM: StateMachineIndex,
222221
{
223222
driver: Ws2812Direct<P, SM, I>,
@@ -226,15 +225,14 @@ where
226225

227226
impl<P, SM, C, I> Ws2812<P, SM, C, I>
228227
where
229-
I: PinId,
230228
C: CountDown,
231-
P: PIOExt + FunctionConfig,
232-
Function<P>: ValidPinMode<I>,
229+
I: AnyPin<Function = P::PinFunction>,
230+
P: PIOExt,
233231
SM: StateMachineIndex,
234232
{
235233
/// Creates a new instance of this driver.
236234
pub fn new(
237-
pin: Pin<I, Function<P>>,
235+
pin: I,
238236
pio: &mut PIO<P>,
239237
sm: UninitStateMachine<(P, SM)>,
240238
clock_freq: fugit::HertzU32,
@@ -246,11 +244,12 @@ where
246244
}
247245
}
248246

249-
impl<'timer, P, SM, I> SmartLedsWrite for Ws2812<P, SM, rp2040_hal::timer::CountDown<'timer>, I>
247+
impl<P, SM, I, C> SmartLedsWrite for Ws2812<P, SM, C, I>
250248
where
251-
I: PinId,
252-
P: PIOExt + FunctionConfig,
253-
Function<P>: ValidPinMode<I>,
249+
C: CountDown,
250+
C::Time: From<MicrosDurationU32>,
251+
I: AnyPin<Function = P::PinFunction>,
252+
P: PIOExt,
254253
SM: StateMachineIndex,
255254
{
256255
type Color = smart_leds_trait::RGB8;

0 commit comments

Comments
 (0)