From 15c80a958093cbf100ad89ed162325bdaf5e5a75 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 16 Oct 2013 12:35:55 +0700 Subject: [PATCH] clean up --- demos/host/src/cdc_serial_app.c | 289 ++++++++++++------------- demos/host/src/cdc_serial_app.h | 140 ++++++------ demos/host/src/keyboard_app.c | 373 ++++++++++++++++---------------- demos/host/src/keyboard_app.h | 152 +++++++------ demos/host/src/mouse_app.c | 10 - demos/host/src/mouse_app.h | 157 +++++++------- demos/host/src/msc_app.c | 362 +++++++++++++++---------------- demos/host/src/msc_app.h | 149 +++++++------ demos/host/src/rndis_app.c | 168 +++++++------- demos/host/src/rndis_app.h | 140 ++++++------ demos/host/src/tusb_config.h | 258 +++++++++++----------- tinyusb/common/errors.c | 97 ++++----- 12 files changed, 1144 insertions(+), 1151 deletions(-) diff --git a/demos/host/src/cdc_serial_app.c b/demos/host/src/cdc_serial_app.c index a83c27ab..3effbe2e 100644 --- a/demos/host/src/cdc_serial_app.c +++ b/demos/host/src/cdc_serial_app.c @@ -1,149 +1,140 @@ -/**************************************************************************/ -/*! - @file cdc_serial_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_app.h" - -#if TUSB_CFG_OS != TUSB_OS_NONE -#include "app_os_prio.h" -#endif - -#if TUSB_CFG_HOST_CDC - -#define QUEUE_SERIAL_DEPTH 100 - -//--------------------------------------------------------------------+ -// MACRO CONSTANT TYPEDEF -//--------------------------------------------------------------------+ -OSAL_TASK_DEF(cdc_serial_app_task, 128, CDC_SERIAL_APP_TASK_PRIO); -OSAL_QUEUE_DEF(queue_def, QUEUE_SERIAL_DEPTH, uint8_t); - -static osal_queue_handle_t queue_hdl; -static uint8_t buffer_in[64] TUSB_CFG_ATTR_USBRAM; - -//--------------------------------------------------------------------+ -// tinyusb Callbacks -//--------------------------------------------------------------------+ -void tusbh_cdc_mounted_cb(uint8_t dev_addr) -{ - // application set-up - - printf("\na CDC device is mounted\n"); - - osal_queue_flush(queue_hdl); - tusbh_cdc_receive(dev_addr, buffer_in, sizeof(buffer_in), true); // first report -} - -void tusbh_cdc_unmounted_cb(uint8_t dev_addr) -{ - // application tear-down - printf("\na CDC device is unmounted\n"); -} - -void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes) -{ - if ( pipe_id == CDC_PIPE_DATA_IN ) - { - switch(event) - { - case TUSB_EVENT_XFER_COMPLETE: - for(uint32_t i=0; ikeycode[i] == keycode) - { - return true; - } - } - - return false; -} - -static inline void process_kbd_report(tusb_keyboard_report_t const *p_new_report) -{ - static tusb_keyboard_report_t prev_report = { 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 ( is_key_in_report(&prev_report, p_new_report->modifier, p_new_report->keycode[i]) ) - { - // previously existed means holding - }else - { - // previously non-existed means key is pressed - printf("%c", keycode_to_ascii(p_new_report->modifier, p_new_report->keycode[i]) ); - } - } - // 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]; -} - -#else - -// dummy implementation to remove #ifdef in main.c -void keyboard_app_init(void) { } -OSAL_TASK_FUNCTION( keyboard_app_task ) (void* p_task_para) -{ - OSAL_TASK_LOOP_BEGIN - OSAL_TASK_LOOP_END -} -#endif +/**************************************************************************/ +/*! + @file keyboard_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 "keyboard_app.h" + +#if TUSB_CFG_OS != TUSB_OS_NONE +#include "app_os_prio.h" +#endif + +#if TUSB_CFG_HOST_HID_KEYBOARD + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ +#define QUEUE_KEYBOARD_REPORT_DEPTH 4 + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +OSAL_TASK_DEF(keyboard_app_task, 128, KEYBOARD_APP_TASK_PRIO); +OSAL_QUEUE_DEF(queue_kbd_def, QUEUE_KEYBOARD_REPORT_DEPTH, tusb_keyboard_report_t); + +static osal_queue_handle_t queue_kbd_hdl; +static tusb_keyboard_report_t usb_keyboard_report TUSB_CFG_ATTR_USBRAM; + +static inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode) ATTR_CONST ATTR_ALWAYS_INLINE; +static inline void process_kbd_report(tusb_keyboard_report_t const * report); + +//--------------------------------------------------------------------+ +// tinyusb callback (ISR context) +//--------------------------------------------------------------------+ +void tusbh_hid_keyboard_mounted_cb(uint8_t dev_addr) +{ + // application set-up + + puts("\na Keyboard device is mounted"); + + osal_queue_flush(queue_kbd_hdl); + tusbh_hid_keyboard_get_report(dev_addr, (uint8_t*) &usb_keyboard_report); // first report +} + +void tusbh_hid_keyboard_unmounted_cb(uint8_t dev_addr) +{ + // application tear-down + puts("\na Keyboard device is unmounted"); +} + +void tusbh_hid_keyboard_isr(uint8_t dev_addr, tusb_event_t event) +{ + switch(event) + { + case TUSB_EVENT_XFER_COMPLETE: + osal_queue_send(queue_kbd_hdl, &usb_keyboard_report); + tusbh_hid_keyboard_get_report(dev_addr, (uint8_t*) &usb_keyboard_report); + break; + + case TUSB_EVENT_XFER_ERROR: + tusbh_hid_keyboard_get_report(dev_addr, (uint8_t*) &usb_keyboard_report); // ignore & continue + break; + + default : + break; + } +} + +//--------------------------------------------------------------------+ +// APPLICATION +//--------------------------------------------------------------------+ +void keyboard_app_init(void) +{ + memclr_(&usb_keyboard_report, sizeof(tusb_keyboard_report_t)); + + queue_kbd_hdl = osal_queue_create( OSAL_QUEUE_REF(queue_kbd_def) ); + ASSERT_PTR( queue_kbd_hdl, VOID_RETURN ); + + ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(keyboard_app_task) ) , + VOID_RETURN); +} + +//------------- main task -------------// +OSAL_TASK_FUNCTION( keyboard_app_task ) (void* p_task_para) +{ + tusb_error_t error; + tusb_keyboard_report_t kbd_report; + + OSAL_TASK_LOOP_BEGIN + + osal_queue_receive(queue_kbd_hdl, &kbd_report, OSAL_TIMEOUT_WAIT_FOREVER, &error); + + process_kbd_report(&kbd_report); + + OSAL_TASK_LOOP_END +} + +//--------------------------------------------------------------------+ +// HELPER +//--------------------------------------------------------------------+ + +// look up new key in previous keys +static inline bool is_key_in_report(tusb_keyboard_report_t const *p_report, uint8_t modifier, uint8_t keycode) +{ + for(uint8_t i=0; i<6; i++) + { + if (p_report->keycode[i] == keycode) + { + return true; + } + } + + return false; +} + +static inline void process_kbd_report(tusb_keyboard_report_t const *p_new_report) +{ + static tusb_keyboard_report_t prev_report = { 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 ( is_key_in_report(&prev_report, p_new_report->modifier, p_new_report->keycode[i]) ) + { + // previously existed means holding + }else + { + // previously non-existed means key is pressed + printf("%c", keycode_to_ascii(p_new_report->modifier, p_new_report->keycode[i]) ); + } + } + // 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/demos/host/src/keyboard_app.h b/demos/host/src/keyboard_app.h index 2b7a27e7..82305ca8 100644 --- a/demos/host/src/keyboard_app.h +++ b/demos/host/src/keyboard_app.h @@ -1,72 +1,80 @@ -/**************************************************************************/ -/*! - @file keyboard_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_APP_H_ -#define _TUSB_KEYBOARD_APP_H_ - -#include "boards/board.h" -#include "tusb.h" - -#ifdef __cplusplus - extern "C" { -#endif - - -void keyboard_app_init(void); -OSAL_TASK_FUNCTION( keyboard_app_task ) (void* p_task_para); - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_KEYBOARD_APP_H_ */ - -/** @} */ +/**************************************************************************/ +/*! + @file keyboard_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_APP_H_ +#define _TUSB_KEYBOARD_APP_H_ + +#include "boards/board.h" +#include "tusb.h" + +#ifdef __cplusplus + extern "C" { +#endif + +#if TUSB_CFG_HOST_HID_KEYBOARD + +void keyboard_app_init(void); +OSAL_TASK_FUNCTION( keyboard_app_task ) (void* p_task_para); + +#else + +#define keyboard_app_init() +#define keyboard_app_task(x) + +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_KEYBOARD_APP_H_ */ + +/** @} */ diff --git a/demos/host/src/mouse_app.c b/demos/host/src/mouse_app.c index df18b966..c5969cd4 100644 --- a/demos/host/src/mouse_app.c +++ b/demos/host/src/mouse_app.c @@ -182,14 +182,4 @@ static inline void process_mouse_report(tusb_mouse_report_t const * p_report) cursor_movement(p_report->x, p_report->y, p_report->wheel); } -#else - -// dummy implementation to remove #ifdef in main.c -void mouse_app_init(void) { } -OSAL_TASK_FUNCTION( mouse_app_task ) (void* p_task_para) -{ - OSAL_TASK_LOOP_BEGIN - OSAL_TASK_LOOP_END -} - #endif diff --git a/demos/host/src/mouse_app.h b/demos/host/src/mouse_app.h index 53ab1e2c..7a5515bb 100644 --- a/demos/host/src/mouse_app.h +++ b/demos/host/src/mouse_app.h @@ -1,74 +1,83 @@ -/**************************************************************************/ -/*! - @file mouse_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_APP_H_ -#define _TUSB_MOUSE_APP_H_ - -#include -#include - -#include "boards/board.h" -#include "tusb.h" - -#ifdef __cplusplus - extern "C" { -#endif - -void mouse_app_init(void); -OSAL_TASK_FUNCTION( mouse_app_task ) (void* p_task_para); - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_MOUSE_APP_H_ */ - -/** @} */ +/**************************************************************************/ +/*! + @file mouse_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_APP_H_ +#define _TUSB_MOUSE_APP_H_ + +#include +#include + +#include "boards/board.h" +#include "tusb.h" + +#ifdef __cplusplus + extern "C" { +#endif + +#if TUSB_CFG_HOST_HID_MOUSE + +void mouse_app_init(void); +OSAL_TASK_FUNCTION( mouse_app_task ) (void* p_task_para); + +#else + +#define mouse_app_init() +#define mouse_app_task(x) + +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_MOUSE_APP_H_ */ + +/** @} */ diff --git a/demos/host/src/msc_app.c b/demos/host/src/msc_app.c index 2591e61a..e9347fa8 100644 --- a/demos/host/src/msc_app.c +++ b/demos/host/src/msc_app.c @@ -1,186 +1,176 @@ -/**************************************************************************/ -/*! - @file msc_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_app.h" - -#if TUSB_CFG_OS != TUSB_OS_NONE -#include "app_os_prio.h" -#endif - -#if TUSB_CFG_HOST_MSC - -#include "cli.h" -#include "ff.h" -#include "diskio.h" - -//--------------------------------------------------------------------+ -// MACRO CONSTANT TYPEDEF -//--------------------------------------------------------------------+ - -//--------------------------------------------------------------------+ -// INTERNAL OBJECT & FUNCTION DECLARATION -//--------------------------------------------------------------------+ -static FATFS fatfs[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM; - -//--------------------------------------------------------------------+ -// tinyusb callback (ISR context) -//--------------------------------------------------------------------+ -void tusbh_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 = tusbh_msc_get_vendor_name(dev_addr); - uint8_t const* p_product = tusbh_msc_get_product_name(dev_addr); - - for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]); - - printf(" "); - for(uint8_t i=0; i<16; i++) putchar(p_product[i]); - putchar('\n'); - - uint32_t last_lba, block_size; - tusbh_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 tusbh_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_LOOP_END -} - -#else -// dummy implementation to remove #ifdef in main.c -void msc_app_init(void) { } -OSAL_TASK_FUNCTION( msc_app_task ) (void* p_task_para) -{ - OSAL_TASK_LOOP_BEGIN - OSAL_TASK_LOOP_END -} - - -#endif +/**************************************************************************/ +/*! + @file msc_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_app.h" + +#if TUSB_CFG_OS != TUSB_OS_NONE +#include "app_os_prio.h" +#endif + +#if TUSB_CFG_HOST_MSC + +#include "cli.h" +#include "ff.h" +#include "diskio.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +static FATFS fatfs[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM; + +//--------------------------------------------------------------------+ +// tinyusb callback (ISR context) +//--------------------------------------------------------------------+ +void tusbh_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 = tusbh_msc_get_vendor_name(dev_addr); + uint8_t const* p_product = tusbh_msc_get_product_name(dev_addr); + + for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]); + + printf(" "); + for(uint8_t i=0; i<16; i++) putchar(p_product[i]); + putchar('\n'); + + uint32_t last_lba, block_size; + tusbh_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 tusbh_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_LOOP_END +} + +#endif diff --git a/demos/host/src/msc_app.h b/demos/host/src/msc_app.h index dc56bbdd..1e680ccc 100644 --- a/demos/host/src/msc_app.h +++ b/demos/host/src/msc_app.h @@ -1,71 +1,78 @@ -/**************************************************************************/ -/*! - @file msc_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_APP_H_ -#define _TUSB_MSC_APP_H_ - -#include -#include - -#include "boards/board.h" -#include "tusb.h" - - -#ifdef __cplusplus - extern "C" { -#endif - - -void msc_app_init(void); -OSAL_TASK_FUNCTION( msc_app_task ) (void* p_task_para); - - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_MSC_APP_H_ */ - -/** @} */ +/**************************************************************************/ +/*! + @file msc_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_APP_H_ +#define _TUSB_MSC_APP_H_ + +#include +#include + +#include "boards/board.h" +#include "tusb.h" + + +#ifdef __cplusplus + extern "C" { +#endif + +#if TUSB_CFG_HOST_MSC + +void msc_app_init(void); +OSAL_TASK_FUNCTION( msc_app_task ) (void* p_task_para); + +#else + +#define msc_app_init() +#define msc_app_task(x) + +#endif + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_MSC_APP_H_ */ + +/** @} */ diff --git a/demos/host/src/rndis_app.c b/demos/host/src/rndis_app.c index 9b75a3c3..f77df8b9 100644 --- a/demos/host/src/rndis_app.c +++ b/demos/host/src/rndis_app.c @@ -1,89 +1,79 @@ -/**************************************************************************/ -/*! - @file rndis_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_app.h" - -#if TUSB_CFG_OS != TUSB_OS_NONE -#include "app_os_prio.h" -#endif - -#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_app_init(void) -{ - -} - -OSAL_TASK_FUNCTION( rndis_app_task ) (void* p_task_para) -{ - OSAL_TASK_LOOP_BEGIN - OSAL_TASK_LOOP_END -} - -#else - -// dummy implementation to remove #ifdef in main.c -void rndis_app_init(void) { } -OSAL_TASK_FUNCTION( rndis_app_task ) (void* p_task_para) -{ - OSAL_TASK_LOOP_BEGIN - OSAL_TASK_LOOP_END -} - -#endif +/**************************************************************************/ +/*! + @file rndis_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_app.h" + +#if TUSB_CFG_OS != TUSB_OS_NONE +#include "app_os_prio.h" +#endif + +#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_app_init(void) +{ + +} + +OSAL_TASK_FUNCTION( rndis_app_task ) (void* p_task_para) +{ + OSAL_TASK_LOOP_BEGIN + OSAL_TASK_LOOP_END +} + +#endif diff --git a/demos/host/src/rndis_app.h b/demos/host/src/rndis_app.h index c9841463..d30ca899 100644 --- a/demos/host/src/rndis_app.h +++ b/demos/host/src/rndis_app.h @@ -1,65 +1,75 @@ -/**************************************************************************/ -/*! - @file rndis_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_APP_H_ -#define _TUSB_RNDIS_APP_H_ - -#include "boards/board.h" -#include "tusb.h" - -#ifdef __cplusplus - extern "C" { -#endif - -void rndis_app_init(void); -OSAL_TASK_FUNCTION( rndis_app_task ) (void* p_task_para); - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_RNDIS_APP_H_ */ - -/** @} */ +/**************************************************************************/ +/*! + @file rndis_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_APP_H_ +#define _TUSB_RNDIS_APP_H_ + +#include "boards/board.h" +#include "tusb.h" + +#ifdef __cplusplus + extern "C" { +#endif + +#if TUSB_CFG_HOST_CDC && TUSB_CFG_HOST_CDC_RNDIS + +void rndis_app_init(void); +OSAL_TASK_FUNCTION( rndis_app_task ) (void* p_task_para); + +#else + +#define rndis_app_init() +#define rndis_app_task(x) + +#endif + + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_RNDIS_APP_H_ */ + +/** @} */ diff --git a/demos/host/src/tusb_config.h b/demos/host/src/tusb_config.h index 3b69dffa..6c1c8268 100644 --- a/demos/host/src/tusb_config.h +++ b/demos/host/src/tusb_config.h @@ -1,129 +1,129 @@ -/**************************************************************************/ -/*! - @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. -*/ -/**************************************************************************/ - -/** \file - * \brief TBD - * - * \note TBD - */ - -/** \ingroup TBD - * \defgroup TBD - * \brief TBD - * - * @{ - */ - -#ifndef _TUSB_TUSB_CONFIG_H_ -#define _TUSB_TUSB_CONFIG_H_ - -#ifdef __cplusplus - extern "C" { -#endif - -//--------------------------------------------------------------------+ -// CONTROLLER CONFIGURATION -//--------------------------------------------------------------------+ -#define TUSB_CFG_CONTROLLER0_MODE (TUSB_MODE_HOST) -#define TUSB_CFG_CONTROLLER1_MODE (TUSB_MODE_NONE) - -//--------------------------------------------------------------------+ -// HOST CONFIGURATION -//--------------------------------------------------------------------+ -#define TUSB_CFG_HOST_DEVICE_MAX 3 -#define TUSB_CFG_CONFIGURATION_MAX 1 - -//------------- USBD -------------// -#define TUSB_CFG_HOST_ENUM_BUFFER_SIZE 255 - -//------------- 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 -#define TUSB_CFG_HOST_MSC 1 -#define TUSB_CFG_HOST_CDC 0 -#define TUSB_CFG_HOST_CDC_RNDIS 0 - -//--------------------------------------------------------------------+ -// DEVICE CONFIGURATION -//--------------------------------------------------------------------+ -//#define TUSB_CFG_DEVICE - -//------------- CORE/CONTROLLER -------------// - -//------------- CLASS -------------// -//#define TUSB_CFG_DEVICE_CDC -//#define TUSB_CFG_DEVICE_HID_KEYBOARD 1 -//#define TUSB_CFG_DEVICE_HID_MOUSE 1 - -//--------------------------------------------------------------------+ -// COMMON CONFIGURATION -//--------------------------------------------------------------------+ - -#define TUSB_CFG_DEBUG 3 - -//#define TUSB_CFG_OS TUSB_OS_NONE // defined using eclipse build -//#define TUSB_CFG_OS_TASK_PRIO - -#define TUSB_CFG_OS_TICKS_PER_SECOND 1000 - -#ifdef __CODE_RED // make use of code red's support for ram region macros - #if (MCU == MCU_LPC11UXX) || (MCU == MCU_LPC13UXX) - #define TUSB_RAM_SECTION ".data.$RAM2" - #elif (MCU == MCU_LPC43XX) - #define TUSB_RAM_SECTION ".data.$RAM3" - #endif - - #define TUSB_CFG_ATTR_USBRAM __attribute__ ((section(TUSB_RAM_SECTION))) -#elif defined __CC_ARM // Compiled with Keil armcc - #define TUSB_CFG_ATTR_USBRAM -#elif __ICCARM__ // compiled with IAR - #define TUSB_CFG_ATTR_USBRAM @ ".ahb_sram1" -#else - #error compiler not specified -#endif - - -#ifdef __cplusplus - } -#endif - -#endif /* _TUSB_TUSB_CONFIG_H_ */ - -/** @} */ +/**************************************************************************/ +/*! + @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. +*/ +/**************************************************************************/ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_TUSB_CONFIG_H_ +#define _TUSB_TUSB_CONFIG_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//--------------------------------------------------------------------+ +// CONTROLLER CONFIGURATION +//--------------------------------------------------------------------+ +#define TUSB_CFG_CONTROLLER0_MODE (TUSB_MODE_HOST) +#define TUSB_CFG_CONTROLLER1_MODE (TUSB_MODE_NONE) + +//--------------------------------------------------------------------+ +// HOST CONFIGURATION +//--------------------------------------------------------------------+ +#define TUSB_CFG_HOST_DEVICE_MAX 3 +#define TUSB_CFG_CONFIGURATION_MAX 1 + +//------------- USBD -------------// +#define TUSB_CFG_HOST_ENUM_BUFFER_SIZE 255 + +//------------- CLASS -------------// +#define TUSB_CFG_HOST_HUB 1 +#define TUSB_CFG_HOST_HID_KEYBOARD 1 +#define TUSB_CFG_HOST_HID_MOUSE 0 +#define TUSB_CFG_HOST_HID_GENERIC 0 +#define TUSB_CFG_HOST_MSC 1 +#define TUSB_CFG_HOST_CDC 0 +#define TUSB_CFG_HOST_CDC_RNDIS 0 + +//--------------------------------------------------------------------+ +// DEVICE CONFIGURATION +//--------------------------------------------------------------------+ +//#define TUSB_CFG_DEVICE + +//------------- CORE/CONTROLLER -------------// + +//------------- CLASS -------------// +//#define TUSB_CFG_DEVICE_CDC +//#define TUSB_CFG_DEVICE_HID_KEYBOARD 1 +//#define TUSB_CFG_DEVICE_HID_MOUSE 1 + +//--------------------------------------------------------------------+ +// COMMON CONFIGURATION +//--------------------------------------------------------------------+ + +#define TUSB_CFG_DEBUG 3 + +//#define TUSB_CFG_OS TUSB_OS_NONE // defined using eclipse build +//#define TUSB_CFG_OS_TASK_PRIO + +#define TUSB_CFG_OS_TICKS_PER_SECOND 1000 + +#ifdef __CODE_RED // make use of code red's support for ram region macros + #if (MCU == MCU_LPC11UXX) || (MCU == MCU_LPC13UXX) + #define TUSB_RAM_SECTION ".data.$RAM2" + #elif (MCU == MCU_LPC43XX) + #define TUSB_RAM_SECTION ".data.$RAM3" + #endif + + #define TUSB_CFG_ATTR_USBRAM __attribute__ ((section(TUSB_RAM_SECTION))) +#elif defined __CC_ARM // Compiled with Keil armcc + #define TUSB_CFG_ATTR_USBRAM +#elif __ICCARM__ // compiled with IAR + #define TUSB_CFG_ATTR_USBRAM @ ".ahb_sram1" +#else + #error compiler not specified +#endif + + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_TUSB_CONFIG_H_ */ + +/** @} */ diff --git a/tinyusb/common/errors.c b/tinyusb/common/errors.c index 782d7be9..00fc5784 100644 --- a/tinyusb/common/errors.c +++ b/tinyusb/common/errors.c @@ -1,49 +1,48 @@ -/**************************************************************************/ -/*! - @file errors.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 "errors.h" - -#if TUSB_CFG_DEBUG == 3 - -char const* const TUSB_ErrorStr[TUSB_ERROR_COUNT] = -{ - ERROR_TABLE(ERROR_STRING) - 0 -}; - -#endif +/**************************************************************************/ +/*! + @file errors.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 "errors.h" + +#if TUSB_CFG_DEBUG == 3 + +char const* const TUSB_ErrorStr[TUSB_ERROR_COUNT] = +{ + ERROR_TABLE(ERROR_STRING) +}; + +#endif