Forked from romilly. Changed the way SPI handler is injected in constructor
Fork of MCP23S17 by
Diff: MCP23S17.cpp
- Revision:
- 8:841b19734955
- Parent:
- 7:53498e24592c
- Child:
- 9:068b1e8909bb
--- a/MCP23S17.cpp Sun Aug 22 15:37:25 2010 +0000 +++ b/MCP23S17.cpp Mon Aug 23 10:57:59 2010 +0000 @@ -2,7 +2,7 @@ * Copyright (c) 2010 Romilly Cocking * Released under the MIT License: http://mbed.org/license/mit * -* version 0.2 +* version 0.3 */ #include "mbed.h" @@ -23,6 +23,10 @@ return result; } +char MCP23S17::_read(Port port, char address) { + return _read(address + (char) port); +} + void MCP23S17::_write(char address, char data) { _ncs = 0; _spi.write(_writeOpcode); @@ -31,24 +35,21 @@ _ncs = 1; } +void MCP23S17::_write(Port port, char address, char data) { + _write(address + (char) port, data); +} + void MCP23S17::_init() { _write(IOCON, (IOCON_BYTE_MODE | IOCON_HAEN )); // Hardware addressing on, operations toggle between A and B registers } -void MCP23S17::directionA(char direction) { - _write(IODIRA, direction); +void MCP23S17::direction(Port port, char direction) { + _write(port, IODIRA, direction); } -void MCP23S17::directionB(char direction) { - _write(IODIRB, direction); -} -void MCP23S17::interruptEnableA(char interruptsEnabledMask) { - _write(GPINTENA, interruptsEnabledMask); -} - -void MCP23S17::interruptEnableB(char interruptsEnabledMask) { - _write(GPINTENB, interruptsEnabledMask); +void MCP23S17::interruptEnable(Port port, char interruptsEnabledMask) { + _write(port, GPINTENA, interruptsEnabledMask); } void MCP23S17::mirrorInterrupts(bool mirror) { @@ -72,26 +73,19 @@ _write(IOCON, iocon); } -void MCP23S17::defaultValueA(char valuesToCompare) { - _write(DEFVALA, valuesToCompare); +void MCP23S17::defaultValue(Port port, char valuesToCompare) { + _write(port, DEFVALA, valuesToCompare); } -void MCP23S17::interruptControlA(char interruptContolBits) { - _write(INTCONA, interruptContolBits); -} - -void MCP23S17::outputA(char byte) { - _write(OLATA, byte); +void MCP23S17::interruptControl(Port port, char interruptContolBits) { + _write(port, INTCONA, interruptContolBits); } -void MCP23S17::outputB(char byte) { - _write(OLATB, byte); +void MCP23S17::write(Port port, char byte) { + _write(port, OLATA, byte); } -char MCP23S17::inputA() { - return _read(GPIOA); +char MCP23S17::read(Port port) { + return _read(port, GPIOA); } -char MCP23S17::inputB() { - return _read(GPIOB); -}