i2cmux4 2.0.0.0
i2cmux4.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 I2CMUX4_H
36#define I2CMUX4_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 I2CMUX4_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define I2CMUX4_RETVAL uint8_t
78
79#define I2CMUX4_OK 0x00
80#define I2CMUX4_INIT_ERROR 0xFF
87#define I2CMUX4_I2C_SLAVE_ADDRESS_0 0x70
88#define I2CMUX4_I2C_SLAVE_ADDRESS_1 0x71
89#define I2CMUX4_I2C_SLAVE_ADDRESS_2 0x72
90#define I2CMUX4_I2C_SLAVE_ADDRESS_3 0x73
97#define I2CMUX4_ENABLE_POWER_OFF 0x00
98#define I2CMUX4_ENABLE_POWER_ON 0x01
105#define I2CMUX4_SEL_CH_ALL_DISABLE 0x00
106#define I2CMUX4_SEL_CH_0 0x01
107#define I2CMUX4_SEL_CH_1 0x02
114#define I2CMUX4_INTERRUPT_CH_0 0x10
115#define I2CMUX4_INTERRUPT_CH_1 0x20
116#define I2CMUX4_INTERRUPT_BIT_MASK 0x30
119 // End group macro
120// --------------------------------------------------------------- PUBLIC TYPES
129typedef struct
130{
131 // Output pins
132
133 digital_out_t rst;
134
135 // Input pins
136
137 digital_in_t int_pin;
138
139 // Modules
140
141 i2c_master_t i2c;
142
143 // ctx variable
144
147
148} i2cmux4_t;
149
153typedef struct
154{
155 // Communication gpio pins
156
157 pin_name_t scl;
158 pin_name_t sda;
159
160 // Additional gpio pins
161
162 pin_name_t rst;
163 pin_name_t int_pin;
164
165 // static variable
166
167 uint32_t i2c_speed;
168 uint8_t i2c_address;
169
171
172 // End types group
173// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174
180#ifdef __cplusplus
181extern "C"{
182#endif
183
193
202
213void i2cmux4_generic_write ( i2cmux4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
214
226void i2cmux4_generic_read ( i2cmux4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227
236void i2cmux4_power_on ( i2cmux4_t *ctx, uint8_t enable );
237
249
261void i2cmux4_write_cmd ( i2cmux4_t *ctx, uint8_t cmd_data );
262
276
297void i2cmux4_set_channel ( i2cmux4_t *ctx, uint8_t sel_ch, uint8_t ch_slave_addr );
298
311
330void i2cmux4_rmt_write_bytes ( i2cmux4_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
331
350void i2cmux4_rmt_read_bytes ( i2cmux4_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
351
364
365#ifdef __cplusplus
366}
367#endif
368#endif // _I2CMUX4_H_
369
370 // End public_function group
372
373// ------------------------------------------------------------------------- END
#define I2CMUX4_RETVAL
Definition i2cmux4.h:77
uint8_t i2cmux4_check_int(i2cmux4_t *ctx)
Check interrupt function.
void i2cmux4_write_cmd(i2cmux4_t *ctx, uint8_t cmd_data)
Write command function.
uint8_t i2cmux4_get_ch_interrupt(i2cmux4_t *ctx)
Get channel interrupt function.
void i2cmux4_cfg_setup(i2cmux4_cfg_t *cfg)
Config Object Initialization function.
void i2cmux4_power_on(i2cmux4_t *ctx, uint8_t enable)
Power On function.
I2CMUX4_RETVAL i2cmux4_init(i2cmux4_t *ctx, i2cmux4_cfg_t *cfg)
Initialization function.
void i2cmux4_generic_write(i2cmux4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void i2cmux4_set_channel(i2cmux4_t *ctx, uint8_t sel_ch, uint8_t ch_slave_addr)
Set channel function.
uint8_t i2cmux4_read_cmd(i2cmux4_t *ctx)
Read command function.
void i2cmux4_hw_reset(i2cmux4_t *ctx)
Hardware reset function.
void i2cmux4_rmt_read_bytes(i2cmux4_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
Generic read data function.
void i2cmux4_rmt_write_bytes(i2cmux4_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes)
Generic rmt write data function.
void i2cmux4_generic_read(i2cmux4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
Click configuration structure definition.
Definition i2cmux4.h:154
uint32_t i2c_speed
Definition i2cmux4.h:167
pin_name_t scl
Definition i2cmux4.h:157
pin_name_t int_pin
Definition i2cmux4.h:163
pin_name_t sda
Definition i2cmux4.h:158
pin_name_t rst
Definition i2cmux4.h:162
uint8_t i2c_address
Definition i2cmux4.h:168
Click ctx object definition.
Definition i2cmux4.h:130
uint8_t rmt_slave_addr
Definition i2cmux4.h:146
digital_in_t int_pin
Definition i2cmux4.h:137
i2c_master_t i2c
Definition i2cmux4.h:141
digital_out_t rst
Definition i2cmux4.h:133
uint8_t slave_address
Definition i2cmux4.h:145