Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with esp-idf-hal #21

Open
weiying-chen opened this issue Jul 5, 2024 · 1 comment
Open

Compatibility with esp-idf-hal #21

weiying-chen opened this issue Jul 5, 2024 · 1 comment

Comments

@weiying-chen
Copy link

I created this based on the STM32 example:

use anyhow::Result;
use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::spi::{config::Config, SpiDeviceDriver, SpiDriver, SpiDriverConfig, SPI2};
use esp_idf_svc::log::EspLogger;
use esp_idf_sys::{self as _};
use log::info;
use smart_leds::{SmartLedsWrite, RGB8};
use ws2812_spi::Ws2812;

fn main() -> Result<()> {
    esp_idf_svc::sys::link_patches();
    EspLogger::initialize_default();

    let peripherals = Peripherals::take()?;
    let spi = peripherals.spi2;

    let sclk = peripherals.pins.gpio6; // SCLK
    let miso = peripherals.pins.gpio4; // MISO
    let mosi = peripherals.pins.gpio7; // MOSI
    let cs = peripherals.pins.gpio10; // Chip Select (unused for LED control)

    println!("Starting WS2812 LED control");

    let driver = SpiDriver::new::<SPI2>(spi, sclk, mosi, Some(miso), &SpiDriverConfig::new())?;

    // WS2812 requires a specific SPI configuration
    let config = Config::new().baudrate(3_000_000.into());
    let mut spi_device = SpiDeviceDriver::new(&driver, Some(cs), &config)?;

    let mut ws = Ws2812::new(spi_device);
    let mut delay = FreeRtos;

    // Data arrays for LED colors
    let mut data: [RGB8; 3] = [RGB8::default(); 3];
    let empty: [RGB8; 3] = [RGB8::default(); 3];

    loop {
        data[0] = RGB8 {
            r: 0,
            g: 0,
            b: 0x10,
        }; // Blue
        data[1] = RGB8 {
            r: 0,
            g: 0x10,
            b: 0,
        }; // Green
        data[2] = RGB8 {
            r: 0x10,
            g: 0,
            b: 0,
        }; // Red

        // Write color data to the LEDs
        ws.write(data.iter().cloned()).unwrap();
        delay.delay_ms(1000);

        // Turn off LEDs
        ws.write(empty.iter().cloned()).unwrap();
        delay.delay_ms(1000);
    }
}

However, I get the following error:

the trait bound `SpiDeviceDriver<'_, &SpiDriver<'_>>: embedded_hal::spi::FullDuplex<u8>` is not satisfied
the trait `embedded_hal::spi::FullDuplex<u8>` is not implemented for `SpiDeviceDriver<'_, &SpiDriver<'_>>`
@sajattack
Copy link
Collaborator

I think the issue is due to embedded-hal 1.0 versus 0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants