-
Notifications
You must be signed in to change notification settings - Fork 31
Adding support for rp235x-hal #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d1a90e4
80474b6
85553cc
a5f6dd5
c5f8e26
055722e
268f664
bc4a674
5cfde66
56ee557
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing for the user: Adding |
||||
| } | ||||
|
|
||||
| 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( | ||||
|
|
@@ -54,6 +68,7 @@ use smart_leds_trait_0_2::SmartLedsWrite as SmartLedsWrite02; | |||
| /// delay_for_at_least_60_microseconds(); | ||||
| /// }; | ||||
| ///``` | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clippy complains about this empty line:
Suggested change
|
||||
| pub struct Ws2812Direct<P, SM, I> | ||||
| where | ||||
| I: AnyPin<Function = P::PinFunction>, | ||||
|
|
@@ -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(); | ||||
|
|
||||
|
|
@@ -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); | ||||
| /// | ||||
|
|
@@ -237,6 +252,7 @@ where | |||
| /// // Do other stuff here... | ||||
| /// }; | ||||
| ///``` | ||||
|
|
||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here:
Suggested change
|
||||
| pub struct Ws2812<P, SM, C, I> | ||||
| where | ||||
| C: CountDown, | ||||
|
|
@@ -268,7 +284,6 @@ where | |||
| Self { driver, cd } | ||||
| } | ||||
| } | ||||
|
|
||||
| impl<P, SM, I, C> SmartLedsWrite for Ws2812<P, SM, C, I> | ||||
| where | ||||
| C: CountDown, | ||||
|
|
@@ -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, | ||||
|
|
||||
There was a problem hiding this comment.
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 bethumbv8m.main-none-eabihf,thumbv8m.main-none-eabiorriscv32imac-unknown-none-elf.