mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-20 18:40:57 +00:00
added cli support
This commit is contained in:
parent
bbfa85aa08
commit
bd9af2d57b
@ -125,6 +125,7 @@ void board_init(void);
|
||||
void board_leds(uint32_t on_mask, uint32_t off_mask);
|
||||
uint32_t board_uart_send(uint8_t *buffer, uint32_t length);
|
||||
uint32_t board_uart_recv(uint8_t *buffer, uint32_t length);
|
||||
uint8_t board_uart_getchar(void);
|
||||
|
||||
extern volatile uint32_t system_ticks;
|
||||
|
||||
|
@ -135,6 +135,11 @@ uint32_t board_uart_recv(uint8_t *buffer, uint32_t length)
|
||||
{
|
||||
return UART_Receive(BOARD_UART_PORT, buffer, length, BLOCKING);
|
||||
}
|
||||
|
||||
uint8_t board_uart_getchar(void)
|
||||
{
|
||||
return UART_ReceiveByte(BOARD_UART_PORT);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -66,8 +66,8 @@
|
||||
|
||||
#include "oem_base_board/pca9532.h" // LEDs
|
||||
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO
|
||||
//#define CFG_PRINTF_TARGET PRINTF_TARGET_UART // FIXME keil's cmsis rtx does not work with UART (work with SWO)
|
||||
//#define CFG_PRINTF_TARGET PRINTF_TARGET_SWO
|
||||
#define CFG_PRINTF_TARGET PRINTF_TARGET_UART // FIXME keil's cmsis rtx does not work with UART (work with SWO)
|
||||
|
||||
/*=========================================================================
|
||||
HARDWARE MAC ADDRESS
|
||||
|
@ -103,9 +103,11 @@ int __sys_readc (void)
|
||||
#elif defined __CC_ARM // keil
|
||||
|
||||
#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART
|
||||
#define retarget_putc(c) board_uart_send( (uint8_t*) &c, 1);
|
||||
#define retarget_putc(c) board_uart_send( (uint8_t*) &c, 1);
|
||||
#define retarget_getchar() board_uart_getchar()
|
||||
#elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO
|
||||
#define retarget_putc(c) ITM_SendChar(c)
|
||||
#define retarget_putc(c) ITM_SendChar(c)
|
||||
#define retarget_getchar() ITM_ReceiveChar()
|
||||
#else
|
||||
#error Thach, did you forget something
|
||||
#endif
|
||||
@ -116,6 +118,11 @@ struct __FILE {
|
||||
uint32_t handle;
|
||||
};
|
||||
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
return retarget_getchar();
|
||||
}
|
||||
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
if (//CFG_PRINTF_NEWLINE[0] == '\r' &&
|
||||
|
@ -446,8 +446,8 @@
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>101</TopLine>
|
||||
<CurrentLine>107</CurrentLine>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>1</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\main.c</PathWithFileName>
|
||||
<FilenameWithoutPath>main.c</FilenameWithoutPath>
|
||||
@ -479,7 +479,7 @@
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>169</TopLine>
|
||||
<CurrentLine>186</CurrentLine>
|
||||
<CurrentLine>180</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\keyboard_app.c</PathWithFileName>
|
||||
<FilenameWithoutPath>keyboard_app.c</FilenameWithoutPath>
|
||||
@ -492,10 +492,10 @@
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<ColumnNumber>44</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>123</TopLine>
|
||||
<CurrentLine>126</CurrentLine>
|
||||
<TopLine>120</TopLine>
|
||||
<CurrentLine>127</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\mouse_app.c</PathWithFileName>
|
||||
<FilenameWithoutPath>mouse_app.c</FilenameWithoutPath>
|
||||
@ -524,16 +524,32 @@
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<ColumnNumber>20</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>1</CurrentLine>
|
||||
<CurrentLine>6</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\msc_app.c</PathWithFileName>
|
||||
<FilenameWithoutPath>msc_app.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>1</GroupNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>2</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>62</TopLine>
|
||||
<CurrentLine>72</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\src\cli.c</PathWithFileName>
|
||||
<FilenameWithoutPath>cli.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
</Group>
|
||||
|
||||
<Group>
|
||||
@ -544,7 +560,7 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>7</FileNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -560,7 +576,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>8</FileNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -576,7 +592,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>9</FileNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -592,7 +608,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>10</FileNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -608,7 +624,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>11</FileNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -624,7 +640,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>12</FileNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -640,7 +656,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>13</FileNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -656,7 +672,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>14</FileNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -672,7 +688,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>15</FileNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -688,7 +704,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>2</GroupNumber>
|
||||
<FileNumber>16</FileNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -706,13 +722,13 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>tinyusb</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>17</FileNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -728,7 +744,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>18</FileNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -744,7 +760,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>19</FileNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -760,7 +776,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>20</FileNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -776,13 +792,13 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>21</FileNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>493</TopLine>
|
||||
<TopLine>494</TopLine>
|
||||
<CurrentLine>501</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\host\usbh.c</PathWithFileName>
|
||||
@ -792,13 +808,13 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>22</FileNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>593</TopLine>
|
||||
<TopLine>598</TopLine>
|
||||
<CurrentLine>605</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\host\ehci\ehci.c</PathWithFileName>
|
||||
@ -808,7 +824,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>23</FileNumber>
|
||||
<FileNumber>24</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -824,7 +840,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>24</FileNumber>
|
||||
<FileNumber>25</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -840,7 +856,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>25</FileNumber>
|
||||
<FileNumber>26</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -856,7 +872,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>26</FileNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -872,7 +888,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>27</FileNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -888,7 +904,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>28</FileNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -904,7 +920,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>29</FileNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -920,7 +936,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>30</FileNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -936,7 +952,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>31</FileNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -952,14 +968,14 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>3</GroupNumber>
|
||||
<FileNumber>32</FileNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>44</ColumnNumber>
|
||||
<ColumnNumber>47</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>1</TopLine>
|
||||
<CurrentLine>8</CurrentLine>
|
||||
<TopLine>2</TopLine>
|
||||
<CurrentLine>13</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\tinyusb\class\msc_host.c</PathWithFileName>
|
||||
<FilenameWithoutPath>msc_host.c</FilenameWithoutPath>
|
||||
@ -970,13 +986,13 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>cmsis</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>33</FileNumber>
|
||||
<FileNumber>34</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -992,7 +1008,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>34</FileNumber>
|
||||
<FileNumber>35</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1008,7 +1024,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>35</FileNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1024,7 +1040,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>36</FileNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1040,7 +1056,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>37</FileNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1056,7 +1072,7 @@
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>4</GroupNumber>
|
||||
<FileNumber>38</FileNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
@ -1080,14 +1096,14 @@
|
||||
<RteFlg>0</RteFlg>
|
||||
<File>
|
||||
<GroupNumber>5</GroupNumber>
|
||||
<FileNumber>39</FileNumber>
|
||||
<FileNumber>40</FileNumber>
|
||||
<FileType>2</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<Focus>0</Focus>
|
||||
<ColumnNumber>18</ColumnNumber>
|
||||
<ColumnNumber>0</ColumnNumber>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<TopLine>144</TopLine>
|
||||
<CurrentLine>150</CurrentLine>
|
||||
<CurrentLine>158</CurrentLine>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName>
|
||||
<FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath>
|
||||
|
@ -421,6 +421,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\msc_app.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>cli.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\cli.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@ -1025,6 +1030,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\msc_app.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>cli.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\src\cli.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
160
demos/host/src/cli.c
Normal file
160
demos/host/src/cli.c
Normal file
@ -0,0 +1,160 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file cli.c
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
#include "cli.h"
|
||||
#include "ctype.h"
|
||||
|
||||
#if TUSB_CFG_HOST_MSC
|
||||
|
||||
// command, function, description
|
||||
#define CLI_COMMAND_TABLE(ENTRY) \
|
||||
ENTRY(unknow , cli_cmd_unknow, NULL) \
|
||||
ENTRY(help , cli_cmd_help, NULL) \
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Expands the function to have the standard function signature
|
||||
//--------------------------------------------------------------------+
|
||||
#define CLI_PROTOTYPE_EXPAND(command, function, description) \
|
||||
tusb_error_t function(char const *);\
|
||||
|
||||
CLI_COMMAND_TABLE(CLI_PROTOTYPE_EXPAND);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Expand to enum value
|
||||
//--------------------------------------------------------------------+
|
||||
#define CLI_ENUM_EXPAND(command, function, description) CLI_CMDTYPE_##command,
|
||||
typedef enum {
|
||||
CLI_COMMAND_TABLE(CLI_ENUM_EXPAND)
|
||||
CLI_CMDTYPE_COUNT
|
||||
}cli_cmdtype_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Expand to string table
|
||||
//--------------------------------------------------------------------+
|
||||
#define CLI_STRING_EXPAND(command, function, description) #command,
|
||||
char const* const cli_string_tbl[] =
|
||||
{
|
||||
CLI_COMMAND_TABLE(CLI_STRING_EXPAND)
|
||||
0
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Expand to Description table
|
||||
//--------------------------------------------------------------------+
|
||||
#define CLI_DESCRIPTION_EXPAND(command, function, description) description,
|
||||
char const* const cli_description_tbl[] =
|
||||
{
|
||||
CLI_COMMAND_TABLE(CLI_DESCRIPTION_EXPAND)
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Expand to Command Lookup Table
|
||||
//--------------------------------------------------------------------+
|
||||
#define CMD_LOOKUP_EXPAND(command, function, description)\
|
||||
[CLI_CMDTYPE_##command] = function,\
|
||||
|
||||
typedef tusb_error_t (* const cli_cmdfunc_t)(char const *);
|
||||
static cli_cmdfunc_t cli_command_tbl[] =
|
||||
{
|
||||
CLI_COMMAND_TABLE(CMD_LOOKUP_EXPAND)
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// IMPLEMENTATION
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_error_t cli_cmd_unknow(char const * para)
|
||||
{
|
||||
puts("unknown command, please type \"help\"");
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
tusb_error_t cli_cmd_help(char const * para)
|
||||
{
|
||||
puts("current supported commands are:");
|
||||
puts("cd\tchange directory");
|
||||
puts("ls\tlist directory");
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
||||
#define CLI_MAX_BUFFER 50
|
||||
static char cli_buffer[CLI_MAX_BUFFER];
|
||||
|
||||
void cli_init(void)
|
||||
{
|
||||
memclr_(cli_buffer, CLI_MAX_BUFFER);
|
||||
}
|
||||
|
||||
void cli_poll(char ch)
|
||||
{
|
||||
if ( isprint(ch) )
|
||||
{
|
||||
if (strlen(cli_buffer) < CLI_MAX_BUFFER)
|
||||
{
|
||||
cli_buffer[ strlen(cli_buffer) ] = ch;
|
||||
putchar(ch);
|
||||
}else
|
||||
{
|
||||
puts("cli buffer overflows");
|
||||
memclr_(cli_buffer, CLI_MAX_BUFFER);
|
||||
}
|
||||
}
|
||||
else if ( ch == '\r')
|
||||
{
|
||||
putchar('\n');
|
||||
for(cli_cmdtype_t cmd_id = CLI_CMDTYPE_help; cmd_id < CLI_CMDTYPE_COUNT; cmd_id++)
|
||||
{
|
||||
if( 0 == strncmp(cli_buffer, cli_string_tbl[cmd_id], CLI_MAX_BUFFER) )
|
||||
{
|
||||
cli_command_tbl[cmd_id](NULL);
|
||||
memclr_(cli_buffer, CLI_MAX_BUFFER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cli_cmd_unknow(NULL);
|
||||
memclr_(cli_buffer, CLI_MAX_BUFFER);
|
||||
}
|
||||
else if (ch=='\t') // \t may be used for auto-complete later
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
62
demos/host/src/cli.h
Normal file
62
demos/host/src/cli.h
Normal file
@ -0,0 +1,62 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file cli.h
|
||||
@author hathach (tinyusb.org)
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2013, hathach (tinyusb.org)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
#ifndef _TUSB_CLI_H_
|
||||
#define _TUSB_CLI_H_
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PUBLIC API
|
||||
//--------------------------------------------------------------------+
|
||||
void cli_init(void);
|
||||
void cli_poll(char ch);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Callback API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _TUSB_CLI_H_
|
@ -50,6 +50,8 @@
|
||||
#include "app_os_prio.h"
|
||||
#endif
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
#include "mouse_app.h"
|
||||
#include "keyboard_app.h"
|
||||
#include "msc_app.h"
|
||||
@ -113,11 +115,11 @@ void os_none_start_scheduler(void)
|
||||
cdc_serial_app_task(NULL);
|
||||
rndis_app_task(NULL);
|
||||
|
||||
// int ch = ITM_ReceiveChar();
|
||||
// if ( ch > 0 )
|
||||
// {
|
||||
// printf("%c", ch);
|
||||
// }
|
||||
int ch = getchar();
|
||||
if ( ch > 0 )
|
||||
{
|
||||
cli_poll( (char) ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -130,6 +132,8 @@ int main(void)
|
||||
|
||||
tusb_init();
|
||||
|
||||
cli_init();
|
||||
|
||||
//------------- application task init -------------//
|
||||
(void) osal_task_create( OSAL_TASK_REF(led_blinking_task) );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user