SPI-Brigde (capseld), for polling interrupt, it is neccessary to adapt the constructor and the function getInt()
SC18IS602.h@2:cb90c271c412, 2019-02-18 (annotated)
- Committer:
- x1dmoesc
- Date:
- Mon Feb 18 16:03:44 2019 +0000
- Revision:
- 2:cb90c271c412
- Parent:
- 1:2a7edc2be6df
- Child:
- 3:9cf83f16c17d
change class construct
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
x1dmoesc | 0:833cb2c6da5d | 1 | #ifndef H_SC18IS602 |
x1dmoesc | 0:833cb2c6da5d | 2 | #define H_SC18IS602 |
x1dmoesc | 0:833cb2c6da5d | 3 | |
x1dmoesc | 0:833cb2c6da5d | 4 | #include "mbed.h" |
x1dmoesc | 0:833cb2c6da5d | 5 | #include <string> |
x1dmoesc | 0:833cb2c6da5d | 6 | |
x1dmoesc | 0:833cb2c6da5d | 7 | #include "PCA9555.h" |
x1dmoesc | 0:833cb2c6da5d | 8 | |
x1dmoesc | 0:833cb2c6da5d | 9 | class SC18IS602 |
x1dmoesc | 0:833cb2c6da5d | 10 | { |
x1dmoesc | 0:833cb2c6da5d | 11 | public: |
x1dmoesc | 0:833cb2c6da5d | 12 | |
x1dmoesc | 2:cb90c271c412 | 13 | static const int BUFFER_SIZE = 200;// Byte |
x1dmoesc | 2:cb90c271c412 | 14 | static const bool ACK = true; |
x1dmoesc | 2:cb90c271c412 | 15 | static const bool NACK = false; |
x1dmoesc | 2:cb90c271c412 | 16 | static const bool INTERRUPT = false; |
x1dmoesc | 2:cb90c271c412 | 17 | static const bool WAIT_SEC = 10e-6; |
x1dmoesc | 0:833cb2c6da5d | 18 | |
x1dmoesc | 0:833cb2c6da5d | 19 | // Register Adress |
x1dmoesc | 2:cb90c271c412 | 20 | static const int HARD_ADR = 0x50; |
x1dmoesc | 2:cb90c271c412 | 21 | static const int USER_ADR_MASK = 0x07; |
x1dmoesc | 0:833cb2c6da5d | 22 | |
x1dmoesc | 2:cb90c271c412 | 23 | struct{ |
x1dmoesc | 2:cb90c271c412 | 24 | static const int CS0 = 0x01; |
x1dmoesc | 2:cb90c271c412 | 25 | static const int CS1 = 0x02; |
x1dmoesc | 2:cb90c271c412 | 26 | static const int CS2 = 0x04; |
x1dmoesc | 2:cb90c271c412 | 27 | static const int CS3 = 0x08; |
x1dmoesc | 2:cb90c271c412 | 28 | }CMD_RW; |
x1dmoesc | 0:833cb2c6da5d | 29 | |
x1dmoesc | 2:cb90c271c412 | 30 | static const int ADR_SPI_CONF = 0xF0; |
x1dmoesc | 2:cb90c271c412 | 31 | |
x1dmoesc | 2:cb90c271c412 | 32 | struct{ |
x1dmoesc | 2:cb90c271c412 | 33 | static const int WRITE = 0xF4; |
x1dmoesc | 2:cb90c271c412 | 34 | static const int READ = 0xF5; |
x1dmoesc | 2:cb90c271c412 | 35 | static const int EN = 0xF6; |
x1dmoesc | 2:cb90c271c412 | 36 | static const int CONF = 0xF7; |
x1dmoesc | 2:cb90c271c412 | 37 | }ADR_GPIO; |
x1dmoesc | 0:833cb2c6da5d | 38 | |
x1dmoesc | 0:833cb2c6da5d | 39 | |
x1dmoesc | 0:833cb2c6da5d | 40 | //Bit position of register Configure SPI Interface |
x1dmoesc | 0:833cb2c6da5d | 41 | static const int SPI_BIT_ORDER = 5; |
x1dmoesc | 0:833cb2c6da5d | 42 | static const int SPI_MODE = 2; |
x1dmoesc | 0:833cb2c6da5d | 43 | static const int SPI_CLK_RATE = 0; |
x1dmoesc | 0:833cb2c6da5d | 44 | |
x1dmoesc | 0:833cb2c6da5d | 45 | // Register Value SPI bit order |
x1dmoesc | 2:cb90c271c412 | 46 | struct{ |
x1dmoesc | 2:cb90c271c412 | 47 | static const int MSB = 0; // MSB of the data word is transmitted first |
x1dmoesc | 2:cb90c271c412 | 48 | static const int LSB = 1; // LSB of the data word is transmitted first |
x1dmoesc | 2:cb90c271c412 | 49 | }SPI_BITORDER; |
x1dmoesc | 2:cb90c271c412 | 50 | |
x1dmoesc | 0:833cb2c6da5d | 51 | |
x1dmoesc | 0:833cb2c6da5d | 52 | // Register Value SPI Mode (CPOL, CPHA) |
x1dmoesc | 0:833cb2c6da5d | 53 | static const int SPI_MODE_00 = 0; |
x1dmoesc | 0:833cb2c6da5d | 54 | static const int SPI_MODE_01 = 1; |
x1dmoesc | 0:833cb2c6da5d | 55 | static const int SPI_MODE_10 = 2; |
x1dmoesc | 0:833cb2c6da5d | 56 | static const int SPI_MODE_11 = 3; |
x1dmoesc | 0:833cb2c6da5d | 57 | |
x1dmoesc | 0:833cb2c6da5d | 58 | //Register Value - Clock Rate |
x1dmoesc | 0:833cb2c6da5d | 59 | static const int SPI_RATE_58K = 0; |
x1dmoesc | 0:833cb2c6da5d | 60 | static const int SPI_RATE_115K = 1; |
x1dmoesc | 0:833cb2c6da5d | 61 | static const int SPI_RATE_461K = 2; |
x1dmoesc | 0:833cb2c6da5d | 62 | static const int SPI_RATE_1M8 = 3; |
x1dmoesc | 0:833cb2c6da5d | 63 | |
x1dmoesc | 0:833cb2c6da5d | 64 | |
x1dmoesc | 0:833cb2c6da5d | 65 | |
x1dmoesc | 0:833cb2c6da5d | 66 | // Bist position of Register GPIO Enable |
x1dmoesc | 2:cb90c271c412 | 67 | struct{ |
x1dmoesc | 2:cb90c271c412 | 68 | static const int CS0 = 0; |
x1dmoesc | 2:cb90c271c412 | 69 | static const int CS1 = 1; |
x1dmoesc | 2:cb90c271c412 | 70 | static const int CS2 = 2; |
x1dmoesc | 2:cb90c271c412 | 71 | static const int CS3 = 3; |
x1dmoesc | 2:cb90c271c412 | 72 | }GPIO; |
x1dmoesc | 0:833cb2c6da5d | 73 | |
x1dmoesc | 0:833cb2c6da5d | 74 | |
x1dmoesc | 0:833cb2c6da5d | 75 | |
x1dmoesc | 0:833cb2c6da5d | 76 | // Bit position of Register GPIO config |
x1dmoesc | 0:833cb2c6da5d | 77 | static const int GPIO_CONF_CS0 = 0; |
x1dmoesc | 0:833cb2c6da5d | 78 | static const int GPIO_CONF_CS1 = 2; |
x1dmoesc | 0:833cb2c6da5d | 79 | static const int GPIO_CONF_CS2 = 4; |
x1dmoesc | 0:833cb2c6da5d | 80 | static const int GPIO_CONF_CS3 = 6; |
x1dmoesc | 0:833cb2c6da5d | 81 | |
x1dmoesc | 0:833cb2c6da5d | 82 | |
x1dmoesc | 0:833cb2c6da5d | 83 | // Register Value of GPIO config |
x1dmoesc | 0:833cb2c6da5d | 84 | static const int BIDIRECTIONAL = 0; // quasi bidirecitonal |
x1dmoesc | 0:833cb2c6da5d | 85 | static const int PUSH_PULL = 1; // |
x1dmoesc | 0:833cb2c6da5d | 86 | static const int INPUT_ONLY = 2; // high impedance |
x1dmoesc | 0:833cb2c6da5d | 87 | static const int OPEN_DRAIN = 3; // needs an external pullup |
x1dmoesc | 0:833cb2c6da5d | 88 | |
x1dmoesc | 0:833cb2c6da5d | 89 | |
x1dmoesc | 0:833cb2c6da5d | 90 | const int iINT; |
x1dmoesc | 0:833cb2c6da5d | 91 | |
x1dmoesc | 0:833cb2c6da5d | 92 | // public |
x1dmoesc | 0:833cb2c6da5d | 93 | SC18IS602(I2C *_i2c, uint8_t uiAdr); |
x1dmoesc | 0:833cb2c6da5d | 94 | SC18IS602(I2C *_i2c, PCA9555 *_pca , uint8_t uiAdr); // |
x1dmoesc | 0:833cb2c6da5d | 95 | SC18IS602(I2C *_i2c, DigitalIn *_IntPin, uint8_t uiAdr); // |
x1dmoesc | 0:833cb2c6da5d | 96 | |
x1dmoesc | 0:833cb2c6da5d | 97 | |
x1dmoesc | 0:833cb2c6da5d | 98 | bool configSPI(uint8_t uiConf); |
x1dmoesc | 0:833cb2c6da5d | 99 | bool enableGPIO(uint8_t uiConf); |
x1dmoesc | 0:833cb2c6da5d | 100 | bool configGPIO(uint8_t uiConf); |
x1dmoesc | 0:833cb2c6da5d | 101 | |
x1dmoesc | 2:cb90c271c412 | 102 | bool gpio_pin3_on(); |
x1dmoesc | 2:cb90c271c412 | 103 | bool gpio_pin3_off(); |
x1dmoesc | 0:833cb2c6da5d | 104 | bool gpio_toggle(uint8_t uiPort); |
x1dmoesc | 0:833cb2c6da5d | 105 | |
x1dmoesc | 0:833cb2c6da5d | 106 | bool sendViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum); |
x1dmoesc | 0:833cb2c6da5d | 107 | bool readViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum); |
x1dmoesc | 0:833cb2c6da5d | 108 | |
x1dmoesc | 0:833cb2c6da5d | 109 | |
x1dmoesc | 1:2a7edc2be6df | 110 | //void setIntFuncPtr( bool (*Int_ptr)(void)); |
x1dmoesc | 0:833cb2c6da5d | 111 | |
x1dmoesc | 2:cb90c271c412 | 112 | protected: // private |
x1dmoesc | 0:833cb2c6da5d | 113 | I2C *i2c; // Serial Data & Clock |
x1dmoesc | 0:833cb2c6da5d | 114 | PCA9555 *pca; |
x1dmoesc | 0:833cb2c6da5d | 115 | DigitalIn *IntPin; // Interrupt pin |
x1dmoesc | 0:833cb2c6da5d | 116 | |
x1dmoesc | 0:833cb2c6da5d | 117 | |
x1dmoesc | 0:833cb2c6da5d | 118 | bool sendViaI2C(const char *cData, int iLength, string sDebug = ""); |
x1dmoesc | 0:833cb2c6da5d | 119 | bool readViaI2C(char *cData, int iLength, string sDebug = ""); |
x1dmoesc | 2:cb90c271c412 | 120 | void waitFor(bool bInt); |
x1dmoesc | 2:cb90c271c412 | 121 | |
x1dmoesc | 0:833cb2c6da5d | 122 | |
x1dmoesc | 1:2a7edc2be6df | 123 | bool getInt(); |
x1dmoesc | 1:2a7edc2be6df | 124 | bool clearInt(); |
x1dmoesc | 1:2a7edc2be6df | 125 | |
x1dmoesc | 2:cb90c271c412 | 126 | //bool (*getInt_ptr)(void); |
x1dmoesc | 0:833cb2c6da5d | 127 | |
x1dmoesc | 0:833cb2c6da5d | 128 | |
x1dmoesc | 0:833cb2c6da5d | 129 | // variable |
x1dmoesc | 0:833cb2c6da5d | 130 | bool bAck; |
x1dmoesc | 0:833cb2c6da5d | 131 | unsigned int uiNumByte; |
x1dmoesc | 0:833cb2c6da5d | 132 | char cCmd[BUFFER_SIZE]; |
x1dmoesc | 0:833cb2c6da5d | 133 | |
x1dmoesc | 0:833cb2c6da5d | 134 | const uint8_t SC18IS602_W; // const write-address |
x1dmoesc | 0:833cb2c6da5d | 135 | const uint8_t SC18IS602_R; // const read-address |
x1dmoesc | 0:833cb2c6da5d | 136 | |
x1dmoesc | 0:833cb2c6da5d | 137 | |
x1dmoesc | 0:833cb2c6da5d | 138 | char cDebug[100]; |
x1dmoesc | 0:833cb2c6da5d | 139 | |
x1dmoesc | 2:cb90c271c412 | 140 | int iTimeOut; |
x1dmoesc | 2:cb90c271c412 | 141 | |
x1dmoesc | 0:833cb2c6da5d | 142 | }; |
x1dmoesc | 0:833cb2c6da5d | 143 | |
x1dmoesc | 0:833cb2c6da5d | 144 | |
x1dmoesc | 0:833cb2c6da5d | 145 | #endif |