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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "drv_analog_in.h"
39 
66 #define ANALOGMUX3_SET_CHANNEL_0 0x00
67 #define ANALOGMUX3_SET_CHANNEL_1 0x01
68 #define ANALOGMUX3_SET_CHANNEL_2 0x02
69 #define ANALOGMUX3_SET_CHANNEL_3 0x03
70 #define ANALOGMUX3_SET_CHANNEL_4 0x04
71 #define ANALOGMUX3_SET_CHANNEL_5 0x05
72 #define ANALOGMUX3_SET_CHANNEL_6 0x06
73 #define ANALOGMUX3_SET_CHANNEL_7 0x07
74 #define ANALOGMUX3_SET_NO_CHANNEL 0xFF
75 
81 #define ANALOGMUX3_VAL_CHANNEL_OFF 0x00
82 #define ANALOGMUX3_VAL_CHANNEL_0 0x01
83 #define ANALOGMUX3_VAL_CHANNEL_1 0x02
84 #define ANALOGMUX3_VAL_CHANNEL_2 0x04
85 #define ANALOGMUX3_VAL_CHANNEL_3 0x08
86 #define ANALOGMUX3_VAL_CHANNEL_4 0x10
87 #define ANALOGMUX3_VAL_CHANNEL_5 0x20
88 #define ANALOGMUX3_VAL_CHANNEL_6 0x40
89 #define ANALOGMUX3_VAL_CHANNEL_7 0x80
90 
96 #define ANALOGMUX3_SET_DEV_ADDR_0 0x4C
97 #define ANALOGMUX3_SET_DEV_ADDR_1 0x4D
98 #define ANALOGMUX3_SET_DEV_ADDR_2 0x4E
99 #define ANALOGMUX3_SET_DEV_ADDR_3 0x4F
100  // analogmux3_set
102 
117 #define ANALOGMUX3_MAP_MIKROBUS( cfg, mikrobus ) \
118  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
119  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
120  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
121  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
122  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
123  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
124  // analogmux3_map // analogmux3
127 
132 typedef struct
133 {
134  // Output pins
135 
136  digital_out_t rst;
138  // Modules
139 
140  analog_in_t adc;
141  spi_master_t spi;
143  pin_name_t chip_select;
145 } analogmux3_t;
146 
151 typedef struct
152 {
153  // Communication gpio pins
154 
155  pin_name_t miso;
156  pin_name_t mosi;
157  pin_name_t sck;
158  pin_name_t cs;
159  pin_name_t an;
161  // Additional gpio pins
162 
163  pin_name_t rst;
165  // Static variable
166 
167  uint32_t spi_speed;
168  spi_master_mode_t spi_mode;
169  spi_master_chip_select_polarity_t cs_polarity;
171  analog_in_resolution_t resolution;
172  float vref;
175 
180 typedef enum
181 {
183  ANALOGMUX3_ERROR = -1
184 
186 
203 
218 err_t analogmux3_init ( analogmux3_t *ctx, analogmux3_cfg_t *cfg );
219 
233 err_t analogmux3_default_cfg ( analogmux3_t *ctx );
234 
250 err_t analogmux3_generic_write ( analogmux3_t *ctx, uint8_t data_in );
251 
261 void analogmux3_hw_reset ( analogmux3_t *ctx );
262 
287 err_t analogmux3_set_channel ( analogmux3_t *ctx, uint8_t mux_ch );
288 
301 err_t analogmux3_read_an_pin_value ( analogmux3_t *ctx, uint16_t *data_out );
302 
317 err_t analogmux3_read_an_pin_voltage ( analogmux3_t *ctx, float *data_out );
318 
319 #ifdef __cplusplus
320 }
321 #endif
322 #endif // ANALOGMUX3_H
323  // analogmux3
325 
326 // ------------------------------------------------------------------------ END
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_OK
Definition: analogmux3.h:181
analogmux3_t
Analog MUX 3 Click context object.
Definition: analogmux3.h:131
analogmux3_cfg_t
Analog MUX 3 Click configuration object.
Definition: analogmux3.h:150
analogmux3_set_channel
err_t analogmux3_set_channel(analogmux3_t *ctx, uint8_t mux_ch)
Analog MUX 3 set channel function.
ANALOGMUX3_ERROR
Definition: analogmux3.h:182
analogmux3_cfg_setup
void analogmux3_cfg_setup(analogmux3_cfg_t *cfg)
Analog MUX 3 configuration object setup function.
analogmux3_return_value_t
analogmux3_return_value_t
Analog MUX 3 Click return value data.
Definition: analogmux3.h:179
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_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.