mux4  2.0.0.0
mux4.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 MUX4_H
29 #define MUX4_H
30 
31 #ifdef __cplusplus
32 extern "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_analog_in.h"
52 
73 #define MUX4_ENABLE_INPUT 0
74 #define MUX4_DISABLE_INPUT 1
75 
80 #define MUX4_SELECT_INPUT_1 1
81 #define MUX4_SELECT_INPUT_2 2
82 #define MUX4_SELECT_INPUT_3 3
83 #define MUX4_SELECT_INPUT_4 4
84 #define MUX4_SELECT_INPUT_5 5
85 #define MUX4_SELECT_INPUT_6 6
86 #define MUX4_SELECT_INPUT_7 7
87 #define MUX4_SELECT_INPUT_8 8
88  // mux4_set
90 
105 #define MUX4_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
107  cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
108  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
109  cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
110  cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_INT )
111  // mux4_map // mux4
114 
119 typedef struct
120 {
121  digital_out_t s2;
122  digital_out_t en;
123  digital_out_t s0;
124  digital_out_t s1;
126  analog_in_t adc;
128 } mux4_t;
129 
134 typedef struct
135 {
136  pin_name_t an;
137  pin_name_t s2;
138  pin_name_t en;
139  pin_name_t s0;
140  pin_name_t s1;
142  analog_in_resolution_t resolution;
143  float vref;
145 } mux4_cfg_t;
146 
151 typedef enum
152 {
153  MUX4_OK = 0,
154  MUX4_ERROR = -1
155 
157 
174 
189 err_t mux4_init ( mux4_t *ctx, mux4_cfg_t *cfg );
190 
203 err_t mux4_read_an_pin_value ( mux4_t *ctx, uint16_t *data_out );
204 
219 err_t mux4_read_an_pin_voltage ( mux4_t *ctx, float *data_out );
220 
231 void mux4_enable_input ( mux4_t *ctx, uint8_t en_state );
232 
242 void mux4_select_input ( mux4_t *ctx, uint8_t input );
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 #endif // MUX4_H
248  // mux4
250 
251 // ------------------------------------------------------------------------ END
mux4_t::s0
digital_out_t s0
Definition: mux4.h:123
mux4_return_value_t
mux4_return_value_t
MUX 4 Click return value data.
Definition: mux4.h:152
mux4_select_input
void mux4_select_input(mux4_t *ctx, uint8_t input)
MUX 4 select input function.
mux4_read_an_pin_voltage
err_t mux4_read_an_pin_voltage(mux4_t *ctx, float *data_out)
MUX 4 read AN pin voltage level function.
mux4_cfg_t::s1
pin_name_t s1
Definition: mux4.h:140
mux4_enable_input
void mux4_enable_input(mux4_t *ctx, uint8_t en_state)
MUX 4 enable input function.
mux4_cfg_t::resolution
analog_in_resolution_t resolution
Definition: mux4.h:142
mux4_t::adc
analog_in_t adc
Definition: mux4.h:126
mux4_cfg_t::en
pin_name_t en
Definition: mux4.h:138
mux4_t::s1
digital_out_t s1
Definition: mux4.h:124
mux4_cfg_t::an
pin_name_t an
Definition: mux4.h:136
mux4_cfg_t::s0
pin_name_t s0
Definition: mux4.h:139
mux4_cfg_t::s2
pin_name_t s2
Definition: mux4.h:137
mux4_t::s2
digital_out_t s2
Definition: mux4.h:121
mux4_t::en
digital_out_t en
Definition: mux4.h:122
mux4_cfg_t::vref
float vref
Definition: mux4.h:143
mux4_t
MUX 4 Click context object.
Definition: mux4.h:120
MUX4_ERROR
@ MUX4_ERROR
Definition: mux4.h:154
mux4_init
err_t mux4_init(mux4_t *ctx, mux4_cfg_t *cfg)
MUX 4 initialization function.
mux4_read_an_pin_value
err_t mux4_read_an_pin_value(mux4_t *ctx, uint16_t *data_out)
MUX 4 read AN pin value function.
mux4_cfg_setup
void mux4_cfg_setup(mux4_cfg_t *cfg)
MUX 4 configuration object setup function.
mux4_cfg_t
MUX 4 Click configuration object.
Definition: mux4.h:135
MUX4_OK
@ MUX4_OK
Definition: mux4.h:153