-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIO.cpp
More file actions
91 lines (81 loc) · 2.4 KB
/
IO.cpp
File metadata and controls
91 lines (81 loc) · 2.4 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* Autor:RecursiveError
biblioteca com as funções basicas de perifericos E operações para manipulação de bits
*/
#include "IO.hpp"
#include <avr/io.h>
namespace digitalIO{
DigitalIO& DigitalIO::output(void){
if(this->_pin < 8u){
DDRD |= (1<<this->_pin);
}else if(this->_pin < 14u){
DDRB |= (1<<(this->_pin - 8u));
}else if(this->_pin < 20u){
DDRC |= (1<<(this->_pin - 14u));
}
return *this;
}
DigitalIO& DigitalIO::input(void){
if(this->_pin < 8u){
DDRD &= ~(1<<this->_pin);
}
if(this->_pin < 14u){
DDRB &= ~(1<<(this->_pin - 8u));
}else if(this->_pin < 20u){
DDRC &= ~(1<<(this->_pin - 14u));
}
return *this;
}
DigitalIO& DigitalIO::input_pullup(void){
if(this->_pin < 8u){
DDRD &= ~(1<<this->_pin);
this->set_high();
}else if(this->_pin < 14u){
DDRB &= ~(1<<(this->_pin - 8u));
this->set_high();
}else if(this->_pin < 20u){
DDRC &= ~(1<<(this->_pin - 14u));
this->set_high();
}
return *this;
}
DigitalIO& DigitalIO::set_high(void){
if(this->_pin < 8U){
PORTD |= (1<<this->_pin);
}else if(this->_pin < 14U){
PORTB |= (1<<(this->_pin - 8u));
}else if(this->_pin < 20u){
PORTC |= (1<<(this->_pin - 14u));
}
return *this;
}
DigitalIO& DigitalIO::set_low(void){
if(this->_pin < 8u){
PORTD &= ~(1<<this->_pin);
}else if(this->_pin < 14u){
PORTB &= ~(1<<(this->_pin - 8u));
}else if(this->_pin < 20u){
PORTC &= ~(1<<(this->_pin - 14u));
}
return *this;
}
DigitalIO& DigitalIO::toggle(void){
if(this->_pin < 8U){
PORTD ^= (1<<this->_pin);
}else if(this->_pin < 14U){
PORTB ^= (1<<(this->_pin - 8u));
}else if(this->_pin < 20u){
PORTC ^= (1<<(this->_pin - 14u));
}
return *this;
}
bool DigitalIO::read(void){
if(this->_pin < 8u){
return (PIND & (1<<this->_pin));
}else if(this->_pin < 14u){
return (PINB & (1<<(this->_pin-8u)));
}else if(this->_pin < 20u){
return (PINC & (1<<(this->_pin-14u)));
}
return false;
}
}