Fork of Smoothie to port to mbed non-LPC targets.
Fork of Smoothie by
Diff: libs/Pin.h
- Revision:
- 3:f151d08d335c
- Parent:
- 2:1df0b61d3b5a
diff -r 1df0b61d3b5a -r f151d08d335c libs/Pin.h --- a/libs/Pin.h Fri Feb 28 18:52:52 2014 -0800 +++ b/libs/Pin.h Sun Mar 02 06:33:08 2014 +0000 @@ -1,12 +1,12 @@ #ifndef PIN_H #define PIN_H +#include "mbed.h" + #include <stdlib.h> #include <stdio.h> #include <string> -#include "libs/LPC17xx/sLPC17xx.h" // smoothed mbed.h lib - class Pin { public: Pin(); @@ -14,18 +14,16 @@ Pin* from_string(std::string value); inline bool connected(){ - return this->pin < 32; + return name != NC; } inline Pin* as_output(){ - if (this->pin < 32) - this->port->FIODIR |= 1<<this->pin; + gpio_dir(&pin, PIN_OUTPUT); return this; } inline Pin* as_input(){ - if (this->pin < 32) - this->port->FIODIR &= ~(1<<this->pin); + gpio_dir(&pin, PIN_INPUT); return this; } @@ -40,24 +38,17 @@ Pin* pull_none(void); inline bool get(){ - - if (this->pin >= 32) return false; - return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1); + 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; + gpio_write(&pin, value ^ this->inverting); } - LPC_GPIO_TypeDef* port; + PinName name; bool inverting; - char port_number; - unsigned char pin; + gpio_t pin; };