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

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Revision:
1:ab59fc9af055
Parent:
0:31e91bb0ef3c
Child:
2:1df0b61d3b5a
--- a/libs/Pin.h	Tue Jul 31 21:11:18 2012 +0000
+++ b/libs/Pin.h	Sat Mar 01 02:37:29 2014 +0000
@@ -9,56 +9,39 @@
 
 class Pin{
     public:
-        Pin(){ }
+        Pin() { }
 
         Pin* from_string(std::string value){
-            LPC_GPIO_TypeDef* gpios[5] ={LPC_GPIO0,LPC_GPIO1,LPC_GPIO2,LPC_GPIO3,LPC_GPIO4};
-            this->port_number =  atoi(value.substr(0,1).c_str());  
-            this->port = gpios[this->port_number]; 
-            this->inverting = ( value.find_first_of("!")!=string::npos ? true : false );
-            this->pin  = atoi( value.substr(2, value.size()-2-(this->inverting?1:0)).c_str() );
+            gpio_init(&pin, A0, PIN_INPUT);
             return this;
         }
 
         inline Pin*  as_output(){
-            this->port->FIODIR |= 1<<this->pin;
+            gpio_dir(&pin, PIN_OUTPUT);
             return this;
         }  
 
         inline Pin*  as_input(){
-            this->port->FIODIR &= ~(1<<this->pin);
+            gpio_dir(&pin, PIN_INPUT);
             return this;
         }  
 
         inline Pin* as_open_drain(){
-            if( this->port_number == 0 ){ LPC_PINCON->PINMODE_OD0 |= (1<<this->pin); }
-            if( this->port_number == 1 ){ LPC_PINCON->PINMODE_OD1 |= (1<<this->pin); }
-            if( this->port_number == 2 ){ LPC_PINCON->PINMODE_OD2 |= (1<<this->pin); }
-            if( this->port_number == 3 ){ LPC_PINCON->PINMODE_OD3 |= (1<<this->pin); }
-            if( this->port_number == 4 ){ LPC_PINCON->PINMODE_OD4 |= (1<<this->pin); }
+            gpio_mode(&pin, OpenDrain);
             return this;
         }
 
         inline bool get(){
-            return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
+            return this->inverting ^ gpio_read(&pin);
         }
 
         inline void set(bool value){
             value = this->inverting ^ value;
-            if( value ){
-                this->port->FIOSET = 1 << this->pin;
-            }else{
-                this->port->FIOCLR = 1 << this->pin;
-            }        
+            gpio_write(&pin, value);
         }
 
         bool inverting; 
-        LPC_GPIO_TypeDef* port;
-        char port_number;
-        char pin; 
+        gpio_t pin;
 };
 
-
-
-
 #endif