mic2 2.0.0.0
mic2.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
35#ifndef MIC2_H
36#define MIC2_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_analog_in.h"
55#include "drv_i2c_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
58
68#define MIC2_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN )
78#define MIC2_OK 0
79#define MIC2_ERROR -1
86#define MIC2_DEVICE_SLAVE_ADDRESS 0x2C
89 // End group macro
90// --------------------------------------------------------------- PUBLIC TYPES
99typedef uint16_t mic2_data_t;
100
104typedef struct
105{
106 // Modules
107 i2c_master_t i2c;
108
109 // ctx variable
111
112 analog_in_t adc;
113
114} mic2_t;
115
119typedef struct
120{
121 // Communication gpio pins
122 pin_name_t scl;
123 pin_name_t sda;
124 pin_name_t an_pin;
125
126 // static variable
127
128 uint32_t i2c_speed;
129 uint8_t i2c_address;
130
131 analog_in_resolution_t resolution; // Resolution
132 float vref; // VRef
133
134} mic2_cfg_t;
135
136 // End types group
137// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138
144#ifdef __cplusplus
145extern "C"{
146#endif
147
157
166err_t mic2_init ( mic2_t *ctx, mic2_cfg_t *cfg );
167
175void mic2_generic_write ( mic2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
176
184void mic2_set_potentiometer ( mic2_t *ctx, uint8_t ptt_value );
185
197err_t mic2_read_an_pin_value ( mic2_t *ctx, uint16_t *data_out );
198
212err_t mic2_read_an_pin_voltage ( mic2_t *ctx, float *data_out );
213
214#ifdef __cplusplus
215}
216#endif
217#endif // _MIC2_H_
218
219 // End public_function group
221
222// ------------------------------------------------------------------------ END
void mic2_generic_write(mic2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Click Default Configuration function.
void mic2_cfg_setup(mic2_cfg_t *cfg)
Config Object Initialization function.
void mic2_set_potentiometer(mic2_t *ctx, uint8_t ptt_value)
Set potentiometer value.
err_t mic2_init(mic2_t *ctx, mic2_cfg_t *cfg)
Initialization function.
err_t mic2_read_an_pin_value(mic2_t *ctx, uint16_t *data_out)
MIC 2 read AN pin value function.
err_t mic2_read_an_pin_voltage(mic2_t *ctx, float *data_out)
MIC 2 read AN pin voltage level function.
uint16_t mic2_data_t
Analog data type.
Definition mic2.h:99
Click configuration structure definition.
Definition mic2.h:120
analog_in_resolution_t resolution
Definition mic2.h:131
float vref
Definition mic2.h:132
uint32_t i2c_speed
Definition mic2.h:128
pin_name_t an_pin
Definition mic2.h:124
pin_name_t scl
Definition mic2.h:122
pin_name_t sda
Definition mic2.h:123
uint8_t i2c_address
Definition mic2.h:129
Click ctx object definition.
Definition mic2.h:105
i2c_master_t i2c
Definition mic2.h:107
uint8_t slave_address
Definition mic2.h:110
analog_in_t adc
Definition mic2.h:112