From acea45c094f574e4c3da13d3cbd2b4d65dd33566 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 7 Mar 2018 11:11:13 +0700 Subject: move old host example to obsolete --- examples/obsolete/host/src/app_os_prio.h | 82 ++++ examples/obsolete/host/src/cdc_serial_host_app.c | 169 ++++++++ examples/obsolete/host/src/cdc_serial_host_app.h | 74 ++++ examples/obsolete/host/src/keyboard_host_app.c | 176 ++++++++ examples/obsolete/host/src/keyboard_host_app.h | 80 ++++ examples/obsolete/host/src/main.c | 143 +++++++ examples/obsolete/host/src/mouse_host_app.c | 181 +++++++++ examples/obsolete/host/src/mouse_host_app.h | 83 ++++ examples/obsolete/host/src/msc_cli.c | 485 +++++++++++++++++++++++ examples/obsolete/host/src/msc_cli.h | 62 +++ examples/obsolete/host/src/msc_host_app.c | 182 +++++++++ examples/obsolete/host/src/msc_host_app.h | 75 ++++ examples/obsolete/host/src/rndis_host_app.c | 76 ++++ examples/obsolete/host/src/rndis_host_app.h | 75 ++++ examples/obsolete/host/src/tusb_config.h | 115 ++++++ 15 files changed, 2058 insertions(+) create mode 100644 examples/obsolete/host/src/app_os_prio.h create mode 100644 examples/obsolete/host/src/cdc_serial_host_app.c create mode 100644 examples/obsolete/host/src/cdc_serial_host_app.h create mode 100644 examples/obsolete/host/src/keyboard_host_app.c create mode 100644 examples/obsolete/host/src/keyboard_host_app.h create mode 100644 examples/obsolete/host/src/main.c create mode 100644 examples/obsolete/host/src/mouse_host_app.c create mode 100644 examples/obsolete/host/src/mouse_host_app.h create mode 100644 examples/obsolete/host/src/msc_cli.c create mode 100644 examples/obsolete/host/src/msc_cli.h create mode 100644 examples/obsolete/host/src/msc_host_app.c create mode 100644 examples/obsolete/host/src/msc_host_app.h create mode 100644 examples/obsolete/host/src/rndis_host_app.c create mode 100644 examples/obsolete/host/src/rndis_host_app.h create mode 100644 examples/obsolete/host/src/tusb_config.h (limited to 'examples/obsolete/host/src') diff --git a/examples/obsolete/host/src/app_os_prio.h b/examples/obsolete/host/src/app_os_prio.h new file mode 100644 index 000000000..99be2de0c --- /dev/null +++ b/examples/obsolete/host/src/app_os_prio.h @@ -0,0 +1,82 @@ +/**************************************************************************/ +/*! + @file app_os_prio.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_APP_OS_PRIO_H_ +#define _TUSB_APP_OS_PRIO_H_ + + +#ifdef __cplusplus + extern "C" { +#endif + +#include "tusb.h" + +#if TUSB_CFG_OS == TUSB_OS_NONE + #define LOWER_PRIO(x) 0 // does not matter +#elif TUSB_CFG_OS == TUSB_OS_FREERTOS + #define LOWER_PRIO(x) ((x)-1) // freeRTOS lower number --> lower priority +#elif TUSB_CFG_OS == TUSB_OS_CMSIS_RTX + #define LOWER_PRIO(x) ((x)-1) // CMSIS-RTOS lower number --> lower priority +#else + #error Priority is not configured for this RTOS +#endif + +enum { + STANDARD_APP_TASK_PRIO = LOWER_PRIO(TUSB_CFG_OS_TASK_PRIO), // Application Task is lower than usb system task + LED_BLINKING_APP_TASK_PRIO = LOWER_PRIO(STANDARD_APP_TASK_PRIO), // Blinking task is lower than normal task + + KEYBOARD_APP_TASK_PRIO = STANDARD_APP_TASK_PRIO, + MOUSE_APP_TASK_PRIO = STANDARD_APP_TASK_PRIO, + CDC_SERIAL_APP_TASK_PRIO = STANDARD_APP_TASK_PRIO, + MSC_APP_TASK_PRIO = STANDARD_APP_TASK_PRIO +}; + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_APP_OS_PRIO_H_ */ + +/** @} */ diff --git a/examples/obsolete/host/src/cdc_serial_host_app.c b/examples/obsolete/host/src/cdc_serial_host_app.c new file mode 100644 index 000000000..768e3a146 --- /dev/null +++ b/examples/obsolete/host/src/cdc_serial_host_app.c @@ -0,0 +1,169 @@ +/**************************************************************************/ +/*! + @file cdc_serial_host_app.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "cdc_serial_host_app.h" +#include "app_os_prio.h" + +#if TUSB_CFG_HOST_CDC + +#define QUEUE_SERIAL_DEPTH 100 + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ +static osal_semaphore_t sem_hdl; + +enum { SERIAL_BUFFER_SIZE = 64 }; +TUSB_CFG_ATTR_USBRAM static uint8_t serial_in_buffer[SERIAL_BUFFER_SIZE]; +TUSB_CFG_ATTR_USBRAM static uint8_t serial_out_buffer[SERIAL_BUFFER_SIZE]; + +static uint8_t received_bytes; // set by transfer complete callback + +//--------------------------------------------------------------------+ +// tinyusb callbacks +//--------------------------------------------------------------------+ +void tuh_cdc_mounted_cb(uint8_t dev_addr) +{ // application set-up + printf("\na CDC device (address %d) is mounted\n", dev_addr); + + memclr_(serial_in_buffer, sizeof(serial_in_buffer)); + memclr_(serial_out_buffer, sizeof(serial_out_buffer)); + received_bytes = 0; + + osal_semaphore_reset(sem_hdl); + tuh_cdc_receive(dev_addr, serial_in_buffer, SERIAL_BUFFER_SIZE, true); // schedule first transfer +} + +void tuh_cdc_unmounted_cb(uint8_t dev_addr) +{ // application tear-down + printf("\na CDC device (address %d) is unmounted \n", dev_addr); +} + +// invoked ISR context +void tuh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) +{ + (void) dev_addr; // compiler warnings + + switch ( pipe_id ) + { + case CDC_PIPE_DATA_IN: + switch(event) + { + case TUSB_EVENT_XFER_COMPLETE: + received_bytes = xferred_bytes; + osal_semaphore_post(sem_hdl); // notify main task + break; + + case TUSB_EVENT_XFER_ERROR: + received_bytes = 0; // ignore + tuh_cdc_receive(dev_addr, serial_in_buffer, SERIAL_BUFFER_SIZE, true); // waiting for next data + break; + + case TUSB_EVENT_XFER_STALLED: + default : + break; + } + break; + + case CDC_PIPE_DATA_OUT: + case CDC_PIPE_NOTIFICATION: + default: + break; + } +} + +//--------------------------------------------------------------------+ +// APPLICATION +//--------------------------------------------------------------------+ +void cdc_serial_host_app_init(void) +{ + sem_hdl = osal_semaphore_create(1, 0); + ASSERT_PTR( sem_hdl, VOID_RETURN); + + VERIFY( osal_task_create(cdc_serial_host_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO), ); +} + +//------------- main task -------------// +void cdc_serial_host_app_task( void* param ) +{ + (void) param; + + OSAL_TASK_BEGIN + + //------------- send characters got from uart terminal to the first CDC device -------------// + for(uint8_t dev_addr=1; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr++) + { + if ( tuh_cdc_serial_is_mounted(dev_addr) ) + { + int ch_tx = getchar(); + if ( ch_tx > 0 ) + { // USB is much faster than serial, here we assume usb is always complete. There could be some characters missing though + serial_out_buffer[0] = (uint8_t) ch_tx; + + if ( !tuh_cdc_is_busy(dev_addr, CDC_PIPE_DATA_OUT) ) + { + tuh_cdc_send(dev_addr, serial_out_buffer, 1, false); // no need for callback on serial out pipe + } + } + break; // demo app only communicate with the first CDC-capable device + } + } + + //------------- print out received characters -------------// + tusb_error_t error; + osal_semaphore_wait(sem_hdl, 100, &error); // waiting for incoming data + + if ( TUSB_ERROR_NONE == error) + { + for(uint8_t i=0; ikeycode[i] == keycode) return true; + } + + return false; +} + +static inline void process_kbd_report(hid_keyboard_report_t const *p_new_report) +{ + static hid_keyboard_report_t prev_report = { 0, 0, {0} }; // previous report to check key released + + //------------- example code ignore control (non-printable) key affects -------------// + for(uint8_t i=0; i<6; i++) + { + if ( p_new_report->keycode[i] ) + { + if ( find_key_in_report(&prev_report, p_new_report->keycode[i]) ) + { + // exist in previous report means the current key is holding + }else + { + // not existed in previous report means the current key is pressed + uint8_t ch = keycode_to_ascii(p_new_report->modifier, p_new_report->keycode[i]); + putchar(ch); + if ( ch == '\r' ) putchar('\n'); // added new line for enter key + } + } + // TODO example skips key released + } + + prev_report = *p_new_report; +} + +static inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode) +{ + // TODO max of keycode_ascii_tbl + return keycode > 128 ? 0 : + hid_keycode_to_ascii_tbl [modifier & (KEYBOARD_MODIFIER_LEFTSHIFT | KEYBOARD_MODIFIER_RIGHTSHIFT) ? 1 : 0] [keycode]; +} + +#endif diff --git a/examples/obsolete/host/src/keyboard_host_app.h b/examples/obsolete/host/src/keyboard_host_app.h new file mode 100644 index 000000000..2b99373a3 --- /dev/null +++ b/examples/obsolete/host/src/keyboard_host_app.h @@ -0,0 +1,80 @@ +/**************************************************************************/ +/*! + @file keyboard_host_app.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_KEYBOARD_HOST_APP_H_ +#define _TUSB_KEYBOARD_HOST_APP_H_ + +#include "board.h" +#include "tusb.h" + +#ifdef __cplusplus + extern "C" { +#endif + +#if TUSB_CFG_HOST_HID_KEYBOARD + +void keyboard_host_app_init(void); +void keyboard_host_app_task(void* param); + +#else + +#define keyboard_host_app_init() +#define keyboard_host_app_task(x) + +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_KEYBOARD_HOST_APP_H_ */ + +/** @} */ diff --git a/examples/obsolete/host/src/main.c b/examples/obsolete/host/src/main.c new file mode 100644 index 000000000..897e538b3 --- /dev/null +++ b/examples/obsolete/host/src/main.c @@ -0,0 +1,143 @@ +/**************************************************************************/ +/*! + @file main.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include +#include +#include + +#include "board.h" +#include "tusb.h" + +#include "mouse_host_app.h" +#include "keyboard_host_app.h" +#include "msc_host_app.h" +#include "cdc_serial_host_app.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +void print_greeting(void); + +//--------------------------------------------------------------------+ +// IMPLEMENTATION +//--------------------------------------------------------------------+ + +#if TUSB_CFG_OS == TUSB_OS_NONE +// like a real RTOS, this function is a main loop invoking each task in application and never return +void os_none_start_scheduler(void) +{ + while (1) + { + tusb_task_runner(); + led_blinking_task(NULL); + + keyboard_host_app_task(NULL); + mouse_host_app_task(NULL); + msc_host_app_task(NULL); + cdc_serial_host_app_task(NULL); + } +} +#endif + +int main(void) +{ +#if TUSB_CFG_OS == TUSB_OS_CMSIS_RTX + osKernelInitialize(); // CMSIS RTX requires kernel init before any other OS functions +#endif + + board_init(); + print_greeting(); + + tusb_init(); + + //------------- application task init -------------// + led_blinking_init(); + + keyboard_host_app_init(); + mouse_host_app_init(); + msc_host_app_init(); + cdc_serial_host_app_init(); + + //------------- start OS scheduler (never return) -------------// +#if TUSB_CFG_OS == TUSB_OS_FREERTOS + vTaskStartScheduler(); +#elif TUSB_CFG_OS == TUSB_OS_NONE + os_none_start_scheduler(); +#elif TUSB_CFG_OS == TUSB_OS_CMSIS_RTX + osKernelStart(); +#else + #error need to start RTOS schduler +#endif + + return 0; +} + +//--------------------------------------------------------------------+ +// HELPER FUNCTION +//--------------------------------------------------------------------+ +void print_greeting(void) +{ + char const * const rtos_name[] = + { + [TUSB_OS_NONE] = "None", + [TUSB_OS_FREERTOS] = "FreeRTOS", + }; + + puts("\n\ +--------------------------------------------------------------------\n\ +- Host Demo (a tinyusb example)\n\ +- if you find any bugs or get any questions, feel free to file an\n\ +- issue at https://github.com/hathach/tinyusb\n\ +--------------------------------------------------------------------\n" + ); + + puts("This HOST demo is configured to support:"); + printf(" - RTOS = %s\n", rtos_name[TUSB_CFG_OS]); + if (TUSB_CFG_HOST_HUB ) puts(" - Hub (1 level only)"); + if (TUSB_CFG_HOST_HID_MOUSE ) puts(" - HID Mouse"); + if (TUSB_CFG_HOST_HID_KEYBOARD ) puts(" - HID Keyboard"); + if (TUSB_CFG_HOST_MSC ) puts(" - Mass Storage"); + if (TUSB_CFG_HOST_CDC ) puts(" - Communication Device Class"); +} diff --git a/examples/obsolete/host/src/mouse_host_app.c b/examples/obsolete/host/src/mouse_host_app.c new file mode 100644 index 000000000..f392e0ace --- /dev/null +++ b/examples/obsolete/host/src/mouse_host_app.c @@ -0,0 +1,181 @@ +/**************************************************************************/ +/*! + @file mouse_host_app.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include "mouse_host_app.h" +#include "app_os_prio.h" + +#if TUSB_CFG_HOST_HID_MOUSE + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ +#define QUEUE_MOUSE_REPORT_DEPTH 4 + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +static osal_queue_t queue_mouse_hdl; +TUSB_CFG_ATTR_USBRAM static hid_mouse_report_t usb_mouse_report; + +static inline void process_mouse_report(hid_mouse_report_t const * p_report); + +//--------------------------------------------------------------------+ +// tinyusb callbacks +//--------------------------------------------------------------------+ +void tuh_hid_mouse_mounted_cb(uint8_t dev_addr) +{ + // application set-up + printf("\na Mouse device (address %d) is mounted\n", dev_addr); + + osal_queue_flush(queue_mouse_hdl); + (void) tuh_hid_mouse_get_report(dev_addr, (uint8_t*) &usb_mouse_report); // first report +} + +void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr) +{ + // application tear-down + printf("\na Mouse device (address %d) is unmounted\n", dev_addr); +} + +// invoked ISR context +void tuh_hid_mouse_isr(uint8_t dev_addr, tusb_event_t event) +{ + switch(event) + { + case TUSB_EVENT_XFER_COMPLETE: + osal_queue_send(queue_mouse_hdl, &usb_mouse_report); + (void) tuh_hid_mouse_get_report(dev_addr, (uint8_t*) &usb_mouse_report); + break; + + case TUSB_EVENT_XFER_ERROR: + (void) tuh_hid_mouse_get_report(dev_addr, (uint8_t*) &usb_mouse_report); // ignore & continue + break; + + default : + break; + } +} + +//--------------------------------------------------------------------+ +// APPLICATION CODE +// NOTICE: MOUSE REPORT IS NOT CORRECT UNTIL A DECENT HID PARSER IS +// IMPLEMENTED, MEANWHILE IT CAN MISS DISPLAY BUTTONS OR X,Y etc +//--------------------------------------------------------------------+ +void mouse_host_app_init(void) +{ + memclr_(&usb_mouse_report, sizeof(hid_mouse_report_t)); + + queue_mouse_hdl = osal_queue_create( QUEUE_MOUSE_REPORT_DEPTH, sizeof(hid_mouse_report_t) ); + ASSERT_PTR( queue_mouse_hdl, VOID_RETURN); + + VERIFY( osal_task_create(mouse_host_app_task, "mouse", 128, NULL, MOUSE_APP_TASK_PRIO), ); +} + +//------------- main task -------------// +void mouse_host_app_task(void* param) +{ + (void) param; + + OSAL_TASK_BEGIN + + tusb_error_t error; + hid_mouse_report_t mouse_report; + + osal_queue_receive(queue_mouse_hdl, &mouse_report, OSAL_TIMEOUT_WAIT_FOREVER, &error); + (void) error; // suppress compiler's warnings + + process_mouse_report(&mouse_report); + + OSAL_TASK_END +} + +//--------------------------------------------------------------------+ +// HELPER +//--------------------------------------------------------------------+ +void cursor_movement(int8_t x, int8_t y, int8_t wheel) +{ + //------------- X -------------// + if ( x < 0) + { + printf(ANSI_CURSOR_BACKWARD(%d), (-x)); // move left + }else if ( x > 0) + { + printf(ANSI_CURSOR_FORWARD(%d), x); // move right + }else { } + + //------------- Y -------------// + if ( y < 0) + { + printf(ANSI_CURSOR_UP(%d), (-y)); // move up + }else if ( y > 0) + { + printf(ANSI_CURSOR_DOWN(%d), y); // move down + }else { } + + //------------- wheel -------------// + if (wheel < 0) + { + printf(ANSI_SCROLL_UP(%d), (-wheel)); // scroll up + }else if (wheel > 0) + { + printf(ANSI_SCROLL_DOWN(%d), wheel); // scroll down + }else { } +} + +static inline void process_mouse_report(hid_mouse_report_t const * p_report) +{ + static hid_mouse_report_t prev_report = { 0, 0, 0, 0 }; + + //------------- button state -------------// + uint8_t button_changed_mask = p_report->buttons ^ prev_report.buttons; + if ( button_changed_mask & p_report->buttons) + { + printf(" %c%c%c ", + p_report->buttons & MOUSE_BUTTON_LEFT ? 'L' : '-', + p_report->buttons & MOUSE_BUTTON_MIDDLE ? 'M' : '-', + p_report->buttons & MOUSE_BUTTON_RIGHT ? 'R' : '-'); + } + + //------------- cursor movement -------------// + cursor_movement(p_report->x, p_report->y, p_report->wheel); +} + +#endif diff --git a/examples/obsolete/host/src/mouse_host_app.h b/examples/obsolete/host/src/mouse_host_app.h new file mode 100644 index 000000000..967444454 --- /dev/null +++ b/examples/obsolete/host/src/mouse_host_app.h @@ -0,0 +1,83 @@ +/**************************************************************************/ +/*! + @file mouse_host_app.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_MOUSE_HOST_APP_H_ +#define _TUSB_MOUSE_HOST_APP_H_ + +#include +#include + +#include "board.h" +#include "tusb.h" + +#ifdef __cplusplus + extern "C" { +#endif + +#if TUSB_CFG_HOST_HID_MOUSE + +void mouse_host_app_init(void); +void mouse_host_app_task(void* param); + +#else + +#define mouse_host_app_init() +#define mouse_host_app_task(x) + +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_MOUSE_HOST_APP_H_ */ + +/** @} */ diff --git a/examples/obsolete/host/src/msc_cli.c b/examples/obsolete/host/src/msc_cli.c new file mode 100644 index 000000000..e4cb2cb28 --- /dev/null +++ b/examples/obsolete/host/src/msc_cli.c @@ -0,0 +1,485 @@ +/**************************************************************************/ +/*! + @file msc_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 "msc_cli.h" +#include "ctype.h" + +#if TUSB_CFG_HOST_MSC + +#include "ff.h" +#include "diskio.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ +#define CLI_MAX_BUFFER 256 +#define CLI_FILE_READ_BUFFER (4*1024) + +enum { + ASCII_BACKSPACE = 8, +}; + +typedef enum +{ + CLI_ERROR_NONE = 0, + CLI_ERROR_INVALID_PARA, + CLI_ERROR_INVALID_PATH, + CLI_ERROR_FILE_EXISTED, + CLI_ERROR_FAILED +}cli_error_t; + +static char const * const cli_error_message[] = +{ + [CLI_ERROR_NONE ] = 0, + [CLI_ERROR_INVALID_PARA ] = "Invalid parameter(s)", + [CLI_ERROR_INVALID_PATH ] = "No such file or directory", + [CLI_ERROR_FILE_EXISTED ] = "file or directory already exists", + [CLI_ERROR_FAILED ] = "failed to execute" +}; + +//--------------------------------------------------------------------+ +// CLI Database definition +//--------------------------------------------------------------------+ + +// command, function, description +#define CLI_COMMAND_TABLE(ENTRY) \ + ENTRY(unknown , cli_cmd_unknown , NULL ) \ + ENTRY(help , cli_cmd_help , NULL ) \ + ENTRY(cls , cli_cmd_clear , "Clear the screen.\n cls\n" ) \ + ENTRY(ls , cli_cmd_list , "List information of the FILEs.\n ls\n" ) \ + ENTRY(cd , cli_cmd_changedir, "change the current directory.\n cd a_folder\n" ) \ + ENTRY(cat , cli_cmd_cat , "display contents of a file.\n cat a_file.txt\n" ) \ + ENTRY(cp , cli_cmd_copy , "Copies one or more files to another location.\n cp a_file.txt dir1/another_file.txt\n cp a_file.txt dir1\n" ) \ + ENTRY(mkdir , cli_cmd_mkdir , "Create a DIRECTORY, if it does not already exist.\n mkdir \n" ) \ + ENTRY(mv , cli_cmd_move , "Rename or move a DIRECTORY or a FILE.\n mv old_name.txt new_name.txt\n mv old_name.txt dir1/new_name.txt\n" ) \ + ENTRY(rm , cli_cmd_remove , "Remove (delete) an empty DIRECTORY or FILE.\n rm deleted_name.txt\n rm empty_dir\n" ) \ + +//--------------------------------------------------------------------+ +// Expands the function to have the standard function signature +//--------------------------------------------------------------------+ +#define CLI_PROTOTYPE_EXPAND(command, function, description) \ + cli_error_t function(char * p_para); + +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) +}; + +//--------------------------------------------------------------------+ +// Expand to Description table +//--------------------------------------------------------------------+ +#define CLI_DESCRIPTION_EXPAND(command, function, description) description, +char const* const cli_description_tbl[] = +{ + CLI_COMMAND_TABLE(CLI_DESCRIPTION_EXPAND) +}; + + +//--------------------------------------------------------------------+ +// Expand to Command Lookup Table +//--------------------------------------------------------------------+ +#define CMD_LOOKUP_EXPAND(command, function, description)\ + [CLI_CMDTYPE_##command] = function,\ + +typedef cli_error_t (* const cli_cmdfunc_t)(char *); +static cli_cmdfunc_t cli_command_tbl[] = +{ + CLI_COMMAND_TABLE(CMD_LOOKUP_EXPAND) +}; + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +TUSB_CFG_ATTR_USBRAM uint8_t fileread_buffer[CLI_FILE_READ_BUFFER]; +static char cli_buffer[CLI_MAX_BUFFER]; +static char volume_label[20]; + +static inline void drive_number2letter(char * p_path) ATTR_ALWAYS_INLINE; +static inline void drive_number2letter(char * p_path) +{ + if (p_path[1] == ':') + { + p_path[0] = 'E' + p_path[0] - '0' ; + } +} + +static inline void drive_letter2number(char * p_path) ATTR_ALWAYS_INLINE; +static inline void drive_letter2number(char * p_path) +{ + if (p_path[1] == ':') + { + p_path[0] = p_path[0] - 'E' + '0'; + } +} + + +//--------------------------------------------------------------------+ +// IMPLEMENTATION +//--------------------------------------------------------------------+ +// NOTES: prompt re-use cli_buffer --> should not be called when cli_buffer has contents +void cli_command_prompt(void) +{ + f_getcwd(cli_buffer, CLI_MAX_BUFFER); + drive_number2letter(cli_buffer); + printf("\n%s %s\n$ ", + (volume_label[0] !=0) ? volume_label : "No Label", + cli_buffer); + + memclr_(cli_buffer, CLI_MAX_BUFFER); +} + +void cli_init(void) +{ + memclr_(cli_buffer, CLI_MAX_BUFFER); + f_getlabel(NULL, volume_label, NULL); + cli_command_prompt(); +} + +void cli_poll(char ch) +{ + if ( isprint(ch) ) + { // accumulate & echo + 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 == ASCII_BACKSPACE && strlen(cli_buffer)) + { + printf(ANSI_CURSOR_BACKWARD(1) ANSI_ERASE_LINE(0) ); // move cursor back & clear to the end of line + cli_buffer[ strlen(cli_buffer)-1 ] = 0; + } + else if ( ch == '\r') + { // execute command + //------------- Separate Command & Parameter -------------// + putchar('\n'); + char* p_space = strchr(cli_buffer, ' '); + uint32_t command_len = (p_space == NULL) ? strlen(cli_buffer) : (uint32_t) (p_space - cli_buffer); + char* p_para = (p_space == NULL) ? (cli_buffer+command_len) : (p_space+1); // point to NULL-character or after space + + //------------- Find entered command in lookup table & execute it -------------// + uint8_t cmd_id; + for(cmd_id = CLI_CMDTYPE_COUNT - 1; cmd_id > CLI_CMDTYPE_unknown; cmd_id--) + { + if( 0 == strncmp(cli_buffer, cli_string_tbl[cmd_id], command_len) ) break; + } + + cli_error_t error = cli_command_tbl[cmd_id]( p_para ); // command execution, (unknown command if cannot find) + + if (CLI_ERROR_NONE != error) puts(cli_error_message[error]); // error message output if any + cli_command_prompt(); // print out current path + } + else if (ch=='\t') // \t may be used for auto-complete later + { + + } +} + +//--------------------------------------------------------------------+ +// UNKNOWN Command +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_unknown(char * p_para) +{ + (void) p_para; + puts("unknown command, please type \"help\" for list of supported commands"); + return CLI_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// HELP command +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_help(char * p_para) +{ + (void) p_para; + + puts("current supported commands are:"); + for(uint8_t cmd_id = CLI_CMDTYPE_help+1; cmd_id < CLI_CMDTYPE_COUNT; cmd_id++) + { + printf("%s\t%s\n", cli_string_tbl[cmd_id], cli_description_tbl[cmd_id]); + } + + return CLI_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// Clear Screen Command +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_clear(char* p_para) +{ + (void) p_para; + printf(ANSI_ERASE_SCREEN(2) ANSI_CURSOR_POSITION(1,1) ); + return CLI_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// LS Command +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_list(char * p_para) +{ + if ( strlen(p_para) == 0 ) // list current directory + { + DIR target_dir; + if ( FR_OK != f_opendir(&target_dir, ".") ) return CLI_ERROR_FAILED; + + TCHAR long_filename[_MAX_LFN]; + FILINFO dir_entry = + { + .lfname = long_filename, + .lfsize = _MAX_LFN + }; + while( (f_readdir(&target_dir, &dir_entry) == FR_OK) && dir_entry.fname[0] != 0) + { + if ( dir_entry.fname[0] != '.' ) // ignore . and .. entry + { + TCHAR const * const p_name = (dir_entry.lfname[0] != 0) ? dir_entry.lfname : dir_entry.fname; + if ( dir_entry.fattrib & AM_DIR ) // directory + { + printf("/%s", p_name); + }else + { + printf("%-40s%d KB", p_name, dir_entry.fsize / 1000); + } + putchar('\n'); + } + } + +// (void) f_closedir(&target_dir); + } + else + { + puts("ls only supports list current directory only, try to cd to that folder first"); + return CLI_ERROR_INVALID_PARA; + } + + return CLI_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// CD Command +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_changedir(char * p_para) +{ + if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA; + + drive_letter2number(p_para); + + if ( FR_OK != f_chdir(p_para) ) + { + return CLI_ERROR_INVALID_PATH; + } + + if ( p_para[1] == ':') + { // path has drive letter --> change drive, update volume label + f_chdrive(p_para[0] - '0'); + f_getlabel(NULL, volume_label, NULL); + } + + return CLI_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// CAT Command +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_cat(char *p_para) +{ + if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA; + + FIL file; + + switch( f_open(&file, p_para, FA_READ) ) + { + case FR_OK: + { + uint32_t bytes_read = 0; + + if ( (FR_OK == f_read(&file, fileread_buffer, CLI_FILE_READ_BUFFER, &bytes_read)) && (bytes_read > 0) ) + { + if ( file.fsize < 0x80000 ) // ~ 500KB + { + putchar('\n'); + do { + for(uint32_t i=0; i 0) ); + }else + { // not display file contents if first character is not printable (high chance of binary file) + printf("%s 's contents is too large\n", p_para); + } + } + f_close(&file); + } + break; + + case FR_INVALID_NAME: + return CLI_ERROR_INVALID_PATH; + + default : + return CLI_ERROR_FAILED; + } + + return CLI_ERROR_NONE; +} + +//--------------------------------------------------------------------+ +// Make Directory command +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_mkdir(char *p_para) +{ + if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA; + + return (f_mkdir(p_para) == FR_OK) ? CLI_ERROR_NONE : CLI_ERROR_FAILED; +} + +//--------------------------------------------------------------------+ +// COPY command +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_copy(char *p_para) +{ + char* p_space = strchr(p_para, ' '); + if ( p_space == NULL ) return CLI_ERROR_INVALID_PARA; + *p_space = 0; // replace space by NULL-character + + char* p_dest = p_space+1; + if ( strlen(p_dest) == 0 ) return CLI_ERROR_INVALID_PARA; + + drive_letter2number(p_para); + drive_letter2number(p_dest); + + //------------- Check Existence of source file -------------// + FIL src_file; + if ( FR_OK != f_open(&src_file , p_para, FA_READ) ) return CLI_ERROR_INVALID_PATH; + + //------------- Check if dest path is a folder or a non-existing file (overwritten is not allowed) -------------// + FILINFO dest_entry; + if ( (f_stat(p_dest, &dest_entry) == FR_OK) && (dest_entry.fattrib & AM_DIR) ) + { // the destination is an existed folder --> auto append dest filename to be the folder + strcat(p_dest, "/"); + strcat(p_dest, p_para); + } + + //------------- Open dest file and start the copy -------------// + cli_error_t error = CLI_ERROR_NONE; + FIL dest_file; + + switch ( f_open(&dest_file, p_dest, FA_WRITE | FA_CREATE_NEW) ) + { + case FR_EXIST: + error = CLI_ERROR_FILE_EXISTED; + break; + + case FR_OK: + while(1) // copying + { + uint32_t bytes_read = 0; + uint32_t bytes_write = 0; + FRESULT res; + + res = f_read(&src_file, fileread_buffer, CLI_FILE_READ_BUFFER, &bytes_read); /* Read a chunk of src file */ + if ( (res != FR_OK) || (bytes_read == 0) ) break; /* error or eof */ + + res = f_write(&dest_file, fileread_buffer, bytes_read, &bytes_write); /* Write it to the dst file */ + if ( (res != FR_OK) || (bytes_write < bytes_read) ) break; /* error or disk full */ + } + + f_close(&dest_file); + break; + + default: + error = CLI_ERROR_FAILED; + break; + } + + f_close(&src_file); + + return error; +} + +//--------------------------------------------------------------------+ +// MOVE/RENAME +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_move(char *p_para) +{ + char* p_space = strchr(p_para, ' '); + if ( p_space == NULL ) return CLI_ERROR_INVALID_PARA; + *p_space = 0; // replace space by NULL-character + + char* p_dest = p_space+1; + if ( strlen(p_dest) == 0 ) return CLI_ERROR_INVALID_PARA; + + return (f_rename(p_para, p_dest) == FR_OK ) ? CLI_ERROR_NONE : CLI_ERROR_FAILED; +} + +//--------------------------------------------------------------------+ +// REMOVE +//--------------------------------------------------------------------+ +cli_error_t cli_cmd_remove(char *p_para) +{ + if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA; + + switch( f_unlink(p_para) ) + { + case FR_OK: return CLI_ERROR_NONE; + + case FR_DENIED: + printf("cannot remove readonly file/foler or non-empty folder\n"); + break; + + default: break; + } + + return CLI_ERROR_FAILED; +} +#endif diff --git a/examples/obsolete/host/src/msc_cli.h b/examples/obsolete/host/src/msc_cli.h new file mode 100644 index 000000000..052ad05ee --- /dev/null +++ b/examples/obsolete/host/src/msc_cli.h @@ -0,0 +1,62 @@ +/**************************************************************************/ +/*! + @file msc_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_MSC_CLI_H_ +#define _TUSB_MSC_CLI_H_ + +#include "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_ diff --git a/examples/obsolete/host/src/msc_host_app.c b/examples/obsolete/host/src/msc_host_app.c new file mode 100644 index 000000000..6faac68c3 --- /dev/null +++ b/examples/obsolete/host/src/msc_host_app.c @@ -0,0 +1,182 @@ +/**************************************************************************/ +/*! + @file msc_host_app.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include "msc_host_app.h" +#include "app_os_prio.h" + +#if TUSB_CFG_HOST_MSC + +#include "msc_cli.h" +#include "ff.h" +#include "diskio.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +TUSB_CFG_ATTR_USBRAM static FATFS fatfs[TUSB_CFG_HOST_DEVICE_MAX]; + +//--------------------------------------------------------------------+ +// tinyusb callbacks +//--------------------------------------------------------------------+ +void tuh_msc_mounted_cb(uint8_t dev_addr) +{ + puts("\na MassStorage device is mounted"); + + //------------- Disk Information -------------// + // SCSI VendorID[8] & ProductID[16] from Inquiry Command + uint8_t const* p_vendor = tuh_msc_get_vendor_name(dev_addr); + uint8_t const* p_product = tuh_msc_get_product_name(dev_addr); + + for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]); + + putchar(' '); + for(uint8_t i=0; i<16; i++) putchar(p_product[i]); + putchar('\n'); + + uint32_t last_lba, block_size; + tuh_msc_get_capacity(dev_addr, &last_lba, &block_size); + printf("Disk Size: %d MB\n", (last_lba+1)/ ((1024*1024)/block_size) ); + printf("LBA 0-0x%X Block Size: %d\n", last_lba, block_size); + + //------------- file system (only 1 LUN support) -------------// + uint8_t phy_disk = dev_addr-1; + disk_initialize(phy_disk); + + if ( disk_is_ready(phy_disk) ) + { + if ( f_mount(phy_disk, &fatfs[phy_disk]) != FR_OK ) + { + puts("mount failed"); + return; + } + + puts("---------------------------------------------------------------------"); + puts("- MASSSTORAGE CLASS CLI IS A IMMATURE CODE. DISK-WRITING COMMANDS"); + puts("- SUCH AS cp(COPY), mkdir(MAKE DIRECTORY) ARE POTENTIAL TO DAMAGE"); + puts("- YOUR USB THUMBDRIVE. USING THOSE COMMANDS ARE AT YOUR OWN RISK."); + puts("- THE AUTHOR HAS NO RESPONSIBILITY WITH YOUR DEVICE NOR ITS DATA"); + puts("---------------------------------------------------------------------"); + + f_chdrive(phy_disk); // change to newly mounted drive + f_chdir("/"); // root as current dir + + cli_init(); + } +} + +void tuh_msc_unmounted_cb(uint8_t dev_addr) +{ + puts("\na MassStorage device is unmounted"); + + uint8_t phy_disk = dev_addr-1; + + f_mount(phy_disk, NULL); // unmount disk + disk_deinitialize(phy_disk); + + if ( phy_disk == f_get_current_drive() ) + { // active drive is unplugged --> change to other drive + for(uint8_t i=0; i 0 ) + { + cli_poll( (char) ch); + } + } + + OSAL_TASK_END +} + +#endif diff --git a/examples/obsolete/host/src/msc_host_app.h b/examples/obsolete/host/src/msc_host_app.h new file mode 100644 index 000000000..25ece8816 --- /dev/null +++ b/examples/obsolete/host/src/msc_host_app.h @@ -0,0 +1,75 @@ +/**************************************************************************/ +/*! + @file msc_host_app.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_MSC_HOST_APP_H_ +#define _TUSB_MSC_HOST_APP_H_ + +#include "board.h" +#include "tusb.h" + + +#ifdef __cplusplus + extern "C" { +#endif + +#if TUSB_CFG_HOST_MSC + +void msc_host_app_init(void); +void msc_host_app_task(void* param); + +#else + +#define msc_host_app_init() +#define msc_host_app_task(x) + +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_MSC_HOST_APP_H_ */ + +/** @} */ diff --git a/examples/obsolete/host/src/rndis_host_app.c b/examples/obsolete/host/src/rndis_host_app.c new file mode 100644 index 000000000..e6b37e4d3 --- /dev/null +++ b/examples/obsolete/host/src/rndis_host_app.c @@ -0,0 +1,76 @@ +/**************************************************************************/ +/*! + @file rndis_host_app.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#include "rndis_host_app.h" +#include "app_os_prio.h" + +#if TUSB_CFG_HOST_CDC && TUSB_CFG_HOST_CDC_RNDIS + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ +void tusbh_cdc_rndis_mounted_cb(uint8_t dev_addr) +{ // application set-up + uint8_t mac_address[6]; + + printf("\nan RNDIS device is mounted\n"); + tusbh_cdc_rndis_get_mac_addr(dev_addr, mac_address); + + printf("MAC Address "); + for(uint8_t i=0; i<6; i++) printf("%X ", mac_address[i]); + printf("\n"); +} + +void tusbh_cdc_rndis_unmounted_cb(uint8_t dev_addr) +{ + // application tear-down + printf("\nan RNDIS device is unmounted\n"); +} + +void rndis_host_app_init(void) +{ + +} + +void rndis_host_app_task(void* param) +{ + OSAL_TASK_BEGIN + OSAL_TASK_END +} + +#endif diff --git a/examples/obsolete/host/src/rndis_host_app.h b/examples/obsolete/host/src/rndis_host_app.h new file mode 100644 index 000000000..e4fcacf46 --- /dev/null +++ b/examples/obsolete/host/src/rndis_host_app.h @@ -0,0 +1,75 @@ +/**************************************************************************/ +/*! + @file rndis_host_app.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_RNDIS_HOST_APP_H_ +#define _TUSB_RNDIS_HOST_APP_H_ + +#include "board.h" +#include "tusb.h" + +#ifdef __cplusplus + extern "C" { +#endif + +#if TUSB_CFG_HOST_CDC && TUSB_CFG_HOST_CDC_RNDIS + +void rndis_host_app_init(void); +void rndis_host_app_task(void* param); + +#else + +#define rndis_host_app_init() +#define rndis_host_app_task(x) + +#endif + + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_RNDIS_HOST_APP_H_ */ + +/** @} */ diff --git a/examples/obsolete/host/src/tusb_config.h b/examples/obsolete/host/src/tusb_config.h new file mode 100644 index 000000000..04fd7e889 --- /dev/null +++ b/examples/obsolete/host/src/tusb_config.h @@ -0,0 +1,115 @@ +/**************************************************************************/ +/*! + @file tusb_config.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. + + This file is part of the tinyusb stack. +*/ +/**************************************************************************/ + +#ifndef _TUSB_TUSB_CONFIG_H_ +#define _TUSB_TUSB_CONFIG_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//--------------------------------------------------------------------+ +// CONTROLLER CONFIGURATION +//--------------------------------------------------------------------+ +//#define TUSB_CFG_MCU will be passed from IDE for easy board/mcu switching +#define TUSB_CFG_CONTROLLER_0_MODE (TUSB_MODE_HOST) + +//--------------------------------------------------------------------+ +// HOST CONFIGURATION +//--------------------------------------------------------------------+ + +//------------- CLASS -------------// +#define TUSB_CFG_HOST_HUB 1 +#define TUSB_CFG_HOST_HID_KEYBOARD 1 +#define TUSB_CFG_HOST_HID_MOUSE 1 +#define TUSB_CFG_HOST_HID_GENERIC 0 // (not yet supported) +#define TUSB_CFG_HOST_MSC 1 +#define TUSB_CFG_HOST_CDC 1 + +#define TUSB_CFG_HOST_DEVICE_MAX (TUSB_CFG_HOST_HUB ? 5 : 1) // normal hub has 4 ports + +//--------------------------------------------------------------------+ +// COMMON CONFIGURATION +//--------------------------------------------------------------------+ +#define TUSB_CFG_DEBUG 2 + +//#define TUSB_CFG_OS TUSB_OS_NONE // defined using eclipse build +//#define TUSB_CFG_OS_TASK_PRIO 0 // defined using eclipse build + +#define TUSB_CFG_TICKS_HZ 1000 + +//--------------------------------------------------------------------+ +// USB RAM PLACEMENT +//--------------------------------------------------------------------+ +#ifdef __CODE_RED // make use of code red's support for ram region macros + + #if TUSB_CFG_MCU == MCU_LPC175X_6X + #define TUSB_CFG_ATTR_USBRAM // LPC17xx USB DMA can access all address + #elif (TUSB_CFG_MCU == MCU_LPC43XX) + #define TUSB_CFG_ATTR_USBRAM ATTR_SECTION(.data.$RAM3) + #endif + +#elif defined __CC_ARM // Compiled with Keil armcc + + #if (TUSB_CFG_MCU == MCU_LPC175X_6X) + #define TUSB_CFG_ATTR_USBRAM // LPC17xx USB DMA can access all address + #elif (TUSB_CFG_MCU == MCU_LPC43XX) + #define TUSB_CFG_ATTR_USBRAM // Use keil tool configure to have AHB SRAM as default memory + #endif + +#elif defined __ICCARM__ // compiled with IAR + + #if (TUSB_CFG_MCU == MCU_LPC175X_6X) + // LP175x_6x can access all but CMSIS-RTX causes overflow in 32KB SRAM --> move to AHB ram + #define TUSB_CFG_ATTR_USBRAM _Pragma("location=\".sram\"") + #elif (TUSB_CFG_MCU == MCU_LPC43XX) + #define TUSB_CFG_ATTR_USBRAM _Pragma("location=\".ahb_sram1\"") + #endif + +#else + + #error compiler not specified + +#endif + + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_TUSB_CONFIG_H_ */ -- cgit v1.3.1 From d0312805ba245b71a2089d72c4b6c89a49b2933a Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 7 Mar 2018 22:59:57 +0700 Subject: rename tusb_task_runner() to tusb_task() --- examples/device/device_virtual_com/src/main.c | 15 +-------------- examples/obsolete/device/src/main.c | 2 +- examples/obsolete/host/src/main.c | 2 +- tinyusb/tusb.c | 2 +- tinyusb/tusb.h | 4 ++-- 5 files changed, 6 insertions(+), 19 deletions(-) (limited to 'examples/obsolete/host/src') diff --git a/examples/device/device_virtual_com/src/main.c b/examples/device/device_virtual_com/src/main.c index 6c55dfb7f..c576b2f4f 100644 --- a/examples/device/device_virtual_com/src/main.c +++ b/examples/device/device_virtual_com/src/main.c @@ -57,19 +57,6 @@ //--------------------------------------------------------------------+ void print_greeting(void); -#if TUSB_CFG_OS == TUSB_OS_NONE -// like a real RTOS, this function is a main loop invoking each task in application and never return -void os_none_start_scheduler(void) -{ - while (1) - { - tusb_task_runner(); - led_blinking_task(NULL); - cdc_serial_app_task(NULL); - } -} -#endif - int main(void) { board_init(); @@ -83,7 +70,7 @@ int main(void) while (1) { - tusb_task_runner(); + tusb_task(); led_blinking_task(NULL); cdc_serial_app_task(NULL); diff --git a/examples/obsolete/device/src/main.c b/examples/obsolete/device/src/main.c index 1e96077f3..42456ae62 100644 --- a/examples/obsolete/device/src/main.c +++ b/examples/obsolete/device/src/main.c @@ -66,7 +66,7 @@ void os_none_start_scheduler(void) { while (1) { - tusb_task_runner(); + tusb_task(); led_blinking_task(NULL); msc_app_task(NULL); diff --git a/examples/obsolete/host/src/main.c b/examples/obsolete/host/src/main.c index 897e538b3..bb0dcd2b3 100644 --- a/examples/obsolete/host/src/main.c +++ b/examples/obsolete/host/src/main.c @@ -70,7 +70,7 @@ void os_none_start_scheduler(void) { while (1) { - tusb_task_runner(); + tusb_task(); led_blinking_task(NULL); keyboard_host_app_task(NULL); diff --git a/tinyusb/tusb.c b/tinyusb/tusb.c index 0e54b4206..cf94c1b23 100644 --- a/tinyusb/tusb.c +++ b/tinyusb/tusb.c @@ -64,7 +64,7 @@ tusb_error_t tusb_init(void) } #if TUSB_CFG_OS == TUSB_OS_NONE -void tusb_task_runner(void) +void tusb_task(void) { #if MODE_HOST_SUPPORTED usbh_enumeration_task(NULL); diff --git a/tinyusb/tusb.h b/tinyusb/tusb.h index 9ff1f5e2a..7450dbfcb 100644 --- a/tinyusb/tusb.h +++ b/tinyusb/tusb.h @@ -117,13 +117,13 @@ tusb_error_t tusb_init(void); { your_application_code(); - tusb_task_runner(); // handle tinyusb event, task etc ... + tusb_task(); // handle tinyusb event, task etc ... } } @endcode * */ -void tusb_task_runner(void); +void tusb_task(void); #endif /** @} */ -- cgit v1.3.1 From 03a4f02b89ccd4bddbfa0b117771ca1905d9f4a6 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 28 Mar 2018 14:49:00 +0700 Subject: rename ASSERT to TU_ASSERT to avoid name conflict --- examples/obsolete/host/src/cdc_serial_host_app.c | 2 +- examples/obsolete/host/src/keyboard_host_app.c | 2 +- examples/obsolete/host/src/mouse_host_app.c | 2 +- tinyusb/class/cdc/cdc_host.c | 12 +++--- tinyusb/class/cdc/cdc_rndis_host.c | 4 +- tinyusb/class/custom_class_host.c | 6 +-- tinyusb/class/hid/hid_host.c | 4 +- tinyusb/class/msc/msc_device.c | 4 +- tinyusb/class/msc/msc_host.c | 2 +- tinyusb/common/assertion.h | 45 ++++++---------------- tinyusb/common/verify.h | 2 +- tinyusb/device/usbd.c | 10 ++--- tinyusb/host/ehci/ehci.c | 14 +++---- tinyusb/host/ohci/ohci.c | 8 ++-- tinyusb/host/usbh.c | 6 +-- .../nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c | 8 ++-- tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c | 4 +- tinyusb/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c | 2 +- 18 files changed, 57 insertions(+), 80 deletions(-) (limited to 'examples/obsolete/host/src') diff --git a/examples/obsolete/host/src/cdc_serial_host_app.c b/examples/obsolete/host/src/cdc_serial_host_app.c index 768e3a146..1ab3f409b 100644 --- a/examples/obsolete/host/src/cdc_serial_host_app.c +++ b/examples/obsolete/host/src/cdc_serial_host_app.c @@ -113,7 +113,7 @@ void tuh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id void cdc_serial_host_app_init(void) { sem_hdl = osal_semaphore_create(1, 0); - ASSERT_PTR( sem_hdl, VOID_RETURN); + TU_ASSERT( sem_hdl, VOID_RETURN); VERIFY( osal_task_create(cdc_serial_host_app_task, "cdc", 128, NULL, CDC_SERIAL_APP_TASK_PRIO), ); } diff --git a/examples/obsolete/host/src/keyboard_host_app.c b/examples/obsolete/host/src/keyboard_host_app.c index f0d2fcd73..b55c062ea 100644 --- a/examples/obsolete/host/src/keyboard_host_app.c +++ b/examples/obsolete/host/src/keyboard_host_app.c @@ -103,7 +103,7 @@ void keyboard_host_app_init(void) memclr_(&usb_keyboard_report, sizeof(hid_keyboard_report_t)); queue_kbd_hdl = osal_queue_create( QUEUE_KEYBOARD_REPORT_DEPTH, sizeof(hid_keyboard_report_t) ); - ASSERT_PTR( queue_kbd_hdl, VOID_RETURN ); + TU_ASSERT( queue_kbd_hdl, VOID_RETURN ); VERIFY( osal_task_create(keyboard_host_app_task, "kbd", 128, NULL, KEYBOARD_APP_TASK_PRIO), ); } diff --git a/examples/obsolete/host/src/mouse_host_app.c b/examples/obsolete/host/src/mouse_host_app.c index f392e0ace..6464b5e8e 100644 --- a/examples/obsolete/host/src/mouse_host_app.c +++ b/examples/obsolete/host/src/mouse_host_app.c @@ -104,7 +104,7 @@ void mouse_host_app_init(void) memclr_(&usb_mouse_report, sizeof(hid_mouse_report_t)); queue_mouse_hdl = osal_queue_create( QUEUE_MOUSE_REPORT_DEPTH, sizeof(hid_mouse_report_t) ); - ASSERT_PTR( queue_mouse_hdl, VOID_RETURN); + TU_ASSERT( queue_mouse_hdl, VOID_RETURN); VERIFY( osal_task_create(mouse_host_app_task, "mouse", 128, NULL, MOUSE_APP_TASK_PRIO), ); } diff --git a/tinyusb/class/cdc/cdc_host.c b/tinyusb/class/cdc/cdc_host.c index 9b2c8816a..25abda277 100644 --- a/tinyusb/class/cdc/cdc_host.c +++ b/tinyusb/class/cdc/cdc_host.c @@ -114,8 +114,8 @@ bool tuh_cdc_serial_is_mounted(uint8_t dev_addr) tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length, bool is_notify) { - ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); - ASSERT( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); + TU_ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); + TU_ASSERT( p_data != NULL && length, TUSB_ERROR_INVALID_PARA); pipe_handle_t pipe_out = cdch_data[dev_addr-1].pipe_out; if ( hcd_pipe_is_busy(pipe_out) ) return TUSB_ERROR_INTERFACE_IS_BUSY; @@ -125,8 +125,8 @@ tusb_error_t tuh_cdc_send(uint8_t dev_addr, void const * p_data, uint32_t length tusb_error_t tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is_notify) { - ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); - ASSERT( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); + TU_ASSERT( tusbh_cdc_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); + TU_ASSERT( p_buffer != NULL && length, TUSB_ERROR_INVALID_PARA); pipe_handle_t pipe_in = cdch_data[dev_addr-1].pipe_in; if ( hcd_pipe_is_busy(pipe_in) ) return TUSB_ERROR_INTERFACE_IS_BUSY; @@ -185,7 +185,7 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ (*p_length) += p_desc[DESCRIPTOR_OFFSET_LENGTH]; p_desc = descriptor_next(p_desc); - ASSERT(pipehandle_is_valid(p_cdc->pipe_notification), TUSB_ERROR_HCD_OPEN_PIPE_FAILED); + TU_ASSERT(pipehandle_is_valid(p_cdc->pipe_notification), TUSB_ERROR_HCD_OPEN_PIPE_FAILED); } //------------- Data Interface (if any) -------------// @@ -206,7 +206,7 @@ tusb_error_t cdch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ &p_cdc->pipe_in : &p_cdc->pipe_out; (*p_pipe_hdl) = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_CDC); - ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); + TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); (*p_length) += p_desc[DESCRIPTOR_OFFSET_LENGTH]; p_desc = descriptor_next( p_desc ); diff --git a/tinyusb/class/cdc/cdc_rndis_host.c b/tinyusb/class/cdc/cdc_rndis_host.c index 7157331dd..7026a3871 100644 --- a/tinyusb/class/cdc/cdc_rndis_host.c +++ b/tinyusb/class/cdc/cdc_rndis_host.c @@ -74,8 +74,8 @@ static tusb_error_t send_message_get_response_subtask( uint8_t dev_addr, cdch_da //--------------------------------------------------------------------+ tusb_error_t tusbh_cdc_rndis_get_mac_addr(uint8_t dev_addr, uint8_t mac_address[6]) { - ASSERT( tusbh_cdc_rndis_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); - ASSERT_PTR( mac_address, TUSB_ERROR_INVALID_PARA); + TU_ASSERT( tusbh_cdc_rndis_is_mounted(dev_addr), TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED); + VERIFY( mac_address, TUSB_ERROR_INVALID_PARA); memcpy(mac_address, rndish_data[dev_addr-1].mac_address, 6); diff --git a/tinyusb/class/custom_class_host.c b/tinyusb/class/custom_class_host.c index 2642a9ec8..318813f4b 100644 --- a/tinyusb/class/custom_class_host.c +++ b/tinyusb/class/custom_class_host.c @@ -64,7 +64,7 @@ static tusb_error_t cush_validate_paras(uint8_t dev_addr, uint16_t vendor_id, ui return TUSB_ERROR_DEVICE_NOT_READY; } - ASSERT( p_buffer != NULL && length != 0, TUSB_ERROR_INVALID_PARA); + TU_ASSERT( p_buffer != NULL && length != 0, TUSB_ERROR_INVALID_PARA); return TUSB_ERROR_NONE; } @@ -122,7 +122,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_ pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ? &custom_interface[dev_addr-1].pipe_in : &custom_interface[dev_addr-1].pipe_out; *p_pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC); - ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); + TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED ); p_desc = descriptor_next(p_desc); } @@ -154,7 +154,7 @@ void cush_close(uint8_t dev_addr) memclr_(p_interface, sizeof(custom_interface_info_t)); - ASSERT(err1 == TUSB_ERROR_NONE && err2 == TUSB_ERROR_NONE, (void) 0 ); + TU_ASSERT(err1 == TUSB_ERROR_NONE && err2 == TUSB_ERROR_NONE, (void) 0 ); } #endif diff --git a/tinyusb/class/hid/hid_host.c b/tinyusb/class/hid/hid_host.c index 0d57a5577..43acddcf2 100644 --- a/tinyusb/class/hid/hid_host.c +++ b/tinyusb/class/hid/hid_host.c @@ -60,7 +60,7 @@ static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, uint8_t interfa p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor p_hid->interface_number = interface_number; - ASSERT (pipehandle_is_valid(p_hid->pipe_hdl), TUSB_ERROR_HCD_FAILED); + TU_ASSERT (pipehandle_is_valid(p_hid->pipe_hdl), TUSB_ERROR_HCD_FAILED); return TUSB_ERROR_NONE; } @@ -77,7 +77,7 @@ tusb_error_t hidh_interface_get_report(uint8_t dev_addr, void * report, hidh_int //------------- parameters validation -------------// // TODO change to use is configured function ASSERT_INT (TUSB_DEVICE_STATE_CONFIGURED, tuh_device_get_state(dev_addr), TUSB_ERROR_DEVICE_NOT_READY); - ASSERT_PTR (report, TUSB_ERROR_INVALID_PARA); + VERIFY (report, TUSB_ERROR_INVALID_PARA); TU_ASSSERT (!hcd_pipe_is_busy(p_hid->pipe_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); ASSERT_STATUS( hcd_pipe_xfer(p_hid->pipe_hdl, report, p_hid->report_size, true) ) ; diff --git a/tinyusb/class/msc/msc_device.c b/tinyusb/class/msc/msc_device.c index b5a29ad91..6f0e6b69b 100644 --- a/tinyusb/class/msc/msc_device.c +++ b/tinyusb/class/msc/msc_device.c @@ -215,8 +215,8 @@ tusb_error_t mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, u else { // Data Phase (non READ10, WRITE10) - ASSERT( p_cbw->xfer_bytes >= p_msc->data_len, TUSB_ERROR_INVALID_PARA ); - ASSERT( sizeof(p_msc->scsi_data) >= p_msc->data_len, TUSB_ERROR_NOT_ENOUGH_MEMORY); // needs to increase size for scsi_data + TU_ASSERT( p_cbw->xfer_bytes >= p_msc->data_len, TUSB_ERROR_INVALID_PARA ); + TU_ASSERT( sizeof(p_msc->scsi_data) >= p_msc->data_len, TUSB_ERROR_NOT_ENOUGH_MEMORY); // needs to increase size for scsi_data uint8_t const ep_data = BIT_TEST_(p_cbw->dir, 7) ? p_msc->ep_in : p_msc->ep_out; diff --git a/tinyusb/class/msc/msc_host.c b/tinyusb/class/msc/msc_host.c index 37a243a20..65d51b5bf 100644 --- a/tinyusb/class/msc/msc_host.c +++ b/tinyusb/class/msc/msc_host.c @@ -91,7 +91,7 @@ uint8_t const* tuh_msc_get_product_name(uint8_t dev_addr) tusb_error_t tuh_msc_get_capacity(uint8_t dev_addr, uint32_t* p_last_lba, uint32_t* p_block_size) { if ( !msch_data[dev_addr-1].is_initialized ) return TUSB_ERROR_MSCH_DEVICE_NOT_MOUNTED; - ASSERT(p_last_lba != NULL && p_block_size != NULL, TUSB_ERROR_INVALID_PARA); + TU_ASSERT(p_last_lba != NULL && p_block_size != NULL, TUSB_ERROR_INVALID_PARA); (*p_last_lba) = msch_data[dev_addr-1].last_lba; (*p_block_size) = (uint32_t) msch_data[dev_addr-1].block_size; diff --git a/tinyusb/common/assertion.h b/tinyusb/common/assertion.h index a3218b5f1..31ae04d30 100644 --- a/tinyusb/common/assertion.h +++ b/tinyusb/common/assertion.h @@ -68,30 +68,18 @@ extern "C" //--------------------------------------------------------------------+ // Assert Helper //--------------------------------------------------------------------+ -#ifndef _TEST_ - #define _ASSERT_MESSAGE(format, ...) _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __func__ , __LINE__, __VA_ARGS__) -#else // TODO remove this - #define _ASSERT_MESSAGE(format, ...) _PRINTF("%d:note: Assert " format "\n", __LINE__, __VA_ARGS__) -#endif - -#ifndef _TEST_ASSERT_ - #define ASSERT_ERROR_HANDLER(x, para) return x -#else - #define ASSERT_ERROR_HANDLER(x, para) Throw(x) -#endif +#define _ASSERT_MESSAGE(format, ...) _PRINTF("Assert at %s: %s: %d: " format "\n", __BASE_FILE__, __func__ , __LINE__, __VA_ARGS__) -#define ASSERT_DEFINE_WITH_HANDLER(error_handler, handler_para, setup_statement, condition, error, format, ...) \ +#define ASSERT_DEFINE(setup_statement, condition, error, format, ...) \ do{\ setup_statement;\ if (!(condition)) {\ tusb_hal_dbg_breakpoint();\ _ASSERT_MESSAGE(format, __VA_ARGS__);\ - error_handler(error, handler_para);\ + return error; /* Throw X for Test */\ }\ }while(0) -#define ASSERT_DEFINE(...) ASSERT_DEFINE_WITH_HANDLER(ASSERT_ERROR_HANDLER, NULL, __VA_ARGS__) - //--------------------------------------------------------------------+ // tusb_error_t Status Assert TODO use ASSERT_DEFINE //--------------------------------------------------------------------+ @@ -106,33 +94,22 @@ extern "C" //--------------------------------------------------------------------+ // Logical Assert //--------------------------------------------------------------------+ -#define ASSERT(...) ASSERT_TRUE(__VA_ARGS__) -#define ASSERT_TRUE(condition , error) ASSERT_DEFINE( , (condition), error, "%s", "evaluated to false") #define ASSERT_FAILED(error) ASSERT_DEFINE( , false, error, "%s", "FAILED") -//--------------------------------------------------------------------+ -// Pointer Assert -//--------------------------------------------------------------------+ -#define ASSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__) -#define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL") -#define ASSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is not NULL") - //--------------------------------------------------------------------+ // Integral Assert //--------------------------------------------------------------------+ #define ASSERT_XXX_EQUAL(type_format, expected, actual, error) \ - ASSERT_DEFINE(\ - uint32_t exp = (expected); uint32_t act = (actual),\ - exp==act,\ - error,\ - "expected " type_format ", actual " type_format, exp, act) + ASSERT_DEFINE( uint32_t exp = (expected); uint32_t act = (actual),\ + exp==act,\ + error,\ + "expected " type_format ", actual " type_format, exp, act) #define ASSERT_XXX_WITHIN(type_format, lower, upper, actual, error) \ - ASSERT_DEFINE(\ - uint32_t low = (lower); uint32_t up = (upper); uint32_t act = (actual),\ - (low <= act) && (act <= up),\ - error,\ - "expected within " type_format " - " type_format ", actual " type_format, low, up, act) + ASSERT_DEFINE( uint32_t low = (lower); uint32_t up = (upper); uint32_t act = (actual),\ + (low <= act) && (act <= up),\ + error,\ + "expected within " type_format " - " type_format ", actual " type_format, low, up, act) //--------------------------------------------------------------------+ // Integer Assert diff --git a/tinyusb/common/verify.h b/tinyusb/common/verify.h index a5eeb5ae8..9fe52ad83 100644 --- a/tinyusb/common/verify.h +++ b/tinyusb/common/verify.h @@ -57,7 +57,7 @@ #if TUSB_CFG_DEBUG >= 1 // #define _VERIFY_MESS(format, ...) cprintf("[%08ld] %s: %d: verify failed\n", get_millis(), __func__, __LINE__) #define _VERIFY_MESS(_status) printf("%s: %d: verify failed, error = %s\n", __PRETTY_FUNCTION__, __LINE__, tusb_strerr[_status]); - #define _ASSERT_MESS() printf("%s: %d: assert failed\n", __PRETTY_FUNCTION__, __LINE__); + #define _ASSERT_MESS() printf("%s: %d: assert failed\n", __PRETTY_FUNCTION__, __LINE__); #else #define _VERIFY_MESS(_status) #define _ASSERT_MESS() diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c index 1d9b8e8b5..e745addd9 100644 --- a/tinyusb/device/usbd.c +++ b/tinyusb/device/usbd.c @@ -218,7 +218,7 @@ tusb_error_t usbd_init (void) osal_task_create(usbd_task, "usbd", TUC_DEVICE_STACKSIZE, NULL, TUSB_CFG_OS_TASK_PRIO); //------------- Descriptor Check -------------// - ASSERT(tusbd_descriptor_pointers.p_device != NULL && tusbd_descriptor_pointers.p_configuration != NULL, TUSB_ERROR_DESCRIPTOR_CORRUPTED); + TU_ASSERT(tusbd_descriptor_pointers.p_device != NULL && tusbd_descriptor_pointers.p_configuration != NULL, TUSB_ERROR_DESCRIPTOR_CORRUPTED); //------------- class init -------------// for (uint8_t class_code = TUSB_CLASS_AUDIO; class_code < USBD_CLASS_DRIVER_COUNT; class_code++) @@ -445,22 +445,22 @@ static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number) p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH]; // ignore Interface Association }else { - ASSERT( TUSB_DESC_INTERFACE == p_desc[DESCRIPTOR_OFFSET_TYPE], TUSB_ERROR_NOT_SUPPORTED_YET ); + TU_ASSERT( TUSB_DESC_INTERFACE == p_desc[DESCRIPTOR_OFFSET_TYPE], TUSB_ERROR_NOT_SUPPORTED_YET ); uint8_t class_index; tusb_desc_interface_t* p_desc_interface = (tusb_desc_interface_t*) p_desc; class_index = p_desc_interface->bInterfaceClass; - ASSERT( class_index != 0 && class_index < USBD_CLASS_DRIVER_COUNT && usbd_class_drivers[class_index].open != NULL, TUSB_ERROR_NOT_SUPPORTED_YET ); - ASSERT( 0 == usbd_devices[rhport].interface2class[p_desc_interface->bInterfaceNumber], TUSB_ERROR_FAILED); // duplicate interface number TODO alternate setting + TU_ASSERT( class_index != 0 && class_index < USBD_CLASS_DRIVER_COUNT && usbd_class_drivers[class_index].open != NULL, TUSB_ERROR_NOT_SUPPORTED_YET ); + TU_ASSERT( 0 == usbd_devices[rhport].interface2class[p_desc_interface->bInterfaceNumber], TUSB_ERROR_FAILED); // duplicate interface number TODO alternate setting usbd_devices[rhport].interface2class[p_desc_interface->bInterfaceNumber] = class_index; uint16_t length=0; ASSERT_STATUS( usbd_class_drivers[class_index].open( rhport, p_desc_interface, &length ) ); - ASSERT( length >= sizeof(tusb_desc_interface_t), TUSB_ERROR_FAILED ); + TU_ASSERT( length >= sizeof(tusb_desc_interface_t), TUSB_ERROR_FAILED ); p_desc += length; } } diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 6ace7c76a..80c2a85a2 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -361,14 +361,14 @@ pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_end { pipe_handle_t const null_handle = { .dev_addr = 0, .xfer_type = 0, .index = 0 }; - ASSERT(dev_addr > 0, null_handle); + TU_ASSERT(dev_addr > 0, null_handle); if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) return null_handle; // TODO not support ISO yet //------------- Prepare Queue Head -------------// ehci_qhd_t * const p_qhd = qhd_find_free(dev_addr); - ASSERT_PTR(p_qhd, null_handle); + TU_ASSERT(p_qhd, null_handle); qhd_init( p_qhd, dev_addr, p_endpoint_desc->wMaxPacketSize.size, p_endpoint_desc->bEndpointAddress, p_endpoint_desc->bmAttributes.xfer, p_endpoint_desc->bInterval ); @@ -403,7 +403,7 @@ tusb_error_t hcd_pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl); ehci_qtd_t *p_qtd = qtd_find_free(pipe_hdl.dev_addr); - ASSERT_PTR(p_qtd, TUSB_ERROR_EHCI_NOT_ENOUGH_QTD); + TU_ASSERT(p_qtd, TUSB_ERROR_EHCI_NOT_ENOUGH_QTD); qtd_init(p_qtd, (uint32_t) buffer, total_bytes); p_qtd->pid = p_qhd->pid_non_control; @@ -432,9 +432,9 @@ tusb_error_t hcd_pipe_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t t /// pipe_close should only be called as a part of unmount/safe-remove process tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) { - ASSERT(pipe_hdl.dev_addr > 0, TUSB_ERROR_INVALID_PARA); + TU_ASSERT(pipe_hdl.dev_addr > 0, TUSB_ERROR_INVALID_PARA); - ASSERT(pipe_hdl.xfer_type != TUSB_XFER_ISOCHRONOUS, TUSB_ERROR_INVALID_PARA); + TU_ASSERT(pipe_hdl.xfer_type != TUSB_XFER_ISOCHRONOUS, TUSB_ERROR_INVALID_PARA); ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle( pipe_hdl ); @@ -971,7 +971,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si } }else { - ASSERT( 0 != interval, VOID_RETURN); + TU_ASSERT( 0 != interval, VOID_RETURN); // Full/Low: 4.12.2.1 (EHCI) case 1 schedule start split at 1 us & complete split at 2,3,4 uframes p_qhd->interrupt_smask = 0x01; p_qhd->non_hs_interrupt_cmask = BIN8(11100); @@ -1056,7 +1056,7 @@ static tusb_error_t list_remove_qhd(ehci_link_t* p_head, ehci_link_t* p_remove) { ehci_link_t *p_prev = list_find_previous_item(p_head, p_remove); - ASSERT_PTR(p_prev, TUSB_ERROR_INVALID_PARA); + TU_ASSERT(p_prev, TUSB_ERROR_INVALID_PARA); p_prev->address = p_remove->address; // EHCI 4.8.2 link the removing queue head to async/period head (which always reachable by Host Controller) diff --git a/tinyusb/host/ohci/ohci.c b/tinyusb/host/ohci/ohci.c index f5cff4e87..268320646 100644 --- a/tinyusb/host/ohci/ohci.c +++ b/tinyusb/host/ohci/ohci.c @@ -388,7 +388,7 @@ static ohci_ed_t * ed_list_find_previous(ohci_ed_t const * p_head, ohci_ed_t con ohci_ed_t const * p_prev = p_head; - ASSERT_PTR(p_prev, NULL); + TU_ASSERT(p_prev, NULL); while ( align16(p_prev->next_ed) != 0 && /* not reach null */ align16(p_prev->next_ed) != (uint32_t) p_ed && /* not found yet */ @@ -422,11 +422,11 @@ pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_end pipe_handle_t const null_handle = { .dev_addr = 0, .xfer_type = 0, .index = 0 }; // TODO iso support - ASSERT(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS, null_handle ); + TU_ASSERT(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS, null_handle ); //------------- Prepare Queue Head -------------// ohci_ed_t * const p_ed = ed_find_free(dev_addr); - ASSERT_PTR(p_ed, null_handle); + TU_ASSERT(p_ed, null_handle); ed_init( p_ed, dev_addr, p_endpoint_desc->wMaxPacketSize.size, p_endpoint_desc->bEndpointAddress, p_endpoint_desc->bmAttributes.xfer, p_endpoint_desc->bInterval ); @@ -475,7 +475,7 @@ static tusb_error_t pipe_queue_xfer(pipe_handle_t pipe_hdl, uint8_t buffer[], u if ( !p_ed->is_iso ) { ohci_gtd_t * const p_gtd = gtd_find_free(pipe_hdl.dev_addr); - ASSERT_PTR(p_gtd, TUSB_ERROR_EHCI_NOT_ENOUGH_QTD); // TODO refractor error code + TU_ASSERT(p_gtd, TUSB_ERROR_EHCI_NOT_ENOUGH_QTD); // TODO refractor error code gtd_init(p_gtd, buffer, total_bytes); p_gtd->index = pipe_hdl.index; diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index c6e9256f9..38f4bb346 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -148,7 +148,7 @@ tusb_error_t usbh_init(void) //------------- Enumeration & Reporter Task init -------------// enum_queue_hdl = osal_queue_create( ENUM_QUEUE_DEPTH, sizeof(uint32_t) ); - ASSERT_PTR(enum_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED); + TU_ASSERT(enum_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED); osal_task_create(usbh_enumeration_task, "usbh", 200, NULL, TUSB_CFG_OS_TASK_PRIO); @@ -158,10 +158,10 @@ tusb_error_t usbh_init(void) usbh_device_info_t * const p_device = &usbh_devices[i]; p_device->control.sem_hdl = osal_semaphore_create(1, 0); - ASSERT_PTR(p_device->control.sem_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); + TU_ASSERT(p_device->control.sem_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); p_device->control.mutex_hdl = osal_mutex_create(); - ASSERT_PTR(p_device->control.mutex_hdl, TUSB_ERROR_OSAL_MUTEX_FAILED); + TU_ASSERT(p_device->control.mutex_hdl, TUSB_ERROR_OSAL_MUTEX_FAILED); } //------------- class init -------------// diff --git a/tinyusb/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c b/tinyusb/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c index 158058d61..140438ce0 100644 --- a/tinyusb/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c +++ b/tinyusb/portable/nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c @@ -153,7 +153,7 @@ STATIC_VAR dcd_11u_13u_data_t dcd_data; static inline uint16_t addr_offset(void const * p_buffer) ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint16_t addr_offset(void const * p_buffer) { - ASSERT( (((uint32_t) p_buffer) & 0x3f) == 0, 0 ); + TU_ASSERT( (((uint32_t) p_buffer) & 0x3f) == 0, 0 ); return (uint16_t) ( (((uint32_t) p_buffer) >> 6 ) & 0xFFFF) ; } @@ -465,14 +465,14 @@ edpt_hdl_t dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) return null_handle; // TODO not support ISO yet - ASSERT (p_endpoint_desc->wMaxPacketSize.size <= 64, null_handle); // TODO ISO can be 1023, but ISO not supported now + TU_ASSERT (p_endpoint_desc->wMaxPacketSize.size <= 64, null_handle); // TODO ISO can be 1023, but ISO not supported now // TODO prevent to open if endpoint size is not 64 //------------- Prepare Queue Head -------------// uint8_t ep_id = edpt_addr2phy(p_endpoint_desc->bEndpointAddress); - ASSERT( dcd_data.qhd[ep_id][0].disable && dcd_data.qhd[ep_id][1].disable, null_handle ); // endpoint must not previously opened, normally this means running out of endpoints + TU_ASSERT( dcd_data.qhd[ep_id][0].disable && dcd_data.qhd[ep_id][1].disable, null_handle ); // endpoint must not previously opened, normally this means running out of endpoints memclr_(dcd_data.qhd[ep_id], 2*sizeof(dcd_11u_13u_qhd_t)); dcd_data.qhd[ep_id][0].is_isochronous = dcd_data.qhd[ep_id][1].is_isochronous = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS); @@ -539,7 +539,7 @@ static void queue_xfer_in_next_td(uint8_t ep_id) tusb_error_t dcd_edpt_queue_xfer(edpt_hdl_t edpt_hdl, uint8_t * buffer, uint16_t total_bytes) { - ASSERT( !dcd_edpt_busy(edpt_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); // endpoint must not in transferring + TU_ASSERT( !dcd_edpt_busy(edpt_hdl), TUSB_ERROR_INTERFACE_IS_BUSY); // endpoint must not in transferring dcd_data.current_ioc = BIT_CLR_(dcd_data.current_ioc, edpt_hdl.index); diff --git a/tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c b/tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c index c93976a30..7285d1461 100644 --- a/tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c +++ b/tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c @@ -275,7 +275,7 @@ void hal_dcd_isr(uint8_t rhport) { uint32_t error_status = sie_read(SIE_CMDCODE_READ_ERROR_STATUS, 1); (void) error_status; -// ASSERT(false, (void) 0); +// TU_ASSERT(false, (void) 0); } } @@ -422,7 +422,7 @@ edpt_hdl_t dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint // TODO refractor to universal pipe open validation function if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) return null_handle; // TODO not support ISO yet - ASSERT (p_endpoint_desc->wMaxPacketSize.size <= 64, null_handle); // TODO ISO can be 1023, but ISO not supported now + TU_ASSERT (p_endpoint_desc->wMaxPacketSize.size <= 64, null_handle); // TODO ISO can be 1023, but ISO not supported now uint8_t ep_id = edpt_addr2phy( p_endpoint_desc->bEndpointAddress ); diff --git a/tinyusb/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c b/tinyusb/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c index 21afed7a4..57290b49f 100644 --- a/tinyusb/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c +++ b/tinyusb/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c @@ -495,7 +495,7 @@ void hal_dcd_isr(uint8_t rhport) } if (int_status & INT_MASK_NAK) {} - if (int_status & INT_MASK_ERROR) ASSERT(false, VOID_RETURN); + if (int_status & INT_MASK_ERROR) TU_ASSERT(false, ); } //--------------------------------------------------------------------+ -- cgit v1.3.1 From e2f97443694c5f8ffd4657055a4caaffab153f2c Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 29 Mar 2018 18:03:04 +0700 Subject: rename tusb_hal_tick_get to tusb_hal_millis rename TUSB_CFG_TICKS_HZ to BOARD_TICKS_HZ --- examples/obsolete/device/src/tusb_config.h | 1 - examples/obsolete/host/src/tusb_config.h | 2 -- hw/bsp/board.h | 2 ++ hw/bsp/ea4357/board_ea4357.c | 24 +++++++++++++++++++++- hw/bsp/hitex/board_hitex4350.c | 2 +- hw/bsp/keil/board_mcb4300.c | 2 +- hw/bsp/lpcxpresso/board_lpclink2.c | 2 +- hw/bsp/lpcxpresso/board_lpcxpresso11u14.c | 2 +- hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c | 2 +- hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c | 2 +- hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c | 2 +- hw/bsp/ngx/board_ngx4330.c | 2 +- tinyusb/common/timeout_timer.h | 8 +++----- tinyusb/osal/osal_common.h | 6 ------ tinyusb/osal/osal_freeRTOS.h | 8 ++++---- tinyusb/osal/osal_none.h | 14 ++++++------- tinyusb/portable/nordic/nrf5x/hal_nrf5x.c | 2 +- tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c | 16 --------------- tinyusb/tusb_hal.h | 2 +- 19 files changed, 49 insertions(+), 52 deletions(-) (limited to 'examples/obsolete/host/src') diff --git a/examples/obsolete/device/src/tusb_config.h b/examples/obsolete/device/src/tusb_config.h index 7d32350ff..f33fb46ba 100644 --- a/examples/obsolete/device/src/tusb_config.h +++ b/examples/obsolete/device/src/tusb_config.h @@ -70,7 +70,6 @@ //#define TUSB_CFG_OS TUSB_OS_NONE // be passed from IDE/command line for easy project switching //#define TUSB_CFG_OS_TASK_PRIO 0 // be passed from IDE/command line for easy project switching -#define TUSB_CFG_TICKS_HZ 1000 //--------------------------------------------------------------------+ // USB RAM PLACEMENT diff --git a/examples/obsolete/host/src/tusb_config.h b/examples/obsolete/host/src/tusb_config.h index 04fd7e889..be1d5c7ed 100644 --- a/examples/obsolete/host/src/tusb_config.h +++ b/examples/obsolete/host/src/tusb_config.h @@ -71,8 +71,6 @@ //#define TUSB_CFG_OS TUSB_OS_NONE // defined using eclipse build //#define TUSB_CFG_OS_TASK_PRIO 0 // defined using eclipse build -#define TUSB_CFG_TICKS_HZ 1000 - //--------------------------------------------------------------------+ // USB RAM PLACEMENT //--------------------------------------------------------------------+ diff --git a/hw/bsp/board.h b/hw/bsp/board.h index aaedf27d6..2c566bb11 100644 --- a/hw/bsp/board.h +++ b/hw/bsp/board.h @@ -121,6 +121,8 @@ //--------------------------------------------------------------------+ #define CFG_UART_BAUDRATE 115200 ///< Baudrate for UART +#define BOARD_TICKS_HZ 1000 + //--------------------------------------------------------------------+ // Board Common API //--------------------------------------------------------------------+ diff --git a/hw/bsp/ea4357/board_ea4357.c b/hw/bsp/ea4357/board_ea4357.c index bfd100e1e..963e7629c 100644 --- a/hw/bsp/ea4357/board_ea4357.c +++ b/hw/bsp/ea4357/board_ea4357.c @@ -65,12 +65,34 @@ enum { BOARD_BUTTON_COUNT = sizeof(buttons) / sizeof(buttons[0]) }; +/*------------------------------------------------------------------*/ +/* TUSB HAL MILLISECOND + *------------------------------------------------------------------*/ +#if TUSB_CFG_OS == TUSB_OS_NONE + +volatile uint32_t system_ticks = 0; + +void SysTick_Handler (void) +{ + system_ticks++; +} + +uint32_t tusb_hal_millis(void) +{ + return (system_ticks*1000) / BOARD_TICKS_HZ; +} + +#endif + +/*------------------------------------------------------------------*/ +/* BOARD API + *------------------------------------------------------------------*/ void board_init(void) { CGU_Init(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / BOARD_TICKS_HZ); // 1 msec tick timer #endif //------------- USB -------------// diff --git a/hw/bsp/hitex/board_hitex4350.c b/hw/bsp/hitex/board_hitex4350.c index 4811f02f0..23e070a92 100644 --- a/hw/bsp/hitex/board_hitex4350.c +++ b/hw/bsp/hitex/board_hitex4350.c @@ -54,7 +54,7 @@ void board_init(void) { CGU_Init(); - SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / BOARD_TICKS_HZ); // 1 msec tick timer //------------- USB Bus power HOST ONLY-------------// // Hitex VBUS0 is P2_3 diff --git a/hw/bsp/keil/board_mcb4300.c b/hw/bsp/keil/board_mcb4300.c index 6addfb252..b9a3f4144 100644 --- a/hw/bsp/keil/board_mcb4300.c +++ b/hw/bsp/keil/board_mcb4300.c @@ -75,7 +75,7 @@ void board_init(void) CGU_Init(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / BOARD_TICKS_HZ); // 1 msec tick timer #endif //------------- USB Bus power HOST ONLY-------------// diff --git a/hw/bsp/lpcxpresso/board_lpclink2.c b/hw/bsp/lpcxpresso/board_lpclink2.c index d59b211fb..5f6f18cb6 100644 --- a/hw/bsp/lpcxpresso/board_lpclink2.c +++ b/hw/bsp/lpcxpresso/board_lpclink2.c @@ -57,7 +57,7 @@ void board_init(void) CGU_Init(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE) / BOARD_TICKS_HZ); // 1 msec tick timer #endif //------------- USB -------------// diff --git a/hw/bsp/lpcxpresso/board_lpcxpresso11u14.c b/hw/bsp/lpcxpresso/board_lpcxpresso11u14.c index eb8c39eda..79df45a36 100644 --- a/hw/bsp/lpcxpresso/board_lpcxpresso11u14.c +++ b/hw/bsp/lpcxpresso/board_lpcxpresso11u14.c @@ -68,7 +68,7 @@ void board_init(void) SystemInit(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer #endif GPIOInit(); diff --git a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c index ffdbc2706..5796c2341 100644 --- a/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c +++ b/hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c @@ -59,7 +59,7 @@ void board_init(void) SystemInit(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer #endif GPIOInit(); diff --git a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c b/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c index a0a615edc..c0a870d7e 100644 --- a/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c +++ b/hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c @@ -69,7 +69,7 @@ void board_init(void) SystemInit(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer #endif GPIOInit(); diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c index 39d669886..7aceb87f4 100644 --- a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c @@ -68,7 +68,7 @@ void board_init(void) SystemInit(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config(SystemCoreClock / TUSB_CFG_TICKS_HZ); // 1 msec tick timer + SysTick_Config(SystemCoreClock / BOARD_TICKS_HZ); // 1 msec tick timer #endif //------------- LED -------------// diff --git a/hw/bsp/ngx/board_ngx4330.c b/hw/bsp/ngx/board_ngx4330.c index 88212146f..63c72756e 100644 --- a/hw/bsp/ngx/board_ngx4330.c +++ b/hw/bsp/ngx/board_ngx4330.c @@ -71,7 +71,7 @@ void board_init(void) CGU_Init(); #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c - SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/TUSB_CFG_TICKS_HZ ); /* 1 ms Timer */ + SysTick_Config( CGU_GetPCLKFrequency(CGU_PERIPHERAL_M4CORE)/BOARD_TICKS_HZ ); /* 1 ms Timer */ #endif //------------- USB Bus power HOST ONLY-------------// diff --git a/tinyusb/common/timeout_timer.h b/tinyusb/common/timeout_timer.h index 2de71ded3..f504cc91f 100644 --- a/tinyusb/common/timeout_timer.h +++ b/tinyusb/common/timeout_timer.h @@ -55,17 +55,15 @@ typedef struct { uint32_t interval; }timeout_timer_t; -static inline void timeout_set(timeout_timer_t* tt, uint32_t msec) ATTR_ALWAYS_INLINE; static inline void timeout_set(timeout_timer_t* tt, uint32_t msec) { - tt->interval = osal_tick_from_msec(msec); - tt->start = osal_tick_get(); + tt->interval = msec; + tt->start = osal_millis(); } -static inline bool timeout_expired(timeout_timer_t* tt) ATTR_ALWAYS_INLINE; static inline bool timeout_expired(timeout_timer_t* tt) { - return ( osal_tick_get() - tt->start ) >= tt->interval; + return ( osal_millis() - tt->start ) >= tt->interval; } #ifdef __cplusplus diff --git a/tinyusb/osal/osal_common.h b/tinyusb/osal/osal_common.h index 2d35e74b4..42ed6e77b 100644 --- a/tinyusb/osal/osal_common.h +++ b/tinyusb/osal/osal_common.h @@ -55,12 +55,6 @@ enum OSAL_TIMEOUT_WAIT_FOREVER = 0xFFFFFFFF }; -static inline uint32_t osal_tick_from_msec(uint32_t msec) ATTR_CONST ATTR_ALWAYS_INLINE; -static inline uint32_t osal_tick_from_msec(uint32_t msec) -{ - return (msec * TUSB_CFG_TICKS_HZ)/1000; -} - #ifdef __cplusplus } #endif diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h index befad3fd0..f2fe668ae 100644 --- a/tinyusb/osal/osal_freeRTOS.h +++ b/tinyusb/osal/osal_freeRTOS.h @@ -59,7 +59,7 @@ extern "C" { //--------------------------------------------------------------------+ // TICK API //--------------------------------------------------------------------+ -#define osal_tick_get xTaskGetTickCount +#define osal_millis xTaskGetTickCount //--------------------------------------------------------------------+ // TASK API @@ -76,7 +76,7 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u static inline void osal_task_delay(uint32_t msec) { - vTaskDelay( (TUSB_CFG_TICKS_HZ * msec) / 1000 ); + vTaskDelay( pdMS_TO_TICKS(msec) ); } //--------------------------------------------------------------------+ @@ -91,7 +91,7 @@ static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size) static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error) { - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : osal_tick_from_msec(msec); + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); portBASE_TYPE result = (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? xQueueReceiveFromISR(queue_hdl, p_data, NULL) : xQueueReceive(queue_hdl, p_data, ticks); (*p_error) = ( result == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT; @@ -137,7 +137,7 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl) static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error) { - uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : osal_tick_from_msec(msec); + uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : pdMS_TO_TICKS(msec); BaseType_t result; diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index f150d5c34..0b73de4e9 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -53,7 +53,7 @@ //--------------------------------------------------------------------+ // TICK API //--------------------------------------------------------------------+ -#define osal_tick_get tusb_hal_tick_get +#define osal_millis tusb_hal_millis //--------------------------------------------------------------------+ // TASK API @@ -97,9 +97,9 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u #define osal_task_delay(msec) \ do {\ - _timeout = osal_tick_get();\ + _timeout = osal_millis();\ _state = __LINE__; case __LINE__:\ - if ( _timeout + osal_tick_from_msec(msec) > osal_tick_get() ) \ + if ( _timeout + msec > osal_millis() ) \ return TUSB_ERROR_OSAL_WAITING;\ }while(0) @@ -164,10 +164,10 @@ static inline void osal_queue_flush(osal_queue_t const queue_hdl) #define osal_queue_receive(queue_hdl, p_data, msec, p_error) \ do {\ - _timeout = osal_tick_get();\ + _timeout = osal_millis();\ _state = __LINE__; case __LINE__:\ if( queue_hdl->count == 0 ) {\ - if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + osal_tick_from_msec(msec) <= osal_tick_get() )) /* time out */ \ + if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && ( _timeout + msec <= osal_millis()) ) /* time out */ \ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ else\ return TUSB_ERROR_OSAL_WAITING;\ @@ -218,10 +218,10 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) #define osal_semaphore_wait(sem_hdl, msec, p_error) \ do {\ - _timeout = osal_tick_get();\ + _timeout = osal_millis();\ _state = __LINE__; case __LINE__:\ if( sem_hdl->count == 0 ) {\ - if ( ( ((uint32_t) (msec)) != OSAL_TIMEOUT_WAIT_FOREVER) && (_timeout + osal_tick_from_msec(msec) <= osal_tick_get()) ) /* time out */ \ + if ( (msec != OSAL_TIMEOUT_WAIT_FOREVER) && (_timeout + msec <= osal_millis()) ) /* time out */ \ *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ else\ return TUSB_ERROR_OSAL_WAITING;\ diff --git a/tinyusb/portable/nordic/nrf5x/hal_nrf5x.c b/tinyusb/portable/nordic/nrf5x/hal_nrf5x.c index 073f4ac36..4cb7f076e 100644 --- a/tinyusb/portable/nordic/nrf5x/hal_nrf5x.c +++ b/tinyusb/portable/nordic/nrf5x/hal_nrf5x.c @@ -81,7 +81,7 @@ void tusb_hal_int_disable(uint8_t rhport) NVIC_DisableIRQ(USBD_IRQn); } -uint32_t tusb_hal_tick_get(void) +uint32_t tusb_hal_millis(void) { //#define tick2ms(tck) ( ( ((uint64_t)(tck)) * 1000) / configTICK_RATE_HZ ) //return tick2ms( app_timer_cnt_get() ); diff --git a/tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c b/tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c index ff7d32a3f..31481b742 100644 --- a/tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c +++ b/tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c @@ -53,22 +53,6 @@ enum { LPC43XX_USBMODE_VBUS_HIGH = 1 }; -#if TUSB_CFG_OS == TUSB_OS_NONE - -volatile uint32_t system_ticks = 0; - -void SysTick_Handler (void) -{ - system_ticks++; -} - -uint32_t tusb_hal_tick_get(void) -{ - return system_ticks; -} - -#endif - void tusb_hal_int_enable(uint8_t rhport) { NVIC_EnableIRQ(rhport ? USB1_IRQn : USB0_IRQn); diff --git a/tinyusb/tusb_hal.h b/tinyusb/tusb_hal.h index 98ec79f97..0025bf844 100644 --- a/tinyusb/tusb_hal.h +++ b/tinyusb/tusb_hal.h @@ -75,7 +75,7 @@ void tusb_hal_int_enable(uint8_t rhport); */ void tusb_hal_int_disable(uint8_t rhport); -uint32_t tusb_hal_tick_get(void); +uint32_t tusb_hal_millis(void); #ifdef __cplusplus } -- cgit v1.3.1 From 3c2467196070eeedd4171e183db04fb815677246 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 10 Apr 2018 14:31:11 +0700 Subject: mass rename TUSB_CFG to CFG_TUSB --- doxygen/configuration.txt | 48 +++++++------- doxygen/getting_started.md | 2 +- doxygen/started_demo.md | 2 +- .../segger/device_virtual_com.emProject | 2 +- examples/device/device_virtual_com/src/main.c | 10 +-- .../device/device_virtual_com/src/tusb_config.h | 66 +++++++++---------- .../device_virtual_com/src/tusb_descriptors.c | 2 +- .../device_virtual_com/src/tusb_descriptors.h | 2 +- .../device/device_virtual_com/xpresso/.cproject | 2 +- examples/device/nrf52840/src/main.c | 10 +-- examples/device/nrf52840/src/msc_device_app.c | 2 +- examples/device/nrf52840/src/msc_device_app.h | 4 +- examples/device/nrf52840/src/msc_device_ramdisk.c | 4 +- examples/device/nrf52840/src/tusb_config.h | 32 ++++----- examples/device/nrf52840/src/tusb_descriptors.c | 2 +- examples/device/nrf52840/src/tusb_descriptors.h | 2 +- examples/obsolete/device/device_freertos/.cproject | 36 +++++----- examples/obsolete/device/device_os_none/.cproject | 24 +++---- examples/obsolete/device/src/app_os_prio.h | 6 +- examples/obsolete/device/src/cdc_device_app.c | 2 +- examples/obsolete/device/src/cdc_device_app.h | 2 +- examples/obsolete/device/src/keyboard_device_app.c | 4 +- examples/obsolete/device/src/keyboard_device_app.h | 2 +- examples/obsolete/device/src/main.c | 16 ++--- examples/obsolete/device/src/mouse_device_app.c | 4 +- examples/obsolete/device/src/mouse_device_app.h | 2 +- examples/obsolete/device/src/msc_device_app.c | 2 +- examples/obsolete/device/src/msc_device_app.h | 4 +- examples/obsolete/device/src/msc_device_ramdisk.c | 4 +- examples/obsolete/device/src/msc_device_romdisk.c | 4 +- examples/obsolete/device/src/tusb_config.h | 62 +++++++++--------- examples/obsolete/device/src/tusb_descriptors.c | 20 +++--- examples/obsolete/device/src/tusb_descriptors.h | 28 ++++---- examples/obsolete/host/host_freertos/.cproject | 28 ++++---- examples/obsolete/host/host_os_none/.cproject | 16 ++--- examples/obsolete/host/src/app_os_prio.h | 8 +-- examples/obsolete/host/src/cdc_serial_host_app.c | 10 +-- examples/obsolete/host/src/cdc_serial_host_app.h | 2 +- examples/obsolete/host/src/keyboard_host_app.c | 4 +- examples/obsolete/host/src/keyboard_host_app.h | 2 +- examples/obsolete/host/src/main.c | 22 +++---- examples/obsolete/host/src/mouse_host_app.c | 4 +- examples/obsolete/host/src/mouse_host_app.h | 2 +- examples/obsolete/host/src/msc_cli.c | 4 +- examples/obsolete/host/src/msc_host_app.c | 8 +-- examples/obsolete/host/src/msc_host_app.h | 2 +- examples/obsolete/host/src/rndis_host_app.c | 2 +- examples/obsolete/host/src/rndis_host_app.h | 2 +- examples/obsolete/host/src/tusb_config.h | 48 +++++++------- examples/readme.md | 2 +- hw/bsp/ea4357/board_ea4357.c | 6 +- hw/bsp/keil/board_mcb4300.c | 2 +- hw/bsp/lpcxpresso/board_lpclink2.c | 2 +- hw/bsp/lpcxpresso/board_lpcxpresso11u14.c | 2 +- hw/bsp/lpcxpresso11u68/board_lpcxpresso11u68.c | 2 +- hw/bsp/lpcxpresso1347/board_lpcxpresso1347.c | 2 +- hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c | 2 +- hw/bsp/ngx/board_ngx4330.c | 2 +- hw/mcu/nxp/lpc11uxx/hal_mcu/hal_lpc11uxx.c | 2 +- hw/mcu/nxp/lpc13uxx/hal_mcu/hal_lpc13uxx.c | 2 +- readme.markdown | 2 +- tests/.cproject | 2 +- tests/lpc175x_6x/project.yml | 2 +- tests/lpc175x_6x/test/test_usbd.c | 12 ++-- tests/lpc18xx_43xx/project.yml | 2 +- tests/lpc18xx_43xx/test/host/cdc/descriptor_cdc.c | 4 +- tests/lpc18xx_43xx/test/host/cdc/test_cdc_host.c | 6 +- .../test/host/cdc/test_cdc_rndis_host.c | 6 +- tests/lpc18xx_43xx/test/host/ehci/test_ehci_init.c | 2 +- tests/lpc18xx_43xx/test/host/ehci/test_ehci_isr.c | 2 +- .../test/host/ehci/test_ehci_structure.c | 2 +- .../test/host/ehci/test_pipe_bulk_open.c | 4 +- .../test/host/ehci/test_pipe_bulk_xfer.c | 4 +- .../test/host/ehci/test_pipe_control_open.c | 4 +- .../test/host/ehci/test_pipe_control_xfer.c | 4 +- .../test/host/ehci/test_pipe_interrupt_open.c | 4 +- .../test/host/ehci/test_pipe_interrupt_xfer.c | 4 +- .../test/host/ehci/test_pipe_isochronous_open.c | 4 +- tests/lpc18xx_43xx/test/host/hid/test_hid_host.c | 4 +- .../lpc18xx_43xx/test/host/hid/test_hidh_generic.c | 6 +- .../test/host/hid/test_hidh_keyboard.c | 6 +- tests/lpc18xx_43xx/test/host/hid/test_hidh_mouse.c | 6 +- tests/lpc18xx_43xx/test/host/host_helper.h | 4 +- .../integration/test_hidh_keyboard_integrate.c | 2 +- tests/lpc18xx_43xx/test/host/msc/test_msc_host.c | 6 +- tests/lpc18xx_43xx/test/host/usbh/test_enum_task.c | 8 +-- tests/lpc18xx_43xx/test/host/usbh/test_usbh.c | 6 +- tests/lpc18xx_43xx/test/test_osal_none.c | 18 ++--- tests/support/descriptor_test.c | 8 +-- tests/support/descriptor_test.h | 2 +- tests/support/ehci_controller_fake.c | 2 +- tests/support/tusb_config.h | 42 ++++++------ tinyusb.Doxyfile | 10 +-- tinyusb/class/cdc/cdc_device.c | 8 +-- tinyusb/class/cdc/cdc_host.c | 6 +- tinyusb/class/cdc/cdc_host.h | 10 +-- tinyusb/class/cdc/cdc_rndis_host.c | 14 ++-- tinyusb/class/custom_class_host.c | 6 +- tinyusb/class/hid/hid_device.c | 10 +-- tinyusb/class/hid/hid_device.h | 8 +-- tinyusb/class/hid/hid_host.c | 40 ++++++------ tinyusb/class/hid/hid_host.h | 4 +- tinyusb/class/msc/msc_device.c | 6 +- tinyusb/class/msc/msc_device.h | 4 +- tinyusb/class/msc/msc_host.c | 8 +-- tinyusb/class/msc/msc_host.h | 6 +- tinyusb/common/tusb_compiler.h | 2 +- tinyusb/common/tusb_error.h | 4 +- tinyusb/common/tusb_fifo.h | 2 +- tinyusb/common/tusb_verify.h | 2 +- tinyusb/device/usbd.c | 18 ++--- tinyusb/device/usbd.h | 4 +- tinyusb/host/ehci/ehci.c | 32 ++++----- tinyusb/host/ehci/ehci.h | 2 +- tinyusb/host/hcd.h | 4 +- tinyusb/host/hub.c | 8 +-- tinyusb/host/ohci/ohci.c | 8 +-- tinyusb/host/ohci/ohci.h | 4 +- tinyusb/host/usbh.c | 38 +++++------ tinyusb/host/usbh_hcd.h | 2 +- tinyusb/osal/osal.c | 2 +- tinyusb/osal/osal.h | 8 +-- tinyusb/portable/nordic/nrf5x/dcd_nrf5x.c | 2 + .../nxp/lpc11xx_lpc13xx/dcd_lpc_11uxx_13uxx.c | 10 +-- tinyusb/portable/nxp/lpc17xx/dcd_lpc175x_6x.c | 10 +-- tinyusb/portable/nxp/lpc17xx/hal_lpc175x_6x.c | 2 +- tinyusb/portable/nxp/lpc43xx_lpc18xx/dcd_lpc43xx.c | 12 ++-- tinyusb/portable/nxp/lpc43xx_lpc18xx/hal_lpc43xx.c | 18 ++--- tinyusb/tusb.c | 4 +- tinyusb/tusb.h | 14 ++-- tinyusb/tusb_hal.h | 8 +-- tinyusb/tusb_option.h | 76 +++++++++++----------- vendor/fatfs/ccsbcs.c | 4 +- vendor/fatfs/diskio.c | 10 +-- vendor/fatfs/diskio.h | 2 +- vendor/fatfs/ff.c | 4 +- vendor/fatfs/ffconf.h | 2 +- vendor/freertos/FreeRTOSConfig.h | 2 +- 138 files changed, 628 insertions(+), 626 deletions(-) (limited to 'examples/obsolete/host/src') diff --git a/doxygen/configuration.txt b/doxygen/configuration.txt index c84eea76e..8f5887718 100644 --- a/doxygen/configuration.txt +++ b/doxygen/configuration.txt @@ -7,46 +7,46 @@ /// \brief tell the stack which mode (host/device/otg) the usb controller0 will be operated on. Possible value is /// from \ref group_mode. Note the hardware usb controller must support the selected mode. -#define TUSB_CFG_CONTROLLER_0_MODE +#define CFG_TUSB_CONTROLLER_0_MODE /** USB controller in MCU often has limited access to specific RAM section. The Stack will use this macro to place internal variables - into the USB RAM section as follows. if your mcu's usb controller has no such limit, define TUSB_CFG_ATTR_USBRAM as empty macro. + into the USB RAM section as follows. if your mcu's usb controller has no such limit, define CFG_TUSB_ATTR_USBRAM as empty macro. @code - TUSB_CFG_ATTR_USBRAM uint8_t usb_xfer_buffer[10]; + CFG_TUSB_ATTR_USBRAM uint8_t usb_xfer_buffer[10]; @endcode */ -#define TUSB_CFG_ATTR_USBRAM +#define CFG_TUSB_ATTR_USBRAM -#define TUSB_CFG_MCU ///< Select one of the supported MCU, the value must be from \ref group_mcu -#define TUSB_CFG_OS ///< Select one of the supported RTOS, the value must be from \ref group_supported_os. -#define TUSB_CFG_OS_TASK_PRIO ///< If \ref TUSB_CFG_OS is configured to use a real RTOS (other than TUSB_OS_NONE). This determines the priority of the usb stack task. -#define TUSB_CFG_TICKS_HZ ///< The rate ticks in hert. This is used in conjunction with \ref tusb_tick_get to calculate timing. +#define CFG_TUSB_MCU ///< Select one of the supported MCU, the value must be from \ref group_mcu +#define CFG_TUSB_OS ///< Select one of the supported RTOS, the value must be from \ref group_supported_os. +#define CFG_TUSB_OS_TASK_PRIO ///< If \ref CFG_TUSB_OS is configured to use a real RTOS (other than TUSB_OS_NONE). This determines the priority of the usb stack task. +#define CFG_TUSB_TICKS_HZ ///< The rate ticks in hert. This is used in conjunction with \ref tusb_tick_get to calculate timing. //--------------------------------------------------------------------+ // HOST CONFIGURATION //--------------------------------------------------------------------+ -/** \defgroup TUSB_CFG_HOST Host Options +/** \defgroup CFG_TUSB_HOST Host Options * @{ */ /** \brief Maximum number of device host stack can manage * \n If hub class is not enabled, set this equal to number of controllers in host mode * \n If hub class is enabled, make sure hub is also counted */ -#define TUSB_CFG_HOST_DEVICE_MAX +#define CFG_TUSB_HOST_DEVICE_MAX /// \brief Buffer size used for getting device configuration descriptor. You may want to increase this from default (256) /// to support lengthy composite device especially with Audio or Video class -#define TUSB_CFG_HOST_ENUM_BUFFER_SIZE +#define CFG_TUSB_HOST_ENUM_BUFFER_SIZE /** \defgroup config_host_class Class Driver * \brief For each Class Driver a value of 1 means enable, value of 0 mean disable * @{ */ -#define TUSB_CFG_HOST_HUB ///< Enable Hub Class -#define TUSB_CFG_HOST_HID_KEYBOARD ///< Enable HID Class for Keyboard -#define TUSB_CFG_HOST_HID_MOUSE ///< Enable HID Class for Mouse -#define TUSB_CFG_HOST_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) -#define TUSB_CFG_HOST_MSC ///< Enable Mass Storage Class (SCSI subclass only) -#define TUSB_CFG_HOST_CDC ///< Enable Virtual Serial (Communication Device Class) +#define CFG_TUSB_HOST_HUB ///< Enable Hub Class +#define CFG_TUSB_HOST_HID_KEYBOARD ///< Enable HID Class for Keyboard +#define CFG_TUSB_HOST_HID_MOUSE ///< Enable HID Class for Mouse +#define CFG_TUSB_HOST_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) +#define CFG_TUSB_HOST_MSC ///< Enable Mass Storage Class (SCSI subclass only) +#define CFG_TUSB_HOST_CDC ///< Enable Virtual Serial (Communication Device Class) /** @} */ /** @} */ // group Host @@ -54,10 +54,10 @@ //--------------------------------------------------------------------+ // DEVICE CONFIGURATION //--------------------------------------------------------------------+ -/** \defgroup TUSB_CFG_DEVICE Device Options +/** \defgroup CFG_TUSB_DEVICE Device Options * @{ */ -#define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE ///< Max packet size of Cotnrol Endpoint, default is 64 +#define CFG_TUSB_DEVICE_CONTROL_ENDOINT_SIZE ///< Max packet size of Cotnrol Endpoint, default is 64 /// Application MUST define this variable and initialize its pointers's member to all required USB descriptors including /// Device Descriptor, Configuration Descriptor, String Descriptors, HID Report Descriptors etc ... @@ -66,11 +66,11 @@ tusbd_descriptor_pointer_t tusbd_descriptor_pointers; /** \defgroup config_device_class Class Driver * \brief For each Class Driver a value of 1 means enable, value of 0 mean disable * @{ */ -#define TUSB_CFG_DEVICE_HID_KEYBOARD ///< Enable HID Class for Keyboard -#define TUSB_CFG_DEVICE_HID_MOUSE ///< Enable HID Class for Mouse -#define TUSB_CFG_DEVICE_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) -#define TUSB_CFG_DEVICE_MSC ///< Enable Mass Storage Class (SCSI subclass only) -#define TUSB_CFG_DEVICE_CDC ///< Enable Virtual Serial (Communication Device Class) +#define CFG_TUSB_DEVICE_HID_KEYBOARD ///< Enable HID Class for Keyboard +#define CFG_TUSB_DEVICE_HID_MOUSE ///< Enable HID Class for Mouse +#define CFG_TUSB_DEVICE_HID_GENERIC ///< Enable HID Class for Generic (not supported yet) +#define CFG_TUSB_DEVICE_MSC ///< Enable Mass Storage Class (SCSI subclass only) +#define CFG_TUSB_DEVICE_CDC ///< Enable Virtual Serial (Communication Device Class) /** @} */ /** @} */ // group Device diff --git a/doxygen/getting_started.md b/doxygen/getting_started.md index d58634845..79bc8f01f 100644 --- a/doxygen/getting_started.md +++ b/doxygen/getting_started.md @@ -35,7 +35,7 @@ It is relatively simple to incorporate tinyusb to your (existing) project 1. Copy core folder **tinyusb** to your project. Let's say it is *your_project/tinyusb* 2. Add all the .c in the core folder to your project settings (uvproj, ewp, makefile) 3. Add *your_project/tinysb* to your include path. Also make sure your current include path also contains the configuration file tusb_config.h. Or you could simply put the tusb_config.h into the tinyusb folder as well. -4. Make sure all required macros are all defined properly in tusb_config.h (configure file in demo application is sufficient, but you need to add a few more such as TUSB_CFG_MCU, TUSB_CFG_OS, TUSB_CFG_OS_TASK_PRIO since they are passed by IDE/compiler to maintain a unique configure for all demo projects). +4. Make sure all required macros are all defined properly in tusb_config.h (configure file in demo application is sufficient, but you need to add a few more such as CFG_TUSB_MCU, CFG_TUSB_OS, CFG_TUSB_OS_TASK_PRIO since they are passed by IDE/compiler to maintain a unique configure for all demo projects). 5. If you use the device stack, make sure you have created/modified usb descriptors for your own need. Ultimately you need to fill out required pointers in tusbd_descriptor_pointers for that stack to work. 6. Add tusb_init() call to your reset initialization code. 7. Implement all enabled classes's callbacks. diff --git a/doxygen/started_demo.md b/doxygen/started_demo.md index 287c55731..7e82596f5 100644 --- a/doxygen/started_demo.md +++ b/doxygen/started_demo.md @@ -34,7 +34,7 @@ void led_blinking_task( void * p_task_para ) static uint32_t led_on_mask = 0; // FreeRTOS API's vTaskDelay is used in place of osal_task_delay. Note it takes input parameter in tick - vTaskDelay( (led_blink_interval_ms * TUSB_CFG_TICKS_HZ) / 1000); + vTaskDelay( (led_blink_interval_ms * CFG_TUSB_TICKS_HZ) / 1000); board_leds(led_on_mask, 1 - led_on_mask); led_on_mask = 1 - led_on_mask; // toggle diff --git a/examples/device/device_virtual_com/segger/device_virtual_com.emProject b/examples/device/device_virtual_com/segger/device_virtual_com.emProject index c52698a89..63927ff9d 100644 --- a/examples/device/device_virtual_com/segger/device_virtual_com.emProject +++ b/examples/device/device_virtual_com/segger/device_virtual_com.emProject @@ -201,7 +201,7 @@ + c_preprocessor_definitions="BOARD=BOARD_EA4357;CFG_TUSB_MCU=MCU_LPC43XX" /> - +