uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Data Structures | Enumerations | Functions
encoder.h File Reference

Interface for rotary encoders. More...

#include <stdbool.h>
#include "gpio.h"
Include dependency graph for encoder.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  encoder_config
 Configuration of an encoder. More...
 
struct  encoder_state
 Internal state of an encoder. More...
 
struct  encoder
 An encoder instance. More...
 

Enumerations

enum  encoder_action { ENCODER_ACTION_NONE, ENCODER_ACTION_PUSH, ENCODER_ACTION_CW, ENCODER_ACTION_CCW }
 An encoder action. More...
 
enum  encoder_type { ENCODER_TYPE_3_PHASE = 3, ENCODER_TYPE_4_PHASE = 4 }
 Valid encoder types. More...
 

Functions

void init_encoder (struct encoder *encoder)
 Initializes the encoder. More...
 
enum encoder_action poll_encoder (struct encoder *encoder)
 Polls the encoder inputs. More...
 

Detailed Description

Interface for rotary encoders.

Enumeration Type Documentation

◆ encoder_action

An encoder action.

Enumerator
ENCODER_ACTION_NONE 

:-( Nothing happened

ENCODER_ACTION_PUSH 

Encoder was pushed.

ENCODER_ACTION_CW 

Encoder was rotated clockwise.

ENCODER_ACTION_CCW 

Encoder was rotated counter-clockwise.

◆ encoder_type

Valid encoder types.

Enumerator
ENCODER_TYPE_3_PHASE 

3-phase rotary encoder

ENCODER_TYPE_4_PHASE 

4-phase rotary encoder

Function Documentation

◆ 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