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