uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
encoder.h
Go to the documentation of this file.
1 
4 /*
5  * Copyright 2015 Sebastian Neuser
6  *
7  * This file is part of the uMIDI firmware.
8  *
9  * the uMIDI firmware is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * the uMIDI firmware is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with the uMIDI firmware. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 /*
24  * Header for encoders
25 */
26 
27 #ifndef _ENCODER_H
28 #define _ENCODER_H
29 
30 
31 //---------------- includes ----------------//
32 #include <stdbool.h>
33 #include "gpio.h"
34 
35 
36 //---------------- data types ----------------//
37 
40 {
45 };
46 
49 {
52 };
53 
56 {
57  const struct gpio_pin* inputA;
58  const struct gpio_pin* inputB;
59  const struct gpio_pin* inputSwitch;
60 
63  const enum encoder_type type;
64 
65  void (*cw_callback )(void);
66  void (*ccw_callback )(void);
67  void (*push_callback)(void);
68 };
69 
74 {
75  bool inputA;
76  bool inputB;
77  int8_t counter;
78 };
79 
81 struct encoder
82 {
83  struct encoder_config config;
84  struct encoder_state state;
85 };
86 
87 
88 //---------------- functions and procedures ----------------//
89 
95 void init_encoder(struct encoder* encoder);
96 
106 
107 
108 //---------------- EOF ----------------//
109 #endif // _ENCODER_H
bool inputB
Input B state.
Definition: encoder.h:76
Encoder was rotated clockwise.
Definition: encoder.h:43
bool inputA
Input A state.
Definition: encoder.h:75
void(* ccw_callback)(void)
Callback for counter-clockwise rotation or NULL
Definition: encoder.h:66
enum encoder_type type
Encoder type (# of phases)
Definition: encoder.h:63
GPIO configuration and service functions.
4-phase rotary encoder
Definition: encoder.h:51
3-phase rotary encoder
Definition: encoder.h:50
void(* push_callback)(void)
Callback for the push button or NULL
Definition: encoder.h:67
Encoder was rotated counter-clockwise.
Definition: encoder.h:44
encoder_type
Valid encoder types.
Definition: encoder.h:48
enum encoder_action poll_encoder(struct encoder *encoder)
Polls the encoder inputs.
Definition: encoder.c:118
const struct gpio_pin * inputA
The GPIO pin that input A is connected to.
Definition: encoder.h:57
:-( Nothing happened
Definition: encoder.h:41
An encoder instance.
Definition: encoder.h:81
const struct gpio_pin * inputSwitch
Definition: encoder.h:59
Encoder was pushed.
Definition: encoder.h:42
Internal state of an encoder.
Definition: encoder.h:73
void(* cw_callback)(void)
Callback for clockwise rotation or NULL
Definition: encoder.h:65
void init_encoder(struct encoder *encoder)
Initializes the encoder.
Definition: encoder.c:103
const struct gpio_pin * inputB
The GPIO pin that input A is connected to.
Definition: encoder.h:58
Configuration of a single GPIO pin.
Definition: gpio.h:57
encoder_action
An encoder action.
Definition: encoder.h:39
int8_t counter
Pulse counter.
Definition: encoder.h:77
Configuration of an encoder.
Definition: encoder.h:55