i2cmux2  2.0.0.0
i2cmux2.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 I2CMUX2_H
36 #define I2CMUX2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define I2CMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
58 
64 #define I2CMUX2_RETVAL uint8_t
65 
66 #define I2CMUX2_OK 0x00
67 #define I2CMUX2_INIT_ERROR 0xFF
68 
70 // Device address
71 #define I2CMUX2_I2C_SLAVE_ADDRESS_0 0x70
72 #define I2CMUX2_I2C_SLAVE_ADDRESS_1 0x71
73 #define I2CMUX2_I2C_SLAVE_ADDRESS_2 0x72
74 #define I2CMUX2_I2C_SLAVE_ADDRESS_3 0x73
75 #define I2CMUX2_I2C_SLAVE_ADDRESS_4 0x74
76 #define I2CMUX2_I2C_SLAVE_ADDRESS_5 0x75
77 #define I2CMUX2_I2C_SLAVE_ADDRESS_6 0x76
78 #define I2CMUX2_I2C_SLAVE_ADDRESS_7 0x77
79 
80 // Set channel
81 #define I2CMUX2_CMD_NO_CH 0x00
82 #define I2CMUX2_CMD_SET_CH_0 0x01
83 #define I2CMUX2_CMD_SET_CH_1 0x02
84 #define I2CMUX2_CMD_SET_CH_2 0x04
85 #define I2CMUX2_CMD_SET_CH_3 0x08
86 
87 // Interrupt bit mask
88 #define I2CMUX2_INT_BITS 0xF0
89 
90 // Interrupt of channel
91 #define I2CMUX2_INT_NO_CH 0x00
92 #define I2CMUX2_INT_CH_0 0x01
93 #define I2CMUX2_INT_CH_1 0x02
94 #define I2CMUX2_INT_CH_2 0x04
95 #define I2CMUX2_INT_CH_3 0x08
96 
97 // Interrupt pin state
98 #define I2CMUX2_INT_PIN_STATE_ACTIVE 0x00
99 #define I2CMUX2_INT_PIN_STATE_NOT_ACTIVE 0x01
100  // End group macro
102 // --------------------------------------------------------------- PUBLIC TYPES
111 typedef struct
112 {
113  // Output pins
114 
115  digital_out_t rst;
116 
117  // Input pins
118 
119  digital_in_t int_pin;
120 
121  // Modules
122 
123  i2c_master_t i2c;
124 
125  // ctx variable
126 
127  uint8_t slave_address;
128 
129 } i2cmux2_t;
130 
134 typedef struct
135 {
136  // Communication gpio pins
137 
138  pin_name_t scl;
139  pin_name_t sda;
140 
141  // Additional gpio pins
142 
143  pin_name_t rst;
144  pin_name_t int_pin;
145 
146  // static variable
147 
148  uint32_t i2c_speed;
149  uint8_t i2c_address;
150 
151 } i2cmux2_cfg_t;
152  // End types group
154 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
155 
161 #ifdef __cplusplus
162 extern "C"{
163 #endif
164 
173 void i2cmux2_cfg_setup ( i2cmux2_cfg_t *cfg );
174 
184 
195 void i2cmux2_generic_write ( i2cmux2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
196 
208 void i2cmux2_generic_read ( i2cmux2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
209 
218 void i2cmux2_hw_reset ( i2cmux2_t *ctx );
219 
229 void i2cmux2_write_cmd ( i2cmux2_t *ctx, uint8_t tx_data );
230 
242 uint8_t i2cmux2_read_cmd ( i2cmux2_t *ctx );
243 
254 void i2cmux2_set_channel ( i2cmux2_t *ctx, uint8_t channel, uint8_t ch_slave_address );
255 
271 uint8_t i2cmux2_read_interrupt ( i2cmux2_t *ctx );
272 
286 uint8_t i2cmux2_check_int ( i2cmux2_t *ctx );
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 #endif // _I2CMUX2_H_
292  // End public_function group
295 
296 // ------------------------------------------------------------------------- END
i2cmux2_read_interrupt
uint8_t i2cmux2_read_interrupt(i2cmux2_t *ctx)
Read interrupt status function.
i2cmux2_generic_write
void i2cmux2_generic_write(i2cmux2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
i2cmux2_t::rst
digital_out_t rst
Definition: i2cmux2.h:115
i2cmux2_generic_read
void i2cmux2_generic_read(i2cmux2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
i2cmux2_t::i2c
i2c_master_t i2c
Definition: i2cmux2.h:123
i2cmux2_read_cmd
uint8_t i2cmux2_read_cmd(i2cmux2_t *ctx)
Read command function.
i2cmux2_cfg_t::int_pin
pin_name_t int_pin
Definition: i2cmux2.h:144
i2cmux2_set_channel
void i2cmux2_set_channel(i2cmux2_t *ctx, uint8_t channel, uint8_t ch_slave_address)
Set channel function.
i2cmux2_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2cmux2.h:149
i2cmux2_t::int_pin
digital_in_t int_pin
Definition: i2cmux2.h:119
i2cmux2_cfg_t::sda
pin_name_t sda
Definition: i2cmux2.h:139
i2cmux2_cfg_t::rst
pin_name_t rst
Definition: i2cmux2.h:143
i2cmux2_cfg_setup
void i2cmux2_cfg_setup(i2cmux2_cfg_t *cfg)
Config Object Initialization function.
i2cmux2_t::slave_address
uint8_t slave_address
Definition: i2cmux2.h:127
i2cmux2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2cmux2.h:148
i2cmux2_init
I2CMUX2_RETVAL i2cmux2_init(i2cmux2_t *ctx, i2cmux2_cfg_t *cfg)
Initialization function.
i2cmux2_write_cmd
void i2cmux2_write_cmd(i2cmux2_t *ctx, uint8_t tx_data)
Write command function.
i2cmux2_check_int
uint8_t i2cmux2_check_int(i2cmux2_t *ctx)
Check interrupt status function.
I2CMUX2_RETVAL
#define I2CMUX2_RETVAL
Definition: i2cmux2.h:64
i2cmux2_cfg_t::scl
pin_name_t scl
Definition: i2cmux2.h:138
i2cmux2_hw_reset
void i2cmux2_hw_reset(i2cmux2_t *ctx)
Hardware reset function.
i2cmux2_t
Click ctx object definition.
Definition: i2cmux2.h:111
i2cmux2_cfg_t
Click configuration structure definition.
Definition: i2cmux2.h:134