opto3  2.0.0.0
opto3.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 OPTO3_H
36 #define OPTO3_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define OPTO3_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.ou1= MIKROBUS( mikrobus, MIKROBUS_AN ); \
53  cfg.ou2= MIKROBUS( mikrobus, MIKROBUS_RST ); \
54  cfg.in1= MIKROBUS( mikrobus, MIKROBUS_PWM ); \
55  cfg.in2= MIKROBUS( mikrobus, MIKROBUS_INT );
56 
62 #define OPTO3_RETVAL uint8_t
63 #define OPTO3_STATE uint8_t
64 #define OPTO3_SWITCH uint8_t
65 
66 #define OPTO3_OK 0x00
67 #define OPTO3_INIT_ERROR 0xFF
68 
74  #define OPTO3_HIGH 0x01
75  #define OPTO3_LOW 0x00
76 
82  #define OPTO3_ON 0x01
83  #define OPTO3_OFF 0x00
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef struct
97 {
98  // Output pins
99 
100  digital_out_t ou1;
101  digital_out_t ou2;
102 
103  // Input pins
104 
105  digital_in_t in1;
106  digital_in_t in2;
107 
108 } opto3_t;
109 
113 typedef struct
114 {
115  // Additional gpio pins
116 
117  pin_name_t ou1;
118  pin_name_t ou2;
119  pin_name_t in1;
120  pin_name_t in2;
121 
122 } opto3_cfg_t;
123  // End types group
125 
126 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
127 
133 #ifdef __cplusplus
134 extern "C"{
135 #endif
136 
145 void opto3_cfg_setup ( opto3_cfg_t *cfg );
146 
155 
164 
173 
182  void opto3_set_out1 ( opto3_t *ctx, OPTO3_SWITCH state );
183 
192  void opto3_set_out2 ( opto3_t *ctx, OPTO3_SWITCH state );
193 
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 #endif // _OPTO3_H_
199  // End public_function group
202 
203 // ------------------------------------------------------------------------- END
opto3_set_out2
void opto3_set_out2(opto3_t *ctx, OPTO3_SWITCH state)
Gets output.
OPTO3_STATE
#define OPTO3_STATE
Definition: opto3.h:63
opto3_t::ou1
digital_out_t ou1
Definition: opto3.h:100
opto3_cfg_t::in1
pin_name_t in1
Definition: opto3.h:119
opto3_init
OPTO3_RETVAL opto3_init(opto3_t *ctx, opto3_cfg_t *cfg)
Initialization function.
OPTO3_SWITCH
#define OPTO3_SWITCH
Definition: opto3.h:64
opto3_set_out1
void opto3_set_out1(opto3_t *ctx, OPTO3_SWITCH state)
Gets output.
opto3_cfg_t::ou2
pin_name_t ou2
Definition: opto3.h:118
opto3_t
Click ctx object definition.
Definition: opto3.h:96
opto3_get_in2
OPTO3_STATE opto3_get_in2(opto3_t *ctx)
Gets input.
opto3_cfg_t::in2
pin_name_t in2
Definition: opto3.h:120
opto3_t::ou2
digital_out_t ou2
Definition: opto3.h:101
opto3_cfg_t
Click configuration structure definition.
Definition: opto3.h:113
OPTO3_RETVAL
#define OPTO3_RETVAL
Definition: opto3.h:62
opto3_t::in2
digital_in_t in2
Definition: opto3.h:106
opto3_cfg_t::ou1
pin_name_t ou1
Definition: opto3.h:117
opto3_t::in1
digital_in_t in1
Definition: opto3.h:105
opto3_get_in1
OPTO3_STATE opto3_get_in1(opto3_t *ctx)
Gets input.
opto3_cfg_setup
void opto3_cfg_setup(opto3_cfg_t *cfg)
Config Object Initialization function.