digiisolator2 2.1.0.0
digiisolator2.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 DIGIISOLATOR2_H
29#define DIGIISOLATOR2_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
74#define DIGIISOLATOR2_REG_INPUT_DATA 0x00
75#define DIGIISOLATOR2_REG_WIRE_BREAK 0x01
76#define DIGIISOLATOR2_REG_FAULT 0x02
77#define DIGIISOLATOR2_REG_FILTER_CH1_CH2 0x03
78#define DIGIISOLATOR2_REG_FILTER_CH3_CH4 0x04
79#define DIGIISOLATOR2_REG_FILTER_CH5_CH6 0x05
80#define DIGIISOLATOR2_REG_FILTER_CH7_CH8 0x06
81
82 // digiisolator2_reg
83
98#define DIGIISOLATOR2_CHANNEL_IN1 0x01
99#define DIGIISOLATOR2_CHANNEL_IN2 0x02
100#define DIGIISOLATOR2_CHANNEL_IN3 0x04
101#define DIGIISOLATOR2_CHANNEL_IN4 0x08
102#define DIGIISOLATOR2_CHANNEL_IN5 0x10
103#define DIGIISOLATOR2_CHANNEL_IN6 0x20
104#define DIGIISOLATOR2_CHANNEL_IN7 0x40
105#define DIGIISOLATOR2_CHANNEL_IN8 0x80
106#define DIGIISOLATOR2_CHANNEL_ALL 0xFF
107
116#define DIGIISOLATOR2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
117#define DIGIISOLATOR2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
118
119 // digiisolator2_set
120
135#define DIGIISOLATOR2_MAP_MIKROBUS( cfg, mikrobus ) \
136 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
137 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
138 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
139 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
140 cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN ); \
141 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
142 cfg.sync = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
143 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
144
145 // digiisolator2_map
146 // digiisolator2
147
158
163typedef struct
164{
165 // Output pins in SPI mode
166 digital_out_t en;
167 digital_out_t rst;
169 // Input pins in SPI mode
170 digital_in_t sync;
171 digital_in_t int_pin;
173 // Input pins in GPIO mode
174 digital_in_t out1;
175 digital_in_t out2;
176 digital_in_t out3;
177 digital_in_t out4;
178 digital_in_t out5;
179 digital_in_t out6;
180 digital_in_t out8;
182 // Modules
183 spi_master_t spi;
185 pin_name_t chip_select;
190
195typedef struct
196{
197 pin_name_t miso;
198 pin_name_t mosi;
199 pin_name_t sck;
200 pin_name_t cs;
202 pin_name_t en;
203 pin_name_t rst;
204 pin_name_t sync;
205 pin_name_t int_pin;
207 uint32_t spi_speed;
208 spi_master_mode_t spi_mode;
209 spi_master_chip_select_polarity_t cs_polarity;
214
225
242
258
273
286err_t digiisolator2_spi_write ( digiisolator2_t *ctx, uint8_t reg, uint8_t data_in );
287
300err_t digiisolator2_spi_read ( digiisolator2_t *ctx, uint8_t reg, uint8_t *data_out );
301
311void digiisolator2_set_rst_pin ( digiisolator2_t *ctx, uint8_t state );
312
322
332
344err_t digiisolator2_read_inputs ( digiisolator2_t *ctx, uint8_t *data_out );
345
355
365
375
385
395
405
415
425
435
436#ifdef __cplusplus
437}
438#endif
439#endif // DIGIISOLATOR2_H
440
441 // digiisolator2
442
443// ------------------------------------------------------------------------ END
digiisolator2_drv_t
DIGI Isolator 2 Click driver selector.
Definition digiisolator2.h:153
@ DIGIISOLATOR2_DRV_SEL_SPI
Definition digiisolator2.h:154
@ DIGIISOLATOR2_DRV_SEL_GPIO
Definition digiisolator2.h:155
digiisolator2_return_value_t
DIGI Isolator 2 Click return value data.
Definition digiisolator2.h:220
@ DIGIISOLATOR2_OK
Definition digiisolator2.h:221
@ DIGIISOLATOR2_ERROR
Definition digiisolator2.h:222
uint8_t digiisolator2_get_out1_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get out1 pin function.
uint8_t digiisolator2_get_out4_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get out4 pin function.
uint8_t digiisolator2_get_out2_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get out2 pin function.
void digiisolator2_drv_interface_sel(digiisolator2_cfg_t *cfg, digiisolator2_drv_t drv_sel)
DIGI Isolator 2 driver interface setup function.
uint8_t digiisolator2_get_out3_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get out3 pin function.
uint8_t digiisolator2_get_out8_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get out8 pin function.
err_t digiisolator2_read_inputs(digiisolator2_t *ctx, uint8_t *data_out)
DIGI Isolator 2 read inputs function.
uint8_t digiisolator2_get_out6_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get out6 pin function.
err_t digiisolator2_init(digiisolator2_t *ctx, digiisolator2_cfg_t *cfg)
DIGI Isolator 2 initialization function.
uint8_t digiisolator2_get_sync_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get sync pin function.
err_t digiisolator2_spi_write(digiisolator2_t *ctx, uint8_t reg, uint8_t data_in)
DIGI Isolator 2 SPI writing function.
void digiisolator2_set_rst_pin(digiisolator2_t *ctx, uint8_t state)
DIGI Isolator 2 set rst pin function.
void digiisolator2_enable_output(digiisolator2_t *ctx)
DIGI Isolator 2 enable output function.
void digiisolator2_disable_output(digiisolator2_t *ctx)
DIGI Isolator 2 disable output function.
uint8_t digiisolator2_get_out5_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get out5 pin function.
uint8_t digiisolator2_get_int_pin(digiisolator2_t *ctx)
DIGI Isolator 2 get int pin function.
void digiisolator2_cfg_setup(digiisolator2_cfg_t *cfg)
DIGI Isolator 2 configuration object setup function.
err_t digiisolator2_spi_read(digiisolator2_t *ctx, uint8_t reg, uint8_t *data_out)
DIGI Isolator 2 SPI reading function.
This file contains SPI specific macros, functions, etc.
DIGI Isolator 2 Click configuration object.
Definition digiisolator2.h:196
pin_name_t sync
Definition digiisolator2.h:204
spi_master_chip_select_polarity_t cs_polarity
Definition digiisolator2.h:209
pin_name_t sck
Definition digiisolator2.h:199
spi_master_mode_t spi_mode
Definition digiisolator2.h:208
pin_name_t mosi
Definition digiisolator2.h:198
uint32_t spi_speed
Definition digiisolator2.h:207
pin_name_t en
Definition digiisolator2.h:202
pin_name_t int_pin
Definition digiisolator2.h:205
pin_name_t miso
Definition digiisolator2.h:197
digiisolator2_drv_t drv_sel
Definition digiisolator2.h:211
pin_name_t rst
Definition digiisolator2.h:203
pin_name_t cs
Definition digiisolator2.h:200
DIGI Isolator 2 Click context object.
Definition digiisolator2.h:164
digital_in_t out6
Definition digiisolator2.h:179
spi_master_t spi
Definition digiisolator2.h:183
digital_in_t sync
Definition digiisolator2.h:170
digital_in_t out1
Definition digiisolator2.h:174
digital_in_t out2
Definition digiisolator2.h:175
digital_in_t out5
Definition digiisolator2.h:178
digital_in_t out8
Definition digiisolator2.h:180
digital_in_t int_pin
Definition digiisolator2.h:171
digital_in_t out3
Definition digiisolator2.h:176
digital_in_t out4
Definition digiisolator2.h:177
digital_out_t en
Definition digiisolator2.h:166
digital_out_t rst
Definition digiisolator2.h:167
digiisolator2_drv_t drv_sel
Definition digiisolator2.h:187
pin_name_t chip_select
Definition digiisolator2.h:185