Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PCF8574.h@3:47c298d4a41b, 2022-01-31 (annotated)
- Committer:
- JohnnyK
- Date:
- Mon Jan 31 18:26:50 2022 +0000
- Revision:
- 3:47c298d4a41b
- Parent:
- 2:e076d7b30aea
- Child:
- 4:f93baeb6119c
Added Namespace IO for compatibility with TextLCD library
Who changed what in which revision?
User | Revision | Line number | New 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 |
JohnnyK | 2:e076d7b30aea | 3 | * 2022, 001: JohnnyK, Reworked Constructor to I2C object instead of I2C pins. I can be usefull with anoter I2C slave on same bus |
JohnnyK | 3:47c298d4a41b | 4 | * 2022, 002: JohnnyK, Added Namespace IO for compatibility with TextLCD library |
simon | 0:ab4e14b911ee | 5 | * |
simon | 0:ab4e14b911ee | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 0:ab4e14b911ee | 7 | * of this software and associated documentation files (the "Software"), to deal |
simon | 0:ab4e14b911ee | 8 | * in the Software without restriction, including without limitation the rights |
simon | 0:ab4e14b911ee | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 0:ab4e14b911ee | 10 | * copies of the Software, and to permit persons to whom the Software is |
simon | 0:ab4e14b911ee | 11 | * furnished to do so, subject to the following conditions: |
simon | 0:ab4e14b911ee | 12 | * |
simon | 0:ab4e14b911ee | 13 | * The above copyright notice and this permission notice shall be included in |
simon | 0:ab4e14b911ee | 14 | * all copies or substantial portions of the Software. |
simon | 0:ab4e14b911ee | 15 | * |
simon | 0:ab4e14b911ee | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 0:ab4e14b911ee | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 0:ab4e14b911ee | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 0:ab4e14b911ee | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 0:ab4e14b911ee | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 0:ab4e14b911ee | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 0:ab4e14b911ee | 22 | * THE SOFTWARE. |
simon | 0:ab4e14b911ee | 23 | */ |
simon | 0:ab4e14b911ee | 24 | |
simon | 0:ab4e14b911ee | 25 | #include "mbed.h" |
simon | 0:ab4e14b911ee | 26 | |
simon | 0:ab4e14b911ee | 27 | #ifndef MBED_PCF8574_H |
simon | 0:ab4e14b911ee | 28 | #define MBED_PCF8574_H |
simon | 0:ab4e14b911ee | 29 | |
JohnnyK | 3:47c298d4a41b | 30 | namespace IO{ |
simon | 0:ab4e14b911ee | 31 | |
JohnnyK | 3:47c298d4a41b | 32 | /** Interface to the popular PCF8574 I2C 8 Bit IO expander */ |
JohnnyK | 3:47c298d4a41b | 33 | class PCF8574 { |
JohnnyK | 3:47c298d4a41b | 34 | public: |
JohnnyK | 3:47c298d4a41b | 35 | /** Create an instance of the PCF8574 connected I2C object, with the specified address. |
JohnnyK | 3:47c298d4a41b | 36 | * |
JohnnyK | 3:47c298d4a41b | 37 | * @param Mbed I2C object |
JohnnyK | 3:47c298d4a41b | 38 | * @param address The I2C address for this PCF8574 |
JohnnyK | 3:47c298d4a41b | 39 | */ |
JohnnyK | 3:47c298d4a41b | 40 | PCF8574(I2C *i2c, int address); |
JohnnyK | 3:47c298d4a41b | 41 | |
JohnnyK | 3:47c298d4a41b | 42 | /** Read the IO pin level |
JohnnyK | 3:47c298d4a41b | 43 | * |
JohnnyK | 3:47c298d4a41b | 44 | * @return The byte read |
JohnnyK | 3:47c298d4a41b | 45 | */ |
JohnnyK | 3:47c298d4a41b | 46 | int read(); |
JohnnyK | 3:47c298d4a41b | 47 | |
JohnnyK | 3:47c298d4a41b | 48 | /** Write to the IO pins |
JohnnyK | 3:47c298d4a41b | 49 | * |
JohnnyK | 3:47c298d4a41b | 50 | * @param data The 8 bits to write to the IO port |
JohnnyK | 3:47c298d4a41b | 51 | */ |
JohnnyK | 3:47c298d4a41b | 52 | void write(int data); |
JohnnyK | 3:47c298d4a41b | 53 | |
JohnnyK | 3:47c298d4a41b | 54 | private: |
JohnnyK | 3:47c298d4a41b | 55 | I2C *_i2c; |
JohnnyK | 3:47c298d4a41b | 56 | int _address; |
JohnnyK | 3:47c298d4a41b | 57 | }; |
JohnnyK | 3:47c298d4a41b | 58 | } |
simon | 0:ab4e14b911ee | 59 | |
simon | 0:ab4e14b911ee | 60 | #endif |