speedsense  2.1.0.0
speedsense.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef SPEEDSENSE_H
29 #define SPEEDSENSE_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 
67 #define SPEEDSENSE_CNV_MIN_TO_MS 60000.0f
68 
73 #define SPEEDSENSE_DIR_STATE_FWD 0
74 #define SPEEDSENSE_DIR_STATE_RVS 1
75 #define SPEEDSENSE_SPEED_STATE_LOW 0
76 #define SPEEDSENSE_SPEED_STATE_HIGH 1
77 
82 #define SPEEDSENSE_STOP_MEASURE 0
83 #define SPEEDSENSE_START_NEW_MEASURE 1
84  // speedsense_set
86 
101 #define SPEEDSENSE_MAP_MIKROBUS( cfg, mikrobus ) \
102  cfg.chb = MIKROBUS( mikrobus, MIKROBUS_AN ); \
103  cfg.cha = MIKROBUS( mikrobus, MIKROBUS_INT )
104  // speedsense_map // speedsense
107 
112 typedef struct
113 {
114  digital_in_t chb;
115  digital_in_t cha;
117 } speedsense_t;
118 
123 typedef struct
124 {
125  pin_name_t chb;
126  pin_name_t cha;
129 
134 typedef enum
135 {
137  SPEEDSENSE_ERROR = -1
138 
140 
157 
172 
184 
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 #endif // SPEEDSENSE_H
201  // speedsense
203 
204 // ------------------------------------------------------------------------ END
speedsense_cfg_t::cha
pin_name_t cha
Definition: speedsense.h:126
speedsense_t
Speed Sense Click context object.
Definition: speedsense.h:113
speedsense_init
err_t speedsense_init(speedsense_t *ctx, speedsense_cfg_t *cfg)
Speed Sense initialization function.
speedsense_cfg_t
Speed Sense Click configuration object.
Definition: speedsense.h:124
speedsense_get_speed
uint8_t speedsense_get_speed(speedsense_t *ctx)
Speed Sense CHA pin reading function.
speedsense_cfg_t::chb
pin_name_t chb
Definition: speedsense.h:125
SPEEDSENSE_OK
@ SPEEDSENSE_OK
Definition: speedsense.h:136
speedsense_t::cha
digital_in_t cha
Definition: speedsense.h:115
speedsense_return_value_t
speedsense_return_value_t
Speed Sense Click return value data.
Definition: speedsense.h:135
speedsense_cfg_setup
void speedsense_cfg_setup(speedsense_cfg_t *cfg)
Speed Sense configuration object setup function.
speedsense_t::chb
digital_in_t chb
Definition: speedsense.h:114
SPEEDSENSE_ERROR
@ SPEEDSENSE_ERROR
Definition: speedsense.h:137
speedsense_get_direction
uint8_t speedsense_get_direction(speedsense_t *ctx)
Speed Sense CHB pin reading function.