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