Find a timing that works with WS2815

This commit is contained in:
Tangent 128 2019-06-13 20:23:35 -04:00
parent 5821dbffb5
commit 2aab355fff
2 changed files with 41 additions and 9 deletions

View file

@ -0,0 +1,26 @@
#![no_std]
#![no_main]
use core::iter::repeat;
use lights::{
gamma::GammaCorrector,
PixelIterator,
rgb::{
gray
}
};
use lights_hal::{boot, delay, entry};
#[entry]
fn main() -> ! {
let mut lights = GammaCorrector(boot());
let mut pattern = repeat(gray(0)).take(15).chain(repeat(gray(255)).take(15)).cycle();
loop {
pattern.clone().take(125).render_to(&mut lights);
pattern.next();
delay(1_000_000);
}
}

View file

@ -31,27 +31,33 @@ pub fn boot() -> impl Lights<Pixel = HardwareRgb> {
let mut pins = hal::Pins::new(peripherals.PORT);
NeopixelLights {
out: pins.d7.into_push_pull_output(&mut pins.port)
out: pins.d7.into_push_pull_output(&mut pins.port),
high_out: pins.d5.into_push_pull_output(&mut pins.port),
}
}
// WS2815 lighting times
// approx. 20ns per clock cycle;
const ZERO_HIGH_CYCLES: u32 = 11; // smidge above 200ns
const ZERO_HIGH_CYCLES: u32 = 8; // about 160ns
const ZERO_LOW_CYCLES: u32 = 42; // about 840ns
const ONE_HIGH_CYCLES: u32 = 35; // about 700ns
const DATA_LOW_CYCLES: u32 = 25; // about 500ns
const LATCH_CYCLES: u32 = 300; // about 6000ns
const ONE_LOW_CYCLES: u32 = 15; // about 300ns
const LATCH_CYCLES: u32 = 15000; // about 300us
pub struct NeopixelLights<T: OutputPin> {
out: T
pub struct NeopixelLights<T: OutputPin, U: OutputPin> {
out: T,
high_out: U
}
impl<T: OutputPin> NeopixelLights<T> {
impl<T: OutputPin, U: OutputPin> NeopixelLights<T, U> {
#[inline]
fn write(&mut self, bit: bool) {
self.out.set_high();
self.high_out.set_high();
delay(if bit { ONE_HIGH_CYCLES } else { ZERO_HIGH_CYCLES });
self.out.set_low();
delay(DATA_LOW_CYCLES);
self.high_out.set_low();
delay(if bit { ONE_LOW_CYCLES } else { ZERO_LOW_CYCLES });
}
#[inline]
@ -67,7 +73,7 @@ impl<T: OutputPin> NeopixelLights<T> {
}
}
impl<T: OutputPin> Lights for NeopixelLights<T> {
impl<T: OutputPin, U: OutputPin> Lights for NeopixelLights<T, U> {
type Pixel = HardwareRgb;
#[inline]