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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_spi_master.h"
39 #include "spi_specifics.h"
40 
61 #define MUX5_REG_DIR0 0x00
62 #define MUX5_REG_DIR1 0x01
63 #define MUX5_REG_DIR2 0x02
64 #define MUX5_REG_DIR3 0x03
65 #define MUX5_REG_SHDW0 0x10
66 #define MUX5_REG_SHDW1 0x11
67 #define MUX5_REG_SHDW2 0x12
68 #define MUX5_REG_SHDW3 0x13
69 #define MUX5_REG_CMD_A 0x14
70 #define MUX5_REG_CMD_B 0x15
71  // mux5_reg
73 
88 #define MUX5_I2C_DRIVER 0
89 #define MUX5_SPI_DRIVER 1
90 #define MUX5_DRIVER_SEL MUX5_I2C_DRIVER
91 
96 #define MUX5_CHANNEL_1 0x0001
97 #define MUX5_CHANNEL_2 0x0002
98 #define MUX5_CHANNEL_3 0x0004
99 #define MUX5_CHANNEL_4 0x0008
100 #define MUX5_CHANNEL_5 0x0010
101 #define MUX5_CHANNEL_6 0x0020
102 #define MUX5_CHANNEL_7 0x0040
103 #define MUX5_CHANNEL_8 0x0080
104 #define MUX5_CHANNEL_9 0x0100
105 #define MUX5_CHANNEL_10 0x0200
106 #define MUX5_CHANNEL_11 0x0400
107 #define MUX5_CHANNEL_12 0x0800
108 #define MUX5_CHANNEL_13 0x1000
109 #define MUX5_CHANNEL_14 0x2000
110 #define MUX5_CHANNEL_15 0x4000
111 #define MUX5_CHANNEL_16 0x8000
112 #define MUX5_CHANNEL_ALL 0xFFFF
113 
118 #define MUX5_CHANNEL_STATE_HIGH_Z 0
119 #define MUX5_CHANNEL_STATE_COM_A 1
120 #define MUX5_CHANNEL_STATE_COM_B 2
121 #define MUX5_CHANNEL_STATE_COM_AB 3
122 
128 #define MUX5_DEVICE_ADDRESS_0 0x4C
129 #define MUX5_DEVICE_ADDRESS_1 0x4D
130 
139 #define MUX5_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
140 #define MUX5_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
141  // mux5_set
143 
158 #define MUX5_MAP_MIKROBUS( cfg, mikrobus ) \
159  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
160  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
161  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
162  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
163  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
164  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
165  cfg.com_b = MIKROBUS( mikrobus, MIKROBUS_AN ); \
166  cfg.sd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
167  cfg.com_a = MIKROBUS( mikrobus, MIKROBUS_INT )
168  // mux5_map // mux5
171 
176 typedef struct mux5_s
177 {
178  digital_out_t sd;
180  digital_in_t com_b;
181  digital_in_t com_a;
183 #if ( MUX5_DRIVER_SEL == MUX5_SPI_DRIVER )
184  spi_master_t spi;
185  pin_name_t chip_select;
186 #else
187  i2c_master_t i2c;
188  uint8_t slave_address;
189 #endif
190  uint16_t ch_a;
191  uint16_t ch_b;
194 
199 typedef struct
200 {
201  pin_name_t scl;
202  pin_name_t sda;
203  pin_name_t miso;
204  pin_name_t mosi;
205  pin_name_t sck;
206  pin_name_t cs;
207  pin_name_t com_b;
208  pin_name_t sd;
209  pin_name_t com_a;
211  uint32_t i2c_speed;
212  uint8_t i2c_address;
214  uint32_t spi_speed;
215  spi_master_mode_t spi_mode;
216  spi_master_chip_select_polarity_t cs_polarity;
218 } mux5_cfg_t;
219 
224 typedef enum
225 {
226  MUX5_OK = 0,
227  MUX5_ERROR = -1
228 
230 
247 
261 err_t mux5_init ( mux5_t *ctx, mux5_cfg_t *cfg );
262 
275 err_t mux5_default_cfg ( mux5_t *ctx );
276 
277 #if ( MUX5_DRIVER_SEL == MUX5_I2C_DRIVER )
278 
290 err_t mux5_i2c_write_register ( mux5_t *ctx, uint8_t reg, uint8_t data_in );
291 
304 err_t mux5_i2c_read_register ( mux5_t *ctx, uint8_t reg, uint8_t *data_out );
305 #endif
306 
324 err_t mux5_set_channels_state ( mux5_t *ctx, uint16_t ch_mask, uint8_t ch_state );
325 
335 
345 
354 uint8_t mux5_get_com_a_pin ( mux5_t *ctx );
355 
364 uint8_t mux5_get_com_b_pin ( mux5_t *ctx );
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 #endif // MUX5_H
370  // mux5
372 
373 // ------------------------------------------------------------------------ END
mux5_init
err_t mux5_init(mux5_t *ctx, mux5_cfg_t *cfg)
MUX 5 initialization function.
mux5_cfg_t::i2c_address
uint8_t i2c_address
Definition: mux5.h:212
mux5_t
struct mux5_s mux5_t
MUX 5 Click context object.
mux5_s::sd
digital_out_t sd
Definition: mux5.h:178
mux5_cfg_t::com_a
pin_name_t com_a
Definition: mux5.h:209
mux5_s::i2c
i2c_master_t i2c
Definition: mux5.h:187
mux5_cfg_t::mosi
pin_name_t mosi
Definition: mux5.h:204
spi_specifics.h
This file contains SPI specific macros, functions, etc.
mux5_disable_device
void mux5_disable_device(mux5_t *ctx)
MUX 5 disable device function.
mux5_cfg_t::cs
pin_name_t cs
Definition: mux5.h:206
MUX5_ERROR
@ MUX5_ERROR
Definition: mux5.h:227
mux5_i2c_read_register
err_t mux5_i2c_read_register(mux5_t *ctx, uint8_t reg, uint8_t *data_out)
MUX 5 I2C read register function.
mux5_set_channels_state
err_t mux5_set_channels_state(mux5_t *ctx, uint16_t ch_mask, uint8_t ch_state)
MUX 5 set channels state function.
mux5_cfg_t::spi_speed
uint32_t spi_speed
Definition: mux5.h:214
mux5_cfg_t::scl
pin_name_t scl
Definition: mux5.h:201
mux5_s::ch_a
uint16_t ch_a
Definition: mux5.h:190
mux5_s::slave_address
uint8_t slave_address
Definition: mux5.h:188
mux5_cfg_t::sck
pin_name_t sck
Definition: mux5.h:205
mux5_s::com_b
digital_in_t com_b
Definition: mux5.h:180
mux5_cfg_t::com_b
pin_name_t com_b
Definition: mux5.h:207
mux5_get_com_b_pin
uint8_t mux5_get_com_b_pin(mux5_t *ctx)
MUX 5 get com b pin function.
mux5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: mux5.h:211
mux5_cfg_t::sda
pin_name_t sda
Definition: mux5.h:202
mux5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: mux5.h:216
mux5_cfg_t::miso
pin_name_t miso
Definition: mux5.h:203
mux5_s::com_a
digital_in_t com_a
Definition: mux5.h:181
mux5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: mux5.h:215
mux5_get_com_a_pin
uint8_t mux5_get_com_a_pin(mux5_t *ctx)
MUX 5 get com a pin function.
mux5_i2c_write_register
err_t mux5_i2c_write_register(mux5_t *ctx, uint8_t reg, uint8_t data_in)
MUX 5 I2C write register function.
mux5_enable_device
void mux5_enable_device(mux5_t *ctx)
MUX 5 enable device function.
mux5_cfg_t::sd
pin_name_t sd
Definition: mux5.h:208
MUX5_OK
@ MUX5_OK
Definition: mux5.h:226
mux5_s::ch_b
uint16_t ch_b
Definition: mux5.h:191
mux5_cfg_setup
void mux5_cfg_setup(mux5_cfg_t *cfg)
MUX 5 configuration object setup function.
mux5_s
MUX 5 Click context object.
Definition: mux5.h:177
mux5_cfg_t
MUX 5 Click configuration object.
Definition: mux5.h:200
mux5_default_cfg
err_t mux5_default_cfg(mux5_t *ctx)
MUX 5 default configuration function.
mux5_return_value_t
mux5_return_value_t
MUX 5 Click return value data.
Definition: mux5.h:225