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

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

Closed
xiaguangbo opened this issue Mar 31, 2024 · 1 comment

Comments

@xiaguangbo
Copy link

xiaguangbo commented Mar 31, 2024

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
@xiaguangbo
Copy link
Author

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

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

No branches or pull requests

1 participant