release the include directive if found in config
[clinton/Smoothieware.git] / src / libs / Pin.h
index 44a1047..c3e781f 100644 (file)
@@ -6,6 +6,12 @@
 #include <string>
 
 #include "libs/LPC17xx/sLPC17xx.h" // smoothed mbed.h lib
+#include "PinNames.h"
+
+namespace mbed {
+    class PwmOut;
+    class InterruptIn;
+}
 
 class Pin {
     public:
@@ -14,17 +20,21 @@ class Pin {
         Pin* from_string(std::string value);
 
         inline bool connected(){
-            return this->pin < 32;
+            return this->valid;
+        }
+
+        inline bool equals(const Pin& other) const {
+            return (this->pin == other.pin) && (this->port == other.port);
         }
 
         inline Pin* as_output(){
-            if (this->pin < 32)
+            if (this->valid)
                 this->port->FIODIR |= 1<<this->pin;
             return this;
         }
 
         inline Pin* as_input(){
-            if (this->pin < 32)
+            if (this->valid)
                 this->port->FIODIR &= ~(1<<this->pin);
             return this;
         }
@@ -39,24 +49,38 @@ class Pin {
 
         Pin* pull_none(void);
 
-        inline bool get(){
-            if (this->pin >= 32) return false;
+        inline bool get() const{
+            if (!this->valid) return false;
             return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
         }
 
         inline void set(bool value)
         {
-            if (this->pin >= 32) return;
+            if (!this->valid) return;
             if ( this->inverting ^ value )
                 this->port->FIOSET = 1 << this->pin;
             else
                 this->port->FIOCLR = 1 << this->pin;
         }
 
+        mbed::PwmOut *hardware_pwm();
+
+        mbed::InterruptIn *interrupt_pin();
+
+        bool is_inverting() const { return inverting; }
+        void set_inverting(bool f) { inverting= f; }
+
+        // these should be private, and use getters
         LPC_GPIO_TypeDef* port;
-        bool inverting;
-        char port_number;
+
         unsigned char pin;
+        char port_number;
+
+    private:
+        struct {
+            bool inverting:1;
+            bool valid:1;
+        };
 };