diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-03-05 09:25:09 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-03-12 18:25:10 +0000 |
commit | 905591215fdad421f9985ad846b082b86a9ed0b7 (patch) | |
tree | bcaab46908cb4112e8f62fd5ba938193e4747c7f | |
parent | e2fcbd04ea8a9334b6c961a2f19933d8b9d675d4 (diff) | |
download | rockbox-905591215fdad421f9985ad846b082b86a9ed0b7.tar.gz rockbox-905591215fdad421f9985ad846b082b86a9ed0b7.zip |
x1000: bootloader: split off recovery menu code
Change-Id: I6c6a25dc248b5dcbca796781f761bef05337431c
-rw-r--r-- | bootloader/SOURCES | 1 | ||||
-rw-r--r-- | bootloader/x1000.c | 109 | ||||
-rw-r--r-- | bootloader/x1000/recovery.c | 136 | ||||
-rw-r--r-- | bootloader/x1000/x1000bootloader.h | 6 |
4 files changed, 143 insertions, 109 deletions
diff --git a/bootloader/SOURCES b/bootloader/SOURCES index e818fab916..16391f8528 100644 --- a/bootloader/SOURCES +++ b/bootloader/SOURCES | |||
@@ -92,4 +92,5 @@ x1000.c | |||
92 | x1000/boot.c | 92 | x1000/boot.c |
93 | x1000/gui.c | 93 | x1000/gui.c |
94 | x1000/install.c | 94 | x1000/install.c |
95 | x1000/recovery.c | ||
95 | #endif | 96 | #endif |
diff --git a/bootloader/x1000.c b/bootloader/x1000.c index c57ddfff4e..8b1dae3050 100644 --- a/bootloader/x1000.c +++ b/bootloader/x1000.c | |||
@@ -56,38 +56,12 @@ | |||
56 | #include <stdio.h> | 56 | #include <stdio.h> |
57 | #include <stdarg.h> | 57 | #include <stdarg.h> |
58 | 58 | ||
59 | enum { | ||
60 | MENUITEM_HEADING, | ||
61 | MENUITEM_ACTION, | ||
62 | }; | ||
63 | |||
64 | struct menuitem { | ||
65 | int type; | ||
66 | const char* text; | ||
67 | void(*action)(void); | ||
68 | }; | ||
69 | |||
70 | void init_lcd(void); | 59 | void init_lcd(void); |
71 | void init_usb(void); | 60 | void init_usb(void); |
72 | int init_disk(void); | 61 | int init_disk(void); |
73 | 62 | ||
74 | void recovery_menu(void) __attribute__((noreturn)); | ||
75 | |||
76 | void usb_mode(void); | 63 | void usb_mode(void); |
77 | 64 | ||
78 | /* Defines the recovery menu contents */ | ||
79 | const struct menuitem recovery_items[] = { | ||
80 | {MENUITEM_HEADING, "System", NULL}, | ||
81 | {MENUITEM_ACTION, "Start Rockbox", &boot_rockbox}, | ||
82 | {MENUITEM_ACTION, "USB mode", &usb_mode}, | ||
83 | {MENUITEM_ACTION, "Shutdown", &shutdown}, | ||
84 | {MENUITEM_ACTION, "Reboot", &reboot}, | ||
85 | {MENUITEM_HEADING, "Bootloader", NULL}, | ||
86 | {MENUITEM_ACTION, "Install or update", &bootloader_install}, | ||
87 | {MENUITEM_ACTION, "Backup", &bootloader_backup}, | ||
88 | {MENUITEM_ACTION, "Restore", &bootloader_restore}, | ||
89 | }; | ||
90 | |||
91 | /* Flags to indicate if hardware was already initialized */ | 65 | /* Flags to indicate if hardware was already initialized */ |
92 | bool usb_inited = false; | 66 | bool usb_inited = false; |
93 | bool disk_inited = false; | 67 | bool disk_inited = false; |
@@ -126,89 +100,6 @@ int init_disk(void) | |||
126 | return 0; | 100 | return 0; |
127 | } | 101 | } |
128 | 102 | ||
129 | void put_help_line(int line, const char* str1, const char* str2) | ||
130 | { | ||
131 | int width = LCD_WIDTH / SYSFONT_WIDTH; | ||
132 | lcd_puts(0, line, str1); | ||
133 | lcd_puts(width - strlen(str2), line, str2); | ||
134 | } | ||
135 | |||
136 | void recovery_menu(void) | ||
137 | { | ||
138 | const int n_items = sizeof(recovery_items)/sizeof(struct menuitem); | ||
139 | |||
140 | int selection = 0; | ||
141 | while(recovery_items[selection].type != MENUITEM_ACTION) | ||
142 | ++selection; | ||
143 | |||
144 | while(1) { | ||
145 | clearscreen(); | ||
146 | putcenter_y(0, "Rockbox recovery menu"); | ||
147 | |||
148 | int top_line = 2; | ||
149 | |||
150 | /* draw the menu */ | ||
151 | for(int i = 0; i < n_items; ++i) { | ||
152 | switch(recovery_items[i].type) { | ||
153 | case MENUITEM_HEADING: | ||
154 | lcd_putsf(0, top_line+i, "[%s]", recovery_items[i].text); | ||
155 | break; | ||
156 | |||
157 | case MENUITEM_ACTION: | ||
158 | lcd_puts(3, top_line+i, recovery_items[i].text); | ||
159 | break; | ||
160 | |||
161 | default: | ||
162 | break; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | /* draw the selection marker */ | ||
167 | lcd_puts(0, top_line+selection, "=>"); | ||
168 | |||
169 | /* draw the help text */ | ||
170 | int line = (LCD_HEIGHT - SYSFONT_HEIGHT)/SYSFONT_HEIGHT - 3; | ||
171 | put_help_line(line++, BL_DOWN_NAME "/" BL_UP_NAME, "move cursor"); | ||
172 | put_help_line(line++, BL_SELECT_NAME, "select item"); | ||
173 | put_help_line(line++, BL_QUIT_NAME, "power off"); | ||
174 | |||
175 | lcd_update(); | ||
176 | |||
177 | /* handle input */ | ||
178 | switch(get_button(TIMEOUT_BLOCK)) { | ||
179 | case BL_SELECT: { | ||
180 | if(recovery_items[selection].action) | ||
181 | recovery_items[selection].action(); | ||
182 | } break; | ||
183 | |||
184 | case BL_UP: | ||
185 | for(int i = selection-1; i >= 0; --i) { | ||
186 | if(recovery_items[i].action) { | ||
187 | selection = i; | ||
188 | break; | ||
189 | } | ||
190 | } | ||
191 | break; | ||
192 | |||
193 | case BL_DOWN: | ||
194 | for(int i = selection+1; i < n_items; ++i) { | ||
195 | if(recovery_items[i].action) { | ||
196 | selection = i; | ||
197 | break; | ||
198 | } | ||
199 | } | ||
200 | break; | ||
201 | |||
202 | case BL_QUIT: | ||
203 | shutdown(); | ||
204 | break; | ||
205 | |||
206 | default: | ||
207 | break; | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | |||
212 | void usb_mode(void) | 103 | void usb_mode(void) |
213 | { | 104 | { |
214 | init_usb(); | 105 | init_usb(); |
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 | } | ||
diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h index 47f340532d..05f421fc61 100644 --- a/bootloader/x1000/x1000bootloader.h +++ b/bootloader/x1000/x1000bootloader.h | |||
@@ -92,4 +92,10 @@ void boot_rockbox(void); | |||
92 | void shutdown(void); | 92 | void shutdown(void); |
93 | void reboot(void); | 93 | void reboot(void); |
94 | 94 | ||
95 | /* | ||
96 | * Misc | ||
97 | */ | ||
98 | |||
99 | void recovery_menu(void) __attribute__((noreturn)); | ||
100 | |||
95 | #endif /* __X1000BOOTLOADER_H__ */ | 101 | #endif /* __X1000BOOTLOADER_H__ */ |