Library with address set to hardware pins

Committer:
Bas
Date:
Sat Sep 08 22:12:10 2012 +0000
Revision:
0:95cf83ce54ec
Name changes in WriteBytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bas 0:95cf83ce54ec 1 /*
Bas 0:95cf83ce54ec 2 * PCF8575 Remote 16-bit I/O expander for I2C-bus
Bas 0:95cf83ce54ec 3 * Copyright (c) 2012 Bas van Drunen Littel
Bas 0:95cf83ce54ec 4 *
Bas 0:95cf83ce54ec 5 * Permission is hereby granted, free of charge, to any person obtaining a copy
Bas 0:95cf83ce54ec 6 * of this software and associated documentation files (the "Software"), to deal
Bas 0:95cf83ce54ec 7 * in the Software without restriction, including without limitation the rights
Bas 0:95cf83ce54ec 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Bas 0:95cf83ce54ec 9 * copies of the Software, and to permit persons to whom the Software is
Bas 0:95cf83ce54ec 10 * furnished to do so, subject to the following conditions:
Bas 0:95cf83ce54ec 11 *
Bas 0:95cf83ce54ec 12 * The above copyright notice and this permission notice shall be included in
Bas 0:95cf83ce54ec 13 * all copies or substantial portions of the Software.
Bas 0:95cf83ce54ec 14 *
Bas 0:95cf83ce54ec 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Bas 0:95cf83ce54ec 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Bas 0:95cf83ce54ec 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Bas 0:95cf83ce54ec 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Bas 0:95cf83ce54ec 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Bas 0:95cf83ce54ec 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Bas 0:95cf83ce54ec 21 * THE SOFTWARE.
Bas 0:95cf83ce54ec 22 */
Bas 0:95cf83ce54ec 23
Bas 0:95cf83ce54ec 24 #include "pcf8575.h"
Bas 0:95cf83ce54ec 25
Bas 0:95cf83ce54ec 26 PCF8575::PCF8575(I2C* _interface, unsigned char _chipselect)
Bas 0:95cf83ce54ec 27 : i2c(_interface)
Bas 0:95cf83ce54ec 28 {
Bas 0:95cf83ce54ec 29 address = (_chipselect << 1) | PCF8575_I2C_ADDRESS;
Bas 0:95cf83ce54ec 30 }
Bas 0:95cf83ce54ec 31
Bas 0:95cf83ce54ec 32 PCF8575::~PCF8575() {}
Bas 0:95cf83ce54ec 33
Bas 0:95cf83ce54ec 34 unsigned short PCF8575::ReadBytes()
Bas 0:95cf83ce54ec 35 {
Bas 0:95cf83ce54ec 36 char data[2];
Bas 0:95cf83ce54ec 37 i2c->read(address,data,2);
Bas 0:95cf83ce54ec 38 return (data[1]<<8) | data[0];
Bas 0:95cf83ce54ec 39 }
Bas 0:95cf83ce54ec 40
Bas 0:95cf83ce54ec 41 void PCF8575::WriteBytes(unsigned short bytes)
Bas 0:95cf83ce54ec 42 {
Bas 0:95cf83ce54ec 43 char data[2];
Bas 0:95cf83ce54ec 44
Bas 0:95cf83ce54ec 45 data[0] = bytes & 0xFF;
Bas 0:95cf83ce54ec 46 data[1] = bytes>> 8;
Bas 0:95cf83ce54ec 47 i2c->write(address,data,2);
Bas 0:95cf83ce54ec 48 }
Bas 0:95cf83ce54ec 49
Bas 0:95cf83ce54ec 50 void PCF8575::WriteBytes(unsigned char byte0, unsigned char byte1)
Bas 0:95cf83ce54ec 51 {
Bas 0:95cf83ce54ec 52 char data[2];
Bas 0:95cf83ce54ec 53
Bas 0:95cf83ce54ec 54 data[0] = byte0;
Bas 0:95cf83ce54ec 55 data[1] = byte1;
Bas 0:95cf83ce54ec 56 i2c->write(address,data,2);
Bas 0:95cf83ce54ec 57 }