Reputation: 142
I am trying to convert from a type erased type to a value type.
I have the following struct that accepts DynPin
, which is the type erased type of a rp2040 gpio pin.
pub struct PhProbe{
analog_read_pin: DynPin,
}
Now using the rp2040 analog to digital converter with OneShot I want to use this pin in the read function (ignore return value). But the read function of the ADC only accepts pins that implement Channel<ADC>
which is done using a macro, which as you can see is only implemented for the specific gpios 26-29.
pub fn read(&mut self, adc: Adc) {
let reading: u16 = adc.read(&mut <DynPin as Into<FloatingInput>>::into(self.analog_read_pin)).unwrap();
}
The pin is created using the into_floating_input()
function and handed to the PhProbe::new()
function by making a DynPin
using into()
.
let ph_pin = pins.gpio26.into_floating_input();
let ph_meter = PhProbe::new(ph_pin.into());
I was trying to make a analog input pin (FloatingInput) out of the DynPin, but this doesn't satisfy the bounds Channel<Adc>
of OneShot
. Is there a a way to use any of the gpio26-29 pins with this or do I need to specify Gpio26
for this?
Upvotes: 3
Views: 170