update firmware.bin
[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 #include "PinNames.h"
10
11 namespace mbed {
12 class PwmOut;
13 }
14
15 class Pin {
16 public:
17 Pin();
18
19 Pin* from_string(std::string value);
20
21 inline bool connected(){
22 return this->pin < 32;
23 }
24
25 inline bool equals(const Pin& other) const {
26 return (this->pin == other.pin) && (this->port == other.port);
27 }
28
29 inline Pin* as_output(){
30 if (this->pin < 32)
31 this->port->FIODIR |= 1<<this->pin;
32 return this;
33 }
34
35 inline Pin* as_input(){
36 if (this->pin < 32)
37 this->port->FIODIR &= ~(1<<this->pin);
38 return this;
39 }
40
41 Pin* as_open_drain(void);
42
43 Pin* as_repeater(void);
44
45 Pin* pull_up(void);
46
47 Pin* pull_down(void);
48
49 Pin* pull_none(void);
50
51 inline bool get(){
52
53 if (this->pin >= 32) return false;
54 return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
55 }
56
57 inline void set(bool value)
58 {
59 if (this->pin >= 32) return;
60 if ( this->inverting ^ value )
61 this->port->FIOSET = 1 << this->pin;
62 else
63 this->port->FIOCLR = 1 << this->pin;
64 }
65
66 mbed::PwmOut *hardware_pwm();
67
68 LPC_GPIO_TypeDef* port;
69 bool inverting;
70 char port_number;
71 unsigned char pin;
72 };
73
74
75
76
77 #endif