diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2022-05-21 14:58:55 +0100 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2022-05-21 14:58:55 +0100 |
commit | c116db6065d7b3c592cfca34fe30986f60fccc76 (patch) | |
tree | 59a55e554e8b847c3fa403c8589e7204f6f6bd48 | |
parent | 2f71571c0ad746ca68a7b7661bae5f799bfd7f35 (diff) | |
download | rockbox-c116db6065d7b3c592cfca34fe30986f60fccc76.tar.gz rockbox-c116db6065d7b3c592cfca34fe30986f60fccc76.zip |
plugins: add USB TSR test plugin
This is intended for testing USB event delivery to TSR plugins.
Usage:
1. enter plugin -> select Start
2. plug and unplug USB
3. reenter plugin -> select Status
it should display "State: disconnected" then "Prev: connected"
4. when done -> select Stop Plugin
Change-Id: I6c70f452db642f3fcbfbcb4f06c57f93e60f4cfd
-rw-r--r-- | apps/plugins/CATEGORIES | 1 | ||||
-rw-r--r-- | apps/plugins/SOURCES | 1 | ||||
-rw-r--r-- | apps/plugins/test_usb.c | 136 |
3 files changed, 138 insertions, 0 deletions
diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES index 332dd1bde4..f2ab4843c2 100644 --- a/apps/plugins/CATEGORIES +++ b/apps/plugins/CATEGORIES | |||
@@ -178,6 +178,7 @@ test_resize,apps | |||
178 | test_sampr,apps | 178 | test_sampr,apps |
179 | test_scanrate,apps | 179 | test_scanrate,apps |
180 | test_touchscreen,apps | 180 | test_touchscreen,apps |
181 | test_usb,apps | ||
181 | test_viewports,apps | 182 | test_viewports,apps |
182 | test_greylib_bitmap_scale,viewers | 183 | test_greylib_bitmap_scale,viewers |
183 | text_editor,apps | 184 | text_editor,apps |
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index c169b61cd1..942f9a5b20 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES | |||
@@ -226,5 +226,6 @@ test_sampr.c | |||
226 | #ifdef HAVE_TOUCHSCREEN | 226 | #ifdef HAVE_TOUCHSCREEN |
227 | test_touchscreen.c | 227 | test_touchscreen.c |
228 | #endif | 228 | #endif |
229 | test_usb.c | ||
229 | test_viewports.c | 230 | test_viewports.c |
230 | #endif /* HAVE_TEST_PLUGINS */ | 231 | #endif /* HAVE_TEST_PLUGINS */ |
diff --git a/apps/plugins/test_usb.c b/apps/plugins/test_usb.c new file mode 100644 index 0000000000..6bb77c40be --- /dev/null +++ b/apps/plugins/test_usb.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 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 "plugin.h" | ||
23 | #include "logf.h" | ||
24 | |||
25 | #undef DEBUGF | ||
26 | #define DEBUGF(...) | ||
27 | //#define DEBUGF printf | ||
28 | |||
29 | #define EV_EXIT MAKE_SYS_EVENT(SYS_EVENT_CLS_PRIVATE, 0xFF) | ||
30 | |||
31 | unsigned char stack[DEFAULT_STACK_SIZE]; | ||
32 | struct event_queue queue; | ||
33 | int thread_id; | ||
34 | const char* state = "none"; | ||
35 | const char* prev_state = "none"; | ||
36 | |||
37 | static void main_loop(void) | ||
38 | { | ||
39 | bool exiting = false; | ||
40 | struct queue_event ev; | ||
41 | |||
42 | while(true) { | ||
43 | rb->queue_wait(&queue, &ev); | ||
44 | |||
45 | /* events that are handled whether exiting or not */ | ||
46 | switch(ev.id) { | ||
47 | case EV_EXIT: | ||
48 | return; | ||
49 | } | ||
50 | |||
51 | if(exiting) | ||
52 | continue; | ||
53 | |||
54 | /* events handled only when not exiting */ | ||
55 | switch(ev.id) { | ||
56 | case SYS_USB_CONNECTED: | ||
57 | prev_state = state; | ||
58 | state = "connected"; | ||
59 | logf("test_usb: connect ack %ld", *rb->current_tick); | ||
60 | DEBUGF("test_usb: connect ack %ld\n", *rb->current_tick); | ||
61 | rb->usb_acknowledge(SYS_USB_CONNECTED_ACK); | ||
62 | break; | ||
63 | |||
64 | case SYS_USB_DISCONNECTED: | ||
65 | prev_state = state; | ||
66 | state = "disconnected"; | ||
67 | logf("test_usb: disconnect %ld", *rb->current_tick); | ||
68 | DEBUGF("test_usb: disconnect %ld\n", *rb->current_tick); | ||
69 | break; | ||
70 | |||
71 | case SYS_POWEROFF: | ||
72 | case SYS_REBOOT: | ||
73 | prev_state = state; | ||
74 | state = "exiting"; | ||
75 | exiting = true; | ||
76 | break; | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | static void kill_tsr(void) | ||
82 | { | ||
83 | rb->queue_post(&queue, EV_EXIT, 0); | ||
84 | rb->thread_wait(thread_id); | ||
85 | rb->queue_delete(&queue); | ||
86 | } | ||
87 | |||
88 | static bool exit_tsr(bool reenter) | ||
89 | { | ||
90 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, | ||
91 | "Status", "Stop plugin", "Back"); | ||
92 | |||
93 | while(true) { | ||
94 | int result = reenter ? rb->do_menu(&menu, NULL, NULL, false) : 1; | ||
95 | switch(result) { | ||
96 | case 0: | ||
97 | rb->splashf(HZ, "State: %s", state); | ||
98 | rb->splashf(HZ, "Prev: %s", prev_state); | ||
99 | break; | ||
100 | case 1: | ||
101 | rb->splashf(HZ, "Stopping USB test thread"); | ||
102 | kill_tsr(); | ||
103 | return true; | ||
104 | case 2: | ||
105 | return false; | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | |||
110 | static void run_tsr(void) | ||
111 | { | ||
112 | rb->queue_init(&queue, true); | ||
113 | thread_id = rb->create_thread(main_loop, stack, sizeof(stack), | ||
114 | 0, "test_usb TSR" | ||
115 | IF_PRIO(, PRIORITY_BACKGROUND) | ||
116 | IF_COP(, CPU)); | ||
117 | rb->plugin_tsr(exit_tsr); | ||
118 | } | ||
119 | |||
120 | enum plugin_status plugin_start(const void* parameter) | ||
121 | { | ||
122 | (void)parameter; | ||
123 | MENUITEM_STRINGLIST(menu, "USB test menu", NULL, | ||
124 | "Start", "Quit"); | ||
125 | |||
126 | switch(rb->do_menu(&menu, NULL, NULL, false)) { | ||
127 | case 0: | ||
128 | run_tsr(); | ||
129 | rb->splashf(HZ, "Thread started"); | ||
130 | return PLUGIN_OK; | ||
131 | case 1: | ||
132 | return PLUGIN_OK; | ||
133 | default: | ||
134 | return PLUGIN_ERROR; | ||
135 | } | ||
136 | } | ||