| Nordic Thingy:52 v2.0.0

drv_bh1745.h
1 /*
2 Copyright (c) 2010 - 2017, Nordic Semiconductor ASA
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10
11 2. Redistributions in binary form, except as embedded into a Nordic
12 Semiconductor ASA integrated circuit in a product or a software update for
13 such product, must reproduce the above copyright notice, this list of
14 conditions and the following disclaimer in the documentation and/or other
15 materials provided with the distribution.
16
17 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18 contributors may be used to endorse or promote products derived from this
19 software without specific prior written permission.
20
21 4. This software, with or without modification, must only be used with a
22 Nordic Semiconductor ASA integrated circuit.
23
24 5. Any software provided in binary form under this license must not be reverse
25 engineered, decompiled, modified and/or disassembled.
26
27 THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
28 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
31 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
48 #ifndef __DRV_BH1745_H__
49 #define __DRV_BH1745_H__
50
51 #include "nrf_drv_twi.h"
52 #include <stdint.h>
53
54 #define REG_SYSTEM_CONTROL 0x40
55 #define REG_MODE_CONTROL1 0x41
56 #define REG_MODE_CONTROL2 0x42
57 #define REG_MODE_CONTROL3 0x44
58 #define REG_RED_DATA_LSBs 0x50
59 #define REG_RED_DATA_MSBs 0x51
60 #define REG_GREEN_DATA_LSB 0x52
61 #define REG_GREEN_DATA_MSB 0x53
62 #define REG_BLUE_DATA_LSB 0x54
63 #define REG_BLUE_DATA_MSB 0x55
64 #define REG_CLEAR_DATA_LSB 0x56
65 #define REG_CLEAR_DATA_MSB 0x57
66 #define REG_DINT_DATA_LSB 0x58
67 #define REG_DINT_DATA_MSB 0x59
68 #define REG_INTERRUPT 0x60
69 #define REG_PERSISTENCE 0x61
70 #define REG_TH_LSB 0x62
71 #define REG_TH_MSB 0x63
72 #define REG_TL_LSB 0x64
73 #define REG_TL_MSB 0x65
74 #define REG_MANUFACTURER_ID 0x92
75
76 #define REG_SYSTEM_CONTROL_PART_ID_Msk 0x3F
77 #define REG_SYSTEM_CONTROL_SW_RESET_Msk 0x80
78 #define REG_SYSTEM_CONTROL_INT_RESET_Msk 0x40
79
80 #define REG_MODE_CONTROL1_MEAS_TIME_Msk 0x07
81
82 #define REG_MODE_CONTROL2_VALID_Msk 0x80
83 #define REG_MODE_CONTROL2_RGBC_EN_Msk 0x10
84 #define REG_MODE_CONTROL2_GAIN_Msk 0x03
85
86 #define REG_INTERRUPT_STATUS_Msk 0x80
87 #define REG_INTERRUPT_LATCH_Msk 0x10
88 #define REG_INTERRUPT_SOURCE_Msk 0x0C
89 #define REG_INTERRUPT_ENABLE_Msk 0x01
90
91 #define REG_PERSISTENCE_PERSISTENCE_Msk 0x03
92
93
96 typedef struct
97 {
98 uint8_t twi_addr;
99 nrf_drv_twi_t const * p_twi_instance;
100 nrf_drv_twi_config_t const * p_twi_cfg;
101 } drv_bh1745_cfg_t;
102
105 typedef enum
106 {
107 DRV_BH1745_MEAS_TIME_160MS,
108 DRV_BH1745_MEAS_TIME_320MS,
109 DRV_BH1745_MEAS_TIME_640MS,
110 DRV_BH1745_MEAS_TIME_1280MS,
111 DRV_BH1745_MEAS_TIME_2560MS,
112 DRV_BH1745_MEAS_TIME_5120MS
113 } drv_bh1745_meas_time_t;
114
117 typedef enum
118 {
119 DRV_BH1745_GAIN_1X,
120 DRV_BH1745_GAIN_2X,
121 DRV_BH1745_GAIN_16X
122 } drv_bh1745_gain_t;
123
126 typedef struct
127 {
128 uint16_t red;
129 uint16_t green;
130 uint16_t blue;
131 uint16_t clear;
132 } drv_bh1745_data_t;
133
136 typedef struct
137 {
138 uint16_t high;
139 uint16_t low;
140 } drv_bh1745_threshold_t;
141
146 uint32_t drv_bh1745_init(void);
147
154 uint32_t drv_bh1745_open(drv_bh1745_cfg_t const * const p_cfg);
155
160 uint32_t drv_bh1745_close(void);
161
169 uint32_t drv_bh1745_manu_id_get(uint8_t * p_manu_id);
170
179 uint32_t drv_bh1745_part_id_get(uint8_t * p_part_id);
180
188 uint32_t drv_bh1745_sw_reset(void);
189
195 uint32_t drv_bh1745_int_reset(void);
196
204 uint32_t drv_bh1745_meas_time_set(drv_bh1745_meas_time_t meas_time);
205
213 uint32_t drv_bh1745_meas_enable(bool enable);
214
222 uint32_t drv_bh1745_gain_set(drv_bh1745_gain_t gain);
223
232 uint32_t drv_bh1745_data_get(drv_bh1745_data_t * p_data);
233
241 uint32_t drv_bh1745_int_get(uint8_t * p_int_reg);
242
251 uint32_t drv_bh1745_int_set(uint8_t int_reg);
252
260 uint32_t drv_bh1745_persistance_get(uint8_t * p_per_reg);
261
270 uint32_t drv_bh1745_persistance_set(uint8_t per_reg);
271
280 uint32_t drv_bh1745_threshold_get(drv_bh1745_threshold_t * p_th);
281
290 uint32_t drv_bh1745_threshold_set(drv_bh1745_threshold_t const * p_th);
291
292 #endif
293
drv_bh1745_threshold_set
uint32_t drv_bh1745_threshold_set(drv_bh1745_threshold_t const *p_th)
Function for setting the BH1745 threshold.
drv_bh1745_persistance_get
uint32_t drv_bh1745_persistance_get(uint8_t *p_per_reg)
Function for getting the BH1745 persistance register.
drv_bh1745_part_id_get
uint32_t drv_bh1745_part_id_get(uint8_t *p_part_id)
Function for getting the BH1745 part ID.
drv_bh1745_int_set
uint32_t drv_bh1745_int_set(uint8_t int_reg)
Function for setting the BH1745 interrupt register.
drv_bh1745_open
uint32_t drv_bh1745_open(drv_bh1745_cfg_t const *const p_cfg)
Function for opening the BH1745 driver according to the specified configuration.
drv_bh1745_threshold_t
Measurement thresholds.
Definition: drv_bh1745.h:136
drv_bh1745_manu_id_get
uint32_t drv_bh1745_manu_id_get(uint8_t *p_manu_id)
Function for getting the BH1745 manufacturer ID.
drv_bh1745_data_t
Measurement result.
Definition: drv_bh1745.h:126
drv_bh1745_gain_t
drv_bh1745_gain_t
RGBC (red, green, blue, clear) gain setting.
Definition: drv_bh1745.h:117
drv_bh1745_meas_time_t
drv_bh1745_meas_time_t
Measurement time.
Definition: drv_bh1745.h:105
drv_bh1745_close
uint32_t drv_bh1745_close(void)
Function for closing the BH1745 driver.
drv_bh1745_cfg_t::p_twi_cfg
nrf_drv_twi_config_t const * p_twi_cfg
The TWI configuration to use while the driver is enabled.
Definition: drv_bh1745.h:100
drv_bh1745_int_reset
uint32_t drv_bh1745_int_reset(void)
Function for resetting the interrupt.
drv_bh1745_cfg_t::twi_addr
uint8_t twi_addr
TWI address of BH1745.
Definition: drv_bh1745.h:98
drv_bh1745_cfg_t::p_twi_instance
nrf_drv_twi_t const * p_twi_instance
The instance of TWI master to be used for transactions.
Definition: drv_bh1745.h:99
drv_bh1745_threshold_get
uint32_t drv_bh1745_threshold_get(drv_bh1745_threshold_t *p_th)
Function for getting the BH1745 threshold.
drv_bh1745_cfg_t
BH1745 configuration.
Definition: drv_bh1745.h:96
drv_bh1745_meas_time_set
uint32_t drv_bh1745_meas_time_set(drv_bh1745_meas_time_t meas_time)
Function for setting the BH1745 measurement time.
drv_bh1745_data_get
uint32_t drv_bh1745_data_get(drv_bh1745_data_t *p_data)
Function for getting the BH1745 data.
drv_bh1745_gain_set
uint32_t drv_bh1745_gain_set(drv_bh1745_gain_t gain)
Function for setting the BH1745 ADC gain.
drv_bh1745_meas_enable
uint32_t drv_bh1745_meas_enable(bool enable)
Function for enabling the BH1745 measurements.
drv_bh1745_init
uint32_t drv_bh1745_init(void)
Function for initializing the BH1745 driver.
drv_bh1745_int_get
uint32_t drv_bh1745_int_get(uint8_t *p_int_reg)
Function for getting the BH1745 interrupt register.
drv_bh1745_persistance_set
uint32_t drv_bh1745_persistance_set(uint8_t per_reg)
Function for setting the BH1745 persistance register.
drv_bh1745_sw_reset
uint32_t drv_bh1745_sw_reset(void)
Function for resetting the BH1745 registers.