Loading...
Searching...
No Matches
opt3001.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 HAW Hamburg
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
40
41#include <stdint.h>
42#include "periph/i2c.h"
43#include "kernel_defines.h"
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
53#define OPT3001_CONVERSION_TIME_100_MS (0x0000)
54#define OPT3001_CONVERSION_TIME_800_MS (0x0800)
56
68#ifndef CONFIG_OPT3001_I2C_ADDRESS
69#define CONFIG_OPT3001_I2C_ADDRESS (0x45)
70#endif
71
78#if IS_ACTIVE(CONFIG_OPT3001_CONVERSION_TIME_100)
79#define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_100_MS
80#elif IS_ACTIVE(CONFIG_OPT3001_CONVERSION_TIME_800)
81#define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
82#endif
83
84#ifndef CONFIG_OPT3001_CONVERSION_TIME
85#define CONFIG_OPT3001_CONVERSION_TIME OPT3001_CONVERSION_TIME_800_MS
86#endif
88
92typedef struct {
94 uint8_t i2c_addr;
96
100typedef struct {
102} opt3001_t;
103
107enum {
112};
113
124int opt3001_init(opt3001_t *dev, const opt3001_params_t *params);
125
135int opt3001_reset(const opt3001_t *dev);
136
146
156int opt3001_read_lux(const opt3001_t *dev, uint32_t *convl);
157
158#ifdef __cplusplus
159}
160#endif
161
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:108
@ OPT3001_ERROR_DEV
Internal device error.
Definition opt3001.h:110
@ OPT3001_ERROR_BUS
I2C bus error.
Definition opt3001.h:109
@ OPT3001_ERROR
General error.
Definition opt3001.h:111
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:155
Low-level I2C peripheral driver interface definition.
Common macros and compiler attributes/pragmas configuration.
Parameters needed for device initialization.
Definition opt3001.h:92
i2c_t i2c_dev
I2C device, the sensor is connected to.
Definition opt3001.h:93
uint8_t i2c_addr
The sensor's slave address on the I2C bus.
Definition opt3001.h:94
Device descriptor for OPT3001 sensors.
Definition opt3001.h:100
opt3001_params_t params
Configuration parameters.
Definition opt3001.h:101