|
32 | 32 | * 2022-07-02 Stanley Lwin add list command |
33 | 33 | * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable |
34 | 34 | * 2024-02-09 Bernard fix the version command |
| 35 | + * 2023-02-25 GuEe-GUI add console |
35 | 36 | */ |
36 | 37 |
|
37 | 38 | #include <rthw.h> |
@@ -60,6 +61,61 @@ static long version(void) |
60 | 61 | } |
61 | 62 | MSH_CMD_EXPORT(version, show RT-Thread version information); |
62 | 63 |
|
| 64 | +#if defined(RT_USING_DEVICE) && defined(RT_USING_CONSOLE) |
| 65 | +#if !defined(RT_USING_POSIX) && defined(RT_USING_POSIX_STDIO) |
| 66 | +#include <posix/stdio.h> |
| 67 | +#endif |
| 68 | + |
| 69 | +static int console(int argc, char **argv) |
| 70 | +{ |
| 71 | + if (argc > 1) |
| 72 | + { |
| 73 | + if (!rt_strcmp(argv[1], "set")) |
| 74 | + { |
| 75 | + if (argc < 3) |
| 76 | + { |
| 77 | + goto _help; |
| 78 | + } |
| 79 | + |
| 80 | + rt_kprintf("console change to %s\n", argv[2]); |
| 81 | + rt_console_set_device(argv[2]); |
| 82 | + |
| 83 | +#ifdef RT_USING_POSIX |
| 84 | + { |
| 85 | + rt_device_t dev = rt_device_find(argv[2]); |
| 86 | + |
| 87 | + if (dev != RT_NULL) |
| 88 | + { |
| 89 | + console_set_iodev(dev); |
| 90 | + } |
| 91 | + } |
| 92 | +#elif !defined(RT_USING_POSIX_STDIO) |
| 93 | + finsh_set_device(argv[2]); |
| 94 | +#else |
| 95 | + rt_posix_stdio_init(); |
| 96 | +#endif /* RT_USING_POSIX */ |
| 97 | + } |
| 98 | + else |
| 99 | + { |
| 100 | + goto _help; |
| 101 | + } |
| 102 | + } |
| 103 | + else |
| 104 | + { |
| 105 | + goto _help; |
| 106 | + } |
| 107 | + |
| 108 | + return RT_EOK; |
| 109 | + |
| 110 | +_help: |
| 111 | + rt_kprintf("Usage: \n"); |
| 112 | + rt_kprintf("console set <name> - change console by name\n"); |
| 113 | + |
| 114 | + return -RT_ERROR; |
| 115 | +} |
| 116 | +MSH_CMD_EXPORT(console, console setting); |
| 117 | +#endif /* RT_USING_DEVICE && RT_USING_CONSOLE */ |
| 118 | + |
63 | 119 | rt_inline void object_split(int len) |
64 | 120 | { |
65 | 121 | while (len--) rt_kprintf("-"); |
|
0 commit comments