SPI-Brigde (capseld), for polling interrupt, it is neccessary to adapt the constructor and the function getInt()
SC18IS602.h@0:833cb2c6da5d, 2019-02-01 (annotated)
- Committer:
- x1dmoesc
- Date:
- Fri Feb 01 09:40:03 2019 +0000
- Revision:
- 0:833cb2c6da5d
- Child:
- 1:2a7edc2be6df
Rename lib; Rename func writeViaI2C -> sendViaI2C
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 | 0:833cb2c6da5d | 13 | static const int BUFFER_SIZE = 200;// Byte |
x1dmoesc | 0:833cb2c6da5d | 14 | static const bool ACK = false; |
x1dmoesc | 0:833cb2c6da5d | 15 | static const bool NACK = true; |
x1dmoesc | 0:833cb2c6da5d | 16 | static const bool INTERRUPT = false; |
x1dmoesc | 0:833cb2c6da5d | 17 | |
x1dmoesc | 0:833cb2c6da5d | 18 | |
x1dmoesc | 0:833cb2c6da5d | 19 | // Register Adress |
x1dmoesc | 0:833cb2c6da5d | 20 | static const int HARD_ADR = 0x50; |
x1dmoesc | 0:833cb2c6da5d | 21 | static const int USER_ADR_MASK = 0x07; |
x1dmoesc | 0:833cb2c6da5d | 22 | |
x1dmoesc | 0:833cb2c6da5d | 23 | static const int CMD_RW_CS0 = 0x01; |
x1dmoesc | 0:833cb2c6da5d | 24 | static const int CMD_RW_CS1 = 0x02; |
x1dmoesc | 0:833cb2c6da5d | 25 | static const int CMD_RW_CS2 = 0x04; |
x1dmoesc | 0:833cb2c6da5d | 26 | static const int CMD_RW_CS3 = 0x08; |
x1dmoesc | 0:833cb2c6da5d | 27 | |
x1dmoesc | 0:833cb2c6da5d | 28 | static const int ADR_SPI_CONF = 0xF0; |
x1dmoesc | 0:833cb2c6da5d | 29 | static const int ADR_GPIO_WRITE = 0xF4; |
x1dmoesc | 0:833cb2c6da5d | 30 | static const int ADR_GPIO_READ = 0xF5; |
x1dmoesc | 0:833cb2c6da5d | 31 | static const int ADR_GPIO_EN = 0xF6; |
x1dmoesc | 0:833cb2c6da5d | 32 | static const int ADR_GPIO_CONF = 0xF7; |
x1dmoesc | 0:833cb2c6da5d | 33 | |
x1dmoesc | 0:833cb2c6da5d | 34 | |
x1dmoesc | 0:833cb2c6da5d | 35 | //Bit position of register Configure SPI Interface |
x1dmoesc | 0:833cb2c6da5d | 36 | static const int SPI_BIT_ORDER = 5; |
x1dmoesc | 0:833cb2c6da5d | 37 | static const int SPI_MODE = 2; |
x1dmoesc | 0:833cb2c6da5d | 38 | static const int SPI_CLK_RATE = 0; |
x1dmoesc | 0:833cb2c6da5d | 39 | |
x1dmoesc | 0:833cb2c6da5d | 40 | // Register Value SPI bit order |
x1dmoesc | 0:833cb2c6da5d | 41 | static const int SPI_BIT_ORDER_MSB = 0; // MSB of the data word is transmitted first |
x1dmoesc | 0:833cb2c6da5d | 42 | static const int SPI_BIT_ORDER_LSB = 1; // LSB of the data word is transmitted first |
x1dmoesc | 0:833cb2c6da5d | 43 | |
x1dmoesc | 0:833cb2c6da5d | 44 | // Register Value SPI Mode (CPOL, CPHA) |
x1dmoesc | 0:833cb2c6da5d | 45 | static const int SPI_MODE_00 = 0; |
x1dmoesc | 0:833cb2c6da5d | 46 | static const int SPI_MODE_01 = 1; |
x1dmoesc | 0:833cb2c6da5d | 47 | static const int SPI_MODE_10 = 2; |
x1dmoesc | 0:833cb2c6da5d | 48 | static const int SPI_MODE_11 = 3; |
x1dmoesc | 0:833cb2c6da5d | 49 | |
x1dmoesc | 0:833cb2c6da5d | 50 | //Register Value - Clock Rate |
x1dmoesc | 0:833cb2c6da5d | 51 | static const int SPI_RATE_58K = 0; |
x1dmoesc | 0:833cb2c6da5d | 52 | static const int SPI_RATE_115K = 1; |
x1dmoesc | 0:833cb2c6da5d | 53 | static const int SPI_RATE_461K = 2; |
x1dmoesc | 0:833cb2c6da5d | 54 | static const int SPI_RATE_1M8 = 3; |
x1dmoesc | 0:833cb2c6da5d | 55 | |
x1dmoesc | 0:833cb2c6da5d | 56 | |
x1dmoesc | 0:833cb2c6da5d | 57 | |
x1dmoesc | 0:833cb2c6da5d | 58 | // Bist position of Register GPIO Enable |
x1dmoesc | 0:833cb2c6da5d | 59 | static const int GPIO_CS0 = 0; |
x1dmoesc | 0:833cb2c6da5d | 60 | static const int GPIO_CS1 = 1; |
x1dmoesc | 0:833cb2c6da5d | 61 | static const int GPIO_CS2 = 2; |
x1dmoesc | 0:833cb2c6da5d | 62 | static const int GPIO_CS3 = 3; |
x1dmoesc | 0:833cb2c6da5d | 63 | |
x1dmoesc | 0:833cb2c6da5d | 64 | |
x1dmoesc | 0:833cb2c6da5d | 65 | |
x1dmoesc | 0:833cb2c6da5d | 66 | // Bit position of Register GPIO config |
x1dmoesc | 0:833cb2c6da5d | 67 | static const int GPIO_CONF_CS0 = 0; |
x1dmoesc | 0:833cb2c6da5d | 68 | static const int GPIO_CONF_CS1 = 2; |
x1dmoesc | 0:833cb2c6da5d | 69 | static const int GPIO_CONF_CS2 = 4; |
x1dmoesc | 0:833cb2c6da5d | 70 | static const int GPIO_CONF_CS3 = 6; |
x1dmoesc | 0:833cb2c6da5d | 71 | |
x1dmoesc | 0:833cb2c6da5d | 72 | |
x1dmoesc | 0:833cb2c6da5d | 73 | // Register Value of GPIO config |
x1dmoesc | 0:833cb2c6da5d | 74 | static const int BIDIRECTIONAL = 0; // quasi bidirecitonal |
x1dmoesc | 0:833cb2c6da5d | 75 | static const int PUSH_PULL = 1; // |
x1dmoesc | 0:833cb2c6da5d | 76 | static const int INPUT_ONLY = 2; // high impedance |
x1dmoesc | 0:833cb2c6da5d | 77 | static const int OPEN_DRAIN = 3; // needs an external pullup |
x1dmoesc | 0:833cb2c6da5d | 78 | |
x1dmoesc | 0:833cb2c6da5d | 79 | |
x1dmoesc | 0:833cb2c6da5d | 80 | const int iINT; |
x1dmoesc | 0:833cb2c6da5d | 81 | |
x1dmoesc | 0:833cb2c6da5d | 82 | // public |
x1dmoesc | 0:833cb2c6da5d | 83 | SC18IS602(I2C *_i2c, uint8_t uiAdr); |
x1dmoesc | 0:833cb2c6da5d | 84 | SC18IS602(I2C *_i2c, PCA9555 *_pca , uint8_t uiAdr); // |
x1dmoesc | 0:833cb2c6da5d | 85 | SC18IS602(I2C *_i2c, DigitalIn *_IntPin, uint8_t uiAdr); // |
x1dmoesc | 0:833cb2c6da5d | 86 | |
x1dmoesc | 0:833cb2c6da5d | 87 | |
x1dmoesc | 0:833cb2c6da5d | 88 | bool configSPI(uint8_t uiConf); |
x1dmoesc | 0:833cb2c6da5d | 89 | bool enableGPIO(uint8_t uiConf); |
x1dmoesc | 0:833cb2c6da5d | 90 | bool configGPIO(uint8_t uiConf); |
x1dmoesc | 0:833cb2c6da5d | 91 | |
x1dmoesc | 0:833cb2c6da5d | 92 | bool GPIO_pin3_on(); |
x1dmoesc | 0:833cb2c6da5d | 93 | bool GPIO_pin3_off(); |
x1dmoesc | 0:833cb2c6da5d | 94 | bool gpio_toggle(uint8_t uiPort); |
x1dmoesc | 0:833cb2c6da5d | 95 | |
x1dmoesc | 0:833cb2c6da5d | 96 | bool sendViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum); |
x1dmoesc | 0:833cb2c6da5d | 97 | bool readViaSPI(char cAdrByte, char *cDataBytes, uint8_t uiNum); |
x1dmoesc | 0:833cb2c6da5d | 98 | |
x1dmoesc | 0:833cb2c6da5d | 99 | |
x1dmoesc | 0:833cb2c6da5d | 100 | bool getInt(); |
x1dmoesc | 0:833cb2c6da5d | 101 | bool clearInt(); |
x1dmoesc | 0:833cb2c6da5d | 102 | |
x1dmoesc | 0:833cb2c6da5d | 103 | private: // private |
x1dmoesc | 0:833cb2c6da5d | 104 | I2C *i2c; // Serial Data & Clock |
x1dmoesc | 0:833cb2c6da5d | 105 | PCA9555 *pca; |
x1dmoesc | 0:833cb2c6da5d | 106 | DigitalIn *IntPin; // Interrupt pin |
x1dmoesc | 0:833cb2c6da5d | 107 | |
x1dmoesc | 0:833cb2c6da5d | 108 | |
x1dmoesc | 0:833cb2c6da5d | 109 | bool sendViaI2C(const char *cData, int iLength, string sDebug = ""); |
x1dmoesc | 0:833cb2c6da5d | 110 | bool readViaI2C(char *cData, int iLength, string sDebug = ""); |
x1dmoesc | 0:833cb2c6da5d | 111 | |
x1dmoesc | 0:833cb2c6da5d | 112 | |
x1dmoesc | 0:833cb2c6da5d | 113 | |
x1dmoesc | 0:833cb2c6da5d | 114 | |
x1dmoesc | 0:833cb2c6da5d | 115 | // variable |
x1dmoesc | 0:833cb2c6da5d | 116 | bool bAck; |
x1dmoesc | 0:833cb2c6da5d | 117 | unsigned int uiNumByte; |
x1dmoesc | 0:833cb2c6da5d | 118 | char cCmd[BUFFER_SIZE]; |
x1dmoesc | 0:833cb2c6da5d | 119 | |
x1dmoesc | 0:833cb2c6da5d | 120 | const uint8_t SC18IS602_W; // const write-address |
x1dmoesc | 0:833cb2c6da5d | 121 | const uint8_t SC18IS602_R; // const read-address |
x1dmoesc | 0:833cb2c6da5d | 122 | |
x1dmoesc | 0:833cb2c6da5d | 123 | |
x1dmoesc | 0:833cb2c6da5d | 124 | char cDebug[100]; |
x1dmoesc | 0:833cb2c6da5d | 125 | |
x1dmoesc | 0:833cb2c6da5d | 126 | }; |
x1dmoesc | 0:833cb2c6da5d | 127 | |
x1dmoesc | 0:833cb2c6da5d | 128 | |
x1dmoesc | 0:833cb2c6da5d | 129 | #endif |