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?
If you are using the esp32c3-hal crate, then
.split()is provided on theAPB_SARADCtype via theSarAdcExttrait. The resulting type ofanalogwould beAvailableAnalog.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.