rng  2.0.0.0
rng.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 RNG_H
36 #define RNG_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define RNG_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define RNG_RETVAL uint8_t
63 
64 #define RNG_OK 0x00
65 #define RNG_INIT_ERROR 0xFF
66 
72 #define RNG_DEVICE_SLAVE_ADDRESS_GND 0x48
73 #define RNG_DEVICE_SLAVE_ADDRESS_VDD 0x49
74 #define RNG_DEVICE_SLAVE_ADDRESS_SDA 0x4A
75 #define RNG_DEVICE_SLAVE_ADDRESS_SCL 0x4B
76 
82 #define RNG_RESET_DEVICE 0x06
83 
89 #define RNG_CONVERSION_REG 0x00
90 #define RNG_CONFIG_REG 0x01
91 #define RNG_LO_THRESH_REG 0x02
92 #define RNG_HI_THRESH_REG 0x03
93 
99 #define RNG_CONFIG_REG_COMP_QUEUE_DISABLE 0x0003
100 #define RNG_CONFIG_REG_COMP_QUEUE_4_CONV 0x0002
101 #define RNG_CONFIG_REG_COMP_QUEUE_2_CONV 0x0001
102 #define RNG_CONFIG_REG_COMP_QUEUE_1_CONV 0x0000
103 #define RNG_CONFIG_REG_COMP_LAT_NON 0x0000
104 #define RNG_CONFIG_REG_COMP_LAT 0x0004
105 #define RNG_CONFIG_REG_COMP_POL_LOW 0x0000
106 #define RNG_CONFIG_REG_COMP_POL_HIGH 0x0008
107 #define RNG_CONFIG_REG_COMP_MODE_TRAD 0x0000
108 #define RNG_CONFIG_REG_COMP_MODE_WINDOW 0x0010
109 #define RNG_CONFIG_REG_DATA_RATE_8_SPS 0x0000
110 #define RNG_CONFIG_REG_DATA_RATE_16_SPS 0x0020
111 #define RNG_CONFIG_REG_DATA_RATE_32_SPS 0x0040
112 #define RNG_CONFIG_REG_DATA_RATE_64_SPS 0x0060
113 #define RNG_CONFIG_REG_DATA_RATE_128_SPS 0x0080
114 #define RNG_CONFIG_REG_DATA_RATE_250_SPS 0x00A0
115 #define RNG_CONFIG_REG_DATA_RATE_475_SPS 0x00C0
116 #define RNG_CONFIG_REG_DATA_RATE_860_SPS 0x00E0
117 #define RNG_CONFIG_REG_DEV_MODE_SINGLE 0x0100
118 #define RNG_CONFIG_REG_DEV_MODE_CONTIN 0x0000
119 #define RNG_CONFIG_REG_PGA_6144 0x0000
120 #define RNG_CONFIG_REG_PGA_4096 0x0200
121 #define RNG_CONFIG_REG_PGA_2048 0x0400
122 #define RNG_CONFIG_REG_PGA_1024 0x0600
123 #define RNG_CONFIG_REG_PGA_512 0x0800
124 #define RNG_CONFIG_REG_PGA_256_1 0x0A00
125 #define RNG_CONFIG_REG_PGA_256_2 0x0C00
126 #define RNG_CONFIG_REG_PGA_256_3 0x0E00
127 #define RNG_CONFIG_REG_MUX_AINP_AINN_0_1 0x0000
128 #define RNG_CONFIG_REG_MUX_AINP_AINN_0_3 0x1000
129 #define RNG_CONFIG_REG_MUX_AINP_AINN_1_3 0x2000
130 #define RNG_CONFIG_REG_MUX_AINP_AINN_2_3 0x3000
131 #define RNG_CONFIG_REG_MUX_AINP_AINN_0_GND 0x4000
132 #define RNG_CONFIG_REG_MUX_AINP_AINN_1_GND 0x5000
133 #define RNG_CONFIG_REG_MUX_AINP_AINN_2_GND 0x6000
134 #define RNG_CONFIG_REG_MUX_AINP_AINN_3_GND 0x7000
135 #define RNG_CONFIG_REG_OS_SINGLE_CONV 0x8000
136 #define RNG_CONFIG_REG_OS_NO_EFFECT 0x0000
137 
143 #define RNG_REG_LOWTHRES_HOLD 0x8000
144 #define RNG_REG_HIGH_THRESH_HOLD 0x7FFF
145  // End group macro
148 // --------------------------------------------------------------- PUBLIC TYPES
157 typedef struct
158 {
159  // Input pins
160 
161  digital_in_t int_pin;
162 
163  // Modules
164 
165  i2c_master_t i2c;
166 
167  // ctx variable
168 
169  uint8_t slave_address;
170 
171  // static variable
172 
173  uint16_t dev_vref;
174 
175 } rng_t;
176 
180 typedef struct
181 {
182  // Communication gpio pins
183 
184  pin_name_t scl;
185  pin_name_t sda;
186 
187  // Additional gpio pins
188 
189  pin_name_t int_pin;
190 
191  // static variable
192 
193  uint32_t i2c_speed;
194  uint8_t i2c_address;
195 
196  uint16_t dev_vref_cfg;
197 
198 } rng_cfg_t;
199  // End types group
201 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
202 
208 #ifdef __cplusplus
209 extern "C"{
210 #endif
211 
220 void rng_cfg_setup ( rng_cfg_t *cfg );
221 
230 RNG_RETVAL rng_init ( rng_t *ctx, rng_cfg_t *cfg );
231 
239 void rng_default_cfg ( rng_t *ctx );
240 
250 void rng_write_function ( rng_t *ctx, uint8_t reg, uint16_t reg_data );
251 
262 uint16_t rng_read_function ( rng_t *ctx, uint8_t reg );
263 
271 void rng_reset_device ( rng_t *ctx );
272 
281 void rng_set_config ( rng_t *ctx, uint16_t conf_data );
282 
291 void rng_set_vref ( rng_t *ctx, uint16_t vref_mv );
292 
302 float rng_get_voltage ( rng_t *ctx );
303 
313 void rng_set_threshold ( rng_t *ctx, uint8_t thresh_reg, uint16_t thresh_data );
314 
315 
316 #ifdef __cplusplus
317 }
318 #endif
319 #endif // _RNG_H_
320  // End public_function group
323 
324 // ------------------------------------------------------------------------- END
rng_cfg_t::int_pin
pin_name_t int_pin
Definition: rng.h:189
rng_set_threshold
void rng_set_threshold(rng_t *ctx, uint8_t thresh_reg, uint16_t thresh_data)
Function used for set threshold values.
rng_cfg_t::dev_vref_cfg
uint16_t dev_vref_cfg
Definition: rng.h:196
rng_reset_device
void rng_reset_device(rng_t *ctx)
Function used for reset device.
rng_cfg_t::sda
pin_name_t sda
Definition: rng.h:185
rng_set_config
void rng_set_config(rng_t *ctx, uint16_t conf_data)
Function used for set configuration.
rng_get_voltage
float rng_get_voltage(rng_t *ctx)
Function used for get voltage.
rng_default_cfg
void rng_default_cfg(rng_t *ctx)
Click Default Configuration function.
rng_cfg_t::scl
pin_name_t scl
Definition: rng.h:184
rng_t::dev_vref
uint16_t dev_vref
Definition: rng.h:173
rng_t::slave_address
uint8_t slave_address
Definition: rng.h:169
rng_read_function
uint16_t rng_read_function(rng_t *ctx, uint8_t reg)
Read function.
rng_init
RNG_RETVAL rng_init(rng_t *ctx, rng_cfg_t *cfg)
Initialization function.
rng_t::i2c
i2c_master_t i2c
Definition: rng.h:165
rng_cfg_t
Click configuration structure definition.
Definition: rng.h:180
rng_cfg_t::i2c_address
uint8_t i2c_address
Definition: rng.h:194
rng_t
Click ctx object definition.
Definition: rng.h:157
rng_set_vref
void rng_set_vref(rng_t *ctx, uint16_t vref_mv)
Function used for set vref in millivolts.
rng_t::int_pin
digital_in_t int_pin
Definition: rng.h:161
rng_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: rng.h:193
rng_write_function
void rng_write_function(rng_t *ctx, uint8_t reg, uint16_t reg_data)
Write function.
rng_cfg_setup
void rng_cfg_setup(rng_cfg_t *cfg)
Config Object Initialization function.
RNG_RETVAL
#define RNG_RETVAL
Definition: rng.h:62