Class module for ISL29011 Ambient Light Sensor

Dependents:   mDotEVBM2X MTDOT-EVBDemo-DRH MTDOT-BOX-EVB-Factory-Firmware-LIB-108 MTDOT-UDKDemo_Senet ... more

Files at this revision

API Documentation at this revision

Comitter:
Evan Hosseini
Date:
Wed Jan 31 09:58:22 2018 -0600
Parent:
4:c1d5f4999b9e
Commit message:
Make driver thread safe by making i2c read transactions atomic

Changed in this revision

ISL29011.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c1d5f4999b9e -r 953adca17438 ISL29011.cpp
--- a/ISL29011.cpp	Thu Oct 06 14:35:26 2016 +0000
+++ b/ISL29011.cpp	Wed Jan 31 09:58:22 2018 -0600
@@ -39,8 +39,6 @@
 {
     uint8_t result = 0;
 
-    _i2c->frequency(400000);
-
     // Reset all registers to POR values
     result = ISL29011::writeRegister(COMMAND1, 0x00);
 
@@ -56,7 +54,7 @@
         result = ISL29011::writeRegister(INT_HT_MSB, 0xFF);
     }
 
-    if(result != 0) {
+    if (result != 0) {
         debug("ILS29011:init failed\n\r");
     }
 
@@ -103,7 +101,6 @@
     char datain[1];
     char dataout;
 
-
     result |= ISL29011::readRegister(COMMAND1,datain);
     dataout = (datain[0] & 0xFC) | int_persist;
     result |= ISL29011::writeRegister(COMMAND1, dataout);
@@ -120,7 +117,6 @@
     char datain[1];
     char dataout;
 
-
     result |= ISL29011::readRegister(COMMAND2,datain);
     dataout = (datain[0] & 0x0F) | prox_scheme | mod_freq | led_drive;
     result |= ISL29011::writeRegister(COMMAND2, dataout);
@@ -137,7 +133,6 @@
     char datain[1];
     char dataout;
 
-
     result |= ISL29011::readRegister(COMMAND2,datain);
     dataout = (datain[0] & 0xF3) | adc_resolution;
     result |= ISL29011::writeRegister(COMMAND2, dataout);
@@ -154,7 +149,6 @@
     char datain[1];
     char dataout;
 
-
     result |= ISL29011::readRegister(COMMAND2,datain);
     dataout = (datain[0] & 0xFC) | lux_range;
     result |= ISL29011::writeRegister(COMMAND2, dataout);
@@ -173,8 +167,8 @@
 
     result |= _i2c->write(_i2c_addr, buf, 2);
 
-    if(result != 0) {
-        debug("ISL29011:writeRegister failed\n\r");
+    if (result != 0) {
+        debug("ISL29011::writeRegister failed\n\r");
     }
 
     return result;
@@ -186,20 +180,21 @@
     char reg_out[1];
 
     reg_out[0] = reg;
+    _i2c->lock();
     result |= _i2c->write(_i2c_addr,reg_out,1,true);
 
-    if(result != 0) {
+    if (result != 0) {
         debug("ISL29011::readRegister failed write\n\r");
-        return result;
+        goto exit;
     }
 
     result |= _i2c->read(_i2c_addr,data,count,false);
 
-    if(result != 0) {
+    if (result != 0) {
         debug("ISL29011::readRegister failed read\n\r");
     }
 
+exit:
+    _i2c->unlock();
     return result;
 }
-
-