optoencoder2  2.0.0.0
optoencoder2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef OPTOENCODER2_H
36 #define OPTOENCODER2_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define OPTOENCODER2_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.b_pin = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
67  cfg.a_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
68 
74 #define OPTOENCODER2_OK 0
75 #define OPTOENCODER2_ERROR -1
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef struct
89 {
90  // Input pins
91  digital_in_t b_pin;
92  digital_in_t a_pin;
93 
94  uint32_t timeout_counter;
96 
98 
102 typedef struct
103 {
104  // Additional gpio pins
105  pin_name_t b_pin;
106  pin_name_t a_pin;
107 
109  // End types group
111 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
112 
118 #ifdef __cplusplus
119 extern "C"{
120 #endif
121 
131 
140 
153 
166 
178 
188 
208 uint8_t optoencoder2_isr ( optoencoder2_t *ctx, uint8_t n_cycles );
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 #endif // _OPTOENCODER2_H_
214  // End public_function group
217 
218 // ------------------------------------------------------------------------- END
optoencoder2_t::position_counter
int32_t position_counter
Definition: optoencoder2.h:95
optoencoder2_init
err_t optoencoder2_init(optoencoder2_t *ctx, optoencoder2_cfg_t *cfg)
Initialization function.
optoencoder2_t::b_pin
digital_in_t b_pin
Definition: optoencoder2.h:91
optoencoder2_isr
uint8_t optoencoder2_isr(optoencoder2_t *ctx, uint8_t n_cycles)
Incrementing/decrementing encoder counter.
optoencoder2_cfg_t
Click configuration structure definition.
Definition: optoencoder2.h:103
optoencoder2_pwm_get
uint8_t optoencoder2_pwm_get(optoencoder2_t *ctx)
Getting PWM pin state.
optoencoder2_t
Click ctx object definition.
Definition: optoencoder2.h:89
optoencoder2_cfg_t::a_pin
pin_name_t a_pin
Definition: optoencoder2.h:106
optoencoder2_get_position
int32_t optoencoder2_get_position(optoencoder2_t *ctx)
Getting encoder position.
optoencoder2_int_get
uint8_t optoencoder2_int_get(optoencoder2_t *ctx)
Getting INT pin state.
optoencoder2_cfg_setup
void optoencoder2_cfg_setup(optoencoder2_cfg_t *cfg)
Config Object Initialization function.
optoencoder2_cfg_t::b_pin
pin_name_t b_pin
Definition: optoencoder2.h:105
optoencoder2_t::a_pin
digital_in_t a_pin
Definition: optoencoder2.h:92
optoencoder2_t::timeout_counter
uint32_t timeout_counter
Definition: optoencoder2.h:94
optoencoder2_zero_counter
void optoencoder2_zero_counter(optoencoder2_t *ctx)
Reset encoder counter.