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 
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_in.h"
53 
54 // -------------------------------------------------------------- PUBLIC MACROS
64 #define LINEFOLLOWER_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.u2= MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.u1= MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.u5= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.u4= MIKROBUS( mikrobus, MIKROBUS_RX ); \
69  cfg.u3= MIKROBUS( mikrobus, MIKROBUS_TX );
70 
76 #define LINEFOLLOWER_RETVAL uint8_t
77 
78 #define LINEFOLLOWER_OK 0x00
79 #define LINEFOLLOWER_INIT_ERROR 0xFF
80 
86 #define LINEFOLLOWER_DATA_DIR_START 0x00
87 #define LINEFOLLOWER_DATA_DIR_1 0x01
88 #define LINEFOLLOWER_DATA_DIR_2 0x02
89 #define LINEFOLLOWER_DATA_DIR_3 0x03
90 #define LINEFOLLOWER_DATA_DIR_4 0x04
91 #define LINEFOLLOWER_DATA_DIR_6 0x06
92 #define LINEFOLLOWER_DATA_DIR_7 0x07
93 #define LINEFOLLOWER_DATA_DIR_8 0x08
94 #define LINEFOLLOWER_DATA_DIR_12 0x0C
95 #define LINEFOLLOWER_DATA_DIR_16 0x10
96 #define LINEFOLLOWER_DATA_DIR_24 0x18
97 #define LINEFOLLOWER_DATA_DIR_28 0x1C
98 #define LINEFOLLOWER_DATA_DIR_31 0x1F
99 
105 #define LINEFOLLOWER_BIT_0 0x01
106 #define LINEFOLLOWER_BIT_1 0x02
107 #define LINEFOLLOWER_BIT_2 0x04
108 #define LINEFOLLOWER_BIT_3 0x08
109 #define LINEFOLLOWER_BIT_4 0x10
110 
116 #define LINEFOLLOWER_DIR_STRAIGHT 0x00
117 #define LINEFOLLOWER_DIR_LEFT 0x01
118 #define LINEFOLLOWER_DIR_RIGHT 0x02
119 #define LINEFOLLOWER_DIR_SHARP_LEFT 0x03
120 #define LINEFOLLOWER_DIR_SHARP_RIGHT 0x04
121 #define LINEFOLLOWER_DIR_TRACKING_LOST 0x05
122  // End group macro
125 // --------------------------------------------------------------- PUBLIC TYPES
134 typedef struct
135 {
136  // Input pins
137 
138  digital_in_t u1;
139  digital_in_t u2;
140  digital_in_t u3;
141  digital_in_t u4;
142  digital_in_t u5;
143 
145 
149 typedef struct
150 {
151  // Additional gpio pins
152 
153  pin_name_t u1;
154  pin_name_t u2;
155  pin_name_t u3;
156  pin_name_t u4;
157  pin_name_t u5;
158 
160  // End types group
162 // ------------------------------------------------------------------ CONSTANTS // End constants group
171 // ------------------------------------------------------------------ VARIABLES
176 typedef struct
177 {
178  uint8_t u1;
179  uint8_t u2;
180  uint8_t u3;
181  uint8_t u4;
182  uint8_t u5;
183 
185  // End variable group
187 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
188 
194 #ifdef __cplusplus
195 extern "C"{
196 #endif
197 
207 
216 
230 
244 
258 
272 
286 
298 
328 
329 
330 #ifdef __cplusplus
331 }
332 #endif
333 #endif // _LINEFOLLOWER_H_
334  // End public_function group
337 
338 // ------------------------------------------------------------------------- END
linefollower_cfg_t::u2
pin_name_t u2
Definition: linefollower.h:154
linefollower_cfg_t
Click configuration structure definition.
Definition: linefollower.h:150
linefollower_cfg_t::u1
pin_name_t u1
Definition: linefollower.h:153
linefollower_t::u3
digital_in_t u3
Definition: linefollower.h:140
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:178
linefollower_direction_t::u5
uint8_t u5
Definition: linefollower.h:182
linefollower_direction_t::u2
uint8_t u2
Definition: linefollower.h:179
linefollower_direction_t
Definition: linefollower.h:177
linefollower_t::u1
digital_in_t u1
Definition: linefollower.h:138
linefollower_direction_t::u3
uint8_t u3
Definition: linefollower.h:180
linefollower_cfg_t::u5
pin_name_t u5
Definition: linefollower.h:157
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:135
linefollower_t::u4
digital_in_t u4
Definition: linefollower.h:141
linefollower_direction_t::u4
uint8_t u4
Definition: linefollower.h:181
linefollower_get_direction
uint8_t linefollower_get_direction(linefollower_t *ctx)
Get direction data function.
LINEFOLLOWER_RETVAL
#define LINEFOLLOWER_RETVAL
Definition: linefollower.h:76
linefollower_t::u5
digital_in_t u5
Definition: linefollower.h:142
linefollower_cfg_t::u4
pin_name_t u4
Definition: linefollower.h:156
linefollower_t::u2
digital_in_t u2
Definition: linefollower.h:139
linefollower_cfg_t::u3
pin_name_t u3
Definition: linefollower.h:155
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.