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
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_uart.h"
38
59#define OPTO7_PIN_STATE_HIGH 0x01
60#define OPTO7_PIN_STATE_LOW 0x00
61
67#define OPTO7_TX_DRV_BUFFER_SIZE 100
68#define OPTO7_RX_DRV_BUFFER_SIZE 300
69 // opto7_cmd
71
86#define OPTO7_MAP_MIKROBUS( cfg, mikrobus ) \
87 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
88 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
89 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
90 cfg.gp2 = MIKROBUS( mikrobus, MIKROBUS_INT );
91 // opto7_map // opto7
94
99typedef enum
100{
105
110typedef struct
111{
112 // Output pins
113 digital_out_t gp1;
115 // Input pins
116 digital_in_t gp2;
118 // Modules
119 uart_t uart;
121 // Buffers
122 uint8_t uart_rx_buffer[ OPTO7_RX_DRV_BUFFER_SIZE ];
123 uint8_t uart_tx_buffer[ OPTO7_TX_DRV_BUFFER_SIZE ];
127} opto7_t;
128
133typedef struct
134{
135 // Communication gpio pins
136 pin_name_t rx_pin;
137 pin_name_t tx_pin;
139 // Additional gpio pins
140 pin_name_t gp1;
141 pin_name_t gp2;
143 // Static variable
144 uint32_t baud_rate;
146 uart_data_bits_t data_bit;
147 uart_parity_t parity_bit;
148 uart_stop_bits_t stop_bit;
152
157typedef enum
158{
160 OPTO7_ERROR = -1
161
163
180
196
210err_t opto7_init ( opto7_t *ctx, opto7_cfg_t *cfg );
211
225
238err_t opto7_generic_write ( opto7_t *ctx, uint8_t *data_in, uint16_t len );
239
252err_t opto7_generic_read ( opto7_t *ctx, uint8_t *data_out, uint16_t len );
253
263void opto7_set_gp1_pin( opto7_t *ctx, uint8_t pin_state );
264
275
276#ifdef __cplusplus
277}
278#endif
279#endif // OPTO7_H
280 // opto7
282
283// ------------------------------------------------------------------------ END
#define OPTO7_TX_DRV_BUFFER_SIZE
Opto 7 driver buffer size.
Definition: opto7.h:67
#define OPTO7_RX_DRV_BUFFER_SIZE
Definition: opto7.h:68
err_t opto7_generic_read(opto7_t *ctx, uint8_t *data_out, uint16_t len)
Opto 7 data reading function.
err_t opto7_default_cfg(opto7_t *ctx)
Opto 7 default configuration function.
uint8_t opto7_get_gp2_pin(opto7_t *ctx)
Opto 7 get GP2 pin function.
err_t opto7_generic_write(opto7_t *ctx, uint8_t *data_in, uint16_t len)
Opto 7 data writing function.
void opto7_set_gp1_pin(opto7_t *ctx, uint8_t pin_state)
Opto 7 set GP1 pin function.
void opto7_cfg_setup(opto7_cfg_t *cfg)
Opto 7 configuration object setup function.
err_t opto7_init(opto7_t *ctx, opto7_cfg_t *cfg)
Opto 7 initialization function.
void opto7_drv_interface_selection(opto7_cfg_t *cfg, opto7_drv_t drv_sel)
Opto 7 driver interface setup function.
opto7_drv_t
Opto 7 Click driver selector.
Definition: opto7.h:100
@ OPTO7_DRV_SEL_GPIO
Definition: opto7.h:101
@ OPTO7_DRV_SEL_UART
Definition: opto7.h:102
opto7_return_value_t
Opto 7 Click return value data.
Definition: opto7.h:158
@ OPTO7_OK
Definition: opto7.h:159
@ OPTO7_ERROR
Definition: opto7.h:160
Opto 7 Click configuration object.
Definition: opto7.h:134
uint32_t baud_rate
Definition: opto7.h:144
opto7_drv_t drv_sel
Definition: opto7.h:149
pin_name_t gp2
Definition: opto7.h:141
bool uart_blocking
Definition: opto7.h:145
uart_data_bits_t data_bit
Definition: opto7.h:146
pin_name_t tx_pin
Definition: opto7.h:137
pin_name_t rx_pin
Definition: opto7.h:136
uart_stop_bits_t stop_bit
Definition: opto7.h:148
pin_name_t gp1
Definition: opto7.h:140
uart_parity_t parity_bit
Definition: opto7.h:147
Opto 7 Click context object.
Definition: opto7.h:111
opto7_drv_t drv_sel
Definition: opto7.h:125
digital_in_t gp2
Definition: opto7.h:116
uart_t uart
Definition: opto7.h:119
digital_out_t gp1
Definition: opto7.h:113