spiisolator2 2.0.0.0
spiisolator2.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 SPIISOLATOR2_H
29#define SPIISOLATOR2_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
78#define SPIISOLATOR2_EEPROM5_CMD_WREN 0x06
79#define SPIISOLATOR2_EEPROM5_CMD_WRDI 0x04
80#define SPIISOLATOR2_EEPROM5_CMD_RDSR 0x05
81#define SPIISOLATOR2_EEPROM5_CMD_WRSR 0x01
82#define SPIISOLATOR2_EEPROM5_CMD_READ 0x03
83#define SPIISOLATOR2_EEPROM5_CMD_WRITE 0x02
84#define SPIISOLATOR2_EEPROM5_CMD_READ_ID 0x83
85#define SPIISOLATOR2_EEPROM5_CMD_WRITE_ID 0x82
86#define SPIISOLATOR2_EEPROM5_CMD_READ_LOCK_STATUS 0x83
87#define SPIISOLATOR2_EEPROM5_CMD_LOCK_ID 0x82
88
89#define SPIISOLATOR2_OUT_DISABLE 0x00
90#define SPIISOLATOR2_OUT_ENABLE 0x01
91
92#define SPIISOLATOR2_DUMMY 0x00
93
94 // spiisolator2_set
95
110#define SPIISOLATOR2_MAP_MIKROBUS( cfg, mikrobus ) \
111 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
112 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
113 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
114 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
115 cfg.en1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
116
117 // spiisolator2_map
118 // spiisolator2
119
124typedef struct
125{
126 // Output pins
127 digital_out_t en1;
129 // Modules
130 spi_master_t spi;
132 pin_name_t chip_select;
135
140typedef struct
141{
142 // Communication gpio pins
143 pin_name_t miso;
144 pin_name_t mosi;
145 pin_name_t sck;
146 pin_name_t cs;
148 // Additional gpio pins
149 pin_name_t en1;
151 // static variable
152 uint32_t spi_speed;
153 spi_master_mode_t spi_mode;
154 spi_master_chip_select_polarity_t cs_polarity;
157
168
185
200
215err_t spiisolator2_generic_write ( spiisolator2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
216
231err_t spiisolator2_generic_read ( spiisolator2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
232
243void spiisolator2_output_enable( spiisolator2_t *ctx, uint8_t en_out );
244
255void spiisolator2_set_cmd ( spiisolator2_t *ctx, uint8_t cmd );
256
269void spiisolator2_write_byte ( spiisolator2_t *ctx, uint8_t reg, uint8_t tx_data );
270
282uint8_t spiisolator2_read_byte ( spiisolator2_t *ctx, uint8_t reg );
283
297void spiisolator2_burst_write ( spiisolator2_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
298
312void spiisolator2_burst_read ( spiisolator2_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
313
328void spiisolator2_multi_write ( spiisolator2_t *ctx, uint32_t addr, uint8_t addr_n_bytes,
329 uint8_t *p_tx_data, uint8_t tx_data_n_bytes );
330
345void spiisolator2_multi_read ( spiisolator2_t *ctx, uint32_t addr, uint8_t addr_n_bytes,
346 uint8_t *p_rx_data, uint8_t tx_data_n_bytes );
347
348#ifdef __cplusplus
349}
350#endif
351#endif // SPIISOLATOR2_H
352
353 // spiisolator2
354
355// ------------------------------------------------------------------------ END
void spiisolator2_cfg_setup(spiisolator2_cfg_t *cfg)
SPI Isolator 2 configuration object setup function.
err_t spiisolator2_init(spiisolator2_t *ctx, spiisolator2_cfg_t *cfg)
SPI Isolator 2 initialization function.
void spiisolator2_set_cmd(spiisolator2_t *ctx, uint8_t cmd)
SPI Isolator 2 send command function.
uint8_t spiisolator2_read_byte(spiisolator2_t *ctx, uint8_t reg)
SPI Isolator 2 read the byte of data function.
void spiisolator2_multi_read(spiisolator2_t *ctx, uint32_t addr, uint8_t addr_n_bytes, uint8_t *p_rx_data, uint8_t tx_data_n_bytes)
SPI Isolator 2 multi read function.
void spiisolator2_burst_write(spiisolator2_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes)
SPI Isolator 2 burst write function.
err_t spiisolator2_generic_write(spiisolator2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
SPI Isolator 2 data writing function.
void spiisolator2_write_byte(spiisolator2_t *ctx, uint8_t reg, uint8_t tx_data)
SPI Isolator 2 write the byte of data function.
err_t spiisolator2_generic_read(spiisolator2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
SPI Isolator 2 data reading function.
void spiisolator2_multi_write(spiisolator2_t *ctx, uint32_t addr, uint8_t addr_n_bytes, uint8_t *p_tx_data, uint8_t tx_data_n_bytes)
SPI Isolator 2 multi write function.
void spiisolator2_burst_read(spiisolator2_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
SPI Isolator 2 burst read function.
void spiisolator2_output_enable(spiisolator2_t *ctx, uint8_t en_out)
SPI Isolator 2 output enable function.
spiisolator2_return_value_t
SPI Isolator 2 Click return value data.
Definition spiisolator2.h:163
@ SPIISOLATOR2_ERROR
Definition spiisolator2.h:165
@ SPIISOLATOR2_OK
Definition spiisolator2.h:164
SPI Isolator 2 Click configuration object.
Definition spiisolator2.h:141
spi_master_chip_select_polarity_t cs_polarity
Definition spiisolator2.h:154
pin_name_t sck
Definition spiisolator2.h:145
spi_master_mode_t spi_mode
Definition spiisolator2.h:153
pin_name_t en1
Definition spiisolator2.h:149
pin_name_t mosi
Definition spiisolator2.h:144
uint32_t spi_speed
Definition spiisolator2.h:152
pin_name_t miso
Definition spiisolator2.h:143
pin_name_t cs
Definition spiisolator2.h:146
SPI Isolator 2 Click context object.
Definition spiisolator2.h:125
spi_master_t spi
Definition spiisolator2.h:130
digital_out_t en1
Definition spiisolator2.h:127
pin_name_t chip_select
Definition spiisolator2.h:132