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
41#ifdef PREINIT_SUPPORTED
42#include "preinit.h"
43#endif
44
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
47 #include "delays.h"
48 #endif
49#endif
50
51#include "drv_digital_out.h"
52#include "drv_digital_in.h"
53#include "drv_analog_in.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
56
66#define ANALOGMUX_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
68 cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69 cfg.s3 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
71 cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define ANALOGMUX_RETVAL uint8_t
79
80#define ANALOGMUX_OK 0x00
81#define ANALOGMUX_INIT_ERROR 0xFF
88#define ANALOGMUX_CHANNEL_0 0x00
89#define ANALOGMUX_CHANNEL_1 0x01
90#define ANALOGMUX_CHANNEL_2 0x02
91#define ANALOGMUX_CHANNEL_3 0x03
92#define ANALOGMUX_CHANNEL_4 0x04
93#define ANALOGMUX_CHANNEL_5 0x05
94#define ANALOGMUX_CHANNEL_6 0x06
95#define ANALOGMUX_CHANNEL_7 0x07
96#define ANALOGMUX_CHANNEL_8 0x08
97#define ANALOGMUX_CHANNEL_9 0x09
98#define ANALOGMUX_CHANNEL_10 0x10
99#define ANALOGMUX_CHANNEL_11 0x11
100#define ANALOGMUX_CHANNEL_12 0x12
101#define ANALOGMUX_CHANNEL_13 0x13
102#define ANALOGMUX_CHANNEL_14 0x14
103#define ANALOGMUX_CHANNEL_15 0x15
106 // End group macro
107// --------------------------------------------------------------- PUBLIC TYPES
116typedef struct
117{
118 // Output pins
119
120 digital_out_t s0;
121 digital_out_t s3;
122 digital_out_t s1;
123 digital_out_t s2;
124
125 // Modules
126
127 analog_in_t adc;
128
130
134typedef struct
135{
136 // Communication gpio pins
137
138 pin_name_t an_pin;
139
140 // Additional gpio pins
141
142 pin_name_t s0;
143 pin_name_t s3;
144 pin_name_t s1;
145 pin_name_t s2;
146
147 // static variable
148
149 analog_in_resolution_t resolution; // Resolution
150 float vref; // VRef
151
153
154 // End types group
155// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
156
162#ifdef __cplusplus
163extern "C"{
164#endif
165
175
185
195
205
214void analogmux_set_channel ( analogmux_t *ctx, uint8_t cfg );
215
216#ifdef __cplusplus
217}
218#endif
219#endif // _ANALOGMUX_H_
220
221 // End public_function group
223
224// ------------------------------------------------------------------------ END
#define ANALOGMUX_RETVAL
Definition analogmux.h:78
void analogmux_set_channel(analogmux_t *ctx, uint8_t cfg)
Set channel function.
uint16_t analogmux_generic_read(analogmux_t *ctx)
Generic read function.
ANALOGMUX_RETVAL analogmux_init(analogmux_t *ctx, analogmux_cfg_t *cfg)
Initialization function.
float analogmux_generic_read_voltage(analogmux_t *ctx)
Generic read voltage function.
void analogmux_cfg_setup(analogmux_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition analogmux.h:135
pin_name_t s2
Definition analogmux.h:145
pin_name_t s3
Definition analogmux.h:143
pin_name_t s0
Definition analogmux.h:142
analog_in_resolution_t resolution
Definition analogmux.h:149
float vref
Definition analogmux.h:150
pin_name_t an_pin
Definition analogmux.h:138
pin_name_t s1
Definition analogmux.h:144
Click ctx object definition.
Definition analogmux.h:117
digital_out_t s3
Definition analogmux.h:121
digital_out_t s2
Definition analogmux.h:123
digital_out_t s1
Definition analogmux.h:122
analog_in_t adc
Definition analogmux.h:127
digital_out_t s0
Definition analogmux.h:120