44 lines
939 B
C
44 lines
939 B
C
#pragma once
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
uint clk_gpio;
|
|
uint dt_gpio;
|
|
uint sw_gpio;
|
|
bool invert_dir;
|
|
} encoder_pins_t;
|
|
|
|
typedef struct {
|
|
encoder_pins_t pins;
|
|
|
|
volatile int32_t position;
|
|
volatile int16_t accum;
|
|
|
|
bool btn_down;
|
|
bool btn_press_event;
|
|
bool btn_raw_last;
|
|
bool btn_stable;
|
|
absolute_time_t btn_last_change;
|
|
absolute_time_t btn_next_sample;
|
|
absolute_time_t mute_until;
|
|
|
|
uint8_t ab_stable;
|
|
uint8_t ab_candidate;
|
|
absolute_time_t ab_candidate_since;
|
|
uint32_t edges;
|
|
uint32_t clicks;
|
|
} encoder_t;
|
|
|
|
void encoder_init(encoder_t *enc, const encoder_pins_t *pins);
|
|
void encoder_poll(encoder_t *enc);
|
|
|
|
int32_t encoder_get_position(const encoder_t *enc);
|
|
void encoder_set_position(encoder_t *enc, int32_t pos);
|
|
|
|
bool encoder_btn_pressed(const encoder_t *enc);
|
|
bool encoder_btn_was_pressed(encoder_t *enc);
|