File syn_encoder.h¶
FileList > input > syn_encoder.h
Go to the source code of this file
Quadrature rotary encoder decoder. More...
#include "../common/syn_defs.h"#include "../drivers/syn_gpio.h"#include "../dsp/syn_signal.h"#include <stdbool.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_Encoder Quadrature encoder instance — pins, position, delta. |
Public Types¶
| Type | Name |
|---|---|
| enum | SYN_EncoderDir Encoder rotation direction. |
Public Functions¶
| Type | Name |
|---|---|
| int32_t | syn_encoder_get_delta (SYN_Encoder * enc) Get accumulated delta since last call and reset it. |
| void | syn_encoder_init (SYN_Encoder * enc, SYN_GPIO_Pin pin_a, SYN_GPIO_Pin pin_b) Initialize encoder. |
| void | syn_encoder_set_stats (SYN_Encoder * enc, SYN_Signal * stats) Attach a signal statistics window for velocity tracking. |
| void | syn_encoder_set_steps_per_detent (SYN_Encoder * enc, uint8_t spd) Set steps-per-detent (default = 1). |
| void | syn_encoder_update (SYN_Encoder * enc) Sample pins and update position. |
Public Static Functions¶
| Type | Name |
|---|---|
| SYN_EncoderDir | syn_encoder_direction (const SYN_Encoder * enc) Get last direction. |
| int32_t | syn_encoder_position (const SYN_Encoder * enc) Get absolute position. |
| void | syn_encoder_set_position (SYN_Encoder * enc, int32_t pos) Set absolute position. |
Detailed Description¶
Decodes A/B quadrature signals from rotary encoders. Supports: * Direction detection (CW/CCW) * Accumulated position * Delta since last read * Optional push-button (use syn_button for debouncing)
Call syn_encoder_update() from a timer ISR or fast loop (≥4× the maximum encoder frequency).
** **
SYN_Encoder enc;
syn_encoder_init(&enc, PIN_A, PIN_B);
// In timer ISR or fast loop:
syn_encoder_update(&enc);
// In main loop:
int32_t delta = syn_encoder_get_delta(&enc);
if (delta != 0) {
volume += delta;
}
Public Types Documentation¶
enum SYN_EncoderDir¶
Encoder rotation direction.
Public Functions Documentation¶
function syn_encoder_get_delta¶
Get accumulated delta since last call and reset it.
Parameters:
encEncoder instance.
Returns:
Number of steps (positive = CW, negative = CCW).
function syn_encoder_init¶
Initialize encoder.
Parameters:
encEncoder instance.pin_aChannel A GPIO.pin_bChannel B GPIO.
function syn_encoder_set_stats¶
Attach a signal statistics window for velocity tracking.
Each call to syn_encoder_get_delta() pushes the delta value into the signal window, giving you velocity min/max/mean/variance.
Parameters:
encEncoder.statsInitialized SYN_Signal, or NULL to detach.
function syn_encoder_set_steps_per_detent¶
Set steps-per-detent (default = 1).
Many mechanical encoders generate 2 or 4 state changes per physical detent. Setting this to 4 means position and delta only increment once per detent rather than once per state change.
Parameters:
encEncoder instance.spdSteps per detent (1, 2, or 4).
function syn_encoder_update¶
Sample pins and update position.
Call from a timer ISR or fast polling loop. Must be called at ≥4× the encoder's maximum rotation speed.
Parameters:
encEncoder instance.
Public Static Functions Documentation¶
function syn_encoder_direction¶
Get last direction.
Parameters:
encEncoder.
Returns:
Last detected direction.
function syn_encoder_position¶
Get absolute position.
Parameters:
encEncoder.
Returns:
Accumulated position.
function syn_encoder_set_position¶
Set absolute position.
Parameters:
encEncoder.posNew position value.
The documentation for this class was generated from the following file src/syntropic/input/syn_encoder.h