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 "drv_digital_out.h"
38 #include "drv_digital_in.h"
39 #include "drv_analog_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
42 
52 #define ANALOGMUX_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
54  cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
55  cfg.s3 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
57  cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define ANALOGMUX_RETVAL uint8_t
65 
66 #define ANALOGMUX_OK 0x00
67 #define ANALOGMUX_INIT_ERROR 0xFF
68 
74 #define ANALOGMUX_CHANNEL_0 0x00
75 #define ANALOGMUX_CHANNEL_1 0x01
76 #define ANALOGMUX_CHANNEL_2 0x02
77 #define ANALOGMUX_CHANNEL_3 0x03
78 #define ANALOGMUX_CHANNEL_4 0x04
79 #define ANALOGMUX_CHANNEL_5 0x05
80 #define ANALOGMUX_CHANNEL_6 0x06
81 #define ANALOGMUX_CHANNEL_7 0x07
82 #define ANALOGMUX_CHANNEL_8 0x08
83 #define ANALOGMUX_CHANNEL_9 0x09
84 #define ANALOGMUX_CHANNEL_10 0x10
85 #define ANALOGMUX_CHANNEL_11 0x11
86 #define ANALOGMUX_CHANNEL_12 0x12
87 #define ANALOGMUX_CHANNEL_13 0x13
88 #define ANALOGMUX_CHANNEL_14 0x14
89 #define ANALOGMUX_CHANNEL_15 0x15
90  // End group macro
93 // --------------------------------------------------------------- PUBLIC TYPES
102 typedef struct
103 {
104  // Output pins
105 
106  digital_out_t s0;
107  digital_out_t s3;
108  digital_out_t s1;
109  digital_out_t s2;
110 
111  // Modules
112 
113  analog_in_t adc;
114 
115 } analogmux_t;
116 
120 typedef struct
121 {
122  // Communication gpio pins
123 
124  pin_name_t an_pin;
125 
126  // Additional gpio pins
127 
128  pin_name_t s0;
129  pin_name_t s3;
130  pin_name_t s1;
131  pin_name_t s2;
132 
133  // static variable
134 
135  analog_in_resolution_t resolution; // Resolution
136  float vref; // VRef
137 
139  // End types group
141 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
161 
171 
181 
191 
200 void analogmux_set_channel ( analogmux_t *ctx, uint8_t cfg );
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 #endif // _ANALOGMUX_H_
206  // End public_function group
209 
210 // ------------------------------------------------------------------------ END
analogmux_cfg_t::vref
float vref
Definition: analogmux.h:136
analogmux_cfg_t::s3
pin_name_t s3
Definition: analogmux.h:129
analogmux_t::s0
digital_out_t s0
Definition: analogmux.h:106
analogmux_cfg_t::s2
pin_name_t s2
Definition: analogmux.h:131
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:135
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:130
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:128
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:121
analogmux_t::s2
digital_out_t s2
Definition: analogmux.h:109
ANALOGMUX_RETVAL
#define ANALOGMUX_RETVAL
Definition: analogmux.h:64
analogmux_t
Click ctx object definition.
Definition: analogmux.h:103
analogmux_cfg_t::an_pin
pin_name_t an_pin
Definition: analogmux.h:124
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:113
analogmux_t::s1
digital_out_t s1
Definition: analogmux.h:108
analogmux_t::s3
digital_out_t s3
Definition: analogmux.h:107