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 
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_spi_master.h"
51 #include "drv_analog_in.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define NOISE_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define NOISE_OK 0
79 #define NOISE_ERROR -1
80 
86 #define NOISE_DEFAULT_COMMAND 0x07
87 #define NOISE_DEFAULT_THRESHOLD 0x0400
88 #define NOISE_DAC_A 0x00
89 #define NOISE_DAC_B 0x08
90 #define NOISE_VREF_UNBUFFERED 0x00
91 #define NOISE_VREF_BUFFERED 0x04
92 #define NOISE_GAIN_2X 0x00
93 #define NOISE_GAIN_1X 0x02
94 #define NOISE_SHDN_ENABLE 0x00
95 #define NOISE_SHDN_DISABLE 0x01
96  // End group macro
99 // --------------------------------------------------------------- PUBLIC TYPES
108 typedef struct
109 {
110  // Output pins
111  digital_out_t rst;
112 
113  // Input pins
114  digital_in_t int_pin;
115 
116  // Modules
117  spi_master_t spi;
118  pin_name_t chip_select;
119  analog_in_t adc;
120 
121 } noise_t;
122 
126 typedef struct
127 {
128  // Communication gpio pins
129  pin_name_t miso;
130  pin_name_t mosi;
131  pin_name_t sck;
132  pin_name_t cs;
133 
134  // Additional gpio pins
135  pin_name_t an;
136  pin_name_t rst;
137  pin_name_t int_pin;
138 
139  // static variable
140  uint32_t spi_speed;
141  spi_master_mode_t spi_mode;
142  spi_master_chip_select_polarity_t cs_polarity;
143 
144  // ADC module variables
145  analog_in_resolution_t resolution;
146  float vref;
147 
148 } noise_cfg_t;
149  // End types group
151 
152 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
171 
179 err_t noise_init ( noise_t *ctx, noise_cfg_t *cfg );
180 
190 
199 void noise_write_cmd_reg ( noise_t *ctx, uint16_t cmd_data );
200 
218 err_t noise_set_cmd_reg ( noise_t *ctx, uint8_t configuration, uint16_t threshold );
219 
228 void noise_set_state ( noise_t *ctx, uint8_t state );
229 
237 void noise_reset ( noise_t *ctx );
238 
248 uint8_t noise_check_int_pin ( noise_t *ctx );
249 
261 err_t noise_read_an_pin_value ( noise_t *ctx, uint16_t *data_out );
262 
276 err_t noise_read_an_pin_voltage ( noise_t *ctx, float *data_out );
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // _NOISE_H_
282  // End public_function group
285 
286 // ------------------------------------------------------------------------- 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:111
noise_cfg_t::int_pin
pin_name_t int_pin
Definition: noise.h:137
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:141
noise_t::chip_select
pin_name_t chip_select
Definition: noise.h:118
noise_cfg_t::an
pin_name_t an
Definition: noise.h:135
noise_cfg_t::sck
pin_name_t sck
Definition: noise.h:131
noise_t::spi
spi_master_t spi
Definition: noise.h:117
noise_cfg_t::resolution
analog_in_resolution_t resolution
Definition: noise.h:145
noise_reset
void noise_reset(noise_t *ctx)
Reset Click.
noise_cfg_t::cs
pin_name_t cs
Definition: noise.h:132
noise_cfg_t::mosi
pin_name_t mosi
Definition: noise.h:130
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:142
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:140
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:146
noise_cfg_t::miso
pin_name_t miso
Definition: noise.h:129
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:114
noise_t::adc
analog_in_t adc
Definition: noise.h:119
noise_t
Click ctx object definition.
Definition: noise.h:109
noise_cfg_t
Click configuration structure definition.
Definition: noise.h:127
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:136