43#define CHIP_NAME "STMicroelectronics UVIS25"
44#define MANUFACTURER_NAME "STMicroelectronics"
45#define SUPPLY_VOLTAGE_MIN 1.7f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 0.01f
48#define TEMPERATURE_MIN -20.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
55#define UVIS25_REG_WHO_AM_I 0x0F
56#define UVIS25_REG_CTRL_REG1 0x20
57#define UVIS25_REG_CTRL_REG2 0x21
58#define UVIS25_REG_CTRL_REG3 0x22
59#define UVIS25_REG_INT_CFG 0x23
60#define UVIS25_REG_INT_SOURCE 0x24
61#define UVIS25_REG_THS_UV 0x25
62#define UVIS25_REG_STATUS_REG 0x27
63#define UVIS25_REG_UV_OUT_REG 0x28
68#define UVIS25_IIC_ADDRESS 0x8E
81static uint8_t a_uvis25_iic_spi_read(
uvis25_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
102 if (handle->
spi_read(reg, buf, len) != 0)
124static uint8_t a_uvis25_iic_spi_write(
uvis25_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
144 if (handle->
spi_write(reg, buf, len) != 0)
171 handle->
iic_spi = (uint8_t)interface;
225 handle->
debug_print(
"uvis25: read register failed.\n");
263 handle->
debug_print(
"uvis25: read register failed.\n");
300 handle->
debug_print(
"uvis25: read register failed.\n");
338 handle->
debug_print(
"uvis25: read register failed.\n");
375 handle->
debug_print(
"uvis25: read register failed.\n");
380 prev |= (!enable) << 4;
413 handle->
debug_print(
"uvis25: read register failed.\n");
450 handle->
debug_print(
"uvis25: read register failed.\n");
488 handle->
debug_print(
"uvis25: read register failed.\n");
525 handle->
debug_print(
"uvis25: read register failed.\n");
563 handle->
debug_print(
"uvis25: read register failed.\n");
600 handle->
debug_print(
"uvis25: read register failed.\n");
605 prev |= pin_type << 6;
638 handle->
debug_print(
"uvis25: read register failed.\n");
675 handle->
debug_print(
"uvis25: read register failed.\n");
679 prev &= ~(0x03 << 0);
713 handle->
debug_print(
"uvis25: read register failed.\n");
750 handle->
debug_print(
"uvis25: read register failed.\n");
754 prev &= ~(0x01 << 3);
788 handle->
debug_print(
"uvis25: read register failed.\n");
825 handle->
debug_print(
"uvis25: read register failed.\n");
829 prev &= ~(0x01 << 2);
863 handle->
debug_print(
"uvis25: read register failed.\n");
900 handle->
debug_print(
"uvis25: read register failed.\n");
904 prev &= ~(0x01 << 1);
938 handle->
debug_print(
"uvis25: read register failed.\n");
975 handle->
debug_print(
"uvis25: read register failed.\n");
979 prev &= ~(0x01 << 0);
1013 handle->
debug_print(
"uvis25: read register failed.\n");
1044 return a_uvis25_iic_spi_write(handle,
UVIS25_REG_THS_UV, (uint8_t *)&threshold, 1);
1069 return a_uvis25_iic_spi_read(handle,
UVIS25_REG_THS_UV, (uint8_t *)threshold, 1);
1098 handle->
debug_print(
"uvis25: read register failed.\n");
1102 if ((prev & (1 < 2)) != 0)
1109 if ((prev & (1 << 1)) != 0)
1116 if ((prev & (1 << 0)) != 0)
1150 *reg = (uint8_t )(uv * 16.0f);
1178 *uv = (float)reg / 16.0f;
1207 handle->
debug_print(
"uvis25: iic_init is null.\n");
1213 handle->
debug_print(
"uvis25: iic_deinit is null.\n");
1219 handle->
debug_print(
"uvis25: iic_read is null.\n");
1225 handle->
debug_print(
"uvis25: iic_write is null.\n");
1231 handle->
debug_print(
"uvis25: spi_init is null.\n");
1237 handle->
debug_print(
"uvis25: spi_deinit is null.\n");
1243 handle->
debug_print(
"uvis25: spi_read is null.\n");
1249 handle->
debug_print(
"uvis25: spi_write is null.\n");
1255 handle->
debug_print(
"uvis25: delay_ms is null.\n");
1264 handle->
debug_print(
"uvis25: iic init failed.\n");
1273 handle->
debug_print(
"uvis25: spi init failed.\n");
1338 handle->
debug_print(
"uvis25: read register failed.\n");
1342 prev &= ~(0x01 << 7);
1347 handle->
debug_print(
"uvis25: write register failed.\n");
1356 handle->
debug_print(
"uvis25: iic deinit failed.\n");
1366 handle->
debug_print(
"uvis25: spi deinit failed.\n");
1406 handle->
debug_print(
"uvis25: read register failed.\n");
1414 handle->
debug_print(
"uvis25: write register failed.\n");
1421 handle->
debug_print(
"uvis25: read register failed.\n");
1430 handle->
debug_print(
"uvis25: write register failed.\n");
1441 handle->
debug_print(
"uvis25: read register failed.\n");
1445 if ((prev & 0x01) != 0)
1454 *uv = (float)(*raw) / 16.0f;
1458 else if (timeout < 100)
1467 handle->
debug_print(
"uvis25: data is not available.\n");
1501 handle->
debug_print(
"uvis25: read register failed.\n");
1510 handle->
debug_print(
"uvis25: write register failed.\n");
1517 handle->
debug_print(
"uvis25: read register failed.\n");
1525 handle->
debug_print(
"uvis25: write register failed.\n");
1560 handle->
debug_print(
"uvis25: read register failed.\n");
1568 handle->
debug_print(
"uvis25: write register failed.\n");
1575 handle->
debug_print(
"uvis25: read register failed.\n");
1583 handle->
debug_print(
"uvis25: write register failed.\n");
1620 handle->
debug_print(
"uvis25: read register failed.\n");
1624 if ((prev & 0x01) != 0)
1633 *uv = (float)(*raw) / 16.0f;
1639 handle->
debug_print(
"uvis25: data is not available.\n");
1669 return a_uvis25_iic_spi_write(handle, reg, buf, len);
1696 return a_uvis25_iic_spi_read(handle, reg, buf, len);
#define UVIS25_REG_INT_SOURCE
#define UVIS25_REG_THS_UV
#define UVIS25_REG_UV_OUT_REG
#define UVIS25_REG_STATUS_REG
#define UVIS25_REG_CTRL_REG3
#define SUPPLY_VOLTAGE_MAX
#define UVIS25_REG_CTRL_REG1
#define UVIS25_REG_CTRL_REG2
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip register definition
#define UVIS25_IIC_ADDRESS
iic address definition
#define UVIS25_REG_WHO_AM_I
chip register definition
#define UVIS25_REG_INT_CFG
driver uvis25 header file
uvis25_interface_t
uvis25 interface enumeration definition
uint8_t uvis25_get_iic(uvis25_handle_t *handle, uvis25_bool_t *enable)
get the chip iic status
uint8_t uvis25_set_boot(uvis25_handle_t *handle, uvis25_boot_mode_t mode)
set the boot mode
uint8_t uvis25_set_spi_wire(uvis25_handle_t *handle, uvis25_spi_wire_t wire)
set the spi wire
uint8_t uvis25_init(uvis25_handle_t *handle)
initialize the chip
uint8_t uvis25_set_iic(uvis25_handle_t *handle, uvis25_bool_t enable)
enable or disable the chip iic
uint8_t uvis25_continuous_read(uvis25_handle_t *handle, uint8_t *raw, float *uv)
read data continuously
uint8_t uvis25_deinit(uvis25_handle_t *handle)
close the chip
uint8_t uvis25_irq_handler(uvis25_handle_t *handle)
irq handler
uint8_t uvis25_set_interface(uvis25_handle_t *handle, uvis25_interface_t interface)
set the chip interface
uint8_t uvis25_get_boot(uvis25_handle_t *handle, uvis25_boot_mode_t *mode)
get the boot mode
uvis25_boot_mode_t
uvis25 boot enumeration definition
uint8_t uvis25_get_interface(uvis25_handle_t *handle, uvis25_interface_t *interface)
get the chip interface
uint8_t uvis25_single_read(uvis25_handle_t *handle, uint8_t *raw, float *uv)
read data once
struct uvis25_info_s uvis25_info_t
uvis25 information structure definition
struct uvis25_handle_s uvis25_handle_t
uvis25 handle structure definition
uint8_t uvis25_info(uvis25_info_t *info)
get chip's information
uvis25_spi_wire_t
uvis25 spi wire enumeration definition
uint8_t uvis25_get_block_data_update(uvis25_handle_t *handle, uvis25_bool_t *enable)
get blocking data update status
uint8_t uvis25_set_block_data_update(uvis25_handle_t *handle, uvis25_bool_t enable)
enable or disable blocking data update
uvis25_bool_t
uvis25 bool enumeration definition
uint8_t uvis25_start_continuous_read(uvis25_handle_t *handle)
start reading
uint8_t uvis25_stop_continuous_read(uvis25_handle_t *handle)
stop reading
uint8_t uvis25_get_spi_wire(uvis25_handle_t *handle, uvis25_spi_wire_t *wire)
get the spi wire
uint8_t uvis25_set_reg(uvis25_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t uvis25_get_reg(uvis25_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
uint8_t uvis25_get_threshold(uvis25_handle_t *handle, uint8_t *threshold)
get the interrupt threshold
uint8_t uvis25_set_interrupt_low_threshold(uvis25_handle_t *handle, uvis25_bool_t enable)
enable or disable the low threshold interrupt
uvis25_interrupt_pin_type_t
uvis25 interrupt pin type enumeration definition
uint8_t uvis25_set_interrupt_high_threshold(uvis25_handle_t *handle, uvis25_bool_t enable)
enable or disable the high threshold interrupt
uint8_t uvis25_get_interrupt_type(uvis25_handle_t *handle, uvis25_interrupt_type_t *type)
get the interrupt type
uint8_t uvis25_get_interrupt_low_threshold(uvis25_handle_t *handle, uvis25_bool_t *enable)
get the low threshold interrupt status
uint8_t uvis25_set_interrupt_pin_type(uvis25_handle_t *handle, uvis25_interrupt_pin_type_t pin_type)
set the interrupt pin type
uint8_t uvis25_set_threshold(uvis25_handle_t *handle, uint8_t threshold)
set the interrupt threshold
uvis25_interrupt_active_level_t
uvis25 interrupt active level enumeration definition
uint8_t uvis25_set_interrupt_active_level(uvis25_handle_t *handle, uvis25_interrupt_active_level_t level)
set the interrupt active level
uint8_t uvis25_get_latch_interrupt(uvis25_handle_t *handle, uvis25_bool_t *enable)
get the latching interrupt status
uint8_t uvis25_threshold_convert_to_register(uvis25_handle_t *handle, float uv, uint8_t *reg)
convert a uv index to a raw register data
uint8_t uvis25_get_interrupt_pin_type(uvis25_handle_t *handle, uvis25_interrupt_pin_type_t *pin_type)
get the interrupt pin type
uint8_t uvis25_get_interrupt_high_threshold(uvis25_handle_t *handle, uvis25_bool_t *enable)
get the high threshold interrupt status
uint8_t uvis25_set_latch_interrupt(uvis25_handle_t *handle, uvis25_bool_t enable)
enable or disable latching interrupt
uint8_t uvis25_get_interrupt(uvis25_handle_t *handle, uvis25_bool_t *enable)
get the chip interrupt status
uint8_t uvis25_set_interrupt_type(uvis25_handle_t *handle, uvis25_interrupt_type_t type)
set the interrupt type
uint8_t uvis25_threshold_convert_to_data(uvis25_handle_t *handle, uint8_t reg, float *uv)
convert a raw register data to a converted uv index
uint8_t uvis25_set_interrupt(uvis25_handle_t *handle, uvis25_bool_t enable)
enable or disable the chip interrupt
uvis25_interrupt_type_t
uvis25 interrupt type enumeration definition
uint8_t uvis25_get_interrupt_active_level(uvis25_handle_t *handle, uvis25_interrupt_active_level_t *level)
get the interrupt active level
@ UVIS25_INTERRUPT_HIGHER
@ UVIS25_INTERRUPT_ACTIVE
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