Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
mcp23s17.hpp
1 /*
2  Title --- driver/mcp23s17.hpp
3 
4  Copyright (C) 2013 Giacomo Trudu - wicker25[at]gmail[dot]com
5 
6  This file is part of Rpi-hw.
7 
8  Rpi-hw is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation version 3 of the License.
11 
12  Rpi-hw is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with Rpi-hw. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef _RPI_HW_DRIVER_MCP23S17_HPP_
23 #define _RPI_HW_DRIVER_MCP23S17_HPP_
24 
25 #include <rpi-hw/rpi.hpp>
26 
27 #include <rpi-hw/consts.hpp>
28 #include <rpi-hw/types.hpp>
29 #include <rpi-hw/exception.hpp>
30 #include <rpi-hw/utils.hpp>
31 
32 #include <rpi-hw/driver/spi.hpp>
33 #include <rpi-hw/driver/mcp23x17.hpp>
34 
35 namespace rpihw { // Begin main namespace
36 
37 namespace driver { // Begin drivers namespace
38 
39 /*!
40  @class mcp23s17
41  @brief 16-bit I/O Expander with SPI.
42 
43  @example driver/mcp23s17.cpp
44 */
45 class mcp23s17 : public mcp23x17 {
46 
47 public:
48 
49  /*!
50  @brief Constructor method.
51  @param[in] dev_path The device path.
52  @param[in] dev_id The device identifier.
53  */
54  mcp23s17( const std::string &dev_path, uint8_t dev_id );
55 
56  //! Destructor method.
57  virtual ~mcp23s17();
58 
59 private:
60 
61  //! Serial Peripheral Interface.
63 
64  //! Device identifier.
65  uint8_t m_dev_id;
66 
67  //! Data buffer used for SPI transmission.
68  uint8_t m_buffer[3];
69 
70  //! Sends data to the device.
71  virtual void send( uint8_t reg, uint8_t data );
72 
73  //! Receives data from the device.
74  virtual uint8_t receive( uint8_t reg );
75 };
76 
77 } // End of drivers namespace
78 
79 } // End of main namespace
80 
81 
82 // Include inline methods
83 #include <rpi-hw/driver/mcp23s17-inl.hpp>
84 
85 #endif /* _RPI_HW_DRIVER_MCP23S17_HPP_ */
16-bit I/O Expander with SPI.
Definition: mcp23s17.hpp:45
mcp23s17(const std::string &dev_path, uint8_t dev_id)
Constructor method.
driver::spi * m_spi
Serial Peripheral Interface.
Definition: mcp23s17.hpp:62
uint8_t m_dev_id
Device identifier.
Definition: mcp23s17.hpp:65
virtual uint8_t receive(uint8_t reg)
Receives data from the device.
virtual ~mcp23s17()
Destructor method.
Serial Peripheral Interface.
Definition: spi.hpp:45
16-bit I/O Expander with SPI/I2C (skeleton).
Definition: mcp23x17.hpp:42
uint8_t m_buffer[3]
Data buffer used for SPI transmission.
Definition: mcp23s17.hpp:68
virtual void send(uint8_t reg, uint8_t data)
Sends data to the device.