diff options
Diffstat (limited to 'bootloader/x1000/recovery.c')
-rw-r--r-- | bootloader/x1000/recovery.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/bootloader/x1000/recovery.c b/bootloader/x1000/recovery.c new file mode 100644 index 0000000000..809bd6578a --- /dev/null +++ b/bootloader/x1000/recovery.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021-2022 Aidan MacDonald | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "x1000bootloader.h" | ||
23 | #include "lcd.h" | ||
24 | #include "font.h" | ||
25 | #include "button.h" | ||
26 | #include "kernel.h" | ||
27 | #include <string.h> | ||
28 | |||
29 | extern void usb_mode(void); | ||
30 | |||
31 | enum { | ||
32 | MENUITEM_HEADING, | ||
33 | MENUITEM_ACTION, | ||
34 | }; | ||
35 | |||
36 | struct menuitem { | ||
37 | int type; | ||
38 | const char* text; | ||
39 | void(*action)(void); | ||
40 | }; | ||
41 | |||
42 | /* Defines the recovery menu contents */ | ||
43 | static const struct menuitem recovery_items[] = { | ||
44 | {MENUITEM_HEADING, "System", NULL}, | ||
45 | {MENUITEM_ACTION, "Start Rockbox", &boot_rockbox}, | ||
46 | {MENUITEM_ACTION, "USB mode", &usb_mode}, | ||
47 | {MENUITEM_ACTION, "Shutdown", &shutdown}, | ||
48 | {MENUITEM_ACTION, "Reboot", &reboot}, | ||
49 | {MENUITEM_HEADING, "Bootloader", NULL}, | ||
50 | {MENUITEM_ACTION, "Install or update", &bootloader_install}, | ||
51 | {MENUITEM_ACTION, "Backup", &bootloader_backup}, | ||
52 | {MENUITEM_ACTION, "Restore", &bootloader_restore}, | ||
53 | }; | ||
54 | |||
55 | static void put_help_line(int line, const char* str1, const char* str2) | ||
56 | { | ||
57 | int width = LCD_WIDTH / SYSFONT_WIDTH; | ||
58 | lcd_puts(0, line, str1); | ||
59 | lcd_puts(width - strlen(str2), line, str2); | ||
60 | } | ||
61 | |||
62 | void recovery_menu(void) | ||
63 | { | ||
64 | const int n_items = sizeof(recovery_items)/sizeof(struct menuitem); | ||
65 | |||
66 | int selection = 0; | ||
67 | while(recovery_items[selection].type != MENUITEM_ACTION) | ||
68 | ++selection; | ||
69 | |||
70 | while(1) { | ||
71 | clearscreen(); | ||
72 | putcenter_y(0, "Rockbox recovery menu"); | ||
73 | |||
74 | int top_line = 2; | ||
75 | |||
76 | /* draw the menu */ | ||
77 | for(int i = 0; i < n_items; ++i) { | ||
78 | switch(recovery_items[i].type) { | ||
79 | case MENUITEM_HEADING: | ||
80 | lcd_putsf(0, top_line+i, "[%s]", recovery_items[i].text); | ||
81 | break; | ||
82 | |||
83 | case MENUITEM_ACTION: | ||
84 | lcd_puts(3, top_line+i, recovery_items[i].text); | ||
85 | break; | ||
86 | |||
87 | default: | ||
88 | break; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | /* draw the selection marker */ | ||
93 | lcd_puts(0, top_line+selection, "=>"); | ||
94 | |||
95 | /* draw the help text */ | ||
96 | int line = (LCD_HEIGHT - SYSFONT_HEIGHT)/SYSFONT_HEIGHT - 3; | ||
97 | put_help_line(line++, BL_DOWN_NAME "/" BL_UP_NAME, "move cursor"); | ||
98 | put_help_line(line++, BL_SELECT_NAME, "select item"); | ||
99 | put_help_line(line++, BL_QUIT_NAME, "power off"); | ||
100 | |||
101 | lcd_update(); | ||
102 | |||
103 | /* handle input */ | ||
104 | switch(get_button(TIMEOUT_BLOCK)) { | ||
105 | case BL_SELECT: { | ||
106 | if(recovery_items[selection].action) | ||
107 | recovery_items[selection].action(); | ||
108 | } break; | ||
109 | |||
110 | case BL_UP: | ||
111 | for(int i = selection-1; i >= 0; --i) { | ||
112 | if(recovery_items[i].action) { | ||
113 | selection = i; | ||
114 | break; | ||
115 | } | ||
116 | } | ||
117 | break; | ||
118 | |||
119 | case BL_DOWN: | ||
120 | for(int i = selection+1; i < n_items; ++i) { | ||
121 | if(recovery_items[i].action) { | ||
122 | selection = i; | ||
123 | break; | ||
124 | } | ||
125 | } | ||
126 | break; | ||
127 | |||
128 | case BL_QUIT: | ||
129 | shutdown(); | ||
130 | break; | ||
131 | |||
132 | default: | ||
133 | break; | ||
134 | } | ||
135 | } | ||
136 | } | ||