lijuang | 86f46b4 | 2015-12-23 13:39:22 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <debug.h> |
| 30 | #include <reg.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <pm8x41.h> |
| 33 | #include <pm8x41_hw.h> |
| 34 | #include <kernel/timer.h> |
| 35 | #include <platform/timer.h> |
| 36 | #include <kernel/thread.h> |
| 37 | #include <dev/keys.h> |
| 38 | #include <dev/fbcon.h> |
| 39 | #include <menu_keys_detect.h> |
| 40 | #include <display_menu.h> |
| 41 | #include <platform/gpio.h> |
| 42 | #include <platform/iomap.h> |
| 43 | #include <platform.h> |
lijuang | f5045b5 | 2015-09-07 17:19:20 +0800 | [diff] [blame] | 44 | #include <reboot.h> |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 45 | #include <sys/types.h> |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 46 | #include <../../../app/aboot/recovery.h> |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 47 | #include <../../../app/aboot/devinfo.h> |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 48 | |
| 49 | #define KEY_DETECT_FREQUENCY 50 |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 50 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 51 | static time_t before_time; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 52 | |
| 53 | extern int target_volume_up(); |
| 54 | extern uint32_t target_volume_down(); |
| 55 | extern void reboot_device(unsigned reboot_reason); |
| 56 | extern void shutdown_device(); |
| 57 | |
| 58 | typedef uint32_t (*keys_detect_func)(void); |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 59 | typedef void (*keys_action_func)(struct select_msg_info* msg_info); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 60 | |
| 61 | struct keys_stru { |
| 62 | int type; |
| 63 | keys_detect_func keys_pressed_func; |
| 64 | }; |
| 65 | |
| 66 | struct keys_stru keys[] = { |
| 67 | {VOLUME_UP, (uint32_t (*)(void))target_volume_up}, |
| 68 | {VOLUME_DOWN, target_volume_down}, |
| 69 | {POWER_KEY, pm8x41_get_pwrkey_is_pressed}, |
| 70 | }; |
| 71 | |
| 72 | struct pages_action { |
| 73 | keys_action_func up_action_func; |
| 74 | keys_action_func down_action_func; |
| 75 | keys_action_func enter_action_func; |
| 76 | }; |
| 77 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 78 | static uint32_t verify_index_action[] = { |
| 79 | [0] = POWEROFF, |
| 80 | [1] = RESTART, |
| 81 | [2] = RECOVER, |
| 82 | [3] = FASTBOOT, |
| 83 | [4] = BACK, |
| 84 | }; |
| 85 | |
| 86 | static uint32_t fastboot_index_action[] = { |
| 87 | [0] = RESTART, |
| 88 | [1] = FASTBOOT, |
| 89 | [2] = RECOVER, |
| 90 | [3] = POWEROFF, |
lijuang | 42aefaa | 2016-04-14 15:55:17 +0800 | [diff] [blame] | 91 | [4] = FFBM, |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | static uint32_t unlock_index_action[] = { |
| 95 | [0] = RECOVER, |
| 96 | [1] = RESTART, |
| 97 | }; |
| 98 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 99 | static int is_key_pressed(int keys_type) |
| 100 | { |
| 101 | int count = 0; |
| 102 | |
| 103 | if (keys[keys_type].keys_pressed_func()) { |
| 104 | /*if key is pressed, wait for 1 second to see if it is released*/ |
| 105 | while(count++ < 10 && keys[keys_type].keys_pressed_func()) |
| 106 | thread_sleep(100); |
| 107 | return 1; |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 113 | static void update_device_status(struct select_msg_info* msg_info, int reason) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 114 | { |
lijuang | 42aefaa | 2016-04-14 15:55:17 +0800 | [diff] [blame] | 115 | char ffbm_page_buffer[FFBM_MODE_BUF_SIZE]; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 116 | fbcon_clear(); |
| 117 | switch (reason) { |
| 118 | case RECOVER: |
| 119 | if (msg_info->info.msg_type == DISPLAY_MENU_UNLOCK) { |
| 120 | set_device_unlock_value(UNLOCK, TRUE); |
| 121 | } else if (msg_info->info.msg_type == DISPLAY_MENU_UNLOCK_CRITICAL) { |
| 122 | set_device_unlock_value(UNLOCK_CRITICAL, TRUE); |
| 123 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 124 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 125 | if (msg_info->info.msg_type == DISPLAY_MENU_UNLOCK || |
| 126 | msg_info->info.msg_type == DISPLAY_MENU_UNLOCK_CRITICAL) { |
| 127 | /* wipe data */ |
| 128 | struct recovery_message msg; |
lijuang | f5045b5 | 2015-09-07 17:19:20 +0800 | [diff] [blame] | 129 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 130 | snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data"); |
| 131 | write_misc(0, &msg, sizeof(msg)); |
| 132 | } |
| 133 | reboot_device(RECOVERY_MODE); |
| 134 | break; |
| 135 | case RESTART: |
| 136 | reboot_device(0); |
| 137 | break; |
| 138 | case POWEROFF: |
| 139 | shutdown_device(); |
| 140 | break; |
| 141 | case FASTBOOT: |
| 142 | reboot_device(FASTBOOT_MODE); |
| 143 | break; |
| 144 | case CONTINUE: |
| 145 | display_image_on_screen(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 146 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 147 | /* Continue boot, no need to detect the keys'status */ |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 148 | msg_info->info.is_exit = true; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 149 | break; |
| 150 | case BACK: |
| 151 | display_bootverify_menu_renew(msg_info, msg_info->last_msg_type); |
| 152 | before_time = current_time(); |
| 153 | |
| 154 | break; |
lijuang | 42aefaa | 2016-04-14 15:55:17 +0800 | [diff] [blame] | 155 | case FFBM: |
| 156 | snprintf(ffbm_page_buffer, sizeof(ffbm_page_buffer), "ffbm-00"); |
| 157 | write_misc(0, ffbm_page_buffer, sizeof(ffbm_page_buffer)); |
| 158 | |
| 159 | reboot_device(0); |
| 160 | break; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 164 | /* msg_lock need to be holded when call this function. */ |
| 165 | static void update_volume_up_bg(struct select_msg_info* msg_info) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 166 | { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 167 | if (msg_info->info.option_index == msg_info->info.option_num - 1) { |
| 168 | fbcon_draw_msg_background(msg_info->info.option_start[0], |
| 169 | msg_info->info.option_end[0], |
| 170 | msg_info->info.option_bg[0], 0); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 171 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 172 | fbcon_draw_msg_background(msg_info->info.option_start[msg_info->info.option_num - 1], |
| 173 | msg_info->info.option_end[msg_info->info.option_num - 1], |
| 174 | msg_info->info.option_bg[msg_info->info.option_num - 1], 1); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 175 | } else { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 176 | fbcon_draw_msg_background(msg_info->info.option_start[msg_info->info.option_index], |
| 177 | msg_info->info.option_end[msg_info->info.option_index], |
| 178 | msg_info->info.option_bg[msg_info->info.option_index], 1); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 179 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 180 | fbcon_draw_msg_background(msg_info->info.option_start[msg_info->info.option_index + 1], |
| 181 | msg_info->info.option_end[msg_info->info.option_index + 1], |
| 182 | msg_info->info.option_bg[msg_info->info.option_index + 1], 0); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 186 | /* msg_lock need to be holded when call this function. */ |
| 187 | static void update_volume_down_bg(struct select_msg_info* msg_info) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 188 | { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 189 | if (msg_info->info.option_index == 0) { |
| 190 | fbcon_draw_msg_background(msg_info->info.option_start[0], |
| 191 | msg_info->info.option_end[0], |
| 192 | msg_info->info.option_bg[0], 1); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 193 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 194 | fbcon_draw_msg_background(msg_info->info.option_start[msg_info->info.option_num - 1], |
| 195 | msg_info->info.option_end[msg_info->info.option_num - 1], |
| 196 | msg_info->info.option_bg[msg_info->info.option_num - 1], 0); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 197 | } else { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 198 | fbcon_draw_msg_background(msg_info->info.option_start[msg_info->info.option_index], |
| 199 | msg_info->info.option_end[msg_info->info.option_index], |
| 200 | msg_info->info.option_bg[msg_info->info.option_index], 1); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 201 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 202 | fbcon_draw_msg_background(msg_info->info.option_start[msg_info->info.option_index - 1], |
| 203 | msg_info->info.option_end[msg_info->info.option_index - 1], |
| 204 | msg_info->info.option_bg[msg_info->info.option_index - 1], 0); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
| 208 | /* update select option's background when volume up key is pressed */ |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 209 | static void menu_volume_up_func (struct select_msg_info* msg_info) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 210 | { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 211 | if (msg_info->info.option_index == 0) |
| 212 | msg_info->info.option_index = msg_info->info.option_num - 1; |
| 213 | else |
| 214 | msg_info->info.option_index--; |
| 215 | |
| 216 | if (msg_info->info.msg_type == DISPLAY_MENU_FASTBOOT) { |
| 217 | display_fastboot_menu_renew(msg_info); |
| 218 | } else { |
| 219 | update_volume_up_bg(msg_info); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 220 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* update select option's background when volume down key is pressed */ |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 224 | static void menu_volume_down_func (struct select_msg_info* msg_info) |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 225 | { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 226 | msg_info->info.option_index++; |
| 227 | if (msg_info->info.option_index >= msg_info->info.option_num) |
| 228 | msg_info->info.option_index = 0; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 229 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 230 | if (msg_info->info.msg_type == DISPLAY_MENU_FASTBOOT) { |
| 231 | display_fastboot_menu_renew(msg_info); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 232 | } else { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 233 | update_volume_down_bg(msg_info); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 234 | } |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 235 | } |
| 236 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 237 | /* enter to boot verification option page if volume key is pressed */ |
| 238 | static void boot_warning_volume_keys_func (struct select_msg_info* msg_info) |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 239 | { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 240 | msg_info->last_msg_type = msg_info->info.msg_type; |
| 241 | display_bootverify_option_menu_renew(msg_info); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | /* update device's status via select option */ |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 245 | static void power_key_func(struct select_msg_info* msg_info) |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 246 | { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 247 | int reason = -1; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 248 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 249 | switch (msg_info->info.msg_type) { |
| 250 | case DISPLAY_MENU_YELLOW: |
| 251 | case DISPLAY_MENU_ORANGE: |
| 252 | case DISPLAY_MENU_RED: |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 253 | case DISPLAY_MENU_LOGGING: |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame^] | 254 | case DISPLAY_MENU_EIO: |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 255 | reason = CONTINUE; |
| 256 | break; |
| 257 | case DISPLAY_MENU_MORE_OPTION: |
| 258 | if(msg_info->info.option_index < ARRAY_SIZE(verify_index_action)) |
| 259 | reason = verify_index_action[msg_info->info.option_index]; |
| 260 | break; |
| 261 | case DISPLAY_MENU_UNLOCK: |
| 262 | case DISPLAY_MENU_UNLOCK_CRITICAL: |
| 263 | if(msg_info->info.option_index < ARRAY_SIZE(unlock_index_action)) |
| 264 | reason = unlock_index_action[msg_info->info.option_index]; |
| 265 | break; |
| 266 | case DISPLAY_MENU_FASTBOOT: |
| 267 | if(msg_info->info.option_index < ARRAY_SIZE(fastboot_index_action)) |
| 268 | reason = fastboot_index_action[msg_info->info.option_index]; |
| 269 | break; |
| 270 | default: |
| 271 | dprintf(CRITICAL,"Unsupported menu type\n"); |
| 272 | break; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 273 | } |
| 274 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 275 | if (reason != -1) { |
| 276 | update_device_status(msg_info, reason); |
| 277 | } |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 278 | } |
| 279 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 280 | /* Initialize different page's function |
| 281 | * DISPLAY_MENU_UNLOCK/DISPLAY_MENU_UNLOCK_CRITICAL |
| 282 | * DISPLAY_MENU_MORE_OPTION/DISPLAY_MENU_FASTBOOT: |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 283 | * up_action_func: update select option's background when volume up |
| 284 | * is pressed |
| 285 | * down_action_func: update select option's background when volume up |
| 286 | * is pressed |
| 287 | * enter_action_func: update device's status via select option |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 288 | * DISPLAY_MENU_YELLOW/DISPLAY_MENU_ORANGE/DISPLAY_MENU_RED: |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 289 | * up_action_func/down_action_func: enter BOOT_VERIFY_PAGE2 when volume |
| 290 | * key is pressed |
| 291 | * enter_action_func: continue booting |
| 292 | */ |
| 293 | static struct pages_action menu_pages_action[] = { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 294 | [DISPLAY_MENU_UNLOCK] = { |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 295 | menu_volume_up_func, |
| 296 | menu_volume_down_func, |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 297 | power_key_func, |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 298 | }, |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 299 | [DISPLAY_MENU_UNLOCK_CRITICAL] = { |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 300 | menu_volume_up_func, |
| 301 | menu_volume_down_func, |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 302 | power_key_func, |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 303 | }, |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 304 | [DISPLAY_MENU_YELLOW] = { |
| 305 | boot_warning_volume_keys_func, |
| 306 | boot_warning_volume_keys_func, |
| 307 | power_key_func, |
| 308 | }, |
| 309 | [DISPLAY_MENU_ORANGE] = { |
| 310 | boot_warning_volume_keys_func, |
| 311 | boot_warning_volume_keys_func, |
| 312 | power_key_func, |
| 313 | }, |
| 314 | [DISPLAY_MENU_RED] = { |
| 315 | boot_warning_volume_keys_func, |
| 316 | boot_warning_volume_keys_func, |
| 317 | power_key_func, |
| 318 | }, |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 319 | [DISPLAY_MENU_LOGGING] = { |
| 320 | boot_warning_volume_keys_func, |
| 321 | boot_warning_volume_keys_func, |
| 322 | power_key_func, |
| 323 | }, |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame^] | 324 | [DISPLAY_MENU_EIO] = { |
| 325 | boot_warning_volume_keys_func, |
| 326 | boot_warning_volume_keys_func, |
| 327 | power_key_func, |
| 328 | }, |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 329 | [DISPLAY_MENU_MORE_OPTION] = { |
| 330 | menu_volume_up_func, |
| 331 | menu_volume_down_func, |
| 332 | power_key_func, |
| 333 | }, |
| 334 | [DISPLAY_MENU_FASTBOOT] = { |
| 335 | menu_volume_up_func, |
| 336 | menu_volume_down_func, |
| 337 | power_key_func, |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 338 | }, |
| 339 | |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 340 | }; |
| 341 | |
| 342 | void keys_detect_init() |
| 343 | { |
lijuang | 86f46b4 | 2015-12-23 13:39:22 +0800 | [diff] [blame] | 344 | /* Waiting for all keys are released */ |
| 345 | while(1) { |
| 346 | if(!keys[VOLUME_UP].keys_pressed_func() && |
| 347 | !keys[VOLUME_DOWN].keys_pressed_func() && |
| 348 | !keys[POWER_KEY].keys_pressed_func()) { |
| 349 | break; |
| 350 | } |
| 351 | thread_sleep(KEY_DETECT_FREQUENCY); |
| 352 | } |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 353 | |
| 354 | before_time = current_time(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | int select_msg_keys_detect(void *param) { |
| 358 | struct select_msg_info *msg_info = (struct select_msg_info*)param; |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 359 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 360 | msg_lock_init(); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 361 | keys_detect_init(); |
| 362 | while(1) { |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 363 | /* 1: update select option's index, default it is the total option number |
| 364 | * volume up: index decrease, the option will scroll up from |
| 365 | * the bottom to top if the key is pressed firstly. |
| 366 | * eg: 5->4->3->2->1->0 |
| 367 | * volume down: index increase, the option will scroll down from |
| 368 | * the bottom to top if the key is pressed firstly. |
| 369 | * eg: 5->0 |
| 370 | * 2: update device's status via select option's index |
| 371 | */ |
| 372 | if (is_key_pressed(VOLUME_UP)) { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 373 | mutex_acquire(&msg_info->msg_lock); |
| 374 | menu_pages_action[msg_info->info.msg_type].up_action_func(msg_info); |
| 375 | mutex_release(&msg_info->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 376 | } else if (is_key_pressed(VOLUME_DOWN)) { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 377 | mutex_acquire(&msg_info->msg_lock); |
| 378 | menu_pages_action[msg_info->info.msg_type].down_action_func(msg_info); |
| 379 | mutex_release(&msg_info->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 380 | } else if (is_key_pressed(POWER_KEY)) { |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 381 | mutex_acquire(&msg_info->msg_lock); |
| 382 | menu_pages_action[msg_info->info.msg_type].enter_action_func(msg_info); |
| 383 | mutex_release(&msg_info->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 384 | } |
| 385 | |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 386 | mutex_acquire(&msg_info->msg_lock); |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 387 | /* Never time out if the timeout_time is 0 */ |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 388 | if(msg_info->info.timeout_time) { |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 389 | if ((current_time() - before_time) > msg_info->info.timeout_time) |
| 390 | msg_info->info.is_exit = true; |
| 391 | } |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 392 | |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 393 | if (msg_info->info.is_exit) { |
| 394 | msg_info->info.rel_exit = true; |
| 395 | mutex_release(&msg_info->msg_lock); |
| 396 | break; |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 397 | } |
| 398 | mutex_release(&msg_info->msg_lock); |
lijuang | 7d235f4 | 2015-07-16 20:19:45 +0800 | [diff] [blame] | 399 | thread_sleep(KEY_DETECT_FREQUENCY); |
| 400 | } |
| 401 | |
| 402 | return 0; |
| 403 | } |