-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbutton.c
More file actions
32 lines (25 loc) · 763 Bytes
/
button.c
File metadata and controls
32 lines (25 loc) · 763 Bytes
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
//___________________________________________
// Joshua Schapiro
//___________________________________________
#include "button.h"
void Button_Init(uint8_t button, bool enableInt, uint8_t edge, uint8_t intNumber,uint8_t intLevel){
Button_Port.DIRCLR = (1 << button);
PORTCFG.MPCMASK = (1 << button);
Button_Port.PIN0CTRL = PORT_OPC_WIREDANDPULL_gc | edge;
if(enableInt){
if(intNumber == 0){
Button_Port.INT0MASK = (1<<button);
Button_Port.INTCTRL |= intLevel;
} else if (intNumber == 1){
Button_Port.INT1MASK = (1<<button);
Button_Port.INTCTRL |= (intLevel << 2);
}
}
}
bool Button_Pressed(uint8_t button){
if((Button_Port.IN & (1<<button)) >0 ){
return false;
} else {
return true;
}
}