48 #define PRINTFDEBUG(...) printf(__VA_ARGS__)
50 #define PRINTFDEBUG(...)
54 enum TSL2563_STATUSTYPES {
61 static enum TSL2563_STATUSTYPES _TSL2563_STATUS = 0x00;
64 calculateLux(uint16_t *buffer)
66 uint32_t ch0, ch1 = 0;
67 uint32_t aux = (1 << 14);
68 uint32_t ratio, lratio, tmp = 0;
70 ch0 = (buffer[0] * aux) >> 10;
71 ch1 = (buffer[1] * aux) >> 10;
73 PRINTFDEBUG(
"B0 %u, B1 %u\n", buffer[0], buffer[1]);
74 PRINTFDEBUG(
"ch0 %lu, ch1 %lu\n", ch0, ch1);
78 lratio = (ratio + 1) >> 1;
80 PRINTFDEBUG(
"ratio %lu, lratio %lu\n", ratio, lratio);
82 if((lratio >= 0) && (lratio <= K1T)) {
83 tmp = (ch0 * B1T) - (ch1 * M1T);
84 }
else if(lratio <= K2T) {
85 tmp = (ch0 * B2T) - (ch1 * M2T);
86 }
else if(lratio <= K3T) {
87 tmp = (ch0 * B3T) - (ch1 * M3T);
88 }
else if(lratio <= K4T) {
89 tmp = (ch0 * B4T) - (ch1 * M4T);
90 }
else if(lratio <= K5T) {
91 tmp = (ch0 * B5T) - (ch1 * M5T);
92 }
else if(lratio <= K6T) {
93 tmp = (ch0 * B6T) - (ch1 * M6T);
94 }
else if(lratio <= K7T) {
95 tmp = (ch0 * B7T) - (ch1 * M7T);
96 }
else if(lratio > K8T) {
97 tmp = (ch0 * B8T) - (ch1 * M8T);
106 PRINTFDEBUG(
"tmp %lu\n", tmp);
115 light_ziglet_init(
void)
117 if(!(_TSL2563_STATUS & INITED)) {
118 PRINTFDEBUG(
"light ziglet init\n");
119 _TSL2563_STATUS |= INITED;
134 tsl2563_write_reg(uint8_t reg, uint16_t val)
136 uint8_t tx_buf[] = { reg, 0x00, 0x00 };
138 tx_buf[1] = (uint8_t)(val >> 8);
139 tx_buf[2] = (uint8_t)(val & 0x00FF);
141 i2c_transmitinit(TSL2563_ADDR);
143 PRINTFDEBUG(
"I2C Ready to TX\n");
145 i2c_transmit_n(3, tx_buf);
147 PRINTFDEBUG(
"WRITE_REG 0x%04X @ reg 0x%02X\n", val, reg);
157 tsl2563_read_reg(uint8_t reg)
159 uint16_t readBuf[] = { 0x00, 0x00 };
160 uint8_t buf[] = { 0x00, 0x00, 0x00, 0x00 };
165 i2c_transmitinit(TSL2563_ADDR);
167 i2c_transmit_n(1, &rtx);
171 i2c_receiveinit(TSL2563_ADDR);
173 i2c_receive_n(4, buf);
176 PRINTFDEBUG(
"\nb0 %u, b1 %u, b2 %u, b3 %u\n", buf[0], buf[1], buf[2], buf[3]);
178 readBuf[0] = (buf[1] << 8 | (buf[0]));
179 readBuf[1] = (buf[3] << 8 | (buf[2]));
181 retVal = calculateLux(readBuf);
185 light_ziglet_on(
void)
188 uint8_t regon = TSL2563_PWRN;
190 i2c_transmitinit(TSL2563_ADDR);
192 i2c_transmit_n(1, ®on);
194 data = (uint16_t)tsl2563_read_reg(TSL2563_READ);
198 light_ziglet_off(
void)
200 uint8_t regoff = 0x00;
202 i2c_transmitinit(TSL2563_ADDR);
204 i2c_transmit_n(1, ®off);
213 light_ziglet_read(
void)
216 lux = light_ziglet_on();
void i2c_enable(void)
Configure serial controller in I2C mode and set I2C speed.
Device drivers header file for light ziglet sensor in Zolertia Z1 WSN Platform.
I2C communication device driver header file for Zolertia Z1 sensor node.