Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and Test check
jobs:
builds:
name: Build checks
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
strategy:
matrix:
mode: ["", "--release"]
Expand Down
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ documentation = "https://docs.rs/ws2812-pio"
repository = "https://github.com/rp-rs/ws2812-pio-rs/"

[dependencies]
cfg-if = "1.0"
embedded-hal = "0.2.5"
fugit = "0.3.5"
rp2040-hal = "0.11"
pio = "0.2.0"
smart-leds-trait = "0.3"
smart-leds-trait-0-2 = { package = "smart-leds-trait", version = "0.2.1" }
nb = "1.0.0"
cortex-m = "0.7.3"
rp2040-hal = { version = "0.11.0", optional = true }
rp235x-hal = { version = "0.3.0", optional = true }

[features]
default = ["rp2040"]
rp2040 = ["dep:rp2040-hal"]
rp235x = ["dep:rp235x-hal"]
Comment on lines +22 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't try it and there may be obstacles, but it could be an alternative to select the right dependencies automatically based on the compile target using platform specific dependencies.

rp2040 should always be thumbv6m-none-eabi, and rp235x may be thumbv8m.main-none-eabihf, thumbv8m.main-none-eabi or riscv32imac-unknown-none-elf.

36 changes: 25 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,24 @@

use embedded_hal::timer::CountDown;
use fugit::{ExtU32, HertzU32, MicrosDurationU32};
use rp2040_hal::{

use cfg_if::cfg_if;

cfg_if! {
if #[cfg(feature = "rp2040")] {
use rp2040_hal as hal;
} else if #[cfg(feature = "rp235x")] {
use rp235x_hal as hal;
} else {
compile_error!("Either 'rp2040' or 'rp235x' feature must be enabled.");
}
Comment on lines +22 to +28
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit confusing for the user: Adding --feature rp235x without also adding --no-default-features doesn't actually enable rp235x support.
I wonder if there's a better alternative. Maybe at least catch the situation where both features are enabled and throw a compile error with a nice explanation? Or make --feature rp235x implicitly disable rp2040 support? (Which could be implemented by switching the order of the two if branches.)

}

use hal::{
gpio::AnyPin,
pio::{PIOExt, StateMachineIndex, Tx, UninitStateMachine, PIO},
};

use smart_leds_trait::SmartLedsWrite;
use smart_leds_trait_0_2::SmartLedsWrite as SmartLedsWrite02;

Expand All @@ -33,9 +47,9 @@ use smart_leds_trait_0_2::SmartLedsWrite as SmartLedsWrite02;
///
/// Typical usage example:
///```ignore
/// use rp2040_hal::clocks::init_clocks_and_plls;
/// use hal::clocks::init_clocks_and_plls;
/// let clocks = init_clocks_and_plls(...);
/// let pins = rp2040_hal::gpio::pin::bank0::Pins::new(...);
/// let pins = hal::gpio::pin::bank0::Pins::new(...);
///
/// let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
/// let mut ws = Ws2812Direct::new(
Expand All @@ -54,6 +68,7 @@ use smart_leds_trait_0_2::SmartLedsWrite as SmartLedsWrite02;
/// delay_for_at_least_60_microseconds();
/// };
///```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clippy complains about this empty line:

warning: empty line after doc comment
  --> src/lib.rs:70:1
   |
70 | / ///```
71 | |
   | |_^
72 |   pub struct Ws2812Direct<P, SM, I>
   |   ----------------------- the comment documents this struct
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#empty_line_after_doc_comments
   = note: `#[warn(clippy::empty_line_after_doc_comments)]` on by default
   = help: if the empty line is unintentional, remove it
Suggested change

pub struct Ws2812Direct<P, SM, I>
where
I: AnyPin<Function = P::PinFunction>,
Expand Down Expand Up @@ -126,20 +141,20 @@ where
let frac: u8 = frac as u8;

let pin = pin.into();
let (mut sm, _, tx) = rp2040_hal::pio::PIOBuilder::from_installed_program(installed)
let (mut sm, _, tx) = hal::pio::PIOBuilder::from_installed_program(installed)
// only use TX FIFO
.buffers(rp2040_hal::pio::Buffers::OnlyTx)
.buffers(hal::pio::Buffers::OnlyTx)
// Pin configuration
.side_set_pin_base(pin.id().num)
// OSR config
.out_shift_direction(rp2040_hal::pio::ShiftDirection::Left)
.out_shift_direction(hal::pio::ShiftDirection::Left)
.autopull(true)
.pull_threshold(24)
.clock_divisor_fixed_point(int, frac)
.build(sm);

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

sm.start();

Expand Down Expand Up @@ -213,9 +228,9 @@ where
///
/// Typical usage example:
///```ignore
/// use rp2040_hal::clocks::init_clocks_and_plls;
/// use hal::clocks::init_clocks_and_plls;
/// let clocks = init_clocks_and_plls(...);
/// let pins = rp2040_hal::gpio::pin::bank0::Pins::new(...);
/// let pins = hal::gpio::pin::bank0::Pins::new(...);
///
/// let timer = Timer::new(pac.TIMER, &mut pac.RESETS);
///
Expand All @@ -237,6 +252,7 @@ where
/// // Do other stuff here...
/// };
///```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here:

warning: empty line after doc comment
   --> src/lib.rs:254:1
    |
254 | / ///```
255 | |
    | |_^
256 |   pub struct Ws2812<P, SM, C, I>
    |   ----------------- the comment documents this struct
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#empty_line_after_doc_comments
    = help: if the empty line is unintentional, remove it

Suggested change

pub struct Ws2812<P, SM, C, I>
where
C: CountDown,
Expand Down Expand Up @@ -268,7 +284,6 @@ where
Self { driver, cd }
}
}

impl<P, SM, I, C> SmartLedsWrite for Ws2812<P, SM, C, I>
where
C: CountDown,
Expand All @@ -293,7 +308,6 @@ where
SmartLedsWrite::write(&mut self.driver, iterator)
}
}

impl<P, SM, I, C> SmartLedsWrite02 for Ws2812<P, SM, C, I>
where
C: CountDown,
Expand Down
Loading