smoke2  2.0.0.0
smoke2.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef SMOKE2_H
29 #define SMOKE2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_spi_master.h"
49 #include "spi_specifics.h"
50 
71 #define SMOKE2_REG_STATUS 0x00
72 #define SMOKE2_REG_INT_MASK 0x01
73 #define SMOKE2_REG_GPIO_DRV 0x02
74 #define SMOKE2_REG_BG_STATUS 0x04
75 #define SMOKE2_REG_FIFO_THR 0x06
76 #define SMOKE2_REG_DEVID 0x08
77 #define SMOKE2_REG_I2CS_ID 0x09
78 #define SMOKE2_REG_CLK_RATIO 0x0A
79 #define SMOKE2_REG_GPIO_CTRL 0x0B
80 #define SMOKE2_REG_SLAVE_ADDR_KEY 0x0D
81 #define SMOKE2_REG_SW_RESET 0x0F
82 #define SMOKE2_REG_MODE 0x10
83 #define SMOKE2_REG_SLOT_EN 0x11
84 #define SMOKE2_REG_FSAMPLE 0x12
85 #define SMOKE2_REG_PD_LED_SELECT 0x14
86 #define SMOKE2_REG_NUM_AVG 0x15
87 #define SMOKE2_REG_BIG_MEAS_A 0x16
88 #define SMOKE2_REG_INT_SEQ_A 0x17
89 #define SMOKE2_REG_SLOTA_CH1_OFFSET 0x18
90 #define SMOKE2_REG_SLOTA_CH2_OFFSET 0x19
91 #define SMOKE2_REG_SLOTA_CH3_OFFSET 0x1A
92 #define SMOKE2_REG_SLOTA_CH4_OFFSET 0x1B
93 #define SMOKE2_REG_BIG_MEAS_B 0x1C
94 #define SMOKE2_REG_INT_SEQ_B 0x1D
95 #define SMOKE2_REG_SLOTB_CH1_OFFSET 0x1E
96 #define SMOKE2_REG_SLOTB_CH2_OFFSET 0x1F
97 #define SMOKE2_REG_SLOTB_CH3_OFFSET 0x20
98 #define SMOKE2_REG_SLOTB_CH4_OFFSET 0x21
99 #define SMOKE2_REG_ILED3_COARSE 0x22
100 #define SMOKE2_REG_ILED1_COARSE 0x23
101 #define SMOKE2_REG_ILED2_COARSE 0x24
102 #define SMOKE2_REG_ILED_FINE 0x25
103 #define SMOKE2_REG_SLOTA_LED_PULSE 0x30
104 #define SMOKE2_REG_SLOTA_NUM_PULSES 0x31
105 #define SMOKE2_REG_LED_DISABLE 0x34
106 #define SMOKE2_REG_SLOTB_LED_PULSE 0x35
107 #define SMOKE2_REG_SLOTB_NUM_PULSES 0x36
108 #define SMOKE2_REG_ALT_PWR_DN 0x37
109 #define SMOKE2_REG_EXT_SYNC_STARTUP 0x38
110 #define SMOKE2_REG_SLOTA_AFE_WINDOW 0x39
111 #define SMOKE2_REG_SLOTB_AFE_WINDOW 0x3B
112 #define SMOKE2_REG_AFE_PWR_CFG1 0x3C
113 #define SMOKE2_REG_SLOTA_FLOAT_LED 0x3E
114 #define SMOKE2_REG_SLOTB_FLOAT_LED 0x3F
115 #define SMOKE2_REG_SLOTA_TIA_CFG 0x42
116 #define SMOKE2_REG_SLOTA_AFE_CFG 0x43
117 #define SMOKE2_REG_SLOTB_TIA_CFG 0x44
118 #define SMOKE2_REG_SLOTB_AFE_CFG 0x45
119 #define SMOKE2_REG_SAMPLE_CLK 0x4B
120 #define SMOKE2_REG_CLK32M_ADJUST 0x4D
121 #define SMOKE2_REG_EXT_SYNC_SEL 0x4F
122 #define SMOKE2_REG_CLK32M_CAL_EN 0x50
123 #define SMOKE2_REG_AFE_PWR_CFG2 0x54
124 #define SMOKE2_REG_TIA_INDEP_GAIN 0x55
125 #define SMOKE2_REG_MATH 0x58
126 #define SMOKE2_REG_FLT_CONFIG_B 0x59
127 #define SMOKE2_REG_FLT_LED_FIRE 0x5A
128 #define SMOKE2_REG_FLT_CONFIG_A 0x5E
129 #define SMOKE2_REG_DATA_ACCESS_CTL 0x5F
130 #define SMOKE2_REG_FIFO_ACCESS 0x60
131 #define SMOKE2_REG_SLOTA_CH1 0x64
132 #define SMOKE2_REG_SLOTA_CH2 0x65
133 #define SMOKE2_REG_SLOTA_CH3 0x66
134 #define SMOKE2_REG_SLOTA_CH4 0x67
135 #define SMOKE2_REG_SLOTB_CH1 0x68
136 #define SMOKE2_REG_SLOTB_CH2 0x69
137 #define SMOKE2_REG_SLOTB_CH3 0x6A
138 #define SMOKE2_REG_SLOTB_CH4 0x6B
139 #define SMOKE2_REG_A_CH1_LOW 0x70
140 #define SMOKE2_REG_A_CH2_LOW 0x71
141 #define SMOKE2_REG_A_CH3_LOW 0x72
142 #define SMOKE2_REG_A_CH4_LOW 0x73
143 #define SMOKE2_REG_A_CH1_HIGH 0x74
144 #define SMOKE2_REG_A_CH2_HIGH 0x75
145 #define SMOKE2_REG_A_CH3_HIGH 0x76
146 #define SMOKE2_REG_A_CH4_HIGH 0x77
147 #define SMOKE2_REG_B_CH1_LOW 0x78
148 #define SMOKE2_REG_B_CH2_LOW 0x79
149 #define SMOKE2_REG_B_CH3_LOW 0x7A
150 #define SMOKE2_REG_B_CH4_LOW 0x7B
151 #define SMOKE2_REG_B_CH1_HIGH 0x7C
152 #define SMOKE2_REG_B_CH2_HIGH 0x7D
153 #define SMOKE2_REG_B_CH3_HIGH 0x7E
154 #define SMOKE2_REG_B_CH4_HIGH 0x7F
155  // smoke2_reg
157 
172 #define SMOKE2_SLOT_A 0
173 #define SMOKE2_SLOT_B 4
174 
179 #define SMOKE2_CHN_1 0
180 #define SMOKE2_CHN_2 1
181 #define SMOKE2_CHN_3 2
182 #define SMOKE2_CHN_4 3
183 
188 #define SMOKE2_MODE_IDLE 0
189 #define SMOKE2_MODE_PROGRAM 1
190 #define SMOKE2_MODE_NORMAL 2
191 
196 #define SMOKE2_SMOKE_DETECTED 0xCC
197 #define SMOKE2_SMOKE_NOT_DETECTED 0xDD
198 
203 #define SMOKE2_READ_CMD 0
204 #define SMOKE2_WRITE_CMD 1
205 
211 #define SMOKE2_SET_DEV_ADDR 0x64
212 
221 #define SMOKE2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
222 #define SMOKE2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
223  // smoke2_set
225 
240 #define SMOKE2_MAP_MIKROBUS( cfg, mikrobus ) \
241  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
242  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
243  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
244  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
245  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
246  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
247  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
248  // smoke2_map // smoke2
251 
256 typedef enum
257 {
262 
267 typedef err_t ( *smoke2_master_io_t )( struct smoke2_s*, uint8_t, uint8_t*, uint8_t );
273 typedef struct smoke2_s
274 {
275  digital_in_t int_pin;
277  i2c_master_t i2c;
278  spi_master_t spi;
280  uint8_t slave_address;
281  pin_name_t chip_select;
288  uint16_t threshold_value;
289  uint8_t enabled_slot;
290 
292 
297 typedef struct
298 {
299  pin_name_t scl;
300  pin_name_t sda;
301  pin_name_t miso;
302  pin_name_t mosi;
303  pin_name_t sck;
304  pin_name_t cs;
305  pin_name_t int_pin;
307  uint32_t i2c_speed;
308  uint8_t i2c_address;
310  uint32_t spi_speed;
311  spi_master_mode_t spi_mode;
312  spi_master_chip_select_polarity_t cs_polarity;
316 } smoke2_cfg_t;
317 
322 typedef enum
323 {
325  SMOKE2_ERROR = -1
326 
328 
345 
361 
376 err_t smoke2_init ( smoke2_t *ctx, smoke2_cfg_t *cfg );
377 
389 
405 err_t smoke2_generic_write ( smoke2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
406 
422 err_t smoke2_generic_read ( smoke2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
423 
433 uint8_t smoke2_get_int_pin ( smoke2_t *ctx );
434 
446 void smoke2_write_data( smoke2_t *ctx, uint8_t reg, uint16_t tx_data );
447 
458 uint16_t smoke2_read_data( smoke2_t *ctx, uint8_t reg );
459 
472 void smoke2_set_bit ( smoke2_t *ctx, uint8_t reg, uint8_t bit_num , uint8_t val );
473 
485 uint8_t smoke2_get_bit ( smoke2_t *ctx, uint8_t reg, uint8_t bit_num );
486 
497 void smoke2_set_mode ( smoke2_t *ctx, uint8_t mode );
498 
511 void smoke2_get_int ( smoke2_t *ctx, uint8_t *fifo, uint8_t *slot_a, uint8_t *slot_b );
512 
524 uint16_t smoke2_read_sens_data ( smoke2_t *ctx, uint8_t slot, uint8_t chn );
525 
536 
547 uint16_t smoke2_smoke_calibration ( smoke2_t *ctx, uint16_t threshold );
548 
558 uint8_t smoke2_check_smoke ( smoke2_t *ctx );
559 
560 #ifdef __cplusplus
561 }
562 #endif
563 #endif // SMOKE2_H
564  // smoke2
566 
567 // ------------------------------------------------------------------------ END
smoke2_cfg_t::sda
pin_name_t sda
Definition: smoke2.h:300
smoke2_t
struct smoke2_s smoke2_t
Smoke 2 Click context object.
smoke2_get_bit
uint8_t smoke2_get_bit(smoke2_t *ctx, uint8_t reg, uint8_t bit_num)
Smoke 2 generic function for reading bit state.
smoke2_get_int
void smoke2_get_int(smoke2_t *ctx, uint8_t *fifo, uint8_t *slot_a, uint8_t *slot_b)
Smoke 2 get mode function.
smoke2_s
Smoke 2 Click context object.
Definition: smoke2.h:274
smoke2_generic_write
err_t smoke2_generic_write(smoke2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Smoke 2 data writing function.
smoke2_s::i2c
i2c_master_t i2c
Definition: smoke2.h:277
smoke2_cfg_t::int_pin
pin_name_t int_pin
Definition: smoke2.h:305
smoke2_s::int_pin
digital_in_t int_pin
Definition: smoke2.h:275
smoke2_cfg_t::cs
pin_name_t cs
Definition: smoke2.h:304
smoke2_cfg_t::sck
pin_name_t sck
Definition: smoke2.h:303
smoke2_read_data
uint16_t smoke2_read_data(smoke2_t *ctx, uint8_t reg)
Smoke 2 generic function for reading data from registar.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
smoke2_cfg_t::i2c_address
uint8_t i2c_address
Definition: smoke2.h:308
smoke2_cfg_setup
void smoke2_cfg_setup(smoke2_cfg_t *cfg)
Smoke 2 configuration object setup function.
smoke2_cfg_t::drv_sel
smoke2_drv_t drv_sel
Definition: smoke2.h:314
smoke2_set_bit
void smoke2_set_bit(smoke2_t *ctx, uint8_t reg, uint8_t bit_num, uint8_t val)
Smoke 2 generic function for writing bit state.
smoke2_s::threshold_value
uint16_t threshold_value
Definition: smoke2.h:288
smoke2_read_sens_data
uint16_t smoke2_read_sens_data(smoke2_t *ctx, uint8_t slot, uint8_t chn)
Smoke 2 reading bit state function.
smoke2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: smoke2.h:311
smoke2_write_data
void smoke2_write_data(smoke2_t *ctx, uint8_t reg, uint16_t tx_data)
Smoke 2 generic function for writing data to register function.
smoke2_drv_t
smoke2_drv_t
Smoke 2 Click driver selector.
Definition: smoke2.h:257
smoke2_cfg_t::spi_speed
uint32_t spi_speed
Definition: smoke2.h:310
smoke2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: smoke2.h:312
smoke2_s::slave_address
uint8_t slave_address
Definition: smoke2.h:280
SMOKE2_OK
@ SMOKE2_OK
Definition: smoke2.h:324
smoke2_s::calibration_value
uint16_t calibration_value
Definition: smoke2.h:287
SMOKE2_DRV_SEL_I2C
@ SMOKE2_DRV_SEL_I2C
Definition: smoke2.h:259
smoke2_cfg_t::mosi
pin_name_t mosi
Definition: smoke2.h:302
smoke2_drv_interface_selection
void smoke2_drv_interface_selection(smoke2_cfg_t *cfg, smoke2_drv_t drv_sel)
Smoke 2 driver interface setup function.
smoke2_smoke_calibration
uint16_t smoke2_smoke_calibration(smoke2_t *ctx, uint16_t threshold)
Smoke 2 calibrating data and setting threshold function.
smoke2_init
err_t smoke2_init(smoke2_t *ctx, smoke2_cfg_t *cfg)
Smoke 2 initialization function.
smoke2_default_cfg
void smoke2_default_cfg(smoke2_t *ctx)
Smoke 2 default configuration function.
smoke2_return_value_t
smoke2_return_value_t
Smoke 2 Click return value data.
Definition: smoke2.h:323
smoke2_generic_read
err_t smoke2_generic_read(smoke2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Smoke 2 data reading function.
smoke2_cfg_t::miso
pin_name_t miso
Definition: smoke2.h:301
smoke2_s::enabled_slot
uint8_t enabled_slot
Definition: smoke2.h:289
smoke2_master_io_t
err_t(* smoke2_master_io_t)(struct smoke2_s *, uint8_t, uint8_t *, uint8_t)
Smoke 2 Click driver interface.
Definition: smoke2.h:267
smoke2_s::chip_select
pin_name_t chip_select
Definition: smoke2.h:281
SMOKE2_ERROR
@ SMOKE2_ERROR
Definition: smoke2.h:325
smoke2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: smoke2.h:307
smoke2_s::drv_sel
smoke2_drv_t drv_sel
Definition: smoke2.h:282
smoke2_s::read_f
smoke2_master_io_t read_f
Definition: smoke2.h:285
smoke2_cfg_t::scl
pin_name_t scl
Definition: smoke2.h:299
smoke2_cfg_t
Smoke 2 Click configuration object.
Definition: smoke2.h:298
smoke2_soft_reset
void smoke2_soft_reset(smoke2_t *ctx)
Smoke 2 reseting device function.
smoke2_s::spi
spi_master_t spi
Definition: smoke2.h:278
smoke2_set_mode
void smoke2_set_mode(smoke2_t *ctx, uint8_t mode)
Smoke 2 setting mode function.
smoke2_s::write_f
smoke2_master_io_t write_f
Definition: smoke2.h:284
smoke2_check_smoke
uint8_t smoke2_check_smoke(smoke2_t *ctx)
Smoke 2 checking smoke detection function.
SMOKE2_DRV_SEL_SPI
@ SMOKE2_DRV_SEL_SPI
Definition: smoke2.h:258
smoke2_get_int_pin
uint8_t smoke2_get_int_pin(smoke2_t *ctx)
Smoke 2 get state of int pin function.