Pin: built-in copy ctor is adequate
[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
44 if (this->pin >= 32) return false;
45 return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
46 }
47
48 inline void set(bool value)
49 {
50 if (this->pin >= 32) return;
51 if ( this->inverting ^ value )
52 this->port->FIOSET = 1 << this->pin;
53 else
54 this->port->FIOCLR = 1 << this->pin;
55 }
56
57 LPC_GPIO_TypeDef* port;
58 bool inverting;
59 char port_number;
60 unsigned char pin;
61 };
62
63
64
65
66 #endif