opt3001.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
42 #ifndef OPT3001_H
43 #define OPT3001_H
44 
45 #include <stdint.h>
46 #include "periph/i2c.h"
47 #include "kernel_defines.h"
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 
58 #define OPT3001_CONVERSION_TIME_100_MS (0x0000)
59 #define OPT3001_CONVERSION_TIME_800_MS (0x0800)
73 #ifndef CONFIG_OPT3001_I2C_ADDRESS
74 #define CONFIG_OPT3001_I2C_ADDRESS (0x45)
75 #endif
76 
83 #if IS_ACTIVE(CONFIG_OPT3001_CONVERSION_TIME_100)
84 #define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_100_MS
85 #elif IS_ACTIVE(CONFIG_OPT3001_CONVERSION_TIME_800)
86 #define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
87 #endif
88 
89 #ifndef CONFIG_OPT3001_CONVERSION_TIME
90 #define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
91 #endif
92 
97 typedef struct {
99  uint8_t i2c_addr;
101 
105 typedef struct {
107 } opt3001_t;
108 
112 enum {
117 };
118 
129 int opt3001_init(opt3001_t *dev, const opt3001_params_t *params);
130 
140 int opt3001_reset(const opt3001_t *dev);
141 
150 int opt3001_set_active(const opt3001_t *dev);
151 
161 int opt3001_read_lux(const opt3001_t *dev, uint32_t *convl);
162 
163 #ifdef __cplusplus
164 }
165 #endif
166 
167 #endif /* OPT3001_H */
168 
opt3001_t
Device descriptor for OPT3001 sensors.
Definition: opt3001.h:105
OPT3001_ERROR_DEV
@ OPT3001_ERROR_DEV
Internal device error.
Definition: opt3001.h:115
opt3001_params_t::i2c_addr
uint8_t i2c_addr
The sensor's slave address on the I2C bus.
Definition: opt3001.h:99
opt3001_t::params
opt3001_params_t params
Configuration parameters.
Definition: opt3001.h:106
kernel_defines.h
Common macros and compiler attributes/pragmas configuration.
i2c_t
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:151
OPT3001_ERROR
@ OPT3001_ERROR
General error.
Definition: opt3001.h:116
opt3001_params_t::i2c_dev
i2c_t i2c_dev
I2C device, the sensor is connected to.
Definition: opt3001.h:98
opt3001_init
int opt3001_init(opt3001_t *dev, const opt3001_params_t *params)
Initialize the OPT3001 sensor driver.
OPT3001_ERROR_BUS
@ OPT3001_ERROR_BUS
I2C bus error.
Definition: opt3001.h:114
opt3001_read_lux
int opt3001_read_lux(const opt3001_t *dev, uint32_t *convl)
Read sensor's raw data and convert it to milliLux.
OPT3001_OK
@ OPT3001_OK
Success, no error.
Definition: opt3001.h:113
opt3001_params_t
Parameters needed for device initialization.
Definition: opt3001.h:97
opt3001_reset
int opt3001_reset(const opt3001_t *dev)
Reset the OPT3001 sensor while simultaneous deactivating measurements.
i2c.h
Low-level I2C peripheral driver interface definition.
opt3001_set_active
int opt3001_set_active(const opt3001_t *dev)
Set active mode, this enables periodic measurements.