opto7  2.1.0.0
opto7.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef OPTO7_H
29 #define OPTO7_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
73 #define OPTO7_PIN_STATE_HIGH 0x01
74 #define OPTO7_PIN_STATE_LOW 0x00
75 
81 #define OPTO7_TX_DRV_BUFFER_SIZE 100
82 #define OPTO7_RX_DRV_BUFFER_SIZE 300
83  // opto7_cmd
85 
100 #define OPTO7_MAP_MIKROBUS( cfg, mikrobus ) \
101  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
102  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
103  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
104  cfg.gp2 = MIKROBUS( mikrobus, MIKROBUS_INT );
105  // opto7_map // opto7
108 
113 typedef enum
114 {
119 
124 typedef struct
125 {
126  // Output pins
127  digital_out_t gp1;
129  // Input pins
130  digital_in_t gp2;
132  // Modules
133  uart_t uart;
135  // Buffers
136  uint8_t uart_rx_buffer[ OPTO7_RX_DRV_BUFFER_SIZE ];
137  uint8_t uart_tx_buffer[ OPTO7_TX_DRV_BUFFER_SIZE ];
141 } opto7_t;
142 
147 typedef struct
148 {
149  // Communication gpio pins
150  pin_name_t rx_pin;
151  pin_name_t tx_pin;
153  // Additional gpio pins
154  pin_name_t gp1;
155  pin_name_t gp2;
157  // Static variable
158  uint32_t baud_rate;
160  uart_data_bits_t data_bit;
161  uart_parity_t parity_bit;
162  uart_stop_bits_t stop_bit;
165 } opto7_cfg_t;
166 
171 typedef enum
172 {
173  OPTO7_OK = 0,
174  OPTO7_ERROR = -1
175 
177 
194 
210 
224 err_t opto7_init ( opto7_t *ctx, opto7_cfg_t *cfg );
225 
238 err_t opto7_default_cfg ( opto7_t *ctx );
239 
252 err_t opto7_generic_write ( opto7_t *ctx, uint8_t *data_in, uint16_t len );
253 
266 err_t opto7_generic_read ( opto7_t *ctx, uint8_t *data_out, uint16_t len );
267 
277 void opto7_set_gp1_pin( opto7_t *ctx, uint8_t pin_state );
278 
288 uint8_t opto7_get_gp2_pin( opto7_t *ctx );
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 #endif // OPTO7_H
294  // opto7
296 
297 // ------------------------------------------------------------------------ END
OPTO7_TX_DRV_BUFFER_SIZE
#define OPTO7_TX_DRV_BUFFER_SIZE
Opto 7 driver buffer size.
Definition: opto7.h:81
opto7_cfg_t::uart_blocking
bool uart_blocking
Definition: opto7.h:159
opto7_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: opto7.h:162
opto7_set_gp1_pin
void opto7_set_gp1_pin(opto7_t *ctx, uint8_t pin_state)
Opto 7 set GP1 pin function.
opto7_t::drv_sel
opto7_drv_t drv_sel
Definition: opto7.h:139
opto7_drv_t
opto7_drv_t
Opto 7 Click driver selector.
Definition: opto7.h:114
opto7_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: opto7.h:160
opto7_cfg_t::baud_rate
uint32_t baud_rate
Definition: opto7.h:158
opto7_generic_read
err_t opto7_generic_read(opto7_t *ctx, uint8_t *data_out, uint16_t len)
Opto 7 data reading function.
OPTO7_ERROR
@ OPTO7_ERROR
Definition: opto7.h:174
opto7_t::gp2
digital_in_t gp2
Definition: opto7.h:130
OPTO7_DRV_SEL_GPIO
@ OPTO7_DRV_SEL_GPIO
Definition: opto7.h:115
opto7_init
err_t opto7_init(opto7_t *ctx, opto7_cfg_t *cfg)
Opto 7 initialization function.
OPTO7_OK
@ OPTO7_OK
Definition: opto7.h:173
OPTO7_DRV_SEL_UART
@ OPTO7_DRV_SEL_UART
Definition: opto7.h:116
opto7_cfg_t::tx_pin
pin_name_t tx_pin
Definition: opto7.h:151
opto7_t
Opto 7 Click context object.
Definition: opto7.h:125
opto7_cfg_t::gp1
pin_name_t gp1
Definition: opto7.h:154
opto7_cfg_setup
void opto7_cfg_setup(opto7_cfg_t *cfg)
Opto 7 configuration object setup function.
opto7_cfg_t
Opto 7 Click configuration object.
Definition: opto7.h:148
opto7_cfg_t::gp2
pin_name_t gp2
Definition: opto7.h:155
opto7_drv_interface_selection
void opto7_drv_interface_selection(opto7_cfg_t *cfg, opto7_drv_t drv_sel)
Opto 7 driver interface setup function.
OPTO7_RX_DRV_BUFFER_SIZE
#define OPTO7_RX_DRV_BUFFER_SIZE
Definition: opto7.h:82
opto7_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: opto7.h:161
opto7_generic_write
err_t opto7_generic_write(opto7_t *ctx, uint8_t *data_in, uint16_t len)
Opto 7 data writing function.
opto7_cfg_t::rx_pin
pin_name_t rx_pin
Definition: opto7.h:150
opto7_default_cfg
err_t opto7_default_cfg(opto7_t *ctx)
Opto 7 default configuration function.
opto7_t::gp1
digital_out_t gp1
Definition: opto7.h:127
opto7_return_value_t
opto7_return_value_t
Opto 7 Click return value data.
Definition: opto7.h:172
opto7_get_gp2_pin
uint8_t opto7_get_gp2_pin(opto7_t *ctx)
Opto 7 get GP2 pin function.
opto7_cfg_t::drv_sel
opto7_drv_t drv_sel
Definition: opto7.h:163
opto7_t::uart
uart_t uart
Definition: opto7.h:133