-
Thanks for the cool library Rahix ! Still attempting to get my rust FU together , but programming micros has always been fun. I am trying to write a differential drive controller. I have got pwm control working in main (using the pwm example mostly). So .. I have a construct that I am trying to build in a generic struct. use embedded_hal::PwmPin;
pub struct DiffDrive<E, P1, P2>
where
E: PwmPin,
P1: OutputPin,
P2: OutputPin,
{
en: E,
p1: P1,
p2: P2,
config: Config,
}
impl<E, P1, P2> DiffDrive<E, P1, P2>
where
E: PwmPin,
P1: OutputPin,
P2: OutputPin,
{
pub fn new(mut en: E, mut p1: P1, mut p2: P2) -> Self {
let conf = Config::default();
Self {
en: en,
p1: p1,
p2: p2,
config: conf,
}
}
} Constructed with // Create the drive parts
// left drive
let timer0 = Timer2Pwm::new(dp.TC2, Prescaler::Prescale64);
let mut pwm_pin = pins.d3.into_output().into_pwm(&timer0);
let mut en_pin1 = pins.d8.into_output();
let mut en_pin2 = pins.d9.into_output();
let mut left_drive = diff_drive::DiffDrive::new(pwm_pin, en_pin1, en_pin2); The output pins work fine, but the PwmPin ( from embedded HAL ) give me a weird trait error.
This seems to be covered by I cannot work out why the trait is not covered... Any hints ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't think we implement the use arduino_hal::port::{Pin, PinOps, mode};
use arduino_hal::simple_pwm::PwmPinOps;
#[derive(Default)]
struct Config;
pub struct DiffDrive<TC, E, P1, P2> {
en: Pin<mode::PwmOutput<TC>, E>,
p1: Pin<mode::Output, P1>,
p2: Pin<mode::Output, P2>,
config: Config,
}
impl<TC, E: PwmPinOps<TC>, P1: PinOps, P2: PinOps> DiffDrive<TC, E, P1, P2> {
pub fn new(
en: Pin<mode::PwmOutput<TC>, E>,
p1: Pin<mode::Output, P1>,
p2: Pin<mode::Output, P2>,
) -> Self {
let config = Config::default();
Self { en, p1, p2, config }
}
} One important sidenote: The import |
Beta Was this translation helpful? Give feedback.
I don't think we implement the
PwmPin
trait fromembedded-hal
right now. So you'll have to be generic over thePwmPinOps
instead, as you noticed. Maybe this works: