43#define CHIP_NAME "Analog Devices MAX44009"
44#define MANUFACTURER_NAME "Analog Devices"
45#define SUPPLY_VOLTAGE_MIN 1.7f
46#define SUPPLY_VOLTAGE_MAX 3.6f
47#define MAX_CURRENT 0.0016f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 1000
55#define MAX44009_REG_INTERRUPT_STATUS 0x00
56#define MAX44009_REG_INTERRUPT_ENABLE 0x01
57#define MAX44009_REG_CONFIGURATION 0x02
58#define MAX44009_REG_LUX_READING_HIGH 0x03
59#define MAX44009_REG_LUX_READING_LOW 0x04
60#define MAX44009_REG_THRESHOLD_UPPER 0x05
61#define MAX44009_REG_THRESHOLD_LOWER 0x06
62#define MAX44009_REG_THRESHOLD_TIMER 0x07
75static uint8_t a_max44009_iic_read(
max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
96static uint8_t a_max44009_iic_write(
max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
176 handle->
debug_print(
"max44009: get interrupt status failed.\n");
213 handle->
debug_print(
"max44009: get interrupt enable failed.\n");
218 prev |= ((uint8_t)(enable) & 0x01) << 0;
222 handle->
debug_print(
"max44009: set interrupt enable failed.\n");
258 handle->
debug_print(
"max44009: get interrupt enable failed.\n");
295 handle->
debug_print(
"max44009: get configuration failed.\n");
300 prev |= ((uint8_t)(enable) & 0x01) << 7;
304 handle->
debug_print(
"max44009: set configuration failed.\n");
340 handle->
debug_print(
"max44009: get configuration failed.\n");
377 handle->
debug_print(
"max44009: get configuration failed.\n");
382 prev |= ((uint8_t)(!enable) & 0x01) << 6;
386 handle->
debug_print(
"max44009: set configuration failed.\n");
422 handle->
debug_print(
"max44009: get configuration failed.\n");
459 handle->
debug_print(
"max44009: get configuration failed.\n");
464 prev |= ((uint8_t)(enable) & 0x01) << 3;
468 handle->
debug_print(
"max44009: set configuration failed.\n");
504 handle->
debug_print(
"max44009: get configuration failed.\n");
541 handle->
debug_print(
"max44009: get configuration failed.\n");
546 prev |= ((uint8_t)(t) & 0x7) << 0;
550 handle->
debug_print(
"max44009: set configuration failed.\n");
586 handle->
debug_print(
"max44009: get configuration failed.\n");
624 handle->
debug_print(
"max44009: set upper threshold failed.\n");
660 handle->
debug_print(
"max44009: get upper threshold failed.\n");
698 handle->
debug_print(
"max44009: set lower threshold failed.\n");
734 handle->
debug_print(
"max44009: get lower threshold failed.\n");
772 handle->
debug_print(
"max44009: set threshold timer failed.\n");
808 handle->
debug_print(
"max44009: get threshold timer failed.\n");
845 fraction = frexpf(f, &xp);
846 while ((xp > 0xF) || (fraction < 240.0f))
852 if (fraction * 2.0f > 240.0f)
859 remain = (uint8_t)fraction;
861 *reg = (((uint8_t)(xp & 0xF)) << 4) | (remain & 0x0F);
891 exponent = (reg >> 4) & 0xF;
892 fractional = (reg & 0xF) << 4;
893 *lux = 0.045f * powf(2.0f, (
float)exponent) * ((float)fractional);
920 *reg = (uint8_t)(ms / 100.0f);
947 *ms = (float)(reg) * 100;
974 handle->
debug_print(
"max44009: iic_init is null.\n");
980 handle->
debug_print(
"max44009: iic_deinit is null.\n");
986 handle->
debug_print(
"max44009: iic_read is null.\n");
992 handle->
debug_print(
"max44009: iic_write is null.\n");
998 handle->
debug_print(
"max44009: delay_ms is null.\n");
1005 handle->
debug_print(
"max44009: iic init failed.\n");
1043 handle->
debug_print(
"max44009: get configuration failed.\n");
1051 handle->
debug_print(
"max44009: set configuration failed.\n");
1058 handle->
debug_print(
"max44009: iic deinit failed.\n");
1098 handle->
debug_print(
"max44009: read data failed.\n");
1102 *raw = (uint16_t)((uint16_t)(buf[0]) << 8) | buf[1];
1103 exponent = (buf[0] >> 4) & 0xF;
1104 mantissa = ((buf[0] & 0xF) << 4) | (buf[1] & 0x0F);
1105 *lux = powf(2.0f, (
float)exponent) * (float)mantissa * 0.045f;
1134 if (a_max44009_iic_write(handle, reg, buf, len) != 0)
1136 handle->
debug_print(
"max44009: set reg failed.\n");
1168 if (a_max44009_iic_read(handle, reg, buf, len) != 0)
1170 handle->
debug_print(
"max44009: get reg failed.\n");
#define MAX44009_REG_LUX_READING_HIGH
#define MAX44009_REG_INTERRUPT_ENABLE
#define MAX44009_REG_THRESHOLD_UPPER
#define MAX44009_REG_INTERRUPT_STATUS
chip register definition
#define MAX44009_REG_THRESHOLD_TIMER
#define SUPPLY_VOLTAGE_MAX
#define MAX44009_REG_THRESHOLD_LOWER
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define MAX44009_REG_CONFIGURATION
#define CHIP_NAME
chip information definition
driver max44009 header file
uint8_t max44009_get_current_div_8(max44009_handle_t *handle, max44009_bool_t *enable)
get current div 8
uint8_t max44009_read(max44009_handle_t *handle, uint16_t *raw, float *lux)
read data
uint8_t max44009_set_integration_time(max44009_handle_t *handle, max44009_integration_time_t t)
set integration time
uint8_t max44009_get_interrupt(max44009_handle_t *handle, max44009_bool_t *enable)
get interrupt status
max44009_integration_time_t
max44009 integration time enumeration definition
uint8_t max44009_timer_convert_to_data(max44009_handle_t *handle, uint8_t reg, float *ms)
convert the register raw data to timer
uint8_t max44009_set_current_div_8(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable current div 8
uint8_t max44009_get_interrupt_status(max44009_handle_t *handle, max44009_bool_t *enable)
get interrupt status
uint8_t max44009_set_interrupt_high_threshold(max44009_handle_t *handle, uint8_t threshold)
set interrupt high threshold
uint8_t max44009_get_interrupt_high_threshold(max44009_handle_t *handle, uint8_t *threshold)
get interrupt high threshold
uint8_t max44009_get_addr_pin(max44009_handle_t *handle, max44009_address_t *addr_pin)
get the address pin
struct max44009_handle_s max44009_handle_t
max44009 handle structure definition
uint8_t max44009_threshold_convert_to_register(max44009_handle_t *handle, float lux, uint8_t *reg)
convert the threshold to the register raw data
uint8_t max44009_get_auto_range(max44009_handle_t *handle, max44009_bool_t *enable)
get auto range
uint8_t max44009_set_addr_pin(max44009_handle_t *handle, max44009_address_t addr_pin)
set the address pin
uint8_t max44009_get_threshold_timer(max44009_handle_t *handle, uint8_t *t)
get threshold timer
uint8_t max44009_set_interrupt_low_threshold(max44009_handle_t *handle, uint8_t threshold)
set interrupt low threshold
uint8_t max44009_info(max44009_info_t *info)
get chip's information
struct max44009_info_s max44009_info_t
max44009 information structure definition
uint8_t max44009_set_continuous_mode(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable continuous mode
uint8_t max44009_get_continuous_mode(max44009_handle_t *handle, max44009_bool_t *enable)
get continuous mode stauts
max44009_address_t
max44009 address enumeration definition
uint8_t max44009_threshold_convert_to_data(max44009_handle_t *handle, uint8_t reg, float *lux)
convert the register raw data to the threshold
uint8_t max44009_set_interrupt(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable interrupt
uint8_t max44009_get_integration_time(max44009_handle_t *handle, max44009_integration_time_t *t)
get integration time
uint8_t max44009_deinit(max44009_handle_t *handle)
close the chip
uint8_t max44009_init(max44009_handle_t *handle)
initialize the chip
uint8_t max44009_get_interrupt_low_threshold(max44009_handle_t *handle, uint8_t *threshold)
get interrupt low threshold
uint8_t max44009_set_auto_range(max44009_handle_t *handle, max44009_bool_t enable)
enable or disable auto range
uint8_t max44009_set_threshold_timer(max44009_handle_t *handle, uint8_t t)
set threshold timer
max44009_bool_t
max44009 bool enumeration definition
uint8_t max44009_timer_convert_to_register(max44009_handle_t *handle, float ms, uint8_t *reg)
convert the timer to the register raw data
uint8_t max44009_set_reg(max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t max44009_get_reg(max44009_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
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