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.out1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
53  cfg.out2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
54  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
55  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_INT );
56 
62 #define OPTO3_OK 0
63 #define OPTO3_ERROR -1
64 
70  #define OPTO3_HIGH 0x01
71  #define OPTO3_LOW 0x00
72  // End group macro
75 // --------------------------------------------------------------- PUBLIC TYPES
84 typedef struct
85 {
86  // Output pins
87  digital_out_t out1;
88  digital_out_t out2;
89 
90  // Input pins
91  digital_in_t in1;
92  digital_in_t in2;
93 
94 } opto3_t;
95 
99 typedef struct
100 {
101  // Additional gpio pins
102  pin_name_t out1;
103  pin_name_t out2;
104  pin_name_t in1;
105  pin_name_t in2;
106 
107 } opto3_cfg_t;
108  // End types group
110 
111 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
112 
118 #ifdef __cplusplus
119 extern "C"{
120 #endif
121 
131 
139 err_t opto3_init ( opto3_t *ctx, opto3_cfg_t *cfg );
140 
148 uint8_t opto3_get_in1 ( opto3_t *ctx );
149 
157 uint8_t opto3_get_in2 ( opto3_t *ctx );
158 
167 void opto3_set_out1 ( opto3_t *ctx, uint8_t state );
168 
177 void opto3_set_out2 ( opto3_t *ctx, uint8_t state );
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 #endif // _OPTO3_H_
183  // End public_function group
186 
187 // ------------------------------------------------------------------------- END
opto3_get_in2
uint8_t opto3_get_in2(opto3_t *ctx)
Get input 2.
opto3_t::out2
digital_out_t out2
Definition: opto3.h:88
opto3_t::out1
digital_out_t out1
Definition: opto3.h:87
opto3_cfg_t::in1
pin_name_t in1
Definition: opto3.h:104
opto3_cfg_t::out2
pin_name_t out2
Definition: opto3.h:103
opto3_get_in1
uint8_t opto3_get_in1(opto3_t *ctx)
Get input 1.
opto3_t
Click ctx object definition.
Definition: opto3.h:85
opto3_cfg_t::in2
pin_name_t in2
Definition: opto3.h:105
opto3_cfg_t
Click configuration structure definition.
Definition: opto3.h:100
opto3_t::in2
digital_in_t in2
Definition: opto3.h:92
opto3_set_out2
void opto3_set_out2(opto3_t *ctx, uint8_t state)
Set output 2.
opto3_set_out1
void opto3_set_out1(opto3_t *ctx, uint8_t state)
Set output 1.
opto3_cfg_t::out1
pin_name_t out1
Definition: opto3.h:102
opto3_t::in1
digital_in_t in1
Definition: opto3.h:91
opto3_init
err_t opto3_init(opto3_t *ctx, opto3_cfg_t *cfg)
Initialization function.
opto3_cfg_setup
void opto3_cfg_setup(opto3_cfg_t *cfg)
Config Object Initialization function.