Driver for the IO Expander/LED Driver

Files at this revision

API Documentation at this revision

Comitter:
mwilkens241
Date:
Thu Apr 20 17:55:01 2017 +0000
Parent:
0:c36e6bab0c22
Child:
2:0f4b9539feca
Commit message:
re-wrote a few of the functions, nothing really changed though

Changed in this revision

SX1509.cpp Show annotated file Show diff for this revision Revisions of this file
SX1509.h Show annotated file Show diff for this revision Revisions of this file
--- a/SX1509.cpp	Tue Apr 18 19:49:29 2017 +0000
+++ b/SX1509.cpp	Thu Apr 20 17:55:01 2017 +0000
@@ -75,7 +75,15 @@
 }
 
 void SX1509::setLEDMode(bool mode){
-    enableLEDDriver(div_g,mode);    
+    uint8_t buf = i2cRead8(REGMISC);
+    if(mode==LINEAR){
+        buf &= ~(1<<3);
+        buf &= ~(1<<7);
+    } else {
+        buf |= (1<<3);
+        buf |= (1<<7);
+    }
+    i2cWrite8(REGMISC, buf);
 }
 
 void SX1509::setMode(uint8_t pin, mode_t mode){
@@ -87,23 +95,19 @@
     
     uint8_t inputReg, pullupReg, opendReg, dirReg, ledReg;
     
-    switch(PINBANK(pin)){
-        case 'A':
+    if(pin < 8){
             inputReg = REGINPUTDISABLEA;
             pullupReg = REGPULLUPA;
             opendReg = REGOPENDRAINA;
             dirReg = REGDIRA;
             ledReg = REGLEDDRIVERENABLEA;
-            break;
-        case 'B':
+    } else {
             inputReg = REGINPUTDISABLEB;
             pullupReg = REGPULLUPB;
             opendReg = REGOPENDRAINB;
             dirReg = REGDIRB;
             ledReg = REGLEDDRIVERENABLEB;
-            break;
-        default:
-            return;
+            pin-=8;
     }
     
     switch(mode){
@@ -155,19 +159,21 @@
 void SX1509::writePin(uint8_t pin, uint8_t intensity){
     i2cWrite8(onIReg[pin], intensity&0xFF);
     uint8_t dataReg;
-    switch(PINBANK(pin)){
-        case 'A':
+    if(pin < 8){
             dataReg = REGDATAA;
-            break;
-        case 'B':
+    } else {
             dataReg = REGDATAB;
-            break;
-        default:
-            return;
+            pin-=8;
     }
     uint8_t buf = i2cRead8(dataReg);
     if(intensity == 0)
         i2cWrite8(dataReg, buf | (1<<pin));
     else
         i2cWrite8(dataReg, buf & ~(1<<pin));
+}
+
+void SX1509::setReset(){
+    uint8_t buf = i2cRead8(REGMISC);
+    buf |= (1<<2);
+    i2cWrite8(REGMISC, buf);
 }
\ No newline at end of file
--- a/SX1509.h	Tue Apr 18 19:49:29 2017 +0000
+++ b/SX1509.h	Thu Apr 20 17:55:01 2017 +0000
@@ -126,8 +126,6 @@
 #define REGTEST1            (0x7E)
 #define REGTEST2            (0x7F)
 
-#define PINBANK(x) ((x<8)?'A':'B')
-
 #define LINEAR 0
 #define LOG 1
 
@@ -153,6 +151,7 @@
         void setBreath(uint8_t pin, uint8_t fadeIn, uint8_t fadeOut);
         void setBlink(uint8_t pin, uint8_t tOn, uint8_t tOff, uint8_t iOff);
         void writePin(uint8_t pin, uint8_t intensity);
+        void setReset();
 };