analogmux2  2.0.0.0
analogmux2.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 ANALOGMUX2_H
29 #define ANALOGMUX2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_analog_in.h"
49 
76 #define ANALOGMUX2_SET_CHANNEL_0 0x00
77 #define ANALOGMUX2_SET_CHANNEL_1 0x01
78 #define ANALOGMUX2_SET_CHANNEL_2 0x02
79 #define ANALOGMUX2_SET_CHANNEL_3 0x03
80 #define ANALOGMUX2_SET_CHANNEL_4 0x04
81 #define ANALOGMUX2_SET_CHANNEL_5 0x05
82 #define ANALOGMUX2_SET_CHANNEL_6 0x06
83 #define ANALOGMUX2_SET_CHANNEL_7 0x07
84 #define ANALOGMUX2_SET_NO_CHANNEL 0xFF
85 
91 #define ANALOGMUX2_VAL_CHANNEL_OFF 0x00
92 #define ANALOGMUX2_VAL_CHANNEL_0 0x01
93 #define ANALOGMUX2_VAL_CHANNEL_1 0x02
94 #define ANALOGMUX2_VAL_CHANNEL_2 0x04
95 #define ANALOGMUX2_VAL_CHANNEL_3 0x08
96 #define ANALOGMUX2_VAL_CHANNEL_4 0x10
97 #define ANALOGMUX2_VAL_CHANNEL_5 0x20
98 #define ANALOGMUX2_VAL_CHANNEL_6 0x40
99 #define ANALOGMUX2_VAL_CHANNEL_7 0x80
100 
106 #define ANALOGMUX2_SET_DEV_ADDR_0 0x4C
107 #define ANALOGMUX2_SET_DEV_ADDR_1 0x4D
108 #define ANALOGMUX2_SET_DEV_ADDR_2 0x4E
109 #define ANALOGMUX2_SET_DEV_ADDR_3 0x4F
110  // analogmux2_set
112 
123 #define ANALOGMUX2_SUCCESS 0
124 #define ANALOGMUX2_ERROR -1
125 
126  // status
128 
129 
144 #define ANALOGMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
145  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
146  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
147  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
148  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
149  // analogmux2_map // analogmux2
152 
157 typedef struct
158 {
159  // Output pins
160 
161  digital_out_t rst;
163  // Modules
164 
165  analog_in_t adc;
166 
167  i2c_master_t i2c;
169  // I2C slave address
170 
171  uint8_t slave_address;
173 } analogmux2_t;
174 
179 typedef struct
180 {
181  pin_name_t scl;
182  pin_name_t sda;
184  pin_name_t an;
185  pin_name_t rst;
187  uint32_t i2c_speed;
188  uint8_t i2c_address;
190  analog_in_resolution_t resolution;
191  float vref;
194 
213 
231 
245 
256 
272 err_t analogmux2_generic_write ( analogmux2_t *ctx, uint8_t tx_data );
273 
289 
314 err_t analogmux2_set_channel ( analogmux2_t *ctx, uint8_t mux_ch );
315 
338 
351 err_t analogmux2_read_an_pin_value ( analogmux2_t *ctx, uint16_t *data_out );
352 
367 err_t analogmux2_read_an_pin_voltage ( analogmux2_t *ctx, float *data_out );
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 #endif // ANALOGMUX2_H
373  // analogmux2
375 
376 // ------------------------------------------------------------------------ END
analogmux2_cfg_t::rst
pin_name_t rst
Definition: analogmux2.h:185
analogmux2_init
err_t analogmux2_init(analogmux2_t *ctx, analogmux2_cfg_t *cfg)
Analog MUX 2 initialization function.
analogmux2_cfg_t::vref
float vref
Definition: analogmux2.h:191
analogmux2_default_cfg
void analogmux2_default_cfg(analogmux2_t *ctx)
Analog MUX 2 default configuration function.
analogmux2_cfg_t::sda
pin_name_t sda
Definition: analogmux2.h:182
analogmux2_cfg_setup
void analogmux2_cfg_setup(analogmux2_cfg_t *cfg)
Analog MUX 2 configuration object setup function.
analogmux2_hw_reset
void analogmux2_hw_reset(analogmux2_t *ctx)
Analog MUX 2 reset the device function.
analogmux2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: analogmux2.h:190
analogmux2_t::adc
analog_in_t adc
Definition: analogmux2.h:165
analogmux2_set_channel
err_t analogmux2_set_channel(analogmux2_t *ctx, uint8_t mux_ch)
Analog MUX 2 set channel function.
analogmux2_t
Analog MUX 2 Click context object.
Definition: analogmux2.h:158
analogmux2_t::i2c
i2c_master_t i2c
Definition: analogmux2.h:167
analogmux2_cfg_t::an
pin_name_t an
Definition: analogmux2.h:184
analogmux2_t::slave_address
uint8_t slave_address
Definition: analogmux2.h:171
analogmux2_cfg_t
Analog MUX 2 Click configuration object.
Definition: analogmux2.h:180
analogmux2_read_an_pin_voltage
err_t analogmux2_read_an_pin_voltage(analogmux2_t *ctx, float *data_out)
Analog MUX 2 read AN pin voltage level function.
analogmux2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: analogmux2.h:187
analogmux2_cfg_t::scl
pin_name_t scl
Definition: analogmux2.h:181
analogmux2_generic_read
uint8_t analogmux2_generic_read(analogmux2_t *ctx)
Analog MUX 2 I2C reading function.
analogmux2_t::rst
digital_out_t rst
Definition: analogmux2.h:161
analogmux2_cfg_t::i2c_address
uint8_t i2c_address
Definition: analogmux2.h:188
analogmux2_get_channel
uint8_t analogmux2_get_channel(analogmux2_t *ctx)
Analog MUX 2 get channel function.
analogmux2_generic_write
err_t analogmux2_generic_write(analogmux2_t *ctx, uint8_t tx_data)
Analog MUX 2 I2C writing function.
analogmux2_read_an_pin_value
err_t analogmux2_read_an_pin_value(analogmux2_t *ctx, uint16_t *data_out)
Analog MUX 2 read AN pin value function.