smart-leds-rs / ws2812-spi-rs

Use ws2812 on rust with embedded-hal spi
Apache License 2.0
64 stars 23 forks source link

Use embedded_hal::blocking::spi::Write instead of FullDuplex #28

Closed andy31415 closed 2 months ago

andy31415 commented 2 years ago

Issue description

Trying to compile the stm32f0 examples results in an error because embedded_hal::spi::FullDuplex is not implemented for SPI on stm32f0xx_hal:

error[E0277]: the trait bound `Spi<stm32f0xx_hal::pac::SPI1, stm32f0xx_hal::gpio::gpioa::PA5<Alternate<stm32f0xx_hal::gpio::AF0>>, stm32f0xx_hal::gpio::gpioa::PA6<Alternate<stm32f0xx_hal::gpio::AF0>>, stm32f0xx_hal::gpio::gpioa::PA7<Alternate<stm32f0xx_hal::gpio::AF0>>, EightBit>: _embedded_hal_spi_FullDuplex<u8>` is not satisfied
  --> examples/stm32f0_ws2812_spi_blink.rs:54:34
   |
54 |         let mut ws = Ws2812::new(spi);
   |                      ----------- ^^^ the trait `_embedded_hal_spi_FullDuplex<u8>` is not implemented for `Spi<stm32f0xx_hal::pac::SPI1, stm32f0xx_hal::gpio::gpioa::PA5<Alternate<stm32f0xx_hal::gpio::AF0>>, stm32f0xx_hal::gpio::gpioa::PA6<Alternate<stm32f0xx_hal::gpio::AF0>>, stm32f0xx_hal::gpio::gpioa::PA7<Alternate<stm32f0xx_hal::gpio::AF0>>, EightBit>`
   |                      |
   |                      required by a bound introduced by this call
   |
note: required by a bound in `ws2812_spi::Ws2812::<SPI>::new`
  --> /home/andrei/.cargo/registry/src/github.com-1ecc6299db9ec823/ws2812-spi-0.4.0/src/lib.rs:49:10
   |
49 |     SPI: FullDuplex<u8, Error = E>,
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ws2812_spi::Ws2812::<SPI>::new`

However embedded_hal::blocking::spi::Write is implemented. This implementation should be available for all FullDuplex implementations:

https://docs.rs/embedded-hal/latest/embedded_hal/blocking/spi/write/trait.Default.html

Testing

Compiled and ran examples on a STM32F030C8Tx, observed LED examples worked well. Compiled other targets and observed compilation finished (did not run, however this seems to confirm that Write trait is implemented where previously FullDuplex was provided).

david-sawatzke commented 2 months ago

This isn't a distinction offered by e-h 1.0.0 anymore