uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Functions
encoder.c File Reference

Implementation of a 3- or 4-phase rotary encoder with (optional) momentary switch. More...

#include <stddef.h>
#include "encoder.h"
#include "gpio.h"
Include dependency graph for encoder.c:

Functions

static void advance_3phase_encoder (struct encoder_state *const state, const bool inputA, const bool inputB)
 Interprets encoder inputs and updates the supplied encoder state. More...
 
static void advance_4phase_encoder (struct encoder_state *const state, const bool inputA, const bool inputB)
 Interprets encoder inputs and updates the supplied encoder state. More...
 
void init_encoder (struct encoder *const encoder)
 Initializes the encoder. More...
 
enum encoder_action poll_encoder (struct encoder *const encoder)
 Polls the encoder inputs. More...
 

Detailed Description

Implementation of a 3- or 4-phase rotary encoder with (optional) momentary switch.

Function Documentation

◆ advance_3phase_encoder()

static void advance_3phase_encoder ( struct encoder_state *const  state,
const bool  inputA,
const bool  inputB 
)
static

Interprets encoder inputs and updates the supplied encoder state.

This helper function implements a 3-phase rotary encoder "protocol".

Parameters
statethe state of the encoder
inputAthe current input on the encoder's A terminal
inputBthe current input on the encoder's B terminal

◆ advance_4phase_encoder()

static void advance_4phase_encoder ( struct encoder_state *const  state,
const bool  inputA,
const bool  inputB 
)
static

Interprets encoder inputs and updates the supplied encoder state.

This helper function implements a 4-phase rotary encoder "protocol".

Parameters
statethe state of the encoder
inputAthe current input on the encoder's A terminal
inputBthe current input on the encoder's B terminal

◆ init_encoder()

void init_encoder ( struct encoder encoder)

Initializes the encoder.

Configures GPIO pins and registers the callbacks.

Parameters
encoderthe encoder instance to initialize
See also
encoder_config

◆ poll_encoder()

enum encoder_action poll_encoder ( struct encoder encoder)

Polls the encoder inputs.

Checks if the encoder was rotated or pushed and updates the saved state. This function also executes registered callbacks, so you can define those in the encoder configuration passed to init_encoder and register this function in a background task, discarding its return value.

Parameters
encoderthe encoder to poll
Returns
the detected action or ENCODER_ACTION_NONE