tilt  2.0.0.0
tilt.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 TILT_H
36 #define TILT_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 TILT_MAP_MIKROBUS( cfg, mikrobus ) \
61  cfg.vo1= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
62  cfg.vo2= MIKROBUS( mikrobus, MIKROBUS_INT )
63 
69 #define TILT_RETVAL uint8_t
70 
71 #define TILT_OK 0x00
72 #define TILT_INIT_ERROR 0xFF
73 
79 #define TILT_NO_DETECTION 0
80 #define TILT_DETECTION 1
81 #define TILT_LEFT_DETECTION 2
82 #define TILT_RIGHT_DETECTION 3
83 #define TILT_UP_DETECTION 4
84 #define TILT_DOWN_DETECTION 5
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  // Input pins
100 
101  digital_in_t vo1;
102  digital_in_t vo2;
103 
104 } tilt_t;
105 
109 typedef struct
110 {
111  // Additional gpio pins
112 
113  pin_name_t vo1;
114  pin_name_t vo2;
115 
116 } tilt_cfg_t;
117  // End types group
119 // ------------------------------------------------------------------ CONSTANTS // End constants group
128 // ------------------------------------------------------------------ VARIABLES // End variable group
136 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
137 
143 #ifdef __cplusplus
144 extern "C"{
145 #endif
146 
156 
165 
178 uint8_t tilt_left ( tilt_t *ctx );
179 
192 uint8_t tilt_right ( tilt_t *ctx );
193 
206 uint8_t tilt_up ( tilt_t *ctx );
207 
220 uint8_t tilt_down ( tilt_t *ctx );
221 
237 uint8_t tilt_direction ( tilt_t *ctx );
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 #endif // _TILT_H_
243  // End public_function group
246 
247 // ------------------------------------------------------------------------- END
tilt_cfg_t::vo1
pin_name_t vo1
Definition: tilt.h:113
tilt_right
uint8_t tilt_right(tilt_t *ctx)
Check the tilt right movement's direction function.
tilt_t::vo1
digital_in_t vo1
Definition: tilt.h:101
tilt_cfg_t
Click configuration structure definition.
Definition: tilt.h:110
tilt_cfg_setup
void tilt_cfg_setup(tilt_cfg_t *cfg)
Config Object Initialization function.
TILT_RETVAL
#define TILT_RETVAL
Definition: tilt.h:69
tilt_cfg_t::vo2
pin_name_t vo2
Definition: tilt.h:114
tilt_left
uint8_t tilt_left(tilt_t *ctx)
Check the tilt left movement's direction function.
tilt_down
uint8_t tilt_down(tilt_t *ctx)
Check the tilt down movement's direction function.
tilt_up
uint8_t tilt_up(tilt_t *ctx)
Check the tilt up movement's direction function.
tilt_t::vo2
digital_in_t vo2
Definition: tilt.h:102
tilt_init
TILT_RETVAL tilt_init(tilt_t *ctx, tilt_cfg_t *cfg)
Initialization function.
tilt_direction
uint8_t tilt_direction(tilt_t *ctx)
Check the tilt movement's direction function.
tilt_t
Click ctx object definition.
Definition: tilt.h:98