YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
opt3001_drv.h
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// Driver for OPT3001 light sensor made by TI.
15// This sensor is accessed by a I2C interface.
16
17#ifndef SRC_DRIVER_OPT3001_DRV_H_
18#define SRC_DRIVER_OPT3001_DRV_H_
19
20#include "i2c_interface.h"
21
22namespace OPT3001 {
23static const uint8_t I2C_ADDR_GND = 0x44;
24static const uint8_t I2C_ADDR_VDD = 0x45;
25static const uint8_t I2C_ADDR_SDA = 0x46;
26static const uint8_t I2C_ADDR_SCL = 0x47;
27
28static const uint16_t CONF_800MS_CONT = 0b1100110000010000;
29static const uint16_t CONF_100MS_CONT = 0b1100010000010000;
30static const uint16_t CONF_800MS_SINGLE = 0b1100101000010000;
31static const uint16_t CONF_100MS_SINGLE = 0b1100001000010000;
32}
33
35public:
36 opt3001_drv(i2c_interface & i2c, uint8_t i2c_addr);
37 void start_measure(uint16_t conf);
38 bool measure_ready();
39 uint32_t get_light();
40 bool detect_sensor();
41
42private:
43 i2c_interface & _i2c;
44 uint8_t _i2c_addr;
45
46 uint16_t readRegister(uint8_t reg);
47 void writeRegister(uint8_t reg, uint16_t value);
48};
49
50#endif /* SRC_DRIVER_OPT3001_DRV_H_ */