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
32extern "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_analog_in.h"
39
66#define ANALOGMUX2_SET_CHANNEL_0 0x00
67#define ANALOGMUX2_SET_CHANNEL_1 0x01
68#define ANALOGMUX2_SET_CHANNEL_2 0x02
69#define ANALOGMUX2_SET_CHANNEL_3 0x03
70#define ANALOGMUX2_SET_CHANNEL_4 0x04
71#define ANALOGMUX2_SET_CHANNEL_5 0x05
72#define ANALOGMUX2_SET_CHANNEL_6 0x06
73#define ANALOGMUX2_SET_CHANNEL_7 0x07
74#define ANALOGMUX2_SET_NO_CHANNEL 0xFF
75
81#define ANALOGMUX2_VAL_CHANNEL_OFF 0x00
82#define ANALOGMUX2_VAL_CHANNEL_0 0x01
83#define ANALOGMUX2_VAL_CHANNEL_1 0x02
84#define ANALOGMUX2_VAL_CHANNEL_2 0x04
85#define ANALOGMUX2_VAL_CHANNEL_3 0x08
86#define ANALOGMUX2_VAL_CHANNEL_4 0x10
87#define ANALOGMUX2_VAL_CHANNEL_5 0x20
88#define ANALOGMUX2_VAL_CHANNEL_6 0x40
89#define ANALOGMUX2_VAL_CHANNEL_7 0x80
90
96#define ANALOGMUX2_SET_DEV_ADDR_0 0x4C
97#define ANALOGMUX2_SET_DEV_ADDR_1 0x4D
98#define ANALOGMUX2_SET_DEV_ADDR_2 0x4E
99#define ANALOGMUX2_SET_DEV_ADDR_3 0x4F
100 // analogmux2_set
102
113#define ANALOGMUX2_SUCCESS 0
114#define ANALOGMUX2_ERROR -1
115
116 // status
118
119
134#define ANALOGMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
135 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
136 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
137 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
138 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
139 // analogmux2_map // analogmux2
142
147typedef struct
148{
149 // Output pins
150
151 digital_out_t rst;
153 // Modules
154
155 analog_in_t adc;
156
157 i2c_master_t i2c;
159 // I2C slave address
160
164
169typedef struct
170{
171 pin_name_t scl;
172 pin_name_t sda;
174 pin_name_t an;
175 pin_name_t rst;
177 uint32_t i2c_speed;
178 uint8_t i2c_address;
180 analog_in_resolution_t resolution;
181 float vref;
184
203
221
235
246
262err_t analogmux2_generic_write ( analogmux2_t *ctx, uint8_t tx_data );
263
279
304err_t analogmux2_set_channel ( analogmux2_t *ctx, uint8_t mux_ch );
305
328
341err_t analogmux2_read_an_pin_value ( analogmux2_t *ctx, uint16_t *data_out );
342
357err_t analogmux2_read_an_pin_voltage ( analogmux2_t *ctx, float *data_out );
358
359#ifdef __cplusplus
360}
361#endif
362#endif // ANALOGMUX2_H
363 // analogmux2
365
366// ------------------------------------------------------------------------ END
uint8_t analogmux2_get_channel(analogmux2_t *ctx)
Analog MUX 2 get channel function.
void analogmux2_hw_reset(analogmux2_t *ctx)
Analog MUX 2 reset the device function.
void analogmux2_default_cfg(analogmux2_t *ctx)
Analog MUX 2 default configuration function.
void analogmux2_cfg_setup(analogmux2_cfg_t *cfg)
Analog MUX 2 configuration object setup function.
uint8_t analogmux2_generic_read(analogmux2_t *ctx)
Analog MUX 2 I2C reading function.
err_t analogmux2_read_an_pin_value(analogmux2_t *ctx, uint16_t *data_out)
Analog MUX 2 read AN pin value function.
err_t analogmux2_generic_write(analogmux2_t *ctx, uint8_t tx_data)
Analog MUX 2 I2C writing function.
err_t analogmux2_init(analogmux2_t *ctx, analogmux2_cfg_t *cfg)
Analog MUX 2 initialization function.
err_t analogmux2_set_channel(analogmux2_t *ctx, uint8_t mux_ch)
Analog MUX 2 set channel function.
err_t analogmux2_read_an_pin_voltage(analogmux2_t *ctx, float *data_out)
Analog MUX 2 read AN pin voltage level function.
Analog MUX 2 Click configuration object.
Definition: analogmux2.h:170
analog_in_resolution_t resolution
Definition: analogmux2.h:180
float vref
Definition: analogmux2.h:181
uint32_t i2c_speed
Definition: analogmux2.h:177
pin_name_t scl
Definition: analogmux2.h:171
pin_name_t sda
Definition: analogmux2.h:172
pin_name_t rst
Definition: analogmux2.h:175
pin_name_t an
Definition: analogmux2.h:174
uint8_t i2c_address
Definition: analogmux2.h:178
Analog MUX 2 Click context object.
Definition: analogmux2.h:148
i2c_master_t i2c
Definition: analogmux2.h:157
digital_out_t rst
Definition: analogmux2.h:151
uint8_t slave_address
Definition: analogmux2.h:161
analog_in_t adc
Definition: analogmux2.h:155