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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 #include "drv_analog_in.h"
43 
44 // -------------------------------------------------------------- PUBLIC MACROS
55 #define NOISE_MAP_MIKROBUS( cfg, mikrobus ) \
56  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
57  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
58  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
59  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
60  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
61  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
62  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
63 
69 #define NOISE_RETVAL uint8_t
70 
71 #define NOISE_OK 0x00
72 #define NOISE_INIT_ERROR 0xFF
73 
79 #define NOISE_DEFAULT_COMMAND 0x01
80 #define NOISE_DEFAULT_THRESHOLD 0x0064
81 #define NOISE_DAC_A 0x00
82 #define NOISE_DAC_B 0x08
83 #define NOISE_VREF_UNBUFFERED 0x00
84 #define NOISE_VREF_BUFFERED 0x04
85 #define NOISE_GAIN_2X 0x00
86 #define NOISE_GAIN_1X 0x02
87 #define NOISE_SHDN_ENABLE 0x00
88 #define NOISE_SHDN_DISABLE 0x01
89  // End group macro
93 // --------------------------------------------------------------- PUBLIC TYPES
102 //typedef analog_in_data_t noise_data_t;
103 
107 typedef struct
108 {
109  // Output pins
110 
111  digital_out_t rst;
112  digital_out_t cs;
113 
114  // Input pins
115 
116  digital_in_t an;
117  digital_in_t int_pin;
118 
119  // Modules
120 
121  spi_master_t spi;
122  pin_name_t chip_select;
123 
124  // dodato
125 
126  analog_in_t adc;
127 
128 } noise_t;
129 
133 typedef struct
134 {
135  // Communication gpio pins
136 
137  pin_name_t miso;
138  pin_name_t mosi;
139  pin_name_t sck;
140  pin_name_t cs;
141 
142  // Additional gpio pins
143 
144  pin_name_t an;
145  pin_name_t rst;
146  pin_name_t int_pin;
147 
148  // static variable
149 
150  uint32_t spi_speed;
151  uint8_t spi_mode;
152  spi_master_chip_select_polarity_t cs_polarity;
153 
154  // dodato
155 
156  analog_in_resolution_t resolution; // Resolution
157  float vref; // VRef
158 
159 } noise_cfg_t;
160  // End types group
162 
163 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
181 void noise_cfg_setup ( noise_cfg_t *cfg );
182 
191 
200 void noise_default_cfg ( noise_t *ctx );
201 
214 (
215  noise_t *ctx,
216  uint8_t *wr_buf,
217  uint16_t wr_len,
218  uint8_t *rd_buf,
219  uint16_t rd_len
220 );
221 
230 void noise_write_command_register ( noise_t *ctx, uint16_t command_and_data_bits );
231 
249 uint8_t noise_set_command_register ( noise_t *ctx, uint8_t configuration,
250  uint16_t threshold );
251 
260 void noise_set_state ( noise_t *ctx, uint8_t state );
261 
269 void noise_reset ( noise_t *ctx );
270 
280 uint8_t noise_check_int_pin ( noise_t *ctx );
281 
291 uint16_t noise_generic_read ( noise_t *ctx );
292 
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 #endif // _NOISE_H_
298  // End public_function group
301 
302 // ------------------------------------------------------------------------- END
noise_set_command_register
uint8_t noise_set_command_register(noise_t *ctx, uint8_t configuration, uint16_t threshold)
Set Command Register.
noise_t::an
digital_in_t an
Definition: noise.h:116
NOISE_RETVAL
#define NOISE_RETVAL
Definition: noise.h:69
noise_t::rst
digital_out_t rst
Definition: noise.h:111
noise_cfg_t::int_pin
pin_name_t int_pin
Definition: noise.h:146
noise_generic_read
uint16_t noise_generic_read(noise_t *ctx)
Read ADC Value.
noise_init
NOISE_RETVAL noise_init(noise_t *ctx, noise_cfg_t *cfg)
Initialization function.
noise_write_command_register
void noise_write_command_register(noise_t *ctx, uint16_t command_and_data_bits)
Write to Command Register.
noise_t::chip_select
pin_name_t chip_select
Definition: noise.h:122
noise_cfg_t::an
pin_name_t an
Definition: noise.h:144
noise_cfg_t::sck
pin_name_t sck
Definition: noise.h:139
noise_t::spi
spi_master_t spi
Definition: noise.h:121
noise_cfg_t::resolution
analog_in_resolution_t resolution
Definition: noise.h:156
noise_reset
void noise_reset(noise_t *ctx)
Reset Click.
noise_cfg_t::cs
pin_name_t cs
Definition: noise.h:140
noise_cfg_t::mosi
pin_name_t mosi
Definition: noise.h:138
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:152
noise_cfg_t::spi_speed
uint32_t spi_speed
Definition: noise.h:150
noise_t::cs
digital_out_t cs
Definition: noise.h:112
noise_cfg_t::vref
float vref
Definition: noise.h:157
noise_cfg_t::spi_mode
uint8_t spi_mode
Definition: noise.h:151
noise_cfg_t::miso
pin_name_t miso
Definition: noise.h:137
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:117
noise_t::adc
analog_in_t adc
Definition: noise.h:126
noise_t
Analog data type.
Definition: noise.h:107
noise_cfg_t
Click configuration structure definition.
Definition: noise.h:133
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:145
noise_generic_transfer
void noise_generic_transfer(noise_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.