MAX14661 Serial Controlled 16:2 Multiplexer
Dependents: MBD2PMD_WebServer ARD2PMD_WebServer MAX14661_DEMO MAX3232_DEMO
Diff: MAX14661.cpp
- Revision:
- 0:6bd0b1a28e10
- Child:
- 2:c3525ee2d636
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MAX14661.cpp Mon Feb 03 04:14:24 2014 +0000 @@ -0,0 +1,60 @@ +/* MAX14661 Driver Library + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "MAX14661.h" +#include "mbed.h" + +MAX14661::MAX14661(PinName sda, PinName scl, int addr) : _i2c(sda, scl) +{ + _addr = addr; +} + +MAX14661::~MAX14661() +{ +} + +void MAX14661::clearAll() +{ + char data[3]; + data[0] = REG_CMD_A; + data[1] = CMD_DIS; + data[2] = CMD_DIS; + _i2c.write(_addr, data, 3); +} + +void MAX14661::setAB(int swA, int swB) +{ + char data[7]; + data[0] = REG_SHDW0; + data[1] = swA; + data[2] = swA >> 8; + data[3] = swB; + data[4] = swB >> 8; + data[5] = CMD_COPY; + data[6] = CMD_COPY; + _i2c.write(_addr, data, 7); +} + +int MAX14661::read() +{ + char data[4]; + data[0] = REG_DIR0; + _i2c.write(_addr, data, 1, true); + _i2c.read(_addr, data, 4); + return ((data[3] << 24) | (data[2] << 16) |(data[1] << 8) | data[0]); +}