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 
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_out.h"
53 
54 // -------------------------------------------------------------- PUBLIC MACROS
64 #define RELAY_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.rel2= MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.rel1= MIKROBUS( mikrobus, MIKROBUS_PWM );
67 
73 #define RELAY_RETVAL uint8_t
74 
75 #define RELAY_OK 0x00
76 #define RELAY_INIT_ERROR 0xFF
77 
83 #define RELAY_STATE_ON 1
84 #define RELAY_STATE_OFF 0
85 
91 #define RELAY_NUM_1 1
92 #define RELAY_NUM_2 2
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
105 typedef struct
106 {
107  // Output pins
108 
109  digital_out_t rel2;
110  digital_out_t rel1;
111 
112 } relay_t;
113 
117 typedef struct
118 {
119  // Additional gpio pins
120 
121  pin_name_t rel2;
122  pin_name_t rel1;
123 
124 } relay_cfg_t;
125  // End types group
127 
128 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129 
135 #ifdef __cplusplus
136 extern "C"{
137 #endif
138 
148 
157 
168 
178 void relay_set_state ( relay_t *ctx, uint8_t relay, uint8_t state );
179 
180 #ifdef __cplusplus
181 }
182 #endif
183 #endif // _RELAY_H_
184  // End public_function group
187 
188 // ------------------------------------------------------------------------- END
relay_t::rel1
digital_out_t rel1
Definition: relay.h:110
relay_t::rel2
digital_out_t rel2
Definition: relay.h:109
relay_t
Click ctx object definition.
Definition: relay.h:106
relay_cfg_t::rel1
pin_name_t rel1
Definition: relay.h:122
RELAY_RETVAL
#define RELAY_RETVAL
Definition: relay.h:73
relay_cfg_t::rel2
pin_name_t rel2
Definition: relay.h:121
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:118
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.