optoencoder  2.0.0.0
optoencoder.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 OPTOENCODER_H
36 #define OPTOENCODER_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define OPTOENCODER_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.o1= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
53  cfg.o2= MIKROBUS( mikrobus, MIKROBUS_INT );
54 
60 #define OPTOENCODER_RETVAL uint8_t
61 
62 #define OPTOENCODER_OK 0x00
63 #define OPTOENCODER_INIT_ERROR 0xFF
64  // End group macro
67 // --------------------------------------------------------------- PUBLIC TYPES
76 typedef struct
77 {
78  // Input pins
79 
80  digital_in_t o1;
81  digital_in_t o2;
82 
83  uint8_t rotary_flag;
84  uint8_t o1_flag;
85  uint8_t o2_flag;
86  int16_t dev_rotation;
87 
89 
93 typedef struct
94 {
95  // Additional gpio pins
96 
97  pin_name_t o1;
98  pin_name_t o2;
99 
101  // End types group
103 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
104 
110 #ifdef __cplusplus
111 extern "C"{
112 #endif
113 
123 
132 
140 uint8_t optoencoder_get_o1 ( optoencoder_t *ctx );
141 
149 uint8_t optoencoder_get_o2 ( optoencoder_t *ctx );
150 
156 void optoencoder_init_dev ( optoencoder_t *ctx );
157 
165 int16_t optoencoder_get_position ( optoencoder_t *ctx );
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 #endif // _OPTOENCODER_H_
171  // End public_function group
174 
175 // ------------------------------------------------------------------------- END
optoencoder_t
Click ctx object definition.
Definition: optoencoder.h:76
optoencoder_cfg_setup
void optoencoder_cfg_setup(optoencoder_cfg_t *cfg)
Config Object Initialization function.
optoencoder_t::dev_rotation
int16_t dev_rotation
Definition: optoencoder.h:86
optoencoder_cfg_t::o2
pin_name_t o2
Definition: optoencoder.h:98
optoencoder_init
OPTOENCODER_RETVAL optoencoder_init(optoencoder_t *ctx, optoencoder_cfg_t *cfg)
Initialization function.
optoencoder_get_o2
uint8_t optoencoder_get_o2(optoencoder_t *ctx)
Function for reading O2 state.
OPTOENCODER_RETVAL
#define OPTOENCODER_RETVAL
Definition: optoencoder.h:60
optoencoder_t::o1
digital_in_t o1
Definition: optoencoder.h:80
optoencoder_t::o1_flag
uint8_t o1_flag
Definition: optoencoder.h:84
optoencoder_t::rotary_flag
uint8_t rotary_flag
Definition: optoencoder.h:83
optoencoder_get_position
int16_t optoencoder_get_position(optoencoder_t *ctx)
Function for reading the position of the encoder.
optoencoder_t::o2_flag
uint8_t o2_flag
Definition: optoencoder.h:85
optoencoder_cfg_t
Click configuration structure definition.
Definition: optoencoder.h:93
optoencoder_init_dev
void optoencoder_init_dev(optoencoder_t *ctx)
Initialization function.
optoencoder_get_o1
uint8_t optoencoder_get_o1(optoencoder_t *ctx)
Function for reading O1 state.
optoencoder_cfg_t::o1
pin_name_t o1
Definition: optoencoder.h:97
optoencoder_t::o2
digital_in_t o2
Definition: optoencoder.h:81