42 #define CHIP_NAME "ROHM BH1750FVI"
43 #define MANUFACTURER_NAME "ROHM"
44 #define SUPPLY_VOLTAGE_MIN 2.4f
45 #define SUPPLY_VOLTAGE_MAX 3.6f
46 #define MAX_CURRENT 0.19f
47 #define TEMPERATURE_MIN -40.0f
48 #define TEMPERATURE_MAX 85.0f
49 #define DRIVER_VERSION 1000
54 #define BH1750FVI_COMMAND_POWER_DOWN 0x00
55 #define BH1750FVI_COMMAND_POWER_ON 0x01
56 #define BH1750FVI_COMMAND_RESET 0x07
57 #define BH1750FVI_COMMAND_CONTINUOUSLY_H_RESOLUTION_MODE 0x10
58 #define BH1750FVI_COMMAND_CONTINUOUSLY_H_RESOLUTION_MODE2 0x11
59 #define BH1750FVI_COMMAND_CONTINUOUSLY_L_RESOLUTION_MODE 0x13
60 #define BH1750FVI_COMMAND_ONE_TIME_H_RESOLUTION_MODE 0x20
61 #define BH1750FVI_COMMAND_ONE_TIME_H_RESOLUTION_MODE2 0x21
62 #define BH1750FVI_COMMAND_ONE_TIME_L_RESOLUTION_MODE 0x23
63 #define BH1750FVI_COMMAND_CHANGE_MEASUREMENT_TIME_HIGH 0x40
64 #define BH1750FVI_COMMAND_CHANGE_MEASUREMENT_TIME_LOW 0x60
76 static uint8_t a_bh1750fvi_iic_read(
bh1750fvi_handle_t *handle, uint8_t *data, uint16_t len)
98 static uint8_t a_bh1750fvi_iic_write(
bh1750fvi_handle_t *handle, uint8_t *data, uint16_t len)
173 handle->
mode = (uint8_t)(mode);
231 handle->
debug_print(
"bh1750fvi: iic_init is null.\n");
237 handle->
debug_print(
"bh1750fvi: iic_deinit is null.\n");
243 handle->
debug_print(
"bh1750fvi: iic_read_cmd is null.\n");
249 handle->
debug_print(
"bh1750fvi: iic_write_cmd is null.\n");
255 handle->
debug_print(
"bh1750fvi: delay_ms is null.\n");
262 handle->
debug_print(
"bh1750fvi: iic init failed.\n");
268 res = a_bh1750fvi_iic_write(handle, &prev, 1);
271 handle->
debug_print(
"bh1750fvi: power on failed.\n");
278 res = a_bh1750fvi_iic_write(handle, &prev, 1);
288 res = a_bh1750fvi_iic_write(handle, &prev, 1);
291 handle->
debug_print(
"bh1750fvi: set measurement time failed.\n");
296 res = a_bh1750fvi_iic_write(handle, &prev, 1);
299 handle->
debug_print(
"bh1750fvi: set measurement time failed.\n");
337 res = a_bh1750fvi_iic_write(handle, &prev, 1);
340 handle->
debug_print(
"bh1750fvi: power down failed.\n");
347 handle->
debug_print(
"bh1750fvi: iic deinit failed.\n");
381 res = a_bh1750fvi_iic_write(handle, &prev, 1);
384 handle->
debug_print(
"bh1750fvi: power down failed.\n");
417 res = a_bh1750fvi_iic_write(handle, &prev, 1);
420 handle->
debug_print(
"bh1750fvi: power on failed.\n");
453 res = a_bh1750fvi_iic_write(handle, &prev, 1);
489 if ((t < 31) || (t > 254))
491 handle->
debug_print(
"bh1750fvi: t < 31 or t > 254.\n");
497 res = a_bh1750fvi_iic_write(handle, &prev, 1);
500 handle->
debug_print(
"bh1750fvi: set measurement time failed.\n");
505 res = a_bh1750fvi_iic_write(handle, &prev, 1);
508 handle->
debug_print(
"bh1750fvi: set measurement time failed.\n");
559 handle->
debug_print(
"bh1750fvi: mode is invalid.\n");
564 res = a_bh1750fvi_iic_write(handle, &prev, 1);
567 handle->
debug_print(
"bh1750fvi: set measurement time failed.\n");
573 handle->
delay_ms((uint32_t)(180.0f * (
float)(handle->
t) / 69.0f));
577 handle->
delay_ms((uint32_t)(180.0f * (
float)(handle->
t) / 69.0f));
581 handle->
delay_ms((uint32_t)(24.0f * (
float)(handle->
t) / 69.0f));
583 res = a_bh1750fvi_iic_read(handle, buf, 2);
586 handle->
debug_print(
"bh1750fvi: read data failed.\n");
590 *raw = (((uint16_t)buf[0]) << 8) | buf[1];
593 *lux = (float)(*raw) / 1.2f * (69.0f / ((float)(handle->
t)));
597 *lux = (float)(*raw) / 1.2f * (69.0f / ((float)(handle->
t))) / 2.0f;
601 *lux = (float)(*raw) / 1.2f * (69.0f / ((float)(handle->
t)));
634 res = a_bh1750fvi_iic_read(handle, buf, 2);
637 handle->
debug_print(
"bh1750fvi: read data failed.\n");
641 *raw = (((uint16_t)buf[0]) << 8) | buf[1];
644 *lux = (float)(*raw) / 1.2f * (69.0f / ((float)(handle->
t)));
648 *lux = (float)(*raw) / 1.2f * (69.0f / ((float)(handle->
t))) / 2.0f;
652 *lux = (float)(*raw) / 1.2f * (69.0f / ((float)(handle->
t)));
697 handle->
debug_print(
"bh1750fvi: mode is invalid.\n");
702 res = a_bh1750fvi_iic_write(handle, &prev, 1);
705 handle->
debug_print(
"bh1750fvi: set measurement time failed.\n");
752 handle->
debug_print(
"bh1750fvi: mode is invalid.\n");
757 res = a_bh1750fvi_iic_write(handle, &prev, 1);
760 handle->
debug_print(
"bh1750fvi: set measurement time failed.\n");
791 return a_bh1750fvi_iic_write(handle, buf, len);
817 return a_bh1750fvi_iic_read(handle, buf, len);
#define BH1750FVI_COMMAND_CHANGE_MEASUREMENT_TIME_LOW
#define BH1750FVI_COMMAND_POWER_DOWN
chip command definition
#define BH1750FVI_COMMAND_CHANGE_MEASUREMENT_TIME_HIGH
#define BH1750FVI_COMMAND_CONTINUOUSLY_L_RESOLUTION_MODE
#define BH1750FVI_COMMAND_CONTINUOUSLY_H_RESOLUTION_MODE2
#define BH1750FVI_COMMAND_POWER_ON
#define SUPPLY_VOLTAGE_MAX
#define BH1750FVI_COMMAND_CONTINUOUSLY_H_RESOLUTION_MODE
#define BH1750FVI_COMMAND_ONE_TIME_L_RESOLUTION_MODE
#define BH1750FVI_COMMAND_RESET
#define BH1750FVI_COMMAND_ONE_TIME_H_RESOLUTION_MODE2
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BH1750FVI_COMMAND_ONE_TIME_H_RESOLUTION_MODE
#define CHIP_NAME
chip information definition
driver bh1750fvi header file
uint8_t bh1750fvi_stop_continuous_read(bh1750fvi_handle_t *handle)
stop chip reading
uint8_t bh1750fvi_reset(bh1750fvi_handle_t *handle)
reset
uint8_t bh1750fvi_single_read(bh1750fvi_handle_t *handle, uint16_t *raw, float *lux)
read data from the chip once
uint8_t bh1750fvi_get_addr_pin(bh1750fvi_handle_t *handle, bh1750fvi_address_t *addr_pin)
get the address pin
uint8_t bh1750fvi_deinit(bh1750fvi_handle_t *handle)
close the chip
uint8_t bh1750fvi_start_continuous_read(bh1750fvi_handle_t *handle)
start chip reading
uint8_t bh1750fvi_set_measurement_time(bh1750fvi_handle_t *handle, uint8_t t)
set the measurement time
uint8_t bh1750fvi_continuous_read(bh1750fvi_handle_t *handle, uint16_t *raw, float *lux)
read data from the chip continuously
uint8_t bh1750fvi_set_addr_pin(bh1750fvi_handle_t *handle, bh1750fvi_address_t addr_pin)
set the address pin
uint8_t bh1750fvi_info(bh1750fvi_info_t *info)
get chip's information
uint8_t bh1750fvi_power_down(bh1750fvi_handle_t *handle)
power down
bh1750fvi_mode_t
bh1750fvi mode enumeration definition
uint8_t bh1750fvi_power_on(bh1750fvi_handle_t *handle)
power on
uint8_t bh1750fvi_init(bh1750fvi_handle_t *handle)
initialize the chip
bh1750fvi_address_t
bh1750fvi address enumeration definition
uint8_t bh1750fvi_get_mode(bh1750fvi_handle_t *handle, bh1750fvi_mode_t *mode)
get the mode
uint8_t bh1750fvi_set_mode(bh1750fvi_handle_t *handle, bh1750fvi_mode_t mode)
set the mode
@ BH1750FVI_MODE_HIGH_RESOLUTION_MODE
@ BH1750FVI_MODE_LOW_RESOLUTION_MODE
@ BH1750FVI_MODE_HIGH_RESOLUTION_MODE2
uint8_t bh1750fvi_get_reg(bh1750fvi_handle_t *handle, uint8_t *buf, uint16_t len)
get the chip register
uint8_t bh1750fvi_set_reg(bh1750fvi_handle_t *handle, uint8_t *buf, uint16_t len)
set the chip register
bh1750fvi handle structure definition
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
bh1750fvi information structure definition
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v