-
Notifications
You must be signed in to change notification settings - Fork 8
Description
I'm using a teensy 4.1 and when using a small sketch with fastled it works but when using this library to control the same hardware setup it does not work. Below is the rough code that I used. I'm using and older version of this library tho as the newer one doesn't compile due to dependency version mismatch – however I have tried just copying the current code of the library and adapting it to the older traits and it still didn't work.
let resources = t41(cx.device);
let lpspi4: board::Lpspi4 = board::lpspi(
resources.lpspi4,
board::LpspiPins {
sdo: resources.pins.p11,
sdi: resources.pins.p12,
sck: resources.pins.p13,
pcs0: resources.pins.p10,
},
4_000_000,
);
let apa102_writer = apa102_spi::Apa102::new_with_options(lpspi4, 4, false, apa102_spi::PixelOrder::BGR);
apa102_writer.write([RGB8::new(255, 0, 0)].into_iter()).unwrap();I hope I just switched up two pins or something different.
Here is also the most simple code that I recreated after this library which also doesn't work but might help debug some things
use cortex_m::prelude::_embedded_hal_blocking_spi_Write;
use teensy4_bsp::board::Lpspi4;
#[derive(Clone, Copy)]
pub struct Pixel {
red: u8,
green: u8,
blue: u8,
brightness: u8,
}
const MAX_BRIGHTNESS: u8 = 0x1F;
impl Pixel {
pub fn new(red: u8, green: u8, blue: u8, mut brightness: u8) -> Self {
// Only 5 bits are allowed for brightness control
if MAX_BRIGHTNESS < brightness {
log::debug!("Brightness value {brightness} exceeds 5 bits (31+)");
brightness = MAX_BRIGHTNESS;
}
Self {
red,
green,
blue,
brightness,
}
}
pub fn to_words(self) -> [u8; 4] {
const BASE_FIRST_BYTE: u8 = 0b1110_0000;
const BRIGHTNESS_MODULATOR: u8 = 0b0010_0000;
[
BASE_FIRST_BYTE + self.brightness % BRIGHTNESS_MODULATOR,
self.blue,
self.green,
self.red,
]
}
}
pub struct LedWriter {
spi: Lpspi4,
number_leds: usize,
end_frame_length_bytes: usize,
}
impl LedWriter {
pub fn new(spi: Lpspi4, number_leds: usize) -> Self {
let end_frame_length_bytes = number_leds.div_ceil(16).max(4);
Self {
spi,
number_leds,
end_frame_length_bytes,
}
}
/// Check out https://cpldcpu.com/2014/11/30/understanding-the-apa102-superled/ for more information
pub fn write(&mut self, mut buffer: &[Pixel]) {
if self.number_leds < buffer.len() {
log::debug!("Exceeded amount of leds to write");
buffer = &buffer[0..self.number_leds];
}
const ZERO: u8 = 0x00;
const START_FRAME: &[u8] = &[ZERO, ZERO, ZERO, ZERO];
self.spi.write(START_FRAME).unwrap();
for pixel in buffer {
self.spi.write(&pixel.to_words()).unwrap();
}
for _ in 0..self.end_frame_length_bytes {
self.spi.write(&[u8::MAX]).unwrap();
}
}
}These are the crates I use:
[dependencies]
rtic = { version = "2", features = ["thumbv7-backend"] }
rtic-monotonics = { version = "1", default-features = false, features = [
"cortex-m-systick",
] }
imxrt-log = { version = "0.1", default-features = false, features = [
"log",
"usbd",
] }
log = { version = "0.4", features = [
"max_level_debug",
"release_max_level_off",
] }
teensy4-panic = { version = "0.2", features = ["log"] }
teensy4-bsp = { version = "0.5", features = ["rt"] }
nb = "1.1.0"
cortex-m = "0.7.7"
apa102-spi = { path = "apa102-spi-rs" }
smart-leds-trait = "0.2"And this is the git commit I checked out for this library to make it compile 1ca02fd (version 0.3.2)
Thank you a lot in advance for helping.