diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f41a9c2..38b2694 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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"] diff --git a/.gitignore b/.gitignore index 96ef6c0..77147e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target Cargo.lock +.idea/ diff --git a/Cargo.toml b/Cargo.toml index 6e8abe5..ef2aa47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/lib.rs b/src/lib.rs index 75ad292..d042fb6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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."); + } +} + +use hal::{ gpio::AnyPin, pio::{PIOExt, StateMachineIndex, Tx, UninitStateMachine, PIO}, }; + use smart_leds_trait::SmartLedsWrite; use smart_leds_trait_0_2::SmartLedsWrite as SmartLedsWrite02; @@ -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( @@ -126,20 +140,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(); @@ -213,9 +227,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); /// @@ -268,7 +282,6 @@ where Self { driver, cd } } } - impl
SmartLedsWrite for Ws2812
where C: CountDown, @@ -293,7 +306,6 @@ where SmartLedsWrite::write(&mut self.driver, iterator) } } - impl
SmartLedsWrite02 for Ws2812
where C: CountDown,