7 Pin
* Pin::from_string(std::string value
)
9 LPC_GPIO_TypeDef
* gpios
[5] ={LPC_GPIO0
,LPC_GPIO1
,LPC_GPIO2
,LPC_GPIO3
,LPC_GPIO4
};
11 // cs is the current position in the string
12 const char* cs
= value
.c_str();
13 // cn is the position of the next char after the number we just read
16 this->port_number
= strtol(cs
, &cn
, 10);
17 if ((cn
> cs
) && (port_number
<= 4))
19 this->port
= gpios
[(unsigned int) this->port_number
];
23 this->pin
= strtol(cs
, &cn
, 10);
24 if ((cn
> cs
) & (pin
< 32))
26 while (is_whitespace(*cn
)) cn
++;
27 this->inverting
= (*cn
== '!');
29 this->port
->FIOMASK
&= ~(1 << this->pin
);
43 Pin
* Pin::as_open_drain()
45 if (this->pin
>= 32) return this;
46 if( this->port_number
== 0 ){ LPC_PINCON
->PINMODE_OD0
|= (1<<this->pin
); }
47 if( this->port_number
== 1 ){ LPC_PINCON
->PINMODE_OD1
|= (1<<this->pin
); }
48 if( this->port_number
== 2 ){ LPC_PINCON
->PINMODE_OD2
|= (1<<this->pin
); }
49 if( this->port_number
== 3 ){ LPC_PINCON
->PINMODE_OD3
|= (1<<this->pin
); }
50 if( this->port_number
== 4 ){ LPC_PINCON
->PINMODE_OD4
|= (1<<this->pin
); }
56 if (this->pin
>= 32) return this;
57 // Set the two bits for this pin as 00
58 if( this->port_number
== 0 && this->pin
< 16 ){ LPC_PINCON
->PINMODE0
&= ~(3<<( this->pin
*2)); }
59 if( this->port_number
== 0 && this->pin
>= 16 ){ LPC_PINCON
->PINMODE1
&= ~(3<<((this->pin
-16)*2)); }
60 if( this->port_number
== 1 && this->pin
< 16 ){ LPC_PINCON
->PINMODE2
&= ~(3<<( this->pin
*2)); }
61 if( this->port_number
== 1 && this->pin
>= 16 ){ LPC_PINCON
->PINMODE3
&= ~(3<<((this->pin
-16)*2)); }
62 if( this->port_number
== 2 && this->pin
< 16 ){ LPC_PINCON
->PINMODE4
&= ~(3<<( this->pin
*2)); }
63 if( this->port_number
== 3 && this->pin
>= 16 ){ LPC_PINCON
->PINMODE7
&= ~(3<<((this->pin
-16)*2)); }
64 if( this->port_number
== 4 && this->pin
>= 16 ){ LPC_PINCON
->PINMODE9
&= ~(3<<((this->pin
-16)*2)); }
70 if (this->pin
>= 32) return this;
71 // Set the two bits for this pin as 11
72 if( this->port_number
== 0 && this->pin
< 16 ){ LPC_PINCON
->PINMODE0
|= (3<<( this->pin
*2)); }
73 if( this->port_number
== 0 && this->pin
>= 16 ){ LPC_PINCON
->PINMODE1
|= (3<<((this->pin
-16)*2)); }
74 if( this->port_number
== 1 && this->pin
< 16 ){ LPC_PINCON
->PINMODE2
|= (3<<( this->pin
*2)); }
75 if( this->port_number
== 1 && this->pin
>= 16 ){ LPC_PINCON
->PINMODE3
|= (3<<((this->pin
-16)*2)); }
76 if( this->port_number
== 2 && this->pin
< 16 ){ LPC_PINCON
->PINMODE4
|= (3<<( this->pin
*2)); }
77 if( this->port_number
== 3 && this->pin
>= 16 ){ LPC_PINCON
->PINMODE7
|= (3<<((this->pin
-16)*2)); }
78 if( this->port_number
== 4 && this->pin
>= 16 ){ LPC_PINCON
->PINMODE9
|= (3<<((this->pin
-16)*2)); }