mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-25 12:02:30 +00:00
clean up some examples
This commit is contained in:
parent
b221cedf80
commit
2882390c82
@ -63,13 +63,11 @@ static void echo_serial_port(uint8_t itf, uint8_t buf[], uint32_t count)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// echo back additional ports as upper case
|
// echo back 2nd port as upper case
|
||||||
if (islower(buf[i])) buf[i] -= 'a' - 'A';
|
if (islower(buf[i])) buf[i] -= 'a' - 'A';
|
||||||
}
|
}
|
||||||
|
|
||||||
tud_cdc_n_write_char(itf, buf[i]);
|
tud_cdc_n_write_char(itf, buf[i]);
|
||||||
|
|
||||||
if ( buf[i] == '\r' ) tud_cdc_n_write_char(itf, '\n');
|
|
||||||
}
|
}
|
||||||
tud_cdc_n_write_flush(itf);
|
tud_cdc_n_write_flush(itf);
|
||||||
}
|
}
|
||||||
@ -85,7 +83,7 @@ static void cdc_task(void)
|
|||||||
{
|
{
|
||||||
// connected() check for DTR bit
|
// connected() check for DTR bit
|
||||||
// Most but not all terminal client set this when making connection
|
// Most but not all terminal client set this when making connection
|
||||||
if ( tud_cdc_n_connected(itf) )
|
// if ( tud_cdc_n_connected(itf) )
|
||||||
{
|
{
|
||||||
if ( tud_cdc_n_available(itf) )
|
if ( tud_cdc_n_available(itf) )
|
||||||
{
|
{
|
||||||
|
@ -104,6 +104,8 @@
|
|||||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
|
||||||
|
// CDC Endpoint transfer buffer size, more is faster
|
||||||
|
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@ enum {
|
|||||||
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
|
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||||
|
|
||||||
void led_blinking_task(void);
|
void led_blinking_task(void);
|
||||||
|
|
||||||
void cdc_task(void);
|
void cdc_task(void);
|
||||||
|
|
||||||
/*------------- MAIN -------------*/
|
/*------------- MAIN -------------*/
|
||||||
@ -112,18 +111,16 @@ void cdc_task(void)
|
|||||||
// connected and there are data available
|
// connected and there are data available
|
||||||
if ( tud_cdc_available() )
|
if ( tud_cdc_available() )
|
||||||
{
|
{
|
||||||
uint8_t buf[64];
|
// read datas
|
||||||
|
char buf[64];
|
||||||
// read and echo back
|
|
||||||
uint32_t count = tud_cdc_read(buf, sizeof(buf));
|
uint32_t count = tud_cdc_read(buf, sizeof(buf));
|
||||||
|
(void) count;
|
||||||
|
|
||||||
for(uint32_t i=0; i<count; i++)
|
// Echo back
|
||||||
{
|
// Note: Skip echo by commenting out write() and write_flush()
|
||||||
tud_cdc_write_char(buf[i]);
|
// for throughput test e.g
|
||||||
|
// $ dd if=/dev/zero of=/dev/ttyACM0 count=10000
|
||||||
if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
|
tud_cdc_write(buf, count);
|
||||||
}
|
|
||||||
|
|
||||||
tud_cdc_write_flush();
|
tud_cdc_write_flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,12 +132,13 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
|||||||
(void) itf;
|
(void) itf;
|
||||||
(void) rts;
|
(void) rts;
|
||||||
|
|
||||||
// connected
|
// TODO set some indicator
|
||||||
if ( dtr )
|
if ( dtr )
|
||||||
{
|
{
|
||||||
// print initial message when connected
|
// Terminal connected
|
||||||
tud_cdc_write_str("\r\nTinyUSB CDC MSC device example\r\n");
|
}else
|
||||||
tud_cdc_write_flush();
|
{
|
||||||
|
// Terminal disconnected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +106,9 @@
|
|||||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
|
||||||
|
// CDC Endpoint transfer buffer size, more is faster
|
||||||
|
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
|
||||||
// MSC Buffer size of Device Mass storage
|
// MSC Buffer size of Device Mass storage
|
||||||
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
||||||
|
|
||||||
|
@ -179,14 +179,13 @@ void cdc_task(void* params)
|
|||||||
|
|
||||||
// read and echo back
|
// read and echo back
|
||||||
uint32_t count = tud_cdc_read(buf, sizeof(buf));
|
uint32_t count = tud_cdc_read(buf, sizeof(buf));
|
||||||
|
(void) count;
|
||||||
|
|
||||||
for(uint32_t i=0; i<count; i++)
|
// Echo back
|
||||||
{
|
// Note: Skip echo by commenting out write() and write_flush()
|
||||||
tud_cdc_write_char(buf[i]);
|
// for throughput test e.g
|
||||||
|
// $ dd if=/dev/zero of=/dev/ttyACM0 count=10000
|
||||||
if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
|
tud_cdc_write(buf, count);
|
||||||
}
|
|
||||||
|
|
||||||
tud_cdc_write_flush();
|
tud_cdc_write_flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,12 +201,13 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
|||||||
(void) itf;
|
(void) itf;
|
||||||
(void) rts;
|
(void) rts;
|
||||||
|
|
||||||
// connected
|
// TODO set some indicator
|
||||||
if ( dtr )
|
if ( dtr )
|
||||||
{
|
{
|
||||||
// print initial message when connected
|
// Terminal connected
|
||||||
tud_cdc_write_str("\r\nTinyUSB CDC MSC device with FreeRTOS example\r\n");
|
}else
|
||||||
tud_cdc_write_flush();
|
{
|
||||||
|
// Terminal disconnected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +106,9 @@
|
|||||||
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
|
||||||
|
// CDC Endpoint transfer buffer size, more is faster
|
||||||
|
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
|
||||||
|
|
||||||
// MSC Buffer size of Device Mass storage
|
// MSC Buffer size of Device Mass storage
|
||||||
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
#define CFG_TUD_MSC_EP_BUFSIZE 512
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user