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

Committer:
MikkoZ
Date:
Wed Sep 14 07:04:40 2016 +0000
Revision:
2:2b4a1b49998d
Parent:
1:64629eee9eab
Added stricter part id checks to prevent SAD collision go unnoticed. Same SADs are used in RPR0521(0x38) and BH1726(0x39).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikkoZ 0:0bcc203c5c75 1 /* Copyright 2016 Rohm Semiconductor
MikkoZ 0:0bcc203c5c75 2
MikkoZ 0:0bcc203c5c75 3 Licensed under the Apache License, Version 2.0 (the "License");
MikkoZ 0:0bcc203c5c75 4 you may not use this file except in compliance with the License.
MikkoZ 0:0bcc203c5c75 5 You may obtain a copy of the License at
MikkoZ 0:0bcc203c5c75 6
MikkoZ 0:0bcc203c5c75 7 http://www.apache.org/licenses/LICENSE-2.0
MikkoZ 0:0bcc203c5c75 8
MikkoZ 0:0bcc203c5c75 9 Unless required by applicable law or agreed to in writing, software
MikkoZ 0:0bcc203c5c75 10 distributed under the License is distributed on an "AS IS" BASIS,
MikkoZ 0:0bcc203c5c75 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikkoZ 0:0bcc203c5c75 12 See the License for the specific language governing permissions and
MikkoZ 0:0bcc203c5c75 13 limitations under the License.
MikkoZ 0:0bcc203c5c75 14 */
MikkoZ 1:64629eee9eab 15 #ifndef BH1745_H
MikkoZ 1:64629eee9eab 16 #define BH1745_H
MikkoZ 0:0bcc203c5c75 17
MikkoZ 0:0bcc203c5c75 18 /* registers */
MikkoZ 1:64629eee9eab 19 #define BH1745_REGISTER_DUMP_START 0x40
MikkoZ 1:64629eee9eab 20 #define BH1745_SYSTEM_CONTROL 0x40
MikkoZ 1:64629eee9eab 21 // Writing MODE_CONTROL1/2/3 restarts measurement if any.
MikkoZ 1:64629eee9eab 22 #define BH1745_MODE_CONTROL1 0x41
MikkoZ 1:64629eee9eab 23 #define BH1745_MODE_CONTROL2 0x42
MikkoZ 1:64629eee9eab 24 // Always write 02h
MikkoZ 1:64629eee9eab 25 #define BH1745_MODE_CONTROL3 0x44
MikkoZ 1:64629eee9eab 26 // Least significant byte of uint16 RED measurement value
MikkoZ 1:64629eee9eab 27 #define BH1745_RED_DATA_LSBS 0x50
MikkoZ 1:64629eee9eab 28 // Most significant byte of uint16 RED measurement value
MikkoZ 1:64629eee9eab 29 #define BH1745_RED_DATA_MSBS 0x51
MikkoZ 1:64629eee9eab 30 #define BH1745_GREEN_DATA_LSBS 0x52
MikkoZ 1:64629eee9eab 31 #define BH1745_GREEN_DATA_MSBS 0x53
MikkoZ 1:64629eee9eab 32 #define BH1745_BLUE_DATA_LSBS 0x54
MikkoZ 1:64629eee9eab 33 #define BH1745_BLUE_DATA_MSBS 0x55
MikkoZ 1:64629eee9eab 34 #define BH1745_CLEAR_DATA_LSBS 0x56
MikkoZ 1:64629eee9eab 35 #define BH1745_CLEAR_DATA_MSBS 0x57
MikkoZ 1:64629eee9eab 36 // DINT data is used for internal calculation of BH1745NUC.
MikkoZ 1:64629eee9eab 37 #define BH1745_DINT_DATA_LSBS 0x58
MikkoZ 1:64629eee9eab 38 // DINT registers are used for IC test only.
MikkoZ 1:64629eee9eab 39 #define BH1745_DINT_DATA_MSBS 0x59
MikkoZ 1:64629eee9eab 40 #define BH1745_INTERRUPT 0x60
MikkoZ 1:64629eee9eab 41 #define BH1745_PERSISTENCE 0x61
MikkoZ 1:64629eee9eab 42 #define BH1745_TH_LSBS 0x62
MikkoZ 1:64629eee9eab 43 #define BH1745_TH_MSBS 0x63
MikkoZ 1:64629eee9eab 44 #define BH1745_TL_LSBS 0x64
MikkoZ 1:64629eee9eab 45 #define BH1745_TL_MSBS 0x65
MikkoZ 1:64629eee9eab 46 #define BH1745_ID_REG 0x92
MikkoZ 1:64629eee9eab 47 #define BH1745_REGISTER_DUMP_END 0x92
MikkoZ 0:0bcc203c5c75 48 /* registers bits */
MikkoZ 1:64629eee9eab 49 // Initial reset is not started
MikkoZ 1:64629eee9eab 50 #define BH1745_SYSTEM_CONTROL_SW_RESET_NOT_STARTED (0x00 << 7)
MikkoZ 1:64629eee9eab 51 // Initial reset is started
MikkoZ 1:64629eee9eab 52 #define BH1745_SYSTEM_CONTROL_SW_RESET_START (0x01 << 7)
MikkoZ 1:64629eee9eab 53 // In specification "not_initialized"
MikkoZ 1:64629eee9eab 54 #define BH1745_SYSTEM_CONTROL_INT_PIN_ACTIVE (0x00 << 6)
MikkoZ 1:64629eee9eab 55 // high impedance
MikkoZ 1:64629eee9eab 56 #define BH1745_SYSTEM_CONTROL_INT_PIN_INACTIVE (0x01 << 6)
MikkoZ 1:64629eee9eab 57 #define BH1745_SYSTEM_CONTROL_PART_ID (0x0B << 0)
MikkoZ 1:64629eee9eab 58 #define BH1745_MODE_CONTROL1_RESERVED_WRITE00000 (0x00 << 3)
MikkoZ 1:64629eee9eab 59 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_160MSEC (0x00 << 0)
MikkoZ 1:64629eee9eab 60 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_320MSEC (0x01 << 0)
MikkoZ 1:64629eee9eab 61 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_640MSEC (0x02 << 0)
MikkoZ 1:64629eee9eab 62 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_1280MSEC (0x03 << 0)
MikkoZ 1:64629eee9eab 63 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_2560MSEC (0x04 << 0)
MikkoZ 1:64629eee9eab 64 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_5120MSEC (0x05 << 0)
MikkoZ 1:64629eee9eab 65 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_FORBIDDEN6 (0x06 << 0)
MikkoZ 1:64629eee9eab 66 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_FORBIDDEN7 (0x07 << 0)
MikkoZ 1:64629eee9eab 67 #define BH1745_MODE_CONTROL2_DATA_UPDATED_NO (0x00 << 7)
MikkoZ 1:64629eee9eab 68 #define BH1745_MODE_CONTROL2_DATA_UPDATED_YES (0x01 << 7)
MikkoZ 1:64629eee9eab 69 #define BH1745_MODE_CONTROL2_RESERVED65_WRITE00 (0x00 << 5)
MikkoZ 1:64629eee9eab 70 #define BH1745_MODE_CONTROL2_RGBC_MEASUREMENT_INACTIVE (0x00 << 4)
MikkoZ 1:64629eee9eab 71 #define BH1745_MODE_CONTROL2_RGBC_MEASUREMENT_ACTIVE (0x01 << 4)
MikkoZ 1:64629eee9eab 72 #define BH1745_MODE_CONTROL2_RESERVED32_WRITE00 (0x00 << 2)
MikkoZ 1:64629eee9eab 73 #define BH1745_MODE_CONTROL2_ADC_GAIN_1X (0x00 << 0)
MikkoZ 1:64629eee9eab 74 #define BH1745_MODE_CONTROL2_ADC_GAIN_2X (0x01 << 0)
MikkoZ 1:64629eee9eab 75 #define BH1745_MODE_CONTROL2_ADC_GAIN_16X (0x02 << 0)
MikkoZ 1:64629eee9eab 76 #define BH1745_MODE_CONTROL2_ADC_GAIN_FORBIDDEN3 (0x03 << 0)
MikkoZ 1:64629eee9eab 77 #define BH1745_MODE_CONTROL3_ALWAYS_02H (0x02 << 0)
MikkoZ 1:64629eee9eab 78 #define BH1745_INTERRUPT_STATUS_INACTIVE (0x00 << 7)
MikkoZ 1:64629eee9eab 79 #define BH1745_INTERRUPT_STATUS_ACTIVE (0x01 << 7)
MikkoZ 1:64629eee9eab 80 #define BH1745_INTERRUPT_RESERVED65_WRITE00 (0x00 << 5)
MikkoZ 1:64629eee9eab 81 // INT pin is latched until INTERRUPT register is read or initialized
MikkoZ 1:64629eee9eab 82 #define BH1745_INTERRUPT_LATCH_ENABLE (0x00 << 4)
MikkoZ 1:64629eee9eab 83 // INT pin is updated after each measurement
MikkoZ 1:64629eee9eab 84 #define BH1745_INTERRUPT_LATCH_DISABLE (0x01 << 4)
MikkoZ 1:64629eee9eab 85 // red channel
MikkoZ 1:64629eee9eab 86 #define BH1745_INTERRUPT_SOURCE_SELECT_RED (0x00 << 2)
MikkoZ 1:64629eee9eab 87 // green channel
MikkoZ 1:64629eee9eab 88 #define BH1745_INTERRUPT_SOURCE_SELECT_GREEN (0x01 << 2)
MikkoZ 1:64629eee9eab 89 // blue channel
MikkoZ 1:64629eee9eab 90 #define BH1745_INTERRUPT_SOURCE_SELECT_BLUE (0x02 << 2)
MikkoZ 1:64629eee9eab 91 // clear channel
MikkoZ 1:64629eee9eab 92 #define BH1745_INTERRUPT_SOURCE_SELECT_CLEAR (0x03 << 2)
MikkoZ 1:64629eee9eab 93 #define BH1745_INTERRUPT_RESERVED1_WRITE0 (0x00 << 1)
MikkoZ 1:64629eee9eab 94 #define BH1745_INTERRUPT_PIN_DISABLE (0x00 << 0)
MikkoZ 1:64629eee9eab 95 #define BH1745_INTERRUPT_PIN_ENABLE (0x01 << 0)
MikkoZ 1:64629eee9eab 96 #define BH1745_PERSISTENCE_RESERVED72_WRITE000001 (0x01 << 2)
MikkoZ 1:64629eee9eab 97 // Interrupt status is toggled at each measurement end.
MikkoZ 1:64629eee9eab 98 #define BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_TOGGLE_AFTER_MEASUREMENT (0x00 << 0)
MikkoZ 1:64629eee9eab 99 // Interrupt status is updated at each measurement end.
MikkoZ 1:64629eee9eab 100 #define BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_UPDATE_AFTER_MEASUREMENT (0x01 << 0)
MikkoZ 1:64629eee9eab 101 // Interrupt status is updated if 4 consecutive threshold judgements are the same
MikkoZ 1:64629eee9eab 102 #define BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_UPDATE_AFTER_4_SAME (0x02 << 0)
MikkoZ 1:64629eee9eab 103 // Interrupt status is updated if 8 consecutive threshold judgements are the same
MikkoZ 1:64629eee9eab 104 #define BH1745_PERSISTENCE_OF_INTERRUPT_STATUS_UPDATE_AFTER_8_SAME (0x03 << 0)
MikkoZ 1:64629eee9eab 105 #define BH1745_ID_REG_MANUFACTURER_ID (0xE0 << 0)
MikkoZ 0:0bcc203c5c75 106 /*registers bit masks */
MikkoZ 1:64629eee9eab 107 #define BH1745_SYSTEM_CONTROL_SW_RESET_MASK 0x80
MikkoZ 1:64629eee9eab 108
MikkoZ 1:64629eee9eab 109 #define BH1745_SYSTEM_CONTROL_INT_PIN_MASK 0x40
MikkoZ 0:0bcc203c5c75 110
MikkoZ 1:64629eee9eab 111 #define BH1745_SYSTEM_CONTROL_PART_MASK 0x3F
MikkoZ 1:64629eee9eab 112 #define BH1745_MODE_CONTROL1_RESERVED_MASK 0xF8
MikkoZ 1:64629eee9eab 113 #define BH1745_MODE_CONTROL1_MEASUREMENT_TIME_MASK 0x07
MikkoZ 1:64629eee9eab 114 #define BH1745_MODE_CONTROL2_DATA_UPDATED_MASK 0x80
MikkoZ 1:64629eee9eab 115 #define BH1745_MODE_CONTROL2_RESERVED65_MASK 0x60
MikkoZ 1:64629eee9eab 116 #define BH1745_MODE_CONTROL2_RGBC_MEASUREMENT_MASK 0x10
MikkoZ 1:64629eee9eab 117 #define BH1745_MODE_CONTROL2_RESERVED32_MASK 0x0C
MikkoZ 1:64629eee9eab 118 #define BH1745_MODE_CONTROL2_ADC_GAIN_MASK 0x03
MikkoZ 1:64629eee9eab 119 #define BH1745_MODE_CONTROL3_ALWAYS_MASK 0xFF
MikkoZ 1:64629eee9eab 120 #define BH1745_INTERRUPT_STATUS_MASK 0x80
MikkoZ 1:64629eee9eab 121 #define BH1745_INTERRUPT_RESERVED65_MASK 0x60
MikkoZ 1:64629eee9eab 122 #define BH1745_INTERRUPT_LATCH_MASK 0x10
MikkoZ 0:0bcc203c5c75 123
MikkoZ 1:64629eee9eab 124 #define BH1745_INTERRUPT_SOURCE_MASK 0x0C
MikkoZ 1:64629eee9eab 125 // Write 0
MikkoZ 1:64629eee9eab 126 #define BH1745_INTERRUPT_RESERVED1_MASK 0x02
MikkoZ 1:64629eee9eab 127 #define BH1745_INTERRUPT_PIN_MASK 0x01
MikkoZ 1:64629eee9eab 128 #define BH1745_PERSISTENCE_RESERVED72_MASK 0xFC
MikkoZ 1:64629eee9eab 129 #define BH1745_PERSISTENCE_OF_INTERRUPT_MASK 0x03
MikkoZ 1:64629eee9eab 130
MikkoZ 1:64629eee9eab 131 #define BH1745_ID_REG_MANUFACTURER_MASK 0xFF
MikkoZ 1:64629eee9eab 132
MikkoZ 1:64629eee9eab 133 #endif /* BH1745_H */