Library for using SI1141 sensor
Fork of SI1143 by
SI1143.h@2:21381f11a5af, 2013-10-17 (annotated)
- Committer:
- GAT27
- Date:
- Thu Oct 17 21:03:01 2013 +0000
- Revision:
- 2:21381f11a5af
- Parent:
- 1:28beeb2f209b
- Child:
- 3:cb3e8160f18e
license
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GAT27 | 2:21381f11a5af | 1 | /** |
GAT27 | 2:21381f11a5af | 2 | * @author Guillermo A Torijano |
GAT27 | 2:21381f11a5af | 3 | * |
GAT27 | 2:21381f11a5af | 4 | * @section LICENSE |
GAT27 | 2:21381f11a5af | 5 | * |
GAT27 | 2:21381f11a5af | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
GAT27 | 2:21381f11a5af | 7 | * of this software and associated documentation files (the "Software"), to deal |
GAT27 | 2:21381f11a5af | 8 | * in the Software without restriction, including without limitation the rights |
GAT27 | 2:21381f11a5af | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
GAT27 | 2:21381f11a5af | 10 | * copies of the Software, and to permit persons to whom the Software is |
GAT27 | 2:21381f11a5af | 11 | * furnished to do so, subject to the following conditions: |
GAT27 | 2:21381f11a5af | 12 | * |
GAT27 | 2:21381f11a5af | 13 | * The above copyright notice and this permission notice shall be included in |
GAT27 | 2:21381f11a5af | 14 | * all copies or substantial portions of the Software. |
GAT27 | 2:21381f11a5af | 15 | * |
GAT27 | 2:21381f11a5af | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
GAT27 | 2:21381f11a5af | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
GAT27 | 2:21381f11a5af | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
GAT27 | 2:21381f11a5af | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
GAT27 | 2:21381f11a5af | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
GAT27 | 2:21381f11a5af | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
GAT27 | 2:21381f11a5af | 22 | * THE SOFTWARE. |
GAT27 | 2:21381f11a5af | 23 | * |
GAT27 | 2:21381f11a5af | 24 | * @section DESCRIPTION |
GAT27 | 2:21381f11a5af | 25 | * |
GAT27 | 2:21381f11a5af | 26 | * Parallax SI1143 Gesture Sensor. |
GAT27 | 2:21381f11a5af | 27 | * |
GAT27 | 2:21381f11a5af | 28 | * Datasheet: |
GAT27 | 2:21381f11a5af | 29 | * |
GAT27 | 2:21381f11a5af | 30 | * http://www.silabs.com/Support%20Documents/TechnicalDocs/Si114x.pdf |
GAT27 | 2:21381f11a5af | 31 | */ |
GAT27 | 2:21381f11a5af | 32 | |
GAT27 | 0:18ebb7348150 | 33 | #ifndef SI1143_h |
GAT27 | 0:18ebb7348150 | 34 | #define SI1143_h |
GAT27 | 0:18ebb7348150 | 35 | |
GAT27 | 0:18ebb7348150 | 36 | #include "mbed.h" |
GAT27 | 0:18ebb7348150 | 37 | |
GAT27 | 1:28beeb2f209b | 38 | #define IR_ADDRESS 0x5A |
GAT27 | 1:28beeb2f209b | 39 | #define HW_KEY_VAL0 0x17 //Value to write into the HW Key register |
GAT27 | 1:28beeb2f209b | 40 | |
GAT27 | 1:28beeb2f209b | 41 | // Register Addresses |
GAT27 | 0:18ebb7348150 | 42 | |
GAT27 | 1:28beeb2f209b | 43 | #define PART_ID 0x00 |
GAT27 | 1:28beeb2f209b | 44 | #define REV_ID 0x01 |
GAT27 | 1:28beeb2f209b | 45 | #define SEQ_ID 0x02 //Si114x-A11 (MAJOR_SEQ=1, MINOR_SEQ=1) |
GAT27 | 1:28beeb2f209b | 46 | #define INT_CFG 0x03 |
GAT27 | 1:28beeb2f209b | 47 | #define IRQ_ENABLE 0x04 |
GAT27 | 1:28beeb2f209b | 48 | #define IRQ_MODE1 0x05 |
GAT27 | 1:28beeb2f209b | 49 | #define IRQ_MODE2 0x06 |
GAT27 | 1:28beeb2f209b | 50 | #define HW_KEY 0x07 |
GAT27 | 0:18ebb7348150 | 51 | |
GAT27 | 1:28beeb2f209b | 52 | #define MEAS_RATE 0x08 |
GAT27 | 1:28beeb2f209b | 53 | #define ALS_RATE 0x09 |
GAT27 | 1:28beeb2f209b | 54 | #define PS_RATE 0x0A |
GAT27 | 0:18ebb7348150 | 55 | |
GAT27 | 1:28beeb2f209b | 56 | #define ALS_LOW_TH0 0x0B |
GAT27 | 1:28beeb2f209b | 57 | #define ALS_LOW_TH1 0x0C |
GAT27 | 1:28beeb2f209b | 58 | #define ALS_HI_TH0 0x0D |
GAT27 | 1:28beeb2f209b | 59 | #define ALS_HI_TH1 0x0E |
GAT27 | 0:18ebb7348150 | 60 | |
GAT27 | 1:28beeb2f209b | 61 | #define PS_LED21 0x0F |
GAT27 | 1:28beeb2f209b | 62 | #define PS_LED3 0x10 |
GAT27 | 0:18ebb7348150 | 63 | |
GAT27 | 1:28beeb2f209b | 64 | #define PS1_TH0 0x11 |
GAT27 | 1:28beeb2f209b | 65 | #define PS1_TH1 0x12 |
GAT27 | 1:28beeb2f209b | 66 | #define PS2_TH0 0x13 |
GAT27 | 1:28beeb2f209b | 67 | #define PS2_TH1 0x14 |
GAT27 | 1:28beeb2f209b | 68 | #define PS3_TH0 0x15 |
GAT27 | 1:28beeb2f209b | 69 | |
GAT27 | 1:28beeb2f209b | 70 | #define PS3_TH1 0x16 |
GAT27 | 1:28beeb2f209b | 71 | #define PARAM_WR 0x17 |
GAT27 | 1:28beeb2f209b | 72 | #define COMMAND 0x18 |
GAT27 | 0:18ebb7348150 | 73 | |
GAT27 | 1:28beeb2f209b | 74 | #define RESPONSE 0x20 |
GAT27 | 1:28beeb2f209b | 75 | #define IRQ_STATUS 0x21 |
GAT27 | 0:18ebb7348150 | 76 | |
GAT27 | 1:28beeb2f209b | 77 | #define ALS_VIS_DATA0 0x22 |
GAT27 | 1:28beeb2f209b | 78 | #define ALS_VIS_DATA1 0x23 |
GAT27 | 1:28beeb2f209b | 79 | #define ALS_IR_DATA0 0x24 |
GAT27 | 1:28beeb2f209b | 80 | #define ALS_IR_DATA1 0x25 |
GAT27 | 0:18ebb7348150 | 81 | |
GAT27 | 1:28beeb2f209b | 82 | #define PS1_DATA0 0x26 |
GAT27 | 1:28beeb2f209b | 83 | #define PS1_DATA1 0x27 |
GAT27 | 1:28beeb2f209b | 84 | #define PS2_DATA0 0x28 |
GAT27 | 1:28beeb2f209b | 85 | #define PS2_DATA1 0x29 |
GAT27 | 1:28beeb2f209b | 86 | #define PS3_DATA0 0x2A |
GAT27 | 1:28beeb2f209b | 87 | #define PS3_DATA1 0x2B |
GAT27 | 0:18ebb7348150 | 88 | |
GAT27 | 0:18ebb7348150 | 89 | |
GAT27 | 1:28beeb2f209b | 90 | #define AUX_DATA0 0x2C |
GAT27 | 1:28beeb2f209b | 91 | #define AUX_DATA1 0x2D |
GAT27 | 0:18ebb7348150 | 92 | |
GAT27 | 1:28beeb2f209b | 93 | #define PARAM_RD 0x2E |
GAT27 | 1:28beeb2f209b | 94 | #define CHIP_STAT 0x30 |
GAT27 | 1:28beeb2f209b | 95 | #define ANA_IN_KEY 0x3B |
GAT27 | 0:18ebb7348150 | 96 | |
GAT27 | 0:18ebb7348150 | 97 | // Command Register Values |
GAT27 | 0:18ebb7348150 | 98 | |
GAT27 | 1:28beeb2f209b | 99 | #define PARAM_QUERY 0x80 //Value is ORed with Parameter Offset |
GAT27 | 1:28beeb2f209b | 100 | #define PARAM_SET 0xA0 //Value is ORed with Parameter Offset |
GAT27 | 1:28beeb2f209b | 101 | #define PARAM_AND 0xC0 //Value is ORed with Parameter Offset |
GAT27 | 1:28beeb2f209b | 102 | #define PARAM_OR 0xE0 //Value is ORed with Parameter Offset |
GAT27 | 1:28beeb2f209b | 103 | #define NOP 0x00 |
GAT27 | 1:28beeb2f209b | 104 | #define RESET 0x01 |
GAT27 | 1:28beeb2f209b | 105 | #define BUSADDR 0x02 |
GAT27 | 1:28beeb2f209b | 106 | #define PS_FORCE 0x05 |
GAT27 | 1:28beeb2f209b | 107 | #define ALS_FORCE 0x06 |
GAT27 | 1:28beeb2f209b | 108 | #define PSALS_FORCE 0x07 |
GAT27 | 1:28beeb2f209b | 109 | #define PS_PAUSE 0x09 |
GAT27 | 1:28beeb2f209b | 110 | #define ALS_PAUSE 0x0A |
GAT27 | 1:28beeb2f209b | 111 | #define PSALS_PAUSE 0x0B |
GAT27 | 1:28beeb2f209b | 112 | #define PS_AUTO 0x0D |
GAT27 | 1:28beeb2f209b | 113 | #define ALS_AUTO 0x0E |
GAT27 | 1:28beeb2f209b | 114 | #define PSALS_AUTO 0x0F |
GAT27 | 0:18ebb7348150 | 115 | |
GAT27 | 1:28beeb2f209b | 116 | // Ram Addresses |
GAT27 | 0:18ebb7348150 | 117 | |
GAT27 | 1:28beeb2f209b | 118 | #define I2C_ADDR 0x00 |
GAT27 | 1:28beeb2f209b | 119 | #define CHLIST 0x01 |
GAT27 | 1:28beeb2f209b | 120 | #define PSLED12_SELECT 0x02 |
GAT27 | 1:28beeb2f209b | 121 | #define PSLED3_SELECT 0x03 |
GAT27 | 1:28beeb2f209b | 122 | #define FILTER_EN 0x04 |
GAT27 | 1:28beeb2f209b | 123 | #define PS_ENCODING 0x05 |
GAT27 | 1:28beeb2f209b | 124 | #define ALS_ENCODING 0x06 |
GAT27 | 1:28beeb2f209b | 125 | #define PS1_ADCMUX 0x07 |
GAT27 | 1:28beeb2f209b | 126 | #define PS2_ADCMUX 0x08 |
GAT27 | 1:28beeb2f209b | 127 | #define PS3_ADCMUX 0x09 |
GAT27 | 1:28beeb2f209b | 128 | #define PS_ADC_COUNTER 0x0A |
GAT27 | 1:28beeb2f209b | 129 | #define PS_ADC_GAIN 0x0B |
GAT27 | 1:28beeb2f209b | 130 | #define PS_ADC_MISC 0x0C |
GAT27 | 1:28beeb2f209b | 131 | #define ALS1_ADCMUX 0x0D |
GAT27 | 1:28beeb2f209b | 132 | #define ALS2_ADCMUX 0x0E |
GAT27 | 1:28beeb2f209b | 133 | #define ALS3_ADCMUX 0x0F |
GAT27 | 1:28beeb2f209b | 134 | #define ALS_VIS_ADC_COUNTER 0x10 |
GAT27 | 1:28beeb2f209b | 135 | #define ALS_VIS_ADC_GAIN 0x11 |
GAT27 | 1:28beeb2f209b | 136 | #define ALS_VIS_ADC_MISC 0x12 |
GAT27 | 1:28beeb2f209b | 137 | #define ALS_HYST 0x16 |
GAT27 | 1:28beeb2f209b | 138 | #define PS_HYST 0x17 |
GAT27 | 1:28beeb2f209b | 139 | #define PS_HISTORY 0x18 |
GAT27 | 1:28beeb2f209b | 140 | #define ALS_HISTORY 0x19 |
GAT27 | 1:28beeb2f209b | 141 | #define ADC_OFFSET 0x1A |
GAT27 | 1:28beeb2f209b | 142 | #define SLEEP_CTRL 0x1B |
GAT27 | 1:28beeb2f209b | 143 | #define LED_REC 0x1C |
GAT27 | 1:28beeb2f209b | 144 | #define ALS_IR_ADC_COUNTER 0x1D |
GAT27 | 1:28beeb2f209b | 145 | #define ALS_IR_ADC_GAIN 0x1E |
GAT27 | 1:28beeb2f209b | 146 | #define ALS_IR_ADC_MISC 0x1F |
GAT27 | 0:18ebb7348150 | 147 | |
GAT27 | 1:28beeb2f209b | 148 | // Measurement Channel List |
GAT27 | 1:28beeb2f209b | 149 | #define PS1_TASK 0x01 |
GAT27 | 1:28beeb2f209b | 150 | #define PS2_TASK 0x02 |
GAT27 | 1:28beeb2f209b | 151 | #define PS3_TASK 0x04 |
GAT27 | 1:28beeb2f209b | 152 | #define ALS_VIS_TASK 0x10 |
GAT27 | 1:28beeb2f209b | 153 | #define ALS_IR_TASK 0x20 |
GAT27 | 1:28beeb2f209b | 154 | #define AUX_TASK 0x40 |
GAT27 | 0:18ebb7348150 | 155 | |
GAT27 | 0:18ebb7348150 | 156 | class SI1143 |
GAT27 | 0:18ebb7348150 | 157 | { |
GAT27 | 0:18ebb7348150 | 158 | public: |
GAT27 | 0:18ebb7348150 | 159 | |
GAT27 | 0:18ebb7348150 | 160 | SI1143(PinName sda, PinName scl); |
GAT27 | 0:18ebb7348150 | 161 | |
GAT27 | 0:18ebb7348150 | 162 | int sample(int point); |
GAT27 | 0:18ebb7348150 | 163 | |
GAT27 | 0:18ebb7348150 | 164 | void bias(void); |
GAT27 | 0:18ebb7348150 | 165 | |
GAT27 | 0:18ebb7348150 | 166 | private: |
GAT27 | 0:18ebb7348150 | 167 | |
GAT27 | 0:18ebb7348150 | 168 | I2C* i2c_; |
GAT27 | 0:18ebb7348150 | 169 | int bias1,bias2,bias3,PS1,PS2,PS3,VIS,IR; |
GAT27 | 0:18ebb7348150 | 170 | char LowB,HighB; |
GAT27 | 0:18ebb7348150 | 171 | |
GAT27 | 0:18ebb7348150 | 172 | void command(char cmd); |
GAT27 | 0:18ebb7348150 | 173 | |
GAT27 | 0:18ebb7348150 | 174 | char read_reg(/*unsigned*/ char address, int num_data); // Read a Register |
GAT27 | 0:18ebb7348150 | 175 | |
GAT27 | 0:18ebb7348150 | 176 | void write_reg(char address, char num_data);// Write a resigter |
GAT27 | 0:18ebb7348150 | 177 | |
GAT27 | 0:18ebb7348150 | 178 | }; |
GAT27 | 0:18ebb7348150 | 179 | |
GAT27 | 0:18ebb7348150 | 180 | #endif |