smoke  2.0.0.0
smoke.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 SMOKE_H
36 #define SMOKE_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 SMOKE_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 SMOKE_RETVAL uint8_t
63 
64 #define SMOKE_OK 0x00
65 #define SMOKE_INIT_ERROR 0xFF
66 
72 #define SMOKE_I2C_ADDRESS 0x57
73 
84 #define SMOKE_INT_STAT1 0x00
85 #define SMOKE_INT_STAT2 0x01
86 #define SMOKE_INT_ENABLE1 0x02
87 #define SMOKE_INT_ENABLE2 0x03
88 
94 #define SMOKE_FIFO_WRITE_PTR 0x04
95 #define SMOKE_FIFO_OVERFLOW 0x05
96 #define SMOKE_FIFO_READ_PTR 0x06
97 #define SMOKE_FIFO_DATA 0x07
98 #define SMOKE_BUFFER_LENGTH 32
99 
105 #define SMOKE_FIFO_CONFIG 0x08
106 #define SMOKE_MODE_CONFIG 0x09
107 #define SMOKE_PARTICLE_CONFIG 0x0A
108 #define SMOKE_LED1_PULSE_AMP 0x0C
109 #define SMOKE_LED2_PULSE_AMP 0x0D
110 #define SMOKE_LED3_PULSE_AMP 0x0E
111 #define SMOKE_LED_PROX_AMP 0x10
112 #define SMOKE_MULTI_LED_CONFIG1 0x11
113 #define SMOKE_MULTI_LED_CONFIG2 0x12
114 #define SMOKE_MIN_POWER_LEVEL 0x01
115 #define SMOKE_AVG_POWER_LEVEL 0x1F
116 #define SMOKE_MAX_POWER_LEVEL 0xFF
117 
123 #define SMOKE_DIE_TEMP_INT 0x1F
124 #define SMOKE_DIE_TEMP_FRAC 0x20
125 #define SMOKE_DIE_TEMP_CONFIG 0x21
126 
132 #define SMOKE_PROX_INT_THRESH 0x30
133 
139 #define SMOKE_REVISION_ID 0xFE
140 #define SMOKE_PART_ID 0xFF
141 
154 #define SMOKE_INT_A_FULL_MASK (uint8_t)~0b10000000
155 #define SMOKE_INT_A_FULL_ENABLE 0x80
156 #define SMOKE_INT_A_FULL_DISABLE 0x00
157 #define SMOKE_INT_DATA_RDY_MASK (uint8_t)~0b01000000
158 #define SMOKE_INT_DATA_RDY_ENABLE 0x40
159 #define SMOKE_INT_DATA_RDY_DISABLE 0x00
160 #define SMOKE_INT_ALC_OVF_MASK (uint8_t)~0b00100000
161 #define SMOKE_INT_ALC_OVF_ENABLE 0x20
162 #define SMOKE_INT_ALC_OVF_DISABLE 0x00
163 #define SMOKE_INT_PROX_INT_MASK (uint8_t)~0b00010000
164 #define SMOKE_INT_PROX_INT_ENABLE 0x10
165 #define SMOKE_INT_PROX_INT_DISABLE 0x00
166 #define SMOKE_INT_DIE_TEMP_RDY_MASK (uint8_t)~0b00000010
167 #define SMOKE_INT_DIE_TEMP_RDY_ENABLE 0x02
168 #define SMOKE_INT_DIE_TEMP_RDY_DISABLE 0x00
169 
175 #define SMOKE_SAMPLEAVG_MASK (uint8_t)~0b11100000
176 #define SMOKE_SAMPLEAVG_1 0x00
177 #define SMOKE_SAMPLEAVG_2 0x20
178 #define SMOKE_SAMPLEAVG_4 0x40
179 #define SMOKE_SAMPLEAVG_8 0x60
180 #define SMOKE_SAMPLEAVG_16 0x80
181 #define SMOKE_SAMPLEAVG_32 0xA0
182 #define SMOKE_ROLLOVER_MASK 0xEF
183 #define SMOKE_ROLLOVER_ENABLE 0x10
184 #define SMOKE_ROLLOVER_DISABLE 0x00
185 #define SMOKE_A_FULL_MASK 0xF0
186 
192 #define SMOKE_SHUTDOWN_MASK 0x7F
193 #define SMOKE_SHUTDOWN 0x80
194 #define SMOKE_WAKEUP 0x00
195 #define SMOKE_RESET_MASK 0xBF
196 #define SMOKE_RESET 0x40
197 #define SMOKE_MODE_MASK 0xF8
198 #define SMOKE_MODE_REDONLY 0x02
199 #define SMOKE_MODE_REDIRONLY 0x03
200 #define SMOKE_MODE_MULTILED 0x07
201 
207 #define SMOKE_ADCRANGE_MASK 0x9F
208 #define SMOKE_ADCRANGE_2048 0x00
209 #define SMOKE_ADCRANGE_4096 0x20
210 #define SMOKE_ADCRANGE_8192 0x40
211 #define SMOKE_ADCRANGE_16384 0x60
212 #define SMOKE_SAMPLERATE_MASK 0xE3
213 #define SMOKE_SAMPLERATE_50 0x00
214 #define SMOKE_SAMPLERATE_100 0x04
215 #define SMOKE_SAMPLERATE_200 0x08
216 #define SMOKE_SAMPLERATE_400 0x0C
217 #define SMOKE_SAMPLERATE_800 0x10
218 #define SMOKE_SAMPLERATE_1000 0x14
219 #define SMOKE_SAMPLERATE_1600 0x18
220 #define SMOKE_SAMPLERATE_3200 0x1C
221 #define SMOKE_PULSEWIDTH_MASK 0xFC
222 #define SMOKE_PULSEWIDTH_69 0x00
223 #define SMOKE_PULSEWIDTH_118 0x01
224 #define SMOKE_PULSEWIDTH_215 0x02
225 #define SMOKE_PULSEWIDTH_411 0x03
226 
232 #define SMOKE_SLOT1_MASK 0xF8
233 #define SMOKE_SLOT2_MASK 0x8F
234 #define SMOKE_SLOT3_MASK 0xF8
235 #define SMOKE_SLOT4_MASK 0x8F
236 #define SMOKE_SLOT_NONE 0x00
237 #define SMOKE_SLOT_RED_LED 0x01
238 #define SMOKE_SLOT_IR_LED 0x02
239 #define SMOKE_SLOT_GREEN_LED 0x03
240 #define SMOKE_SLOT_NONE_PILOT 0x04
241 #define SMOKE_SLOT_RED_PILOT 0x05
242 #define SMOKE_SLOT_IR_PILOT 0x06
243 #define SMOKE_SLOT_GREEN_PILOT 0x07
244  // End group macro
247 // --------------------------------------------------------------- PUBLIC TYPES
256 typedef struct
257 {
258  // Input pins
259 
260  digital_in_t int_pin;
261 
262  // Modules
263 
264  i2c_master_t i2c;
265 
266  // ctx variable
267 
268  uint8_t slave_address;
269 
270 } smoke_t;
271 
275 typedef struct
276 {
277  // Communication gpio pins
278 
279  pin_name_t scl;
280  pin_name_t sda;
281 
282  // Additional gpio pins
283 
284  pin_name_t int_pin;
285 
286  // static variable
287 
288  uint32_t i2c_speed;
289  uint8_t i2c_address;
290 
291 } smoke_cfg_t;
292 
296 typedef struct
297 {
298  // Structure fields
299 
300  uint8_t avg_samp;
301  uint8_t mode;
302  uint8_t adc_range;
303  uint8_t samp_rate;
304  uint8_t pulse_width;
305  uint8_t led_pow_lvl;
306 
308  // End types group
310 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
311 
317 #ifdef __cplusplus
318 extern "C"{
319 #endif
320 
329 void smoke_cfg_setup ( smoke_cfg_t *cfg );
330 
340 
348 void smoke_default_cfg ( smoke_t *ctx );
349 
359 void smoke_write_data ( smoke_t *ctx, uint8_t wr_addr, uint8_t wr_data );
360 
371 uint8_t smoke_read_data ( smoke_t *ctx, uint8_t rd_addr );
372 
383 void smoke_multi_read ( smoke_t *ctx, uint8_t rd_addr, uint8_t *buffer, uint8_t cnt );
384 
395 void smoke_set_new_value ( smoke_t *ctx, uint8_t reg, uint8_t mask, uint8_t value );
396 
407 uint8_t smoke_get_intrrupt ( smoke_t *ctx, uint8_t flag );
408 
433 void smoke_enable_disable_interrupts ( smoke_t *ctx, uint8_t interrupt_flag, uint8_t enable_flag );
434 
456 void smoke_setting_function ( smoke_t *ctx, uint8_t flag, uint8_t mode );
457 
478 void smoke_setting_prox_and_amp ( smoke_t *ctx, uint8_t flag, uint8_t write_data );
479 
489 void smoke_enable_slot ( smoke_t *ctx, uint8_t slot_num, uint8_t dev );
490 
498 void smoke_disable_slots ( smoke_t *ctx );
499 
507 void smoke_clear_fifo ( smoke_t *ctx );
508 
528 void smoke_fifo_setting ( smoke_t *ctx, uint8_t flag, uint8_t samp_num );
529 
539 uint8_t smoke_get_write_ptr ( smoke_t *ctx );
540 
550 uint8_t smoke_get_read_ptr ( smoke_t *ctx );
551 
560 float smoke_read_temp_c ( smoke_t *ctx );
561 
570 float smoke_read_temp_f ( smoke_t *ctx );
571 
578 void smoke_reset ( smoke_t *ctx );
579 
588 uint8_t smoke_read_device_id ( smoke_t *ctx );
589 
598 uint32_t smoke_get_red_val ( smoke_t *ctx );
599 
608 uint32_t smoke_get_ir_val ( smoke_t *ctx );
609 
618 uint32_t smoke_get_green_val ( smoke_t *ctx );
619 
637 void smoke_set_registers ( smoke_t *ctx, smoke_set_registers_t *registers );
638 
646 uint8_t smoke_check_int ( smoke_t *ctx );
647 
648 #ifdef __cplusplus
649 }
650 #endif
651 #endif // _SMOKE_H_
652  // End public_function group
655 
656 // ------------------------------------------------------------------------- END
void smoke_set_registers(smoke_t *ctx, smoke_set_registers_t *registers)
Set registers values function.
uint8_t mode
Definition: smoke.h:301
uint32_t smoke_get_red_val(smoke_t *ctx)
Get Red value function.
pin_name_t sda
Definition: smoke.h:280
void smoke_write_data(smoke_t *ctx, uint8_t wr_addr, uint8_t wr_data)
Generic write function.
Click configuration structure definition.
Definition: smoke.h:275
uint8_t smoke_check_int(smoke_t *ctx)
Get Interrupt state function.
uint8_t led_pow_lvl
Definition: smoke.h:305
digital_in_t int_pin
Definition: smoke.h:260
void smoke_clear_fifo(smoke_t *ctx)
Clearing FIFO pointers function.
uint8_t samp_rate
Definition: smoke.h:303
uint8_t i2c_address
Definition: smoke.h:289
i2c_master_t i2c
Definition: smoke.h:264
void smoke_setting_function(smoke_t *ctx, uint8_t flag, uint8_t mode)
Set corresponding configuration register function.
void smoke_multi_read(smoke_t *ctx, uint8_t rd_addr, uint8_t *buffer, uint8_t cnt)
Multi read function.
uint32_t smoke_get_ir_val(smoke_t *ctx)
Get IR value function.
#define SMOKE_RETVAL
Definition: smoke.h:62
uint32_t smoke_get_green_val(smoke_t *ctx)
Get Green value function.
void smoke_set_new_value(smoke_t *ctx, uint8_t reg, uint8_t mask, uint8_t value)
Set new value function.
void smoke_cfg_setup(smoke_cfg_t *cfg)
Config Object Initialization function.
float smoke_read_temp_c(smoke_t *ctx)
Read temperature in Centigrade function.
void smoke_enable_slot(smoke_t *ctx, uint8_t slot_num, uint8_t dev)
Define slots in MultiLED mode function.
void smoke_reset(smoke_t *ctx)
Reset device function.
uint8_t pulse_width
Definition: smoke.h:304
uint8_t smoke_get_intrrupt(smoke_t *ctx, uint8_t flag)
Get desired interrupt function.
uint32_t i2c_speed
Definition: smoke.h:288
uint8_t smoke_read_device_id(smoke_t *ctx)
Read device ID function.
uint8_t adc_range
Definition: smoke.h:302
void smoke_disable_slots(smoke_t *ctx)
Disable slots in MultiLED mode function.
void smoke_default_cfg(smoke_t *ctx)
Click Default Configuration function.
uint8_t slave_address
Definition: smoke.h:268
void smoke_setting_prox_and_amp(smoke_t *ctx, uint8_t flag, uint8_t write_data)
Set corresponding amplitude or proximity threshold function.
Click ctx object definition.
Definition: smoke.h:256
pin_name_t scl
Definition: smoke.h:279
uint8_t smoke_get_read_ptr(smoke_t *ctx)
Read the FIFO Read Pointer function.
float smoke_read_temp_f(smoke_t *ctx)
Read temperature in Fahrenheit function.
uint8_t smoke_read_data(smoke_t *ctx, uint8_t rd_addr)
Generic read function.
pin_name_t int_pin
Definition: smoke.h:284
void smoke_enable_disable_interrupts(smoke_t *ctx, uint8_t interrupt_flag, uint8_t enable_flag)
Enable or disable interrupt function.
uint8_t smoke_get_write_ptr(smoke_t *ctx)
Read the FIFO Write Pointer function.
SMOKE_RETVAL smoke_init(smoke_t *ctx, smoke_cfg_t *cfg)
Initialization function.
void smoke_fifo_setting(smoke_t *ctx, uint8_t flag, uint8_t samp_num)
Set FIFO configuration register function.
uint8_t avg_samp
Definition: smoke.h:300
Click registers object definition.
Definition: smoke.h:296