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 
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 TILT_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.vo1= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
66  cfg.vo2= MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define TILT_RETVAL uint8_t
74 
75 #define TILT_OK 0x00
76 #define TILT_INIT_ERROR 0xFF
77 
83 #define TILT_NO_DETECTION 0
84 #define TILT_DETECTION 1
85 #define TILT_LEFT_DETECTION 2
86 #define TILT_RIGHT_DETECTION 3
87 #define TILT_UP_DETECTION 4
88 #define TILT_DOWN_DETECTION 5
89  // End group macro
92 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103  // Input pins
104 
105  digital_in_t vo1;
106  digital_in_t vo2;
107 
108 } tilt_t;
109 
113 typedef struct
114 {
115  // Additional gpio pins
116 
117  pin_name_t vo1;
118  pin_name_t vo2;
119 
120 } tilt_cfg_t;
121  // End types group
123 // ------------------------------------------------------------------ CONSTANTS // End constants group
132 // ------------------------------------------------------------------ VARIABLES // End variable group
140 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
141 
147 #ifdef __cplusplus
148 extern "C"{
149 #endif
150 
160 
169 
182 uint8_t tilt_left ( tilt_t *ctx );
183 
196 uint8_t tilt_right ( tilt_t *ctx );
197 
210 uint8_t tilt_up ( tilt_t *ctx );
211 
224 uint8_t tilt_down ( tilt_t *ctx );
225 
241 uint8_t tilt_direction ( tilt_t *ctx );
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 #endif // _TILT_H_
247  // End public_function group
250 
251 // ------------------------------------------------------------------------- END
tilt_cfg_t::vo1
pin_name_t vo1
Definition: tilt.h:117
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:105
tilt_cfg_t
Click configuration structure definition.
Definition: tilt.h:114
tilt_cfg_setup
void tilt_cfg_setup(tilt_cfg_t *cfg)
Config Object Initialization function.
TILT_RETVAL
#define TILT_RETVAL
Definition: tilt.h:73
tilt_cfg_t::vo2
pin_name_t vo2
Definition: tilt.h:118
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:106
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:102