diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/button.c | 45 | ||||
-rw-r--r-- | firmware/drivers/button.h | 10 |
2 files changed, 45 insertions, 10 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 636376b4e5..24e45886ad 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -36,6 +36,8 @@ struct event_queue button_queue; | |||
36 | #define REPEAT_INTERVAL 4 | 36 | #define REPEAT_INTERVAL 4 |
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; | ||
40 | static int locked_mask = DEFAULT_LOCKED_MASK; | ||
39 | 41 | ||
40 | static int button_read(void); | 42 | static int button_read(void); |
41 | 43 | ||
@@ -45,13 +47,23 @@ static void button_tick(void) | |||
45 | static int count=0; | 47 | static int count=0; |
46 | static int lastbtn=0; | 48 | static int lastbtn=0; |
47 | static bool repeat=false; | 49 | static bool repeat=false; |
50 | int diff; | ||
48 | 51 | ||
49 | /* only poll every X ticks */ | 52 | /* only poll every X ticks */ |
50 | if ( ++tick >= POLL_FREQUENCY ) { | 53 | if ( ++tick >= POLL_FREQUENCY ) { |
51 | bool post = false; | 54 | bool post = false; |
52 | int btn = button_read(); | 55 | int btn = button_read(); |
53 | 56 | ||
54 | if ( btn ) { | 57 | if ( btn ) |
58 | { | ||
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 | |||
55 | /* normal keypress */ | 67 | /* normal keypress */ |
56 | if ( btn != lastbtn ) { | 68 | if ( btn != lastbtn ) { |
57 | post = true; | 69 | post = true; |
@@ -96,7 +108,8 @@ static void button_tick(void) | |||
96 | /* Report that the key has been released */ | 108 | /* Report that the key has been released */ |
97 | if(lastbtn != btn) | 109 | if(lastbtn != btn) |
98 | { | 110 | { |
99 | queue_post(&button_queue, BUTTON_REL | lastbtn, NULL); | 111 | if(lastbtn & release_mask) |
112 | queue_post(&button_queue, BUTTON_REL | lastbtn, NULL); | ||
100 | } | 113 | } |
101 | } | 114 | } |
102 | 115 | ||
@@ -118,6 +131,27 @@ int button_get(bool block) | |||
118 | return BUTTON_NONE; | 131 | return BUTTON_NONE; |
119 | } | 132 | } |
120 | 133 | ||
134 | int button_set_repeat(int newmask) | ||
135 | { | ||
136 | int oldmask = repeat_mask; | ||
137 | repeat_mask = newmask; | ||
138 | return oldmask; | ||
139 | } | ||
140 | |||
141 | int button_set_release(int newmask) | ||
142 | { | ||
143 | int oldmask = release_mask; | ||
144 | release_mask = newmask; | ||
145 | return oldmask; | ||
146 | } | ||
147 | |||
148 | int button_set_locked(int newmask) | ||
149 | { | ||
150 | int oldmask = locked_mask; | ||
151 | locked_mask = newmask; | ||
152 | return oldmask; | ||
153 | } | ||
154 | |||
121 | #ifdef HAVE_RECORDER_KEYPAD | 155 | #ifdef HAVE_RECORDER_KEYPAD |
122 | 156 | ||
123 | /* AJBR buttons are connected to the CPU as follows: | 157 | /* AJBR buttons are connected to the CPU as follows: |
@@ -151,13 +185,6 @@ void button_init() | |||
151 | tick_add_task(button_tick); | 185 | tick_add_task(button_tick); |
152 | } | 186 | } |
153 | 187 | ||
154 | int button_set_repeat(int newmask) | ||
155 | { | ||
156 | int oldmask = repeat_mask; | ||
157 | repeat_mask = newmask; | ||
158 | return oldmask; | ||
159 | } | ||
160 | |||
161 | /* | 188 | /* |
162 | * Get button pressed from hardware | 189 | * Get button pressed from hardware |
163 | */ | 190 | */ |
diff --git a/firmware/drivers/button.h b/firmware/drivers/button.h index 0ff6b58291..d5c194cedb 100644 --- a/firmware/drivers/button.h +++ b/firmware/drivers/button.h | |||
@@ -27,6 +27,8 @@ extern struct event_queue button_queue; | |||
27 | void button_init (void); | 27 | 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); | ||
31 | int button_set_locked(int newmask); | ||
30 | 32 | ||
31 | /* Shared button codes */ | 33 | /* Shared button codes */ |
32 | #define BUTTON_NONE 0x0000 | 34 | #define BUTTON_NONE 0x0000 |
@@ -40,6 +42,9 @@ int button_set_repeat(int newmask); | |||
40 | #define BUTTON_HELD 0x4000 | 42 | #define BUTTON_HELD 0x4000 |
41 | #define BUTTON_REL 0x8000 | 43 | #define BUTTON_REL 0x8000 |
42 | 44 | ||
45 | /* Special message */ | ||
46 | #define BUTTON_LOCKED 0x2000 | ||
47 | |||
43 | #ifdef HAVE_RECORDER_KEYPAD | 48 | #ifdef HAVE_RECORDER_KEYPAD |
44 | 49 | ||
45 | /* Recorder specific button codes */ | 50 | /* Recorder specific button codes */ |
@@ -61,6 +66,9 @@ int button_set_repeat(int newmask); | |||
61 | 66 | ||
62 | #define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT) | 67 | #define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT) |
63 | 68 | ||
64 | #endif | 69 | #endif /* HAVE_PLAYER_KEYPAD */ |
70 | |||
71 | #define DEFAULT_RELEASE_MASK 0 | ||
72 | #define DEFAULT_LOCKED_MASK 0 | ||
65 | 73 | ||
66 | #endif | 74 | #endif |