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 "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_i2c_master.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
52#define I2CMUX_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 )
62#define I2CMUX_RETVAL uint8_t
63
64#define I2CMUX_OK 0x00
65#define I2CMUX_INIT_ERROR 0xFF
72#define I2CMUX_I2C_SLAVE_ADDRESS_0 0x70
73#define I2CMUX_I2C_SLAVE_ADDRESS_1 0x71
74#define I2CMUX_I2C_SLAVE_ADDRESS_2 0x72
75#define I2CMUX_I2C_SLAVE_ADDRESS_3 0x73
76#define I2CMUX_I2C_SLAVE_ADDRESS_4 0x74
77#define I2CMUX_I2C_SLAVE_ADDRESS_5 0x75
78#define I2CMUX_I2C_SLAVE_ADDRESS_6 0x76
79#define I2CMUX_I2C_SLAVE_ADDRESS_7 0x77
86#define I2CMUX_CMD_NO_CH 0x00
87#define I2CMUX_CMD_SET_CH_0 0x01
88#define I2CMUX_CMD_SET_CH_1 0x02
89#define I2CMUX_CMD_SET_CH_2 0x04
90#define I2CMUX_CMD_SET_CH_3 0x08 // End group macro
94// --------------------------------------------------------------- PUBLIC TYPES
103typedef struct
104{
105 // Output pins
106
107 digital_out_t rst;
108
109 // Modules
110
111 i2c_master_t i2c;
112
113 // ctx variable
114
116
117} i2cmux_t;
118
122typedef struct
123{
124 // Communication gpio pins
125
126 pin_name_t scl;
127 pin_name_t sda;
128
129 // Additional gpio pins
130
131 pin_name_t rst;
132
133 // static variable
134
135 uint32_t i2c_speed;
136 uint8_t i2c_address;
137
139 // End types group
141// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142
148#ifdef __cplusplus
149extern "C"{
150#endif
151
161
171
182void i2cmux_generic_write ( i2cmux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
183
194void i2cmux_generic_read ( i2cmux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
195
205
216void i2cmux_write_cmd ( i2cmux_t *ctx, uint8_t tx_data );
217
227uint8_t i2cmux_read_cmd ( i2cmux_t *ctx );
228
238void i2cmux_set_channel ( i2cmux_t *ctx, uint8_t channel, uint8_t ch_slave_address );
239
240#ifdef __cplusplus
241}
242#endif
243#endif // _I2CMUX_H_
244 // End public_function group
247
248// ------------------------------------------------------------------------- END
#define I2CMUX_RETVAL
Definition: i2cmux.h:62
I2CMUX_RETVAL i2cmux_init(i2cmux_t *ctx, i2cmux_cfg_t *cfg)
Initialization function.
void i2cmux_write_cmd(i2cmux_t *ctx, uint8_t tx_data)
Write command function.
void i2cmux_generic_read(i2cmux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void i2cmux_set_channel(i2cmux_t *ctx, uint8_t channel, uint8_t ch_slave_address)
Set channel function.
void i2cmux_cfg_setup(i2cmux_cfg_t *cfg)
Config Object Initialization function.
void i2cmux_generic_write(i2cmux_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void i2cmux_hw_reset(i2cmux_t *ctx)
Hardware reset function.
uint8_t i2cmux_read_cmd(i2cmux_t *ctx)
Read command function.
Click configuration structure definition.
Definition: i2cmux.h:123
uint32_t i2c_speed
Definition: i2cmux.h:135
pin_name_t scl
Definition: i2cmux.h:126
pin_name_t sda
Definition: i2cmux.h:127
pin_name_t rst
Definition: i2cmux.h:131
uint8_t i2c_address
Definition: i2cmux.h:136
Click ctx object definition.
Definition: i2cmux.h:104
i2c_master_t i2c
Definition: i2cmux.h:111
digital_out_t rst
Definition: i2cmux.h:107
uint8_t slave_address
Definition: i2cmux.h:115