-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.h
More file actions
40 lines (32 loc) · 1.22 KB
/
Copy pathinput.h
File metadata and controls
40 lines (32 loc) · 1.22 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
// input.h — Button and joystick polling interface.
//
// Four directional inputs on PORTD (PD2, PD4, PD5, PD6), internal
// pull-ups enabled, active-low. NOTE: that's direction-only -- there's no
// separate confirm/back/select line in the spec. See the TODO in menu.c;
// this is flagged as an open design question, not silently worked around.
#ifndef INPUT_H
#define INPUT_H
#include <stdint.h>
#include <stdbool.h>
typedef enum {
BUTTON_UP = 0,
BUTTON_DOWN,
BUTTON_LEFT,
BUTTON_RIGHT,
BUTTON_START,
BUTTON_SELECT,
BUTTON_HOME,
BUTTON_COUNT
} ButtonId;
void inputInit(void);
// Call once per main loop iteration with the current systemGetTimeMs().
// Runs edge-triggered, time-based debouncing for all four buttons.
void inputUpdate(uint32_t nowMs);
bool inputIsHeld(ButtonId btn);
bool inputWasPressed(ButtonId btn); // debounced press edge this frame
bool inputWasReleased(ButtonId btn); // debounced release edge this frame
bool inputIsRepeated(ButtonId btn); // triggers on press, then repeats while held
// Returns the raw ADC 10-bit value (0-1023). Midpoint is ~512.
uint16_t inputGetJoystickX(void);
uint16_t inputGetJoystickY(void);
#endif // INPUT_H