opt3001_regs.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 
19 #ifndef OPT3001_REGS_H
20 #define OPT3001_REGS_H
21 
22 
23 #ifdef __cplusplus
24  extern "C" {
25 #endif
26 
31  #define OPT3001_REGS_RESULT 0x00
32  #define OPT3001_REGS_CONFIG 0x01
33  #define OPT3001_REGS_LOW_LIMIT 0x02
34  #define OPT3001_REGS_HIGH_LIMIT 0x03
35  #define OPT3001_REGS_MANUFACTURER_ID 0x7E
36  #define OPT3001_REGS_DEVICE_ID 0x7F
38  #define OPT3001_DID_VALUE (0x3001)
40  #define OPT3001_CONFIG_RESET (0xC810)
42  #define OPT3001_CONFIG_RN_FSR (0xC000)
44  #define OPT3001_REGS_CONFIG_CT_MASK (0x0800)
45  #define OPT3001_REGS_CONFIG_CT(x) (((uint16_t)(x)) \
46  & OPT3001_REGS_CONFIG_CT_MASK)
48  #define OPT3001_CONFIG_M_SHUTDOWN (0x0)
49  #define OPT3001_CONFIG_M_SINGLE (0x1)
50  #define OPT3001_CONFIG_M_CONTINUOUS (0x2)
51  #define OPT3001_CONFIG_MOC_SHIFT (9U)
52  #define OPT3001_CONFIG_MOC_MASK (0x0600)
53  #define OPT3001_REGS_CONFIG_MOC(x) (((uint16_t)(((uint16_t)(x)) \
54  << OPT3001_CONFIG_MOC_SHIFT)) \
55  & OPT3001_CONFIG_MOC_MASK)
57  #define OPT3001_REGS_CONFIG_OVF (1 << 8)
58  #define OPT3001_REGS_CONFIG_CRF (1 << 7)
59  #define OPT3001_REGS_CONFIG_FH (1 << 6)
60  #define OPT3001_REGS_CONFIG_FL (1 << 5)
61  #define OPT3001_REGS_CONFIG_L (1 << 4)
62  #define OPT3001_REGS_CONFIG_POL (1 << 3)
63  #define OPT3001_REGS_CONFIG_ME (1 << 2)
65  #define OPT3001_REGS_CONFIG_FC_MASK (0x0003)
67  #define OPT3001_REGS_LOW_LIMIT_EOC_ENABLE (0xC000)
69  #define OPT3001_REGS_REG_EXPONENT(x) ((x) >> 12)
70  #define OPT3001_REGS_REG_MANTISSA(x) ((x) & 0xFFF)
72 /*
73  * Time to wait for the conversion to complete.
74  * The data sheet of the device (sect. 6.5) indicates that the conversion time is the integration time plus 3 ms.
75  * It has been added a bit more time just to be safe.
76  */
77  #define OPT3001_REGS_INT_TIME_SHORT 100000
78  #define OPT3001_REGS_INT_TIME_LONG 800000
80  #define OPT3001_CONVERSION_TIME_OFFSET 4000
82  #define OPT3001_CONVERSION_TIME_COMBINED OPT3001_REGS_INT_TIME_SHORT \
83  + OPT3001_REGS_INT_TIME_LONG \
84  + OPT3001_CONVERSION_TIME_OFFSET
86 #ifdef __cplusplus
87 }
88 #endif
89 
90 #endif /* OPT3001_REGS_H */
91