driver  2.0.0.0
driver.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 DRIVER_H
36 #define DRIVER_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_out.h"
49 #include "drv_digital_in.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define DRIVER_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.in1= MIKROBUS( mikrobus, MIKROBUS_AN ); \
63  cfg.in2= MIKROBUS( mikrobus, MIKROBUS_RST ); \
64  cfg.in3= MIKROBUS( mikrobus, MIKROBUS_CS ); \
65  cfg.in4= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
66  cfg.in5= MIKROBUS( mikrobus, MIKROBUS_INT ); \
67  cfg.in6= MIKROBUS( mikrobus, MIKROBUS_RX ); \
68  cfg.in7= MIKROBUS( mikrobus, MIKROBUS_TX )
69  //RX and TX are inverted because of mapping
70 
77 #define DRIVER_RETVAL uint8_t
78 
79 #define DRIVER_OK 0x00
80 #define DRIVER_INIT_ERROR 0xFF
81 
87 #define PULSE_WIDTH 3000
88 #define ENABLE_IN 0
89 #define DISABLE_IN 1
90  // End group macro
93 // --------------------------------------------------------------- PUBLIC TYPES
102 typedef struct
103 {
104  // Output pins
105 
106  digital_out_t in1;
107  digital_out_t in2;
108  digital_out_t in3;
109  digital_out_t in4;
110  digital_out_t in5;
111  digital_out_t in6;
112  digital_out_t in7;
113 
114 } driver_t;
115 
119 typedef struct
120 {
121  // Additional gpio pins
122 
123  pin_name_t in1;
124  pin_name_t in2;
125  pin_name_t in3;
126  pin_name_t in4;
127  pin_name_t in5;
128  pin_name_t in6;
129  pin_name_t in7;
130 
131 } driver_cfg_t;
132  // End types group
134 // ------------------------------------------------------------------ CONSTANTS
135 
136 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
137 
143 #ifdef __cplusplus
144 extern "C"{
145 #endif
146 
156 
165 
174 void driver_set_in1 ( driver_t *ctx, uint8_t state );
175 
184 void driver_set_in2 ( driver_t *ctx, uint8_t state );
185 
194 void driver_set_in3 ( driver_t *ctx, uint8_t state );
195 
203 void driver_set_in4 ( driver_t *ctx, uint8_t state );
204 
212 void driver_set_in5 ( driver_t *ctx, uint8_t state );
213 
221 void driver_set_in6 ( driver_t *ctx, uint8_t state );
222 
230 void driver_set_in7 ( driver_t *ctx, uint8_t state );
231 
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 #endif // _DRIVER_H_
237  // End public_function group
240 
241 // ------------------------------------------------------------------------- END
driver_t::in6
digital_out_t in6
Definition: driver.h:111
driver_t::in7
digital_out_t in7
Definition: driver.h:112
driver_set_in2
void driver_set_in2(driver_t *ctx, uint8_t state)
IN2 Set function.
driver_t::in3
digital_out_t in3
Definition: driver.h:108
driver_cfg_t::in6
pin_name_t in6
Definition: driver.h:128
driver_init
DRIVER_RETVAL driver_init(driver_t *ctx, driver_cfg_t *cfg)
Initialization function.
driver_cfg_t::in3
pin_name_t in3
Definition: driver.h:125
driver_cfg_t::in7
pin_name_t in7
Definition: driver.h:129
driver_t::in4
digital_out_t in4
Definition: driver.h:109
driver_set_in3
void driver_set_in3(driver_t *ctx, uint8_t state)
IN3 Set function.
driver_t::in5
digital_out_t in5
Definition: driver.h:110
driver_set_in6
void driver_set_in6(driver_t *ctx, uint8_t state)
IN6 Set function.
driver_cfg_t::in5
pin_name_t in5
Definition: driver.h:127
driver_t
Click ctx object definition.
Definition: driver.h:103
driver_set_in7
void driver_set_in7(driver_t *ctx, uint8_t state)
IN7 Set function.
driver_cfg_setup
void driver_cfg_setup(driver_cfg_t *cfg)
Config Object Initialization function.
driver_cfg_t
Click configuration structure definition.
Definition: driver.h:120
driver_cfg_t::in2
pin_name_t in2
Definition: driver.h:124
driver_set_in5
void driver_set_in5(driver_t *ctx, uint8_t state)
IN5 Set function.
driver_set_in4
void driver_set_in4(driver_t *ctx, uint8_t state)
IN4 Set function.
DRIVER_RETVAL
#define DRIVER_RETVAL
Definition: driver.h:77
driver_cfg_t::in4
pin_name_t in4
Definition: driver.h:126
driver_cfg_t::in1
pin_name_t in1
Definition: driver.h:123
driver_t::in1
digital_out_t in1
Definition: driver.h:106
driver_t::in2
digital_out_t in2
Definition: driver.h:107
driver_set_in1
void driver_set_in1(driver_t *ctx, uint8_t state)
IN1 Set function.