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 
Internal device error.
Definition: opt3001.h:115
i2c_t i2c_dev
I2C device, the sensor is connected to.
Definition: opt3001.h:98
General error.
Definition: opt3001.h:116
opt3001_params_t params
Configuration parameters.
Definition: opt3001.h:106
unsigned int i2c_t
Default i2c_t type definition.
Definition: i2c.h:157
int opt3001_init(opt3001_t *dev, const opt3001_params_t *params)
Initialize the OPT3001 sensor driver.
int opt3001_read_lux(const opt3001_t *dev, uint32_t *convl)
Read sensor&#39;s raw data and convert it to milliLux.
Success, no error.
Definition: opt3001.h:113
Parameters needed for device initialization.
Definition: opt3001.h:97
I2C bus error.
Definition: opt3001.h:114
int opt3001_reset(const opt3001_t *dev)
Reset the OPT3001 sensor while simultaneous deactivating measurements.
Common macros and compiler attributes/pragmas configuration.
Device descriptor for OPT3001 sensors.
Definition: opt3001.h:105
uint8_t i2c_addr
The sensor&#39;s slave address on the I2C bus.
Definition: opt3001.h:99
int opt3001_set_active(const opt3001_t *dev)
Set active mode, this enables periodic measurements.
Low-level I2C peripheral driver interface definition.