linefollower  2.0.0.0
linefollower.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 LINEFOLLOWER_H
36 #define LINEFOLLOWER_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_in.h"
49 
50 // -------------------------------------------------------------- PUBLIC MACROS
60 #define LINEFOLLOWER_MAP_MIKROBUS( cfg, mikrobus ) \
61  cfg.u2= MIKROBUS( mikrobus, MIKROBUS_AN ); \
62  cfg.u1= MIKROBUS( mikrobus, MIKROBUS_RST ); \
63  cfg.u5= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg.u4= MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.u3= MIKROBUS( mikrobus, MIKROBUS_TX );
66 
72 #define LINEFOLLOWER_RETVAL uint8_t
73 
74 #define LINEFOLLOWER_OK 0x00
75 #define LINEFOLLOWER_INIT_ERROR 0xFF
76 
82 #define LINEFOLLOWER_DATA_DIR_START 0x00
83 #define LINEFOLLOWER_DATA_DIR_1 0x01
84 #define LINEFOLLOWER_DATA_DIR_2 0x02
85 #define LINEFOLLOWER_DATA_DIR_3 0x03
86 #define LINEFOLLOWER_DATA_DIR_4 0x04
87 #define LINEFOLLOWER_DATA_DIR_6 0x06
88 #define LINEFOLLOWER_DATA_DIR_7 0x07
89 #define LINEFOLLOWER_DATA_DIR_8 0x08
90 #define LINEFOLLOWER_DATA_DIR_12 0x0C
91 #define LINEFOLLOWER_DATA_DIR_16 0x10
92 #define LINEFOLLOWER_DATA_DIR_24 0x18
93 #define LINEFOLLOWER_DATA_DIR_28 0x1C
94 #define LINEFOLLOWER_DATA_DIR_31 0x1F
95 
101 #define LINEFOLLOWER_BIT_0 0x01
102 #define LINEFOLLOWER_BIT_1 0x02
103 #define LINEFOLLOWER_BIT_2 0x04
104 #define LINEFOLLOWER_BIT_3 0x08
105 #define LINEFOLLOWER_BIT_4 0x10
106 
112 #define LINEFOLLOWER_DIR_STRAIGHT 0x00
113 #define LINEFOLLOWER_DIR_LEFT 0x01
114 #define LINEFOLLOWER_DIR_RIGHT 0x02
115 #define LINEFOLLOWER_DIR_SHARP_LEFT 0x03
116 #define LINEFOLLOWER_DIR_SHARP_RIGHT 0x04
117 #define LINEFOLLOWER_DIR_TRACKING_LOST 0x05
118  // End group macro
121 // --------------------------------------------------------------- PUBLIC TYPES
130 typedef struct
131 {
132  // Input pins
133 
134  digital_in_t u1;
135  digital_in_t u2;
136  digital_in_t u3;
137  digital_in_t u4;
138  digital_in_t u5;
139 
141 
145 typedef struct
146 {
147  // Additional gpio pins
148 
149  pin_name_t u1;
150  pin_name_t u2;
151  pin_name_t u3;
152  pin_name_t u4;
153  pin_name_t u5;
154 
156  // End types group
158 // ------------------------------------------------------------------ CONSTANTS // End constants group
167 // ------------------------------------------------------------------ VARIABLES
172 typedef struct
173 {
174  uint8_t u1;
175  uint8_t u2;
176  uint8_t u3;
177  uint8_t u4;
178  uint8_t u5;
179 
181  // End variable group
183 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184 
190 #ifdef __cplusplus
191 extern "C"{
192 #endif
193 
203 
212 
226 
240 
254 
268 
282 
294 
324 
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 #endif // _LINEFOLLOWER_H_
330  // End public_function group
333 
334 // ------------------------------------------------------------------------- END
linefollower_cfg_t::u2
pin_name_t u2
Definition: linefollower.h:150
linefollower_cfg_t
Click configuration structure definition.
Definition: linefollower.h:146
linefollower_cfg_t::u1
pin_name_t u1
Definition: linefollower.h:149
linefollower_t::u3
digital_in_t u3
Definition: linefollower.h:136
linefollower_get_u1
uint8_t linefollower_get_u1(linefollower_t *ctx)
Get status of U1 pin function.
linefollower_direction_t::u1
uint8_t u1
Definition: linefollower.h:174
linefollower_direction_t::u5
uint8_t u5
Definition: linefollower.h:178
linefollower_direction_t::u2
uint8_t u2
Definition: linefollower.h:175
linefollower_direction_t
Definition: linefollower.h:173
linefollower_t::u1
digital_in_t u1
Definition: linefollower.h:134
linefollower_direction_t::u3
uint8_t u3
Definition: linefollower.h:176
linefollower_cfg_t::u5
pin_name_t u5
Definition: linefollower.h:153
linefollower_get_u2
uint8_t linefollower_get_u2(linefollower_t *ctx)
Get status of U2 pin function.
linefollower_get_u5
uint8_t linefollower_get_u5(linefollower_t *ctx)
Get status of U5 pin function.
linefollower_data_track
void linefollower_data_track(linefollower_t *ctx, linefollower_direction_t *data_track)
Get status of all pin function.
linefollower_t
Click ctx object definition.
Definition: linefollower.h:131
linefollower_t::u4
digital_in_t u4
Definition: linefollower.h:137
linefollower_direction_t::u4
uint8_t u4
Definition: linefollower.h:177
linefollower_get_direction
uint8_t linefollower_get_direction(linefollower_t *ctx)
Get direction data function.
LINEFOLLOWER_RETVAL
#define LINEFOLLOWER_RETVAL
Definition: linefollower.h:72
linefollower_t::u5
digital_in_t u5
Definition: linefollower.h:138
linefollower_cfg_t::u4
pin_name_t u4
Definition: linefollower.h:152
linefollower_t::u2
digital_in_t u2
Definition: linefollower.h:135
linefollower_cfg_t::u3
pin_name_t u3
Definition: linefollower.h:151
linefollower_cfg_setup
void linefollower_cfg_setup(linefollower_cfg_t *cfg)
Config Object Initialization function.
linefollower_get_u3
uint8_t linefollower_get_u3(linefollower_t *ctx)
Get status of U3 pin function.
linefollower_init
LINEFOLLOWER_RETVAL linefollower_init(linefollower_t *ctx, linefollower_cfg_t *cfg)
Initialization function.
linefollower_get_u4
uint8_t linefollower_get_u4(linefollower_t *ctx)
Get status of U4 pin function.