i2cmux7 2.0.0.0
i2cmux7.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 I2CMUX7_H
29#define I2CMUX7_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_i2c_master.h"
52
73#define I2CMUX7_CHANNEL_DISABLE 0x00
74#define I2CMUX7_CHANNEL_0 0x08
75#define I2CMUX7_CHANNEL_1 0x09
76#define I2CMUX7_CHANNEL_2 0x0A
77#define I2CMUX7_CHANNEL_3 0x0B
78#define I2CMUX7_CHANNEL_4 0x0C
79#define I2CMUX7_CHANNEL_5 0x0D
80#define I2CMUX7_CHANNEL_6 0x0E
81#define I2CMUX7_CHANNEL_7 0x0F
82#define I2CMUX7_CHANNEL_NUM_MASK 0x07
83
89#define I2CMUX7_DEV_ADDR_A2A1A0_000 0x70
90#define I2CMUX7_DEV_ADDR_A2A1A0_001 0x71
91#define I2CMUX7_DEV_ADDR_A2A1A0_010 0x72
92#define I2CMUX7_DEV_ADDR_A2A1A0_011 0x73
93#define I2CMUX7_DEV_ADDR_A2A1A0_100 0x74
94#define I2CMUX7_DEV_ADDR_A2A1A0_101 0x75
95#define I2CMUX7_DEV_ADDR_A2A1A0_110 0x76
96#define I2CMUX7_DEV_ADDR_A2A1A0_111 0x77
97
98 // i2cmux7_set
99
114#define I2CMUX7_MAP_MIKROBUS( cfg, mikrobus ) \
115 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
116 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
117 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
118
119 // i2cmux7_map
120 // i2cmux7
121
126typedef struct
127{
128 // Output pins
129 digital_out_t rst;
131 // Modules
132 i2c_master_t i2c;
134 // I2C slave address
138} i2cmux7_t;
139
144typedef struct
145{
146 pin_name_t scl;
147 pin_name_t sda;
149 pin_name_t rst;
151 uint32_t i2c_speed;
152 uint8_t i2c_address;
155
160typedef enum
161{
163 I2CMUX7_ERROR = -1
164
166
183
199
212err_t i2cmux7_set_channel ( i2cmux7_t *ctx, uint8_t ch_sel, uint8_t ch_slave_addr );
213
225err_t i2cmux7_read_channel ( i2cmux7_t *ctx, uint8_t *ch_sel );
226
236
251err_t i2cmux7_generic_write ( i2cmux7_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
252
267err_t i2cmux7_generic_read ( i2cmux7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
268
269#ifdef __cplusplus
270}
271#endif
272#endif // I2CMUX7_H
273
274 // i2cmux7
275
276// ------------------------------------------------------------------------ END
err_t i2cmux7_generic_write(i2cmux7_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
I2C MUX 7 I2C writing function.
err_t i2cmux7_read_channel(i2cmux7_t *ctx, uint8_t *ch_sel)
I2C MUX 7 read channel function.
err_t i2cmux7_init(i2cmux7_t *ctx, i2cmux7_cfg_t *cfg)
I2C MUX 7 initialization function.
err_t i2cmux7_generic_read(i2cmux7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
I2C MUX 7 I2C reading function.
void i2cmux7_cfg_setup(i2cmux7_cfg_t *cfg)
I2C MUX 7 configuration object setup function.
err_t i2cmux7_set_channel(i2cmux7_t *ctx, uint8_t ch_sel, uint8_t ch_slave_addr)
I2C MUX 7 set channel function.
void i2cmux7_reset_device(i2cmux7_t *ctx)
I2C MUX 7 reset device function.
i2cmux7_return_value_t
I2C MUX 7 Click return value data.
Definition i2cmux7.h:161
@ I2CMUX7_ERROR
Definition i2cmux7.h:163
@ I2CMUX7_OK
Definition i2cmux7.h:162
I2C MUX 7 Click configuration object.
Definition i2cmux7.h:145
uint32_t i2c_speed
Definition i2cmux7.h:151
pin_name_t scl
Definition i2cmux7.h:146
pin_name_t sda
Definition i2cmux7.h:147
pin_name_t rst
Definition i2cmux7.h:149
uint8_t i2c_address
Definition i2cmux7.h:152
I2C MUX 7 Click context object.
Definition i2cmux7.h:127
uint8_t ch_slave_address
Definition i2cmux7.h:136
i2c_master_t i2c
Definition i2cmux7.h:132
digital_out_t rst
Definition i2cmux7.h:129
uint8_t slave_address
Definition i2cmux7.h:135