added tud_cdc_write_str, tu_fifo only use mutex for RTOS config

This commit is contained in:
hathach
2018-11-13 15:34:50 +07:00
parent 5a046799f6
commit 3fe7cd1659
19 changed files with 110 additions and 83 deletions

View File

@@ -32,12 +32,6 @@
target_reset_script="Reset();"
target_script_file="$(ProjectDir)/nRF_Target.js"
target_trace_initialize_script="EnableTrace("$(TraceInterfaceType)")" />
<folder Name="RTT Files">
<file file_name="SEGGER_RTT.c" />
<file file_name="SEGGER_RTT.h" />
<file file_name="SEGGER_RTT_Conf.h" />
<file file_name="SEGGER_RTT_SES.c" />
</folder>
<folder Name="Script Files">
<file file_name="nRF_Target.js">
<configuration Name="Common" file_type="Reset Script" />
@@ -61,6 +55,12 @@
<file file_name="../src/msc_app.h" />
<file file_name="../src/msc_flash_ram.c" />
<file file_name="../src/msc_flash_qspi.c" />
<folder Name="segger_rtt">
<file file_name="../src/segger_rtt/SEGGER_RTT.c" />
<file file_name="../src/segger_rtt/SEGGER_RTT_Conf.h" />
<file file_name="../src/segger_rtt/SEGGER_RTT.h" />
<file file_name="../src/segger_rtt/SEGGER_RTT_SES.c" />
</folder>
</folder>
<folder Name="hw">
<folder Name="bsp">

View File

@@ -55,56 +55,51 @@
//--------------------------------------------------------------------+
void print_greeting(void);
void led_blinking_task(void);
void virtual_com_task(void);
void usb_hid_task(void);
/*------------- MAIN -------------*/
int main(void)
{
board_init();
print_greeting();
tusb_init();
while (1)
{
tusb_task();
led_blinking_task();
virtual_com_task();
usb_hid_task();
}
return 0;
}
//--------------------------------------------------------------------+
// USB CDC
//--------------------------------------------------------------------+
#if CFG_TUD_CDC
void virtual_com_task(void)
{
#if CFG_TUD_CDC
// connected and there are data available
if ( tud_mounted() && tud_cdc_available() )
if ( tud_cdc_connected() )
{
uint8_t buf[64];
if ( tud_cdc_available() )
{
uint8_t buf[64];
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
tud_cdc_write(buf, count);
}
tud_cdc_write(buf, count);
tud_cdc_write_flush();
}
#endif
}
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
{
(void) itf;
// connected
if ( dtr && rts )
{
// print greeting
tud_cdc_write_str("tinyusb usb cdc\n");
}
}
#else
#define virtual_com_task()
#endif
//--------------------------------------------------------------------+
// USB HID
//--------------------------------------------------------------------+
#if CFG_TUD_HID
void usb_hid_task(void)
{
#if CFG_TUD_HID
// Poll every 10ms
static tu_timeout_t tm = { .start = 0, .interval = 10 };
@@ -144,10 +139,8 @@ void usb_hid_task(void)
if ( btn & 0x04 ) tud_hid_mouse_move( 0 , -DELTA); // up
if ( btn & 0x08 ) tud_hid_mouse_move( 0 , DELTA); // down
}
#endif
}
#if CFG_TUD_HID
uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
{
// TODO not Implemented
@@ -158,8 +151,32 @@ void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_t
{
// TODO not Implemented
}
#else
#define usb_hid_task()
#endif
/*------------- MAIN -------------*/
int main(void)
{
board_init();
print_greeting();
tusb_init();
while (1)
{
tusb_task();
led_blinking_task();
virtual_com_task();
usb_hid_task();
}
return 0;
}
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+

View File

@@ -32,12 +32,6 @@
target_reset_script="Reset();"
target_script_file="$(ProjectDir)/nRF_Target.js"
target_trace_initialize_script="EnableTrace(&quot;$(TraceInterfaceType)&quot;)" />
<folder Name="RTT Files">
<file file_name="SEGGER_RTT.c" />
<file file_name="SEGGER_RTT.h" />
<file file_name="SEGGER_RTT_Conf.h" />
<file file_name="SEGGER_RTT_SES.c" />
</folder>
<folder Name="Script Files">
<file file_name="nRF_Target.js">
<configuration Name="Common" file_type="Reset Script" />
@@ -60,6 +54,12 @@
<file file_name="../src/msc_flash_qspi.c" />
<file file_name="../src/msc_app.c" />
<file file_name="../src/msc_app.h" />
<folder Name="segger_rtt">
<file file_name="../src/segger_rtt/SEGGER_RTT.c" />
<file file_name="../src/segger_rtt/SEGGER_RTT_Conf.h" />
<file file_name="../src/segger_rtt/SEGGER_RTT.h" />
<file file_name="../src/segger_rtt/SEGGER_RTT_SES.c" />
</folder>
</folder>
<folder Name="hw">
<folder Name="bsp">

View File

@@ -101,18 +101,32 @@ void cdc_task(void* params)
while ( 1 )
{
// connected and there are data available
if ( tud_mounted() && tud_cdc_available() )
if ( tud_cdc_connected() )
{
uint8_t buf[64];
if ( tud_cdc_available() )
{
uint8_t buf[64];
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
tud_cdc_write(buf, count);
}
tud_cdc_write(buf, count);
tud_cdc_write_flush();
}
}
}
taskYIELD();
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
{
(void) itf;
// connected
if ( dtr && rts )
{
// print greeting
tud_cdc_write_str("tinyusb usb cdc\n");
}
}
#endif

View File

@@ -55,7 +55,7 @@
/*------------- RTOS -------------*/
#define CFG_TUSB_OS OPT_OS_FREERTOS
#define CFG_TUD_TASK_PRIO (configMAX_PRIORITIES-3)
#define CFG_TUD_TASK_PRIO (configMAX_PRIORITIES-1)
//#define CFG_TUD_TASK_QUEUE_SZ 16
//#define CFG_TUD_TASK_STACK_SZ 150