esp-rs / std-training

Embedded Rust on Espressif training material.

Home Page:https://esp-rs.github.io/std-training

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'None' cannot be used for the 'Option' type in 'SpiDeviceDriver::new_single()'

xiaguangbo opened this issue · comments

code:

use esp_idf_svc::hal::delay::*;
use esp_idf_svc::hal::gpio::*;
use esp_idf_svc::hal::peripheral::*;
use esp_idf_svc::hal::spi::*;

pub struct Max31865<'a> {
    spi: SpiDeviceDriver<'a, SpiDriver<'a>>,
    delay: Delay,
}

impl<'a> Max31865<'a> {
    pub fn new<SPI, CLK, MOSI, MISO>(spi: SPI, clk: CLK, mosi: MOSI, miso: MISO) -> Self
    where
        SPI: Peripheral<P = SPI> + SpiAnyPins + 'a,
        CLK: Peripheral<P = CLK> + OutputPin,
        MOSI: Peripheral<P = MOSI> + OutputPin,
        MISO: Peripheral<P = MISO> + InputPin,
    {
        let config = config::Config::default().data_mode(config::MODE_3);
        let spi = SpiDeviceDriver::new_single(
            spi,
            clk,
            mosi,
            Some(miso),
            None, // Can't I use 'None'?
            &SpiDriverConfig::new(),
            &config,
        )
        .unwrap();

        Self {
            spi,
            delay: Delay::new_default(),
        }
    }
}

err:

xiaguangbo@debian:/media/xiaguangbo/linux_data/project/xctrl/xtempctrl/esp32c2$ cargo build
   Compiling esp32c2 v0.1.0 (/media/xiaguangbo/linux_data/project/xctrl/xtempctrl/esp32c2)
error[E0283]: type annotations needed
   --> src/component/max31865.rs:20:19
    |
20  |           let spi = SpiDeviceDriver::new_single(
    |  ___________________^
21  | |             spi,
22  | |             clk,
23  | |             mosi,
...   |
27  | |             &config,
28  | |         )
    | |_________^ cannot infer type for type parameter `impl OutputPin` declared on the associated function `new_single`
    |
    = note: cannot satisfy `_: esp_idf_hal::gpio::OutputPin`
    = help: the following types implement trait `esp_idf_hal::gpio::OutputPin`:
              esp_idf_hal::gpio::AnyIOPin
              AnyOutputPin
              Gpio0
              Gpio1
              Gpio2
              Gpio3
              Gpio4
              Gpio5
            and 15 others
note: required by a bound in `esp_idf_hal::spi::SpiDeviceDriver::<'d, esp_idf_hal::spi::SpiDriver<'d>>::new_single`
   --> /home/xiaguangbo/.cargo/registry/src/index.crates.io-6f17d22bba15001f/esp-idf-hal-0.43.1/src/spi.rs:762:45
    |
757 |     pub fn new_single<SPI: SpiAnyPins>(
    |            ---------- required by a bound in this associated function
...
762 |         cs: Option<impl Peripheral<P = impl OutputPin> + 'd>,
    |                                             ^^^^^^^^^ required by this bound in `SpiDeviceDriver::<'d, SpiDriver<'d>>::new_single`

For more information about this error, try `rustc --explain E0283`.
error: could not compile `esp32c2` (bin "esp32c2") due to 1 previous error

use Option::<AnyIOPin>::None is ok