42#define CHIP_NAME "VISHAY VEML7700"
43#define MANUFACTURER_NAME "VISHAY"
44#define SUPPLY_VOLTAGE_MIN 2.5f
45#define SUPPLY_VOLTAGE_MAX 3.6f
46#define MAX_CURRENT 0.045f
47#define TEMPERATURE_MIN -25.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
54#define VEML7700_ADDRESS 0x20
59#define VEML7700_REG_ALS_CONF_0 0x00
60#define VEML7700_REG_ALS_WH 0x01
61#define VEML7700_REG_ALS_WL 0x02
62#define VEML7700_REG_POWER_SAVING 0x03
63#define VEML7700_REG_ALS 0x04
64#define VEML7700_REG_WHITE 0x05
65#define VEML7700_REG_ALS_INT 0x06
66#define VEML7700_REG_ID 0x07
71static const double gsc_resolution[6][4] =
73 {0.0042, 0.0084, 0.0336, 0.0672},
74 {0.0084, 0.0168, 0.0672, 0.1344},
75 {0.0168, 0.0336, 0.1344, 0.2688},
76 {0.0336, 0.0672, 0.2688, 0.5376},
77 {0.0672, 0.1344, 0.5376, 1.0752},
78 {0.1344, 0.2688, 1.0752, 2.1504},
91static uint8_t a_veml7700_iic_read(
veml7700_handle_t *handle, uint8_t reg, uint16_t *data)
101 *data = (((uint16_t)buf[1]) << 8) | buf[0];
116static uint8_t a_veml7700_iic_write(
veml7700_handle_t *handle, uint8_t reg, uint16_t data)
121 buf[0] = (data >> 0) & 0xFF;
122 buf[1] = (data >> 8) & 0xFF;
154 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
159 ind = (prev >> 11) & 0x3;
177 ind = (prev >> 6) & 0xF;
182 else if (ind == 0x08)
186 else if (ind == 0x00)
190 else if (ind == 0x01)
194 else if (ind == 0x02)
198 else if (ind == 0x03)
206 resolution = gsc_resolution[integration][gain];
207 resolution *= (double)(raw);
208 *lux = (((6.0135e-13 * resolution - 9.3924e-9) *
209 resolution + 8.1488e-5) *
210 resolution + 1.0023) * resolution;
225static uint8_t a_run_auto_range(
veml7700_handle_t *handle, uint16_t raw,
double lux)
239 else if (lux < 550.0)
244 else if (lux < 1101.0)
249 else if (lux < 2202.0)
254 else if (lux < 4404.0)
259 else if (lux < 8808.0)
264 else if (lux < 17616.0)
269 else if (lux < 35232.0)
274 else if (lux < 70463.0)
288 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
295 prev |= integration << 6;
299 handle->
debug_print(
"veml7700: write als conf0 failed.\n");
313 else if (lux > 35232.0)
318 else if (lux > 17616.0)
323 else if (lux > 8808.0)
328 else if (lux > 4404.0)
333 else if (lux > 2202.0)
338 else if (lux > 1101.0)
343 else if (lux > 550.0)
348 else if (lux > 275.0)
362 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
369 prev |= integration << 6;
373 handle->
debug_print(
"veml7700: write als conf0 failed.\n");
414 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
423 handle->
debug_print(
"veml7700: write als conf0 failed.\n");
459 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
496 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
505 handle->
debug_print(
"veml7700: write als conf0 failed.\n");
541 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
578 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
583 prev |= persistence << 4;
587 handle->
debug_print(
"veml7700: write als conf0 failed.\n");
623 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
660 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
669 handle->
debug_print(
"veml7700: write als conf0 failed.\n");
705 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
742 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
751 handle->
debug_print(
"veml7700: write als conf0 failed.\n");
787 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
823 handle->
debug_print(
"veml7700: write als high threshold failed.\n");
858 handle->
debug_print(
"veml7700: read als high threshold failed.\n");
893 handle->
debug_print(
"veml7700: write als low threshold failed.\n");
928 handle->
debug_print(
"veml7700: read als low threshold failed.\n");
964 handle->
debug_print(
"veml7700: read power saving mode failed.\n");
973 handle->
debug_print(
"veml7700: write power saving mode failed.\n");
1009 handle->
debug_print(
"veml7700: read power saving mode failed.\n");
1046 handle->
debug_print(
"veml7700: read power saving mode failed.\n");
1051 prev |= enable << 0;
1055 handle->
debug_print(
"veml7700: write power saving mode failed.\n");
1091 handle->
debug_print(
"veml7700: read power saving mode failed.\n");
1129 handle->
debug_print(
"veml7700: read als int failed.\n");
1166 handle->
debug_print(
"veml7700: iic_init is null.\n");
1172 handle->
debug_print(
"veml7700: iic_deinit is null.\n");
1178 handle->
debug_print(
"veml7700: iic_read is null.\n");
1184 handle->
debug_print(
"veml7700: iic_write is null.\n");
1190 handle->
debug_print(
"veml7700: delay_ms is null.\n");
1197 handle->
debug_print(
"veml7700: iic init failed.\n");
1205 handle->
debug_print(
"veml7700: read id failed.\n");
1213 handle->
debug_print(
"veml7700: id is invalid.\n");
1251 handle->
debug_print(
"veml7700: read als conf0 failed.\n");
1259 handle->
debug_print(
"veml7700: write als conf0 failed.\n");
1266 handle->
debug_print(
"veml7700: iic deinit failed.\n");
1352 handle->
debug_print(
"veml7700: read white failed.\n");
1390 handle->
debug_print(
"veml7700: read als failed.\n");
1394 res = a_calculate(handle, *raw, lux);
1397 handle->
debug_print(
"veml7700: calculate failed.\n");
1403 res = a_run_auto_range(handle, *raw, *lux);
1406 handle->
debug_print(
"veml7700: run auto range failed.\n");
1438 return a_veml7700_iic_write(handle, reg, data);
1464 return a_veml7700_iic_read(handle, reg, data);
#define VEML7700_REG_ALS_WL
#define VEML7700_REG_WHITE
#define VEML7700_REG_ALS_CONF_0
chip register definition
#define SUPPLY_VOLTAGE_MAX
#define VEML7700_REG_ALS_INT
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define VEML7700_REG_ALS_WH
#define CHIP_NAME
chip information definition
#define VEML7700_ADDRESS
chip address definition
#define VEML7700_REG_POWER_SAVING
driver veml7700 header file
uint8_t veml7700_get_interrupt_status(veml7700_handle_t *handle, veml7700_bool_t *low_threshold, veml7700_bool_t *high_threshold)
get interrupt status
uint8_t veml7700_set_als_integration_time(veml7700_handle_t *handle, veml7700_als_integration_time_t t)
set als integration time
veml7700_bool_t
veml7700 bool enumeration definition
uint8_t veml7700_deinit(veml7700_handle_t *handle)
close the chip
#define VEML7700_AUTO_RANGE_HIGH_THRESHOLD
veml7700 auto range high threshold definition
uint8_t veml7700_set_als_interrupt(veml7700_handle_t *handle, veml7700_bool_t enable)
enable or disable als interrupt
uint8_t veml7700_get_als_persistence(veml7700_handle_t *handle, veml7700_als_persistence_t *persistence)
get als persistence
uint8_t veml7700_read_white(veml7700_handle_t *handle, uint16_t *raw)
read white channel
uint8_t veml7700_get_power_saving_mode(veml7700_handle_t *handle, veml7700_power_saving_mode_t *mode)
get power saving mode
uint8_t veml7700_info(veml7700_info_t *info)
get chip's information
uint8_t veml7700_get_als_low_threshold(veml7700_handle_t *handle, uint16_t *threshold)
get als low threshold
struct veml7700_info_s veml7700_info_t
veml7700 information structure definition
uint8_t veml7700_init(veml7700_handle_t *handle)
initialize the chip
uint8_t veml7700_read_als(veml7700_handle_t *handle, uint16_t *raw, double *lux)
read als channel
uint8_t veml7700_set_als_mode(veml7700_handle_t *handle, veml7700_als_mode_t mode)
set als mode
uint8_t veml7700_set_als_gain(veml7700_handle_t *handle, veml7700_als_gain_t gain)
set als gain
veml7700_power_saving_mode_t
veml7700 power saving mode enumeration definition
uint8_t veml7700_get_als_gain(veml7700_handle_t *handle, veml7700_als_gain_t *gain)
get als gain
#define VEML7700_AUTO_RANGE_LOW_THRESHOLD
veml7700 auto range low threshold definition
uint8_t veml7700_get_als_high_threshold(veml7700_handle_t *handle, uint16_t *threshold)
get als high threshold
struct veml7700_handle_s veml7700_handle_t
veml7700 handle structure definition
uint8_t veml7700_get_als_interrupt(veml7700_handle_t *handle, veml7700_bool_t *enable)
get als interrupt status
veml7700_als_integration_time_t
veml7700 als integration time enumeration definition
uint8_t veml7700_set_als_persistence(veml7700_handle_t *handle, veml7700_als_persistence_t persistence)
set als persistence
veml7700_als_gain_t
veml7700 als gain enumeration definition
uint8_t veml7700_set_als_low_threshold(veml7700_handle_t *handle, uint16_t threshold)
set als low threshold
uint8_t veml7700_get_als_integration_time(veml7700_handle_t *handle, veml7700_als_integration_time_t *t)
get als integration time
uint8_t veml7700_set_als_high_threshold(veml7700_handle_t *handle, uint16_t threshold)
set als high threshold
uint8_t veml7700_get_auto_range(veml7700_handle_t *handle, veml7700_bool_t *enable)
get auto range
uint8_t veml7700_get_power_saving(veml7700_handle_t *handle, veml7700_bool_t *enable)
get power saving status
uint8_t veml7700_set_auto_range(veml7700_handle_t *handle, veml7700_bool_t enable)
set auto range
veml7700_als_persistence_t
veml7700 als persistence enumeration definition
veml7700_als_mode_t
veml7700 als mode enumeration definition
uint8_t veml7700_set_power_saving(veml7700_handle_t *handle, veml7700_bool_t enable)
enable or disable power saving
uint8_t veml7700_set_power_saving_mode(veml7700_handle_t *handle, veml7700_power_saving_mode_t mode)
set power saving mode
uint8_t veml7700_get_als_mode(veml7700_handle_t *handle, veml7700_als_mode_t *mode)
get als mode
@ VEML7700_ALS_INTEGRATION_TIME_400MS
@ VEML7700_ALS_INTEGRATION_TIME_50MS
@ VEML7700_ALS_INTEGRATION_TIME_25MS
@ VEML7700_ALS_INTEGRATION_TIME_200MS
@ VEML7700_ALS_INTEGRATION_TIME_800MS
@ VEML7700_ALS_INTEGRATION_TIME_100MS
@ VEML7700_ALS_GAIN_1_DIV_4
@ VEML7700_ALS_GAIN_1_DIV_8
uint8_t veml7700_set_reg(veml7700_handle_t *handle, uint8_t reg, uint16_t data)
set the chip register
uint8_t veml7700_get_reg(veml7700_handle_t *handle, uint8_t reg, uint16_t *data)
get the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(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