TimerImplementation

Trait TimerImplementation 

Source
pub trait TimerImplementation {
    // Required methods
    fn create(
        function: unsafe extern "C" fn(*mut c_void),
        data: *mut c_void,
    ) -> TimerPtr;
    unsafe fn delete(timer: TimerPtr);
    unsafe fn arm(timer: TimerPtr, timeout: u64, periodic: bool);
    unsafe fn is_active(timer: TimerPtr) -> bool;
    unsafe fn disarm(timer: TimerPtr);
}
Expand description

A timer implementation.

The following snippet demonstrates the boilerplate necessary to implement a timer using the TimerImplementation trait:

use esp_radio_rtos_driver::{
    register_timer_implementation,
    timer::{TimerImplementation, TimerPtr},
};

struct MyTimer {
    // Timer implementation details
}

impl TimerImplementation for MyTimer {
    fn create(function: unsafe extern "C" fn(*mut c_void), data: *mut c_void) -> TimerPtr {
        unimplemented!()
    }

    unsafe fn delete(mutex: MutexPtr) {
        unimplemented!()
    }

    unsafe fn arm(timer: TimerPtr, timeout: u64, periodic: bool) {
        unimplemented!()
    }

    unsafe fn is_active(timer: TimerPtr) -> bool {
        unimplemented!()
    }

    unsafe fn disarm(timer: TimerPtr) -> bool {
        unimplemented!()
    }
}

register_timer_implementation!(MyTimer);

Required Methods§

Source

fn create( function: unsafe extern "C" fn(*mut c_void), data: *mut c_void, ) -> TimerPtr

Creates a new timer instance from the given callback.

Source

unsafe fn delete(timer: TimerPtr)

Deletes a timer instance.

§Safety

timer must be a pointer returned from Self::create.

Source

unsafe fn arm(timer: TimerPtr, timeout: u64, periodic: bool)

Configures the timer to be triggered after the given timeout.

The timeout is specified in microsecond. If the timer is set to be periodic, the timer will be triggered with a constant frequency.

§Safety

timer must be a pointer returned from Self::create.

Source

unsafe fn is_active(timer: TimerPtr) -> bool

Checks if the timer is currently active.

§Safety

timer must be a pointer returned from Self::create.

Source

unsafe fn disarm(timer: TimerPtr)

Stops the timer.

§Safety

timer must be a pointer returned from Self::create.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§