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
SI1143.h@1:28beeb2f209b, 2013-10-17 (annotated)
- Committer:
- GAT27
- Date:
- Thu Oct 17 20:52:40 2013 +0000
- Revision:
- 1:28beeb2f209b
- Parent:
- 0:18ebb7348150
- Child:
- 2:21381f11a5af
working, shows all 3 led in forced mode
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GAT27 | 0:18ebb7348150 | 1 | #ifndef SI1143_h |
GAT27 | 0:18ebb7348150 | 2 | #define SI1143_h |
GAT27 | 0:18ebb7348150 | 3 | |
GAT27 | 0:18ebb7348150 | 4 | #include "mbed.h" |
GAT27 | 0:18ebb7348150 | 5 | |
GAT27 | 1:28beeb2f209b | 6 | #define IR_ADDRESS 0x5A |
GAT27 | 1:28beeb2f209b | 7 | #define HW_KEY_VAL0 0x17 //Value to write into the HW Key register |
GAT27 | 1:28beeb2f209b | 8 | |
GAT27 | 1:28beeb2f209b | 9 | // Register Addresses |
GAT27 | 0:18ebb7348150 | 10 | |
GAT27 | 1:28beeb2f209b | 11 | #define PART_ID 0x00 |
GAT27 | 1:28beeb2f209b | 12 | #define REV_ID 0x01 |
GAT27 | 1:28beeb2f209b | 13 | #define SEQ_ID 0x02 //Si114x-A11 (MAJOR_SEQ=1, MINOR_SEQ=1) |
GAT27 | 1:28beeb2f209b | 14 | #define INT_CFG 0x03 |
GAT27 | 1:28beeb2f209b | 15 | #define IRQ_ENABLE 0x04 |
GAT27 | 1:28beeb2f209b | 16 | #define IRQ_MODE1 0x05 |
GAT27 | 1:28beeb2f209b | 17 | #define IRQ_MODE2 0x06 |
GAT27 | 1:28beeb2f209b | 18 | #define HW_KEY 0x07 |
GAT27 | 0:18ebb7348150 | 19 | |
GAT27 | 1:28beeb2f209b | 20 | #define MEAS_RATE 0x08 |
GAT27 | 1:28beeb2f209b | 21 | #define ALS_RATE 0x09 |
GAT27 | 1:28beeb2f209b | 22 | #define PS_RATE 0x0A |
GAT27 | 0:18ebb7348150 | 23 | |
GAT27 | 1:28beeb2f209b | 24 | #define ALS_LOW_TH0 0x0B |
GAT27 | 1:28beeb2f209b | 25 | #define ALS_LOW_TH1 0x0C |
GAT27 | 1:28beeb2f209b | 26 | #define ALS_HI_TH0 0x0D |
GAT27 | 1:28beeb2f209b | 27 | #define ALS_HI_TH1 0x0E |
GAT27 | 0:18ebb7348150 | 28 | |
GAT27 | 1:28beeb2f209b | 29 | #define PS_LED21 0x0F |
GAT27 | 1:28beeb2f209b | 30 | #define PS_LED3 0x10 |
GAT27 | 0:18ebb7348150 | 31 | |
GAT27 | 1:28beeb2f209b | 32 | #define PS1_TH0 0x11 |
GAT27 | 1:28beeb2f209b | 33 | #define PS1_TH1 0x12 |
GAT27 | 1:28beeb2f209b | 34 | #define PS2_TH0 0x13 |
GAT27 | 1:28beeb2f209b | 35 | #define PS2_TH1 0x14 |
GAT27 | 1:28beeb2f209b | 36 | #define PS3_TH0 0x15 |
GAT27 | 1:28beeb2f209b | 37 | |
GAT27 | 1:28beeb2f209b | 38 | #define PS3_TH1 0x16 |
GAT27 | 1:28beeb2f209b | 39 | #define PARAM_WR 0x17 |
GAT27 | 1:28beeb2f209b | 40 | #define COMMAND 0x18 |
GAT27 | 0:18ebb7348150 | 41 | |
GAT27 | 1:28beeb2f209b | 42 | #define RESPONSE 0x20 |
GAT27 | 1:28beeb2f209b | 43 | #define IRQ_STATUS 0x21 |
GAT27 | 0:18ebb7348150 | 44 | |
GAT27 | 1:28beeb2f209b | 45 | #define ALS_VIS_DATA0 0x22 |
GAT27 | 1:28beeb2f209b | 46 | #define ALS_VIS_DATA1 0x23 |
GAT27 | 1:28beeb2f209b | 47 | #define ALS_IR_DATA0 0x24 |
GAT27 | 1:28beeb2f209b | 48 | #define ALS_IR_DATA1 0x25 |
GAT27 | 0:18ebb7348150 | 49 | |
GAT27 | 1:28beeb2f209b | 50 | #define PS1_DATA0 0x26 |
GAT27 | 1:28beeb2f209b | 51 | #define PS1_DATA1 0x27 |
GAT27 | 1:28beeb2f209b | 52 | #define PS2_DATA0 0x28 |
GAT27 | 1:28beeb2f209b | 53 | #define PS2_DATA1 0x29 |
GAT27 | 1:28beeb2f209b | 54 | #define PS3_DATA0 0x2A |
GAT27 | 1:28beeb2f209b | 55 | #define PS3_DATA1 0x2B |
GAT27 | 0:18ebb7348150 | 56 | |
GAT27 | 0:18ebb7348150 | 57 | |
GAT27 | 1:28beeb2f209b | 58 | #define AUX_DATA0 0x2C |
GAT27 | 1:28beeb2f209b | 59 | #define AUX_DATA1 0x2D |
GAT27 | 0:18ebb7348150 | 60 | |
GAT27 | 1:28beeb2f209b | 61 | #define PARAM_RD 0x2E |
GAT27 | 1:28beeb2f209b | 62 | #define CHIP_STAT 0x30 |
GAT27 | 1:28beeb2f209b | 63 | #define ANA_IN_KEY 0x3B |
GAT27 | 0:18ebb7348150 | 64 | |
GAT27 | 0:18ebb7348150 | 65 | // Command Register Values |
GAT27 | 0:18ebb7348150 | 66 | |
GAT27 | 1:28beeb2f209b | 67 | #define PARAM_QUERY 0x80 //Value is ORed with Parameter Offset |
GAT27 | 1:28beeb2f209b | 68 | #define PARAM_SET 0xA0 //Value is ORed with Parameter Offset |
GAT27 | 1:28beeb2f209b | 69 | #define PARAM_AND 0xC0 //Value is ORed with Parameter Offset |
GAT27 | 1:28beeb2f209b | 70 | #define PARAM_OR 0xE0 //Value is ORed with Parameter Offset |
GAT27 | 1:28beeb2f209b | 71 | #define NOP 0x00 |
GAT27 | 1:28beeb2f209b | 72 | #define RESET 0x01 |
GAT27 | 1:28beeb2f209b | 73 | #define BUSADDR 0x02 |
GAT27 | 1:28beeb2f209b | 74 | #define PS_FORCE 0x05 |
GAT27 | 1:28beeb2f209b | 75 | #define ALS_FORCE 0x06 |
GAT27 | 1:28beeb2f209b | 76 | #define PSALS_FORCE 0x07 |
GAT27 | 1:28beeb2f209b | 77 | #define PS_PAUSE 0x09 |
GAT27 | 1:28beeb2f209b | 78 | #define ALS_PAUSE 0x0A |
GAT27 | 1:28beeb2f209b | 79 | #define PSALS_PAUSE 0x0B |
GAT27 | 1:28beeb2f209b | 80 | #define PS_AUTO 0x0D |
GAT27 | 1:28beeb2f209b | 81 | #define ALS_AUTO 0x0E |
GAT27 | 1:28beeb2f209b | 82 | #define PSALS_AUTO 0x0F |
GAT27 | 0:18ebb7348150 | 83 | |
GAT27 | 1:28beeb2f209b | 84 | // Ram Addresses |
GAT27 | 0:18ebb7348150 | 85 | |
GAT27 | 1:28beeb2f209b | 86 | #define I2C_ADDR 0x00 |
GAT27 | 1:28beeb2f209b | 87 | #define CHLIST 0x01 |
GAT27 | 1:28beeb2f209b | 88 | #define PSLED12_SELECT 0x02 |
GAT27 | 1:28beeb2f209b | 89 | #define PSLED3_SELECT 0x03 |
GAT27 | 1:28beeb2f209b | 90 | #define FILTER_EN 0x04 |
GAT27 | 1:28beeb2f209b | 91 | #define PS_ENCODING 0x05 |
GAT27 | 1:28beeb2f209b | 92 | #define ALS_ENCODING 0x06 |
GAT27 | 1:28beeb2f209b | 93 | #define PS1_ADCMUX 0x07 |
GAT27 | 1:28beeb2f209b | 94 | #define PS2_ADCMUX 0x08 |
GAT27 | 1:28beeb2f209b | 95 | #define PS3_ADCMUX 0x09 |
GAT27 | 1:28beeb2f209b | 96 | #define PS_ADC_COUNTER 0x0A |
GAT27 | 1:28beeb2f209b | 97 | #define PS_ADC_GAIN 0x0B |
GAT27 | 1:28beeb2f209b | 98 | #define PS_ADC_MISC 0x0C |
GAT27 | 1:28beeb2f209b | 99 | #define ALS1_ADCMUX 0x0D |
GAT27 | 1:28beeb2f209b | 100 | #define ALS2_ADCMUX 0x0E |
GAT27 | 1:28beeb2f209b | 101 | #define ALS3_ADCMUX 0x0F |
GAT27 | 1:28beeb2f209b | 102 | #define ALS_VIS_ADC_COUNTER 0x10 |
GAT27 | 1:28beeb2f209b | 103 | #define ALS_VIS_ADC_GAIN 0x11 |
GAT27 | 1:28beeb2f209b | 104 | #define ALS_VIS_ADC_MISC 0x12 |
GAT27 | 1:28beeb2f209b | 105 | #define ALS_HYST 0x16 |
GAT27 | 1:28beeb2f209b | 106 | #define PS_HYST 0x17 |
GAT27 | 1:28beeb2f209b | 107 | #define PS_HISTORY 0x18 |
GAT27 | 1:28beeb2f209b | 108 | #define ALS_HISTORY 0x19 |
GAT27 | 1:28beeb2f209b | 109 | #define ADC_OFFSET 0x1A |
GAT27 | 1:28beeb2f209b | 110 | #define SLEEP_CTRL 0x1B |
GAT27 | 1:28beeb2f209b | 111 | #define LED_REC 0x1C |
GAT27 | 1:28beeb2f209b | 112 | #define ALS_IR_ADC_COUNTER 0x1D |
GAT27 | 1:28beeb2f209b | 113 | #define ALS_IR_ADC_GAIN 0x1E |
GAT27 | 1:28beeb2f209b | 114 | #define ALS_IR_ADC_MISC 0x1F |
GAT27 | 0:18ebb7348150 | 115 | |
GAT27 | 1:28beeb2f209b | 116 | // Measurement Channel List |
GAT27 | 1:28beeb2f209b | 117 | #define PS1_TASK 0x01 |
GAT27 | 1:28beeb2f209b | 118 | #define PS2_TASK 0x02 |
GAT27 | 1:28beeb2f209b | 119 | #define PS3_TASK 0x04 |
GAT27 | 1:28beeb2f209b | 120 | #define ALS_VIS_TASK 0x10 |
GAT27 | 1:28beeb2f209b | 121 | #define ALS_IR_TASK 0x20 |
GAT27 | 1:28beeb2f209b | 122 | #define AUX_TASK 0x40 |
GAT27 | 0:18ebb7348150 | 123 | |
GAT27 | 0:18ebb7348150 | 124 | class SI1143 |
GAT27 | 0:18ebb7348150 | 125 | { |
GAT27 | 0:18ebb7348150 | 126 | public: |
GAT27 | 0:18ebb7348150 | 127 | |
GAT27 | 0:18ebb7348150 | 128 | SI1143(PinName sda, PinName scl); |
GAT27 | 0:18ebb7348150 | 129 | |
GAT27 | 0:18ebb7348150 | 130 | int sample(int point); |
GAT27 | 0:18ebb7348150 | 131 | |
GAT27 | 0:18ebb7348150 | 132 | void bias(void); |
GAT27 | 0:18ebb7348150 | 133 | |
GAT27 | 0:18ebb7348150 | 134 | private: |
GAT27 | 0:18ebb7348150 | 135 | |
GAT27 | 0:18ebb7348150 | 136 | I2C* i2c_; |
GAT27 | 0:18ebb7348150 | 137 | int bias1,bias2,bias3,PS1,PS2,PS3,VIS,IR; |
GAT27 | 0:18ebb7348150 | 138 | char LowB,HighB; |
GAT27 | 0:18ebb7348150 | 139 | |
GAT27 | 0:18ebb7348150 | 140 | void command(char cmd); |
GAT27 | 0:18ebb7348150 | 141 | |
GAT27 | 0:18ebb7348150 | 142 | char read_reg(/*unsigned*/ char address, int num_data); // Read a Register |
GAT27 | 0:18ebb7348150 | 143 | |
GAT27 | 0:18ebb7348150 | 144 | void write_reg(char address, char num_data);// Write a resigter |
GAT27 | 0:18ebb7348150 | 145 | |
GAT27 | 0:18ebb7348150 | 146 | }; |
GAT27 | 0:18ebb7348150 | 147 | |
GAT27 | 0:18ebb7348150 | 148 | #endif |