capsules_extra

Module buzzer_pwm

Source
Expand description

Service capsule for a buzzer that uses a PWM pin.

§Instantiation

Instantiate the capsule for use as a service capsule, using a virtual pwm buzzer and a virtual alarm. For example:


let mux_pwm = static_init!(
    capsules::virtual_pwm::MuxPwm<'static, nrf52833::pwm::Pwm>,
    capsules::virtual_pwm::MuxPwm::new(&base_peripherals.pwm0)
);
let virtual_pwm_buzzer = static_init!(
    capsules::virtual_pwm::PwmPinUser<'static, nrf52833::pwm::Pwm>,
    capsules::virtual_pwm::PwmPinUser::new(
        mux_pwm,
        nrf52833::pinmux::Pinmux::new(SPEAKER_PIN as u32)
    )
);
virtual_pwm_buzzer.add_to_mux();

let virtual_alarm_buzzer = static_init!(
    capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52833::rtc::Rtc>,
    capsules::virtual_alarm::VirtualMuxAlarm::new(mux_alarm)
);
virtual_alarm_buzzer.setup();

let pwm_buzzer = static_init!(
    capsules::buzzer_pwm::PwmBuzzer<
        'static,
        capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52833::rtc::Rtc>,
        capsules::virtual_pwm::PwmPinUser<'static, nrf52833::pwm::Pwm>,
    >,
    capsules::buzzer_pwm::PwmBuzzer::new(
        virtual_pwm_buzzer,
        virtual_alarm_buzzer,
        capsules::buzzer_pwm::DEFAULT_MAX_BUZZ_TIME_MS,
    )
);

pwm_buzzer.set_client(buzzer);

virtual_alarm_buzzer.set_alarm_client(pwm_buzzer);

Structs§

Constants§