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 
9 #pragma once
10 
44 #include <stdint.h>
45 #include "periph/i2c.h"
46 #include "kernel_defines.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
56 #define OPT3001_CONVERSION_TIME_100_MS (0x0000)
57 #define OPT3001_CONVERSION_TIME_800_MS (0x0800)
71 #ifndef CONFIG_OPT3001_I2C_ADDRESS
72 #define CONFIG_OPT3001_I2C_ADDRESS (0x45)
73 #endif
74 
81 #if IS_ACTIVE(CONFIG_OPT3001_CONVERSION_TIME_100)
82 #define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_100_MS
83 #elif IS_ACTIVE(CONFIG_OPT3001_CONVERSION_TIME_800)
84 #define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
85 #endif
86 
87 #ifndef CONFIG_OPT3001_CONVERSION_TIME
88 #define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
89 #endif
95 typedef struct {
97  uint8_t i2c_addr;
99 
103 typedef struct {
105 } opt3001_t;
106 
110 enum {
115 };
116 
127 int opt3001_init(opt3001_t *dev, const opt3001_params_t *params);
128 
138 int opt3001_reset(const opt3001_t *dev);
139 
149 
159 int opt3001_read_lux(const opt3001_t *dev, uint32_t *convl);
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
int opt3001_set_active(const opt3001_t *dev)
Set active mode, this enables periodic measurements.
int opt3001_read_lux(const opt3001_t *dev, uint32_t *convl)
Read sensor's raw data and convert it to milliLux.
int opt3001_init(opt3001_t *dev, const opt3001_params_t *params)
Initialize the OPT3001 sensor driver.
int opt3001_reset(const opt3001_t *dev)
Reset the OPT3001 sensor while simultaneous deactivating measurements.
@ OPT3001_OK
Success, no error.
Definition: opt3001.h:111
@ OPT3001_ERROR_DEV
Internal device error.
Definition: opt3001.h:113
@ OPT3001_ERROR_BUS
I2C bus error.
Definition: opt3001.h:112
@ OPT3001_ERROR
General error.
Definition: opt3001.h:114
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition: i2c.h:144
Low-level I2C peripheral driver interface definition.
Common macros and compiler attributes/pragmas configuration.
Parameters needed for device initialization.
Definition: opt3001.h:95
i2c_t i2c_dev
I2C device, the sensor is connected to.
Definition: opt3001.h:96
uint8_t i2c_addr
The sensor's slave address on the I2C bus.
Definition: opt3001.h:97
Device descriptor for OPT3001 sensors.
Definition: opt3001.h:103
opt3001_params_t params
Configuration parameters.
Definition: opt3001.h:104