Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
io-expander.hpp
1 /*
2  Title --- driver/io-expander.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_IO_EXPANDER_HPP_
23 #define _RPI_HW_DRIVER_IO_EXPANDER_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 namespace rpihw { // Begin main namespace
33 
34 namespace driver { // Begin drivers namespace
35 
36 /*!
37  @class io_expander
38  @brief GPIO controller.
39 */
40 class io_expander {
41 
42 public:
43 
44  /*!
45  @brief Sets the mode of a GPIO pin.
46  @param[in] pin The GPIO pin.
47  @param[in] mode The GPIO mode.
48  @param[in] pull_mode The pull resistor mode.
49  */
50  virtual void setup( uint8_t pin, uint8_t mode, uint8_t pull_mode = PULL_OFF );
51 
52  /*!
53  @brief Sets the value of a output pin.
54  @param[in] pin The output pin.
55  @param[in] value The value of output pin.
56  */
57  virtual void write( uint8_t pin, bool value );
58 
59  /*!
60  @brief Returns the value of a input pin.
61  @param[in] pin The input pin.
62  @return The value of input pin.
63  */
64  virtual bool read( uint8_t pin );
65 
66  /*!
67  @brief Returns the event state of a GPIO pin.
68  @param[in] pin The GPIO pin.
69  @return The event state.
70  */
71  virtual bool checkEvent( uint8_t pin );
72 
73  /*!
74  @brief Enables/disables the rising edge event on a GPIO pin.
75  @param[in] pin The GPIO pin.
76  @param[in] enabled If \c true enable the rising edge event.
77  */
78  virtual void setRisingEvent( uint8_t pin, bool enabled );
79 
80  /*!
81  @brief Enables/disables the falling edge event on a GPIO pin.
82  @param[in] pin The GPIO pin.
83  @param[in] enabled If \c true enable the falling edge event.
84  */
85  virtual void setFallingEvent( uint8_t pin, bool enabled );
86 
87  /*!
88  @brief Enables/disables the high event on a GPIO pin.
89  @param[in] pin The GPIO pin.
90  @param[in] enabled If \c true enable the high event.
91  */
92  virtual void setHighEvent( uint8_t pin, bool enabled );
93 
94  /*!
95  @brief Enables/disables the low event on a GPIO pin.
96  @param[in] pin The GPIO pin.
97  @param[in] enabled If \c true enable the low event.
98  */
99  virtual void setLowEvent( uint8_t pin, bool enabled );
100 
101  /*!
102  @brief Enables/disables the pull-up/down control on a GPIO pin.
103  @param[in] pin The GPIO pin.
104  @param[in] mode The pull resistor mode.
105  */
106  virtual void setPullUpDown( uint8_t pin, uint8_t mode );
107 };
108 
109 } // End of drivers namespace
110 
111 } // End of main namespace
112 
113 
114 // Include inline methods
115 #include <rpi-hw/driver/io-expander-inl.hpp>
116 
117 #endif /* _RPI_HW_DRIVER_IO_EXPANDER_HPP_ */
virtual void setFallingEvent(uint8_t pin, bool enabled)
Enables/disables the falling edge event on a GPIO pin.
virtual void setPullUpDown(uint8_t pin, uint8_t mode)
Enables/disables the pull-up/down control on a GPIO pin.
virtual bool checkEvent(uint8_t pin)
Returns the event state of a GPIO pin.
virtual void setup(uint8_t pin, uint8_t mode, uint8_t pull_mode=PULL_OFF)
Sets the mode of a GPIO pin.
virtual void write(uint8_t pin, bool value)
Sets the value of a output pin.
virtual bool read(uint8_t pin)
Returns the value of a input pin.
virtual void setLowEvent(uint8_t pin, bool enabled)
Enables/disables the low event on a GPIO pin.
virtual void setHighEvent(uint8_t pin, bool enabled)
Enables/disables the high event on a GPIO pin.
virtual void setRisingEvent(uint8_t pin, bool enabled)
Enables/disables the rising edge event on a GPIO pin.