Forked from romilly. Changed the way SPI handler is injected in constructor
Fork of MCP23S17 by
Revision 10:ca0429a15915, committed 2014-03-02
- Comitter:
- wyunreal
- Date:
- Sun Mar 02 18:15:17 2014 +0000
- Parent:
- 9:068b1e8909bb
- Commit message:
- changing the spi reference by an spi pointer in constructor
Changed in this revision
MCP23S17.cpp | Show annotated file Show diff for this revision Revisions of this file |
MCP23S17.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 068b1e8909bb -r ca0429a15915 MCP23S17.cpp --- a/MCP23S17.cpp Sat Aug 28 09:48:38 2010 +0000 +++ b/MCP23S17.cpp Sun Mar 02 18:15:17 2014 +0000 @@ -8,7 +8,8 @@ #include "mbed.h" #include "MCP23S17.h" -MCP23S17::MCP23S17(SPI& spi, PinName ncs, char writeOpcode) : _spi(spi), _ncs(ncs) { +MCP23S17::MCP23S17(SPI* spi, PinName ncs, char writeOpcode) : _ncs(ncs) { + _spi = spi; _writeOpcode = writeOpcode; _readOpcode = _writeOpcode | 1; // low order bit = 1 for read _init(); @@ -16,9 +17,9 @@ char MCP23S17::_read(char address) { _ncs = 0; - _spi.write(_readOpcode); - _spi.write(address); - char result = _spi.write(0); + _spi->write(_readOpcode); + _spi->write(address); + char result = _spi->write(0); _ncs = 1; return result; } @@ -29,9 +30,9 @@ void MCP23S17::_write(char address, char data) { _ncs = 0; - _spi.write(_writeOpcode); - _spi.write(address); - _spi.write(data); + _spi->write(_writeOpcode); + _spi->write(address); + _spi->write(data); _ncs = 1; }
diff -r 068b1e8909bb -r ca0429a15915 MCP23S17.h --- a/MCP23S17.h Sat Aug 28 09:48:38 2010 +0000 +++ b/MCP23S17.h Sun Mar 02 18:15:17 2014 +0000 @@ -34,7 +34,7 @@ class MCP23S17 { public: - MCP23S17(SPI& spi, PinName ncs, char writeOpcode); + MCP23S17(SPI* spi, PinName ncs, char writeOpcode); void direction(Port port, char direction); void configurePullUps(Port port, char offOrOn); void interruptEnable(Port port, char interruptsEnabledMask); @@ -45,7 +45,7 @@ char read(Port port); void write(Port port, char byte); protected: - SPI& _spi; + SPI* _spi; DigitalOut _ncs; void _init(); void _write(Port port, char address, char data);