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
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_spi_master.h"
48 #include "drv_analog_in.h"
49 
76 #define ANALOGMUX3_SET_CHANNEL_0 0x00
77 #define ANALOGMUX3_SET_CHANNEL_1 0x01
78 #define ANALOGMUX3_SET_CHANNEL_2 0x02
79 #define ANALOGMUX3_SET_CHANNEL_3 0x03
80 #define ANALOGMUX3_SET_CHANNEL_4 0x04
81 #define ANALOGMUX3_SET_CHANNEL_5 0x05
82 #define ANALOGMUX3_SET_CHANNEL_6 0x06
83 #define ANALOGMUX3_SET_CHANNEL_7 0x07
84 #define ANALOGMUX3_SET_NO_CHANNEL 0xFF
85 
91 #define ANALOGMUX3_VAL_CHANNEL_OFF 0x00
92 #define ANALOGMUX3_VAL_CHANNEL_0 0x01
93 #define ANALOGMUX3_VAL_CHANNEL_1 0x02
94 #define ANALOGMUX3_VAL_CHANNEL_2 0x04
95 #define ANALOGMUX3_VAL_CHANNEL_3 0x08
96 #define ANALOGMUX3_VAL_CHANNEL_4 0x10
97 #define ANALOGMUX3_VAL_CHANNEL_5 0x20
98 #define ANALOGMUX3_VAL_CHANNEL_6 0x40
99 #define ANALOGMUX3_VAL_CHANNEL_7 0x80
100 
106 #define ANALOGMUX3_SET_DEV_ADDR_0 0x4C
107 #define ANALOGMUX3_SET_DEV_ADDR_1 0x4D
108 #define ANALOGMUX3_SET_DEV_ADDR_2 0x4E
109 #define ANALOGMUX3_SET_DEV_ADDR_3 0x4F
110  // analogmux3_set
112 
127 #define ANALOGMUX3_MAP_MIKROBUS( cfg, mikrobus ) \
128  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
129  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
130  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
131  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
132  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
133  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
134  // analogmux3_map // analogmux3
137 
142 typedef struct
143 {
144  // Output pins
145 
146  digital_out_t rst;
148  // Modules
149 
150  analog_in_t adc;
151  spi_master_t spi;
153  pin_name_t chip_select;
155 } analogmux3_t;
156 
161 typedef struct
162 {
163  // Communication gpio pins
164 
165  pin_name_t miso;
166  pin_name_t mosi;
167  pin_name_t sck;
168  pin_name_t cs;
169  pin_name_t an;
171  // Additional gpio pins
172 
173  pin_name_t rst;
175  // Static variable
176 
177  uint32_t spi_speed;
178  spi_master_mode_t spi_mode;
179  spi_master_chip_select_polarity_t cs_polarity;
181  analog_in_resolution_t resolution;
182  float vref;
185 
190 typedef enum
191 {
193  ANALOGMUX3_ERROR = -1
194 
196 
213 
229 
244 
260 err_t analogmux3_generic_write ( analogmux3_t *ctx, uint8_t data_in );
261 
272 
297 err_t analogmux3_set_channel ( analogmux3_t *ctx, uint8_t mux_ch );
298 
311 err_t analogmux3_read_an_pin_value ( analogmux3_t *ctx, uint16_t *data_out );
312 
327 err_t analogmux3_read_an_pin_voltage ( analogmux3_t *ctx, float *data_out );
328 
329 #ifdef __cplusplus
330 }
331 #endif
332 #endif // ANALOGMUX3_H
333  // analogmux3
335 
336 // ------------------------------------------------------------------------ END
analogmux3_cfg_t::resolution
analog_in_resolution_t resolution
Definition: analogmux3.h:181
analogmux3_cfg_t::vref
float vref
Definition: analogmux3.h:182
analogmux3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: analogmux3.h:179
analogmux3_hw_reset
void analogmux3_hw_reset(analogmux3_t *ctx)
Analog MUX 3 reset the device function.
analogmux3_generic_write
err_t analogmux3_generic_write(analogmux3_t *ctx, uint8_t data_in)
Analog MUX 3 data writing function.
analogmux3_default_cfg
err_t analogmux3_default_cfg(analogmux3_t *ctx)
Analog MUX 3 default configuration function.
analogmux3_init
err_t analogmux3_init(analogmux3_t *ctx, analogmux3_cfg_t *cfg)
Analog MUX 3 initialization function.
analogmux3_cfg_t::miso
pin_name_t miso
Definition: analogmux3.h:165
ANALOGMUX3_OK
@ ANALOGMUX3_OK
Definition: analogmux3.h:192
analogmux3_cfg_t::cs
pin_name_t cs
Definition: analogmux3.h:168
analogmux3_cfg_t::sck
pin_name_t sck
Definition: analogmux3.h:167
analogmux3_cfg_t::mosi
pin_name_t mosi
Definition: analogmux3.h:166
analogmux3_t
Analog MUX 3 Click context object.
Definition: analogmux3.h:143
analogmux3_t::chip_select
pin_name_t chip_select
Definition: analogmux3.h:153
analogmux3_cfg_t
Analog MUX 3 Click configuration object.
Definition: analogmux3.h:162
analogmux3_t::adc
analog_in_t adc
Definition: analogmux3.h:150
analogmux3_cfg_t::an
pin_name_t an
Definition: analogmux3.h:169
analogmux3_set_channel
err_t analogmux3_set_channel(analogmux3_t *ctx, uint8_t mux_ch)
Analog MUX 3 set channel function.
analogmux3_t::spi
spi_master_t spi
Definition: analogmux3.h:151
ANALOGMUX3_ERROR
@ ANALOGMUX3_ERROR
Definition: analogmux3.h:193
analogmux3_cfg_t::rst
pin_name_t rst
Definition: analogmux3.h:173
analogmux3_t::rst
digital_out_t rst
Definition: analogmux3.h:146
analogmux3_cfg_setup
void analogmux3_cfg_setup(analogmux3_cfg_t *cfg)
Analog MUX 3 configuration object setup function.
analogmux3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: analogmux3.h:178
analogmux3_return_value_t
analogmux3_return_value_t
Analog MUX 3 Click return value data.
Definition: analogmux3.h:191
analogmux3_read_an_pin_voltage
err_t analogmux3_read_an_pin_voltage(analogmux3_t *ctx, float *data_out)
Analog MUX 3 read AN pin voltage level function.
analogmux3_cfg_t::spi_speed
uint32_t spi_speed
Definition: analogmux3.h:177
analogmux3_read_an_pin_value
err_t analogmux3_read_an_pin_value(analogmux3_t *ctx, uint16_t *data_out)
Analog MUX 3 read AN pin value function.