didn't save any pin memory as classes ar ealwasys rounded up to even 4 byte boundarie...
[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->valid;
18 }
19
20 inline bool equals(const Pin& other) const {
21 return (this->pin == other.pin) && (this->port == other.port);
22 }
23
24 inline Pin* as_output(){
25 if (this->valid)
26 this->port->FIODIR |= 1<<this->pin;
27 return this;
28 }
29
30 inline Pin* as_input(){
31 if (this->valid)
32 this->port->FIODIR &= ~(1<<this->pin);
33 return this;
34 }
35
36 Pin* as_open_drain(void);
37
38 Pin* as_repeater(void);
39
40 Pin* pull_up(void);
41
42 Pin* pull_down(void);
43
44 Pin* pull_none(void);
45
46 inline bool get(){
47 if (!this->valid) return false;
48 return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
49 }
50
51 inline void set(bool value)
52 {
53 if (!this->valid) return;
54 if ( this->inverting ^ value )
55 this->port->FIOSET = 1 << this->pin;
56 else
57 this->port->FIOCLR = 1 << this->pin;
58 }
59
60 // these should be private, and use getters
61 LPC_GPIO_TypeDef* port;
62
63 unsigned char pin;
64 char port_number;
65 struct {
66 bool inverting:1;
67 bool valid:1;
68 };
69 };
70
71
72
73
74 #endif