relay  2.0.0.0
relay.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 RELAY_H
36 #define RELAY_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 
50 // -------------------------------------------------------------- PUBLIC MACROS
60 #define RELAY_MAP_MIKROBUS( cfg, mikrobus ) \
61  cfg.rel2= MIKROBUS( mikrobus, MIKROBUS_CS ); \
62  cfg.rel1= MIKROBUS( mikrobus, MIKROBUS_PWM );
63 
69 #define RELAY_RETVAL uint8_t
70 
71 #define RELAY_OK 0x00
72 #define RELAY_INIT_ERROR 0xFF
73 
79 #define RELAY_STATE_ON 1
80 #define RELAY_STATE_OFF 0
81 
87 #define RELAY_NUM_1 1
88 #define RELAY_NUM_2 2
89  // End group macro
92 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103  // Output pins
104 
105  digital_out_t rel2;
106  digital_out_t rel1;
107 
108 } relay_t;
109 
113 typedef struct
114 {
115  // Additional gpio pins
116 
117  pin_name_t rel2;
118  pin_name_t rel1;
119 
120 } relay_cfg_t;
121  // End types group
123 
124 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
125 
131 #ifdef __cplusplus
132 extern "C"{
133 #endif
134 
144 
153 
164 
174 void relay_set_state ( relay_t *ctx, uint8_t relay, uint8_t state );
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 #endif // _RELAY_H_
180  // End public_function group
183 
184 // ------------------------------------------------------------------------- END
relay_t::rel1
digital_out_t rel1
Definition: relay.h:106
relay_t::rel2
digital_out_t rel2
Definition: relay.h:105
relay_t
Click ctx object definition.
Definition: relay.h:102
relay_cfg_t::rel1
pin_name_t rel1
Definition: relay.h:118
RELAY_RETVAL
#define RELAY_RETVAL
Definition: relay.h:69
relay_cfg_t::rel2
pin_name_t rel2
Definition: relay.h:117
relay_set_state
void relay_set_state(relay_t *ctx, uint8_t relay, uint8_t state)
Relay set state.
relay_cfg_t
Click configuration structure definition.
Definition: relay.h:114
relay_cfg_setup
void relay_cfg_setup(relay_cfg_t *cfg)
Config Object Initialization function.
relay_default_cfg
void relay_default_cfg(relay_t *ctx)
Click Default Configuration function.
relay_init
RELAY_RETVAL relay_init(relay_t *ctx, relay_cfg_t *cfg)
Initialization function.