smart-leds-rs / apa102-spi-rs

SPI-based Driver for apa102 leds
Apache License 2.0
7 stars 5 forks source link

Can't get working with adafruit itsybitsy nrf52840 #10

Closed dzfranklin closed 2 years ago

dzfranklin commented 2 years ago

I'm trying to use the built-in DotStar led on the Adafruit ItsyBitsy nrf52840. I've confirmed on the pinout that it is an Apa102.

I initialize like so.

let port0 = hal::gpio::p0::Parts::new(cx.device.P0);
let port1 = hal::gpio::p1::Parts::new(cx.device.P1);

// Setup builtin dotstar led
let dotstar_pins = spi::Pins {
    // Pin numbers from <https://blog.adafruit.com/2021/05/26/pin-reference-adafruit-itsybitsy-nrf52840-prettypins/>
    sck: port1.p1_09.into_push_pull_output(Level::High).degrade(),
    mosi: Some(port0.p0_08.into_push_pull_output(Level::High).degrade()),
    miso: None,
};

let dotstar_spi = Spi::new(
    cx.device.SPI0,
    dotstar_pins,
    spi0::frequency::FREQUENCY_A::K125,
    apa102_spi::MODE,
);
// Not inverting end frame b/c adafruit does something similar in their bsp for other boards
// See <https://github.com/atsamd-rs/atsamd/blob/9495af975d6a35ae8bb455fae29ad0356fe20e09/boards/trinket_m0/src/lib.rs#L155>
let dotstar = Apa102::new_with_custom_postamble(dotstar_spi, 4, false);

I've tried varying the frequency and invert_end_frame. I'm running in release mode.

Here's how I try to actually set the led

cx.shared.dotstar.lock(|dotstar| {
    dotstar.write([RGB8::new(0, 0, 64)].into_iter()).unwrap();
});

This results in no visible change.

david-sawatzke commented 2 years ago

Your code doesn't look obviously wrong. I don't have an itsybitsy nrf52840 or something similar at hand, but the trinket m0 also has an apa102 led onboard.

https://github.com/smart-leds-rs/smart-leds-samples/blob/master/trinket-m0-examples/examples/trinket_apa102_onboard_blink.rs is an example for the trinket m0 with a very similar apa102 using the bitbang_hal. You could try adapting it to the nrf52 to find out if there's an issue with using the nrf52 spi peripheral together with this crate or if something else is wrong.

dzfranklin commented 2 years ago

Thanks! That's the code I based my attempt off of. I'm going to go with a different design that doesn't require this.