Jan Kamidra / PCF8574
Committer:
JohnnyK
Date:
Mon Jan 31 18:39:48 2022 +0000
Revision:
4:f93baeb6119c
Parent:
3:47c298d4a41b
Changed class name for compatibility with TextLCD library

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
JohnnyK 4:f93baeb6119c 4 * 2022, 002: JohnnyK, Changed class name 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 "PCF8574.h"
simon 0:ab4e14b911ee 26 #include "mbed.h"
simon 0:ab4e14b911ee 27
JohnnyK 4:f93baeb6119c 28 PCF8574IO::PCF8574IO(I2C *i2c, int address)
JohnnyK 2:e076d7b30aea 29 : _i2c(i2c) {
simon 0:ab4e14b911ee 30 _address = address;
simon 0:ab4e14b911ee 31 }
simon 0:ab4e14b911ee 32
JohnnyK 4:f93baeb6119c 33 int PCF8574IO::read() {
simon 0:ab4e14b911ee 34 char foo[1];
JohnnyK 2:e076d7b30aea 35 _i2c->read(_address, foo, 1);
simon 0:ab4e14b911ee 36 return foo[0];
simon 0:ab4e14b911ee 37 }
simon 0:ab4e14b911ee 38
JohnnyK 4:f93baeb6119c 39 void PCF8574IO::write(int data) {
simon 0:ab4e14b911ee 40 char foo[1];
simon 0:ab4e14b911ee 41 foo[0] = data;
JohnnyK 2:e076d7b30aea 42 _i2c->write(_address, foo, 1);
simon 0:ab4e14b911ee 43 }