analogmux4  2.0.0.0
analogmux4.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 ANALOGMUX4_H
29 #define ANALOGMUX4_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_analog_in.h"
48 
69 #define ANALOGMUX4_CHANNEL_0 0x00
70 #define ANALOGMUX4_CHANNEL_1 0x01
71 #define ANALOGMUX4_CHANNEL_2 0x02
72 #define ANALOGMUX4_CHANNEL_3 0x03
73 #define ANALOGMUX4_CHANNEL_4 0x04
74 #define ANALOGMUX4_CHANNEL_5 0x05
75 #define ANALOGMUX4_CHANNEL_6 0x06
76 #define ANALOGMUX4_CHANNEL_7 0x07
77  // analogmux4_set
79 
94 #define ANALOGMUX4_MAP_MIKROBUS( cfg, mikrobus ) \
95  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
96  cfg.a2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
97  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
98  cfg.a0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
99  cfg.a1 = MIKROBUS( mikrobus, MIKROBUS_INT )
100  // analogmux4_map // analogmux4
103 
108 typedef struct
109 {
110  digital_out_t a0;
111  digital_out_t en;
112  digital_out_t a2;
113  digital_out_t a1;
115  analog_in_t adc;
117 } analogmux4_t;
118 
123 typedef struct
124 {
125  pin_name_t an;
126  pin_name_t a0;
127  pin_name_t en;
128  pin_name_t a2;
129  pin_name_t a1;
131  analog_in_resolution_t resolution;
132  float vref;
135 
140 typedef enum
141 {
143  ANALOGMUX4_ERROR = -1
144 
146 
163 
179 
192 err_t analogmux4_read_an_pin_value ( analogmux4_t *ctx, uint16_t *data_out );
193 
208 err_t analogmux4_read_an_pin_voltage ( analogmux4_t *ctx, float *data_out );
209 
219 
229 
239 void analogmux4_set_input_channel ( analogmux4_t *ctx, uint8_t channel );
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 #endif // ANALOGMUX4_H
245  // analogmux4
247 
248 // ------------------------------------------------------------------------ END
analogmux4_enable_input
void analogmux4_enable_input(analogmux4_t *ctx)
Analog MUX 4 enable input function.
analogmux4_cfg_t::a0
pin_name_t a0
Definition: analogmux4.h:126
analogmux4_cfg_t::a2
pin_name_t a2
Definition: analogmux4.h:128
analogmux4_return_value_t
analogmux4_return_value_t
Analog MUX 4 Click return value data.
Definition: analogmux4.h:141
analogmux4_cfg_t::vref
float vref
Definition: analogmux4.h:132
analogmux4_cfg_t::an
pin_name_t an
Definition: analogmux4.h:125
analogmux4_read_an_pin_value
err_t analogmux4_read_an_pin_value(analogmux4_t *ctx, uint16_t *data_out)
Analog MUX 4 read AN pin value function.
analogmux4_disable_input
void analogmux4_disable_input(analogmux4_t *ctx)
Analog MUX 4 disable input function.
analogmux4_t::en
digital_out_t en
Definition: analogmux4.h:111
ANALOGMUX4_OK
@ ANALOGMUX4_OK
Definition: analogmux4.h:142
analogmux4_t::a0
digital_out_t a0
Definition: analogmux4.h:110
analogmux4_cfg_t
Analog MUX 4 Click configuration object.
Definition: analogmux4.h:124
analogmux4_t
Analog MUX 4 Click context object.
Definition: analogmux4.h:109
analogmux4_read_an_pin_voltage
err_t analogmux4_read_an_pin_voltage(analogmux4_t *ctx, float *data_out)
Analog MUX 4 read AN pin voltage level function.
analogmux4_cfg_setup
void analogmux4_cfg_setup(analogmux4_cfg_t *cfg)
Analog MUX 4 configuration object setup function.
analogmux4_cfg_t::en
pin_name_t en
Definition: analogmux4.h:127
ANALOGMUX4_ERROR
@ ANALOGMUX4_ERROR
Definition: analogmux4.h:143
analogmux4_t::a1
digital_out_t a1
Definition: analogmux4.h:113
analogmux4_cfg_t::resolution
analog_in_resolution_t resolution
Definition: analogmux4.h:131
analogmux4_t::adc
analog_in_t adc
Definition: analogmux4.h:115
analogmux4_t::a2
digital_out_t a2
Definition: analogmux4.h:112
analogmux4_init
err_t analogmux4_init(analogmux4_t *ctx, analogmux4_cfg_t *cfg)
Analog MUX 4 initialization function.
analogmux4_cfg_t::a1
pin_name_t a1
Definition: analogmux4.h:129
analogmux4_set_input_channel
void analogmux4_set_input_channel(analogmux4_t *ctx, uint8_t channel)
Analog MUX 4 set input channel function.