mux5 2.1.0.0
mux5.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef MUX5_H
29#define MUX5_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define MUX5_REG_DIR0 0x00
76#define MUX5_REG_DIR1 0x01
77#define MUX5_REG_DIR2 0x02
78#define MUX5_REG_DIR3 0x03
79#define MUX5_REG_SHDW0 0x10
80#define MUX5_REG_SHDW1 0x11
81#define MUX5_REG_SHDW2 0x12
82#define MUX5_REG_SHDW3 0x13
83#define MUX5_REG_CMD_A 0x14
84#define MUX5_REG_CMD_B 0x15
85
86 // mux5_reg
87
102#define MUX5_I2C_DRIVER 0
103#define MUX5_SPI_DRIVER 1
104#define MUX5_DRIVER_SEL MUX5_I2C_DRIVER
105
110#define MUX5_CHANNEL_1 0x0001
111#define MUX5_CHANNEL_2 0x0002
112#define MUX5_CHANNEL_3 0x0004
113#define MUX5_CHANNEL_4 0x0008
114#define MUX5_CHANNEL_5 0x0010
115#define MUX5_CHANNEL_6 0x0020
116#define MUX5_CHANNEL_7 0x0040
117#define MUX5_CHANNEL_8 0x0080
118#define MUX5_CHANNEL_9 0x0100
119#define MUX5_CHANNEL_10 0x0200
120#define MUX5_CHANNEL_11 0x0400
121#define MUX5_CHANNEL_12 0x0800
122#define MUX5_CHANNEL_13 0x1000
123#define MUX5_CHANNEL_14 0x2000
124#define MUX5_CHANNEL_15 0x4000
125#define MUX5_CHANNEL_16 0x8000
126#define MUX5_CHANNEL_ALL 0xFFFF
127
132#define MUX5_CHANNEL_STATE_HIGH_Z 0
133#define MUX5_CHANNEL_STATE_COM_A 1
134#define MUX5_CHANNEL_STATE_COM_B 2
135#define MUX5_CHANNEL_STATE_COM_AB 3
136
142#define MUX5_DEVICE_ADDRESS_0 0x4C
143#define MUX5_DEVICE_ADDRESS_1 0x4D
144
153#define MUX5_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
154#define MUX5_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
155
156 // mux5_set
157
172#define MUX5_MAP_MIKROBUS( cfg, mikrobus ) \
173 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
174 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
175 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
176 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
177 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
178 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
179 cfg.com_b = MIKROBUS( mikrobus, MIKROBUS_AN ); \
180 cfg.sd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
181 cfg.com_a = MIKROBUS( mikrobus, MIKROBUS_INT )
182
183 // mux5_map
184 // mux5
185
190typedef struct mux5_s
191{
192 digital_out_t sd;
194 digital_in_t com_b;
195 digital_in_t com_a;
197#if ( MUX5_DRIVER_SEL == MUX5_SPI_DRIVER )
198 spi_master_t spi;
199 pin_name_t chip_select;
200#else
201 i2c_master_t i2c;
203#endif
204 uint16_t ch_a;
205 uint16_t ch_b;
208
213typedef struct
214{
215 pin_name_t scl;
216 pin_name_t sda;
217 pin_name_t miso;
218 pin_name_t mosi;
219 pin_name_t sck;
220 pin_name_t cs;
221 pin_name_t com_b;
222 pin_name_t sd;
223 pin_name_t com_a;
225 uint32_t i2c_speed;
226 uint8_t i2c_address;
228 uint32_t spi_speed;
229 spi_master_mode_t spi_mode;
230 spi_master_chip_select_polarity_t cs_polarity;
232} mux5_cfg_t;
233
238typedef enum
239{
241 MUX5_ERROR = -1
242
244
261
275err_t mux5_init ( mux5_t *ctx, mux5_cfg_t *cfg );
276
290
291#if ( MUX5_DRIVER_SEL == MUX5_I2C_DRIVER )
304err_t mux5_i2c_write_register ( mux5_t *ctx, uint8_t reg, uint8_t data_in );
305
318err_t mux5_i2c_read_register ( mux5_t *ctx, uint8_t reg, uint8_t *data_out );
319#endif
320
338err_t mux5_set_channels_state ( mux5_t *ctx, uint16_t ch_mask, uint8_t ch_state );
339
349
359
368uint8_t mux5_get_com_a_pin ( mux5_t *ctx );
369
378uint8_t mux5_get_com_b_pin ( mux5_t *ctx );
379
380#ifdef __cplusplus
381}
382#endif
383#endif // MUX5_H
384
385 // mux5
386
387// ------------------------------------------------------------------------ END
void mux5_enable_device(mux5_t *ctx)
MUX 5 enable device function.
err_t mux5_i2c_read_register(mux5_t *ctx, uint8_t reg, uint8_t *data_out)
MUX 5 I2C read register function.
uint8_t mux5_get_com_b_pin(mux5_t *ctx)
MUX 5 get com b pin function.
void mux5_cfg_setup(mux5_cfg_t *cfg)
MUX 5 configuration object setup function.
err_t mux5_default_cfg(mux5_t *ctx)
MUX 5 default configuration function.
uint8_t mux5_get_com_a_pin(mux5_t *ctx)
MUX 5 get com a pin function.
err_t mux5_set_channels_state(mux5_t *ctx, uint16_t ch_mask, uint8_t ch_state)
MUX 5 set channels state function.
err_t mux5_init(mux5_t *ctx, mux5_cfg_t *cfg)
MUX 5 initialization function.
err_t mux5_i2c_write_register(mux5_t *ctx, uint8_t reg, uint8_t data_in)
MUX 5 I2C write register function.
void mux5_disable_device(mux5_t *ctx)
MUX 5 disable device function.
struct mux5_s mux5_t
MUX 5 Click context object.
mux5_return_value_t
MUX 5 Click return value data.
Definition mux5.h:239
@ MUX5_ERROR
Definition mux5.h:241
@ MUX5_OK
Definition mux5.h:240
This file contains SPI specific macros, functions, etc.
MUX 5 Click configuration object.
Definition mux5.h:214
pin_name_t sd
Definition mux5.h:222
uint32_t i2c_speed
Definition mux5.h:225
pin_name_t com_a
Definition mux5.h:223
spi_master_chip_select_polarity_t cs_polarity
Definition mux5.h:230
pin_name_t sck
Definition mux5.h:219
spi_master_mode_t spi_mode
Definition mux5.h:229
pin_name_t com_b
Definition mux5.h:221
pin_name_t mosi
Definition mux5.h:218
uint32_t spi_speed
Definition mux5.h:228
pin_name_t scl
Definition mux5.h:215
pin_name_t miso
Definition mux5.h:217
pin_name_t sda
Definition mux5.h:216
pin_name_t cs
Definition mux5.h:220
uint8_t i2c_address
Definition mux5.h:226
MUX 5 Click context object.
Definition mux5.h:191
uint16_t ch_b
Definition mux5.h:205
digital_in_t com_a
Definition mux5.h:195
digital_out_t sd
Definition mux5.h:192
i2c_master_t i2c
Definition mux5.h:201
uint16_t ch_a
Definition mux5.h:204
uint8_t slave_address
Definition mux5.h:202
digital_in_t com_b
Definition mux5.h:194