Module capsules_extra::servo
source · Expand description
This provides virtualized userspace access to a servomotor.
§Usage
ⓘ
use kernel::static_init;
let mux_pwm = components::pwm::PwmMuxComponent::new(&peripherals.pwm)
.finalize(components::pwm_mux_component_static!(rp2040::pwm::Pwm));
let virtual_pwm_servo: &PwmPinUser<'static, rp2040::pwm::Pwm<'static>> =
components::pwm::PwmPinUserComponent::new(mux_pwm, rp2040::gpio::RPGpio::GPIO4)
.finalize(components::pwm_pin_user_component_static!(rp2040::pwm::Pwm));
let sg90_servo = static_init!(
capsules_extra::sg90::Sg90<
'static,
capsules_core::virtualizers::virtual_pwm::PwmPinUser<'static, rp2040::pwm::Pwm>,
>,
capsules_extra::sg90::Sg90::new(virtual_pwm_servo)
);
// Here, we initialize an array of two SG90 servomotors as an example.
let multi_servo = static_init!(
[&'static dyn hil::servo::Servo<'static>; 2],
[sg90_servo, sg90_servo]
);
let servo = static_init!(
capsules_extra::servo::Servo<'static, 2>,
capsules_extra::servo::Servo::new(multi_servo)
);