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