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
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#include "drv_digital_in.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define OPTO3_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.out1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67 cfg.out2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68 cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69 cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_INT );
76#define OPTO3_OK 0
77#define OPTO3_ERROR -1
84 #define OPTO3_HIGH 0x01
85 #define OPTO3_LOW 0x00
88 // End group macro
89// --------------------------------------------------------------- PUBLIC TYPES
98typedef struct
99{
100 // Output pins
101 digital_out_t out1;
102 digital_out_t out2;
103
104 // Input pins
105 digital_in_t in1;
106 digital_in_t in2;
107
108} opto3_t;
109
113typedef struct
114{
115 // Additional gpio pins
116 pin_name_t out1;
117 pin_name_t out2;
118 pin_name_t in1;
119 pin_name_t in2;
120
122
123 // End types group
124
125// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
126
132#ifdef __cplusplus
133extern "C"{
134#endif
135
145
153err_t opto3_init ( opto3_t *ctx, opto3_cfg_t *cfg );
154
162uint8_t opto3_get_in1 ( opto3_t *ctx );
163
171uint8_t opto3_get_in2 ( opto3_t *ctx );
172
181void opto3_set_out1 ( opto3_t *ctx, uint8_t state );
182
191void opto3_set_out2 ( opto3_t *ctx, uint8_t state );
192
193#ifdef __cplusplus
194}
195#endif
196#endif // _OPTO3_H_
197
198 // End public_function group
200
201// ------------------------------------------------------------------------- END
void opto3_set_out2(opto3_t *ctx, uint8_t state)
Set output 2.
uint8_t opto3_get_in2(opto3_t *ctx)
Get input 2.
void opto3_cfg_setup(opto3_cfg_t *cfg)
Config Object Initialization function.
void opto3_set_out1(opto3_t *ctx, uint8_t state)
Set output 1.
err_t opto3_init(opto3_t *ctx, opto3_cfg_t *cfg)
Initialization function.
uint8_t opto3_get_in1(opto3_t *ctx)
Get input 1.
Click configuration structure definition.
Definition opto3.h:114
pin_name_t in2
Definition opto3.h:119
pin_name_t out2
Definition opto3.h:117
pin_name_t in1
Definition opto3.h:118
pin_name_t out1
Definition opto3.h:116
Click ctx object definition.
Definition opto3.h:99
digital_in_t in2
Definition opto3.h:106
digital_in_t in1
Definition opto3.h:105
digital_out_t out1
Definition opto3.h:101
digital_out_t out2
Definition opto3.h:102