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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define I2CMUX4_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define I2CMUX4_RETVAL uint8_t
64 
65 #define I2CMUX4_OK 0x00
66 #define I2CMUX4_INIT_ERROR 0xFF
67 
73 #define I2CMUX4_I2C_SLAVE_ADDRESS_0 0x70
74 #define I2CMUX4_I2C_SLAVE_ADDRESS_1 0x71
75 #define I2CMUX4_I2C_SLAVE_ADDRESS_2 0x72
76 #define I2CMUX4_I2C_SLAVE_ADDRESS_3 0x73
77 
83 #define I2CMUX4_ENABLE_POWER_OFF 0x00
84 #define I2CMUX4_ENABLE_POWER_ON 0x01
85 
91 #define I2CMUX4_SEL_CH_ALL_DISABLE 0x00
92 #define I2CMUX4_SEL_CH_0 0x01
93 #define I2CMUX4_SEL_CH_1 0x02
94 
100 #define I2CMUX4_INTERRUPT_CH_0 0x10
101 #define I2CMUX4_INTERRUPT_CH_1 0x20
102 #define I2CMUX4_INTERRUPT_BIT_MASK 0x30
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Output pins
118 
119  digital_out_t rst;
120 
121  // Input pins
122 
123  digital_in_t int_pin;
124 
125  // Modules
126 
127  i2c_master_t i2c;
128 
129  // ctx variable
130 
131  uint8_t slave_address;
132  uint8_t rmt_slave_addr;
133 
134 } i2cmux4_t;
135 
139 typedef struct
140 {
141  // Communication gpio pins
142 
143  pin_name_t scl;
144  pin_name_t sda;
145 
146  // Additional gpio pins
147 
148  pin_name_t rst;
149  pin_name_t int_pin;
150 
151  // static variable
152 
153  uint32_t i2c_speed;
154  uint8_t i2c_address;
155 
156 } i2cmux4_cfg_t;
157  // End types group
159 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
160 
166 #ifdef __cplusplus
167 extern "C"{
168 #endif
169 
178 void i2cmux4_cfg_setup ( i2cmux4_cfg_t *cfg );
179 
188 
199 void i2cmux4_generic_write ( i2cmux4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
200 
212 void i2cmux4_generic_read ( i2cmux4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
213 
222 void i2cmux4_power_on ( i2cmux4_t *ctx, uint8_t enable );
223 
234 void i2cmux4_hw_reset ( i2cmux4_t *ctx );
235 
247 void i2cmux4_write_cmd ( i2cmux4_t *ctx, uint8_t cmd_data );
248 
261 uint8_t i2cmux4_read_cmd ( i2cmux4_t *ctx );
262 
283 void i2cmux4_set_channel ( i2cmux4_t *ctx, uint8_t sel_ch, uint8_t ch_slave_addr );
284 
296 uint8_t i2cmux4_get_ch_interrupt ( i2cmux4_t *ctx );
297 
316 void i2cmux4_rmt_write_bytes ( i2cmux4_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
317 
336 void i2cmux4_rmt_read_bytes ( i2cmux4_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
337 
349 uint8_t i2cmux4_check_int ( i2cmux4_t *ctx );
350 
351 #ifdef __cplusplus
352 }
353 #endif
354 #endif // _I2CMUX4_H_
355  // End public_function group
358 
359 // ------------------------------------------------------------------------- END
i2cmux4_t::rmt_slave_addr
uint8_t rmt_slave_addr
Definition: i2cmux4.h:132
I2CMUX4_RETVAL
#define I2CMUX4_RETVAL
Definition: i2cmux4.h:63
i2cmux4_t::rst
digital_out_t rst
Definition: i2cmux4.h:119
i2cmux4_write_cmd
void i2cmux4_write_cmd(i2cmux4_t *ctx, uint8_t cmd_data)
Write command function.
i2cmux4_cfg_t::scl
pin_name_t scl
Definition: i2cmux4.h:143
i2cmux4_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2cmux4.h:154
i2cmux4_t::int_pin
digital_in_t int_pin
Definition: i2cmux4.h:123
i2cmux4_set_channel
void i2cmux4_set_channel(i2cmux4_t *ctx, uint8_t sel_ch, uint8_t ch_slave_addr)
Set channel function.
i2cmux4_t::slave_address
uint8_t slave_address
Definition: i2cmux4.h:131
i2cmux4_power_on
void i2cmux4_power_on(i2cmux4_t *ctx, uint8_t enable)
Power On function.
i2cmux4_t
Click ctx object definition.
Definition: i2cmux4.h:115
i2cmux4_cfg_setup
void i2cmux4_cfg_setup(i2cmux4_cfg_t *cfg)
Config Object Initialization function.
i2cmux4_hw_reset
void i2cmux4_hw_reset(i2cmux4_t *ctx)
Hardware reset function.
i2cmux4_cfg_t::int_pin
pin_name_t int_pin
Definition: i2cmux4.h:149
i2cmux4_read_cmd
uint8_t i2cmux4_read_cmd(i2cmux4_t *ctx)
Read command function.
i2cmux4_rmt_read_bytes
void i2cmux4_rmt_read_bytes(i2cmux4_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
Generic read data function.
i2cmux4_cfg_t::rst
pin_name_t rst
Definition: i2cmux4.h:148
i2cmux4_generic_write
void i2cmux4_generic_write(i2cmux4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
i2cmux4_check_int
uint8_t i2cmux4_check_int(i2cmux4_t *ctx)
Check interrupt function.
i2cmux4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2cmux4.h:153
i2cmux4_get_ch_interrupt
uint8_t i2cmux4_get_ch_interrupt(i2cmux4_t *ctx)
Get channel interrupt function.
i2cmux4_rmt_write_bytes
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.
i2cmux4_cfg_t::sda
pin_name_t sda
Definition: i2cmux4.h:144
i2cmux4_generic_read
void i2cmux4_generic_read(i2cmux4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
i2cmux4_cfg_t
Click configuration structure definition.
Definition: i2cmux4.h:139
i2cmux4_init
I2CMUX4_RETVAL i2cmux4_init(i2cmux4_t *ctx, i2cmux4_cfg_t *cfg)
Initialization function.
i2cmux4_t::i2c
i2c_master_t i2c
Definition: i2cmux4.h:127