i2cisolator2 2.0.0.0
i2cisolator2.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef I2CISOLATOR2_H
36#define I2CISOLATOR2_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define I2CISOLATOR2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.pdis = MIKROBUS( mikrobus, MIKROBUS_PWM )
76#define I2CISOLATOR2_OK 0
77#define I2CISOLATOR2_ERROR -1
84#define I2CISOLATOR2_POWER_ENABLE 0
85#define I2CISOLATOR2_POWER_DISABLE 1
86
89 // End group macro
90// --------------------------------------------------------------- PUBLIC TYPES
99typedef struct
100{
101 // Output pins
102 digital_out_t pdis;
103
104 // Modules
105 i2c_master_t i2c;
106
107 // ctx variable
109
111
115typedef struct
116{
117 // Communication gpio pins
118 pin_name_t scl;
119 pin_name_t sda;
120
121 // Additional gpio pins
122 pin_name_t pdis;
123
124 // static variable
125 uint32_t i2c_speed;
126 uint8_t i2c_address;
127
129
130 // End types group
131// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
132
138#ifdef __cplusplus
139extern "C"{
140#endif
141
151
164
173void i2cisolator2_enable_power ( i2cisolator2_t *ctx, uint8_t state );
174
187err_t i2cisolator2_write ( i2cisolator2_t *ctx, uint8_t *data_in, uint16_t len );
188
201err_t i2cisolator2_read ( i2cisolator2_t *ctx, uint8_t *data_out, uint16_t len );
202
218err_t i2cisolator2_write_then_read ( i2cisolator2_t *ctx, uint8_t *data_in, uint16_t in_len,
219 uint8_t *data_out, uint16_t out_len );
220
232err_t i2cisolator2_set_slave_address ( i2cisolator2_t *ctx, uint8_t slave_addr );
233
234#ifdef __cplusplus
235}
236#endif
237#endif // _I2CISOLATOR2_H_
238
239 // End public_function group
241
242// ------------------------------------------------------------------------- END
void i2cisolator2_enable_power(i2cisolator2_t *ctx, uint8_t state)
This function sets PDIS pin state.
err_t i2cisolator2_write_then_read(i2cisolator2_t *ctx, uint8_t *data_in, uint16_t in_len, uint8_t *data_out, uint16_t out_len)
Generic write then read function.
err_t i2cisolator2_read(i2cisolator2_t *ctx, uint8_t *data_out, uint16_t len)
Generic read function.
err_t i2cisolator2_init(i2cisolator2_t *ctx, i2cisolator2_cfg_t *cfg)
Initialization function.
err_t i2cisolator2_set_slave_address(i2cisolator2_t *ctx, uint8_t slave_addr)
Set slave address function.
void i2cisolator2_cfg_setup(i2cisolator2_cfg_t *cfg)
Config Object Initialization function.
err_t i2cisolator2_write(i2cisolator2_t *ctx, uint8_t *data_in, uint16_t len)
Generic write function.
Click configuration structure definition.
Definition i2cisolator2.h:116
uint32_t i2c_speed
Definition i2cisolator2.h:125
pin_name_t scl
Definition i2cisolator2.h:118
pin_name_t pdis
Definition i2cisolator2.h:122
pin_name_t sda
Definition i2cisolator2.h:119
uint8_t i2c_address
Definition i2cisolator2.h:126
Click ctx object definition.
Definition i2cisolator2.h:100
digital_out_t pdis
Definition i2cisolator2.h:102
i2c_master_t i2c
Definition i2cisolator2.h:105
uint8_t slave_address
Definition i2cisolator2.h:108