qdec.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Gilles DOFFE <gdoffe@gmail.com>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
79 #include <stdint.h>
80 #include <limits.h>
81 
82 #include "periph_cpu.h"
83 #include "periph_conf.h"
84 
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 
92 #ifndef QDEC_DEV
93 #define QDEC_DEV(x) (x)
94 #endif
95 
99 #ifndef QDEC_UNDEF
100 #define QDEC_UNDEF (UINT_FAST8_MAX)
101 #endif
102 
106 #ifndef HAVE_QDEC_T
107 typedef uint_fast8_t qdec_t;
108 #endif
109 
113 #ifndef HAVE_QDEC_MODE_T
114 typedef enum {
115  QDEC_X1, /* X1 mode */
116  QDEC_X2, /* X2 mode */
117  QDEC_X4, /* X4 mode */
118 } qdec_mode_t;
119 #endif
120 
126 typedef void (*qdec_cb_t)(void *arg);
127 
131 #ifndef HAVE_TIMER_ISR_CTX_T
132 typedef struct {
134  void *arg;
136 #endif
137 
159 int32_t qdec_init(qdec_t dev, qdec_mode_t mode, qdec_cb_t cb, void *arg);
160 
168 int32_t qdec_read(qdec_t dev);
169 
178 
186 void qdec_start(qdec_t qdec);
187 
195 void qdec_stop(qdec_t qdec);
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 
int32_t qdec_init(qdec_t dev, qdec_mode_t mode, qdec_cb_t cb, void *arg)
Initialize a QDEC device.
int32_t qdec_read_and_reset(qdec_t dev)
Read the current value of the given qdec device and reset it.
qdec_mode_t
Default QDEC mode definition.
Definition: qdec.h:114
uint_fast8_t qdec_t
Default QDEC type definition.
Definition: qdec.h:107
int32_t qdec_read(qdec_t dev)
Read the current value of the given qdec device.
void qdec_stop(qdec_t qdec)
Stop the given qdec timer.
void qdec_start(qdec_t qdec)
Start the given qdec timer.
void(* qdec_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: qdec.h:126
Default interrupt context entry holding callback and argument.
Definition: qdec.h:132
qdec_cb_t cb
callback executed from qdec interrupt
Definition: qdec.h:133
void * arg
optional argument given to that callback
Definition: qdec.h:134