diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/button.c | 105 | ||||
-rw-r--r-- | firmware/drivers/button.h | 13 |
2 files changed, 67 insertions, 51 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 24e45886ad..878f041c78 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -37,7 +37,6 @@ struct event_queue button_queue; | |||
37 | 37 | ||
38 | static int repeat_mask = DEFAULT_REPEAT_MASK; | 38 | static int repeat_mask = DEFAULT_REPEAT_MASK; |
39 | static int release_mask = DEFAULT_RELEASE_MASK; | 39 | static int release_mask = DEFAULT_RELEASE_MASK; |
40 | static int locked_mask = DEFAULT_LOCKED_MASK; | ||
41 | 40 | ||
42 | static int button_read(void); | 41 | static int button_read(void); |
43 | 42 | ||
@@ -50,73 +49,92 @@ static void button_tick(void) | |||
50 | int diff; | 49 | int diff; |
51 | 50 | ||
52 | /* only poll every X ticks */ | 51 | /* only poll every X ticks */ |
53 | if ( ++tick >= POLL_FREQUENCY ) { | 52 | if ( ++tick >= POLL_FREQUENCY ) |
53 | { | ||
54 | bool post = false; | 54 | bool post = false; |
55 | int btn = button_read(); | 55 | int btn = button_read(); |
56 | 56 | ||
57 | /* Find out if a key has been released */ | ||
58 | diff = btn ^ lastbtn; | ||
59 | if((btn & diff) == 0) | ||
60 | { | ||
61 | if(diff & release_mask) | ||
62 | queue_post(&button_queue, BUTTON_REL | diff, NULL); | ||
63 | } | ||
64 | |||
57 | if ( btn ) | 65 | if ( btn ) |
58 | { | 66 | { |
59 | /* Find out if a key has been released */ | ||
60 | diff = btn ^ lastbtn; | ||
61 | if((btn & diff) == 0) | ||
62 | { | ||
63 | if(diff & release_mask) | ||
64 | queue_post(&button_queue, BUTTON_REL | diff, NULL); | ||
65 | } | ||
66 | |||
67 | /* normal keypress */ | 67 | /* normal keypress */ |
68 | if ( btn != lastbtn ) { | 68 | if ( btn != lastbtn ) |
69 | { | ||
69 | post = true; | 70 | post = true; |
71 | repeat = false; | ||
70 | } | 72 | } |
71 | /* repeat? */ | 73 | else /* repeat? */ |
72 | else { | 74 | { |
73 | if ( repeat ) { | 75 | if ( repeat ) |
76 | { | ||
74 | if ( ! --count ) { | 77 | if ( ! --count ) { |
75 | post = true; | 78 | post = true; |
76 | count = REPEAT_INTERVAL; | 79 | count = REPEAT_INTERVAL; |
77 | } | 80 | } |
78 | } | 81 | } |
79 | else if (count++ > REPEAT_START) { | 82 | else |
80 | /* Only repeat if a repeatable key is pressed */ | 83 | { |
81 | if(btn & repeat_mask) | 84 | if(btn & repeat_mask || |
85 | #ifdef HAVE_RECORDER_KEYPAD | ||
86 | btn == BUTTON_OFF) | ||
87 | #else | ||
88 | btn == BUTTON_STOP) | ||
89 | #endif | ||
82 | { | 90 | { |
83 | post = true; | 91 | if (count++ > REPEAT_START) |
84 | repeat = true; | 92 | { |
85 | count = REPEAT_INTERVAL; | 93 | /* Only repeat if a repeatable key is pressed */ |
86 | } | 94 | if(btn & repeat_mask) |
87 | /* If the OFF button is pressed long enough, and we are | 95 | { |
88 | still alive, then the unit must be connected to a | 96 | post = true; |
89 | charger. Therefore we will reboot and let the original | 97 | repeat = true; |
90 | firmware handle the charging. */ | 98 | count = REPEAT_INTERVAL; |
99 | } | ||
100 | /* If the OFF button is pressed long enough, | ||
101 | and we are still alive, then the unit must be | ||
102 | connected to a charger. Therefore we will | ||
103 | reboot and let the original firmware handle | ||
104 | the charging. */ | ||
91 | #ifdef HAVE_RECORDER_KEYPAD | 105 | #ifdef HAVE_RECORDER_KEYPAD |
92 | if(btn == BUTTON_OFF) | 106 | if(btn == BUTTON_OFF) |
93 | #elif HAVE_PLAYER_KEYPAD | 107 | #elif HAVE_PLAYER_KEYPAD |
94 | if(btn == BUTTON_STOP) | 108 | if(btn == BUTTON_STOP) |
95 | #endif | 109 | #endif |
96 | system_reboot(); | 110 | system_reboot(); |
111 | } | ||
112 | } | ||
113 | else | ||
114 | { | ||
115 | count = 0; | ||
116 | } | ||
97 | } | 117 | } |
98 | } | 118 | } |
99 | if ( post ) | 119 | if ( post ) |
100 | { | 120 | { |
101 | queue_post(&button_queue, btn, NULL); | 121 | if(repeat) |
122 | queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); | ||
123 | else | ||
124 | queue_post(&button_queue, btn, NULL); | ||
102 | backlight_on(); | 125 | backlight_on(); |
103 | } | 126 | } |
104 | } | 127 | } |
105 | else { | 128 | else |
129 | { | ||
106 | repeat = false; | 130 | repeat = false; |
107 | count = 0; | 131 | count = 0; |
108 | /* Report that the key has been released */ | ||
109 | if(lastbtn != btn) | ||
110 | { | ||
111 | if(lastbtn & release_mask) | ||
112 | queue_post(&button_queue, BUTTON_REL | lastbtn, NULL); | ||
113 | } | ||
114 | } | 132 | } |
115 | 133 | ||
116 | lastbtn = btn; | 134 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); |
117 | tick = 0; | 135 | tick = 0; |
118 | } | 136 | } |
119 | 137 | ||
120 | backlight_tick(); | 138 | backlight_tick(); |
121 | } | 139 | } |
122 | 140 | ||
@@ -145,13 +163,6 @@ int button_set_release(int newmask) | |||
145 | return oldmask; | 163 | return oldmask; |
146 | } | 164 | } |
147 | 165 | ||
148 | int button_set_locked(int newmask) | ||
149 | { | ||
150 | int oldmask = locked_mask; | ||
151 | locked_mask = newmask; | ||
152 | return oldmask; | ||
153 | } | ||
154 | |||
155 | #ifdef HAVE_RECORDER_KEYPAD | 166 | #ifdef HAVE_RECORDER_KEYPAD |
156 | 167 | ||
157 | /* AJBR buttons are connected to the CPU as follows: | 168 | /* AJBR buttons are connected to the CPU as follows: |
diff --git a/firmware/drivers/button.h b/firmware/drivers/button.h index d5c194cedb..22d648caf6 100644 --- a/firmware/drivers/button.h +++ b/firmware/drivers/button.h | |||
@@ -28,7 +28,6 @@ void button_init (void); | |||
28 | int button_get (bool block); | 28 | int button_get (bool block); |
29 | int button_set_repeat(int newmask); | 29 | int button_set_repeat(int newmask); |
30 | int button_set_release(int newmask); | 30 | int button_set_release(int newmask); |
31 | int button_set_locked(int newmask); | ||
32 | 31 | ||
33 | /* Shared button codes */ | 32 | /* Shared button codes */ |
34 | #define BUTTON_NONE 0x0000 | 33 | #define BUTTON_NONE 0x0000 |
@@ -39,7 +38,7 @@ int button_set_locked(int newmask); | |||
39 | #define BUTTON_RIGHT 0x0080 | 38 | #define BUTTON_RIGHT 0x0080 |
40 | 39 | ||
41 | /* Button modifiers */ | 40 | /* Button modifiers */ |
42 | #define BUTTON_HELD 0x4000 | 41 | #define BUTTON_REPEAT 0x4000 |
43 | #define BUTTON_REL 0x8000 | 42 | #define BUTTON_REL 0x8000 |
44 | 43 | ||
45 | /* Special message */ | 44 | /* Special message */ |
@@ -56,7 +55,11 @@ int button_set_locked(int newmask); | |||
56 | 55 | ||
57 | #define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT | \ | 56 | #define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT | \ |
58 | BUTTON_UP | BUTTON_DOWN) | 57 | BUTTON_UP | BUTTON_DOWN) |
59 | 58 | ||
59 | #define ALL_BUTTONS (BUTTON_ON | BUTTON_UP | BUTTON_DOWN | BUTTON_LEFT | \ | ||
60 | BUTTON_RIGHT | BUTTON_OFF | BUTTON_PLAY | BUTTON_F1 | \ | ||
61 | BUTTON_F2 | BUTTON_F3) | ||
62 | |||
60 | #elif HAVE_PLAYER_KEYPAD | 63 | #elif HAVE_PLAYER_KEYPAD |
61 | 64 | ||
62 | /* Jukebox 6000 and Studio specific button codes */ | 65 | /* Jukebox 6000 and Studio specific button codes */ |
@@ -66,9 +69,11 @@ int button_set_locked(int newmask); | |||
66 | 69 | ||
67 | #define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT) | 70 | #define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT) |
68 | 71 | ||
72 | #define ALL_BUTTONS (BUTTON_ON | BUTTON_UP | BUTTON_DOWN | BUTTON_LEFT | \ | ||
73 | BUTTON_RIGHT | BUTTON_OFF | BUTTON_MENU) | ||
74 | |||
69 | #endif /* HAVE_PLAYER_KEYPAD */ | 75 | #endif /* HAVE_PLAYER_KEYPAD */ |
70 | 76 | ||
71 | #define DEFAULT_RELEASE_MASK 0 | 77 | #define DEFAULT_RELEASE_MASK 0 |
72 | #define DEFAULT_LOCKED_MASK 0 | ||
73 | 78 | ||
74 | #endif | 79 | #endif |