analogmux  2.0.0.0
analogmux.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
34 #ifndef ANALOGMUX_H
35 #define ANALOGMUX_H
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_out.h"
48 #include "drv_digital_in.h"
49 #include "drv_analog_in.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
52 
62 #define ANALOGMUX_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
64  cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
65  cfg.s3 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
67  cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define ANALOGMUX_RETVAL uint8_t
75 
76 #define ANALOGMUX_OK 0x00
77 #define ANALOGMUX_INIT_ERROR 0xFF
78 
84 #define ANALOGMUX_CHANNEL_0 0x00
85 #define ANALOGMUX_CHANNEL_1 0x01
86 #define ANALOGMUX_CHANNEL_2 0x02
87 #define ANALOGMUX_CHANNEL_3 0x03
88 #define ANALOGMUX_CHANNEL_4 0x04
89 #define ANALOGMUX_CHANNEL_5 0x05
90 #define ANALOGMUX_CHANNEL_6 0x06
91 #define ANALOGMUX_CHANNEL_7 0x07
92 #define ANALOGMUX_CHANNEL_8 0x08
93 #define ANALOGMUX_CHANNEL_9 0x09
94 #define ANALOGMUX_CHANNEL_10 0x10
95 #define ANALOGMUX_CHANNEL_11 0x11
96 #define ANALOGMUX_CHANNEL_12 0x12
97 #define ANALOGMUX_CHANNEL_13 0x13
98 #define ANALOGMUX_CHANNEL_14 0x14
99 #define ANALOGMUX_CHANNEL_15 0x15
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
112 typedef struct
113 {
114  // Output pins
115 
116  digital_out_t s0;
117  digital_out_t s3;
118  digital_out_t s1;
119  digital_out_t s2;
120 
121  // Modules
122 
123  analog_in_t adc;
124 
125 } analogmux_t;
126 
130 typedef struct
131 {
132  // Communication gpio pins
133 
134  pin_name_t an_pin;
135 
136  // Additional gpio pins
137 
138  pin_name_t s0;
139  pin_name_t s3;
140  pin_name_t s1;
141  pin_name_t s2;
142 
143  // static variable
144 
145  analog_in_resolution_t resolution; // Resolution
146  float vref; // VRef
147 
149  // End types group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
181 
191 
201 
210 void analogmux_set_channel ( analogmux_t *ctx, uint8_t cfg );
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 #endif // _ANALOGMUX_H_
216  // End public_function group
219 
220 // ------------------------------------------------------------------------ END
analogmux_cfg_t::vref
float vref
Definition: analogmux.h:146
analogmux_cfg_t::s3
pin_name_t s3
Definition: analogmux.h:139
analogmux_t::s0
digital_out_t s0
Definition: analogmux.h:116
analogmux_cfg_t::s2
pin_name_t s2
Definition: analogmux.h:141
analogmux_generic_read
uint16_t analogmux_generic_read(analogmux_t *ctx)
Generic read function.
analogmux_cfg_t::resolution
analog_in_resolution_t resolution
Definition: analogmux.h:145
analogmux_set_channel
void analogmux_set_channel(analogmux_t *ctx, uint8_t cfg)
Set channel function.
analogmux_cfg_t::s1
pin_name_t s1
Definition: analogmux.h:140
analogmux_init
ANALOGMUX_RETVAL analogmux_init(analogmux_t *ctx, analogmux_cfg_t *cfg)
Initialization function.
analogmux_cfg_t::s0
pin_name_t s0
Definition: analogmux.h:138
analogmux_cfg_setup
void analogmux_cfg_setup(analogmux_cfg_t *cfg)
Config Object Initialization function.
analogmux_cfg_t
Click configuration structure definition.
Definition: analogmux.h:131
analogmux_t::s2
digital_out_t s2
Definition: analogmux.h:119
ANALOGMUX_RETVAL
#define ANALOGMUX_RETVAL
Definition: analogmux.h:74
analogmux_t
Click ctx object definition.
Definition: analogmux.h:113
analogmux_cfg_t::an_pin
pin_name_t an_pin
Definition: analogmux.h:134
analogmux_generic_read_voltage
float analogmux_generic_read_voltage(analogmux_t *ctx)
Generic read voltage function.
analogmux_t::adc
analog_in_t adc
Definition: analogmux.h:123
analogmux_t::s1
digital_out_t s1
Definition: analogmux.h:118
analogmux_t::s3
digital_out_t s3
Definition: analogmux.h:117