I2Cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs

TCA6424A/TCA6424A.h
00001 // I2Cdev library collection - TCA6424A I2C device class header file
00002 // Based on Texas Instruments TCA6424A datasheet, 9/2010 (document SCPS193B)
00003 // 7/31/2011 by Jeff Rowberg <jeff@rowberg.net>
00004 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
00005 //
00006 // Changelog:
00007 //     2011-07-31 - initial release
00008 
00009 /* ============================================
00010 I2Cdev device library code is placed under the MIT license
00011 Copyright (c) 2011 Jeff Rowberg
00012 
00013 Permission is hereby granted, free of charge, to any person obtaining a copy
00014 of this software and associated documentation files (the "Software"), to deal
00015 in the Software without restriction, including without limitation the rights
00016 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00017 copies of the Software, and to permit persons to whom the Software is
00018 furnished to do so, subject to the following conditions:
00019 
00020 The above copyright notice and this permission notice shall be included in
00021 all copies or substantial portions of the Software.
00022 
00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00024 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00026 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00028 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00029 THE SOFTWARE.
00030 ===============================================
00031 */
00032 
00033 #ifndef _TCA6424A_H_
00034 #define _TCA6424A_H_
00035 
00036 #include "I2Cdev.h"
00037 
00038 #define TCA6424A_ADDRESS_ADDR_LOW   0x34 // address pin low (GND)
00039 #define TCA6424A_ADDRESS_ADDR_HIGH  0x35 // address pin high (VCC)
00040 #define TCA6424A_DEFAULT_ADDRESS    TCA6424A_ADDRESS_ADDR_LOW
00041 
00042 #define TCA6424A_RA_INPUT0          0x00
00043 #define TCA6424A_RA_INPUT1          0x01
00044 #define TCA6424A_RA_INPUT2          0x02
00045 #define TCA6424A_RA_OUTPUT0         0x04
00046 #define TCA6424A_RA_OUTPUT1         0x05
00047 #define TCA6424A_RA_OUTPUT2         0x06
00048 #define TCA6424A_RA_POLARITY0       0x08
00049 #define TCA6424A_RA_POLARITY1       0x09
00050 #define TCA6424A_RA_POLARITY2       0x0A
00051 #define TCA6424A_RA_CONFIG0         0x0C
00052 #define TCA6424A_RA_CONFIG1         0x0D
00053 #define TCA6424A_RA_CONFIG2         0x0E
00054 
00055 #define TCA6424A_AUTO_INCREMENT     0x80
00056 
00057 #define TCA6424A_LOW                0
00058 #define TCA6424A_HIGH               1
00059 
00060 #define TCA6424A_POLARITY_NORMAL    0
00061 #define TCA6424A_POLARITY_INVERTED  1
00062 
00063 #define TCA6424A_OUTPUT             0
00064 #define TCA6424A_INPUT              1
00065 
00066 #define TCA6424A_P00                0
00067 #define TCA6424A_P01                1
00068 #define TCA6424A_P02                2
00069 #define TCA6424A_P03                3
00070 #define TCA6424A_P04                4
00071 #define TCA6424A_P05                5
00072 #define TCA6424A_P06                6
00073 #define TCA6424A_P07                7
00074 #define TCA6424A_P10                8
00075 #define TCA6424A_P11                9
00076 #define TCA6424A_P12                10
00077 #define TCA6424A_P13                11
00078 #define TCA6424A_P14                12
00079 #define TCA6424A_P15                13
00080 #define TCA6424A_P16                14
00081 #define TCA6424A_P17                15
00082 #define TCA6424A_P20                16
00083 #define TCA6424A_P21                17
00084 #define TCA6424A_P22                18
00085 #define TCA6424A_P23                19
00086 #define TCA6424A_P24                20
00087 #define TCA6424A_P25                21
00088 #define TCA6424A_P26                22
00089 #define TCA6424A_P27                23
00090 
00091 class TCA6424A {
00092     public:
00093         TCA6424A();
00094         TCA6424A(uint8_t address);
00095         
00096         void initialize();
00097         bool testConnection();
00098         
00099         // INPUT* registers (x0h - x2h)
00100         bool readPin(uint16_t pin);
00101         uint8_t readBank(uint8_t bank);
00102         void readAll(uint8_t *banks);
00103         void readAll(uint8_t *bank0, uint8_t *bank1, uint8_t *bank2);
00104 
00105         // OUTPUT* registers (x4h - x6h)
00106         bool getPinOutputLevel(uint16_t pin);
00107         uint8_t getBankOutputLevel(uint8_t bank);
00108         void getAllOutputLevel(uint8_t *banks);
00109         void getAllOutputLevel(uint8_t *bank0, uint8_t *bank1, uint8_t *bank2);
00110         void writePin(uint16_t pin, bool polarity);
00111         void writeBank(uint8_t bank, uint8_t value);
00112         void writeAll(uint8_t *banks);
00113         void writeAll(uint8_t bank0, uint8_t bank1, uint8_t bank2);
00114 
00115         // POLARITY* registers (x8h - xAh)
00116         bool getPinPolarity(uint16_t pin);
00117         uint8_t getBankPolarity(uint8_t bank);
00118         void getAllPolarity(uint8_t *banks);
00119         void getAllPolarity(uint8_t *bank0, uint8_t *bank1, uint8_t *bank2);
00120         void setPinPolarity(uint16_t pin, bool polarity);
00121         void setBankPolarity(uint8_t bank, uint8_t polarity);
00122         void setAllPolarity(uint8_t *banks);
00123         void setAllPolarity(uint8_t bank0, uint8_t bank1, uint8_t bank2);
00124 
00125         // CONFIG* registers (xCh - xEh)
00126         bool getPinDirection(uint16_t pin);
00127         uint8_t getBankDirection(uint8_t bank);
00128         void getAllDirection(uint8_t *banks);
00129         void getAllDirection(uint8_t *bank0, uint8_t *bank1, uint8_t *bank2);
00130         void setPinDirection(uint16_t pin, bool direction);
00131         void setBankDirection(uint8_t bank, uint8_t direction);
00132         void setAllDirection(uint8_t *banks);
00133         void setAllDirection(uint8_t bank0, uint8_t bank1, uint8_t bank2);
00134 
00135     private:
00136         uint8_t devAddr;
00137         uint8_t buffer[3];
00138 };
00139 
00140 #endif /* _TCA6424A_H_ */
 All Data Structures Functions Variables