42#define CHIP_NAME "AMS AS3935"
43#define MANUFACTURER_NAME "AMS"
44#define SUPPLY_VOLTAGE_MIN 2.4f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 0.35f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define AS3935_REG_NUMBER_0 0x00
55#define AS3935_REG_NUMBER_1 0x01
56#define AS3935_REG_NUMBER_2 0x02
57#define AS3935_REG_NUMBER_3 0x03
58#define AS3935_REG_NUMBER_4 0x04
59#define AS3935_REG_NUMBER_5 0x05
60#define AS3935_REG_NUMBER_6 0x06
61#define AS3935_REG_NUMBER_7 0x07
62#define AS3935_REG_NUMBER_8 0x08
63#define AS3935_REG_NUMBER_A 0x3A
64#define AS3935_REG_NUMBER_B 0x3B
65#define AS3935_REG_PRESET_DEFAULT 0x3C
66#define AS3935_REG_CALIB_RCO 0x3D
79static uint8_t a_as3935_iic_spi_read(
as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
94 command = (1 << 6) | (reg & 0x3F);
95 if (handle->
spi_read(command, buf, len) != 0)
115static uint8_t a_as3935_iic_spi_write(
as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
130 command = reg & 0x3F;
131 if (handle->
spi_write(command, buf, len) != 0)
156 handle->
iic_spi = (uint8_t)interface;
198 handle->
iic_addr = (uint8_t)addr_pin;
252 handle->
debug_print(
"as3935: read reg 0 failed.\n");
261 handle->
debug_print(
"as3935: write reg 0 failed.\n");
297 handle->
debug_print(
"as3935: read reg 0 failed.\n");
334 handle->
debug_print(
"as3935: read reg 0 failed.\n");
338 prev &= ~(0x1F << 1);
343 handle->
debug_print(
"as3935: write reg 0 failed.\n");
379 handle->
debug_print(
"as3935: read reg 0 failed.\n");
416 handle->
debug_print(
"as3935: read reg 1 failed.\n");
425 handle->
debug_print(
"as3935: write reg 1 failed.\n");
461 handle->
debug_print(
"as3935: read reg 1 failed.\n");
495 if (threshold > 0x0F)
497 handle->
debug_print(
"as3935: threshold > 0x0F.\n");
505 handle->
debug_print(
"as3935: read reg 1 failed.\n");
510 prev |= threshold << 0;
514 handle->
debug_print(
"as3935: write reg 1 failed.\n");
550 handle->
debug_print(
"as3935: read reg 1 failed.\n");
554 *threshold = (prev >> 0) & 0x0F;
587 handle->
debug_print(
"as3935: read reg 2 failed.\n");
596 handle->
debug_print(
"as3935: write reg 2 failed.\n");
632 handle->
debug_print(
"as3935: read reg 2 failed.\n");
669 handle->
debug_print(
"as3935: read reg 2 failed.\n");
678 handle->
debug_print(
"as3935: write reg 2 failed.\n");
714 handle->
debug_print(
"as3935: read reg 2 failed.\n");
748 if (rejection > 0x0F)
750 handle->
debug_print(
"as3935: rejection > 0x0F.\n");
758 handle->
debug_print(
"as3935: read reg 2 failed.\n");
763 prev |= rejection << 0;
767 handle->
debug_print(
"as3935: write reg 2 failed.\n");
803 handle->
debug_print(
"as3935: read reg 2 failed.\n");
807 *rejection = (prev >> 0) & 0x0F;
840 handle->
debug_print(
"as3935: read reg 3 failed.\n");
845 prev |= division << 6;
849 handle->
debug_print(
"as3935: write reg 3 failed.\n");
885 handle->
debug_print(
"as3935: read reg 3 failed.\n");
922 handle->
debug_print(
"as3935: read reg 3 failed.\n");
931 handle->
debug_print(
"as3935: write reg 3 failed.\n");
967 handle->
debug_print(
"as3935: read reg 3 failed.\n");
1004 handle->
debug_print(
"as3935: read reg 3 failed.\n");
1041 handle->
debug_print(
"as3935: read reg 4 failed.\n");
1045 *energy = (uint32_t)((uint32_t)(buf[2] & 0x1F) << 16) |
1046 (uint32_t)((uint32_t)buf[1] << 8) | buf[0];
1080 handle->
debug_print(
"as3935: read reg 7 failed.\n");
1223 handle->
debug_print(
"as3935: read reg 8 failed.\n");
1228 prev |= enable << 7;
1232 handle->
debug_print(
"as3935: write reg 8 failed.\n");
1268 handle->
debug_print(
"as3935: read reg 8 failed.\n");
1305 handle->
debug_print(
"as3935: read reg 8 failed.\n");
1310 prev |= enable << 6;
1314 handle->
debug_print(
"as3935: write reg 8 failed.\n");
1350 handle->
debug_print(
"as3935: read reg 8 failed.\n");
1387 handle->
debug_print(
"as3935: read reg 8 failed.\n");
1392 prev |= enable << 5;
1396 handle->
debug_print(
"as3935: write reg 8 failed.\n");
1432 handle->
debug_print(
"as3935: read reg 8 failed.\n");
1476 handle->
debug_print(
"as3935: read reg 8 failed.\n");
1480 prev &= ~(0xF << 0);
1485 handle->
debug_print(
"as3935: write reg 8 failed.\n");
1521 handle->
debug_print(
"as3935: read reg 8 failed.\n");
1558 handle->
debug_print(
"as3935: read reg a failed.\n");
1595 handle->
debug_print(
"as3935: read reg a failed.\n");
1632 handle->
debug_print(
"as3935: read reg b failed.\n");
1669 handle->
debug_print(
"as3935: read reg b failed.\n");
1706 handle->
debug_print(
"as3935: write command failed.\n");
1742 handle->
debug_print(
"as3935: write command failed.\n");
1772 *reg = (uint8_t)(pf / 8.0f);
1799 *pf = (float)(reg) * 8.0f;
1818 handle->
debug_print(
"as3935: iic deinit failed.\n");
1829 handle->
debug_print(
"as3935: spi deinit failed.\n");
1860 handle->
debug_print(
"as3935: iic_init is null.\n");
1866 handle->
debug_print(
"as3935: iic_deinit is null.\n");
1872 handle->
debug_print(
"as3935: iic_read is null.\n");
1878 handle->
debug_print(
"as3935: iic_write is null.\n");
1884 handle->
debug_print(
"as3935: spi_init is null.\n");
1890 handle->
debug_print(
"as3935: spi_deinit is null.\n");
1896 handle->
debug_print(
"as3935: spi_read is null.\n");
1902 handle->
debug_print(
"as3935: spi_write is null.\n");
1908 handle->
debug_print(
"as3935: delay_ms is null.\n");
1914 handle->
debug_print(
"as3935: receive_callback is null.\n");
1923 handle->
debug_print(
"as3935: iic init failed.\n");
1932 handle->
debug_print(
"as3935: spi init failed.\n");
1970 handle->
debug_print(
"as3935: read reg 0 failed.\n");
1979 handle->
debug_print(
"as3935: write reg 0 failed.\n");
1983 res = a_as3935_close(handle);
2023 handle->
debug_print(
"as3935: read reg 3 failed.\n");
2027 status = ((prev >> 0) & 0x0F);
2078 return a_as3935_iic_spi_write(handle, reg, buf, len);
2105 return a_as3935_iic_spi_read(handle, reg, buf, len);
#define AS3935_REG_NUMBER_8
#define AS3935_REG_NUMBER_0
chip register definition
#define AS3935_REG_NUMBER_2
#define AS3935_REG_NUMBER_7
#define SUPPLY_VOLTAGE_MAX
#define AS3935_REG_NUMBER_4
#define AS3935_REG_NUMBER_1
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define AS3935_REG_PRESET_DEFAULT
#define AS3935_REG_NUMBER_B
#define AS3935_REG_CALIB_RCO
#define CHIP_NAME
chip register definition
#define AS3935_REG_NUMBER_A
#define AS3935_REG_NUMBER_3
driver as3935 header file
uint8_t as3935_set_frequency_division_ration(as3935_handle_t *handle, as3935_frequency_division_ration_t division)
set frequency division ration
uint8_t as3935_set_interface(as3935_handle_t *handle, as3935_interface_t interface)
set the chip interface
uint8_t as3935_set_clear_statistics(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable clear statistics
uint8_t as3935_set_power_down(as3935_handle_t *handle, as3935_bool_t enable)
set power down
uint8_t as3935_get_lightning_min_number(as3935_handle_t *handle, as3935_lightning_min_number_t *number)
get lightning min number
uint8_t as3935_get_watchdog_threshold(as3935_handle_t *handle, uint8_t *threshold)
get watchdog threshold
uint8_t as3935_get_spike_rejection(as3935_handle_t *handle, uint8_t *rejection)
get spike rejection
uint8_t as3935_set_watchdog_threshold(as3935_handle_t *handle, uint8_t threshold)
set watchdog threshold
uint8_t as3935_get_frequency_division_ration(as3935_handle_t *handle, as3935_frequency_division_ration_t *division)
get frequency division ration
uint8_t as3935_info(as3935_info_t *info)
get chip's information
uint8_t as3935_set_spike_rejection(as3935_handle_t *handle, uint8_t rejection)
set spike rejection
uint8_t as3935_get_noise_floor_level(as3935_handle_t *handle, as3935_noise_floor_level_t *level)
get noise floor level
uint8_t as3935_get_internal_tuning_capacitor(as3935_handle_t *handle, uint8_t *cap)
get internal tuning capacitor
uint8_t as3935_internal_tuning_capacitor_convert_to_register(as3935_handle_t *handle, float pf, uint8_t *reg)
convert the internal tuning capacitor to the register raw data
uint8_t as3935_get_clear_statistics(as3935_handle_t *handle, as3935_bool_t *enable)
get clear statistics status
uint8_t as3935_set_noise_floor_level(as3935_handle_t *handle, as3935_noise_floor_level_t level)
set noise floor level
uint8_t as3935_set_calibrate_rc_osc(as3935_handle_t *handle)
calibrate rc osc
uint8_t as3935_deinit(as3935_handle_t *handle)
close the chip
uint8_t as3935_get_power_down(as3935_handle_t *handle, as3935_bool_t *enable)
get power down
uint8_t as3935_get_interface(as3935_handle_t *handle, as3935_interface_t *interface)
get the chip interface
uint8_t as3935_set_afe_gain_boost(as3935_handle_t *handle, as3935_afe_gain_t gain)
set afe gain boost
as3935_interrupt_status_t
as3935 interrupt status enumeration definition
uint8_t as3935_read_single_lightning_energy(as3935_handle_t *handle, uint32_t *energy)
read single lightning energy
as3935_address_t
as3935 address enumeration definition
as3935_interface_t
as3935 interface enumeration definition
uint8_t as3935_set_mask_disturber(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable mask disturber
uint8_t as3935_get_mask_disturber(as3935_handle_t *handle, as3935_bool_t *enable)
get mask disturber status
uint8_t as3935_set_internal_tuning_capacitor(as3935_handle_t *handle, uint8_t cap)
set internal tuning capacitor
struct as3935_info_s as3935_info_t
as3935 information structure definition
uint8_t as3935_get_addr_pin(as3935_handle_t *handle, as3935_address_t *addr_pin)
get the iic address pin
uint8_t as3935_init(as3935_handle_t *handle)
initialize the chip
struct as3935_handle_s as3935_handle_t
as3935 handle structure definition
uint8_t as3935_get_interrupt_status(as3935_handle_t *handle, as3935_interrupt_status_t *status)
get interrupt status
uint8_t as3935_get_afe_gain_boost(as3935_handle_t *handle, as3935_afe_gain_t *gain)
get afe gain boost
uint8_t as3935_get_timer_rc_osc_calibration_done(as3935_handle_t *handle, as3935_bool_t *enable)
get timer rc osc calibration done status
as3935_frequency_division_ration_t
as3935 frequency division ration enumeration definition
uint8_t as3935_set_lightning_min_number(as3935_handle_t *handle, as3935_lightning_min_number_t number)
set lightning min number
uint8_t as3935_set_addr_pin(as3935_handle_t *handle, as3935_address_t addr_pin)
set the iic address pin
uint8_t as3935_get_system_rc_osc_calibration_done(as3935_handle_t *handle, as3935_bool_t *enable)
get system rc osc calibration done status
uint8_t as3935_set_system_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable system rc osc display on irq
as3935_noise_floor_level_t
as3935 noise floor level enumeration definition
uint8_t as3935_read_distance(as3935_handle_t *handle, uint8_t *raw, int8_t *km)
read distance
uint8_t as3935_set_lc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable lc osc display on irq
uint8_t as3935_get_system_rc_osc_calibration_not_ok(as3935_handle_t *handle, as3935_bool_t *enable)
get system rc osc calibration not ok status
uint8_t as3935_irq_handler(as3935_handle_t *handle)
irq handler
as3935_bool_t
as3935 bool enumeration definition
uint8_t as3935_get_display_lc_osc_on_irq(as3935_handle_t *handle, as3935_bool_t *enable)
get lc osc display on irq status
uint8_t as3935_reset_default(as3935_handle_t *handle)
reset to default
as3935_lightning_min_number_t
as3935 lightning min number enumeration definition
uint8_t as3935_internal_tuning_capacitor_convert_to_data(as3935_handle_t *handle, uint8_t reg, float *pf)
convert the register raw data to the internal tuning capacitor
uint8_t as3935_set_timer_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t enable)
enable or disable timer rc osc display on irq
uint8_t as3935_get_timer_rc_osc_calibration_not_ok(as3935_handle_t *handle, as3935_bool_t *enable)
get timer rc osc calibration not ok status
as3935_afe_gain_t
as3935 afe gain enumeration definition
uint8_t as3935_get_timer_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t *enable)
get timer rc osc display on irq status
uint8_t as3935_get_system_rc_osc_display_on_irq(as3935_handle_t *handle, as3935_bool_t *enable)
get system rc osc display on irq status
@ AS3935_INTERRUPT_STATUS_DISTURBER_DETECTED
@ AS3935_INTERRUPT_STATUS_LIGHTNING_INTERRUPT
@ AS3935_INTERRUPT_STATUS_NOISE_LEVEL_TOO_HIGH
uint8_t as3935_get_reg(as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t as3935_set_reg(as3935_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* receive_callback)(uint8_t type)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v