digiisolator 2.1.0.0
digiisolator.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 DIGIISOLATOR_H
29#define DIGIISOLATOR_H
30
31#ifdef __cplusplus
32extern "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_spi_master.h"
52#include "spi_specifics.h"
53#include "drv_uart.h"
54#include "drv_analog_in.h"
55
76#define DIGIISOLATOR_VREF_3V3 3.3
77#define DIGIISOLATOR_VREF_5V 5.0
78
84#define DIGIISOLATOR_TX_DRV_BUFFER_SIZE 100
85#define DIGIISOLATOR_RX_DRV_BUFFER_SIZE 300
86
95#define DIGIISOLATOR_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
96#define DIGIISOLATOR_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
97
98 // digiisolator_set
99
114#define DIGIISOLATOR_MAP_MIKROBUS( cfg, mikrobus ) \
115 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
116 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
117 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
118 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
119 cfg.d1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
120 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
121 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
122 cfg.d2 = MIKROBUS( mikrobus, MIKROBUS_INT )
123
124 // digiisolator_map
125 // digiisolator
126
131typedef struct
132{
133 // Input pins
134 analog_in_t adc;
135 digital_in_t d2;
137 // Modules
138 spi_master_t spi;
139 uart_t uart;
141 pin_name_t chip_select;
143 // Buffers
144 char uart_rx_buffer[ DIGIISOLATOR_RX_DRV_BUFFER_SIZE ];
145 char uart_tx_buffer[ DIGIISOLATOR_TX_DRV_BUFFER_SIZE ];
148
153typedef struct
154{
155 // Communication gpio pins
156 pin_name_t miso;
157 pin_name_t mosi;
158 pin_name_t sck;
159 pin_name_t cs;
160 pin_name_t rx_pin;
161 pin_name_t tx_pin;
163 // Additional gpio pins
164 pin_name_t d1;
165 pin_name_t d2;
167 // Static variable
168 uint32_t spi_speed;
169 spi_master_mode_t spi_mode;
170 spi_master_chip_select_polarity_t cs_polarity;
171 uint32_t baud_rate;
173 uart_data_bits_t data_bit;
174 uart_parity_t parity_bit;
175 uart_stop_bits_t stop_bit;
177 analog_in_resolution_t resolution;
178 float vref;
181
192
209
224
238err_t digiisolator_spi_write ( digiisolator_t *ctx, uint8_t *data_in, uint8_t len );
239
253err_t digiisolator_spi_read ( digiisolator_t *ctx, uint8_t *data_out, uint8_t len );
254
270err_t digiisolator_spi_write_read ( digiisolator_t *ctx, uint8_t *data_in, uint8_t len_in, uint8_t *data_out, uint8_t len_out );
271
286err_t digiisolator_spi_transfer ( digiisolator_t *ctx, uint8_t *data_in, uint8_t *data_out, uint8_t len );
287
301err_t digiisolator_uart_write ( digiisolator_t *ctx, char *data_in, uint16_t len );
302
315err_t digiisolator_uart_read ( digiisolator_t *ctx, char *data_out, uint16_t len );
316
328err_t digiisolator_get_d1_pin_value ( digiisolator_t *ctx, uint16_t *data_out );
329
343err_t digiisolator_get_d1_pin_voltage ( digiisolator_t *ctx, float *data_out );
344
355
356#ifdef __cplusplus
357}
358#endif
359#endif // DIGIISOLATOR_H
360
361 // digiisolator
362
363// ------------------------------------------------------------------------ END
digiisolator_return_value_t
DIGI Isolator Click return value data.
Definition digiisolator.h:187
@ DIGIISOLATOR_OK
Definition digiisolator.h:188
@ DIGIISOLATOR_ERROR
Definition digiisolator.h:189
#define DIGIISOLATOR_TX_DRV_BUFFER_SIZE
DIGI Isolator driver buffer size.
Definition digiisolator.h:84
#define DIGIISOLATOR_RX_DRV_BUFFER_SIZE
Definition digiisolator.h:85
err_t digiisolator_get_d1_pin_voltage(digiisolator_t *ctx, float *data_out)
DIGI Isolator read D1 pin voltage level function.
err_t digiisolator_uart_read(digiisolator_t *ctx, char *data_out, uint16_t len)
DIGI Isolator UART data reading function.
err_t digiisolator_spi_transfer(digiisolator_t *ctx, uint8_t *data_in, uint8_t *data_out, uint8_t len)
DIGI Isolator SPI transfer function.
err_t digiisolator_uart_write(digiisolator_t *ctx, char *data_in, uint16_t len)
DIGI Isolator UART data writing function.
err_t digiisolator_get_d1_pin_value(digiisolator_t *ctx, uint16_t *data_out)
DIGI Isolator read D1 pin value function.
err_t digiisolator_spi_write(digiisolator_t *ctx, uint8_t *data_in, uint8_t len)
DIGI Isolator SPI data writing function.
void digiisolator_cfg_setup(digiisolator_cfg_t *cfg)
DIGI Isolator configuration object setup function.
uint8_t digiisolator_get_d2(digiisolator_t *ctx)
DIGI Isolator get D2 function.
err_t digiisolator_spi_write_read(digiisolator_t *ctx, uint8_t *data_in, uint8_t len_in, uint8_t *data_out, uint8_t len_out)
DIGI Isolator SPI write then read function.
err_t digiisolator_spi_read(digiisolator_t *ctx, uint8_t *data_out, uint8_t len)
DIGI Isolator SPI data reading function.
err_t digiisolator_init(digiisolator_t *ctx, digiisolator_cfg_t *cfg)
DIGI Isolator initialization function.
This file contains SPI specific macros, functions, etc.
DIGI Isolator Click configuration object.
Definition digiisolator.h:154
uint32_t baud_rate
Definition digiisolator.h:171
analog_in_resolution_t resolution
Definition digiisolator.h:177
float vref
Definition digiisolator.h:178
spi_master_chip_select_polarity_t cs_polarity
Definition digiisolator.h:170
bool uart_blocking
Definition digiisolator.h:172
pin_name_t sck
Definition digiisolator.h:158
uart_data_bits_t data_bit
Definition digiisolator.h:173
spi_master_mode_t spi_mode
Definition digiisolator.h:169
pin_name_t d1
Definition digiisolator.h:164
pin_name_t tx_pin
Definition digiisolator.h:161
pin_name_t mosi
Definition digiisolator.h:157
uint32_t spi_speed
Definition digiisolator.h:168
pin_name_t d2
Definition digiisolator.h:165
pin_name_t rx_pin
Definition digiisolator.h:160
uart_stop_bits_t stop_bit
Definition digiisolator.h:175
pin_name_t miso
Definition digiisolator.h:156
uart_parity_t parity_bit
Definition digiisolator.h:174
pin_name_t cs
Definition digiisolator.h:159
DIGI Isolator Click context object.
Definition digiisolator.h:132
spi_master_t spi
Definition digiisolator.h:138
digital_in_t d2
Definition digiisolator.h:135
uart_t uart
Definition digiisolator.h:139
pin_name_t chip_select
Definition digiisolator.h:141
analog_in_t adc
Definition digiisolator.h:134