thunder 2.0.0.0
thunder.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 THUNDER_H
36#define THUNDER_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55#include "spi_specifics.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define THUNDER_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
84#define THUNDER_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
85#define THUNDER_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
86
91#define THUNDER_OK 0x00
92#define THUNDER_ERROR 0xFF
99#define THUNDER_DEV_ADDR_0 0x00
100#define THUNDER_DEV_ADDR_1 0x01
101#define THUNDER_DEV_ADDR_2 0x02
102#define THUNDER_DEV_ADDR_3 0x03
109#define THUNDER_REG_CONFIG_0 0x00
110#define THUNDER_REG_CONFIG_1 0x01
111#define THUNDER_REG_CONFIG_2 0x02
112#define THUNDER_REG_CONFIG_3_INTERR 0x03
113#define THUNDER_REG_ENERGY_LIGHTNING_LSBYTE 0x04
114#define THUNDER_REG_ENERGY_LIGHTNING_MSBYTE 0x05
115#define THUNDER_REG_ENERGY_LIGHTNING_MMSBYTE 0x06
116#define THUNDER_REG_DISTANCE 0x07
117#define THUNDER_REG_INTERR_PIN_CONFIG 0x08
118#define THUNDER_REG_LDLUT_1 0x09
119#define THUNDER_REG_LDLUT_2 0x0A
120#define THUNDER_REG_LDLUT_3 0x0B
121#define THUNDER_REG_LDLUT_4 0x0C
122#define THUNDER_REG_LDLUT_5 0x0D
123#define THUNDER_REG_LDLUT_6 0x0E
124#define THUNDER_REG_LDLUT_7 0x0F
125#define THUNDER_REG_LDLUT_8 0x10
126#define THUNDER_REG_LDLUT_9 0x11
127#define THUNDER_REG_LDLUT_10 0x12
128#define THUNDER_REG_LDLUT_11 0x13
129#define THUNDER_REG_LDLUT_12 0x14
130#define THUNDER_REG_LDLUT_13 0x15
131#define THUNDER_REG_LDLUT_14 0x16
132#define THUNDER_REG_LDLUT_15 0x17
133#define THUNDER_REG_LDLUT_16 0x18
134#define THUNDER_REG_LDLUT_17 0x19
135#define THUNDER_REG_LDLUT_18 0x1A
136#define THUNDER_REG_LDLUT_19 0x1B
137#define THUNDER_REG_LDLUT_20 0x1C
138#define THUNDER_REG_LDLUT_21 0x1D
139#define THUNDER_REG_LDLUT_22 0x1E
140#define THUNDER_REG_LDLUT_23 0x1F
141#define THUNDER_REG_LDLUT_24 0x20
142#define THUNDER_REG_LDLUT_25 0x21
143#define THUNDER_REG_LDLUT_26 0x22
144#define THUNDER_REG_LDLUT_27 0x23
145#define THUNDER_REG_LDLUT_28 0x24
146#define THUNDER_REG_LDLUT_29 0x25
147#define THUNDER_REG_LDLUT_30 0x26
148#define THUNDER_REG_LDLUT_31 0x27
149#define THUNDER_REG_LDLUT_32 0x28
150#define THUNDER_REG_LDLUT_33 0x29
151#define THUNDER_REG_LDLUT_34 0x2A
152#define THUNDER_REG_LDLUT_35 0x2B
153#define THUNDER_REG_LDLUT_36 0x2C
154#define THUNDER_REG_LDLUT_37 0x2D
155#define THUNDER_REG_LDLUT_38 0x2E
156#define THUNDER_REG_LDLUT_39 0x2F
157#define THUNDER_REG_LDLUT_40 0x30
158#define THUNDER_REG_LDLUT_41 0x31
159#define THUNDER_REG_LDLUT_42 0x32
160#define THUNDER_REG_RESET 0x3C
161#define THUNDER_REG_CALIB 0x3D
168#define THUNDER_INDOOR 0x24
169#define THUNDER_OUTDOOR 0x1C
170#define THUNDER_NORMAL_MODE 0x00
171#define THUNDER_POWER_DOWN 0x01
178#define THUNDER_DEFAULT_NOISE_FLOOR_LVL 0x20
179#define THUNDER_DEFAULT_WDG_THRESHOLD 0x02
186#define THUNDER_CLEAR_STAT 0xC0
187#define THUNDER_1_LIGHTNING 0x80
188#define THUNDER_5_LIGHTNINGS 0x90
189#define THUNDER_9_LIGHTNINGS 0xA0
190#define THUNDER_16_LIGHTNINGS 0xB0
191#define THUNDER_DEFAULT_SREJ 0x82
198#define THUNDER_DIV_RATIO_16 0x00
199#define THUNDER_DIV_RATIO_32 0x40
200#define THUNDER_DIV_RATIO_64 0x80
201#define THUNDER_DIV_RATIO_128 0xC0
202#define THUNDER_MASK_DISTURBER 0x20
203#define THUNDER_UNMASK_DISTURBER 0x00
204#define THUNDER_NO_INTERR 0x00
205#define THUNDER_NOISE_LEVEL_INTERR 0x01
206#define THUNDER_DISTURBER_INTERR 0x04
207#define THUNDER_LIGHTNING_INTERR 0x08
214#define THUNDER_LCO_ON_IRQ_PIN 0x80
215#define THUNDER_SRCO_ON_IRQ_PIN 0x40
216#define THUNDER_TRCO_ON_IRQ_PIN 0x20
217#define THUNDER_NO_DISPLAY_ON_IRQ_PIN 0x00
218#define THUNDER_DEFAULT_TUNE_CAP 0x00
225#define THUNDER_RESET_COMM 0x00
226#define THUNDER_CALIB_RCO_COMM 0x01
229 // End group macro
230// --------------------------------------------------------------- PUBLIC TYPES
239typedef struct
240{
241 // Input pins
242 digital_in_t irq;
243
244 // Modules
245 spi_master_t spi;
246 pin_name_t chip_select;
247
248} thunder_t;
249
253typedef struct
254{
255 // Communication gpio pins
256 pin_name_t miso;
257 pin_name_t mosi;
258 pin_name_t sck;
259 pin_name_t cs;
260
261 // Additional gpio pins
262 pin_name_t irq;
263
264 // static variable
265 uint32_t spi_speed;
266 spi_master_mode_t spi_mode;
267 spi_master_chip_select_polarity_t cs_polarity;
268
270
271 // End types group
272// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
273
278#ifdef __cplusplus
279extern "C"{
280#endif
281
291
302
311
324err_t thunder_generic_write ( thunder_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
325
338err_t thunder_generic_read ( thunder_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
339
351err_t thunder_write_reg ( thunder_t *ctx, uint8_t reg, uint8_t data_in );
352
364err_t thunder_read_reg ( thunder_t *ctx, uint8_t reg, uint8_t *data_out );
365
374void thunder_send_command ( thunder_t *ctx, uint8_t command );
375
386
396void thunder_get_storm_info ( thunder_t *ctx, uint32_t *energy_out, uint8_t *distance_out );
397
408
409#ifdef __cplusplus
410}
411#endif
412#endif // _THUNDER_H_
413
414 // End public_function group
416
417// ------------------------------------------------------------------------- END
void thunder_send_command(thunder_t *ctx, uint8_t command)
Command Send function.
void thunder_cfg_setup(thunder_cfg_t *cfg)
Config Object Initialization function.
uint8_t thunder_check_int(thunder_t *ctx)
Interrupt Check function.
uint8_t thunder_check_irq_pin(thunder_t *ctx)
IRQ Pin Check function.
err_t thunder_init(thunder_t *ctx, thunder_cfg_t *cfg)
Initialization function.
err_t thunder_generic_read(thunder_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Generic read function.
err_t thunder_generic_write(thunder_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Generic write function.
void thunder_get_storm_info(thunder_t *ctx, uint32_t *energy_out, uint8_t *distance_out)
Storm Information Get function.
void thunder_default_cfg(thunder_t *ctx)
Click Default Configuration function.
err_t thunder_write_reg(thunder_t *ctx, uint8_t reg, uint8_t data_in)
Write reg function.
err_t thunder_read_reg(thunder_t *ctx, uint8_t reg, uint8_t *data_out)
Read reg function.
This file contains SPI specific macros, functions, etc.
Click configuration structure definition.
Definition thunder.h:254
pin_name_t irq
Definition thunder.h:262
spi_master_chip_select_polarity_t cs_polarity
Definition thunder.h:267
pin_name_t sck
Definition thunder.h:258
spi_master_mode_t spi_mode
Definition thunder.h:266
pin_name_t mosi
Definition thunder.h:257
uint32_t spi_speed
Definition thunder.h:265
pin_name_t miso
Definition thunder.h:256
pin_name_t cs
Definition thunder.h:259
Click ctx object definition.
Definition thunder.h:240
spi_master_t spi
Definition thunder.h:245
digital_in_t irq
Definition thunder.h:242
pin_name_t chip_select
Definition thunder.h:246