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 
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 MUX4_ENABLE_INPUT 0
70 #define MUX4_DISABLE_INPUT 1
71 
76 #define MUX4_SELECT_INPUT_1 1
77 #define MUX4_SELECT_INPUT_2 2
78 #define MUX4_SELECT_INPUT_3 3
79 #define MUX4_SELECT_INPUT_4 4
80 #define MUX4_SELECT_INPUT_5 5
81 #define MUX4_SELECT_INPUT_6 6
82 #define MUX4_SELECT_INPUT_7 7
83 #define MUX4_SELECT_INPUT_8 8
84  // mux4_set
86 
101 #define MUX4_MAP_MIKROBUS( cfg, mikrobus ) \
102  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
103  cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
104  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
105  cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
106  cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_INT )
107  // mux4_map // mux4
110 
115 typedef struct
116 {
117  digital_out_t s2;
118  digital_out_t en;
119  digital_out_t s0;
120  digital_out_t s1;
122  analog_in_t adc;
124 } mux4_t;
125 
130 typedef struct
131 {
132  pin_name_t an;
133  pin_name_t s2;
134  pin_name_t en;
135  pin_name_t s0;
136  pin_name_t s1;
138  analog_in_resolution_t resolution;
139  float vref;
141 } mux4_cfg_t;
142 
147 typedef enum
148 {
149  MUX4_OK = 0,
150  MUX4_ERROR = -1
151 
153 
170 
185 err_t mux4_init ( mux4_t *ctx, mux4_cfg_t *cfg );
186 
199 err_t mux4_read_an_pin_value ( mux4_t *ctx, uint16_t *data_out );
200 
215 err_t mux4_read_an_pin_voltage ( mux4_t *ctx, float *data_out );
216 
227 void mux4_enable_input ( mux4_t *ctx, uint8_t en_state );
228 
238 void mux4_select_input ( mux4_t *ctx, uint8_t input );
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 #endif // MUX4_H
244  // mux4
246 
247 // ------------------------------------------------------------------------ END
mux4_t::s0
digital_out_t s0
Definition: mux4.h:119
mux4_return_value_t
mux4_return_value_t
MUX 4 Click return value data.
Definition: mux4.h:148
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:136
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:138
mux4_t::adc
analog_in_t adc
Definition: mux4.h:122
mux4_cfg_t::en
pin_name_t en
Definition: mux4.h:134
mux4_t::s1
digital_out_t s1
Definition: mux4.h:120
mux4_cfg_t::an
pin_name_t an
Definition: mux4.h:132
mux4_cfg_t::s0
pin_name_t s0
Definition: mux4.h:135
mux4_cfg_t::s2
pin_name_t s2
Definition: mux4.h:133
mux4_t::s2
digital_out_t s2
Definition: mux4.h:117
mux4_t::en
digital_out_t en
Definition: mux4.h:118
mux4_cfg_t::vref
float vref
Definition: mux4.h:139
mux4_t
MUX 4 Click context object.
Definition: mux4.h:116
MUX4_ERROR
@ MUX4_ERROR
Definition: mux4.h:150
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:131
MUX4_OK
@ MUX4_OK
Definition: mux4.h:149