summaryrefslogtreecommitdiff
path: root/firmware/drivers/button.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/button.c')
-rw-r--r--firmware/drivers/button.c105
1 files changed, 58 insertions, 47 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
38static int repeat_mask = DEFAULT_REPEAT_MASK; 38static int repeat_mask = DEFAULT_REPEAT_MASK;
39static int release_mask = DEFAULT_RELEASE_MASK; 39static int release_mask = DEFAULT_RELEASE_MASK;
40static int locked_mask = DEFAULT_LOCKED_MASK;
41 40
42static int button_read(void); 41static 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
148int 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: