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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_analog_in.h"
51 #include "drv_i2c_master.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
54 
64 #define MIC2_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
66  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
67  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN )
68 
74 #define MIC2_OK 0
75 #define MIC2_ERROR -1
76 
82 #define MIC2_DEVICE_SLAVE_ADDRESS 0x2C
83  // End group macro
86 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef uint16_t mic2_data_t;
96 
100 typedef struct
101 {
102  // Modules
103  i2c_master_t i2c;
104 
105  // ctx variable
106  uint8_t slave_address;
107 
108  analog_in_t adc;
109 
110 } mic2_t;
111 
115 typedef struct
116 {
117  // Communication gpio pins
118  pin_name_t scl;
119  pin_name_t sda;
120  pin_name_t an_pin;
121 
122  // static variable
123 
124  uint32_t i2c_speed;
125  uint8_t i2c_address;
126 
127  analog_in_resolution_t resolution; // Resolution
128  float vref; // VRef
129 
130 } mic2_cfg_t;
131  // End types group
133 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134 
140 #ifdef __cplusplus
141 extern "C"{
142 #endif
143 
153 
162 err_t mic2_init ( mic2_t *ctx, mic2_cfg_t *cfg );
163 
171 void mic2_generic_write ( mic2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
172 
180 void mic2_set_potentiometer ( mic2_t *ctx, uint8_t ptt_value );
181 
193 err_t mic2_read_an_pin_value ( mic2_t *ctx, uint16_t *data_out );
194 
208 err_t mic2_read_an_pin_voltage ( mic2_t *ctx, float *data_out );
209 
210 #ifdef __cplusplus
211 }
212 #endif
213 #endif // _MIC2_H_
214  // End public_function group
217 
218 // ------------------------------------------------------------------------ END
mic2_generic_write
void mic2_generic_write(mic2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Click Default Configuration function.
mic2_cfg_t
Click configuration structure definition.
Definition: mic2.h:116
mic2_cfg_t::i2c_address
uint8_t i2c_address
Definition: mic2.h:125
mic2_cfg_t::sda
pin_name_t sda
Definition: mic2.h:119
mic2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: mic2.h:127
mic2_read_an_pin_voltage
err_t mic2_read_an_pin_voltage(mic2_t *ctx, float *data_out)
MIC 2 read AN pin voltage level function.
mic2_cfg_t::an_pin
pin_name_t an_pin
Definition: mic2.h:120
mic2_t
Click ctx object definition.
Definition: mic2.h:101
mic2_init
err_t mic2_init(mic2_t *ctx, mic2_cfg_t *cfg)
Initialization function.
mic2_cfg_t::vref
float vref
Definition: mic2.h:128
mic2_set_potentiometer
void mic2_set_potentiometer(mic2_t *ctx, uint8_t ptt_value)
Set potentiometer value.
mic2_cfg_t::scl
pin_name_t scl
Definition: mic2.h:118
mic2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: mic2.h:124
mic2_t::slave_address
uint8_t slave_address
Definition: mic2.h:106
mic2_cfg_setup
void mic2_cfg_setup(mic2_cfg_t *cfg)
Config Object Initialization function.
mic2_t::adc
analog_in_t adc
Definition: mic2.h:108
mic2_data_t
uint16_t mic2_data_t
Analog data type.
Definition: mic2.h:95
mic2_t::i2c
i2c_master_t i2c
Definition: mic2.h:103
mic2_read_an_pin_value
err_t mic2_read_an_pin_value(mic2_t *ctx, uint16_t *data_out)
MIC 2 read AN pin value function.