-
PCA9555/PCA9555.h@0:3835ff675f6b, 2019-02-01 (annotated)
- Committer:
- x1dmoesc
- Date:
- Fri Feb 01 09:41:20 2019 +0000
- Revision:
- 0:3835ff675f6b
New Lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
x1dmoesc | 0:3835ff675f6b | 1 | #ifndef PCA9555_H |
x1dmoesc | 0:3835ff675f6b | 2 | #define PCA9555_H |
x1dmoesc | 0:3835ff675f6b | 3 | |
x1dmoesc | 0:3835ff675f6b | 4 | #include <mbed.h> |
x1dmoesc | 0:3835ff675f6b | 5 | |
x1dmoesc | 0:3835ff675f6b | 6 | |
x1dmoesc | 0:3835ff675f6b | 7 | class PCA9555 |
x1dmoesc | 0:3835ff675f6b | 8 | { |
x1dmoesc | 0:3835ff675f6b | 9 | public: |
x1dmoesc | 0:3835ff675f6b | 10 | |
x1dmoesc | 0:3835ff675f6b | 11 | // ADDRESS |
x1dmoesc | 0:3835ff675f6b | 12 | static const int HARD_ADR = 0x40; |
x1dmoesc | 0:3835ff675f6b | 13 | static const int USER_ADR_MASK = 0x07; |
x1dmoesc | 0:3835ff675f6b | 14 | |
x1dmoesc | 0:3835ff675f6b | 15 | |
x1dmoesc | 0:3835ff675f6b | 16 | // PORT 0 |
x1dmoesc | 0:3835ff675f6b | 17 | static const int PORT0_INPUT = 0x00; |
x1dmoesc | 0:3835ff675f6b | 18 | static const int PORT0_OUTPUT = 0x02; |
x1dmoesc | 0:3835ff675f6b | 19 | static const int PORT0_POLAR = 0x04; |
x1dmoesc | 0:3835ff675f6b | 20 | static const int PORT0_CONFIG = 0x06; |
x1dmoesc | 0:3835ff675f6b | 21 | |
x1dmoesc | 0:3835ff675f6b | 22 | |
x1dmoesc | 0:3835ff675f6b | 23 | |
x1dmoesc | 0:3835ff675f6b | 24 | // PORT 1 |
x1dmoesc | 0:3835ff675f6b | 25 | static const int PORT1_INPUT = 0x01; |
x1dmoesc | 0:3835ff675f6b | 26 | static const int PORT1_OUTPUT = 0x03; |
x1dmoesc | 0:3835ff675f6b | 27 | static const int PORT1_POLAR = 0x05; |
x1dmoesc | 0:3835ff675f6b | 28 | static const int PORT1_CONFIG = 0x07; |
x1dmoesc | 0:3835ff675f6b | 29 | |
x1dmoesc | 0:3835ff675f6b | 30 | |
x1dmoesc | 0:3835ff675f6b | 31 | // BIT polarity |
x1dmoesc | 0:3835ff675f6b | 32 | static const int NORM_POL_BIT0 = (0 << 0); |
x1dmoesc | 0:3835ff675f6b | 33 | static const int NORM_POL_BIT1 = (0 << 1); |
x1dmoesc | 0:3835ff675f6b | 34 | static const int NORM_POL_BIT2 = (0 << 2); |
x1dmoesc | 0:3835ff675f6b | 35 | static const int NORM_POL_BIT3 = (0 << 3); |
x1dmoesc | 0:3835ff675f6b | 36 | static const int NORM_POL_BIT4 = (0 << 4); |
x1dmoesc | 0:3835ff675f6b | 37 | static const int NORM_POL_BIT5 = (0 << 5); |
x1dmoesc | 0:3835ff675f6b | 38 | static const int NORM_POL_BIT6 = (0 << 6); |
x1dmoesc | 0:3835ff675f6b | 39 | static const int NORM_POL_BIT7 = (0 << 7); |
x1dmoesc | 0:3835ff675f6b | 40 | |
x1dmoesc | 0:3835ff675f6b | 41 | static const int INV_POL_BIT0 = (1 << 0); |
x1dmoesc | 0:3835ff675f6b | 42 | static const int INV_POL_BIT1 = (1 << 1); |
x1dmoesc | 0:3835ff675f6b | 43 | static const int INV_POL_BIT2 = (1 << 2); |
x1dmoesc | 0:3835ff675f6b | 44 | static const int INV_POL_BIT3 = (1 << 3); |
x1dmoesc | 0:3835ff675f6b | 45 | static const int INV_POL_BIT4 = (1 << 4); |
x1dmoesc | 0:3835ff675f6b | 46 | static const int INV_POL_BIT5 = (1 << 5); |
x1dmoesc | 0:3835ff675f6b | 47 | static const int INV_POL_BIT6 = (1 << 6); |
x1dmoesc | 0:3835ff675f6b | 48 | static const int INV_POL_BIT7 = (1 << 7); |
x1dmoesc | 0:3835ff675f6b | 49 | |
x1dmoesc | 0:3835ff675f6b | 50 | |
x1dmoesc | 0:3835ff675f6b | 51 | |
x1dmoesc | 0:3835ff675f6b | 52 | |
x1dmoesc | 0:3835ff675f6b | 53 | static const int BIT0 = 0; |
x1dmoesc | 0:3835ff675f6b | 54 | static const int BIT1 = 1; |
x1dmoesc | 0:3835ff675f6b | 55 | static const int BIT2 = 2; |
x1dmoesc | 0:3835ff675f6b | 56 | static const int BIT3 = 3; |
x1dmoesc | 0:3835ff675f6b | 57 | static const int BIT4 = 4; |
x1dmoesc | 0:3835ff675f6b | 58 | static const int BIT5 = 5; |
x1dmoesc | 0:3835ff675f6b | 59 | static const int BIT6 = 6; |
x1dmoesc | 0:3835ff675f6b | 60 | static const int BIT7 = 7; |
x1dmoesc | 0:3835ff675f6b | 61 | |
x1dmoesc | 0:3835ff675f6b | 62 | |
x1dmoesc | 0:3835ff675f6b | 63 | |
x1dmoesc | 0:3835ff675f6b | 64 | |
x1dmoesc | 0:3835ff675f6b | 65 | //public: |
x1dmoesc | 0:3835ff675f6b | 66 | // definitions |
x1dmoesc | 0:3835ff675f6b | 67 | typedef enum { _PORT0, _PORT1, _BOTH} _GPIO; |
x1dmoesc | 0:3835ff675f6b | 68 | |
x1dmoesc | 0:3835ff675f6b | 69 | typedef union { |
x1dmoesc | 0:3835ff675f6b | 70 | struct{ |
x1dmoesc | 0:3835ff675f6b | 71 | unsigned int B0 : 1; |
x1dmoesc | 0:3835ff675f6b | 72 | unsigned int B1 : 1; |
x1dmoesc | 0:3835ff675f6b | 73 | unsigned int B2 : 1; |
x1dmoesc | 0:3835ff675f6b | 74 | unsigned int B3 : 1; |
x1dmoesc | 0:3835ff675f6b | 75 | unsigned int B4 : 1; |
x1dmoesc | 0:3835ff675f6b | 76 | unsigned int B5 : 1; |
x1dmoesc | 0:3835ff675f6b | 77 | unsigned int B6 : 1; |
x1dmoesc | 0:3835ff675f6b | 78 | unsigned int B7 : 1; |
x1dmoesc | 0:3835ff675f6b | 79 | }Pin; |
x1dmoesc | 0:3835ff675f6b | 80 | |
x1dmoesc | 0:3835ff675f6b | 81 | uint8_t uiPort; |
x1dmoesc | 0:3835ff675f6b | 82 | }GPIO; |
x1dmoesc | 0:3835ff675f6b | 83 | |
x1dmoesc | 0:3835ff675f6b | 84 | |
x1dmoesc | 0:3835ff675f6b | 85 | // function |
x1dmoesc | 0:3835ff675f6b | 86 | PCA9555(I2C *_i2c, uint8_t uiAdr); |
x1dmoesc | 0:3835ff675f6b | 87 | |
x1dmoesc | 0:3835ff675f6b | 88 | |
x1dmoesc | 0:3835ff675f6b | 89 | bool confDirGPIO(_GPIO gpio, uint8_t uiData0, uint8_t uiData1 = NULL); |
x1dmoesc | 0:3835ff675f6b | 90 | |
x1dmoesc | 0:3835ff675f6b | 91 | |
x1dmoesc | 0:3835ff675f6b | 92 | uint8_t getGPIO0(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 93 | bool getGPIO0_B0(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 94 | bool getGPIO0_B1(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 95 | bool getGPIO0_B2(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 96 | bool getGPIO0_B3(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 97 | bool getGPIO0_B4(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 98 | bool getGPIO0_B5(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 99 | bool getGPIO0_B6(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 100 | bool getGPIO0_B7(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 101 | |
x1dmoesc | 0:3835ff675f6b | 102 | uint8_t getGPIO1(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 103 | bool getGPIO1_B0(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 104 | bool getGPIO1_B1(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 105 | bool getGPIO1_B2(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 106 | bool getGPIO1_B3(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 107 | bool getGPIO1_B4(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 108 | bool getGPIO1_B5(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 109 | bool getGPIO1_B6(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 110 | bool getGPIO1_B7(bool bUpdate); |
x1dmoesc | 0:3835ff675f6b | 111 | |
x1dmoesc | 0:3835ff675f6b | 112 | |
x1dmoesc | 0:3835ff675f6b | 113 | bool setGPIO(_GPIO gpio, uint8_t uiData0, uint8_t uiData1 = NULL); |
x1dmoesc | 0:3835ff675f6b | 114 | bool setGPIO0_B0(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 115 | bool setGPIO0_B1(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 116 | bool setGPIO0_B2(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 117 | bool setGPIO0_B3(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 118 | bool setGPIO0_B4(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 119 | bool setGPIO0_B5(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 120 | bool setGPIO0_B6(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 121 | bool setGPIO0_B7(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 122 | |
x1dmoesc | 0:3835ff675f6b | 123 | bool setGPIO1_B0(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 124 | bool setGPIO1_B1(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 125 | bool setGPIO1_B2(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 126 | bool setGPIO1_B3(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 127 | bool setGPIO1_B4(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 128 | bool setGPIO1_B5(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 129 | bool setGPIO1_B6(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 130 | bool setGPIO1_B7(bool bBit); |
x1dmoesc | 0:3835ff675f6b | 131 | |
x1dmoesc | 0:3835ff675f6b | 132 | // variable |
x1dmoesc | 0:3835ff675f6b | 133 | static const _GPIO PORT0 = _PORT0; |
x1dmoesc | 0:3835ff675f6b | 134 | static const _GPIO PORT1 = _PORT1; |
x1dmoesc | 0:3835ff675f6b | 135 | static const _GPIO BOTH = _BOTH; |
x1dmoesc | 0:3835ff675f6b | 136 | |
x1dmoesc | 0:3835ff675f6b | 137 | GPIO GPIO0, GPIO1; |
x1dmoesc | 0:3835ff675f6b | 138 | |
x1dmoesc | 0:3835ff675f6b | 139 | |
x1dmoesc | 0:3835ff675f6b | 140 | //uint8_t uiGPIO0, uiGPIO1; |
x1dmoesc | 0:3835ff675f6b | 141 | |
x1dmoesc | 0:3835ff675f6b | 142 | |
x1dmoesc | 0:3835ff675f6b | 143 | private: |
x1dmoesc | 0:3835ff675f6b | 144 | // functions |
x1dmoesc | 0:3835ff675f6b | 145 | bool getGPIO(_GPIO gpio); |
x1dmoesc | 0:3835ff675f6b | 146 | |
x1dmoesc | 0:3835ff675f6b | 147 | // variable |
x1dmoesc | 0:3835ff675f6b | 148 | const uint8_t PCA9555_W; |
x1dmoesc | 0:3835ff675f6b | 149 | const uint8_t PCA9555_R; |
x1dmoesc | 0:3835ff675f6b | 150 | |
x1dmoesc | 0:3835ff675f6b | 151 | |
x1dmoesc | 0:3835ff675f6b | 152 | |
x1dmoesc | 0:3835ff675f6b | 153 | char cCmd[10]; |
x1dmoesc | 0:3835ff675f6b | 154 | bool bAck; |
x1dmoesc | 0:3835ff675f6b | 155 | |
x1dmoesc | 0:3835ff675f6b | 156 | // Class |
x1dmoesc | 0:3835ff675f6b | 157 | I2C *i2c; |
x1dmoesc | 0:3835ff675f6b | 158 | }; |
x1dmoesc | 0:3835ff675f6b | 159 | |
x1dmoesc | 0:3835ff675f6b | 160 | #endif |