Laelaps  2.3.5
RoadNarrows Robotics Small Outdoor Mobile Robot Project
laeGpio.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: Laelasp
4 //
5 // Library: liblaelaps
6 //
7 // File: laeGpio.h
8 //
9 /*! \file
10  *
11  * $LastChangedDate: 2016-01-21 16:50:25 -0700 (Thu, 21 Jan 2016) $
12  * $Rev: 4268 $
13  *
14  * \brief Laelaps Odroid General Purpose I/O class interfaces.
15  *
16  * \author Robin Knight (robin.knight@roadnarrows.com)
17  *
18  * \par Copyright
19  * \h_copy 2015-2017. RoadNarrows LLC.\n
20  * http://www.roadnarrows.com\n
21  * All Rights Reserved
22  */
23 /*
24  * @EulaBegin@
25  *
26  * Unless otherwise stated explicitly, all materials contained are copyrighted
27  * and may not be used without RoadNarrows LLC's written consent,
28  * except as provided in these terms and conditions or in the copyright
29  * notice (documents and software) or other proprietary notice provided with
30  * the relevant materials.
31  *
32  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY
33  * MEMBERS/EMPLOYEES/CONTRACTORS OF ROADNARROWS OR DISTRIBUTORS OF THIS SOFTWARE
34  * BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR
35  * CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
36  * DOCUMENTATION, EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *
39  * THE AUTHORS AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
40  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
41  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
42  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
43  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
44  *
45  * @EulaEnd@
46  */
47 ////////////////////////////////////////////////////////////////////////////////
48 
49 #ifndef _LAE_GPIO_H
50 #define _LAE_GPIO_H
51 
52 #include <sys/types.h>
53 
54 #include <string>
55 
56 #include "rnr/rnrconfig.h"
57 #include "rnr/gpio.h"
58 #include "rnr/log.h"
59 
60 #include "Laelaps/laelaps.h"
61 #include "Laelaps/laeSysDev.h"
62 
63 namespace laelaps
64 {
65  // ---------------------------------------------------------------------------
66  // LaeGpio Class
67  // ---------------------------------------------------------------------------
68 
69  /*!
70  * \brief Laelaps Odroid GPIO base class.
71  *
72  * \note The configuration of the GPIO is assumed done elsewhere
73  * (e.g. at system initialization time).
74  */
75  class LaeGpio
76  {
77  public:
78  /*!
79  * \brief GPIO tri-state value.
80  */
81  enum TriState
82  {
83  UNKNOWN = -1, ///< unknown state value
84  LOW = 0, ///< low value
85  HIGH = 1 ///< high value
86  };
87 
88  /*!
89  * \brief GPIO direction.
90  */
91  enum Direction
92  {
93  INPUT = GPIO_DIR_IN, ///< input direction
94  OUTPUT = GPIO_DIR_OUT ///< output direction
95  };
96 
97  /*!
98  * \brief Default intialization constructor.
99  *
100  * No file I/O operations are perform.
101  *
102  * \param strTag Tag identifier associated with GPIO pin.
103  * \param gpio Exported GPIO number.
104  * \param dir GPIO direction.
105  */
106  LaeGpio(const std::string &strTag,
107  const int gpio,
108  const LaeGpio::Direction dir);
109 
110  /*!
111  * \brief Destructor.
112  */
113  virtual ~LaeGpio()
114  {
115  }
116 
117  /*!
118  * \brief Synchronized this with GPIO hardware state.
119  */
120  virtual void sync();
121 
122  /*!
123  * \brief Write value to gpio.
124  *
125  * \param value LOW/HIGH tri-state value.
126  *
127  * \copydoc doc_return_std
128  */
129  virtual int writeValue(const LaeGpio::TriState value)
130  {
131  return writeValue((const int)value);
132  }
133 
134  /*!
135  * \brief Write value to gpio.
136  *
137  * \param value LOW/HIGH integer value.
138  *
139  * \copydoc doc_return_std
140  */
141  virtual int writeValue(const int value);
142 
143  /*!
144  * \brief Read current value of gpio.
145  *
146  * \param [out] value LOW/HIGH integer value.
147  *
148  * \copydoc doc_return_std
149  */
150  virtual int readValue(int &value);
151 
152  /*!
153  * \brief Get the current shadowed gpio value.
154  *
155  * \return Returns LaeGpio::TriState value as an integer.
156  */
157  int hasValue() const
158  {
159  return m_gpioVal;
160  }
161 
162  /*!
163  * \brief Is the exported GPIO number configured to match this ojbect?
164  *
165  * Ass Laelaps evolves, the test can distinguish between different platform
166  * versions. For example, Laelaps 2.0 does not have a gpio pin dedicated
167  * to enabling power to the motor controllers, while subsequent version do.
168  *
169  * \return Returns true or false.
170  */
171  bool isConfigured() const
172  {
173  return m_gpioCfg;
174  }
175 
176  protected:
177  std::string m_gpioTag; ///< identifying tag
178  int m_gpioNum; ///< exported GPIO number
179  LaeGpio::Direction m_gpioDir; ///< GPIO direction
180  int m_gpioVal; ///< shadowed value
181  bool m_gpioCfg; ///< GPIO is [not] configured (correctly)
182 
183  /*!
184  * \brief Check if the exported GPIO exists in /sys/class and that it has
185  * been configured to match this objects configuration.
186  *
187  * \return Returns true or false.
188  */
189  bool checkConfig();
190  };
191 
192 
193  // ---------------------------------------------------------------------------
194  // LaeMotorCtlrEnable Class
195  // ---------------------------------------------------------------------------
196 
197  /*!
198  * \brief Laelaps motor controller power enable class.
199  */
201  {
202  public:
203  static const int TPowerUp = 500000; ///< power-up time (usec)
204 
205  /*!
206  * \brief Default constructor.
207  */
209  LaeGpio("MotorCtlrEn", LaeGpioMotorCtlrEn, LaeGpio::OUTPUT)
210  {
211  }
212 
213  /*!
214  * \brief Destructor.
215  */
217  {
218  }
219 
220  /*!
221  * \brief Synchronized this with GPIO hardware state.
222  */
223  virtual void sync();
224 
225  /*!
226  * \brief Enable power to motor controllers.
227  *
228  * \return Returns true if power is enabled, false otherwise.
229  */
230  bool enable();
231 
232  /*!
233  * \brief Disable power to motor controllers.
234  *
235  * \return Returns true if power is enabled, false otherwise.
236  */
237  bool disable();
238 
239  /*!
240  * \brief Test if power to motor controllers is enabled.
241  *
242  * \return Returns true if power is enabled, false otherwise.
243  */
244  bool isEnabled();
245 
246  protected:
247  };
248 
249 
250  // ---------------------------------------------------------------------------
251  // LaeWatchDogReset Class
252  // ---------------------------------------------------------------------------
253 
254  /*!
255  * \brief Laelaps watchdog sub-processor reset class.
256  */
257  class LaeWatchDogReset : public LaeGpio
258  {
259  public:
260  static const int TTrans = 10000; ///< signal transition time (usec)
261  static const int TReboot = 500000; ///< reboot time (usec)
262 
263  /*!
264  * \brief Default constructor.
265  */
267  LaeGpio("WatchDogReset", LaeGpioWdReset, LaeGpio::OUTPUT)
268  {
269  }
270 
271  /*!
272  * \brief Destructor.
273  */
275  {
276  }
277 
278  /*!
279  * \brief Synchronized this with GPIO hardware state.
280  */
281  virtual void sync();
282 
283  /*!
284  * \brief Reset the watchdog sub-processor.
285  *
286  * The reset is caused by a high to low edge trigger.
287  */
288  void reset();
289 
290  protected:
291  };
292 
293 
294  // ---------------------------------------------------------------------------
295  // LaeI2CMuxReset Class
296  // ---------------------------------------------------------------------------
297 
298  /*!
299  * \brief Laelaps I2C multiplexer reset class.
300  */
301 
302  // controlled by ThreadRange
303  class LaeI2CMuxReset : public LaeGpio
304  {
305  public:
306  static const int TTrans = 10000; ///< signal transition time (usec)
307  static const int TReboot = 10000; ///< reboot time (usec)
308 
309  /*!
310  * \brief Default constructor.
311  */
313  LaeGpio("I2CMuxReset", LaeGpioI2CMuxReset, LaeGpio::OUTPUT)
314  {
315  }
316 
317  /*!
318  * \brief Destructor.
319  */
320  virtual ~LaeI2CMuxReset()
321  {
322  }
323 
324  /*!
325  * \brief Synchronized this with GPIO hardware state.
326  */
327  virtual void sync();
328 
329  /*!
330  * \brief Reset the I2C mulitplex chip.
331  *
332  * The reset is caused by a high to low edge trigger.
333  */
334  void reset();
335 
336  protected:
337  };
338 
339 
340  // ---------------------------------------------------------------------------
341  // LaeAuxBattOutEnable Class
342  // ---------------------------------------------------------------------------
343 
344  /*!
345  * \brief Laelaps top deck auxilliary battery power out enable class.
346  */
348  {
349  public:
350  /*!
351  * \brief Default constructor.
352  */
354  LaeGpio("AuxBattEn", LaeGpioAuxBattEn, LaeGpio::OUTPUT)
355  {
356  }
357 
358  /*!
359  * \brief Destructor.
360  */
362  {
363  }
364 
365  /*!
366  * \brief Synchronized this with GPIO hardware state.
367  */
368  virtual void sync();
369 
370  /*!
371  * \brief Enable battery power to top deck.
372  *
373  * \return Returns true if power is enabled, false otherwise.
374  */
375  bool enable();
376 
377  /*!
378  * \brief Disable battery power to top deck.
379  *
380  * \return Returns true if power is enabled, false otherwise.
381  */
382  bool disable();
383 
384  /*!
385  * \brief Test if battery power to top deck is enabled.
386  *
387  * \return Returns true if power is enabled, false otherwise.
388  */
389  bool isEnabled();
390 
391  protected:
392  };
393 
394 
395  // ---------------------------------------------------------------------------
396  // LaeAux5VOutEnable Class
397  // ---------------------------------------------------------------------------
398 
399  /*!
400  * \brief Laelaps top deck auxilliary regulated 5V power out enable class.
401  */
402  class LaeAux5VOutEnable : public LaeGpio
403  {
404  public:
405  /*!
406  * \brief Default constructor.
407  */
409  LaeGpio("Aux5VEn", LaeGpioAux5VEn, LaeGpio::OUTPUT)
410  {
411  }
412 
413  /*!
414  * \brief Destructor.
415  */
417  {
418  }
419 
420  /*!
421  * \brief Synchronized this with GPIO hardware state.
422  */
423  virtual void sync();
424 
425  /*!
426  * \brief Enable regulated 5V power to top deck.
427  *
428  * \return Returns true if power is enabled, false otherwise.
429  */
430  bool enable();
431 
432  /*!
433  * \brief Disable regulated 5V power to top deck.
434  *
435  * \return Returns true if power is enabled, false otherwise.
436  */
437  bool disable();
438 
439  /*!
440  * \brief Test if regulated 5V power to top deck is enabled.
441  *
442  * \return Returns true if power is enabled, false otherwise.
443  */
444  bool isEnabled();
445 
446  protected:
447  };
448 
449 } // namespace laelaps
450 
451 
452 #endif // _LAE_GPIO_H
const int LaeGpioMotorCtlrEn
motor controler enable gpio
Definition: laeSysDev.h:201
LaeGpio::Direction m_gpioDir
GPIO direction.
Definition: laeGpio.h:179
const int LaeGpioWdReset
Watchdog subprocessor reset gpio.
Definition: laeSysDev.h:209
virtual ~LaeMotorCtlrEnable()
Destructor.
Definition: laeGpio.h:216
low value
Definition: laeGpio.h:84
Laelaps top deck auxilliary regulated 5V power out enable class.
Definition: laeGpio.h:402
virtual ~LaeAux5VOutEnable()
Destructor.
Definition: laeGpio.h:416
Laelaps motor controller power enable class.
Definition: laeGpio.h:200
const int LaeGpioAuxBattEn
auxilliary battery enable gpio
Definition: laeSysDev.h:226
LaeI2CMuxReset()
Default constructor.
Definition: laeGpio.h:312
int m_gpioNum
exported GPIO number
Definition: laeGpio.h:178
LaeGpio(const std::string &strTag, const int gpio, const LaeGpio::Direction dir)
Default intialization constructor.
Definition: laeGpio.cxx:72
The <b><i>Laelaps</i></b> namespace encapsulates all <b><i>Laelaps</i></b> related constructs...
Definition: laeAlarms.h:64
output direction
Definition: laeGpio.h:94
virtual void sync()
Synchronized this with GPIO hardware state.
Definition: laeGpio.cxx:81
int hasValue() const
Get the current shadowed gpio value.
Definition: laeGpio.h:157
virtual ~LaeI2CMuxReset()
Destructor.
Definition: laeGpio.h:320
LaeAuxBattOutEnable()
Default constructor.
Definition: laeGpio.h:353
bool isConfigured() const
Is the exported GPIO number configured to match this ojbect?
Definition: laeGpio.h:171
const int LaeGpioAux5VEn
Deck regulated 5V enable gpio.
Definition: laeSysDev.h:235
virtual ~LaeAuxBattOutEnable()
Destructor.
Definition: laeGpio.h:361
Laelaps system devices.
LaeWatchDogReset()
Default constructor.
Definition: laeGpio.h:266
virtual int readValue(int &value)
Read current value of gpio.
Definition: laeGpio.cxx:115
unknown state value
Definition: laeGpio.h:83
bool checkConfig()
Check if the exported GPIO exists in /sys/class and that it has been configured to match this objects...
Definition: laeGpio.cxx:138
bool m_gpioCfg
GPIO is [not] configured (correctly)
Definition: laeGpio.h:181
virtual ~LaeGpio()
Destructor.
Definition: laeGpio.h:113
Laelaps I2C multiplexer reset class.
Definition: laeGpio.h:303
Laelaps watchdog sub-processor reset class.
Definition: laeGpio.h:257
virtual ~LaeWatchDogReset()
Destructor.
Definition: laeGpio.h:274
LaeMotorCtlrEnable()
Default constructor.
Definition: laeGpio.h:208
input direction
Definition: laeGpio.h:93
virtual int writeValue(const LaeGpio::TriState value)
Write value to gpio.
Definition: laeGpio.h:129
high value
Definition: laeGpio.h:85
TriState
GPIO tri-state value.
Definition: laeGpio.h:81
int m_gpioVal
shadowed value
Definition: laeGpio.h:180
std::string m_gpioTag
identifying tag
Definition: laeGpio.h:177
LaeAux5VOutEnable()
Default constructor.
Definition: laeGpio.h:408
const int LaeGpioI2CMuxReset
I2C multiplexer reset gpio.
Definition: laeSysDev.h:217
Top-level package include file.
Laelaps Odroid GPIO base class.
Definition: laeGpio.h:75
Laelaps top deck auxilliary battery power out enable class.
Definition: laeGpio.h:347
Direction
GPIO direction.
Definition: laeGpio.h:91