SPI-Brigde (capseld), for polling interrupt, it is neccessary to adapt the constructor and the function getInt()

Files at this revision

API Documentation at this revision

Comitter:
x1dmoesc
Date:
Thu Apr 23 22:55:50 2020 +0000
Parent:
2:cb90c271c412
Commit message:
last version;

Changed in this revision

SC18IS602.cpp Show annotated file Show diff for this revision Revisions of this file
SC18IS602.h Show annotated file Show diff for this revision Revisions of this file
--- a/SC18IS602.cpp	Mon Feb 18 16:03:44 2019 +0000
+++ b/SC18IS602.cpp	Thu Apr 23 22:55:50 2020 +0000
@@ -219,14 +219,20 @@
 //******************************************************************************//
 //
 //******************************************************************************//
-bool SC18IS602::sendViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum)
+bool SC18IS602::sendViaSPI(uint8_t uiCS, char cAdrByte, char *cDataBytes, uint8_t uiNum)
 {
     if((int)uiNum >= BUFFER_SIZE - 1)                                           // If number of sending Bytes greather than BUFFER_SIZE - 1 (Register-Adress-Byte)
         return NACK;                                                            // returns NACK (failure)
+        
+        
+    if( uiCS != CMD_RW.CS0 and uiCS != CMD_RW.CS1 
+        and uiCS != CMD_RW.CS2 and uiCS != CMD_RW.CS3){                         // If uiCS not element of CMD_RW, than return NACK (faiure)
+            return NACK;
+    }
     
     
     uiNumByte = 0;
-    cCmd[uiNumByte] = CMD_RW.CS0;                                               // send via SPI and CS0 (SS0)
+    cCmd[uiNumByte] = uiCS;                                                     // send via SPI and CS0 (SS0)
     cCmd[++uiNumByte] = cAdrByte;
     for(int n = uiNum - 1 ; n >= 0; n--) {
         cCmd[++uiNumByte] = cDataBytes[n];
@@ -235,7 +241,7 @@
     
     uiNumByte++;                                                                // char cCmd counts from 0, so the number is +1    
     bAck = sendViaI2C(cCmd, uiNumByte, "TX via SPI");                           // send via SPI      
-    waitFor(INTERRUPT);                                                  // If there was an interrupt, wait until it is cleared   
+    waitFor(INTERRUPT);                                                         // If there was an interrupt, wait until it is cleared   
     clearInt();  
     waitFor(not INTERRUPT);                                                      // If there was an interrupt, wait until it is cleared
     
@@ -247,15 +253,21 @@
 //******************************************************************************//
 //  returns reading data. The first byte is the status byte
 //******************************************************************************//
-bool SC18IS602::readViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum)
+bool SC18IS602::readViaSPI(uint8_t uiCS, char cAdrByte, char *cDataBytes, uint8_t uiNum)
 {   
     if((int)uiNum >= BUFFER_SIZE - 1)                                           // If number of sending Bytes greather than BUFFER_SIZE - 1 (Register-Adress-Byte)
         return NACK;                                                            // returns NACK (failure)    
+    
+    
+    if( uiCS != CMD_RW.CS0 and uiCS != CMD_RW.CS1 
+        and uiCS != CMD_RW.CS2 and uiCS != CMD_RW.CS3){                         // If uiCS not element of CMD_RW, than return NACK (faiure)
+            return NACK;
+    }
 
     
     // send first time Read comand
     uiNumByte = 0;
-    cCmd[uiNumByte++] = CMD_RW.CS0;                                               // send via SPI and CS0 (SS0)
+    cCmd[uiNumByte++] = uiCS;                                                   // send via SPI and CS0 (SS0)
     cCmd[uiNumByte++] = cAdrByte;
     
     for(int n = uiNum - 1 ; n >= 0; n--) {
--- a/SC18IS602.h	Mon Feb 18 16:03:44 2019 +0000
+++ b/SC18IS602.h	Thu Apr 23 22:55:50 2020 +0000
@@ -21,10 +21,10 @@
         static const int USER_ADR_MASK      = 0x07;
         
         struct{
-            static const int CS0            = 0x01;
-            static const int CS1            = 0x02;
-            static const int CS2            = 0x04;
-            static const int CS3            = 0x08;
+            static const uint8_t CS0            = 0x01;
+            static const uint8_t CS1            = 0x02;
+            static const uint8_t CS2            = 0x04;
+            static const uint8_t CS3            = 0x08;
         }CMD_RW;
         
         static const int ADR_SPI_CONF       = 0xF0;
@@ -63,7 +63,7 @@
         
         
                 
-        // Bist position of Register GPIO Enable
+        // Bit position of Register GPIO Enable
         struct{
             static const int CS0          = 0;
             static const int CS1          = 1;
@@ -92,7 +92,7 @@
         // public
         SC18IS602(I2C *_i2c, uint8_t uiAdr);         
         SC18IS602(I2C *_i2c, PCA9555 *_pca , uint8_t uiAdr);                    //
-        SC18IS602(I2C *_i2c, DigitalIn *_IntPin, uint8_t uiAdr);                 //
+        SC18IS602(I2C *_i2c, DigitalIn *_IntPin, uint8_t uiAdr);                //
 
         
         bool configSPI(uint8_t uiConf);
@@ -103,8 +103,8 @@
         bool gpio_pin3_off();
         bool gpio_toggle(uint8_t uiPort);
         
-        bool sendViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum);
-        bool readViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum);
+        bool sendViaSPI(uint8_t uiCS, char cAdrByte, char *cDataBytes, uint8_t uiNum);
+        bool readViaSPI(uint8_t uiCS, char cAdrByte, char *cDataBytes, uint8_t uiNum);
     
     
         //void setIntFuncPtr( bool (*Int_ptr)(void));