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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ authors = ["Paul Sajna <[email protected]>"]
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"
13 changes: 6 additions & 7 deletions examples/rainbow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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) {
Expand All @@ -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();
Expand Down
29 changes: 16 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#![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<P: OutputPin> {
pin: P,
}

impl<P: OutputPin> Ws2812<P> {
pub fn new(pin: P) -> Ws2812<P> {
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);
Expand All @@ -35,15 +35,18 @@ impl<P> SmartLedsWrite for Ws2812<P>
where
P: OutputPin,
{
type Color = RGB8;
type Error = ();
fn write<T>(&mut self, iterator: T) -> Result<(), ()>
fn write<T, I>(&mut self, iterator: T) -> Result<(), ()>
where
T: Iterator<Item = Color>,
T: Iterator<Item = I>,
I: Into<Self::Color>,
{
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(())
}
Expand Down