NXP PCA9544A device driver: 4-channel I2C-bus multiplexer with interrupt logic
Diff: pca9544a.h
- Revision:
- 1:4d19097c0571
- Parent:
- 0:905d325977dc
diff -r 905d325977dc -r 4d19097c0571 pca9544a.h --- a/pca9544a.h Tue Sep 12 17:16:49 2017 +0000 +++ b/pca9544a.h Thu Sep 14 00:20:01 2017 +0000 @@ -1,8 +1,58 @@ -// NXP PCA9544A: 8-channel I2C switch with reset +/* mbed Microcontroller Library + * Copyright (c) 2017 AT&T, IIoT Foundry, Plano, TX, USA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** \addtogroup drivers */ + +/** Support for the NXP PCA9544A 4-channel I2C switch. + * + * Example: + * @code + * + * #include "mbed.h" + * #include "PCA9544A.h" + * + * // PCA9544A strapped for address option 0 (7-bit I2C address 0x70) + * + * I2C i2c(I2C_SDA, I2C_SCL); + * PCA9544A<I2C> pca9544a(&i2c, 0); + * + * int main() { + * bool ok; + * + * // Enable channel 1 + * bool ok = _pca9544a->select_channel(1); + * if (ok) { + * printf("I2C device on channel 1 is now accessible\r\n); + * } else { + * printf("pca9544a error!\r\n"); + * } + * + * // Disconnect all downstream devices from the I2C bus + * _pca9544a->reset(); + * } + * @endcode + * @ingroup drivers + */ + +#pragma once #define PCA9544A_BASE_ADDR_7BIT 0x70 #define MAX_CHANNELS 4 +template <class T> class PCA9544A { public: @@ -13,7 +63,7 @@ * @param addr_3bit address of the multiplexer (A0-A2 pin strapping) * Valid values are 0-7 */ - PCA9544A(I2C * i2c, uint8_t addr_3bit) : _i2c(i2c) { + PCA9544A(T * i2c, uint8_t addr_3bit) : _i2c(i2c) { _addr_8bit = ((addr_3bit & 0x7) + PCA9544A_BASE_ADDR_7BIT) << 1; } @@ -47,6 +97,7 @@ } protected: - int _addr_8bit; - I2C * _i2c; + int _addr_8bit; + T *_i2c; }; +