i2cmux  2.0.0.0
i2cmux.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 I2CMUX_H
36 #define I2CMUX_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define I2CMUX_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
66 
72 #define I2CMUX_RETVAL uint8_t
73 
74 #define I2CMUX_OK 0x00
75 #define I2CMUX_INIT_ERROR 0xFF
76 
82 #define I2CMUX_I2C_SLAVE_ADDRESS_0 0x70
83 #define I2CMUX_I2C_SLAVE_ADDRESS_1 0x71
84 #define I2CMUX_I2C_SLAVE_ADDRESS_2 0x72
85 #define I2CMUX_I2C_SLAVE_ADDRESS_3 0x73
86 #define I2CMUX_I2C_SLAVE_ADDRESS_4 0x74
87 #define I2CMUX_I2C_SLAVE_ADDRESS_5 0x75
88 #define I2CMUX_I2C_SLAVE_ADDRESS_6 0x76
89 #define I2CMUX_I2C_SLAVE_ADDRESS_7 0x77
90 
96 #define I2CMUX_CMD_NO_CH 0x00
97 #define I2CMUX_CMD_SET_CH_0 0x01
98 #define I2CMUX_CMD_SET_CH_1 0x02
99 #define I2CMUX_CMD_SET_CH_2 0x04
100 #define I2CMUX_CMD_SET_CH_3 0x08
101  // End group macro
104 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  // Output pins
116 
117  digital_out_t rst;
118 
119  // Modules
120 
121  i2c_master_t i2c;
122 
123  // ctx variable
124 
125  uint8_t slave_address;
126 
127 } i2cmux_t;
128 
132 typedef struct
133 {
134  // Communication gpio pins
135 
136  pin_name_t scl;
137  pin_name_t sda;
138 
139  // Additional gpio pins
140 
141  pin_name_t rst;
142 
143  // static variable
144 
145  uint32_t i2c_speed;
146  uint8_t i2c_address;
147 
148 } i2cmux_cfg_t;
149  // End types group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
181 
192 void i2cmux_generic_write ( i2cmux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
193 
204 void i2cmux_generic_read ( i2cmux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
205 
214 void i2cmux_hw_reset ( i2cmux_t *ctx );
215 
226 void i2cmux_write_cmd ( i2cmux_t *ctx, uint8_t tx_data );
227 
237 uint8_t i2cmux_read_cmd ( i2cmux_t *ctx );
238 
248 void i2cmux_set_channel ( i2cmux_t *ctx, uint8_t channel, uint8_t ch_slave_address );
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // _I2CMUX_H_
254  // End public_function group
257 
258 // ------------------------------------------------------------------------- END
i2cmux_t::i2c
i2c_master_t i2c
Definition: i2cmux.h:121
i2cmux_write_cmd
void i2cmux_write_cmd(i2cmux_t *ctx, uint8_t tx_data)
Write command function.
i2cmux_cfg_t::sda
pin_name_t sda
Definition: i2cmux.h:137
i2cmux_t
Click ctx object definition.
Definition: i2cmux.h:114
i2cmux_cfg_setup
void i2cmux_cfg_setup(i2cmux_cfg_t *cfg)
Config Object Initialization function.
i2cmux_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2cmux.h:146
I2CMUX_RETVAL
#define I2CMUX_RETVAL
Definition: i2cmux.h:72
i2cmux_cfg_t
Click configuration structure definition.
Definition: i2cmux.h:133
i2cmux_read_cmd
uint8_t i2cmux_read_cmd(i2cmux_t *ctx)
Read command function.
i2cmux_set_channel
void i2cmux_set_channel(i2cmux_t *ctx, uint8_t channel, uint8_t ch_slave_address)
Set channel function.
i2cmux_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2cmux.h:145
i2cmux_cfg_t::scl
pin_name_t scl
Definition: i2cmux.h:136
i2cmux_t::slave_address
uint8_t slave_address
Definition: i2cmux.h:125
i2cmux_init
I2CMUX_RETVAL i2cmux_init(i2cmux_t *ctx, i2cmux_cfg_t *cfg)
Initialization function.
i2cmux_t::rst
digital_out_t rst
Definition: i2cmux.h:117
i2cmux_generic_read
void i2cmux_generic_read(i2cmux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
i2cmux_cfg_t::rst
pin_name_t rst
Definition: i2cmux.h:141
i2cmux_hw_reset
void i2cmux_hw_reset(i2cmux_t *ctx)
Hardware reset function.
i2cmux_generic_write
void i2cmux_generic_write(i2cmux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.