optoencoder3  2.0.0.0
optoencoder3.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 OPTOENCODER3_H
36 #define OPTOENCODER3_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 OPTOENCODER3_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.o1= MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.o2= MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.en= MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.o4= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
70  cfg.o3= MIKROBUS( mikrobus, MIKROBUS_INT );
71 
77 #define OPTOENCODER3_RETVAL uint8_t
78 
79 #define OPTOENCODER3_OK 0x00
80 #define OPTOENCODER3_INIT_ERROR 0xFF
81 
87 #define OPTOENCODER3_ENABLE 0
88 #define OPTOENCODER3_DISABLE 1
89 
95 #define OPTOENCODER3_PIN_ACTIVE 0
96 #define OPTOENCODER3_PIN_NOT_ACTIVE 1
97  // End group macro
100 // --------------------------------------------------------------- PUBLIC TYPES
109 typedef struct
110 {
111  // Output pins
112 
113  digital_out_t en;
114 
115  // Input pins
116 
117  digital_in_t o1;
118  digital_in_t o2;
119  digital_in_t o4;
120  digital_in_t o3;
121 
122  uint8_t dev_cnt;
125  uint8_t dev_stage;
126 
128 
132 typedef struct
133 {
134  // Additional gpio pins
135 
136  pin_name_t o1;
137  pin_name_t o2;
138  pin_name_t en;
139  pin_name_t o4;
140  pin_name_t o3;
141 
143 
147 typedef struct
148 {
149  uint8_t pin_o1;
150  uint8_t pin_o2;
151  uint8_t pin_o3;
152  uint8_t pin_o4;
153 
155  // End types group
157 
158 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
159 
165 #ifdef __cplusplus
166 extern "C"{
167 #endif
168 
178 
187 
195 void optoencoder3_enable ( optoencoder3_t *ctx, uint8_t active );
196 
205 
214 
223 
232 
241 
255 
262 
271 
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 #endif // _OPTOENCODER3_H_
277  // End public_function group
280 
281 // ------------------------------------------------------------------------- END
optoencoder3_read_pin_o1
uint8_t optoencoder3_read_pin_o1(optoencoder3_t *ctx)
Functions for reading state of pin o1.
optoencoder3_t
Click ctx object definition.
Definition: optoencoder3.h:110
optoencoder3_pins_t::pin_o1
uint8_t pin_o1
Definition: optoencoder3.h:149
optoencoder3_cfg_setup
void optoencoder3_cfg_setup(optoencoder3_cfg_t *cfg)
Config Object Initialization function.
optoencoder3_t::o1
digital_in_t o1
Definition: optoencoder3.h:117
optoencoder3_t::o4
digital_in_t o4
Definition: optoencoder3.h:119
optoencoder3_cfg_t
Click configuration structure definition.
Definition: optoencoder3.h:133
optoencoder3_cfg_t::o4
pin_name_t o4
Definition: optoencoder3.h:139
optoencoder3_enable
void optoencoder3_enable(optoencoder3_t *ctx, uint8_t active)
Sets state of click.
optoencoder3_pins_t
Click pins state.
Definition: optoencoder3.h:148
optoencoder3_cnt
uint8_t optoencoder3_cnt(optoencoder3_t *ctx)
Functions for reading number of swipes.
pins
optoencoder3_pins_t pins
Definition: main.c:32
OPTOENCODER3_RETVAL
#define OPTOENCODER3_RETVAL
Definition: optoencoder3.h:77
optoencoder3_cfg_t::o3
pin_name_t o3
Definition: optoencoder3.h:140
optoencoder3_init
OPTOENCODER3_RETVAL optoencoder3_init(optoencoder3_t *ctx, optoencoder3_cfg_t *cfg)
Initialization function.
optoencoder3_t::o3
digital_in_t o3
Definition: optoencoder3.h:120
optoencoder3_t::o2
digital_in_t o2
Definition: optoencoder3.h:118
optoencoder3_pins_t::pin_o2
uint8_t pin_o2
Definition: optoencoder3.h:150
optoencoder3_read_pin_o2
uint8_t optoencoder3_read_pin_o2(optoencoder3_t *ctx)
Functions for reading state of pin o2.
optoencoder3_t::dev_swiping_dir
uint8_t dev_swiping_dir
Definition: optoencoder3.h:124
optoencoder3_read_all_pins
void optoencoder3_read_all_pins(optoencoder3_t *ctx, optoencoder3_pins_t *pins)
Sets state of all pins.
optoencoder3_read_pin_o4
uint8_t optoencoder3_read_pin_o4(optoencoder3_t *ctx)
Functions for reading state of pin o4.
optoencoder3_pins_t::pin_o4
uint8_t pin_o4
Definition: optoencoder3.h:152
optoencoder3_t::dev_stage
uint8_t dev_stage
Definition: optoencoder3.h:125
optoencoder3_cfg_t::o1
pin_name_t o1
Definition: optoencoder3.h:136
optoencoder3_t::dev_swipe_cnt
int8_t dev_swipe_cnt
Definition: optoencoder3.h:123
optoencoder3_pins_t::pin_o3
uint8_t pin_o3
Definition: optoencoder3.h:151
optoencoder3_t::dev_cnt
uint8_t dev_cnt
Definition: optoencoder3.h:122
optoencoder3_dir_cnt
int8_t optoencoder3_dir_cnt(optoencoder3_t *ctx)
Functions for reading number of swipe directions.
optoencoder3_read_pin_o3
uint8_t optoencoder3_read_pin_o3(optoencoder3_t *ctx)
Functions for reading state of pin o3.
optoencoder3_cfg_t::o2
pin_name_t o2
Definition: optoencoder3.h:137
optoencoder3_cfg_t::en
pin_name_t en
Definition: optoencoder3.h:138
optoencoder3_reset_counters
void optoencoder3_reset_counters(optoencoder3_t *ctx)
Functions for reseting counters.
optoencoder3_t::en
digital_out_t en
Definition: optoencoder3.h:113