LibDriver OPT300X
Loading...
Searching...
No Matches
driver_opt300x.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_OPT300X_H
38#define DRIVER_OPT300X_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
62typedef enum
63{
64 OPT3001 = 0x01,
65 OPT3002 = 0x02,
66 OPT3004 = 0x04,
67 OPT3005 = 0x05,
68 OPT3006 = 0x06,
69 OPT3007 = 0x07,
70} opt300x_t;
71
82
86typedef enum
87{
91
100
109
120
140
160
180
189
193typedef struct opt300x_handle_s
194{
195 uint8_t iic_addr;
196 uint8_t (*iic_init)(void);
197 uint8_t (*iic_deinit)(void);
198 uint8_t (*iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
199 uint8_t (*iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len);
200 void (*receive_callback)(uint8_t type);
201 void (*delay_ms)(uint32_t ms);
202 void (*debug_print)(const char *const fmt, ...);
203 uint8_t type;
204 uint8_t inited;
206
222
226
233
240#define DRIVER_OPT300X_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
241
248#define DRIVER_OPT300X_LINK_IIC_INIT(HANDLE, FUC) (HANDLE)->iic_init = FUC
249
256#define DRIVER_OPT300X_LINK_IIC_DEINIT(HANDLE, FUC) (HANDLE)->iic_deinit = FUC
257
264#define DRIVER_OPT300X_LINK_IIC_READ(HANDLE, FUC) (HANDLE)->iic_read = FUC
265
272#define DRIVER_OPT300X_LINK_IIC_WRITE(HANDLE, FUC) (HANDLE)->iic_write = FUC
273
280#define DRIVER_OPT300X_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
281
288#define DRIVER_OPT300X_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
289
296#define DRIVER_OPT300X_LINK_RECEIVE_CALLBACK(HANDLE, FUC) (HANDLE)->receive_callback = FUC
297
301
308
317uint8_t opt300x_info(opt300x_info_t *info);
318
328uint8_t opt300x_set_type(opt300x_handle_t *handle, opt300x_t type);
329
339uint8_t opt300x_get_type(opt300x_handle_t *handle, opt300x_t *type);
340
351
362
374
386uint8_t opt300x_init(opt300x_handle_t *handle);
387
399uint8_t opt300x_deinit(opt300x_handle_t *handle);
400
412
424
439uint8_t opt300x_continuous_read(opt300x_handle_t *handle, uint16_t *raw, float *lux);
440
455uint8_t opt3002_continuous_read(opt300x_handle_t *handle, uint16_t *raw, float *nw_cm2);
456
472uint8_t opt300x_single_read(opt300x_handle_t *handle, uint16_t *raw, float *lux);
473
489uint8_t opt3002_single_read(opt300x_handle_t *handle, uint16_t *raw, float *nw_cm2);
490
502uint8_t opt300x_set_low_limit(opt300x_handle_t *handle, uint16_t limit);
503
515uint8_t opt300x_get_low_limit(opt300x_handle_t *handle, uint16_t *limit);
516
528uint8_t opt300x_set_high_limit(opt300x_handle_t *handle, uint16_t limit);
529
541uint8_t opt300x_get_high_limit(opt300x_handle_t *handle, uint16_t *limit);
542
555uint8_t opt300x_limit_convert_to_register(opt300x_handle_t *handle, float lux, uint16_t *reg);
556
569uint8_t opt300x_limit_convert_to_data(opt300x_handle_t *handle, uint16_t reg, float *lux);
570
583uint8_t opt3002_limit_convert_to_register(opt300x_handle_t *handle, float nw_cm2, uint16_t *reg);
584
597uint8_t opt3002_limit_convert_to_data(opt300x_handle_t *handle, uint16_t reg, float *nw_cm2);
598
612
625uint8_t opt300x_get_range(opt300x_handle_t *handle, opt300x_range_t *range);
626
640
653uint8_t opt3002_get_range(opt300x_handle_t *handle, opt3002_range_t *range);
654
668
681uint8_t opt3005_get_range(opt300x_handle_t *handle, opt3005_range_t *range);
682
695
708
721
734
747
760
773
786
799
812
816
823
836uint8_t opt300x_set_reg(opt300x_handle_t *handle, uint8_t reg, uint16_t data);
837
850uint8_t opt300x_get_reg(opt300x_handle_t *handle, uint8_t reg, uint16_t *data);
851
855
859
860#ifdef __cplusplus
861}
862#endif
863
864#endif
uint8_t opt300x_get_range(opt300x_handle_t *handle, opt300x_range_t *range)
get range
uint8_t opt300x_set_fault_count(opt300x_handle_t *handle, opt300x_fault_count_t count)
set fault count
uint8_t opt300x_info(opt300x_info_t *info)
get chip's information
uint8_t opt300x_get_low_limit(opt300x_handle_t *handle, uint16_t *limit)
get low limit
uint8_t opt300x_get_high_limit(opt300x_handle_t *handle, uint16_t *limit)
get high limit
uint8_t opt3002_continuous_read(opt300x_handle_t *handle, uint16_t *raw, float *nw_cm2)
read data from the chip continuously
uint8_t opt3005_set_range(opt300x_handle_t *handle, opt3005_range_t range)
set range
uint8_t opt3002_single_read(opt300x_handle_t *handle, uint16_t *raw, float *nw_cm2)
read data from the chip
uint8_t opt300x_set_type(opt300x_handle_t *handle, opt300x_t type)
set the chip type
uint8_t opt300x_set_mask_exponent(opt300x_handle_t *handle, opt300x_bool_t enable)
enable or disable mask exponent
opt300x_address_t
opt300x address enumeration definition
uint8_t opt300x_set_high_limit(opt300x_handle_t *handle, uint16_t limit)
set high limit
opt300x_bool_t
opt300x bool enumeration definition
uint8_t opt300x_get_interrupt_pin_polarity(opt300x_handle_t *handle, opt300x_interrupt_polarity_t *polarity)
get interrupt pin polarity
opt3005_range_t
opt3005 range enumeration definition
uint8_t opt300x_get_conversion_time(opt300x_handle_t *handle, opt300x_conversion_time_t *t)
get conversion time
uint8_t opt300x_start_continuous_read(opt300x_handle_t *handle)
start the chip reading
opt300x_range_t
opt300x range enumeration definition
uint8_t opt300x_continuous_read(opt300x_handle_t *handle, uint16_t *raw, float *lux)
read data from the chip continuously
uint8_t opt300x_set_low_limit(opt300x_handle_t *handle, uint16_t limit)
set low limit
struct opt300x_info_s opt300x_info_t
opt300x information structure definition
uint8_t opt300x_limit_convert_to_register(opt300x_handle_t *handle, float lux, uint16_t *reg)
convert the limit threshold to the register raw data
uint8_t opt3005_get_range(opt300x_handle_t *handle, opt3005_range_t *range)
get range
opt300x_t
opt300x type enumeration definition
uint8_t opt3002_get_range(opt300x_handle_t *handle, opt3002_range_t *range)
get range
uint8_t opt300x_set_interrupt_pin_polarity(opt300x_handle_t *handle, opt300x_interrupt_polarity_t polarity)
set interrupt pin polarity
uint8_t opt300x_get_type(opt300x_handle_t *handle, opt300x_t *type)
get the iic chip type
uint8_t opt3002_limit_convert_to_register(opt300x_handle_t *handle, float nw_cm2, uint16_t *reg)
convert the limit threshold to the register raw data
uint8_t opt300x_set_conversion_time(opt300x_handle_t *handle, opt300x_conversion_time_t t)
set conversion time
uint8_t opt300x_get_addr_pin(opt300x_handle_t *handle, opt300x_address_t *addr_pin)
get the iic address pin
uint8_t opt300x_get_interrupt_latch(opt300x_handle_t *handle, opt300x_bool_t *enable)
get interrupt latch status
uint8_t opt3002_limit_convert_to_data(opt300x_handle_t *handle, uint16_t reg, float *nw_cm2)
convert the register raw data to the limit threshold
uint8_t opt300x_set_interrupt_latch(opt300x_handle_t *handle, opt300x_bool_t enable)
enable or disable interrupt latch
uint8_t opt300x_set_range(opt300x_handle_t *handle, opt300x_range_t range)
set range
uint8_t opt300x_deinit(opt300x_handle_t *handle)
close the chip
opt300x_conversion_time_t
opt300x conversion time enumeration definition
uint8_t opt300x_get_fault_count(opt300x_handle_t *handle, opt300x_fault_count_t *count)
get fault count
uint8_t opt300x_stop_continuous_read(opt300x_handle_t *handle)
stop the chip reading
uint8_t opt300x_limit_convert_to_data(opt300x_handle_t *handle, uint16_t reg, float *lux)
convert the register raw data to the limit threshold
opt3002_range_t
opt3002 range enumeration definition
opt300x_interrupt_t
opt300x interrupt enumeration definition
uint8_t opt300x_set_addr_pin(opt300x_handle_t *handle, opt300x_address_t addr_pin)
set the iic address pin
uint8_t opt300x_init(opt300x_handle_t *handle)
initialize the chip
uint8_t opt300x_irq_handler(opt300x_handle_t *handle)
irq handler
opt300x_interrupt_polarity_t
opt300x interrupt polarity enumeration definition
uint8_t opt3002_set_range(opt300x_handle_t *handle, opt3002_range_t range)
set range
uint8_t opt300x_single_read(opt300x_handle_t *handle, uint16_t *raw, float *lux)
read data from the chip
opt300x_fault_count_t
opt300x fault count enumeration definition
struct opt300x_handle_s opt300x_handle_t
opt300x handle structure definition
uint8_t opt300x_get_mask_exponent(opt300x_handle_t *handle, opt300x_bool_t *enable)
get mask exponent status
@ OPT300X_ADDRESS_SCL
@ OPT300X_ADDRESS_VCC
@ OPT300X_ADDRESS_SDA
@ OPT300X_ADDRESS_GND
@ OPT300X_BOOL_FALSE
@ OPT300X_BOOL_TRUE
@ OPT3005_RANGE_5241P60_LUX
@ OPT3005_RANGE_AUTO
@ OPT3005_RANGE_167731P20_LUX
@ OPT3005_RANGE_2620P80_LUX
@ OPT3005_RANGE_81P90_LUX
@ OPT3005_RANGE_655P20_LUX
@ OPT3005_RANGE_41932P80_LUX
@ OPT3005_RANGE_327P60_LUX
@ OPT3005_RANGE_20966P40_LUX
@ OPT3005_RANGE_163P80_LUX
@ OPT3005_RANGE_83865P60_LUX
@ OPT3005_RANGE_10483P20_LUX
@ OPT3005_RANGE_1310P40_LUX
@ OPT300X_RANGE_1310P40_LUX
@ OPT300X_RANGE_10483P20_LUX
@ OPT300X_RANGE_83865P60_LUX
@ OPT300X_RANGE_5241P60_LUX
@ OPT300X_RANGE_81P90_LUX
@ OPT300X_RANGE_40P95_LUX
@ OPT300X_RANGE_20966P40_LUX
@ OPT300X_RANGE_41932P80_LUX
@ OPT300X_RANGE_163P80_LUX
@ OPT300X_RANGE_327P60_LUX
@ OPT300X_RANGE_AUTO
@ OPT300X_RANGE_655P20_LUX
@ OPT300X_RANGE_2620P80_LUX
@ OPT3002
@ OPT3005
@ OPT3006
@ OPT3004
@ OPT3007
@ OPT3001
@ OPT300X_CONVERSION_TIME_800_MS
@ OPT300X_CONVERSION_TIME_100_MS
@ OPT3002_RANGE_19656_NW_CM2
@ OPT3002_RANGE_9828_NW_CM2
@ OPT3002_RANGE_78624_NW_CM2
@ OPT3002_RANGE_39312_NW_CM2
@ OPT3002_RANGE_AUTO
@ OPT3002_RANGE_1257984_NW_CM2
@ OPT3002_RANGE_157248_NW_CM2
@ OPT3002_RANGE_10063872_NW_CM2
@ OPT3002_RANGE_2515968_NW_CM2
@ OPT3002_RANGE_314496_NW_CM2
@ OPT3002_RANGE_4914_NW_CM2
@ OPT3002_RANGE_5031936_NW_CM2
@ OPT3002_RANGE_628992_NW_CM2
@ OPT300X_INTERRUPT_HIGH_LIMIT
@ OPT300X_INTERRUPT_LOW_LIMIT
@ OPT300X_INTERRUPT_POLARITY_LOW
@ OPT300X_INTERRUPT_POLARITY_HIGH
@ OPT300X_FAULT_COUNT_EIGHT
@ OPT300X_FAULT_COUNT_ONE
@ OPT300X_FAULT_COUNT_TWO
@ OPT300X_FAULT_COUNT_FOUR
uint8_t opt300x_get_reg(opt300x_handle_t *handle, uint8_t reg, uint16_t *data)
get the chip register
uint8_t opt300x_set_reg(opt300x_handle_t *handle, uint8_t reg, uint16_t data)
set the chip register
opt300x handle structure definition
void(* delay_ms)(uint32_t ms)
void(* receive_callback)(uint8_t type)
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)
opt300x information structure definition
uint32_t driver_version
char manufacturer_name[32]