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 "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 OPTO3_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.out1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
63  cfg.out2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
64  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
65  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_INT );
66 
72 #define OPTO3_OK 0
73 #define OPTO3_ERROR -1
74 
80  #define OPTO3_HIGH 0x01
81  #define OPTO3_LOW 0x00
82  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
94 typedef struct
95 {
96  // Output pins
97  digital_out_t out1;
98  digital_out_t out2;
99 
100  // Input pins
101  digital_in_t in1;
102  digital_in_t in2;
103 
104 } opto3_t;
105 
109 typedef struct
110 {
111  // Additional gpio pins
112  pin_name_t out1;
113  pin_name_t out2;
114  pin_name_t in1;
115  pin_name_t in2;
116 
117 } opto3_cfg_t;
118  // End types group
120 
121 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
122 
128 #ifdef __cplusplus
129 extern "C"{
130 #endif
131 
141 
149 err_t opto3_init ( opto3_t *ctx, opto3_cfg_t *cfg );
150 
158 uint8_t opto3_get_in1 ( opto3_t *ctx );
159 
167 uint8_t opto3_get_in2 ( opto3_t *ctx );
168 
177 void opto3_set_out1 ( opto3_t *ctx, uint8_t state );
178 
187 void opto3_set_out2 ( opto3_t *ctx, uint8_t state );
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 #endif // _OPTO3_H_
193  // End public_function group
196 
197 // ------------------------------------------------------------------------- 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:98
opto3_t::out1
digital_out_t out1
Definition: opto3.h:97
opto3_cfg_t::in1
pin_name_t in1
Definition: opto3.h:114
opto3_cfg_t::out2
pin_name_t out2
Definition: opto3.h:113
opto3_get_in1
uint8_t opto3_get_in1(opto3_t *ctx)
Get input 1.
opto3_t
Click ctx object definition.
Definition: opto3.h:95
opto3_cfg_t::in2
pin_name_t in2
Definition: opto3.h:115
opto3_cfg_t
Click configuration structure definition.
Definition: opto3.h:110
opto3_t::in2
digital_in_t in2
Definition: opto3.h:102
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:112
opto3_t::in1
digital_in_t in1
Definition: opto3.h:101
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.