MAX44000 Ambient and Infrared Proximity Sensor
Dependents: test_MAX44000 testSensor PMK2022_Agriculture
MAX44000.h@2:93ed4e2fe7fd, 2016-07-07 (annotated)
- Committer:
- Rhyme
- Date:
- Thu Jul 07 03:57:36 2016 +0000
- Revision:
- 2:93ed4e2fe7fd
- Parent:
- 1:e3d11ab4c524
Some document descriptions added about registers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 2:93ed4e2fe7fd | 1 | /** MAX44000 Ambient and Infrared Proximity Sensor |
Rhyme | 0:c9c9e362ec57 | 2 | * I2C 7bit address: 0x4A |
Rhyme | 0:c9c9e362ec57 | 3 | * |
Rhyme | 0:c9c9e362ec57 | 4 | */ |
Rhyme | 0:c9c9e362ec57 | 5 | |
Rhyme | 0:c9c9e362ec57 | 6 | #ifndef _MAX44000_H_ |
Rhyme | 0:c9c9e362ec57 | 7 | #define _MAX44000_H_ |
Rhyme | 0:c9c9e362ec57 | 8 | |
Rhyme | 0:c9c9e362ec57 | 9 | #include "mbed.h" |
Rhyme | 0:c9c9e362ec57 | 10 | |
Rhyme | 2:93ed4e2fe7fd | 11 | /** @code |
Rhyme | 2:93ed4e2fe7fd | 12 | * Registers |
Rhyme | 2:93ed4e2fe7fd | 13 | * addr : R/W : Rst : Register |
Rhyme | 2:93ed4e2fe7fd | 14 | * 0x00 : R : 0x04 : Interrupt Status |
Rhyme | 2:93ed4e2fe7fd | 15 | * 0x01 : R/W : 0x24 : Main Configuration |
Rhyme | 2:93ed4e2fe7fd | 16 | * 0x02 : R/W : 0x00 : Receive Configuration |
Rhyme | 2:93ed4e2fe7fd | 17 | * 0x03 : R/W : 0x00 : Transmit Configuration |
Rhyme | 2:93ed4e2fe7fd | 18 | * 0x04 : R : 0x00 : ADC High Byte (ALS) |
Rhyme | 2:93ed4e2fe7fd | 19 | * 0x05 : R : 0x00 : ADC Low Byte (ALS) |
Rhyme | 2:93ed4e2fe7fd | 20 | * 0x16 : R : 0x00 : ADC Byte (PROX) |
Rhyme | 2:93ed4e2fe7fd | 21 | * 0x06 : R/W : 0x00 : ALS Upper Threshold (High Byte) |
Rhyme | 2:93ed4e2fe7fd | 22 | * 0x07 : R/W : 0x00 : ALS Upper Threshold (Low Byte) |
Rhyme | 2:93ed4e2fe7fd | 23 | * 0x08 : R/W : 0x00 : ALS Lower Threshold (High Byte) |
Rhyme | 2:93ed4e2fe7fd | 24 | * 0x09 : R/W : 0x00 : ALS Lower Threshold (Low Byte) |
Rhyme | 2:93ed4e2fe7fd | 25 | * 0x0A : R/W : 0x00 : Threshold Persist Timer |
Rhyme | 2:93ed4e2fe7fd | 26 | * 0x0B : R/W : 0x00 : PROX Threshold Indicator |
Rhyme | 2:93ed4e2fe7fd | 27 | * 0x0C : R/W : 0x00 : PROX Threshold |
Rhyme | 2:93ed4e2fe7fd | 28 | * 0x0F : R/W : 0x80 : Digital Gain Trim of Green Channel |
Rhyme | 2:93ed4e2fe7fd | 29 | * 0x10 : R/W : 0x80 : Digital Gain Trim of Infrared Channel |
Rhyme | 2:93ed4e2fe7fd | 30 | * |
Rhyme | 2:93ed4e2fe7fd | 31 | * 0x00 : R : 0x04 : Interrupt Status |
Rhyme | 2:93ed4e2fe7fd | 32 | * Bit[7:3] : (reserved) |
Rhyme | 2:93ed4e2fe7fd | 33 | * Bit[2] : PWRON : if set, indicates that a power-on-reset (POR) condition has occurred, |
Rhyme | 2:93ed4e2fe7fd | 34 | * and any user-programmed thresholds cannot be valid anymore. |
Rhyme | 2:93ed4e2fe7fd | 35 | * Bit[1] : PRXINTS : indicates that an ambient light nterrupt condition occurred. |
Rhyme | 2:93ed4e2fe7fd | 36 | * BIt[0] : ALSINTS : indicates that a proximity receive interrupt condition occurred. |
Rhyme | 0:c9c9e362ec57 | 37 | * |
Rhyme | 2:93ed4e2fe7fd | 38 | * 0x01 : R/W : 0x24 : Main Configuration |
Rhyme | 1:e3d11ab4c524 | 39 | * Bit[7:6] : (reserved) |
Rhyme | 1:e3d11ab4c524 | 40 | * Bit[5] : TRIM |
Rhyme | 1:e3d11ab4c524 | 41 | * 0: Use bytes written to TRIM_GAIN_GREEN[7:0] and TRIM_GAIN_IR[7:0] registers |
Rhyme | 1:e3d11ab4c524 | 42 | * to set the fine-trim gain of the green and IR gain channels. |
Rhyme | 1:e3d11ab4c524 | 43 | * 1: Use factory-programmed gains for green and IR channels. |
Rhyme | 1:e3d11ab4c524 | 44 | * Ignore bytes written to TRIM_GAIN_GEEN[7:0] and TRIM_GAIN_IR[7:0] registers. |
Rhyme | 1:e3d11ab4c524 | 45 | * Bit[4:2] : mode |
Rhyme | 1:e3d11ab4c524 | 46 | * 000: Shutdown : Analog circuits are shut down, but the digital register retains values. |
Rhyme | 1:e3d11ab4c524 | 47 | * 001: ALS G-IR : Standard ALS mode stores the difference between green and infrared channel readings. |
Rhyme | 1:e3d11ab4c524 | 48 | * Proximity channel operation and updates are disabled. |
Rhyme | 1:e3d11ab4c524 | 49 | * 010: ALS G : ALS green channel only. Proximity channel operation and updates are disabled. |
Rhyme | 1:e3d11ab4c524 | 50 | * 011: ALS IR : Infrared channel only. Proximity channel operation and updates are disabled. |
Rhyme | 1:e3d11ab4c524 | 51 | * 100: ALS/PROX : ALS and PROX are interleaved continuously. |
Rhyme | 1:e3d11ab4c524 | 52 | * 101: PROX Only : PROX only continuously. ALS channel operation and updates are disabled. |
Rhyme | 1:e3d11ab4c524 | 53 | * 110: (reserved) |
Rhyme | 1:e3d11ab4c524 | 54 | * 111: (reserved) |
Rhyme | 2:93ed4e2fe7fd | 55 | * Bit[1] : PRXINTE : |
Rhyme | 2:93ed4e2fe7fd | 56 | * 0 : The PRXINTS bit remains unasserted, and proximity channel readings |
Rhyme | 2:93ed4e2fe7fd | 57 | * are not compared with interrupt thresholds. |
Rhyme | 2:93ed4e2fe7fd | 58 | * 1 : Detection of a proxmity interrupt event triggers a hardware interrupt (/INT pin is pulled low) |
Rhyme | 2:93ed4e2fe7fd | 59 | * and sets the PRXINTS bit (register 0x00, B1). Proximity channel readings are compared with |
Rhyme | 2:93ed4e2fe7fd | 60 | * proximity interrupt threshold settings and proximity persist timer. |
Rhyme | 1:e3d11ab4c524 | 61 | * Bit[0] : ALSINTE |
Rhyme | 2:93ed4e2fe7fd | 62 | * 0 : The ALSINTS bit reamins unasserted, and ALS channel readings are not compared with interrupt thresholds. |
Rhyme | 2:93ed4e2fe7fd | 63 | * 1 : Detection of an ambient light interrupt event triggers a hardware interrupt (/INT pin is pullued low) |
Rhyme | 2:93ed4e2fe7fd | 64 | * and sets the ALSINTS bit (register 0x00, B0). ALS channel readings are compared with ALS interrupt |
Rhyme | 2:93ed4e2fe7fd | 65 | * threshold settings and ALS persist timer. |
Rhyme | 2:93ed4e2fe7fd | 66 | * |
Rhyme | 2:93ed4e2fe7fd | 67 | * 0x02 : R/W : 0x00 : Receive Configuration |
Rhyme | 2:93ed4e2fe7fd | 68 | * Bit[7:4] : (reserved) |
Rhyme | 2:93ed4e2fe7fd | 69 | * Bit[3:2] : ALSTIM : Ambient ADC Conversion Time |
Rhyme | 2:93ed4e2fe7fd | 70 | * | Intergration Time (ms) | Full-Scale ADC counts | Bit Resolution | Relative LSB Size | |
Rhyme | 2:93ed4e2fe7fd | 71 | * 00 | 100 | 16,384 | 14 | 1x | |
Rhyme | 2:93ed4e2fe7fd | 72 | * 01 | 25 | 4,096 | 12 | 4x | |
Rhyme | 2:93ed4e2fe7fd | 73 | * 10 | 6.25 | 1,024 | 10 | 16x | |
Rhyme | 2:93ed4e2fe7fd | 74 | * 11 | 1.5625 | 256 | 8 | 64x | |
Rhyme | 2:93ed4e2fe7fd | 75 | * Bit[1:0] : ALSPGA : Ambient Light Measurement Gain |
Rhyme | 2:93ed4e2fe7fd | 76 | * | LUX/LSB | Relative LSB Size | |
Rhyme | 2:93ed4e2fe7fd | 77 | * 00 | 0.03125 | 1x | |
Rhyme | 2:93ed4e2fe7fd | 78 | * 01 | 0.125 | 4x | |
Rhyme | 2:93ed4e2fe7fd | 79 | * 10 | 0.5 | 16x | |
Rhyme | 2:93ed4e2fe7fd | 80 | * 11 | 4 | 128x | |
Rhyme | 2:93ed4e2fe7fd | 81 | * |
Rhyme | 2:93ed4e2fe7fd | 82 | * 0x03 | R/W | 0x00 | Transmit Configuration |
Rhyme | 2:93ed4e2fe7fd | 83 | * 0x04 | R | 0x00 | ADC High Byte (ALS) |
Rhyme | 2:93ed4e2fe7fd | 84 | * 0x05 | R | 0x00 | ADC Low Byte (ALS) |
Rhyme | 2:93ed4e2fe7fd | 85 | * 0x16 | R | 0x00 | ADC Byte (PROX) |
Rhyme | 2:93ed4e2fe7fd | 86 | @endcode |
Rhyme | 2:93ed4e2fe7fd | 87 | */ |
Rhyme | 2:93ed4e2fe7fd | 88 | |
Rhyme | 2:93ed4e2fe7fd | 89 | |
Rhyme | 2:93ed4e2fe7fd | 90 | |
Rhyme | 2:93ed4e2fe7fd | 91 | class MAX44000 |
Rhyme | 2:93ed4e2fe7fd | 92 | { |
Rhyme | 2:93ed4e2fe7fd | 93 | public: |
Rhyme | 2:93ed4e2fe7fd | 94 | /** |
Rhyme | 2:93ed4e2fe7fd | 95 | * constructor |
Rhyme | 2:93ed4e2fe7fd | 96 | * |
Rhyme | 2:93ed4e2fe7fd | 97 | * @param sda SDA pin |
Rhyme | 2:93ed4e2fe7fd | 98 | * @param scl SCL pin |
Rhyme | 2:93ed4e2fe7fd | 99 | * @param addr address of the I2C peripheral |
Rhyme | 2:93ed4e2fe7fd | 100 | */ |
Rhyme | 2:93ed4e2fe7fd | 101 | MAX44000(PinName sda, PinName scl, int addr) ; |
Rhyme | 2:93ed4e2fe7fd | 102 | |
Rhyme | 2:93ed4e2fe7fd | 103 | /** |
Rhyme | 2:93ed4e2fe7fd | 104 | * destructor |
Rhyme | 2:93ed4e2fe7fd | 105 | */ |
Rhyme | 2:93ed4e2fe7fd | 106 | ~MAX44000() ; |
Rhyme | 2:93ed4e2fe7fd | 107 | |
Rhyme | 2:93ed4e2fe7fd | 108 | /* |
Rhyme | 2:93ed4e2fe7fd | 109 | * some member functions here (yet to be written) |
Rhyme | 2:93ed4e2fe7fd | 110 | */ |
Rhyme | 2:93ed4e2fe7fd | 111 | |
Rhyme | 2:93ed4e2fe7fd | 112 | /** |
Rhyme | 2:93ed4e2fe7fd | 113 | * Get Interrupt Status |
Rhyme | 2:93ed4e2fe7fd | 114 | * @param uint8_t *data pointer to receive the 8bit register value. |
Rhyme | 2:93ed4e2fe7fd | 115 | */ |
Rhyme | 2:93ed4e2fe7fd | 116 | void getIntStatus(uint8_t *data) ; |
Rhyme | 2:93ed4e2fe7fd | 117 | /** |
Rhyme | 2:93ed4e2fe7fd | 118 | * Get Main Configuration |
Rhyme | 2:93ed4e2fe7fd | 119 | * @param uint8_t *conf pointer to receive the 8bit register value. |
Rhyme | 1:e3d11ab4c524 | 120 | */ |
Rhyme | 0:c9c9e362ec57 | 121 | void getMainConfig(uint8_t *conf) ; |
Rhyme | 1:e3d11ab4c524 | 122 | /** |
Rhyme | 1:e3d11ab4c524 | 123 | * Set Mein Configuration |
Rhyme | 1:e3d11ab4c524 | 124 | * @param conf uint8_t to specify the 8bit register value. |
Rhyme | 1:e3d11ab4c524 | 125 | */ |
Rhyme | 0:c9c9e362ec57 | 126 | void setMainConfig(uint8_t newConf) ; |
Rhyme | 0:c9c9e362ec57 | 127 | void getRxConfig(uint8_t *conf) ; |
Rhyme | 0:c9c9e362ec57 | 128 | void setRxConfig(uint8_t newConf) ; |
Rhyme | 0:c9c9e362ec57 | 129 | void getTxConfig(uint8_t *conf) ; |
Rhyme | 0:c9c9e362ec57 | 130 | void setTxConfig(uint8_t newConf) ; |
Rhyme | 2:93ed4e2fe7fd | 131 | /** |
Rhyme | 2:93ed4e2fe7fd | 132 | * Get ALS |
Rhyme | 2:93ed4e2fe7fd | 133 | * |
Rhyme | 2:93ed4e2fe7fd | 134 | * @param uint8_t *ofl overflow indicator |
Rhyme | 2:93ed4e2fe7fd | 135 | * @param uint16_t *value ALS value |
Rhyme | 2:93ed4e2fe7fd | 136 | */ |
Rhyme | 0:c9c9e362ec57 | 137 | void getALS(uint8_t *ofl, uint16_t *value) ; |
Rhyme | 2:93ed4e2fe7fd | 138 | /** |
Rhyme | 2:93ed4e2fe7fd | 139 | * Get PROX |
Rhyme | 2:93ed4e2fe7fd | 140 | * |
Rhyme | 2:93ed4e2fe7fd | 141 | * @param uint8_t *value PROX value |
Rhyme | 2:93ed4e2fe7fd | 142 | */ |
Rhyme | 0:c9c9e362ec57 | 143 | void getProx(uint8_t *value) ; |
Rhyme | 2:93ed4e2fe7fd | 144 | /** |
Rhyme | 2:93ed4e2fe7fd | 145 | * Get ADC value(s) |
Rhyme | 2:93ed4e2fe7fd | 146 | * |
Rhyme | 2:93ed4e2fe7fd | 147 | * @param uint8_t *ofl overfolow indicator |
Rhyme | 2:93ed4e2fe7fd | 148 | * @param uint16_t *als ALS data |
Rhyme | 2:93ed4e2fe7fd | 149 | * @param uint8_t *prox PROX data |
Rhyme | 2:93ed4e2fe7fd | 150 | */ |
Rhyme | 0:c9c9e362ec57 | 151 | void getADC(uint8_t *ofl, uint16_t *als, uint8_t *prox) ; |
Rhyme | 0:c9c9e362ec57 | 152 | void getUPTHR(uint16_t *thr) ; |
Rhyme | 0:c9c9e362ec57 | 153 | void setUPTHR(uint16_t newThr) ; |
Rhyme | 0:c9c9e362ec57 | 154 | void getLOTHR(uint16_t *thr) ; |
Rhyme | 0:c9c9e362ec57 | 155 | void setLOTHR(uint16_t newThr) ; |
Rhyme | 0:c9c9e362ec57 | 156 | void getTHRPT(uint8_t *data) ; |
Rhyme | 0:c9c9e362ec57 | 157 | void setTHRPT(uint8_t newData) ; |
Rhyme | 0:c9c9e362ec57 | 158 | void getPRXTHR_IND(uint8_t *value) ; |
Rhyme | 0:c9c9e362ec57 | 159 | void setPRXTHR_IND(uint8_t newValue) ; |
Rhyme | 0:c9c9e362ec57 | 160 | void getPRX_THR(uint8_t *data) ; |
Rhyme | 0:c9c9e362ec57 | 161 | void setPRX_THR(uint8_t newValue) ; |
Rhyme | 0:c9c9e362ec57 | 162 | void getTRM_GAING(uint8_t *data) ; |
Rhyme | 0:c9c9e362ec57 | 163 | void setTRM_GAING(uint8_t newValue) ; |
Rhyme | 0:c9c9e362ec57 | 164 | void getTRM_GAINIR(uint8_t *data) ; |
Rhyme | 0:c9c9e362ec57 | 165 | void setTRM_GAINIR(uint8_t newValue) ; |
Rhyme | 0:c9c9e362ec57 | 166 | |
Rhyme | 0:c9c9e362ec57 | 167 | private: |
Rhyme | 0:c9c9e362ec57 | 168 | I2C m_i2c; |
Rhyme | 0:c9c9e362ec57 | 169 | int m_addr; |
Rhyme | 0:c9c9e362ec57 | 170 | void readRegs(int addr, uint8_t *data, int len) ; |
Rhyme | 0:c9c9e362ec57 | 171 | void writeRegs(uint8_t *data, int len) ; |
Rhyme | 0:c9c9e362ec57 | 172 | } ; |
Rhyme | 0:c9c9e362ec57 | 173 | #endif /* _MAX44000_H_ */ |