-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons4.h
executable file
·99 lines (85 loc) · 3.35 KB
/
buttons4.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
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
92
93
94
95
96
97
98
99
#ifndef BUTTONS_H_
#define BUTTONS_H_
// *******************************************************
// buttons4.h
//
// Support for a set of FOUR specific buttons on the Tiva/Orbit.
// ENCE361 sample code.
// The buttons are: UP and DOWN (on the Orbit daughterboard) plus
// LEFT and RIGHT on the Tiva.
//
// P.J. Bones UCECE
// Last modified: 7.2.2018
//
// *******************************************************
#include <stdint.h>
#include <stdbool.h>
//*****************************************************************************
// Constants
//*****************************************************************************
enum butNames {UP = 0, DOWN, LEFT, RIGHT, NUM_BUTS};
enum butStates {RELEASED = 0, PUSHED, NO_CHANGE};
// UP button
#define UP_BUT_PERIPH SYSCTL_PERIPH_GPIOE
#define UP_BUT_PORT_BASE GPIO_PORTE_BASE
#define UP_BUT_PIN GPIO_PIN_0
#define UP_BUT_NORMAL false
// DOWN button
#define DOWN_BUT_PERIPH SYSCTL_PERIPH_GPIOD
#define DOWN_BUT_PORT_BASE GPIO_PORTD_BASE
#define DOWN_BUT_PIN GPIO_PIN_2
#define DOWN_BUT_NORMAL false
// LEFT button
#define LEFT_BUT_PERIPH SYSCTL_PERIPH_GPIOF
#define LEFT_BUT_PORT_BASE GPIO_PORTF_BASE
#define LEFT_BUT_PIN GPIO_PIN_4
#define LEFT_BUT_NORMAL true
// RIGHT button
#define RIGHT_BUT_PERIPH SYSCTL_PERIPH_GPIOF
#define RIGHT_BUT_PORT_BASE GPIO_PORTF_BASE
#define RIGHT_BUT_PIN GPIO_PIN_0
#define RIGHT_BUT_NORMAL true
// *******************************************
// SW1 Switch
// J1-10, PA7
// *******************************************
#define SW1_PERIPH SYSCTL_PERIPH_GPIOA
#define SW1_PORT_BASE GPIO_PORTA_BASE
#define SW1_PIN GPIO_PIN_7
// *******************************************
// Reset Button
// J1-09, PA6
// *******************************************
//#define RESET_PERIPH SYSCTL_PERIPH_GPIOA
//#define RESET_PORT_BASE GPIO_PORTA_BASE
//#define GPIO_PIN_6 GPIO_PIN_6
#define NUM_BUT_POLLS 3
// Debounce algorithm: A state machine is associated with each button.
// A state change occurs only after NUM_BUT_POLLS consecutive polls have
// read the pin in the opposite condition, before the state changes and
// a flag is set. Set NUM_BUT_POLLS according to the polling rate.
// *******************************************************
// initButtons: Initialise the variables associated with the set of buttons
// defined by the constants above.
void
initButtons (void);
// *******************************************************
// updateButtons: Function designed to be called regularly. It polls all
// buttons once and updates variables associated with the buttons if
// necessary. It is efficient enough to be part of an ISR, e.g. from
// a SysTick interrupt.
void
updateButtons (void);
// *******************************************************
// checkButton: Function returns the new button state if the button state
// (PUSHED or RELEASED) has changed since the last call, otherwise returns
// NO_CHANGE. The argument butName should be one of constants in the
// enumeration butStates, excluding 'NUM_BUTS'. Safe under interrupt.
uint8_t
checkButton (uint8_t butName);
// *******************************************
// checkSwitch: Function returns state of the switch
// (UP = 1, DOWN = 0).
// *******************************************
uint8_t checkSwitch();
#endif /*BUTTONS_H_*/