analogmux3 2.0.0.0
analogmux3.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 ANALOGMUX3_H
29#define ANALOGMUX3_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_spi_master.h"
52#include "drv_analog_in.h"
53
80#define ANALOGMUX3_SET_CHANNEL_0 0x00
81#define ANALOGMUX3_SET_CHANNEL_1 0x01
82#define ANALOGMUX3_SET_CHANNEL_2 0x02
83#define ANALOGMUX3_SET_CHANNEL_3 0x03
84#define ANALOGMUX3_SET_CHANNEL_4 0x04
85#define ANALOGMUX3_SET_CHANNEL_5 0x05
86#define ANALOGMUX3_SET_CHANNEL_6 0x06
87#define ANALOGMUX3_SET_CHANNEL_7 0x07
88#define ANALOGMUX3_SET_NO_CHANNEL 0xFF
89
95#define ANALOGMUX3_VAL_CHANNEL_OFF 0x00
96#define ANALOGMUX3_VAL_CHANNEL_0 0x01
97#define ANALOGMUX3_VAL_CHANNEL_1 0x02
98#define ANALOGMUX3_VAL_CHANNEL_2 0x04
99#define ANALOGMUX3_VAL_CHANNEL_3 0x08
100#define ANALOGMUX3_VAL_CHANNEL_4 0x10
101#define ANALOGMUX3_VAL_CHANNEL_5 0x20
102#define ANALOGMUX3_VAL_CHANNEL_6 0x40
103#define ANALOGMUX3_VAL_CHANNEL_7 0x80
104
110#define ANALOGMUX3_SET_DEV_ADDR_0 0x4C
111#define ANALOGMUX3_SET_DEV_ADDR_1 0x4D
112#define ANALOGMUX3_SET_DEV_ADDR_2 0x4E
113#define ANALOGMUX3_SET_DEV_ADDR_3 0x4F
114
115 // analogmux3_set
116
131#define ANALOGMUX3_MAP_MIKROBUS( cfg, mikrobus ) \
132 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
133 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
134 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
135 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
136 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
137 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
138
139 // analogmux3_map
140 // analogmux3
141
146typedef struct
147{
148 // Output pins
149
150 digital_out_t rst;
152 // Modules
153
154 analog_in_t adc;
155 spi_master_t spi;
157 pin_name_t chip_select;
160
165typedef struct
166{
167 // Communication gpio pins
168
169 pin_name_t miso;
170 pin_name_t mosi;
171 pin_name_t sck;
172 pin_name_t cs;
173 pin_name_t an;
175 // Additional gpio pins
176
177 pin_name_t rst;
179 // Static variable
180
181 uint32_t spi_speed;
182 spi_master_mode_t spi_mode;
183 spi_master_chip_select_polarity_t cs_polarity;
185 analog_in_resolution_t resolution;
186 float vref;
189
200
217
233
248
264err_t analogmux3_generic_write ( analogmux3_t *ctx, uint8_t data_in );
265
276
301err_t analogmux3_set_channel ( analogmux3_t *ctx, uint8_t mux_ch );
302
315err_t analogmux3_read_an_pin_value ( analogmux3_t *ctx, uint16_t *data_out );
316
331err_t analogmux3_read_an_pin_voltage ( analogmux3_t *ctx, float *data_out );
332
333#ifdef __cplusplus
334}
335#endif
336#endif // ANALOGMUX3_H
337
338 // analogmux3
339
340// ------------------------------------------------------------------------ END
analogmux3_return_value_t
Analog MUX 3 Click return value data.
Definition analogmux3.h:195
@ ANALOGMUX3_ERROR
Definition analogmux3.h:197
@ ANALOGMUX3_OK
Definition analogmux3.h:196
void analogmux3_cfg_setup(analogmux3_cfg_t *cfg)
Analog MUX 3 configuration object setup function.
err_t analogmux3_init(analogmux3_t *ctx, analogmux3_cfg_t *cfg)
Analog MUX 3 initialization function.
void analogmux3_hw_reset(analogmux3_t *ctx)
Analog MUX 3 reset the device function.
err_t analogmux3_set_channel(analogmux3_t *ctx, uint8_t mux_ch)
Analog MUX 3 set channel function.
err_t analogmux3_generic_write(analogmux3_t *ctx, uint8_t data_in)
Analog MUX 3 data writing function.
err_t analogmux3_read_an_pin_voltage(analogmux3_t *ctx, float *data_out)
Analog MUX 3 read AN pin voltage level function.
err_t analogmux3_default_cfg(analogmux3_t *ctx)
Analog MUX 3 default configuration function.
err_t analogmux3_read_an_pin_value(analogmux3_t *ctx, uint16_t *data_out)
Analog MUX 3 read AN pin value function.
Analog MUX 3 Click configuration object.
Definition analogmux3.h:166
analog_in_resolution_t resolution
Definition analogmux3.h:185
float vref
Definition analogmux3.h:186
spi_master_chip_select_polarity_t cs_polarity
Definition analogmux3.h:183
pin_name_t sck
Definition analogmux3.h:171
spi_master_mode_t spi_mode
Definition analogmux3.h:182
pin_name_t mosi
Definition analogmux3.h:170
uint32_t spi_speed
Definition analogmux3.h:181
pin_name_t miso
Definition analogmux3.h:169
pin_name_t rst
Definition analogmux3.h:177
pin_name_t an
Definition analogmux3.h:173
pin_name_t cs
Definition analogmux3.h:172
Analog MUX 3 Click context object.
Definition analogmux3.h:147
spi_master_t spi
Definition analogmux3.h:155
digital_out_t rst
Definition analogmux3.h:150
pin_name_t chip_select
Definition analogmux3.h:157
analog_in_t adc
Definition analogmux3.h:154