Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Revision:
2:1df0b61d3b5a
Parent:
1:ab59fc9af055
Child:
3:f151d08d335c
diff -r ab59fc9af055 -r 1df0b61d3b5a libs/Pin.h
--- a/libs/Pin.h	Sat Mar 01 02:37:29 2014 +0000
+++ b/libs/Pin.h	Fri Feb 28 18:52:52 2014 -0800
@@ -2,46 +2,65 @@
 #define PIN_H
 
 #include <stdlib.h>
-#include "mbed.h" // smoothed mbed.h lib
-#include "libs/Kernel.h"
-#include "libs/utils.h"
+#include <stdio.h>
 #include <string>
 
-class Pin{
+#include "libs/LPC17xx/sLPC17xx.h" // smoothed mbed.h lib
+
+class Pin {
     public:
-        Pin() { }
+        Pin();
+
+        Pin* from_string(std::string value);
+
+        inline bool connected(){
+            return this->pin < 32;
+        }
 
-        Pin* from_string(std::string value){
-            gpio_init(&pin, A0, PIN_INPUT);
+        inline Pin* as_output(){
+            if (this->pin < 32)
+                this->port->FIODIR |= 1<<this->pin;
+            return this;
+        }
+
+        inline Pin* as_input(){
+            if (this->pin < 32)
+                this->port->FIODIR &= ~(1<<this->pin);
             return this;
         }
 
-        inline Pin*  as_output(){
-            gpio_dir(&pin, PIN_OUTPUT);
-            return this;
-        }  
+        Pin* as_open_drain(void);
+
+        Pin* as_repeater(void);
+
+        Pin* pull_up(void);
 
-        inline Pin*  as_input(){
-            gpio_dir(&pin, PIN_INPUT);
-            return this;
-        }  
+        Pin* pull_down(void);
+
+        Pin* pull_none(void);
 
-        inline Pin* as_open_drain(){
-            gpio_mode(&pin, OpenDrain);
-            return this;
+        inline bool get(){
+
+            if (this->pin >= 32) return false;
+            return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
         }
 
-        inline bool get(){
-            return this->inverting ^ gpio_read(&pin);
+        inline void set(bool value)
+        {
+            if (this->pin >= 32) return;
+            if ( this->inverting ^ value )
+                this->port->FIOSET = 1 << this->pin;
+            else
+                this->port->FIOCLR = 1 << this->pin;
         }
 
-        inline void set(bool value){
-            value = this->inverting ^ value;
-            gpio_write(&pin, value);
-        }
-
-        bool inverting; 
-        gpio_t pin;
+        LPC_GPIO_TypeDef* port;
+        bool inverting;
+        char port_number;
+        unsigned char pin;
 };
 
+
+
+
 #endif