Skip to content

Commit

Permalink
Merge pull request #28 from rp-rs/hal-0.9
Browse files Browse the repository at this point in the history
Use rp2040-hal version 0.9.0 & bump version to 0.7.0
  • Loading branch information
jannic authored Sep 1, 2023
2 parents 0b0dbb0 + fa78c84 commit 944494c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ws2812-pio"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
license = "Apache-2.0"
description = "Driver implementation for the WS2812 smart LED using the RP2040's PIO peripheral."
Expand All @@ -10,11 +10,8 @@ repository = "https://github.com/rp-rs/ws2812-pio-rs/"
[dependencies]
embedded-hal = "0.2.5"
fugit = "0.3.5"
rp2040-hal = "0.8.0"
rp2040-hal = "0.9.0"
pio = "0.2.0"
smart-leds-trait = "0.2.1"
nb = "1.0.0"
cortex-m = "0.7.3"

[patch.crates-io]
rp2040-hal = { git = "https://github.com/ithinuel/rp-hal" }
55 changes: 27 additions & 28 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
//! Bear in mind that you will have to take care of timing requirements
//! yourself then.

use cortex_m;
use embedded_hal::timer::CountDown;
use fugit::{ExtU32, HertzU32};
use fugit::{ExtU32, HertzU32, MicrosDurationU32};
use rp2040_hal::{
gpio::{Function, FunctionConfig, Pin, PinId, ValidPinMode},
gpio::AnyPin,
pio::{PIOExt, StateMachineIndex, Tx, UninitStateMachine, PIO},
};
use smart_leds_trait::SmartLedsWrite;
Expand Down Expand Up @@ -56,25 +55,23 @@ use smart_leds_trait::SmartLedsWrite;
///```
pub struct Ws2812Direct<P, SM, I>
where
I: PinId,
P: PIOExt + FunctionConfig,
Function<P>: ValidPinMode<I>,
I: AnyPin<Function = P::PinFunction>,
P: PIOExt,
SM: StateMachineIndex,
{
tx: Tx<(P, SM)>,
_pin: Pin<I, Function<P>>,
_pin: I,
}

impl<P, SM, I> Ws2812Direct<P, SM, I>
where
I: PinId,
P: PIOExt + FunctionConfig,
Function<P>: ValidPinMode<I>,
I: AnyPin<Function = P::PinFunction>,
P: PIOExt,
SM: StateMachineIndex,
{
/// Creates a new instance of this driver.
pub fn new(
pin: Pin<I, Function<P>>,
pin: I,
pio: &mut PIO<P>,
sm: UninitStateMachine<(P, SM)>,
clock_freq: fugit::HertzU32,
Expand Down Expand Up @@ -127,11 +124,12 @@ where
let int: u16 = int as u16;
let frac: u8 = frac as u8;

let pin = pin.into();
let (mut sm, _, tx) = rp2040_hal::pio::PIOBuilder::from_program(installed)
// only use TX FIFO
.buffers(rp2040_hal::pio::Buffers::OnlyTx)
// Pin configuration
.side_set_pin_base(I::DYN.num)
.side_set_pin_base(pin.id().num)
// OSR config
.out_shift_direction(rp2040_hal::pio::ShiftDirection::Left)
.autopull(true)
Expand All @@ -140,19 +138,21 @@ where
.build(sm);

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

sm.start();

Self { tx, _pin: pin }
Self {
tx,
_pin: I::from(pin),
}
}
}

impl<P, SM, I> SmartLedsWrite for Ws2812Direct<P, SM, I>
where
I: PinId,
P: PIOExt + FunctionConfig,
Function<P>: ValidPinMode<I>,
I: AnyPin<Function = P::PinFunction>,
P: PIOExt,
SM: StateMachineIndex,
{
type Color = smart_leds_trait::RGB8;
Expand Down Expand Up @@ -214,10 +214,9 @@ where
///```
pub struct Ws2812<P, SM, C, I>
where
I: PinId,
C: CountDown,
P: PIOExt + FunctionConfig,
Function<P>: ValidPinMode<I>,
I: AnyPin<Function = P::PinFunction>,
P: PIOExt,
SM: StateMachineIndex,
{
driver: Ws2812Direct<P, SM, I>,
Expand All @@ -226,15 +225,14 @@ where

impl<P, SM, C, I> Ws2812<P, SM, C, I>
where
I: PinId,
C: CountDown,
P: PIOExt + FunctionConfig,
Function<P>: ValidPinMode<I>,
I: AnyPin<Function = P::PinFunction>,
P: PIOExt,
SM: StateMachineIndex,
{
/// Creates a new instance of this driver.
pub fn new(
pin: Pin<I, Function<P>>,
pin: I,
pio: &mut PIO<P>,
sm: UninitStateMachine<(P, SM)>,
clock_freq: fugit::HertzU32,
Expand All @@ -246,11 +244,12 @@ where
}
}

impl<'timer, P, SM, I> SmartLedsWrite for Ws2812<P, SM, rp2040_hal::timer::CountDown<'timer>, I>
impl<P, SM, I, C> SmartLedsWrite for Ws2812<P, SM, C, I>
where
I: PinId,
P: PIOExt + FunctionConfig,
Function<P>: ValidPinMode<I>,
C: CountDown,
C::Time: From<MicrosDurationU32>,
I: AnyPin<Function = P::PinFunction>,
P: PIOExt,
SM: StateMachineIndex,
{
type Color = smart_leds_trait::RGB8;
Expand Down

0 comments on commit 944494c

Please sign in to comment.