none

Committer:
dimavb
Date:
Sun Jun 02 14:42:06 2019 +0000
Revision:
6:34744274e63e
Parent:
5:e5bb35ac2c61
start

Who changed what in which revision?

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