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
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_analog_in.h"
53
80#define ANALOGMUX2_SET_CHANNEL_0 0x00
81#define ANALOGMUX2_SET_CHANNEL_1 0x01
82#define ANALOGMUX2_SET_CHANNEL_2 0x02
83#define ANALOGMUX2_SET_CHANNEL_3 0x03
84#define ANALOGMUX2_SET_CHANNEL_4 0x04
85#define ANALOGMUX2_SET_CHANNEL_5 0x05
86#define ANALOGMUX2_SET_CHANNEL_6 0x06
87#define ANALOGMUX2_SET_CHANNEL_7 0x07
88#define ANALOGMUX2_SET_NO_CHANNEL 0xFF
89
95#define ANALOGMUX2_VAL_CHANNEL_OFF 0x00
96#define ANALOGMUX2_VAL_CHANNEL_0 0x01
97#define ANALOGMUX2_VAL_CHANNEL_1 0x02
98#define ANALOGMUX2_VAL_CHANNEL_2 0x04
99#define ANALOGMUX2_VAL_CHANNEL_3 0x08
100#define ANALOGMUX2_VAL_CHANNEL_4 0x10
101#define ANALOGMUX2_VAL_CHANNEL_5 0x20
102#define ANALOGMUX2_VAL_CHANNEL_6 0x40
103#define ANALOGMUX2_VAL_CHANNEL_7 0x80
104
110#define ANALOGMUX2_SET_DEV_ADDR_0 0x4C
111#define ANALOGMUX2_SET_DEV_ADDR_1 0x4D
112#define ANALOGMUX2_SET_DEV_ADDR_2 0x4E
113#define ANALOGMUX2_SET_DEV_ADDR_3 0x4F
114
115 // analogmux2_set
116
127#define ANALOGMUX2_SUCCESS 0
128#define ANALOGMUX2_ERROR -1
129
130
131 // status
132
133
148#define ANALOGMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
149 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
150 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
151 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
152 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
153
154 // analogmux2_map
155 // analogmux2
156
161typedef struct
162{
163 // Output pins
164
165 digital_out_t rst;
167 // Modules
168
169 analog_in_t adc;
170
171 i2c_master_t i2c;
173 // I2C slave address
174
178
183typedef struct
184{
185 pin_name_t scl;
186 pin_name_t sda;
188 pin_name_t an;
189 pin_name_t rst;
191 uint32_t i2c_speed;
192 uint8_t i2c_address;
194 analog_in_resolution_t resolution;
195 float vref;
198
217
235
249
260
276err_t analogmux2_generic_write ( analogmux2_t *ctx, uint8_t tx_data );
277
293
318err_t analogmux2_set_channel ( analogmux2_t *ctx, uint8_t mux_ch );
319
342
355err_t analogmux2_read_an_pin_value ( analogmux2_t *ctx, uint16_t *data_out );
356
371err_t analogmux2_read_an_pin_voltage ( analogmux2_t *ctx, float *data_out );
372
373#ifdef __cplusplus
374}
375#endif
376#endif // ANALOGMUX2_H
377
378 // analogmux2
379
380// ------------------------------------------------------------------------ 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:184
analog_in_resolution_t resolution
Definition analogmux2.h:194
float vref
Definition analogmux2.h:195
uint32_t i2c_speed
Definition analogmux2.h:191
pin_name_t scl
Definition analogmux2.h:185
pin_name_t sda
Definition analogmux2.h:186
pin_name_t rst
Definition analogmux2.h:189
pin_name_t an
Definition analogmux2.h:188
uint8_t i2c_address
Definition analogmux2.h:192
Analog MUX 2 Click context object.
Definition analogmux2.h:162
i2c_master_t i2c
Definition analogmux2.h:171
digital_out_t rst
Definition analogmux2.h:165
uint8_t slave_address
Definition analogmux2.h:175
analog_in_t adc
Definition analogmux2.h:169