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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_analog_in.h"
38 
59 #define MUX4_ENABLE_INPUT 0
60 #define MUX4_DISABLE_INPUT 1
61 
66 #define MUX4_SELECT_INPUT_1 1
67 #define MUX4_SELECT_INPUT_2 2
68 #define MUX4_SELECT_INPUT_3 3
69 #define MUX4_SELECT_INPUT_4 4
70 #define MUX4_SELECT_INPUT_5 5
71 #define MUX4_SELECT_INPUT_6 6
72 #define MUX4_SELECT_INPUT_7 7
73 #define MUX4_SELECT_INPUT_8 8
74  // mux4_set
76 
91 #define MUX4_MAP_MIKROBUS( cfg, mikrobus ) \
92  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
93  cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
94  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
95  cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
96  cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_INT )
97  // mux4_map // mux4
100 
105 typedef struct
106 {
107  digital_out_t s2;
108  digital_out_t en;
109  digital_out_t s0;
110  digital_out_t s1;
112  analog_in_t adc;
114 } mux4_t;
115 
120 typedef struct
121 {
122  pin_name_t an;
123  pin_name_t s2;
124  pin_name_t en;
125  pin_name_t s0;
126  pin_name_t s1;
128  analog_in_resolution_t resolution;
129  float vref;
131 } mux4_cfg_t;
132 
137 typedef enum
138 {
139  MUX4_OK = 0,
140  MUX4_ERROR = -1
141 
143 
160 
175 err_t mux4_init ( mux4_t *ctx, mux4_cfg_t *cfg );
176 
189 err_t mux4_read_an_pin_value ( mux4_t *ctx, uint16_t *data_out );
190 
205 err_t mux4_read_an_pin_voltage ( mux4_t *ctx, float *data_out );
206 
217 void mux4_enable_input ( mux4_t *ctx, uint8_t en_state );
218 
228 void mux4_select_input ( mux4_t *ctx, uint8_t input );
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 #endif // MUX4_H
234  // mux4
236 
237 // ------------------------------------------------------------------------ END
mux4_t::s0
digital_out_t s0
Definition: mux4.h:109
mux4_return_value_t
mux4_return_value_t
MUX 4 Click return value data.
Definition: mux4.h:138
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:126
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:128
mux4_t::adc
analog_in_t adc
Definition: mux4.h:112
mux4_cfg_t::en
pin_name_t en
Definition: mux4.h:124
mux4_t::s1
digital_out_t s1
Definition: mux4.h:110
mux4_cfg_t::an
pin_name_t an
Definition: mux4.h:122
mux4_cfg_t::s0
pin_name_t s0
Definition: mux4.h:125
mux4_cfg_t::s2
pin_name_t s2
Definition: mux4.h:123
mux4_t::s2
digital_out_t s2
Definition: mux4.h:107
mux4_t::en
digital_out_t en
Definition: mux4.h:108
mux4_cfg_t::vref
float vref
Definition: mux4.h:129
mux4_t
MUX 4 Click context object.
Definition: mux4.h:106
MUX4_ERROR
@ MUX4_ERROR
Definition: mux4.h:140
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:121
MUX4_OK
@ MUX4_OK
Definition: mux4.h:139