removed most mbed.h includes
[clinton/Smoothieware.git] / src / libs / Pin.h
CommitLineData
3b1e82d2
AW
1#ifndef PIN_H
2#define PIN_H
3
423df6df
AW
4#include "mbed.h" //Required for LPC_GPIO* . can probably be found in one othe the files mbed.h includes. TODO
5//#include "../gcc4mbed/external/mbed/LPC1768/LPC17xx.h"
3b1e82d2
AW
6#include "libs/Kernel.h"
7#include "libs/utils.h"
8#include <string>
9
10class Pin{
11 public:
12 Pin(){ }
13
14 Pin* from_string(std::string value){
15 LPC_GPIO_TypeDef* gpios[5] ={LPC_GPIO0,LPC_GPIO1,LPC_GPIO2,LPC_GPIO3,LPC_GPIO4};
16 this->port = gpios[ atoi(value.substr(0,1).c_str()) ];
17 this->inverting = ( value.find_first_of("!")!=string::npos ? true : false );
18 this->pin = atoi( value.substr(2, value.size()-2-(this->inverting?1:0)).c_str() );
19 return this;
20 }
21
22 inline Pin* as_output(){
23 this->port->FIODIR |= 1<<this->pin;
24 return this;
25 }
26
81b547a1
AW
27 inline Pin* as_input(){
28 this->port->FIODIR &= ~(1<<this->pin);
29 return this;
30 }
31
32 inline bool get(){
33 if( this->inverting ){
34 return ~(( this->port->FIOPIN >> this->pin ) & 1);
35 }else{
36 return (( this->port->FIOPIN >> this->pin ) & 1);
37 }
38 }
39
3b1e82d2 40 inline void set(bool value){
81b547a1 41 // TODO : This should be bitmath
3b1e82d2
AW
42 if( this->inverting ){ value = !value; }
43 if( value ){
44 this->port->FIOSET = 1 << this->pin;
45 }else{
46 this->port->FIOCLR = 1 << this->pin;
47 }
48 }
49
50 bool inverting;
51 LPC_GPIO_TypeDef* port;
52 char pin;
53};
54
55
56
57
3b1e82d2 58#endif