-
Notifications
You must be signed in to change notification settings - Fork 1
/
button.c
66 lines (50 loc) · 1.15 KB
/
button.c
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
/*
* button.c
*
* Created on: Apr 8, 2016
* Author: nbergman
*/
#include "button.h"
//Navigation buttons -- Port 4
#define PB_UP BIT3
#define PB_DN BIT4
#define PB_LF BIT5
#define PB_RT BIT6
#define PB_SEL BIT7
//Power switch -- Port 4
#define PWR_SW_PIN BIT2
//#define PWR_ON_LED BIT4 //Port 3
//Initialize ports for buttons, and proj_on switch
void button_initPorts(void)
{
P4DIR &= ~(PB_UP | PB_DN | PB_LF | PB_RT | PB_SEL);
//P2IE |= (PB_UP | PB_DN | PB_LF | PB_RT | PB_SEL);
P4DIR &= ~(PWR_SW_PIN);
}
//Check for change in power switch and toggle current state
void button_checkPowerKey(powerState_t *currentState)
{
//TODO: change to pin change interrupt
switch(*currentState)
{
case OFF:
if(P4IN & PWR_SW_PIN) *currentState = TURN_ON;
//Else Nothing
break;
case TURN_ON:
*currentState = ON;
break;
case ON:
if(!(P4IN & PWR_SW_PIN)) *currentState = TURN_OFF;
//Do Nothing
break;
case TURN_OFF:
*currentState = OFF;
//P3OUT |= PWR_ON_LED;
break;
default:
//Error undefined state
//P3OUT |= BIT5; //Error led
break;
}
}