diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-02-27 22:08:58 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-03-28 00:01:37 +0000 |
commit | 3ec66893e377b088c1284d2d23adb2aeea6d7965 (patch) | |
tree | b647717f83ad56b15dc42cfdef5d04d68cd9bd6b /firmware/target/mips/ingenic_x1000/debug-x1000.c | |
parent | 83fcbedc65f4b9ae7e491ecf6f07c0af4b245f74 (diff) | |
download | rockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.tar.gz rockbox-3ec66893e377b088c1284d2d23adb2aeea6d7965.zip |
New port: FiiO M3K on bare metal
Change-Id: I7517e7d5459e129dcfc9465c6fbd708619888fbe
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/debug-x1000.c')
-rw-r--r-- | firmware/target/mips/ingenic_x1000/debug-x1000.c | 215 |
1 files changed, 215 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_x1000/debug-x1000.c b/firmware/target/mips/ingenic_x1000/debug-x1000.c new file mode 100644 index 0000000000..fed586691c --- /dev/null +++ b/firmware/target/mips/ingenic_x1000/debug-x1000.c | |||
@@ -0,0 +1,215 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 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 | #ifndef BOOTLOADER | ||
23 | #include "system.h" | ||
24 | #include "kernel.h" | ||
25 | #include "button.h" | ||
26 | #include "lcd.h" | ||
27 | #include "font.h" | ||
28 | #include "action.h" | ||
29 | #include "list.h" | ||
30 | |||
31 | #include "clk-x1000.h" | ||
32 | #include "gpio-x1000.h" | ||
33 | |||
34 | static bool dbg_clocks(void) | ||
35 | { | ||
36 | do { | ||
37 | lcd_clear_display(); | ||
38 | int line = 0; | ||
39 | for(int i = 0; i < X1000_CLK_COUNT; ++i) { | ||
40 | uint32_t hz = clk_get(i); | ||
41 | uint32_t khz = hz / 1000; | ||
42 | uint32_t mhz = khz / 1000; | ||
43 | lcd_putsf(2, line++, "%8s %4u,%03u,%03u Hz", clk_get_name(i), | ||
44 | mhz, (khz - mhz*1000), (hz - khz*1000)); | ||
45 | } | ||
46 | |||
47 | lcd_update(); | ||
48 | } while(get_action(CONTEXT_STD, HZ) != ACTION_STD_CANCEL); | ||
49 | |||
50 | return false; | ||
51 | } | ||
52 | |||
53 | static void dbg_gpios_show_state(void) | ||
54 | { | ||
55 | const char portname[] = "ABCD"; | ||
56 | for(int i = 0; i < 4; ++i) | ||
57 | lcd_putsf(0, i, "GPIO %c: %08x", portname[i], REG_GPIO_PIN(i)); | ||
58 | } | ||
59 | |||
60 | static void dbg_gpios_show_config(void) | ||
61 | { | ||
62 | const char portname[] = "ABCD"; | ||
63 | int line = 0; | ||
64 | for(int i = 0; i < 4; ++i) { | ||
65 | uint32_t intr = REG_GPIO_INT(i); | ||
66 | uint32_t mask = REG_GPIO_MSK(i); | ||
67 | uint32_t pat0 = REG_GPIO_PAT0(i); | ||
68 | uint32_t pat1 = REG_GPIO_PAT1(i); | ||
69 | lcd_putsf(0, line++, "GPIO %c", portname[i]); | ||
70 | lcd_putsf(2, line++, " int %08lx", intr); | ||
71 | lcd_putsf(2, line++, " msk %08lx", mask); | ||
72 | lcd_putsf(2, line++, "pat0 %08lx", pat0); | ||
73 | lcd_putsf(2, line++, "pat1 %08lx", pat1); | ||
74 | line++; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | static bool dbg_gpios(void) | ||
79 | { | ||
80 | enum { STATE, CONFIG, NUM_SCREENS }; | ||
81 | const int timeouts[NUM_SCREENS] = { 1, HZ }; | ||
82 | int screen = STATE; | ||
83 | |||
84 | while(1) { | ||
85 | lcd_clear_display(); | ||
86 | switch(screen) { | ||
87 | case CONFIG: | ||
88 | dbg_gpios_show_config(); | ||
89 | break; | ||
90 | case STATE: | ||
91 | dbg_gpios_show_state(); | ||
92 | break; | ||
93 | } | ||
94 | |||
95 | lcd_update(); | ||
96 | |||
97 | switch(get_action(CONTEXT_STD, timeouts[screen])) { | ||
98 | case ACTION_STD_CANCEL: | ||
99 | return false; | ||
100 | case ACTION_STD_PREV: | ||
101 | case ACTION_STD_PREVREPEAT: | ||
102 | screen -= 1; | ||
103 | if(screen < 0) | ||
104 | screen = NUM_SCREENS - 1; | ||
105 | break; | ||
106 | case ACTION_STD_NEXT: | ||
107 | case ACTION_STD_NEXTREPEAT: | ||
108 | screen += 1; | ||
109 | if(screen >= NUM_SCREENS) | ||
110 | screen = 0; | ||
111 | break; | ||
112 | default: | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | return false; | ||
118 | } | ||
119 | |||
120 | extern volatile unsigned aic_tx_underruns; | ||
121 | |||
122 | static bool dbg_audio(void) | ||
123 | { | ||
124 | do { | ||
125 | lcd_clear_display(); | ||
126 | lcd_putsf(0, 0, "TX underruns: %u", aic_tx_underruns); | ||
127 | lcd_update(); | ||
128 | } while(get_action(CONTEXT_STD, HZ) != ACTION_STD_CANCEL); | ||
129 | |||
130 | return false; | ||
131 | } | ||
132 | |||
133 | static bool dbg_cpuidle(void) | ||
134 | { | ||
135 | do { | ||
136 | lcd_clear_display(); | ||
137 | lcd_putsf(0, 0, "CPU idle time: %d.%01d%%", | ||
138 | __cpu_idle_cur/10, __cpu_idle_cur%10); | ||
139 | lcd_putsf(0, 1, "CPU frequency: %d.%03d MHz", | ||
140 | FREQ/1000000, (FREQ%1000000)/1000); | ||
141 | lcd_update(); | ||
142 | } while(get_action(CONTEXT_STD, HZ) != ACTION_STD_CANCEL); | ||
143 | |||
144 | return false; | ||
145 | } | ||
146 | |||
147 | #ifdef FIIO_M3K | ||
148 | extern bool dbg_fiiom3k_touchpad(void); | ||
149 | extern bool axp173_debug_menu(void); | ||
150 | #endif | ||
151 | |||
152 | /* Menu definition */ | ||
153 | static const struct { | ||
154 | const char* name; | ||
155 | bool(*function)(void); | ||
156 | } menuitems[] = { | ||
157 | {"Clocks", &dbg_clocks}, | ||
158 | {"GPIOs", &dbg_gpios}, | ||
159 | {"CPU idle", &dbg_cpuidle}, | ||
160 | {"Audio", &dbg_audio}, | ||
161 | #ifdef FIIO_M3K | ||
162 | {"Touchpad", &dbg_fiiom3k_touchpad}, | ||
163 | {"Power stats", &axp173_debug_menu}, | ||
164 | #endif | ||
165 | }; | ||
166 | |||
167 | static int hw_info_menu_action_cb(int btn, struct gui_synclist* lists) | ||
168 | { | ||
169 | if(btn == ACTION_STD_OK) { | ||
170 | int sel = gui_synclist_get_sel_pos(lists); | ||
171 | FOR_NB_SCREENS(i) | ||
172 | viewportmanager_theme_enable(i, false, NULL); | ||
173 | |||
174 | lcd_setfont(FONT_SYSFIXED); | ||
175 | lcd_set_foreground(LCD_WHITE); | ||
176 | lcd_set_background(LCD_BLACK); | ||
177 | |||
178 | if(menuitems[sel].function()) | ||
179 | btn = SYS_USB_CONNECTED; | ||
180 | else | ||
181 | btn = ACTION_REDRAW; | ||
182 | |||
183 | lcd_setfont(FONT_UI); | ||
184 | |||
185 | FOR_NB_SCREENS(i) | ||
186 | viewportmanager_theme_undo(i, false); | ||
187 | } | ||
188 | |||
189 | return btn; | ||
190 | } | ||
191 | |||
192 | static const char* hw_info_menu_get_name(int item, void* data, | ||
193 | char* buffer, size_t buffer_len) | ||
194 | { | ||
195 | (void)buffer; | ||
196 | (void)buffer_len; | ||
197 | (void)data; | ||
198 | return menuitems[item].name; | ||
199 | } | ||
200 | |||
201 | bool dbg_hw_info(void) | ||
202 | { | ||
203 | struct simplelist_info info; | ||
204 | simplelist_info_init(&info, MODEL_NAME " debug menu", | ||
205 | ARRAYLEN(menuitems), NULL); | ||
206 | info.action_callback = hw_info_menu_action_cb; | ||
207 | info.get_name = hw_info_menu_get_name; | ||
208 | return simplelist_show_list(&info); | ||
209 | } | ||
210 | |||
211 | bool dbg_ports(void) | ||
212 | { | ||
213 | return false; | ||
214 | } | ||
215 | #endif | ||