noise  2.0.0.0
noise.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 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef NOISE_H
36 #define NOISE_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_spi_master.h"
55 #include "drv_analog_in.h"
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
68 #define NOISE_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
74  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
75  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76 
82 #define NOISE_OK 0
83 #define NOISE_ERROR -1
84 
90 #define NOISE_DEFAULT_COMMAND 0x07
91 #define NOISE_DEFAULT_THRESHOLD 0x0400
92 #define NOISE_DAC_A 0x00
93 #define NOISE_DAC_B 0x08
94 #define NOISE_VREF_UNBUFFERED 0x00
95 #define NOISE_VREF_BUFFERED 0x04
96 #define NOISE_GAIN_2X 0x00
97 #define NOISE_GAIN_1X 0x02
98 #define NOISE_SHDN_ENABLE 0x00
99 #define NOISE_SHDN_DISABLE 0x01
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
112 typedef struct
113 {
114  // Output pins
115  digital_out_t rst;
116 
117  // Input pins
118  digital_in_t int_pin;
119 
120  // Modules
121  spi_master_t spi;
122  pin_name_t chip_select;
123  analog_in_t adc;
124 
125 } noise_t;
126 
130 typedef struct
131 {
132  // Communication gpio pins
133  pin_name_t miso;
134  pin_name_t mosi;
135  pin_name_t sck;
136  pin_name_t cs;
137 
138  // Additional gpio pins
139  pin_name_t an;
140  pin_name_t rst;
141  pin_name_t int_pin;
142 
143  // static variable
144  uint32_t spi_speed;
145  spi_master_mode_t spi_mode;
146  spi_master_chip_select_polarity_t cs_polarity;
147 
148  // ADC module variables
149  analog_in_resolution_t resolution;
150  float vref;
151 
152 } noise_cfg_t;
153  // End types group
155 
156 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
157 
162 #ifdef __cplusplus
163 extern "C"{
164 #endif
165 
175 
183 err_t noise_init ( noise_t *ctx, noise_cfg_t *cfg );
184 
194 
203 void noise_write_cmd_reg ( noise_t *ctx, uint16_t cmd_data );
204 
222 err_t noise_set_cmd_reg ( noise_t *ctx, uint8_t configuration, uint16_t threshold );
223 
232 void noise_set_state ( noise_t *ctx, uint8_t state );
233 
241 void noise_reset ( noise_t *ctx );
242 
252 uint8_t noise_check_int_pin ( noise_t *ctx );
253 
265 err_t noise_read_an_pin_value ( noise_t *ctx, uint16_t *data_out );
266 
280 err_t noise_read_an_pin_voltage ( noise_t *ctx, float *data_out );
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 #endif // _NOISE_H_
286  // End public_function group
289 
290 // ------------------------------------------------------------------------- END
noise_read_an_pin_voltage
err_t noise_read_an_pin_voltage(noise_t *ctx, float *data_out)
Noise read AN pin voltage level function.
noise_read_an_pin_value
err_t noise_read_an_pin_value(noise_t *ctx, uint16_t *data_out)
Noise read AN pin value function.
noise_t::rst
digital_out_t rst
Definition: noise.h:115
noise_cfg_t::int_pin
pin_name_t int_pin
Definition: noise.h:141
noise_init
err_t noise_init(noise_t *ctx, noise_cfg_t *cfg)
Initialization function.
noise_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: noise.h:145
noise_t::chip_select
pin_name_t chip_select
Definition: noise.h:122
noise_cfg_t::an
pin_name_t an
Definition: noise.h:139
noise_cfg_t::sck
pin_name_t sck
Definition: noise.h:135
noise_t::spi
spi_master_t spi
Definition: noise.h:121
noise_cfg_t::resolution
analog_in_resolution_t resolution
Definition: noise.h:149
noise_reset
void noise_reset(noise_t *ctx)
Reset Click.
noise_cfg_t::cs
pin_name_t cs
Definition: noise.h:136
noise_cfg_t::mosi
pin_name_t mosi
Definition: noise.h:134
noise_cfg_setup
void noise_cfg_setup(noise_cfg_t *cfg)
Config Object Initialization function.
noise_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: noise.h:146
noise_set_cmd_reg
err_t noise_set_cmd_reg(noise_t *ctx, uint8_t configuration, uint16_t threshold)
Set Command Register.
noise_cfg_t::spi_speed
uint32_t spi_speed
Definition: noise.h:144
noise_write_cmd_reg
void noise_write_cmd_reg(noise_t *ctx, uint16_t cmd_data)
Write to Command Register.
noise_cfg_t::vref
float vref
Definition: noise.h:150
noise_cfg_t::miso
pin_name_t miso
Definition: noise.h:133
noise_default_cfg
void noise_default_cfg(noise_t *ctx)
Click Default Configuration function.
noise_set_state
void noise_set_state(noise_t *ctx, uint8_t state)
Enable/disable click.
noise_t::int_pin
digital_in_t int_pin
Definition: noise.h:118
noise_t::adc
analog_in_t adc
Definition: noise.h:123
noise_t
Click ctx object definition.
Definition: noise.h:113
noise_cfg_t
Click configuration structure definition.
Definition: noise.h:131
noise_check_int_pin
uint8_t noise_check_int_pin(noise_t *ctx)
Get INT pin state.
noise_cfg_t::rst
pin_name_t rst
Definition: noise.h:140