PCF8574 I2C IO Expander Interface

Dependents:   PCF8574_HelloWorld PCF8574_I2C_4x4_Keypad PCF8574_I2C_4x4_Keypad_interface PCF8574_ButtonPress

Committer:
simon
Date:
Thu Jun 03 13:00:49 2010 +0000
Revision:
1:ec8da0c59403
Parent:
0:ab4e14b911ee

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:ab4e14b911ee 1 /* mbed PCF8574 Library, for driving the I2C I/O Expander
simon 0:ab4e14b911ee 2 * Copyright (c) 2008-2010, cstyles, sford
simon 0:ab4e14b911ee 3 *
simon 0:ab4e14b911ee 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 0:ab4e14b911ee 5 * of this software and associated documentation files (the "Software"), to deal
simon 0:ab4e14b911ee 6 * in the Software without restriction, including without limitation the rights
simon 0:ab4e14b911ee 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 0:ab4e14b911ee 8 * copies of the Software, and to permit persons to whom the Software is
simon 0:ab4e14b911ee 9 * furnished to do so, subject to the following conditions:
simon 0:ab4e14b911ee 10 *
simon 0:ab4e14b911ee 11 * The above copyright notice and this permission notice shall be included in
simon 0:ab4e14b911ee 12 * all copies or substantial portions of the Software.
simon 0:ab4e14b911ee 13 *
simon 0:ab4e14b911ee 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 0:ab4e14b911ee 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 0:ab4e14b911ee 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 0:ab4e14b911ee 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 0:ab4e14b911ee 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 0:ab4e14b911ee 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 0:ab4e14b911ee 20 * THE SOFTWARE.
simon 0:ab4e14b911ee 21 */
simon 0:ab4e14b911ee 22
simon 0:ab4e14b911ee 23 #include "mbed.h"
simon 0:ab4e14b911ee 24
simon 0:ab4e14b911ee 25 #ifndef MBED_PCF8574_H
simon 0:ab4e14b911ee 26 #define MBED_PCF8574_H
simon 0:ab4e14b911ee 27
simon 0:ab4e14b911ee 28 /** Interface to the popular PCF8574 I2C 8 Bit IO expander */
simon 0:ab4e14b911ee 29 class PCF8574 {
simon 0:ab4e14b911ee 30 public:
simon 0:ab4e14b911ee 31 /** Create an instance of the PCF8574 connected to specfied I2C pins, with the specified address.
simon 0:ab4e14b911ee 32 *
simon 0:ab4e14b911ee 33 * @param sda The I2C data pin
simon 0:ab4e14b911ee 34 * @param scl The I2C clock pin
simon 0:ab4e14b911ee 35 * @param address The I2C address for this PCF8574
simon 0:ab4e14b911ee 36 */
simon 0:ab4e14b911ee 37 PCF8574(PinName sda, PinName scl, int address);
simon 0:ab4e14b911ee 38
simon 0:ab4e14b911ee 39 /** Read the IO pin level
simon 0:ab4e14b911ee 40 *
simon 0:ab4e14b911ee 41 * @return The byte read
simon 0:ab4e14b911ee 42 */
simon 0:ab4e14b911ee 43 int read();
simon 0:ab4e14b911ee 44
simon 0:ab4e14b911ee 45 /** Write to the IO pins
simon 0:ab4e14b911ee 46 *
simon 0:ab4e14b911ee 47 * @param data The 8 bits to write to the IO port
simon 0:ab4e14b911ee 48 */
simon 0:ab4e14b911ee 49 void write(int data);
simon 0:ab4e14b911ee 50
simon 0:ab4e14b911ee 51 private:
simon 0:ab4e14b911ee 52 I2C _i2c;
simon 0:ab4e14b911ee 53 int _address;
simon 0:ab4e14b911ee 54 };
simon 0:ab4e14b911ee 55
simon 0:ab4e14b911ee 56 #endif