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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define I2CMUX7_CHANNEL_DISABLE 0x00
70 #define I2CMUX7_CHANNEL_0 0x08
71 #define I2CMUX7_CHANNEL_1 0x09
72 #define I2CMUX7_CHANNEL_2 0x0A
73 #define I2CMUX7_CHANNEL_3 0x0B
74 #define I2CMUX7_CHANNEL_4 0x0C
75 #define I2CMUX7_CHANNEL_5 0x0D
76 #define I2CMUX7_CHANNEL_6 0x0E
77 #define I2CMUX7_CHANNEL_7 0x0F
78 #define I2CMUX7_CHANNEL_NUM_MASK 0x07
79 
85 #define I2CMUX7_DEV_ADDR_A2A1A0_000 0x70
86 #define I2CMUX7_DEV_ADDR_A2A1A0_001 0x71
87 #define I2CMUX7_DEV_ADDR_A2A1A0_010 0x72
88 #define I2CMUX7_DEV_ADDR_A2A1A0_011 0x73
89 #define I2CMUX7_DEV_ADDR_A2A1A0_100 0x74
90 #define I2CMUX7_DEV_ADDR_A2A1A0_101 0x75
91 #define I2CMUX7_DEV_ADDR_A2A1A0_110 0x76
92 #define I2CMUX7_DEV_ADDR_A2A1A0_111 0x77
93  // i2cmux7_set
95 
110 #define I2CMUX7_MAP_MIKROBUS( cfg, mikrobus ) \
111  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
112  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
113  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
114  // i2cmux7_map // i2cmux7
117 
122 typedef struct
123 {
124  // Output pins
125  digital_out_t rst;
127  // Modules
128  i2c_master_t i2c;
130  // I2C slave address
131  uint8_t slave_address;
134 } i2cmux7_t;
135 
140 typedef struct
141 {
142  pin_name_t scl;
143  pin_name_t sda;
145  pin_name_t rst;
147  uint32_t i2c_speed;
148  uint8_t i2c_address;
150 } i2cmux7_cfg_t;
151 
156 typedef enum
157 {
159  I2CMUX7_ERROR = -1
160 
162 
179 
194 err_t i2cmux7_init ( i2cmux7_t *ctx, i2cmux7_cfg_t *cfg );
195 
208 err_t i2cmux7_set_channel ( i2cmux7_t *ctx, uint8_t ch_sel, uint8_t ch_slave_addr );
209 
221 err_t i2cmux7_read_channel ( i2cmux7_t *ctx, uint8_t *ch_sel );
222 
232 
247 err_t i2cmux7_generic_write ( i2cmux7_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
248 
263 err_t i2cmux7_generic_read ( i2cmux7_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif // I2CMUX7_H
269  // i2cmux7
271 
272 // ------------------------------------------------------------------------ END
i2cmux7_cfg_t::sda
pin_name_t sda
Definition: i2cmux7.h:143
i2cmux7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2cmux7.h:147
i2cmux7_t::i2c
i2c_master_t i2c
Definition: i2cmux7.h:128
i2cmux7_t::ch_slave_address
uint8_t ch_slave_address
Definition: i2cmux7.h:132
i2cmux7_t::slave_address
uint8_t slave_address
Definition: i2cmux7.h:131
i2cmux7_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2cmux7.h:148
i2cmux7_cfg_setup
void i2cmux7_cfg_setup(i2cmux7_cfg_t *cfg)
I2C MUX 7 configuration object setup function.
i2cmux7_set_channel
err_t i2cmux7_set_channel(i2cmux7_t *ctx, uint8_t ch_sel, uint8_t ch_slave_addr)
I2C MUX 7 set channel function.
i2cmux7_cfg_t::rst
pin_name_t rst
Definition: i2cmux7.h:145
i2cmux7_init
err_t i2cmux7_init(i2cmux7_t *ctx, i2cmux7_cfg_t *cfg)
I2C MUX 7 initialization function.
i2cmux7_read_channel
err_t i2cmux7_read_channel(i2cmux7_t *ctx, uint8_t *ch_sel)
I2C MUX 7 read channel function.
i2cmux7_generic_write
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.
i2cmux7_reset_device
void i2cmux7_reset_device(i2cmux7_t *ctx)
I2C MUX 7 reset device function.
I2CMUX7_OK
@ I2CMUX7_OK
Definition: i2cmux7.h:158
i2cmux7_t
I2C MUX 7 Click context object.
Definition: i2cmux7.h:123
I2CMUX7_ERROR
@ I2CMUX7_ERROR
Definition: i2cmux7.h:159
i2cmux7_cfg_t::scl
pin_name_t scl
Definition: i2cmux7.h:142
i2cmux7_return_value_t
i2cmux7_return_value_t
I2C MUX 7 Click return value data.
Definition: i2cmux7.h:157
i2cmux7_generic_read
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.
i2cmux7_cfg_t
I2C MUX 7 Click configuration object.
Definition: i2cmux7.h:141
i2cmux7_t::rst
digital_out_t rst
Definition: i2cmux7.h:125