summaryrefslogtreecommitdiff
path: root/bootloader/x1000
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader/x1000')
-rw-r--r--bootloader/x1000/recovery.c136
-rw-r--r--bootloader/x1000/x1000bootloader.h6
2 files changed, 142 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
29extern void usb_mode(void);
30
31enum {
32 MENUITEM_HEADING,
33 MENUITEM_ACTION,
34};
35
36struct menuitem {
37 int type;
38 const char* text;
39 void(*action)(void);
40};
41
42/* Defines the recovery menu contents */
43static 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
55static 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
62void 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);
92void shutdown(void); 92void shutdown(void);
93void reboot(void); 93void reboot(void);
94 94
95/*
96 * Misc
97 */
98
99void recovery_menu(void) __attribute__((noreturn));
100
95#endif /* __X1000BOOTLOADER_H__ */ 101#endif /* __X1000BOOTLOADER_H__ */