Skip to content

Commit 438de41

Browse files
committed
修改 usb 后端例子
1 parent bdc695c commit 438de41

File tree

7 files changed

+205
-79
lines changed

7 files changed

+205
-79
lines changed

README.md

+41-25
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Agile Console 是基于 RT-Thread 的一个简单易用的调试设备中间件
88

99
- 后端实现极其方便,任何接口都可快速接入。
1010

11-
**注意** : 由于 Agile Console 会直接接管 `console` 设备,建议将 `RT-Thread` `Kernel` 中的 `RT_CONSOLE_DEVICE_NAME` 配置为一个不存在的设备。
11+
**注意** : 由于 Agile Console 会直接接管 `console` 设备,建议将 `RT-Thread` `Kernel` 中的 `RT_CONSOLE_DEVICE_NAME` 配置为一个不存在的设备。
1212

1313
Agile Console 目前支持的后端接口如下:
1414

@@ -83,45 +83,61 @@ Agile Console package 遵循 LGPLv2.1 许可,详见 `LICENSE` 文件。
8383
8484
RT-Thread 版本 >= 4.1.0 才有该选项。使能后会选中 [tinyusb](https://github.com/RT-Thread-packages/tinyusb) 软件包。
8585
86+
- Doxygen 文档生成
87+
88+
- 使用 `Doxywizard` 打开 [Doxyfile](./doc/doxygen/Doxyfile) 运行,生成的文件在 [doxygen/output](./doc/doxygen/output) 下。
89+
90+
- 需要更改 `Graphviz` 路径。
91+
92+
- `HTML` 生成未使用 `chm` 格式的,如果使能需要更改 `hhc.exe` 路径。
93+
94+
- 多后端演示
95+
96+
- 串口、Telnet 和 USB CDC 同时交互演示:
97+
98+
![whole](./figures/whole.gif)
99+
86100
## 3、新的后端接入 Agile Console
87101
88-
可以参考 [examples](./examples) 文件夹中的例子和 [agile_telnet](https://github.com/loogg/agile_telnet) 软件包。
102+
- 可以参考 [examples](./examples) 文件夹中的例子和 [agile_telnet](https://github.com/loogg/agile_telnet) 软件包
103+
104+
- USB CDC 后端例子中展示了如何屏蔽输入输出
89105
90-
Agile Console 提供了后端接口结构体定义:
106+
- Agile Console 提供了后端接口结构体定义:
91107
92-
```C
93-
/**
94-
* @brief Agile Console 后端接口结构体
95-
*/
96-
struct agile_console_backend {
97-
void (*output)(rt_device_t dev, const uint8_t *buf, int len); /**< 向后端输出数据接口 */
98-
int (*read)(rt_device_t dev, uint8_t *buf, int len); /**< 从后端读取数据接口 */
99-
int (*control)(rt_device_t dev, int cmd, void *arg); /**< 对后端进行设置接口 */
100-
rt_slist_t slist; /**< 单向链表节点 */
101-
};
102-
```
108+
```C
109+
/**
110+
* @brief Agile Console 后端接口结构体
111+
*/
112+
struct agile_console_backend {
113+
void (*output)(rt_device_t dev, const uint8_t *buf, int len); /**< 向后端输出数据接口 */
114+
int (*read)(rt_device_t dev, uint8_t *buf, int len); /**< 从后端读取数据接口 */
115+
int (*control)(rt_device_t dev, int cmd, void *arg); /**< 对后端进行设置接口 */
116+
rt_slist_t slist; /**< 单向链表节点 */
117+
};
118+
```
103119

104-
实现一个新的后端并接入 Agile Console 的步骤如下:
120+
- 实现一个新的后端并接入 Agile Console 的步骤如下:
105121

106-
1. 定义后端变量
122+
1. 定义后端变量
107123

108-
2. 实现后端的 `output``read``control` 接口
124+
2. 实现后端的 `output``read``control` 接口
109125

110-
- `output` 接口
126+
- `output` 接口
111127

112-
实现时 **不能调用** **任何可能导致线程挂起的 API**。建议将数据放入 `ringbuffer` 并创建线程异步发送。
128+
实现时 **不能调用任何可能导致线程挂起的 API** 。建议将数据放入 `ringbuffer` 并创建线程异步发送。
113129

114-
- `read` 接口
130+
- `read` 接口
115131

116-
除了保护资源而使用的互斥锁外,其他引起阻塞的 API 不建议调用。已有的数据存放到数据区后立马返回。
132+
除了保护资源而使用的互斥锁外,其他引起阻塞的 API 不建议调用。已有的数据存放到数据区后立马返回。
117133

118-
- `control` 接口
134+
- `control` 接口
119135

120-
该接口用作控制后端。除 `TCFLSH` 命令,其他命令均会调用该接口。可不实现。
136+
该接口用作控制后端。除 `TCFLSH` 命令,其他命令均会调用该接口。可不实现。
121137

122-
3. 调用 `agile_console_backend_register` 注册后端
138+
3. 调用 `agile_console_backend_register` 注册后端
123139

124-
4. 后端收到数据时调用 `agile_console_wakeup` 唤醒接收线程
140+
4. 后端收到数据时调用 `agile_console_wakeup` 唤醒接收线程
125141

126142
## 4、联系方式 & 感谢
127143

doc/doxygen/Agile_Console.chm

-53.8 KB
Binary file not shown.

doc/doxygen/Doxyfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ RECURSIVE = YES
960960
# Note that relative paths are relative to the directory from which doxygen is
961961
# run.
962962

963-
EXCLUDE =
963+
EXCLUDE = ../../examples
964964

965965
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
966966
# directories that are symbolic links (a Unix file system feature) are excluded

doc/doxygen/output/index.html

+94-36
Original file line numberDiff line numberDiff line change
@@ -51,66 +51,124 @@ <h1><a class="anchor" id="autotoc_md4"></a>
5151
<li>接管 <code>console</code> 设备,支持 <code>device</code> 接口和 <code>posix</code> 接口。</li>
5252
<li>后端实现极其方便,任何接口都可快速接入。</li>
5353
</ul>
54-
<p ><b>注意</b> :</p>
54+
<p ><b>注意</b> : 由于 Agile Console 会直接接管 <code>console</code> 设备,建议将 <code>RT-Thread</code> <code>Kernel</code> 中的 <code>RT_CONSOLE_DEVICE_NAME</code> 配置为一个不存在的设备。</p>
55+
<p >Agile Console 目前支持的后端接口如下:</p>
56+
<ul>
57+
<li>串口后端</li>
58+
<li><p class="startli">USB CDC 后端</p>
59+
<p class="startli">使用到 <a href="https://github.com/RT-Thread-packages/tinyusb">tinyusb</a></p>
60+
</li>
61+
<li><p class="startli">Telnet 后端</p>
62+
<p class="startli">使用到 <a href="https://github.com/loogg/agile_telnet">agile_telnet</a></p>
63+
</li>
64+
</ul>
5565
<h2><a class="anchor" id="autotoc_md5"></a>
56-
1.1 目录结构</h2>
66+
1.1目录结构</h2>
5767
<table class="markdownTable">
5868
<tr class="markdownTableHead">
5969
<th class="markdownTableHeadNone">名称 </th><th class="markdownTableHeadNone">说明 </th></tr>
6070
<tr class="markdownTableRowOdd">
61-
<td class="markdownTableBodyNone">example </td><td class="markdownTableBodyNone">示例 </td></tr>
71+
<td class="markdownTableBodyNone">doc </td><td class="markdownTableBodyNone">文档 </td></tr>
6272
<tr class="markdownTableRowEven">
63-
<td class="markdownTableBodyNone">figures </td><td class="markdownTableBodyNone">文档图片 </td></tr>
73+
<td class="markdownTableBodyNone">examples </td><td class="markdownTableBodyNone">示例 </td></tr>
6474
<tr class="markdownTableRowOdd">
65-
<td class="markdownTableBodyNone">inc </td><td class="markdownTableBodyNone">头文件目录 </td></tr>
75+
<td class="markdownTableBodyNone">figures </td><td class="markdownTableBodyNone">素材 </td></tr>
6676
<tr class="markdownTableRowEven">
67-
<td class="markdownTableBodyNone">src </td><td class="markdownTableBodyNone">源代码目录 </td></tr>
77+
<td class="markdownTableBodyNone">inc </td><td class="markdownTableBodyNone">头文件 </td></tr>
78+
<tr class="markdownTableRowOdd">
79+
<td class="markdownTableBodyNone">src </td><td class="markdownTableBodyNone">源代码 </td></tr>
6880
</table>
6981
<h2><a class="anchor" id="autotoc_md6"></a>
70-
1.2 许可证</h2>
71-
<p ><code><a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a></code> package 遵循 LGPLv2.1 许可,详见 <code>LICENSE</code> 文件。</p>
82+
1.2许可证</h2>
83+
<p >Agile Console package 遵循 LGPLv2.1 许可,详见 <code>LICENSE</code> 文件。</p>
7284
<h2><a class="anchor" id="autotoc_md7"></a>
73-
1.3 依赖</h2>
85+
1.3依赖</h2>
7486
<ul>
75-
<li>RT-Thread 3.0+</li>
87+
<li>RT-Thread 4.0.3</li>
88+
<li>RT-Thread 4.0.5 ~ master</li>
7689
</ul>
7790
<h1><a class="anchor" id="autotoc_md8"></a>
78-
2、如何打开 agile_console</h1>
79-
<p >使用 <code><a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a></code> package 需要在 RT-Thread 的包管理器中选择它,具体路径如下:</p>
91+
2、使用 Agile Console</h1>
92+
<ul>
93+
<li>帮助文档请查看 <a href="./doc/doxygen/Agile_Console.chm">doc/doxygen/Agile_Console.chm</a></li>
94+
<li><p class="startli">使用 Agile Console package 需要在 RT-Thread 的包管理器中选择它,具体路径如下:</p>
8095
<div class="fragment"><div class="line">RT-Thread online packages</div>
8196
<div class="line"> peripheral libraries and drivers ---&gt;</div>
82-
<div class="line"> [*] agile_console: A agile console pachage. ---&gt;</div>
83-
<div class="line"> (256) Set agile_console rx buffer size</div>
84-
<div class="line"> (acon) Set agile_console device name</div>
85-
<div class="line"> (19) Set agile_console thread priority</div>
86-
<div class="line"> (2048) Set agile_console thread stack size</div>
87-
<div class="line"> [*] Enable agile_console serial example</div>
97+
<div class="line"> [*] <a class="code hl_struct" href="structagile__console.html">agile_console</a>: Simple debugging device Middleware. ---&gt;</div>
98+
<div class="line"> (1024) Set <a class="code hl_struct" href="structagile__console.html">agile_console</a> rx buffer size</div>
99+
<div class="line"> (tty) Set <a class="code hl_struct" href="structagile__console.html">agile_console</a> device name</div>
100+
<div class="line"> (9) Set <a class="code hl_struct" href="structagile__console.html">agile_console</a> thread priority</div>
101+
<div class="line"> (2048) Set <a class="code hl_struct" href="structagile__console.html">agile_console</a> thread stack size</div>
102+
<div class="line"> [*] Enable <a class="code hl_struct" href="structagile__console.html">agile_console</a> serial example</div>
88103
<div class="line"> (uart1) Set serial device name</div>
104+
<div class="line"> [*] Enable telnet plugin</div>
105+
<div class="line"> [*] Enable tinyusb plugin (RT-Thread 版本 &gt;= 4.1.0)</div>
89106
<div class="line"> Version (latest) ---&gt;</div>
107+
<div class="ttc" id="astructagile__console_html"><div class="ttname"><a href="structagile__console.html">agile_console</a></div><div class="ttdoc">Agile Console 结构体</div><div class="ttdef"><b>Definition:</b> <a href="agile__console_8h_source.html#l00043">agile_console.h:43</a></div></div>
90108
</div><!-- fragment --><ul>
91-
<li>**Set <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> rx buffer size**:<code><a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a></code>接受环形缓冲区大小</li>
92-
<li>**Set <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> device name**:<code><a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a></code>设备名</li>
93-
<li>**Set <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> thread priority**:<code><a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a></code>线程优先级</li>
94-
<li>**Set <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> thread stack size**:<code><a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a></code>线程堆栈大小</li>
95-
<li>**Enable <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> serial example**:使能串行接口例程</li>
96-
<li>**Set serial device name**:串行接口设备名</li>
109+
<li><b>Set <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> rx buffer size</b> :Agile Console 接受环形缓冲区大小</li>
110+
<li><b>Set <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> device name</b> :Agile Console 设备名</li>
111+
<li><b>Set <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> thread priority</b> :Agile Console 线程优先级</li>
112+
<li><b>Set <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> thread stack size</b> :Agile Console 线程堆栈大小</li>
113+
<li><b>Enable <a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a> serial example</b> :使能串口例程</li>
114+
<li><b>Set serial device name</b> :串口设备名</li>
115+
<li><p class="startli"><b>Enable telnet plugin</b> :使能 telnet 后端插件</p>
116+
<p class="startli">使能后会选中 <a href="https://github.com/loogg/agile_telnet">agile_telnet</a> 软件包。</p>
117+
</li>
118+
<li><p class="startli"><b>Enable tinyusb plugin</b> :使能 tinyusb 后端插件</p>
119+
<p class="startli">RT-Thread 版本 &gt;= 4.1.0 才有该选项。使能后会选中 <a href="https://github.com/RT-Thread-packages/tinyusb">tinyusb</a> 软件包。</p>
120+
</li>
121+
</ul>
122+
</li>
123+
<li>Doxygen 文档生成<ul>
124+
<li>使用 <code>Doxywizard</code> 打开 <a href="./doc/doxygen/Doxyfile">Doxyfile</a> 运行,生成的文件在 <a href="./doc/doxygen/output">doxygen/output</a> 下。</li>
125+
<li>需要更改 <code>Graphviz</code> 路径。</li>
126+
<li><code>HTML</code> 生成未使用 <code>chm</code> 格式的,如果使能需要更改 <code>hhc.exe</code> 路径。</li>
127+
</ul>
128+
</li>
97129
</ul>
98-
<p >然后让 RT-Thread 的包管理器自动更新,或者使用 <code>pkgs --update</code> 命令更新包到 BSP 中。</p>
99130
<h1><a class="anchor" id="autotoc_md9"></a>
100-
3、使用 agile_console</h1>
101-
<p >在打开 <code><a class="el" href="structagile__console.html" title="Agile Console 结构体">agile_console</a></code> package 后,当进行 bsp 编译时,它会被加入到 bsp 工程中进行编译。</p>
102-
<p ><img src="./figures/agile_console_test.gif" alt="agile_console_test" class="inline"/></p>
103-
<p >如上面动图所示,我注册了串行接口和telnet两个通道,可以看到两个终端都能使用shell。</p>
104-
<h1><a class="anchor" id="autotoc_md10"></a>
105-
4、注意事项</h1>
131+
3、新的后端接入 Agile Console</h1>
106132
<ul>
107-
<li>agile_console使能后是会自动注册为调试设备,是在<code>INIT_BOARD_EXPORT</code>层注册设备并更改为调试设备的。</li>
108-
<li>配置<code>RT_CONSOLE_DEVICE_NAME</code>为一个不存在的设备名或在<code>rt_hw_board_init</code>中将<code>rt_console_set_device(RT_CONSOLE_DEVICE_NAME);</code>删除。</li>
133+
<li>可以参考 <a href="./examples">examples</a> 文件夹中的例子和 <a href="https://github.com/loogg/agile_telnet">agile_telnet</a> 软件包</li>
134+
<li>USB CDC 后端例子中展示了如何屏蔽输入输出</li>
135+
<li><p class="startli">Agile Console 提供了后端接口结构体定义:</p>
136+
<div class="fragment"><div class="line"> </div>
137+
<div class="line"><span class="keyword">struct </span><a class="code hl_struct" href="structagile__console__backend.html">agile_console_backend</a> {</div>
138+
<div class="line"> void (*<a class="code hl_variable" href="structagile__console__backend.html#a414aa128e511ad511e53b35f7b60e818">output</a>)(rt_device_t dev, <span class="keyword">const</span> uint8_t *buf, <span class="keywordtype">int</span> len); </div>
139+
<div class="line"> int (*<a class="code hl_variable" href="structagile__console__backend.html#a020729f4e30754f939ba556bca583a48">read</a>)(rt_device_t dev, uint8_t *buf, <span class="keywordtype">int</span> len); </div>
140+
<div class="line"> int (*<a class="code hl_variable" href="structagile__console__backend.html#ab2c886bf05885d6acc2912d62b301c27">control</a>)(rt_device_t dev, <span class="keywordtype">int</span> cmd, <span class="keywordtype">void</span> *arg); </div>
141+
<div class="line"> rt_slist_t <a class="code hl_variable" href="structagile__console__backend.html#a87d68b1de31ca26ce6864f645a66cde5">slist</a>; </div>
142+
<div class="line">};</div>
143+
<div class="ttc" id="astructagile__console__backend_html"><div class="ttname"><a href="structagile__console__backend.html">agile_console_backend</a></div><div class="ttdoc">Agile Console 后端接口结构体</div><div class="ttdef"><b>Definition:</b> <a href="agile__console_8h_source.html#l00033">agile_console.h:33</a></div></div>
144+
<div class="ttc" id="astructagile__console__backend_html_a020729f4e30754f939ba556bca583a48"><div class="ttname"><a href="structagile__console__backend.html#a020729f4e30754f939ba556bca583a48">agile_console_backend::read</a></div><div class="ttdeci">int(* read)(rt_device_t dev, uint8_t *buf, int len)</div><div class="ttdoc">从后端读取数据接口</div><div class="ttdef"><b>Definition:</b> <a href="agile__console_8h_source.html#l00035">agile_console.h:35</a></div></div>
145+
<div class="ttc" id="astructagile__console__backend_html_a414aa128e511ad511e53b35f7b60e818"><div class="ttname"><a href="structagile__console__backend.html#a414aa128e511ad511e53b35f7b60e818">agile_console_backend::output</a></div><div class="ttdeci">void(* output)(rt_device_t dev, const uint8_t *buf, int len)</div><div class="ttdoc">向后端输出数据接口</div><div class="ttdef"><b>Definition:</b> <a href="agile__console_8h_source.html#l00034">agile_console.h:34</a></div></div>
146+
<div class="ttc" id="astructagile__console__backend_html_a87d68b1de31ca26ce6864f645a66cde5"><div class="ttname"><a href="structagile__console__backend.html#a87d68b1de31ca26ce6864f645a66cde5">agile_console_backend::slist</a></div><div class="ttdeci">rt_slist_t slist</div><div class="ttdoc">单向链表节点</div><div class="ttdef"><b>Definition:</b> <a href="agile__console_8h_source.html#l00037">agile_console.h:37</a></div></div>
147+
<div class="ttc" id="astructagile__console__backend_html_ab2c886bf05885d6acc2912d62b301c27"><div class="ttname"><a href="structagile__console__backend.html#ab2c886bf05885d6acc2912d62b301c27">agile_console_backend::control</a></div><div class="ttdeci">int(* control)(rt_device_t dev, int cmd, void *arg)</div><div class="ttdoc">对后端进行设置接口</div><div class="ttdef"><b>Definition:</b> <a href="agile__console_8h_source.html#l00036">agile_console.h:36</a></div></div>
148+
</div><!-- fragment --></li>
149+
<li>实现一个新的后端并接入 Agile Console 的步骤如下:<ol type="1">
150+
<li>定义后端变量</li>
151+
<li>实现后端的 <code>output</code><code>read</code><code>control</code> 接口<ul>
152+
<li><p class="startli"><code>output</code> 接口</p>
153+
<p class="startli">实现时 <b>不能调用任何可能导致线程挂起的 API</b> 。建议将数据放入 <code>ringbuffer</code> 并创建线程异步发送。</p>
154+
</li>
155+
<li><p class="startli"><code>read</code> 接口</p>
156+
<p class="startli">除了保护资源而使用的互斥锁外,其他引起阻塞的 API 不建议调用。已有的数据存放到数据区后立马返回。</p>
157+
</li>
158+
<li><p class="startli"><code>control</code> 接口</p>
159+
<p class="startli">该接口用作控制后端。除 <code>TCFLSH</code> 命令,其他命令均会调用该接口。可不实现。</p>
160+
</li>
109161
</ul>
110-
<h1><a class="anchor" id="autotoc_md11"></a>
111-
5、联系方式 &amp; 感谢</h1>
162+
</li>
163+
<li>调用 <code>agile_console_backend_register</code> 注册后端</li>
164+
<li>后端收到数据时调用 <code>agile_console_wakeup</code> 唤醒接收线程</li>
165+
</ol>
166+
</li>
167+
</ul>
168+
<h1><a class="anchor" id="autotoc_md10"></a>
169+
4、联系方式 &amp; 感谢</h1>
112170
<ul>
113-
<li>维护:malongwei</li>
171+
<li>维护:马龙伟</li>
114172
<li>主页:<a href="https://github.com/loogg/agile_console">https://github.com/loogg/agile_console</a></li>
115173
<li>邮箱:<a href="#" onclick="location.href='mai'+'lto:'+'254'+'40'+'472'+'13'+'@qq'+'.c'+'om'; return false;">25440<span style="display: none;">.nosp@m.</span>4721<span style="display: none;">.nosp@m.</span>3@qq.<span style="display: none;">.nosp@m.</span>com</a> </li>
116174
</ul>

0 commit comments

Comments
 (0)