i2cmux3  2.0.0.0
i2cmux3.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 I2CMUX3_H
36 #define I2CMUX3_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 I2CMUX3_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 
62 #define I2CMUX3_RETVAL uint8_t
63 
64 #define I2CMUX3_OK 0x00
65 #define I2CMUX3_INIT_ERROR 0xFF
66 
72 #define I2CMUX3_DEV_ADR_0 0x70
73 #define I2CMUX3_DEV_ADR_1 0x71
74 #define I2CMUX3_DEV_ADR_2 0x72
75 #define I2CMUX3_DEV_ADR_3 0x73
76 #define I2CMUX3_DEV_ADR_4 0x74
77 #define I2CMUX3_DEV_ADR_5 0x75
78 #define I2CMUX3_DEV_ADR_6 0x76
79 #define I2CMUX3_DEV_ADR_7 0x77
80 
86 #define I2CMUX3_DIS_ALL_CH 0x00
87 #define I2CMUX3_SEL_CH_0 0x01
88 #define I2CMUX3_SEL_CH_1 0x02
89 #define I2CMUX3_SEL_CH_2 0x04
90 #define I2CMUX3_SEL_CH_3 0x08
91 #define I2CMUX3_SEL_CH_4 0x10
92 #define I2CMUX3_SEL_CH_5 0x20
93 #define I2CMUX3_SEL_CH_6 0x40
94 #define I2CMUX3_SEL_CH_7 0x80
95 
101 #define I2CMUX3_DEV_DIS 0x00
102 #define I2CMUX3_DEV_EN 0x01
103  // End group macro
106 // --------------------------------------------------------------- PUBLIC TYPES
115 typedef struct
116 {
117  // Output pins
118 
119  digital_out_t rst;
120 
121  // Modules
122 
123  i2c_master_t i2c;
124 
125  // ctx variable
126 
127  uint8_t slave_address;
128 
129 } i2cmux3_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 
145  // static variable
146 
147  uint32_t i2c_speed;
148  uint8_t i2c_address;
149 
150 } i2cmux3_cfg_t;
151  // End types group
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154 
160 #ifdef __cplusplus
161 extern "C"{
162 #endif
163 
172 void i2cmux3_cfg_setup ( i2cmux3_cfg_t *cfg );
173 
182 
193 void i2cmux3_generic_write ( i2cmux3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
194 
206 void i2cmux3_generic_read ( i2cmux3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
207 
216 void i2cmux3_write_ctl ( i2cmux3_t *ctx, uint8_t wr_data );
217 
227 uint8_t i2cmux3_read_ctl ( i2cmux3_t *ctx );
228 
239 void i2cmux3_ch_sel ( i2cmux3_t *ctx, uint8_t sel_ch );
240 
254 void i2cmux3_wr_slv ( i2cmux3_t *ctx, uint8_t slv_sel_adr, uint8_t reg, uint8_t *p_wr_data,
255  uint8_t n_bytes );
256 
270 void i2cmux3_rd_slv ( i2cmux3_t *ctx, uint8_t slv_sel_adr, uint8_t reg, uint8_t *p_rd_data,
271  uint8_t n_bytes );
272 
283 void i2cmux3_dev_enable ( i2cmux3_t *ctx, uint8_t stat );
284 
293 void i2cmux3_hw_rst ( i2cmux3_t *ctx );
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 #endif // _I2CMUX3_H_
299  // End public_function group
302 
303 // ------------------------------------------------------------------------- END
i2cmux3_generic_write
void i2cmux3_generic_write(i2cmux3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
i2cmux3_init
I2CMUX3_RETVAL i2cmux3_init(i2cmux3_t *ctx, i2cmux3_cfg_t *cfg)
Initialization function.
i2cmux3_dev_enable
void i2cmux3_dev_enable(i2cmux3_t *ctx, uint8_t stat)
Device enable function.
i2cmux3_write_ctl
void i2cmux3_write_ctl(i2cmux3_t *ctx, uint8_t wr_data)
Write Control Register function.
i2cmux3_cfg_t::i2c_address
uint8_t i2c_address
Definition: i2cmux3.h:148
i2cmux3_t::rst
digital_out_t rst
Definition: i2cmux3.h:119
i2cmux3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: i2cmux3.h:147
i2cmux3_hw_rst
void i2cmux3_hw_rst(i2cmux3_t *ctx)
Hardware reset function.
i2cmux3_t::i2c
i2c_master_t i2c
Definition: i2cmux3.h:123
i2cmux3_wr_slv
void i2cmux3_wr_slv(i2cmux3_t *ctx, uint8_t slv_sel_adr, uint8_t reg, uint8_t *p_wr_data, uint8_t n_bytes)
Slave Device Write function.
I2CMUX3_RETVAL
#define I2CMUX3_RETVAL
Definition: i2cmux3.h:62
i2cmux3_generic_read
void i2cmux3_generic_read(i2cmux3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
i2cmux3_cfg_t::rst
pin_name_t rst
Definition: i2cmux3.h:143
i2cmux3_rd_slv
void i2cmux3_rd_slv(i2cmux3_t *ctx, uint8_t slv_sel_adr, uint8_t reg, uint8_t *p_rd_data, uint8_t n_bytes)
Slave Device Read function.
i2cmux3_cfg_t::scl
pin_name_t scl
Definition: i2cmux3.h:138
i2cmux3_t
Click ctx object definition.
Definition: i2cmux3.h:115
i2cmux3_cfg_setup
void i2cmux3_cfg_setup(i2cmux3_cfg_t *cfg)
Config Object Initialization function.
i2cmux3_read_ctl
uint8_t i2cmux3_read_ctl(i2cmux3_t *ctx)
Read Control Register function.
i2cmux3_cfg_t::sda
pin_name_t sda
Definition: i2cmux3.h:139
i2cmux3_ch_sel
void i2cmux3_ch_sel(i2cmux3_t *ctx, uint8_t sel_ch)
Select Channel function.
i2cmux3_cfg_t
Click configuration structure definition.
Definition: i2cmux3.h:134
i2cmux3_t::slave_address
uint8_t slave_address
Definition: i2cmux3.h:127