Andy K / Lib17_Core
Revision:
6:40a18fb62f1f
Parent:
5:a3b5b8fc77e3
--- a/include/Lib17_DIO.h	Mon Apr 11 16:16:23 2011 +0000
+++ b/include/Lib17_DIO.h	Tue Apr 12 08:47:15 2011 +0000
@@ -23,10 +23,10 @@
  ***************************************************************************/
 
 /**
- * @defgroup API The Lib17 Core API 
+ * @defgroup API The Lib17 Core API
  * @defgroup Lib17_DIO Lib17_DIO functions
  */
- 
+
 #ifndef AJK_Lib17_DIO_H
 #define AJK_Lib17_DIO_H
 
@@ -44,6 +44,20 @@
  * to link against the Mbed library. This increase portability when using
  * alternate compilers (such as the Code Red GCC C++ compiler for LPCXpresso).
  *
+ * Example code:-
+ * @code
+ * #include "Lib17_Core.h"
+ *
+ * Lib17_DIO myin(p5, Lib17_DIO::In);
+ * Lib17_DIO myled(LED1);
+ *
+ * int main() {
+ *     while(1) {
+ *         myled = myin;
+ *     }
+ * }
+ * @endcode
+ *
  * @see http://cornflakes.wikidot.com/lib17:core
  * @ingroup Lib17_DIO
  */
@@ -84,35 +98,35 @@
 
     /** write
      *
-     * Writes a value to the pin. 
+     * Writes a value to the pin.
      *
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      * @param i Zero makes the pin 0v, non-zero makes the pin 1.
      */
     void write(int i)     { if (i!=0) { pinUp(); } else { pinDn(); } }
-    
+
     /** read
      *
-     * Reads the value on the pin. 
+     * Reads the value on the pin.
      *
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      * @return int 0v returns zero, otherwise returns 1.
      */
     int  read(void)       { return pinIs() ? 1 : 0; };
-    
+
     /** output
      *
      * Setup the pin to be an output.
      *
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
-     * @ingroup API 
+     * @ingroup API
      * @return int 0v returns zero, otherwise returns 1.
      */
     void output(void)    { *((volatile uint32_t *)fiodir) |=  mask; }
-    
+
     /** input
      *
      * Setup the pin to be an input.
@@ -132,7 +146,7 @@
      * @return int 0v returns zero, otherwise returns 1.
      */
     PinName getPin(void) { return pin; }
-    
+
     /** getDirection
      *
      * Get the operational direction this pin is setup for.
@@ -145,7 +159,7 @@
 
     /**  operator int()
      *
-     * Reads the value on the pin. 
+     * Reads the value on the pin.
      *
      * @see read
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
@@ -153,20 +167,20 @@
      * @return int 0v returns zero, otherwise returns 1.
      */
     operator int() { return read(); }
-    
-    /** operator= 
+
+    /** operator=
      *
-     * Writes a value to the pin. 
+     * Writes a value to the pin.
      *
      * @see write
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      */
     Lib17_DIO& operator= (int value)  { write(value); return *this; }
-    
-    /** operator= 
+
+    /** operator=
      *
-     * Writes a value to the pin. 
+     * Writes a value to the pin.
      *
      * @see write
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
@@ -181,9 +195,9 @@
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      * @return uint32_t The mask value used by this pin.
-     */ 
+     */
     uint32_t getMask(void)    { return mask;    }
-    
+
     /** getFiodir
      *
      * Get the FIODIR register for the port the pin is on.
@@ -191,9 +205,9 @@
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      * @return uint32_t The register value.
-     */ 
+     */
     uint32_t getFiodir(void)  { return fiodir;  }
-    
+
     /** getFiomask
      *
      * Get the FIOMASK register for the port the pin is on.
@@ -201,9 +215,9 @@
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      * @return uint32_t The register value.
-     */ 
+     */
     uint32_t getFiomask(void) { return fiomask; }
-    
+
     /** getFiopin
      *
      * Get the FIOPIN register for the port the pin is on.
@@ -211,9 +225,9 @@
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      * @return uint32_t The register value.
-     */ 
+     */
     uint32_t getFiopin(void)  { return fiopin;  }
-    
+
     /** getFioset
      *
      * Get the FIOSET register for the port the pin is on.
@@ -221,9 +235,9 @@
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      * @return uint32_t The register value.
-     */ 
+     */
     uint32_t getFioset(void)  { return fioset;  }
-    
+
     /** getFioclr
      *
      * Get the FIOCLR register for the port the pin is on.
@@ -231,7 +245,7 @@
      * @see http://cornflakes.wikidot.com/lib17:core:lib17-dio
      * @ingroup Lib17_DIO
      * @return uint32_t The register value.
-     */ 
+     */
     uint32_t getFioclr(void)  { return fioclr;  }
 
 
@@ -242,9 +256,9 @@
         // sets all pins to be GPIO. The user will change
         // that if they need to. So we don't bother trying
         // to setup PINSELx
-    
+
         // psel(); // Not used, see above.
-    
+
         setpin(p);
         setmask(p);
         setDir(p);
@@ -252,7 +266,7 @@
         setPin(p);
         setSet(p);
         setClr(p);
-    
+
         if (d == Out) output();
         else mode( m );
     }
@@ -261,7 +275,7 @@
     void psel(void)
     {
         uint32_t ppsel, pumask;
-    
+
         if (pin >= P0_0 && pin <= P0_15)         ppsel = (uint32_t)(&LPC_PINCON->PINSEL0);
         else if (pin >= P0_16 && pin <= P0_31)     ppsel = (uint32_t)(&LPC_PINCON->PINSEL1);
         else if (pin >= P1_0 && pin <= P1_15)     ppsel = (uint32_t)(&LPC_PINCON->PINSEL2);
@@ -270,16 +284,16 @@
         else if (pin >= P3_16 && pin <= P3_31)     ppsel = (uint32_t)(&LPC_PINCON->PINSEL7);
         else if (pin >= P4_16 && pin <= P4_31)     ppsel = (uint32_t)(&LPC_PINCON->PINSEL9);
         else return;
-    
+
         pumask = ~(3UL << ((pin & 0x1F)>>1));
         *((volatile uint32_t *)ppsel) &= pumask;
     }
 
 public:
-    void mode(PinMode m) 
+    void mode(PinMode m)
     {
         uint32_t ppmod, pumask;
-    
+
         if (m == OpenDrain) {
             openDrain(1);
         }
@@ -313,13 +327,13 @@
                 pumask = ((m & 0x3) << ( ((pin & 0x1F)-16)*2) );
             }
             else return;
-    
+
             *((volatile uint32_t *)ppmod) |= pumask;
         }
     }
 
 public:
-    void openDrain(int i = 1) 
+    void openDrain(int i = 1)
     {
         if (pin >= P0_0 && pin <= P0_31)           { if (i) LPC_PINCON->PINMODE_OD0 |= mask; else LPC_PINCON->PINMODE_OD0 &= ~mask; }
         else if (pin >= P1_0 && pin <= P1_31)      { if (i) LPC_PINCON->PINMODE_OD1 |= mask; else LPC_PINCON->PINMODE_OD1 &= ~mask; }