Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SC18IS602.h
00001 #ifndef H_SC18IS602 00002 #define H_SC18IS602 00003 00004 #include "mbed.h" 00005 #include <string> 00006 00007 #include "PCA9555.h" 00008 00009 class SC18IS602 00010 { 00011 public: 00012 00013 static const int BUFFER_SIZE = 200;// Byte 00014 static const bool ACK = true; 00015 static const bool NACK = false; 00016 static const bool INTERRUPT = false; 00017 static const bool WAIT_SEC = 10e-6; 00018 00019 // Register Adress 00020 static const int HARD_ADR = 0x50; 00021 static const int USER_ADR_MASK = 0x07; 00022 00023 struct{ 00024 static const uint8_t CS0 = 0x01; 00025 static const uint8_t CS1 = 0x02; 00026 static const uint8_t CS2 = 0x04; 00027 static const uint8_t CS3 = 0x08; 00028 }CMD_RW; 00029 00030 static const int ADR_SPI_CONF = 0xF0; 00031 00032 struct{ 00033 static const int WRITE = 0xF4; 00034 static const int READ = 0xF5; 00035 static const int EN = 0xF6; 00036 static const int CONF = 0xF7; 00037 }ADR_GPIO; 00038 00039 00040 //Bit position of register Configure SPI Interface 00041 static const int SPI_BIT_ORDER = 5; 00042 static const int SPI_MODE = 2; 00043 static const int SPI_CLK_RATE = 0; 00044 00045 // Register Value SPI bit order 00046 struct{ 00047 static const int MSB = 0; // MSB of the data word is transmitted first 00048 static const int LSB = 1; // LSB of the data word is transmitted first 00049 }SPI_BITORDER; 00050 00051 00052 // Register Value SPI Mode (CPOL, CPHA) 00053 static const int SPI_MODE_00 = 0; 00054 static const int SPI_MODE_01 = 1; 00055 static const int SPI_MODE_10 = 2; 00056 static const int SPI_MODE_11 = 3; 00057 00058 //Register Value - Clock Rate 00059 static const int SPI_RATE_58K = 0; 00060 static const int SPI_RATE_115K = 1; 00061 static const int SPI_RATE_461K = 2; 00062 static const int SPI_RATE_1M8 = 3; 00063 00064 00065 00066 // Bit position of Register GPIO Enable 00067 struct{ 00068 static const int CS0 = 0; 00069 static const int CS1 = 1; 00070 static const int CS2 = 2; 00071 static const int CS3 = 3; 00072 }GPIO; 00073 00074 00075 00076 // Bit position of Register GPIO config 00077 static const int GPIO_CONF_CS0 = 0; 00078 static const int GPIO_CONF_CS1 = 2; 00079 static const int GPIO_CONF_CS2 = 4; 00080 static const int GPIO_CONF_CS3 = 6; 00081 00082 00083 // Register Value of GPIO config 00084 static const int BIDIRECTIONAL = 0; // quasi bidirecitonal 00085 static const int PUSH_PULL = 1; // 00086 static const int INPUT_ONLY = 2; // high impedance 00087 static const int OPEN_DRAIN = 3; // needs an external pullup 00088 00089 00090 const int iINT; 00091 00092 // public 00093 SC18IS602(I2C *_i2c, uint8_t uiAdr); 00094 SC18IS602(I2C *_i2c, PCA9555 *_pca , uint8_t uiAdr); // 00095 SC18IS602(I2C *_i2c, DigitalIn *_IntPin, uint8_t uiAdr); // 00096 00097 00098 bool configSPI(uint8_t uiConf); 00099 bool enableGPIO(uint8_t uiConf); 00100 bool configGPIO(uint8_t uiConf); 00101 00102 bool gpio_pin3_on(); 00103 bool gpio_pin3_off(); 00104 bool gpio_toggle(uint8_t uiPort); 00105 00106 bool sendViaSPI(uint8_t uiCS, char cAdrByte, char *cDataBytes, uint8_t uiNum); 00107 bool readViaSPI(uint8_t uiCS, char cAdrByte, char *cDataBytes, uint8_t uiNum); 00108 00109 00110 //void setIntFuncPtr( bool (*Int_ptr)(void)); 00111 00112 protected: // private 00113 I2C *i2c; // Serial Data & Clock 00114 PCA9555 *pca; 00115 DigitalIn *IntPin; // Interrupt pin 00116 00117 00118 bool sendViaI2C(const char *cData, int iLength, string sDebug = ""); 00119 bool readViaI2C(char *cData, int iLength, string sDebug = ""); 00120 void waitFor(bool bInt); 00121 00122 00123 bool getInt(); 00124 bool clearInt(); 00125 00126 //bool (*getInt_ptr)(void); 00127 00128 00129 // variable 00130 bool bAck; 00131 unsigned int uiNumByte; 00132 char cCmd[BUFFER_SIZE]; 00133 00134 const uint8_t SC18IS602_W; // const write-address 00135 const uint8_t SC18IS602_R; // const read-address 00136 00137 00138 char cDebug[100]; 00139 00140 int iTimeOut; 00141 00142 }; 00143 00144 00145 #endif
Generated on Sun Jul 24 2022 00:08:08 by
1.7.2