Merge pull request #294 from wolfmanjm/upstreamedge
[clinton/Smoothieware.git] / src / libs / Pin.h
1 #ifndef PIN_H
2 #define PIN_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string>
7
8 #include "libs/LPC17xx/sLPC17xx.h" // smoothed mbed.h lib
9
10 class Pin {
11 public:
12 Pin();
13
14 Pin* from_string(std::string value);
15
16 inline bool connected(){
17 return this->pin < 32;
18 }
19
20 inline Pin* as_output(){
21 if (this->pin < 32)
22 this->port->FIODIR |= 1<<this->pin;
23 return this;
24 }
25
26 inline Pin* as_input(){
27 if (this->pin < 32)
28 this->port->FIODIR &= ~(1<<this->pin);
29 return this;
30 }
31
32 Pin* as_open_drain(void);
33
34 Pin* as_repeater(void);
35
36 Pin* pull_up(void);
37
38 Pin* pull_down(void);
39
40 Pin* pull_none(void);
41
42 inline bool get(){
43 if (this->pin >= 32) return false;
44 return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
45 }
46
47 inline void set(bool value)
48 {
49 if (this->pin >= 32) return;
50 if ( this->inverting ^ value )
51 this->port->FIOSET = 1 << this->pin;
52 else
53 this->port->FIOCLR = 1 << this->pin;
54 }
55
56 LPC_GPIO_TypeDef* port;
57 bool inverting;
58 char port_number;
59 unsigned char pin;
60 };
61
62
63
64
65 #endif