Rohm BH1745 red-green-blue-clear -color sensor driver

Dependents:   rohm-bh1745-hello rohm-tileshield-6sensor-demo GR-PEACH_IoT_Platform_HTTP_sample

Fork of rohm-rpr0521 by Rohm

Files at this revision

API Documentation at this revision

Comitter:
MikkoZ
Date:
Mon Sep 12 12:31:40 2016 +0000
Parent:
0:0bcc203c5c75
Child:
2:2b4a1b49998d
Commit message:
Initial version of bh1745 driver

Changed in this revision

rohm-bh1745/bh1745.h Show annotated file Show diff for this revision Revisions of this file
rohm-bh1745/bh1745_driver.h Show annotated file Show diff for this revision Revisions of this file
rohm-rpr0521/rpr0521.h Show diff for this revision Revisions of this file
rohm-rpr0521/rpr0521_driver.h Show diff for this revision Revisions of this file
source/bh1745_driver.cpp Show annotated file Show diff for this revision Revisions of this file
source/rpr0521_driver.cpp Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rohm-bh1745/bh1745.h	Mon Sep 12 12:31:40 2016 +0000
@@ -0,0 +1,133 @@
+/*   Copyright 2016 Rohm Semiconductor
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+#ifndef BH1745_H
+#define BH1745_H
+
+/* registers */
+#define BH1745_REGISTER_DUMP_START 0x40
+#define BH1745_SYSTEM_CONTROL 0x40
+// Writing MODE_CONTROL1/2/3 restarts measurement if any.
+#define BH1745_MODE_CONTROL1 0x41
+#define BH1745_MODE_CONTROL2 0x42
+// Always write 02h
+#define BH1745_MODE_CONTROL3 0x44
+// Least significant byte of uint16 RED measurement value
+#define BH1745_RED_DATA_LSBS 0x50
+// Most significant byte of uint16 RED measurement value
+#define BH1745_RED_DATA_MSBS 0x51
+#define BH1745_GREEN_DATA_LSBS 0x52
+#define BH1745_GREEN_DATA_MSBS 0x53
+#define BH1745_BLUE_DATA_LSBS 0x54
+#define BH1745_BLUE_DATA_MSBS 0x55
+#define BH1745_CLEAR_DATA_LSBS 0x56
+#define BH1745_CLEAR_DATA_MSBS 0x57
+// DINT data is used for internal calculation of BH1745NUC.
+#define BH1745_DINT_DATA_LSBS 0x58
+// DINT registers are used for IC test only.
+#define BH1745_DINT_DATA_MSBS 0x59
+#define BH1745_INTERRUPT 0x60
+#define BH1745_PERSISTENCE 0x61
+#define BH1745_TH_LSBS 0x62
+#define BH1745_TH_MSBS 0x63
+#define BH1745_TL_LSBS 0x64
+#define BH1745_TL_MSBS 0x65
+#define BH1745_ID_REG 0x92
+#define BH1745_REGISTER_DUMP_END 0x92
+/* registers bits */
+// Initial reset is not started
+#define BH1745_SYSTEM_CONTROL_SW_RESET_NOT_STARTED (0x00 << 7)
+// Initial reset is started
+#define BH1745_SYSTEM_CONTROL_SW_RESET_START (0x01 << 7)
+// In specification "not_initialized"
+#define BH1745_SYSTEM_CONTROL_INT_PIN_ACTIVE (0x00 << 6)
+// high impedance
+#define BH1745_SYSTEM_CONTROL_INT_PIN_INACTIVE (0x01 << 6)
+#define BH1745_SYSTEM_CONTROL_PART_ID (0x0B << 0)
+#define BH1745_MODE_CONTROL1_RESERVED_WRITE00000 (0x00 << 3)
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_160MSEC (0x00 << 0)
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_320MSEC (0x01 << 0)
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_640MSEC (0x02 << 0)
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_1280MSEC (0x03 << 0)
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_2560MSEC (0x04 << 0)
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_5120MSEC (0x05 << 0)
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_FORBIDDEN6 (0x06 << 0)
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_FORBIDDEN7 (0x07 << 0)
+#define BH1745_MODE_CONTROL2_DATA_UPDATED_NO (0x00 << 7)
+#define BH1745_MODE_CONTROL2_DATA_UPDATED_YES (0x01 << 7)
+#define BH1745_MODE_CONTROL2_RESERVED65_WRITE00 (0x00 << 5)
+#define BH1745_MODE_CONTROL2_RGBC_MEASUREMENT_INACTIVE (0x00 << 4)
+#define BH1745_MODE_CONTROL2_RGBC_MEASUREMENT_ACTIVE (0x01 << 4)
+#define BH1745_MODE_CONTROL2_RESERVED32_WRITE00 (0x00 << 2)
+#define BH1745_MODE_CONTROL2_ADC_GAIN_1X (0x00 << 0)
+#define BH1745_MODE_CONTROL2_ADC_GAIN_2X (0x01 << 0)
+#define BH1745_MODE_CONTROL2_ADC_GAIN_16X (0x02 << 0)
+#define BH1745_MODE_CONTROL2_ADC_GAIN_FORBIDDEN3 (0x03 << 0)
+#define BH1745_MODE_CONTROL3_ALWAYS_02H (0x02 << 0)
+#define BH1745_INTERRUPT_STATUS_INACTIVE (0x00 << 7)
+#define BH1745_INTERRUPT_STATUS_ACTIVE (0x01 << 7)
+#define BH1745_INTERRUPT_RESERVED65_WRITE00 (0x00 << 5)
+// INT pin is latched until INTERRUPT register is read or initialized
+#define BH1745_INTERRUPT_LATCH_ENABLE (0x00 << 4)
+// INT pin is updated after each measurement
+#define BH1745_INTERRUPT_LATCH_DISABLE (0x01 << 4)
+// red channel
+#define BH1745_INTERRUPT_SOURCE_SELECT_RED (0x00 << 2)
+// green channel
+#define BH1745_INTERRUPT_SOURCE_SELECT_GREEN (0x01 << 2)
+// blue channel
+#define BH1745_INTERRUPT_SOURCE_SELECT_BLUE (0x02 << 2)
+// clear channel
+#define BH1745_INTERRUPT_SOURCE_SELECT_CLEAR (0x03 << 2)
+#define BH1745_INTERRUPT_RESERVED1_WRITE0 (0x00 << 1)
+#define BH1745_INTERRUPT_PIN_DISABLE (0x00 << 0)
+#define BH1745_INTERRUPT_PIN_ENABLE (0x01 << 0)
+#define BH1745_PERSISTENCE_RESERVED72_WRITE000001 (0x01 << 2)
+// Interrupt status is toggled at each measurement end.
+#define BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_TOGGLE_AFTER_MEASUREMENT (0x00 << 0)
+// Interrupt status is updated at each measurement end.
+#define BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_UPDATE_AFTER_MEASUREMENT (0x01 << 0)
+// Interrupt status is updated if 4 consecutive threshold judgements are the same
+#define BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_UPDATE_AFTER_4_SAME (0x02 << 0)
+// Interrupt status is updated if 8 consecutive threshold judgements are the same
+#define BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_UPDATE_AFTER_8_SAME (0x03 << 0)
+#define BH1745_ID_REG_MANUFACTURER_ID (0xE0 << 0)
+ /*registers bit masks */
+#define BH1745_SYSTEM_CONTROL_SW_RESET_MASK 0x80
+
+#define BH1745_SYSTEM_CONTROL_INT_PIN_MASK 0x40
+
+#define BH1745_SYSTEM_CONTROL_PART_MASK 0x3F
+#define BH1745_MODE_CONTROL1_RESERVED_MASK 0xF8
+#define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_MASK 0x07
+#define BH1745_MODE_CONTROL2_DATA_UPDATED_MASK 0x80
+#define BH1745_MODE_CONTROL2_RESERVED65_MASK 0x60
+#define BH1745_MODE_CONTROL2_RGBC_MEASUREMENT_MASK 0x10
+#define BH1745_MODE_CONTROL2_RESERVED32_MASK 0x0C
+#define BH1745_MODE_CONTROL2_ADC_GAIN_MASK 0x03
+#define BH1745_MODE_CONTROL3_ALWAYS_MASK 0xFF
+#define BH1745_INTERRUPT_STATUS_MASK 0x80
+#define BH1745_INTERRUPT_RESERVED65_MASK 0x60
+#define BH1745_INTERRUPT_LATCH_MASK 0x10
+
+#define BH1745_INTERRUPT_SOURCE_MASK 0x0C
+// Write 0
+#define BH1745_INTERRUPT_RESERVED1_MASK 0x02
+#define BH1745_INTERRUPT_PIN_MASK 0x01
+#define BH1745_PERSISTENCE_RESERVED72_MASK 0xFC
+#define BH1745_PERSISTENCE_OF_INTERRUPT_MASK 0x03
+
+#define BH1745_ID_REG_MANUFACTURER_MASK 0xFF
+
+#endif /* BH1745_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rohm-bh1745/bh1745_driver.h	Mon Sep 12 12:31:40 2016 +0000
@@ -0,0 +1,29 @@
+/*   Copyright 2016 Rohm Semiconductor
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+#ifndef bh1745_driver_h
+#define bh1745_driver_h
+
+#include "../../rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h"         //types
+
+/* bh1745 driver*/
+uint8_t bh1745_readId();
+void bh1745_wait_until_found();
+void bh1745_soft_reset();
+bool bh1745_read_data(uint16_t* data16);
+void bh1745_initial_setup();
+void bh1745_clear_interrupt();
+
+#endif
+
--- a/rohm-rpr0521/rpr0521.h	Mon Sep 12 09:53:15 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +0,0 @@
-/*   Copyright 2016 Rohm Semiconductor
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
-#ifndef RPR0521_H
-#define RPR0521_H
-
-/* registers */
-#define RPR0521_REGISTER_DUMP_START 0x40
-#define RPR0521_SYSTEM_CONTROL 0x40
-#define RPR0521_MODE_CONTROL 0x41
-#define RPR0521_ALS_PS_CONTROL 0x42
-#define RPR0521_PS_CONTROL 0x43
-// low 8bit
-#define RPR0521_PS_DATA_LSBS 0x44
-// high 4bit
-#define RPR0521_PS_DATA_MSBS 0x45
-// low 8bit
-#define RPR0521_ALS_DATA0_LSBS 0x46
-// high 8bit
-#define RPR0521_ALS_DATA0_MSBS 0x47
-// low 8bit
-#define RPR0521_ALS_DATA1_LSBS 0x48
-// high 8bit
-#define RPR0521_ALS_DATA1_MSBS 0x49
-#define RPR0521_INTERRUPT 0x4A
-// low 8bit
-#define RPR0521_PS_TH_LSBS 0x4B
-// high 4bit
-#define RPR0521_PS_TH_MSBS 0x4C
-// low 8bit
-#define RPR0521_PS_TL_LSBS 0x4D
-// high 4bit
-#define RPR0521_PS_TL_MSBS 0x4E
-// low 8bit
-#define RPR0521_ALS_DATA0_TH_LSBS 0x4F
-// high 8bit
-#define RPR0521_ALS_DATA0_TH_MSBS 0x50
-// low 8bit
-#define RPR0521_ALS_DATA0_TL_LSBS 0x51
-// high 8bit
-#define RPR0521_ALS_DATA0_TL_MSBS 0x52
-// low 8bit
-#define RPR0521_PS_OFFSET_LSBS 0x53
-// high 2bit
-#define RPR0521_PS_OFFSET_MSBS 0x54
-#define RPR0521_MANUFACT 0x92
-#define RPR0521_MANUFACT_VALUE 0xE0
-#define RPR0521_REGISTER_DUMP_END 0x54
-/* registers bits */
-#define RPR0521_SYSTEM_CONTROL_SW_RESET_NOT_STARTED (0x00 << 7)
-#define RPR0521_SYSTEM_CONTROL_SW_RESET_START (0x01 << 7)
-#define RPR0521_SYSTEM_CONTROL_INT_PIN_NO_INIT (0x00 << 6)
-#define RPR0521_SYSTEM_CONTROL_INT_PIN_HI_Z (0x01 << 6)
-#define RPR0521_SYSTEM_CONTROL_PART_ID (0x0A << 0)
-#define RPR0521_MODE_CONTROL_ALS_EN_FALSE (0x00 << 7)
-#define RPR0521_MODE_CONTROL_ALS_EN_TRUE (0x01 << 7)
-#define RPR0521_MODE_CONTROL_PS_EN_FALSE (0x00 << 6)
-#define RPR0521_MODE_CONTROL_PS_EN_TRUE (0x01 << 6)
-#define RPR0521_MODE_CONTROL_PS_PULSE_200US (0x00 << 5)
-#define RPR0521_MODE_CONTROL_PS_PULSE_330US (0x01 << 5)
-#define RPR0521_MODE_CONTROL_PS_OPERATING_MODE_NORMAL (0x00 << 4)
-#define RPR0521_MODE_CONTROL_PS_OPERATING_MODE_DOUBLE_MEASUREMENT (0x01 << 4)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_OFF_OFF (0x00 << 0)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_OFF_10MS (0x01 << 0)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_OFF_40MS (0x02 << 0)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_OFF_100MS (0x03 << 0)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_OFF_400MS (0x04 << 0)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_100MS_50MS (0x05 << 0)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_100MS_100MS (0x06 << 0)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_100MS_400MS (0x07 << 0)
-// ALS measurement time is 100ms, sleep time is 300ms
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_400MS_50MS (0x08 << 0)
-// ALS measurement time is 100ms, sleep time is 300ms
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_400MS_100MS (0x09 << 0)
-// Measurement time 400ms, high sensitivity mode.
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_400MS_OFF (0x0A << 0)
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_400MS_400MS (0x0B << 0)
-// Additional sw process is necessary. Check P.18
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_50MS_50MS (0x0C << 0)
-#define RPR0521_ALS_PS_CONTROL_RESERVED67_WRITE_00 (0x00 << 6)
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA0_GAIN_X1 (0x00 << 4)
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA0_GAIN_X2 (0x01 << 4)
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA0_GAIN_X64 (0x02 << 4)
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA0_GAIN_X128 (0x03 << 4)
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA1_GAIN_X1 (0x00 << 2)
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA1_GAIN_X2 (0x01 << 2)
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA1_GAIN_X64 (0x02 << 2)
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA1_GAIN_X128 (0x03 << 2)
-#define RPR0521_ALS_PS_CONTROL_LED_CURRENT_25MA (0x00 << 0)
-#define RPR0521_ALS_PS_CONTROL_LED_CURRENT_50MA (0x01 << 0)
-#define RPR0521_ALS_PS_CONTROL_LED_CURRENT_100MA (0x02 << 0)
-#define RPR0521_ALS_PS_CONTROL_LED_CURRENT_200MA (0x03 << 0)
-#define RPR0521_PS_CONTROL_AMBIENT_IR_FLAG_LOW (0x00 << 6)
-#define RPR0521_PS_CONTROL_AMBIENT_IR_FLAG_HIGH (0x01 << 6)
-#define RPR0521_PS_CONTROL_AMBIENT_IR_FLAG_TOO_HIGH (0x02 << 6)
-#define RPR0521_PS_CONTROL_PS_GAIN_X1 (0x00 << 4)
-#define RPR0521_PS_CONTROL_PS_GAIN_X2 (0x01 << 4)
-#define RPR0521_PS_CONTROL_PS_GAIN_X4 (0x02 << 4)
-#define RPR0521_PS_CONTROL_PERSISTENCE_DRDY (0x00 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_1 (0x01 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_2 (0x02 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_3 (0x03 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_4 (0x04 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_5 (0x05 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_6 (0x06 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_7 (0x07 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_8 (0x08 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_9 (0x09 << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_10 (0x0A << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_11 (0x0B << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_12 (0x0C << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_13 (0x0D << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_14 (0x0E << 0)
-#define RPR0521_PS_CONTROL_PERSISTENCE_CONSECUTIVE_15 (0x0F << 0)
-#define RPR0521_INTERRUPT_PS_INT_STATUS_INACTIVE (0x00 << 7)
-#define RPR0521_INTERRUPT_PS_INT_STATUS_ACTIVE (0x01 << 7)
-#define RPR0521_INTERRUPT_ALS_INT_STATUS_INACTIVE (0x00 << 6)
-#define RPR0521_INTERRUPT_ALS_INT_STATUS_ACTIVE (0x01 << 6)
-#define RPR0521_INTERRUPT_INT_MODE_PS_TH_H_ACTIVE (0x00 << 4)
-#define RPR0521_INTERRUPT_INT_MODE_PS_TH_HYSTERESIS (0x01 << 4)
-#define RPR0521_INTERRUPT_INT_MODE_PS_TH_OUTSIDE_DETECTION (0x02 << 4)
-#define RPR0521_INTERRUPT_INT_ASSERT_STABLE (0x00 << 3)
-#define RPR0521_INTERRUPT_INT_ASSERT_REINT (0x01 << 3)
-#define RPR0521_INTERRUPT_INT_LATCH_ENABLED (0x00 << 2)
-#define RPR0521_INTERRUPT_INT_LATCH_DISABLED (0x01 << 2)
-#define RPR0521_INTERRUPT_INT_TRIG_INACTIVE (0x00 << 0)
-#define RPR0521_INTERRUPT_INT_TRIG_BY_PS (0x01 << 0)
-#define RPR0521_INTERRUPT_INT_TRIG_BY_ALS (0x02 << 0)
-#define RPR0521_INTERRUPT_INT_TRIG_BY_BOTH (0x03 << 0)
-#define RPR0521_MANUFACT_ID_E0H (0xE0 << 0)
- /*registers bit masks */
-#define RPR0521_SYSTEM_CONTROL_SW_RESET_MASK 0x80
-#define RPR0521_SYSTEM_CONTROL_INT_PIN_MASK 0x40
-#define RPR0521_SYSTEM_CONTROL_PART_MASK 0x3F
-#define RPR0521_MODE_CONTROL_ALS_EN_MASK 0x80
-#define RPR0521_MODE_CONTROL_PS_EN_MASK 0x40
-#define RPR0521_MODE_CONTROL_PS_PULSE_MASK 0x20
-#define RPR0521_MODE_CONTROL_PS_OPERATING_MODE_MASK 0x10
-#define RPR0521_MODE_CONTROL_MEASUREMENT_TIME_MASK 0x0F
-
-#define RPR0521_ALS_PS_CONTROL_RESERVED67_MASK 0xC0
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA0_GAIN_MASK 0x30
-#define RPR0521_ALS_PS_CONTROL_ALS_DATA1_GAIN_MASK 0x0C
-#define RPR0521_ALS_PS_CONTROL_LED_CURRENT_MASK 0x03
-#define RPR0521_PS_CONTROL_AMBIENT_IR_FLAG_MASK 0xC0
-#define RPR0521_PS_CONTROL_PS_GAIN_MASK 0x30
-#define RPR0521_PS_CONTROL_PERSISTENCE_MASK 0x0F
-#define RPR0521_INTERRUPT_PS_INT_STATUS_MASK 0x80
-#define RPR0521_INTERRUPT_ALS_INT_STATUS_MASK 0x40
-#define RPR0521_INTERRUPT_INT_MODE_MASK 0x30
-#define RPR0521_INTERRUPT_INT_ASSERT_MASK 0x08
-#define RPR0521_INTERRUPT_INT_LATCH_MASK 0x04
-#define RPR0521_INTERRUPT_INT_TRIG_MASK 0x03
-#define RPR0521_MANUFACT_ID_MASK 0xFF
-
-#endif /* RPR0521_H */
--- a/rohm-rpr0521/rpr0521_driver.h	Mon Sep 12 09:53:15 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*   Copyright 2016 Rohm Semiconductor
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
-#ifndef rpr0521_driver_h
-#define rpr0521_driver_h
-
-#include "../../rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h"         //types
-
-/* rpr0521 driver*/
-uint8_t rpr0521_readId();
-void rpr0521_wait_until_found();
-void rpr0521_soft_reset();
-bool rpr0521_read_data(uint16_t* data16);
-void rpr0521_initial_setup();
-void rpr0521_clear_interrupt();
-
-#endif
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/source/bh1745_driver.cpp	Mon Sep 12 12:31:40 2016 +0000
@@ -0,0 +1,108 @@
+/*   Copyright 2016 Rohm Semiconductor
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+#include "../../rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h"         //types, DEBUG_print*
+#include "../../rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"        //read_register, write_register, change_bits
+
+#include "../rohm-bh1745/bh1745.h"      //bh1745_* register definitions
+#include "../rohm-bh1745/bh1745_driver.h"
+//Choose SAD according to setup
+//#define SAD  0x38
+#define SAD 0x39
+
+/* bh1745 driver*/
+uint8_t bh1745_readId(){
+    uint8_t id;
+    uint8_t read_bytes;
+
+    read_bytes = read_register(SAD, BH1745_ID_REG, &id, 1);
+    if ( read_bytes > 0 ){
+        uint8_t partid;
+        
+        DEBUG_printf("Manufacturer: %u\n\r", id);
+        read_bytes = read_register(SAD, BH1745_SYSTEM_CONTROL, &partid, 1);
+        if ( read_bytes > 0 ){
+            DEBUG_printf("Part ID: %u\n\r", (partid & 0b00111111) );
+        return(partid);
+        }
+        else{
+            DEBUG_print("Part ID read failed.\n\r");
+            return 255;
+        }
+    }
+    else{
+        DEBUG_print("Manufacturer read failed.\n\r");
+        return 255;
+    }
+}
+
+void bh1745_wait_until_found(){
+  uint8_t id;
+
+  id = bh1745_readId();
+  while (id == 255){
+    wait(100);
+    id = bh1745_readId();
+    }
+  return;
+  }
+
+void bh1745_soft_reset(){
+    change_bits(SAD, BH1745_MODE_CONTROL1, BH1745_SYSTEM_CONTROL_SW_RESET_MASK, BH1745_SYSTEM_CONTROL_SW_RESET_START);
+}
+
+void bh1745_clear_interrupt(){
+    uint8_t tmp;
+    read_register(SAD, BH1745_INTERRUPT, &tmp, 1);
+}
+
+void bh1745_initial_setup(){
+    write_register(SAD, BH1745_INTERRUPT,
+        (BH1745_INTERRUPT_STATUS_INACTIVE |
+        BH1745_INTERRUPT_LATCH_ENABLE |
+        BH1745_INTERRUPT_PIN_DISABLE)
+        );
+    write_register(SAD, BH1745_PERSISTENCE,
+        (BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_TOGGLE_AFTER_MEASUREMENT)
+        );
+    write_register(SAD, BH1745_MODE_CONTROL1,
+        (BH1745_MODE_CONTROL1_MEASUREMENT_TIME_160MSEC)
+        );
+    write_register(SAD, BH1745_MODE_CONTROL2,
+        (BH1745_MODE_CONTROL2_RGBC_MEASUREMENT_ACTIVE |
+         BH1745_MODE_CONTROL2_ADC_GAIN_1X)
+        );
+}
+
+/* input param: data16, pointer to 4*16bit memory 
+   return: error, true/false */
+bool bh1745_read_data(uint16_t* data16){
+    #define BH1745_DATA_LEN 8
+    uint8_t data[BH1745_DATA_LEN];
+    uint8_t read_bytes;
+
+    read_bytes = read_register(SAD, BH1745_RED_DATA_LSBS, &data[0], BH1745_DATA_LEN);
+    if (read_bytes == BH1745_DATA_LEN){
+        data16[0] = (data[0]) | (data[1] << 8); //red
+        data16[1] = (data[2]) | (data[3] << 8); //green
+        data16[2] = (data[4]) | (data[5] << 8); //blue
+        data16[3] = (data[6]) | (data[7] << 8); //clear
+        return false;
+        }
+    else{
+        DEBUG_printf("Read error. Read %d bytes\n\r", read_bytes);
+        return true;
+        }
+   
+    }
--- a/source/rpr0521_driver.cpp	Mon Sep 12 09:53:15 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,94 +0,0 @@
-/*   Copyright 2016 Rohm Semiconductor
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-*/
-#include "../../rohm-sensor-hal/rohm-sensor-hal/rohm_hal.h"         //types, DEBUG_print*
-#include "../../rohm-sensor-hal/rohm-sensor-hal/I2CCommon.h"        //read_register, write_register, change_bits
-
-#include "../rohm-rpr0521/rpr0521.h"      //RPR0521_* register definitions
-#include "../rohm-rpr0521/rpr0521_driver.h"
-#define SAD 0x38
-
-
-/* rpr0521 driver*/
-
-uint8_t rpr0521_readId(){
-  uint8_t id;
-  uint8_t read_bytes;
-
-  read_bytes = read_register(SAD, RPR0521_MANUFACT, &id, 1);
-  if ( read_bytes > 0 ){
-    DEBUG_printf("Manufacturer: %u\n\r", id);
-    return(id);
-    }
-  else{
-    DEBUG_print("Manufacturer read failed.\n\r");
-    return 255;
-    }
-}
-
-void rpr0521_wait_until_found(){
-  uint8_t id;
-
-  id = rpr0521_readId();
-  while (id == 255){
-    wait(100);
-    id = rpr0521_readId();
-    }
-  return;
-  }
-
-void rpr0521_soft_reset(){
-    write_register(SAD, RPR0521_SYSTEM_CONTROL, RPR0521_SYSTEM_CONTROL_SW_RESET_START);
-}
-
-void rpr0521_clear_interrupt(){
-    write_register(SAD, RPR0521_SYSTEM_CONTROL, RPR0521_SYSTEM_CONTROL_INT_PIN_HI_Z);
-}
-
-void rpr0521_initial_setup(){
-    write_register(SAD, RPR0521_ALS_PS_CONTROL,
-        (RPR0521_ALS_PS_CONTROL_ALS_DATA0_GAIN_X1 | 
-         RPR0521_ALS_PS_CONTROL_ALS_DATA1_GAIN_X1 | 
-         RPR0521_ALS_PS_CONTROL_LED_CURRENT_25MA)
-        );
-    write_register(SAD, RPR0521_PS_CONTROL,
-        (RPR0521_PS_CONTROL_PS_GAIN_X1 |
-         RPR0521_PS_CONTROL_PERSISTENCE_DRDY )
-        );
-    write_register(SAD, RPR0521_MODE_CONTROL,
-        (RPR0521_MODE_CONTROL_ALS_EN_TRUE | RPR0521_MODE_CONTROL_PS_EN_TRUE |
-         RPR0521_MODE_CONTROL_PS_PULSE_200US | RPR0521_MODE_CONTROL_PS_OPERATING_MODE_NORMAL |
-         RPR0521_MODE_CONTROL_MEASUREMENT_TIME_100MS_100MS)
-        );
-}
-
-/* input param: data16, pointer to 3*16bit memory 
-   return: error, true/false */
-bool rpr0521_read_data(uint16_t* data16){
-    uint8_t data[6];
-    uint8_t read_bytes;
-
-    read_bytes = read_register(SAD, RPR0521_PS_DATA_LSBS, &data[0], 6);
-    if (read_bytes == 6){
-        data16[0] = (data[0]) | (data[1] << 8); //ps_data
-        data16[1] = (data[2]) | (data[3] << 8); //als_data0
-        data16[2] = (data[4]) | (data[5] << 8); //als_data1
-        return false;
-        }
-    else{
-        DEBUG_printf("Read error. Read %d bytes\n\r", read_bytes);
-        return true;
-        }
-   
-    }