Jan Kamidra / PCF8574
Committer:
JohnnyK
Date:
Mon Jan 31 17:49:53 2022 +0000
Revision:
2:e076d7b30aea
Parent:
1:ec8da0c59403
Child:
3:47c298d4a41b
Reworked Constructor to I2C object instead of I2C pins. I can be usefull with anoter I2C slave on same bus

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
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
simon 0:ab4e14b911ee 4 *
simon 0:ab4e14b911ee 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 0:ab4e14b911ee 6 * of this software and associated documentation files (the "Software"), to deal
simon 0:ab4e14b911ee 7 * in the Software without restriction, including without limitation the rights
simon 0:ab4e14b911ee 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 0:ab4e14b911ee 9 * copies of the Software, and to permit persons to whom the Software is
simon 0:ab4e14b911ee 10 * furnished to do so, subject to the following conditions:
simon 0:ab4e14b911ee 11 *
simon 0:ab4e14b911ee 12 * The above copyright notice and this permission notice shall be included in
simon 0:ab4e14b911ee 13 * all copies or substantial portions of the Software.
simon 0:ab4e14b911ee 14 *
simon 0:ab4e14b911ee 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 0:ab4e14b911ee 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 0:ab4e14b911ee 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 0:ab4e14b911ee 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 0:ab4e14b911ee 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 0:ab4e14b911ee 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 0:ab4e14b911ee 21 * THE SOFTWARE.
simon 0:ab4e14b911ee 22 */
simon 0:ab4e14b911ee 23
simon 0:ab4e14b911ee 24 #include "PCF8574.h"
simon 0:ab4e14b911ee 25 #include "mbed.h"
simon 0:ab4e14b911ee 26
JohnnyK 2:e076d7b30aea 27 PCF8574::PCF8574(I2C *i2c, int address)
JohnnyK 2:e076d7b30aea 28 : _i2c(i2c) {
simon 0:ab4e14b911ee 29 _address = address;
simon 0:ab4e14b911ee 30 }
simon 0:ab4e14b911ee 31
simon 0:ab4e14b911ee 32 int PCF8574::read() {
simon 0:ab4e14b911ee 33 char foo[1];
JohnnyK 2:e076d7b30aea 34 _i2c->read(_address, foo, 1);
simon 0:ab4e14b911ee 35 return foo[0];
simon 0:ab4e14b911ee 36 }
simon 0:ab4e14b911ee 37
simon 0:ab4e14b911ee 38 void PCF8574::write(int data) {
simon 0:ab4e14b911ee 39 char foo[1];
simon 0:ab4e14b911ee 40 foo[0] = data;
JohnnyK 2:e076d7b30aea 41 _i2c->write(_address, foo, 1);
simon 0:ab4e14b911ee 42 }