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"
6 #include "libs/Kernel.h"
7 #include "libs/utils.h"
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_number
= atoi(value
.substr(0,1).c_str());
17 this->port
= gpios
[this->port_number
];
18 this->inverting
= ( value
.find_first_of("!")!=string::npos
? true : false );
19 this->pin
= atoi( value
.substr(2, value
.size()-2-(this->inverting
?1:0)).c_str() );
23 inline Pin
* as_output(){
24 this->port
->FIODIR
|= 1<<this->pin
;
28 inline Pin
* as_input(){
29 this->port
->FIODIR
&= ~(1<<this->pin
);
33 inline Pin
* as_open_drain(){
34 if( this->port_number
== 0 ){ LPC_PINCON
->PINMODE_OD0
|= (1<<this->pin
); }
35 if( this->port_number
== 1 ){ LPC_PINCON
->PINMODE_OD1
|= (1<<this->pin
); }
36 if( this->port_number
== 2 ){ LPC_PINCON
->PINMODE_OD2
|= (1<<this->pin
); }
37 if( this->port_number
== 3 ){ LPC_PINCON
->PINMODE_OD3
|= (1<<this->pin
); }
38 if( this->port_number
== 4 ){ LPC_PINCON
->PINMODE_OD4
|= (1<<this->pin
); }
43 if( this->inverting
){
44 return ~(( this->port
->FIOPIN
>> this->pin
) & 1);
46 return (( this->port
->FIOPIN
>> this->pin
) & 1);
50 inline void set(bool value
){
51 // TODO : This should be bitmath
52 if( this->inverting
){ value
= !value
; }
54 this->port
->FIOSET
= 1 << this->pin
;
56 this->port
->FIOCLR
= 1 << this->pin
;
61 LPC_GPIO_TypeDef
* port
;