diff --git a/Cargo.toml b/Cargo.toml index eb9e0fd..b3b25aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,16 +5,16 @@ authors = ["Paul Sajna "] edition = "2018" [dependencies] -smart-leds-trait = "~0.1" -cortex-m = "~0.5" +smart-leds-trait = "~0.2" +cortex-m = "~0.6" [dependencies.embedded-hal] features = ["unproven"] version = "0.2.1" [dev-dependencies] -atsamd-hal = "~0.4" -metro_m4 = "~0.1" -cortex-m-rt = "~0.6" +atsamd-hal = "~0.7" +metro_m4 = "0.4.0" +cortex-m-rt = "~0.6" panic-halt = "~0.2" -smart-leds = "~0.1" +smart-leds = "~0.2" diff --git a/examples/rainbow.rs b/examples/rainbow.rs index acd93bf..ae96738 100644 --- a/examples/rainbow.rs +++ b/examples/rainbow.rs @@ -2,20 +2,19 @@ #![no_main] extern crate cortex_m; -extern crate panic_halt; extern crate metro_m4 as hal; +extern crate panic_halt; extern crate ws2812_nop_samd51 as ws2812; - +use cortex_m_rt::entry; use hal::clock::GenericClockController; use hal::delay::Delay; +use hal::pac::{CorePeripherals, Peripherals}; use hal::prelude::*; -use hal::{CorePeripherals, Peripherals}; -use cortex_m_rt::entry; use smart_leds::brightness; -use smart_leds::Color; use smart_leds::SmartLedsWrite; +use smart_leds::RGB8; use ws2812::Ws2812; #[entry] @@ -35,7 +34,7 @@ fn main() -> ! { let mut neopixel = Ws2812::new(neopixel_pin); const NUM_LEDS: usize = 1; - let mut data = [Color::default(); NUM_LEDS]; + let mut data = [RGB8::default(); NUM_LEDS]; loop { for j in 0..(256 * 5) { @@ -52,7 +51,7 @@ fn main() -> ! { /// Input a value 0 to 255 to get a color value /// The colours are a transition r - g - b - back to r. -fn wheel(mut wheel_pos: u8) -> Color { +fn wheel(mut wheel_pos: u8) -> RGB8 { wheel_pos = 255 - wheel_pos; if wheel_pos < 85 { return (255 - wheel_pos * 3, 0, wheel_pos * 3).into(); diff --git a/src/lib.rs b/src/lib.rs index 737bb18..116d377 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ #![no_std] use cortex_m::asm::delay; -use embedded_hal::digital::OutputPin; -use smart_leds_trait::{Color, SmartLedsWrite}; +use embedded_hal::digital::v2::OutputPin; +use smart_leds_trait::{SmartLedsWrite, RGB8}; pub struct Ws2812 { pin: P, @@ -10,19 +10,19 @@ pub struct Ws2812 { impl Ws2812

{ pub fn new(pin: P) -> Ws2812

{ - Ws2812 { pin: pin } + Ws2812 { pin } } fn write_byte(&mut self, data: u8) { let mut bitmask: u8 = 0x80; while bitmask != 0 { - self.pin.set_high(); + let _ = self.pin.set_high(); delay(2); if data & bitmask != 0 { - delay(3); - self.pin.set_low(); + delay(3); + let _ = self.pin.set_low(); } else { - self.pin.set_low(); - delay(2); + let _ = self.pin.set_low(); + delay(2); } bitmask >>= 1; delay(4); @@ -35,15 +35,18 @@ impl

SmartLedsWrite for Ws2812

where P: OutputPin, { + type Color = RGB8; type Error = (); - fn write(&mut self, iterator: T) -> Result<(), ()> + fn write(&mut self, iterator: T) -> Result<(), ()> where - T: Iterator, + T: Iterator, + I: Into, { for item in iterator { - self.write_byte(item.g); - self.write_byte(item.r); - self.write_byte(item.b); + let color: Self::Color = item.into(); + self.write_byte(color.g); + self.write_byte(color.r); + self.write_byte(color.b); } Ok(()) }