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 struct
100{
101 // Output pins
102 digital_out_t gp1;
104 // Input pins
105 digital_in_t gp2;
107 // Modules
108 uart_t uart;
110 // Buffers
111 uint8_t uart_rx_buffer[ OPTO7_RX_DRV_BUFFER_SIZE ];
112 uint8_t uart_tx_buffer[ OPTO7_TX_DRV_BUFFER_SIZE ];
114} opto7_t;
115
120typedef struct
121{
122 // Communication gpio pins
123 pin_name_t rx_pin;
124 pin_name_t tx_pin;
126 // Additional gpio pins
127 pin_name_t gp1;
128 pin_name_t gp2;
130 // Static variable
131 uint32_t baud_rate;
133 uart_data_bits_t data_bit;
134 uart_parity_t parity_bit;
135 uart_stop_bits_t stop_bit;
138
143typedef enum
144{
146 OPTO7_ERROR = -1
147
149
166
180err_t opto7_init ( opto7_t *ctx, opto7_cfg_t *cfg );
181
195
208err_t opto7_generic_write ( opto7_t *ctx, uint8_t *data_in, uint16_t len );
209
222err_t opto7_generic_read ( opto7_t *ctx, uint8_t *data_out, uint16_t len );
223
233void opto7_set_gp1_pin( opto7_t *ctx, uint8_t pin_state );
234
245
246#ifdef __cplusplus
247}
248#endif
249#endif // OPTO7_H
250 // opto7
252
253// ------------------------------------------------------------------------ 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.
opto7_return_value_t
Opto 7 Click return value data.
Definition: opto7.h:144
@ OPTO7_OK
Definition: opto7.h:145
@ OPTO7_ERROR
Definition: opto7.h:146
Opto 7 Click configuration object.
Definition: opto7.h:121
uint32_t baud_rate
Definition: opto7.h:131
pin_name_t gp2
Definition: opto7.h:128
bool uart_blocking
Definition: opto7.h:132
uart_data_bits_t data_bit
Definition: opto7.h:133
pin_name_t tx_pin
Definition: opto7.h:124
pin_name_t rx_pin
Definition: opto7.h:123
uart_stop_bits_t stop_bit
Definition: opto7.h:135
pin_name_t gp1
Definition: opto7.h:127
uart_parity_t parity_bit
Definition: opto7.h:134
Opto 7 Click context object.
Definition: opto7.h:100
digital_in_t gp2
Definition: opto7.h:105
uart_t uart
Definition: opto7.h:108
digital_out_t gp1
Definition: opto7.h:102