rotary-encoder-embedded

A rotary encoder library for embedded rust applications

features

example

Note: Quick example based on the stm32h7xx-hal.

``` static ROTARY_ENCODER: Mutex>> = Mutex::new(RefCell::new(None));

fn main() -> ! { // ... Initialize DT and CLK pins as desired. Typically PullUp Push-Pull. // ... Initialize interrupt on rising and falling edge

interrupt::free(|cs| {
    ROTARY_ENCODER.borrow(cs).replace(Some(
        RotaryEncoder::new(
            rotary_dt,
            rotary_clk,
            Option::None, // optional velocity_inc_factor
            Option::None, // optional velocity_dec_factor
            Option::None, // optional velocity_action_ms
        )
    ));
});

loop {
    // Will update time based properties such as the angular velocity.
    // Could also be executed from a timer. Modify the `velocity_dec_factor` to match its execution frequency
    rotary_encoder.tick();
}

}

[interrupt]

fn EXTI1() { // DT rising or falling edge interrupt interrupt::free(|cs| { if let Some(ref mut rotaryencoder) = ROTARYENCODER.borrow(cs).borrowmut().derefmut() { let currenttime = ... // Get this NaiveDateTime based from your RTC or SysTick handler rotaryencoder.update(currenttime); controls .rotaryencoder .borrowpins() .0 .clearinterruptpendingbit(); } }); }

[interrupt]

fn EXTI2() { // CLK rising or falling edge interrupt interrupt::free(|cs| { if let Some(ref mut rotaryencoder) = ROTARYENCODER.borrow(cs).borrowmut().derefmut() { let currenttime = ... // Get this NaiveDateTime based from your RTC or SysTick handler rotaryencoder.update(currenttime); controls .rotaryencoder .borrowpins() .1 .clearinterruptpendingbit(); } }); }

```