i2c RGBW led driver push/pull or opendrain output

Fork of PCA9633 by Mederic Melard

Files at this revision

API Documentation at this revision

Comitter:
mederic
Date:
Mon Jun 25 07:55:37 2018 +0000
Parent:
1:f95d80e0f84a
Child:
3:abc759c7c7bb
Commit message:
invert openDrain option; make config method to dont touch DMBLNK bit

Changed in this revision

PCA9633.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/PCA9633.cpp	Thu Jun 21 07:28:23 2018 +0000
+++ b/PCA9633.cpp	Mon Jun 25 07:55:37 2018 +0000
@@ -37,9 +37,13 @@
     config(invert, openDrain);
 }
 
-void PCA9633::config(bool invert, bool openDrain){
-    char buf[2] = {PCA9633_REG_MODE2,0};
-    buf[1] = (invert<<PCA9633_BIT_INVRT ) | (openDrain<<PCA9633_BIT_OUTDRV);
+void PCA9633::config(bool invert, bool openDrain){    
+    char buf[3] = {PCA9633_REG_MODE2,0,0};
+    _i2c->write(_addr,buf,1);          //cmd to read mode2 
+    _i2c->read(_addr, &buf[1],1);      //stock in buf[1]
+    
+    buf[1] &= ~((1<<PCA9633_BIT_INVRT)|(1<<PCA9633_BIT_OUTDRV));
+    buf[1] |= ((invert<<PCA9633_BIT_INVRT )|((!openDrain)<<PCA9633_BIT_OUTDRV));
     _i2c->write(_addr,buf,2);
 }