Files
MTGcompanion/main/encoder.h
2026-09-11 19:10:31 +02:00

61 lines
1.2 KiB
C

/*
* MTG RFID Companion - EC11 rotary encoder driver
*
* Phase 7 Step 7.1: Interrupt-driven quadrature decode on GPIO CLK/DT with
* a debounced push button on SW (active low).
*/
#pragma once
#include "esp_err.h"
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Install GPIO ISR service and configure encoder pins.
*/
esp_err_t encoder_init(void);
/**
* @brief True if the encoder has rotated since the last check.
*/
bool encoder_has_delta(void);
/**
* @brief Return the accumulated rotation steps and reset it.
* Positive = clockwise, negative = counter-clockwise (configurable).
*/
int32_t encoder_get_delta_and_reset(void);
/**
* @brief Return current accumulator without resetting.
*/
int32_t encoder_get_delta(void);
/**
* @brief True if the push button was pressed since last poll.
*/
bool encoder_button_pressed(void);
/**
* @brief Clear the button-pressed flag.
*/
void encoder_clear_button(void);
/**
* @brief Get current quadrature steps per mechanical detent tick (2 or 4).
*/
int8_t encoder_get_steps_per_detent(void);
/**
* @brief Set quadrature steps per mechanical detent tick (2 or 4).
*/
void encoder_set_steps_per_detent(int8_t steps);
#ifdef __cplusplus
}
#endif