A Library for MCP3008
Dependents: Nucleo_MCP3008_Test ProjetoBB KIK01 MASTER_SPI_MCP3008
Revision 3:a9e08cdf0b95, committed 2017-06-30
- Comitter:
- ryood
- Date:
- Fri Jun 30 15:58:59 2017 +0000
- Parent:
- 2:96130c28149e
- Commit message:
- SPI object as a pointer
Changed in this revision
mcp3008.cpp | Show annotated file Show diff for this revision Revisions of this file |
mcp3008.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 96130c28149e -r a9e08cdf0b95 mcp3008.cpp --- a/mcp3008.cpp Sun Jun 18 19:58:42 2017 +0000 +++ b/mcp3008.cpp Fri Jun 30 15:58:59 2017 +0000 @@ -6,8 +6,8 @@ #define MODE_DIFF 0x00 // Differential mode -MCP3008::MCP3008(SPI bus, PinName cs) - : m_cs(cs), m_bus(bus) +MCP3008::MCP3008(SPI* p_bus, PinName cs) + : m_cs(cs), m_p_bus(p_bus) { deselect(); } @@ -37,9 +37,9 @@ select(); // Odd writing requirements, see the datasheet for details - m_bus.write(command_high); - int high_byte = m_bus.write(command_low) & 0x03; - int low_byte = m_bus.write(0); + m_p_bus->write(command_high); + int high_byte = m_p_bus->write(command_low) & 0x03; + int low_byte = m_p_bus->write(0); deselect(); @@ -61,9 +61,9 @@ select(); // Odd writing and reading requirements, see the datasheet for details. - m_bus.write(command_high); - int high_byte = m_bus.write(command_low) & 0x03; - int low_byte = m_bus.write(0); + m_p_bus->write(command_high); + int high_byte = m_p_bus->write(command_low) & 0x03; + int low_byte = m_p_bus->write(0); deselect();
diff -r 96130c28149e -r a9e08cdf0b95 mcp3008.h --- a/mcp3008.h Sun Jun 18 19:58:42 2017 +0000 +++ b/mcp3008.h Fri Jun 30 15:58:59 2017 +0000 @@ -31,7 +31,7 @@ * @param bus An SPI bus object. * @param cs The name of a pin to use as the chip select. */ - MCP3008(SPI bus, PinName cs); + MCP3008(SPI* p_bus, PinName cs); ~MCP3008(); /** Read from a single-ended input. @@ -66,7 +66,7 @@ private: DigitalOut m_cs; - SPI m_bus; + SPI* m_p_bus; void select(); void deselect();