Starting library to get the SI1143 Gesture Sensor to work. Currently only works in forced conversion mode.

Dependents:   Gesture_Sensor Gesture_Arm_Robot mbed_gesture Gesture_Sensor_Sample ... more

Committer:
GAT27
Date:
Thu Oct 17 22:03:54 2013 +0000
Revision:
3:cb3e8160f18e
Parent:
2:21381f11a5af
Child:
4:af8f820733e0
class definitions

Who changed what in which revision?

UserRevisionLine numberNew 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 3:cb3e8160f18e 36 /**
GAT27 3:cb3e8160f18e 37 * Includes
GAT27 3:cb3e8160f18e 38 */
GAT27 3:cb3e8160f18e 39
GAT27 0:18ebb7348150 40 #include "mbed.h"
GAT27 0:18ebb7348150 41
GAT27 3:cb3e8160f18e 42 /**
GAT27 3:cb3e8160f18e 43 * Defines
GAT27 3:cb3e8160f18e 44 */
GAT27 3:cb3e8160f18e 45
GAT27 1:28beeb2f209b 46 #define IR_ADDRESS 0x5A
GAT27 1:28beeb2f209b 47 #define HW_KEY_VAL0 0x17 //Value to write into the HW Key register
GAT27 1:28beeb2f209b 48
GAT27 1:28beeb2f209b 49 // Register Addresses
GAT27 0:18ebb7348150 50
GAT27 1:28beeb2f209b 51 #define PART_ID 0x00
GAT27 1:28beeb2f209b 52 #define REV_ID 0x01
GAT27 1:28beeb2f209b 53 #define SEQ_ID 0x02 //Si114x-A11 (MAJOR_SEQ=1, MINOR_SEQ=1)
GAT27 1:28beeb2f209b 54 #define INT_CFG 0x03
GAT27 1:28beeb2f209b 55 #define IRQ_ENABLE 0x04
GAT27 1:28beeb2f209b 56 #define IRQ_MODE1 0x05
GAT27 1:28beeb2f209b 57 #define IRQ_MODE2 0x06
GAT27 1:28beeb2f209b 58 #define HW_KEY 0x07
GAT27 0:18ebb7348150 59
GAT27 1:28beeb2f209b 60 #define MEAS_RATE 0x08
GAT27 1:28beeb2f209b 61 #define ALS_RATE 0x09
GAT27 1:28beeb2f209b 62 #define PS_RATE 0x0A
GAT27 0:18ebb7348150 63
GAT27 1:28beeb2f209b 64 #define ALS_LOW_TH0 0x0B
GAT27 1:28beeb2f209b 65 #define ALS_LOW_TH1 0x0C
GAT27 1:28beeb2f209b 66 #define ALS_HI_TH0 0x0D
GAT27 1:28beeb2f209b 67 #define ALS_HI_TH1 0x0E
GAT27 0:18ebb7348150 68
GAT27 1:28beeb2f209b 69 #define PS_LED21 0x0F
GAT27 1:28beeb2f209b 70 #define PS_LED3 0x10
GAT27 0:18ebb7348150 71
GAT27 1:28beeb2f209b 72 #define PS1_TH0 0x11
GAT27 1:28beeb2f209b 73 #define PS1_TH1 0x12
GAT27 1:28beeb2f209b 74 #define PS2_TH0 0x13
GAT27 1:28beeb2f209b 75 #define PS2_TH1 0x14
GAT27 1:28beeb2f209b 76 #define PS3_TH0 0x15
GAT27 1:28beeb2f209b 77
GAT27 1:28beeb2f209b 78 #define PS3_TH1 0x16
GAT27 1:28beeb2f209b 79 #define PARAM_WR 0x17
GAT27 1:28beeb2f209b 80 #define COMMAND 0x18
GAT27 0:18ebb7348150 81
GAT27 1:28beeb2f209b 82 #define RESPONSE 0x20
GAT27 1:28beeb2f209b 83 #define IRQ_STATUS 0x21
GAT27 0:18ebb7348150 84
GAT27 1:28beeb2f209b 85 #define ALS_VIS_DATA0 0x22
GAT27 1:28beeb2f209b 86 #define ALS_VIS_DATA1 0x23
GAT27 1:28beeb2f209b 87 #define ALS_IR_DATA0 0x24
GAT27 1:28beeb2f209b 88 #define ALS_IR_DATA1 0x25
GAT27 0:18ebb7348150 89
GAT27 1:28beeb2f209b 90 #define PS1_DATA0 0x26
GAT27 1:28beeb2f209b 91 #define PS1_DATA1 0x27
GAT27 1:28beeb2f209b 92 #define PS2_DATA0 0x28
GAT27 1:28beeb2f209b 93 #define PS2_DATA1 0x29
GAT27 1:28beeb2f209b 94 #define PS3_DATA0 0x2A
GAT27 1:28beeb2f209b 95 #define PS3_DATA1 0x2B
GAT27 0:18ebb7348150 96
GAT27 0:18ebb7348150 97
GAT27 1:28beeb2f209b 98 #define AUX_DATA0 0x2C
GAT27 1:28beeb2f209b 99 #define AUX_DATA1 0x2D
GAT27 0:18ebb7348150 100
GAT27 1:28beeb2f209b 101 #define PARAM_RD 0x2E
GAT27 1:28beeb2f209b 102 #define CHIP_STAT 0x30
GAT27 1:28beeb2f209b 103 #define ANA_IN_KEY 0x3B
GAT27 0:18ebb7348150 104
GAT27 0:18ebb7348150 105 // Command Register Values
GAT27 0:18ebb7348150 106
GAT27 1:28beeb2f209b 107 #define PARAM_QUERY 0x80 //Value is ORed with Parameter Offset
GAT27 1:28beeb2f209b 108 #define PARAM_SET 0xA0 //Value is ORed with Parameter Offset
GAT27 1:28beeb2f209b 109 #define PARAM_AND 0xC0 //Value is ORed with Parameter Offset
GAT27 1:28beeb2f209b 110 #define PARAM_OR 0xE0 //Value is ORed with Parameter Offset
GAT27 1:28beeb2f209b 111 #define NOP 0x00
GAT27 1:28beeb2f209b 112 #define RESET 0x01
GAT27 1:28beeb2f209b 113 #define BUSADDR 0x02
GAT27 1:28beeb2f209b 114 #define PS_FORCE 0x05
GAT27 1:28beeb2f209b 115 #define ALS_FORCE 0x06
GAT27 1:28beeb2f209b 116 #define PSALS_FORCE 0x07
GAT27 1:28beeb2f209b 117 #define PS_PAUSE 0x09
GAT27 1:28beeb2f209b 118 #define ALS_PAUSE 0x0A
GAT27 1:28beeb2f209b 119 #define PSALS_PAUSE 0x0B
GAT27 1:28beeb2f209b 120 #define PS_AUTO 0x0D
GAT27 1:28beeb2f209b 121 #define ALS_AUTO 0x0E
GAT27 1:28beeb2f209b 122 #define PSALS_AUTO 0x0F
GAT27 0:18ebb7348150 123
GAT27 1:28beeb2f209b 124 // Ram Addresses
GAT27 0:18ebb7348150 125
GAT27 1:28beeb2f209b 126 #define I2C_ADDR 0x00
GAT27 1:28beeb2f209b 127 #define CHLIST 0x01
GAT27 1:28beeb2f209b 128 #define PSLED12_SELECT 0x02
GAT27 1:28beeb2f209b 129 #define PSLED3_SELECT 0x03
GAT27 1:28beeb2f209b 130 #define FILTER_EN 0x04
GAT27 1:28beeb2f209b 131 #define PS_ENCODING 0x05
GAT27 1:28beeb2f209b 132 #define ALS_ENCODING 0x06
GAT27 1:28beeb2f209b 133 #define PS1_ADCMUX 0x07
GAT27 1:28beeb2f209b 134 #define PS2_ADCMUX 0x08
GAT27 1:28beeb2f209b 135 #define PS3_ADCMUX 0x09
GAT27 1:28beeb2f209b 136 #define PS_ADC_COUNTER 0x0A
GAT27 1:28beeb2f209b 137 #define PS_ADC_GAIN 0x0B
GAT27 1:28beeb2f209b 138 #define PS_ADC_MISC 0x0C
GAT27 1:28beeb2f209b 139 #define ALS1_ADCMUX 0x0D
GAT27 1:28beeb2f209b 140 #define ALS2_ADCMUX 0x0E
GAT27 1:28beeb2f209b 141 #define ALS3_ADCMUX 0x0F
GAT27 1:28beeb2f209b 142 #define ALS_VIS_ADC_COUNTER 0x10
GAT27 1:28beeb2f209b 143 #define ALS_VIS_ADC_GAIN 0x11
GAT27 1:28beeb2f209b 144 #define ALS_VIS_ADC_MISC 0x12
GAT27 1:28beeb2f209b 145 #define ALS_HYST 0x16
GAT27 1:28beeb2f209b 146 #define PS_HYST 0x17
GAT27 1:28beeb2f209b 147 #define PS_HISTORY 0x18
GAT27 1:28beeb2f209b 148 #define ALS_HISTORY 0x19
GAT27 1:28beeb2f209b 149 #define ADC_OFFSET 0x1A
GAT27 1:28beeb2f209b 150 #define SLEEP_CTRL 0x1B
GAT27 1:28beeb2f209b 151 #define LED_REC 0x1C
GAT27 1:28beeb2f209b 152 #define ALS_IR_ADC_COUNTER 0x1D
GAT27 1:28beeb2f209b 153 #define ALS_IR_ADC_GAIN 0x1E
GAT27 1:28beeb2f209b 154 #define ALS_IR_ADC_MISC 0x1F
GAT27 0:18ebb7348150 155
GAT27 1:28beeb2f209b 156 // Measurement Channel List
GAT27 3:cb3e8160f18e 157
GAT27 1:28beeb2f209b 158 #define PS1_TASK 0x01
GAT27 1:28beeb2f209b 159 #define PS2_TASK 0x02
GAT27 1:28beeb2f209b 160 #define PS3_TASK 0x04
GAT27 1:28beeb2f209b 161 #define ALS_VIS_TASK 0x10
GAT27 1:28beeb2f209b 162 #define ALS_IR_TASK 0x20
GAT27 1:28beeb2f209b 163 #define AUX_TASK 0x40
GAT27 0:18ebb7348150 164
GAT27 3:cb3e8160f18e 165 /**
GAT27 3:cb3e8160f18e 166 * Parallax SI1143 Gesture Sensor.
GAT27 3:cb3e8160f18e 167 */
GAT27 0:18ebb7348150 168 class SI1143
GAT27 0:18ebb7348150 169 {
GAT27 0:18ebb7348150 170 public:
GAT27 0:18ebb7348150 171
GAT27 3:cb3e8160f18e 172 /**
GAT27 3:cb3e8160f18e 173 * Constructor.
GAT27 3:cb3e8160f18e 174 *
GAT27 3:cb3e8160f18e 175 * @param sda mbed pin to use for SDA line of I2C interface.
GAT27 3:cb3e8160f18e 176 * @param scl mbed pin to use for SCL line of I2C interface.
GAT27 3:cb3e8160f18e 177 */
GAT27 0:18ebb7348150 178 SI1143(PinName sda, PinName scl);
GAT27 0:18ebb7348150 179
GAT27 3:cb3e8160f18e 180 /**
GAT27 3:cb3e8160f18e 181 * Sample the device and return a result.
GAT27 3:cb3e8160f18e 182 *
GAT27 3:cb3e8160f18e 183 * @param A value of 1 will output led1
GAT27 3:cb3e8160f18e 184 * A value of 2 will output led2
GAT27 3:cb3e8160f18e 185 * A value of 3 will output led3
GAT27 3:cb3e8160f18e 186 * A value of 4 will output ambient light
GAT27 3:cb3e8160f18e 187 * A value of 5 will output infrared light
GAT27 3:cb3e8160f18e 188 * A value of anything else will output 0
GAT27 3:cb3e8160f18e 189 * @return In forced conversion output mode, will display the raw output minus any baseline
GAT27 3:cb3e8160f18e 190 */
GAT27 0:18ebb7348150 191 int sample(int point);
GAT27 0:18ebb7348150 192
GAT27 3:cb3e8160f18e 193 /**
GAT27 3:cb3e8160f18e 194 * Creates a baseline for sampling measurements.
GAT27 3:cb3e8160f18e 195 */
GAT27 0:18ebb7348150 196 void bias(void);
GAT27 0:18ebb7348150 197
GAT27 0:18ebb7348150 198 private:
GAT27 0:18ebb7348150 199
GAT27 0:18ebb7348150 200 I2C* i2c_;
GAT27 0:18ebb7348150 201 int bias1,bias2,bias3,PS1,PS2,PS3,VIS,IR;
GAT27 0:18ebb7348150 202 char LowB,HighB;
GAT27 0:18ebb7348150 203
GAT27 3:cb3e8160f18e 204 /**
GAT27 3:cb3e8160f18e 205 * Wait for the device to respond, then send it a specific command.
GAT27 3:cb3e8160f18e 206 */
GAT27 0:18ebb7348150 207 void command(char cmd);
GAT27 0:18ebb7348150 208
GAT27 3:cb3e8160f18e 209 /**
GAT27 3:cb3e8160f18e 210 * Read a register from the device.
GAT27 3:cb3e8160f18e 211 */
GAT27 3:cb3e8160f18e 212 char read_reg(/*unsigned*/ char address, int num_data);
GAT27 0:18ebb7348150 213
GAT27 3:cb3e8160f18e 214 /**
GAT27 3:cb3e8160f18e 215 * Write to a register on the device.
GAT27 3:cb3e8160f18e 216 */
GAT27 3:cb3e8160f18e 217 void write_reg(char address, char num_data);
GAT27 0:18ebb7348150 218
GAT27 0:18ebb7348150 219 };
GAT27 0:18ebb7348150 220
GAT27 0:18ebb7348150 221 #endif