0

In Demystifying .. Split.. and .. using the ADC blog:

// Promote ADC peripheral to HAL-level Struct
let analog = peripherals.APB_SARADC.split();

But I cannot figure out what the return type is of .split() or even for sure what definition it is using. rust-analyzer has no tooltip for split and "No type definition found for "split". Tooltip for analog just says let analog: {unknown}.

I can then use it in this code which builds and runs without panicking (although I'm trying to debug stuff)

// Create handle for ADC, configuring clock, and passing configuration handle
    let mut adc = ADC::adc(
        &mut system.peripheral_clock_control,
        analog.adc1,                               // <<< "no definition found for `adc1`
        adc_config,
    )
    .unwrap();

ADC::adc wants a adc_instance: impl crate::peripheral::Peripheral<P = ADCI> + 'd for that parameter, but I haven't been able to adapt that to an accepted explicit type annotation on analog.

If rust doesn't know what analog is, why isn't there a compilation error? What type is it?

Jason Kleban
  • 20,024
  • 18
  • 75
  • 125
  • Needs more context. What are the relevant crates? What type is `peripherals.APB_SARADC`? `ADC` is sadly not very unique in the embedded world. – Finomnis Aug 19 '23 at 23:20
  • The first link seems to be using the stm32f4xx-hal crate while the second link (and your code) seem to be using the esp32c3-hal crate. Confusing me and maybe you as well. – kmdreko Aug 19 '23 at 23:27

1 Answers1

2

If you are using the esp32c3-hal crate, then .split() is provided on the APB_SARADC type via the SarAdcExt trait. The resulting type of analog would be AvailableAnalog.

Its hard to tell why rust-analyzer is having issues deducing the type, but the compiler should be trusted over it, so there's clearly no type issue with your code.

kmdreko
  • 42,554
  • 6
  • 57
  • 106