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 
77 #ifndef PERIPH_QDEC_H
78 #define PERIPH_QDEC_H
79 
80 #include <stdint.h>
81 #include <limits.h>
82 
83 #include "periph_cpu.h"
84 #include "periph_conf.h"
85 
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
89 
93 #ifndef QDEC_DEV
94 #define QDEC_DEV(x) (x)
95 #endif
96 
100 #ifndef QDEC_UNDEF
101 #define QDEC_UNDEF (UINT_MAX)
102 #endif
103 
107 #ifndef HAVE_QDEC_T
108 typedef unsigned int qdec_t;
109 #endif
110 
114 #ifndef HAVE_QDEC_MODE_T
115 typedef enum {
116  QDEC_X1, /* X1 mode */
117  QDEC_X2, /* X2 mode */
118  QDEC_X4, /* X4 mode */
119 } qdec_mode_t;
120 #endif
121 
127 typedef void (*qdec_cb_t)(void *arg);
128 
132 #ifndef HAVE_TIMER_ISR_CTX_T
133 typedef struct {
135  void *arg;
137 #endif
138 
160 int32_t qdec_init(qdec_t dev, qdec_mode_t mode, qdec_cb_t cb, void *arg);
161 
169 int32_t qdec_read(qdec_t dev);
170 
178 int32_t qdec_read_and_reset(qdec_t dev);
179 
187 void qdec_start(qdec_t qdec);
188 
196 void qdec_stop(qdec_t qdec);
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif /* PERIPH_QDEC_H */
203 
qdec_isr_ctx_t::cb
qdec_cb_t cb
callback executed from qdec interrupt
Definition: qdec.h:134
qdec_read_and_reset
int32_t qdec_read_and_reset(qdec_t dev)
Read the current value of the given qdec device and reset it.
qdec_start
void qdec_start(qdec_t qdec)
Start the given qdec timer.
qdec_mode_t
qdec_mode_t
Default QDEC mode definition.
Definition: qdec.h:115
qdec_isr_ctx_t::arg
void * arg
optional argument given to that callback
Definition: qdec.h:135
qdec_stop
void qdec_stop(qdec_t qdec)
Stop the given qdec timer.
qdec_t
unsigned int qdec_t
Default QDEC type definition.
Definition: qdec.h:108
qdec_read
int32_t qdec_read(qdec_t dev)
Read the current value of the given qdec device.
qdec_init
int32_t qdec_init(qdec_t dev, qdec_mode_t mode, qdec_cb_t cb, void *arg)
Initialize a QDEC device.
qdec_cb_t
void(* qdec_cb_t)(void *arg)
Signature of event callback functions triggered from interrupts.
Definition: qdec.h:127
qdec_isr_ctx_t
Default interrupt context entry holding callback and argument.
Definition: qdec.h:133