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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define I2CISOLATOR2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.pdis = MIKROBUS( mikrobus, MIKROBUS_PWM )
56 
62 #define I2CISOLATOR2_RETVAL uint8_t
63 
64 #define I2CISOLATOR2_OK 0x00
65 #define I2CISOLATOR2_INIT_ERROR 0xFF
66 
72 #define I2CISOLATOR2_POWER_ENABLE 0x00
73 #define I2CISOLATOR2_POWER_DISABLE 0x01
74  // End group macro
78 // --------------------------------------------------------------- PUBLIC TYPES
87 typedef struct
88 {
89  // Output pins
90 
91  digital_out_t pdis;
92 
93  // Modules
94 
95  i2c_master_t i2c;
96 
97  // ctx variable
98 
99  uint8_t slave_address;
100 
102 
106 typedef struct
107 {
108  // Communication gpio pins
109 
110  pin_name_t scl;
111  pin_name_t sda;
112 
113  // Additional gpio pins
114 
115  pin_name_t pdis;
116 
117  // static variable
118 
119  uint32_t i2c_speed;
120  uint8_t i2c_address;
121 
123  // End types group
125 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
126 
132 #ifdef __cplusplus
133 extern "C"{
134 #endif
135 
145 
155 
164 void i2cisolator2_enable_power ( i2cisolator2_t *ctx, uint8_t state );
165 
176 void i2cisolator2_generic_write ( i2cisolator2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
177 
188 void i2cisolator2_generic_read ( i2cisolator2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
189 
200 void i2cisolator2_write_two_byte_reg ( i2cisolator2_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len );
201 
212 void i2cisolator2_read_two_byte_reg ( i2cisolator2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
213 
222 void i2cisolator2_set_slave_address ( i2cisolator2_t *ctx, uint8_t slave_addr );
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 #endif // _I2CISOLATOR2_H_
228  // End public_function group
231 
232 // ------------------------------------------------------------------------- END
i2cisolator2_t
Click ctx object definition.
Definition: i2cisolator2.h:88
i2cisolator2_read_two_byte_reg
void i2cisolator2_read_two_byte_reg(i2cisolator2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function for two-byte registers.
i2cisolator2_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2cisolator2.h:120
i2cisolator2_enable_power
void i2cisolator2_enable_power(i2cisolator2_t *ctx, uint8_t state)
This function sets PDIS pin state.
i2cisolator2_cfg_setup
void i2cisolator2_cfg_setup(i2cisolator2_cfg_t *cfg)
Config Object Initialization function.
i2cisolator2_t::slave_address
uint8_t slave_address
Definition: i2cisolator2.h:99
i2cisolator2_init
I2CISOLATOR2_RETVAL i2cisolator2_init(i2cisolator2_t *ctx, i2cisolator2_cfg_t *cfg)
Initialization function.
i2cisolator2_cfg_t::scl
pin_name_t scl
Definition: i2cisolator2.h:110
i2cisolator2_cfg_t::sda
pin_name_t sda
Definition: i2cisolator2.h:111
i2cisolator2_generic_read
void i2cisolator2_generic_read(i2cisolator2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
i2cisolator2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2cisolator2.h:119
i2cisolator2_cfg_t::pdis
pin_name_t pdis
Definition: i2cisolator2.h:115
i2cisolator2_t::i2c
i2c_master_t i2c
Definition: i2cisolator2.h:95
i2cisolator2_generic_write
void i2cisolator2_generic_write(i2cisolator2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
i2cisolator2_t::pdis
digital_out_t pdis
Definition: i2cisolator2.h:91
I2CISOLATOR2_RETVAL
#define I2CISOLATOR2_RETVAL
Definition: i2cisolator2.h:62
i2cisolator2_write_two_byte_reg
void i2cisolator2_write_two_byte_reg(i2cisolator2_t *ctx, uint16_t reg, uint8_t *data_buf, uint8_t len)
Generic write function for two-byte registers.
i2cisolator2_cfg_t
Click configuration structure definition.
Definition: i2cisolator2.h:107
i2cisolator2_set_slave_address
void i2cisolator2_set_slave_address(i2cisolator2_t *ctx, uint8_t slave_addr)
Set slave address function.