Merge pull request #25 from hathach/devlocal

remove OSAL_TASK_DEF, osal_task_create
This commit is contained in:
hathach 2018-12-13 15:28:04 +07:00 committed by GitHub
commit 27208ad2fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 135 additions and 2289 deletions

View File

@ -1,6 +1,6 @@
# tinyusb
# TinyUSB
tinyusb is an cross-platform open-source USB Host/Device stack for embedded system.
TinyUSB is an cross-platform open-source USB Host/Device stack for embedded system.
![tinyusb](https://user-images.githubusercontent.com/249515/49858616-f60c9700-fe27-11e8-8627-e76936352ff7.png)

View File

@ -20,7 +20,6 @@
#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_TUD_TASK_PRIO ///< If \ref CFG_TUSB_OS is configured to use a real RTOS (other than OPT_OS_NONE). This determines the priority of the usb stack task.
//--------------------------------------------------------------------+
// HOST CONFIGURATION

View File

@ -37,11 +37,11 @@ It is relatively simple to incorporate tinyusb to your (existing) project
1. Copy or `git submodule` this repo into your project in a subfolder. Let's say it is *your_project/tinyusb*
2. Add all the .c in the src 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 CFG_TUSB_MCU, CFG_TUSB_OS, CFG_TUD_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 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.
8. If you don't use any RTOSes at all, you need to continuously and/or periodically call tusb_task() function. Most of the callbacks and functionality are handled and invoke within the call of that task runner.
8. If you don't use any RTOSes at all, you need to continuously and/or periodically call tud_task()/tuh_task() function. Most of the callbacks and functionality are handled and invoke within the call of that task runner.
~~~{.c}
int main(void)
@ -53,7 +53,8 @@ int main(void)
{
your_application_code();
tusb_task(); // handle tinyusb event, task etc ...
tud_task(); // tinyusb device task
tuh_task(); // tinyusb host task
}
}
~~~

View File

@ -61,7 +61,7 @@ The OPT_OS_NONE option is the only option which requires an MCU specific functio
### Device API
After the USB device is setup, the USB device code works by processing events on the main thread (by calling `tusb_task`). These events are queued by the USB interrupt handler. So, there are three parts to the device low-level API: device setup, endpoint setup and interrupt processing.
After the USB device is setup, the USB device code works by processing events on the main thread (by calling `tud_task`). These events are queued by the USB interrupt handler. So, there are three parts to the device low-level API: device setup, endpoint setup and interrupt processing.
All of the code for the low-level device API is in `src/portable/<vendor>/<chip family>/dcd_<chip family>.c`.
@ -164,4 +164,4 @@ At this point you should have everything working! ;-) Of course, you may not wri
Use [WireShark](https://www.wireshark.org/) or [a Beagle](https://www.totalphase.com/protocols/usb/) to sniff the USB traffic. When things aren't working its likely very early in the USB enumeration process. Figuring out where can help clue in where the issue is. For example:
* If the host sends a SETUP packet and its not ACKed then your USB peripheral probably isn't started correctly.
* If the peripheral is started correctly but it still didn't work, then verify your usb clock is correct. (You did output a PWM based on it right? ;-) )
* If the SETUP packet is ACKed but nothing is sent back then you interrupt handler isn't queueing the setup packet correctly. (Also, if you are using your own code instead of an example `tusb_task` may not be called.) If thats OK, the `dcd_xfer_complete` may not be setting up the next transaction correctly.
* If the SETUP packet is ACKed but nothing is sent back then you interrupt handler isn't queueing the setup packet correctly. (Also, if you are using your own code instead of an example `tud_task` may not be called.) If thats OK, the `dcd_xfer_complete` may not be setting up the next transaction correctly.

View File

@ -46,7 +46,6 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
void print_greeting(void);
void led_blinking_task(void);
extern void virtual_com_task(void);
@ -56,13 +55,13 @@ extern void usb_hid_task(void);
int main(void)
{
board_init();
print_greeting();
tusb_init();
while (1)
{
tusb_task();
// tinyusb device task
tud_task();
led_blinking_task();
@ -84,9 +83,9 @@ int main(void)
#if CFG_TUD_CDC
void virtual_com_task(void)
{
// connected and there are data available
if ( tud_cdc_connected() )
{
// connected and there are data available
if ( tud_cdc_available() )
{
uint8_t buf[64];
@ -98,11 +97,7 @@ void virtual_com_task(void)
{
tud_cdc_write_char(buf[i]);
if ( buf[i] == '\r' )
{
tud_cdc_write_char('\n');
tud_cdc_write_str("tinyusb cdc: ");
}
if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
}
tud_cdc_write_flush();
@ -117,8 +112,8 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
// connected
if ( dtr && rts )
{
// print greeting
tud_cdc_write_str("tinyusb cdc: ");
// print initial message when connected
tud_cdc_write_str("\r\nTinyUSB CDC MSC HID device example\r\n");
}
}
#endif
@ -213,28 +208,3 @@ void led_blinking_task(void)
board_led_control(led_state);
led_state = 1 - led_state; // toggle
}
//--------------------------------------------------------------------+
// HELPER FUNCTION
//--------------------------------------------------------------------+
void print_greeting(void)
{
char const * const rtos_name[] =
{
[OPT_OS_NONE] = "None",
[OPT_OS_FREERTOS] = "FreeRTOS",
};
printf("\n--------------------------------------------------------------------\n");
printf("- Device Demo (a tinyusb example)\n");
printf("- if you find any bugs or get any questions, feel free to file an\n");
printf("- issue at https://github.com/hathach/tinyusb\n");
printf("--------------------------------------------------------------------\n\n");
printf("This DEVICE demo is configured to support:");
printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
if (CFG_TUD_CDC ) puts(" - Communication Device Class");
if (CFG_TUD_MSC ) puts(" - Mass Storage");
if (CFG_TUD_HID_KEYBOARD ) puts(" - HID Keyboard");
if (CFG_TUD_HID_MOUSE ) puts(" - HID Mouse");
}

View File

@ -18,11 +18,12 @@
arm_target_debug_interface_type="ADIv5"
arm_target_device_name="nRF52840_xxAA"
arm_target_interface_type="SWD"
build_treat_warnings_as_errors="Yes"
build_treat_warnings_as_errors="No"
c_preprocessor_definitions="NRF52840_XXAA;__nRF_FAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_PCA10056;CFG_TUSB_MCU=OPT_MCU_NRF5X"
c_user_include_directories="./;../../src;$(rootDir)/hw/cmsis/Include;$(rootDir)/hw;$(rootDir)/src;$(nrfxDir)/..;$(nrfxDir);$(nrfxDir)/mdk;$(nrfxDir)/hal;$(nrfxDir)/drivers/include;$(freertosDir)/Source/include;$(freertosDir)/Source/portable/GCC/ARM_CM4F"
debug_register_definition_file="nrf52840_Registers.xml"
debug_target_connection="J-Link"
gcc_enable_all_warnings="Yes"
gcc_entry_point="Reset_Handler"
link_use_linker_script_file="No"
linker_memory_map_file="nRF52840_xxAA_MemoryMap.xml"

View File

@ -59,14 +59,13 @@
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
void print_greeting(void);
void led_blinky_cb(TimerHandle_t xTimer);
void usb_device_task(void* param);
/*------------- MAIN -------------*/
int main(void)
{
board_init();
print_greeting();
// soft timer for blinky
TimerHandle_t tm_hdl = xTimerCreate(NULL, pdMS_TO_TICKS(1000), true, NULL, led_blinky_cb);
@ -74,10 +73,13 @@ int main(void)
tusb_init();
// Create a task for tinyusb device stack
xTaskCreate( usb_device_task, "usbd", 150, NULL, configMAX_PRIORITIES-1, NULL);
// Create task
#if CFG_TUD_CDC
extern void cdc_task(void* params);
xTaskCreate( cdc_task, "cdc", 256, NULL, 2, NULL);
xTaskCreate( cdc_task, "cdc", 256, NULL, configMAX_PRIORITIES-2, NULL);
#endif
#if CFG_TUD_HID
@ -90,6 +92,20 @@ int main(void)
return 0;
}
// USB Device Driver task
// This top level thread process all usb events and invoke callbacks
void usb_device_task(void* param)
{
(void) param;
// RTOS forever loop
while (1)
{
// tinyusb device task
tud_task();
}
}
//--------------------------------------------------------------------+
// USB CDC
//--------------------------------------------------------------------+
@ -98,11 +114,12 @@ void cdc_task(void* params)
{
(void) params;
// RTOS forever loop
while ( 1 )
{
// connected and there are data available
if ( tud_cdc_connected() )
{
// connected and there are data available
if ( tud_cdc_available() )
{
uint8_t buf[64];
@ -110,10 +127,15 @@ void cdc_task(void* params)
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
tud_cdc_write(buf, count);
}
for(uint32_t i=0; i<count; i++)
{
tud_cdc_write_char(buf[i]);
tud_cdc_write_flush();
if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
}
tud_cdc_write_flush();
}
}
}
}
@ -125,8 +147,8 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
// connected
if ( dtr && rts )
{
// print greeting
tud_cdc_write_str("tinyusb usb cdc\n");
// print initial message when connected
tud_cdc_write_str("\r\nTinyUSB CDC MSC HID device with FreeRTOS example\r\n");
}
}
#endif
@ -206,6 +228,7 @@ void tud_umount_cb(void)
void tud_cdc_rx_cb(uint8_t itf)
{
(void) itf;
}
//--------------------------------------------------------------------+
@ -219,28 +242,3 @@ void led_blinky_cb(TimerHandle_t xTimer)
board_led_control(led_state);
led_state = 1 - led_state; // toggle
}
//--------------------------------------------------------------------+
// HELPER FUNCTION
//--------------------------------------------------------------------+
void print_greeting(void)
{
char const * const rtos_name[] =
{
[OPT_OS_NONE] = "None",
[OPT_OS_FREERTOS] = "FreeRTOS",
};
printf("\n--------------------------------------------------------------------\n");
printf("- Device Demo (a tinyusb example)\n");
printf("- if you find any bugs or get any questions, feel free to file an\n");
printf("- issue at https://github.com/hathach/tinyusb\n");
printf("--------------------------------------------------------------------\n\n");
printf("This DEVICE demo is configured to support:");
printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
if (CFG_TUD_CDC ) puts(" - Communication Device Class");
if (CFG_TUD_MSC ) puts(" - Mass Storage");
if (CFG_TUD_HID_KEYBOARD ) puts(" - HID Keyboard");
if (CFG_TUD_HID_MOUSE ) puts(" - HID Mouse");
}

View File

@ -53,14 +53,8 @@
#endif
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
#define CFG_TUSB_DEBUG 2
/*------------- RTOS -------------*/
#define CFG_TUSB_OS OPT_OS_FREERTOS
#define CFG_TUD_TASK_PRIO (configMAX_PRIORITIES-1)
//#define CFG_TUD_TASK_QUEUE_SZ 16
//#define CFG_TUD_TASK_STACK_SZ 150
#define CFG_TUSB_DEBUG 2
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
* Tinyusb use follows macros to declare transferring memory so that they can be put

View File

@ -62,7 +62,8 @@ int main(void)
while (1)
{
tusb_task();
// tinyusb host task
tuh_task();
led_blinking_task();

View File

@ -80,14 +80,14 @@
// DEVICE CONFIGURATION
//--------------------------------------------------------------------
#define CFG_TUH_HUB 1
#define CFG_TUH_CDC 1
#define CFG_TUH_HID_KEYBOARD 0
#define CFG_TUH_HID_MOUSE 0
#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported)
#define CFG_TUH_MSC 0
#define CFG_TUH_HUB 1
#define CFG_TUH_CDC 1
#define CFG_TUH_HID_KEYBOARD 0
#define CFG_TUH_HID_MOUSE 0
#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported)
#define CFG_TUH_MSC 0
#define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports
#define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports
//------------- CLASS -------------//
#define CFG_TUD_CDC 0

View File

@ -1,81 +0,0 @@
# Device Demos #
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**
- [Prerequisites](#prerequisites)
- [Human Interface Device (HID)](#human-interface-device-hid)
- [Keyboard](#keyboard)
- [Mouse](#mouse)
- [Mass Storage Class Device (MSC)](#mass-storage-class-device-msc)
- [Communication Class Device (CDC)](#communication-class-device-cdc)
- [Serial](#serial)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
device application code is store at *demos/device/src* containing
File | Description
----- | -------------
main.c | Initialization (board, stack) and a RTOS task scheduler call or just simple a indefinite loop for non OS to invoke class-specific tasks.
tusb_config.h | tinyusb stack configuration.
tusb_descriptors(c,h) | contains all the required usb descriptors for all combination of supported classes. And definition of stack-required variable *tusbd_descriptor_pointers*.
app_os_prio.h | RTOS task priority definitions
Class-specific | Application files for supported classes.
The demo will start with the greeting of enabled classes and chosen RTOS then start to blink an LED at 1 Hz.
## Prerequisites ##
In order to run application demo, you would need
- A [supported development board](../../boards/readme.md) with at least a button for mouse, keyboard demo.
- A supported toolchain: LPCXpresso, Keil, IAR.
- A decent terminal such as [Tera Term](http://en.sourceforge.jp/projects/ttssh2/) for CDC Serial.
## Human Interface Device (HID)
### Keyboard
After the board get enumerated successfully, you can try to press some buttons while opening notepad. It should get some characters out accordingly. In addition, when you press Capslock or Numlock key on your own pc's keyboard, the LED will blink faster twice. This demonstrates that keyboard application can receive Set Report via control pipe.
Notes: The very same buttons may also used by Mouse application. You can get the mouse moving and character, should you enable both.
### Mouse
After the board get enumerated successfully, you can try to press some buttons. The mouse's cursor should move accordingly.
Notes: The very same buttons may also used by Keyboard application. You can get the mouse moving and character, should you enable both.
## Mass Storage Class Device (MSC)
This class is very simple, as soon as the demo work, you could open the demo drive. Inside, you should find a *README.TXT* file which contains a few lines of descriptions. The demo drive's format is FAT12 and only has 8KB, which is the smallest possible to work with most host OS (Windows/Linux).
Notes: The entire disk contents ( 8KB ) is located on MCU's SRAM if possible (such as lpc43xx, lpc175x_6x). For MCU (lpc11u, lpc13u) that cannot afford that, the contents is instead on internal Flash which make the demo drive is read-only.
## Communication Class Device (CDC)
CDC has several subclass, currently tinyusb only supports the popular *Abstract Control Model (ACM)*
### Serial
The virtual COM is also as easy as MSC. Except that we need to "install" driver for the first plug if your host OS is Windows, Linux should be able to work right away.
**Install Driver for Windows**
Actually Windows already has the needed driver to operate with virtual serial of CDC-ACM, the *usbser*. However, since it also use Abstract Control Model for other purposes, it requires us to tell exactly which VendorID/ProductID comibination should be used as a virtual serial. The demo's src folder includes *WinCDCdriver.inf* to do just that.
Firstly open *Device Manager*, we should find our board under "Other devices", right click on it and choose "Update Driver Software..."
![Serial Install Driver](http://docs.tinyusb.org/images/demo_serial_driver.png)
Then choose "Browse my computer for driver software" then navigate to the device demo's *src* and click next. Since I am nowhere near a known publisher to Microsoft, it will warn you with a scary dialog. With all your trust in me, click next and hope that nothing harmful will ever happen and we are done with the driver.
![Serial Install Driver](http://docs.tinyusb.org/images/demo_serial_driver2.png)
**Testing Demo**
Connect to the "tinyusb Serial Port" with your terminal application, and start to type. You should get echo back as the CDC serial application demo is written to transmit what it received. Notes: if Windows/terminal don't realize serial port (especially if you unplugged device without disconnect previously), simply unplug and plug device again. This is a "known feature" of Windows's usbser.
![Serial Connect](http://docs.tinyusb.org/images/demo_cdc_connect.png)

View File

@ -1,106 +0,0 @@
;************************************************************
; Windows USB CDC ACM Setup File
; Copyright (c) 2000 Microsoft Corporation
[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%MFGNAME%
LayoutFile=layout.inf
CatalogFile=%MFGFILENAME%.cat
DriverVer=11/15/2007,5.1.2600.0
[Manufacturer]
%MFGNAME%=DeviceList, NTamd64
[DestinationDirs]
DefaultDestDir=12
;------------------------------------------------------------------------------
; Windows 2000/XP/Vista-32bit Sections
;------------------------------------------------------------------------------
[DriverInstall.nt]
include=mdmcpq.inf
CopyFiles=DriverCopyFiles.nt
AddReg=DriverInstall.nt.AddReg
[DriverCopyFiles.nt]
usbser.sys,,,0x20
[DriverInstall.nt.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
[DriverInstall.nt.Services]
AddService=usbser, 0x00000002, DriverService.nt
[DriverService.nt]
DisplayName=%SERVICE%
ServiceType=1
StartType=3
ErrorControl=1
ServiceBinary=%12%\%DRIVERFILENAME%.sys
;------------------------------------------------------------------------------
; Vista-64bit Sections
;------------------------------------------------------------------------------
[DriverInstall.NTamd64]
include=mdmcpq.inf
CopyFiles=DriverCopyFiles.NTamd64
AddReg=DriverInstall.NTamd64.AddReg
[DriverCopyFiles.NTamd64]
%DRIVERFILENAME%.sys,,,0x20
[DriverInstall.NTamd64.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,%DRIVERFILENAME%.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
[DriverInstall.NTamd64.Services]
AddService=usbser, 0x00000002, DriverService.NTamd64
[DriverService.NTamd64]
DisplayName=%SERVICE%
ServiceType=1
StartType=3
ErrorControl=1
ServiceBinary=%12%\%DRIVERFILENAME%.sys
;------------------------------------------------------------------------------
; Vendor and Product ID Definitions
;------------------------------------------------------------------------------
; When developing your USB device, the VID and PID used in the PC side
; application program and the firmware on the microcontroller must match.
; Modify the below line to use your VID and PID. Use the format as shown below.
; Note: One INF file can be used for multiple devices with different VID and PIDs.
; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line.
;------------------------------------------------------------------------------
[SourceDisksFiles]
[SourceDisksNames]
[DeviceList]
%DESCRIPTION%=DriverInstall, USB\VID_CAFE&PID_4001&MI_00, USB\VID_CAFE&PID_4003&MI_00, USB\VID_CAFE&PID_4005&MI_00, USB\VID_CAFE&PID_4007&MI_00, USB\VID_CAFE&PID_4009&MI_00, USB\VID_CAFE&PID_400b&MI_00, USB\VID_CAFE&PID_400d&MI_00, USB\VID_CAFE&PID_400f&MI_00, USB\VID_CAFE&PID_4011&MI_00, USB\VID_CAFE&PID_4013&MI_00, USB\VID_CAFE&PID_4015&MI_00, USB\VID_CAFE&PID_4017&MI_00, USB\VID_CAFE&PID_4019&MI_00, USB\VID_CAFE&PID_401b&MI_00, USB\VID_CAFE&PID_401d&MI_00, USB\VID_CAFE&PID_401f&MI_00, USB\VID_CAFE&PID_4021&MI_00, USB\VID_CAFE&PID_4023&MI_00, USB\VID_CAFE&PID_4025&MI_00, USB\VID_CAFE&PID_4027&MI_00, USB\VID_CAFE&PID_4029&MI_00, USB\VID_CAFE&PID_402b&MI_00, USB\VID_CAFE&PID_402d&MI_00, USB\VID_CAFE&PID_402f&MI_00, USB\VID_CAFE&PID_4031&MI_00, USB\VID_CAFE&PID_4033&MI_00, USB\VID_CAFE&PID_4035&MI_00, USB\VID_CAFE&PID_4037&MI_00, USB\VID_CAFE&PID_4039&MI_00, USB\VID_CAFE&PID_403b&MI_00, USB\VID_CAFE&PID_403d&MI_00, USB\VID_CAFE&PID_403f&MI_00
[DeviceList.NTamd64]
%DESCRIPTION%=DriverInstall, USB\VID_CAFE&PID_4001&MI_00, USB\VID_CAFE&PID_4003&MI_00, USB\VID_CAFE&PID_4005&MI_00, USB\VID_CAFE&PID_4007&MI_00, USB\VID_CAFE&PID_4009&MI_00, USB\VID_CAFE&PID_400b&MI_00, USB\VID_CAFE&PID_400d&MI_00, USB\VID_CAFE&PID_400f&MI_00, USB\VID_CAFE&PID_4011&MI_00, USB\VID_CAFE&PID_4013&MI_00, USB\VID_CAFE&PID_4015&MI_00, USB\VID_CAFE&PID_4017&MI_00, USB\VID_CAFE&PID_4019&MI_00, USB\VID_CAFE&PID_401b&MI_00, USB\VID_CAFE&PID_401d&MI_00, USB\VID_CAFE&PID_401f&MI_00, USB\VID_CAFE&PID_4021&MI_00, USB\VID_CAFE&PID_4023&MI_00, USB\VID_CAFE&PID_4025&MI_00, USB\VID_CAFE&PID_4027&MI_00, USB\VID_CAFE&PID_4029&MI_00, USB\VID_CAFE&PID_402b&MI_00, USB\VID_CAFE&PID_402d&MI_00, USB\VID_CAFE&PID_402f&MI_00, USB\VID_CAFE&PID_4031&MI_00, USB\VID_CAFE&PID_4033&MI_00, USB\VID_CAFE&PID_4035&MI_00, USB\VID_CAFE&PID_4037&MI_00, USB\VID_CAFE&PID_4039&MI_00, USB\VID_CAFE&PID_403b&MI_00, USB\VID_CAFE&PID_403d&MI_00, USB\VID_CAFE&PID_403f&MI_00
;------------------------------------------------------------------------------
; String Definitions
;------------------------------------------------------------------------------
;Modify these strings to customize your device
;------------------------------------------------------------------------------
[Strings]
MFGFILENAME="CDC_vista"
DRIVERFILENAME ="usbser"
MFGNAME="tinyusb.org"
INSTDISK="tinyusb CDC driver"
DESCRIPTION="tinyusb Serial Port"
SERVICE="USB RS-232 Emulation Driver"

View File

@ -1,71 +0,0 @@
/**************************************************************************/
/*!
@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.
*/
/**************************************************************************/
#ifndef _TUSB_APP_OS_PRIO_H_
#define _TUSB_APP_OS_PRIO_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "tusb.h"
#if CFG_TUSB_OS == OPT_OS_NONE
#define LOWER_PRIO(x) 0 // does not matter
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
#define LOWER_PRIO(x) ((x)-1) // freeRTOS lower number --> lower priority
#else
#error Priority is not configured for this RTOS
#endif
enum {
STANDARD_APP_TASK_PRIO = LOWER_PRIO(CFG_TUD_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_ */

View File

@ -1,111 +0,0 @@
/**************************************************************************/
/*!
@file cdc_device_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_device_app.h"
#if CFG_TUD_CDC
#include "common/tusb_fifo.h" // TODO refractor
#include "app_os_prio.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
enum { SERIAL_BUFFER_SIZE = 64 };
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
void cdc_serial_app_task(void* param);
OSAL_TASK_DEF(cdc_task_def, "blinky", cdc_serial_app_task, CDC_SERIAL_APP_TASK_PRIO, 128);
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
void cdc_serial_app_mount(uint8_t rhport)
{
}
void cdc_serial_app_umount(uint8_t rhport)
{
}
void tud_cdc_rx_cb(uint8_t itf)
{
}
//--------------------------------------------------------------------+
// APPLICATION CODE
//--------------------------------------------------------------------+
void cdc_serial_app_init(void)
{
osal_task_create(&cdc_task_def);
}
tusb_error_t cdc_serial_subtask(void);
void cdc_serial_app_task(void* param)
{
(void) param;
OSAL_TASK_BEGIN
cdc_serial_subtask();
OSAL_TASK_END
}
tusb_error_t cdc_serial_subtask(void)
{
OSAL_SUBTASK_BEGIN
if ( tud_mounted() && tud_cdc_available() )
{
uint8_t buf[64];
// read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
tud_cdc_write(buf, count);
}
OSAL_SUBTASK_END
}
#endif

View File

@ -1,80 +0,0 @@
/**************************************************************************/
/*!
@file cdc_device_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_CDCD_DEVICE_APP_H_
#define _TUSB_CDCD_DEVICE_APP_H_
#include "bsp/board.h"
#include "tusb.h"
#ifdef __cplusplus
extern "C" {
#endif
#if CFG_TUD_CDC
void cdc_serial_app_init(void);
void cdc_serial_app_task(void* param);
void cdc_serial_app_mount(uint8_t rhport);
void cdc_serial_app_umount(uint8_t rhport);
#else
#define cdc_serial_app_init()
#define cdc_serial_app_task(x)
#define cdc_serial_app_mount(x)
#define cdc_serial_app_umount(x)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_CDCD_DEVICE_APP_H_ */
/** @} */

View File

@ -1,153 +0,0 @@
/**************************************************************************/
/*!
@file keyboard_device_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 "keyboard_device_app.h"
#if CFG_TUD_HID_KEYBOARD
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
#include "app_os_prio.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION hid_keyboard_report_t keyboard_report;
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
void keyboard_app_mount(uint8_t rhport)
{
}
void keyboard_app_umount(uint8_t rhport)
{
}
void tud_hid_keyboard_cb(uint8_t rhport, xfer_result_t event, uint32_t xferred_bytes)
{
switch(event)
{
case XFER_RESULT_SUCCESS:
case XFER_RESULT_FAILED:
case XFER_RESULT_STALLED:
default: break;
}
}
uint16_t tud_hid_keyboard_get_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
{
// get other than input report is not supported by this keyboard demo
if ( report_type != HID_REPORT_TYPE_INPUT ) return 0;
memcpy(buffer, &keyboard_report, reqlen);
return reqlen;
}
void tud_hid_keyboard_set_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
{
// set other than output report is not supported by this keyboard demo
if ( report_type != HID_REPORT_TYPE_OUTPUT ) return;
uint8_t kbd_led = buffer[0];
uint32_t interval_divider = 1; // each LED will reduce blinking interval by a half
if (kbd_led & KEYBOARD_LED_NUMLOCK ) interval_divider *= 2;
if (kbd_led & KEYBOARD_LED_CAPSLOCK ) interval_divider *= 2;
if (kbd_led & KEYBOARD_LED_SCROLLLOCK) interval_divider *= 2;
// TODO remove
extern void led_blinking_set_interval(uint32_t ms);
led_blinking_set_interval( 1000 / interval_divider);
}
//--------------------------------------------------------------------+
// APPLICATION CODE
//--------------------------------------------------------------------+
void keyboard_app_init(void)
{
osal_task_create(keyboard_app_task, "kbd", 128, NULL, KEYBOARD_APP_TASK_PRIO);
}
tusb_error_t keyboard_device_subtask(void);
void keyboard_app_task(void* param)
{
(void) param;
OSAL_TASK_BEGIN
keyboard_device_subtask();
OSAL_TASK_END
}
tusb_error_t keyboard_device_subtask(void)
{
OSAL_SUBTASK_BEGIN
osal_task_delay(50);
if ( tud_mounted() && tud_hid_keyboard_ready(0) )
{
static uint32_t button_mask = 0;
uint32_t new_button_mask = board_buttons();
//------------- button pressed -------------//
if (button_mask != new_button_mask)
{
button_mask = new_button_mask;
for (uint8_t i=0; i<6; i++)
{ // demo support up to 6 buttons, button0 = 'a', button1 = 'b', etc ...
keyboard_report.keycode[i] = BIT_TEST_(button_mask, i) ? (0x04+i) : 0;
}
tud_hid_keyboard_send(0, &keyboard_report );
}
}
OSAL_SUBTASK_END
}
#endif

View File

@ -1,79 +0,0 @@
/**************************************************************************/
/*!
@file keyboard_device_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_KEYBOARDD_DEVICE_APP_H_
#define _TUSB_KEYBOARDD_DEVICE_APP_H_
#include "bsp/board.h"
#include "tusb.h"
#ifdef __cplusplus
extern "C" {
#endif
#if CFG_TUD_HID_KEYBOARD
void keyboard_app_init(void);
void keyboard_app_task(void* param);
void keyboard_app_mount(uint8_t rhport);
void keyboard_app_umount(uint8_t rhport);
#else
#define keyboard_app_init()
#define keyboard_app_task(x)
#define keyboard_app_mount(x)
#define keyboard_app_umount(x)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_KEYBOARDD_DEVICE_APP_H_ */
/** @} */

View File

@ -1,205 +0,0 @@
/**************************************************************************/
/*!
@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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "bsp/board.h"
#include "app_os_prio.h"
#include "tusb.h"
#include "msc_device_app.h"
#include "keyboard_device_app.h"
#include "mouse_device_app.h"
#include "cdc_device_app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
void print_greeting(void);
void led_blinking_init(void);
void led_blinking_task(void* param);
#if CFG_TUSB_OS == OPT_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();
led_blinking_task(NULL);
msc_app_task(NULL);
keyboard_app_task(NULL);
mouse_app_task(NULL);
cdc_serial_app_task(NULL);
}
}
#endif
int main(void)
{
board_init();
print_greeting();
tusb_init();
//------------- application task init -------------//
led_blinking_init();
msc_app_init();
keyboard_app_init();
mouse_app_init();
cdc_serial_app_init();
//------------- start OS scheduler (never return) -------------//
#if CFG_TUSB_OS == OPT_OS_FREERTOS
vTaskStartScheduler();
#elif CFG_TUSB_OS == OPT_OS_NONE
os_none_start_scheduler();
#else
#error need to start RTOS schduler
#endif
return 0;
}
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
void tud_mount_cb(void)
{
uint8_t rhport = 0; // TODO remove
cdc_serial_app_mount(rhport);
keyboard_app_mount(rhport);
msc_app_mount(rhport);
}
void tud_umount_cb(void)
{
uint8_t rhport = 0; // TODO remove
cdc_serial_app_umount(rhport);
keyboard_app_umount(rhport);
msc_app_umount(rhport);
}
//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+
OSAL_TASK_DEF(blink_task_def, "blinky", led_blinking_task, LED_BLINKING_APP_TASK_PRIO, 128);
static uint32_t led_blink_interval_ms = 1000; // default is 1 second
void led_blinking_init(void)
{
led_blink_interval_ms = 1000;
osal_task_create(&blink_task_def);
}
void led_blinking_set_interval(uint32_t ms)
{
led_blink_interval_ms = ms;
}
tusb_error_t led_blinking_subtask(void);
void led_blinking_task(void* param)
{
(void) param;
OSAL_TASK_BEGIN
led_blinking_subtask();
OSAL_TASK_END
}
tusb_error_t led_blinking_subtask(void)
{
OSAL_SUBTASK_BEGIN
static bool led_state = false;
osal_task_delay(led_blink_interval_ms);
board_led_control(led_state);
led_state = 1 - led_state; // toggle
// uint32_t btn_mask;
// btn_mask = board_buttons();
//
// for(uint8_t i=0; i<32; i++)
// {
// if ( BIT_TEST_(btn_mask, i) ) printf("button %d is pressed\n", i);
// }
OSAL_SUBTASK_END
}
//--------------------------------------------------------------------+
// HELPER FUNCTION
//--------------------------------------------------------------------+
void print_greeting(void)
{
char const * const rtos_name[] =
{
[OPT_OS_NONE] = "None",
[OPT_OS_FREERTOS] = "FreeRTOS",
};
printf("\n\
--------------------------------------------------------------------\n\
- Device 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\n"
);
puts("This DEVICE demo is configured to support:");
printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
if (CFG_TUD_HID_MOUSE ) puts(" - HID Mouse");
if (CFG_TUD_HID_KEYBOARD ) puts(" - HID Keyboard");
if (CFG_TUD_MSC ) puts(" - Mass Storage");
if (CFG_TUD_CDC ) puts(" - Communication Device Class");
}

View File

@ -1,153 +0,0 @@
/**************************************************************************/
/*!
@file mouse_device_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 "mouse_device_app.h"
#if CFG_TUD_HID_MOUSE
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
#include "app_os_prio.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION hid_mouse_report_t mouse_report;
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
void mouse_app_mount(uint8_t rhport)
{
}
void mouse_app_umount(uint8_t rhport)
{
}
void tud_hid_mouse_cb(uint8_t rhport, xfer_result_t event, uint32_t xferred_bytes)
{
switch(event)
{
case XFER_RESULT_SUCCESS:
case XFER_RESULT_FAILED:
case XFER_RESULT_STALLED:
default: break;
}
}
uint16_t tud_hid_mouse_get_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
{
if ( report_type != HID_REPORT_TYPE_INPUT ) return 0; // not support other report type for this mouse demo
memcpy(buffer, &mouse_report, reqlen);
return reqlen;
}
//--------------------------------------------------------------------+
// APPLICATION CODE
//--------------------------------------------------------------------+
void mouse_app_init(void)
{
osal_task_create(mouse_app_task, "mouse", 128, NULL, MOUSE_APP_TASK_PRIO);
}
void mouse_app_subtask(void);
void mouse_app_task(void * param)
{
(void) param;
OSAL_TASK_BEGIN
mouse_app_subtask();
OSAL_TASK_END
}
void mouse_app_subtask(void)
{
OSAL_SUBTASK_BEGIN
osal_task_delay(20);
if ( tud_mounted() && !tud_hid_mouse_is_busy(0) )
{
static uint8_t prev_mouse_buttons = 0;
enum {
BUTTON_UP = 0, // map to button mask
BUTTON_DOWN = 1,
BUTTON_LEFT = 2,
BUTTON_RIGHT = 3,
BUTTON_CLICK_LEFT = 4,
BUTTON_CLICK_RIGHT = 5,
BUTTON_CLICK_MIDDLE = 6
};
enum { MOUSE_RESOLUTION = 5 };
uint32_t button_mask = board_buttons();
tu_memclr(&mouse_report, sizeof(hid_mouse_report_t));
if ( BIT_TEST_(button_mask, BUTTON_UP ) ) mouse_report.y = -MOUSE_RESOLUTION;
if ( BIT_TEST_(button_mask, BUTTON_DOWN ) ) mouse_report.y = MOUSE_RESOLUTION;
if ( BIT_TEST_(button_mask, BUTTON_LEFT ) ) mouse_report.x = -MOUSE_RESOLUTION;
if ( BIT_TEST_(button_mask, BUTTON_RIGHT ) ) mouse_report.x = MOUSE_RESOLUTION;
if ( BIT_TEST_(button_mask, BUTTON_CLICK_LEFT ) ) mouse_report.buttons |= MOUSE_BUTTON_LEFT;
if ( BIT_TEST_(button_mask, BUTTON_CLICK_RIGHT ) ) mouse_report.buttons |= MOUSE_BUTTON_RIGHT;
if ( BIT_TEST_(button_mask, BUTTON_CLICK_MIDDLE ) ) mouse_report.buttons |= MOUSE_BUTTON_MIDDLE;
if ( ! (prev_mouse_buttons == mouse_report.buttons && mouse_report.y == 0 && mouse_report.x == 0 && mouse_report.wheel == 0) )
{ // send report if clicked buttons are changed or there is any movement x, y, wheel
prev_mouse_buttons = mouse_report.buttons;
tud_hid_mouse_send(0, &mouse_report);
}
}
OSAL_SUBTASK_END
}
#endif

View File

@ -1,78 +0,0 @@
/**************************************************************************/
/*!
@file mouse_device_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_MOUSED_DEVICE_APP_H_
#define _TUSB_MOUSED_DEVICE_APP_H_
#include "bsp/board.h"
#include "tusb.h"
#ifdef __cplusplus
extern "C" {
#endif
#if CFG_TUD_HID_MOUSE
void mouse_app_init(void);
void mouse_app_task(void * param);
void mouse_app_mount(uint8_t rhport);
void mouse_app_umount(uint8_t rhport);
#else
#define mouse_app_init()
#define mouse_app_task(x)
#define mouse_app_mount(x)
#define mouse_app_umount(x)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_MOUSED_DEVICE_APP_H_ */
/** @} */

View File

@ -1,129 +0,0 @@
/**************************************************************************/
/*!
@file msc_device_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 "msc_device_app.h"
#if CFG_TUD_MSC
#include "app_os_prio.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// tinyusb callbacks
//--------------------------------------------------------------------+
void msc_app_mount(uint8_t rhport)
{
}
void msc_app_umount(uint8_t rhport)
{
}
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize)
{
// read10 & write10 has their own callback and MUST not be handled here
void const* ptr = NULL;
uint16_t len = 0;
// most scsi handled is input
bool in_xfer = true;
switch (scsi_cmd[0])
{
case SCSI_CMD_TEST_UNIT_READY:
// Command that host uses to check our readiness before sending other commands
len = 0;
break;
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
// Host is about to read/write etc ... better not to disconnect disk
len = 0;
break;
case SCSI_CMD_START_STOP_UNIT:
// Host try to eject/safe remove/powerof us. We could safely disconnect with disk storage, or go into lower power
// scsi_start_stop_unit_t const * cmd_start_stop = (scsi_start_stop_unit_t const *) scsi_cmd
len = 0;
break;
default:
// negative is error -> Data stage is STALL, status = failed
return -1;
}
// return len must not larger than bufsize
TU_ASSERT( bufsize >= len );
if ( ptr && len )
{
if(in_xfer)
{
memcpy(buffer, ptr, len);
}else
{
// SCSI output
}
}
return len;
}
//--------------------------------------------------------------------+
// APPLICATION CODE
//--------------------------------------------------------------------+
void msc_app_task(void* param)
{ // no need to implement the task yet
(void) param;
OSAL_TASK_BEGIN
OSAL_TASK_END
}
void msc_app_init (void)
{
}
#endif

View File

@ -1,93 +0,0 @@
/**************************************************************************/
/*!
@file msc_device_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 group_demo
* \defgroup Mass Storage Device App
* @{ */
#ifndef _TUSB_MSCD_DEVICE_APP_H_
#define _TUSB_MSCD_DEVICE_APP_H_
#include "bsp/board.h"
#include "tusb.h"
#ifdef __cplusplus
extern "C" {
#endif
#if CFG_TUD_MSC
enum
{
DISK_BLOCK_NUM = 16, // 8KB is the smallest size that windows allow to mount
DISK_BLOCK_SIZE = 512
};
#define README_CONTENTS \
"This is tinyusb's MassStorage Class demo.\r\n\r\n\
If you find any bugs or get any questions, feel free to file an\r\n\
issue at github.com/hathach/tinyusb"
#if CFG_TUSB_MCU==OPT_MCU_LPC11UXX || CFG_TUSB_MCU==OPT_MCU_LPC13XX
#define MSCD_APP_ROMDISK
#else // defaults is ram disk
#define MSCD_APP_RAMDISK
#endif
void msc_app_init(void);
void msc_app_task(void* param);
void msc_app_mount(uint8_t rhport);
void msc_app_umount(uint8_t rhport);
#else
#define msc_app_init()
#define msc_app_task(x)
#define msc_app_mount(x)
#define msc_app_umount(x)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_MSCD_DEVICE_APP_H_ */
/** @} */

View File

@ -1,114 +0,0 @@
/**************************************************************************/
/*!
@file msc_device_ramdisk.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 "msc_device_app.h"
#if CFG_TUD_MSC && defined (MSCD_APP_RAMDISK)
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION
uint8_t msc_device_ramdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] =
{
//------------- Boot Sector -------------//
// byte_per_sector = DISK_BLOCK_SIZE; fat12_sector_num_16 = DISK_BLOCK_NUM;
// sector_per_cluster = 1; reserved_sectors = 1;
// fat_num = 1; fat12_root_entry_num = 16;
// sector_per_fat = 1; sector_per_track = 1; head_num = 1; hidden_sectors = 0;
// drive_number = 0x80; media_type = 0xf8; extended_boot_signature = 0x29;
// filesystem_type = "FAT12 "; volume_serial_number = 0x1234; volume_label = "tinyusb msc";
[0] =
{
0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53, 0x35, 0x2E, 0x30, 0x00, 0x02, 0x01, 0x01, 0x00,
0x01, 0x10, 0x00, 0x10, 0x00, 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x29, 0x34, 0x12, 0x00, 0x00, 0x74, 0x69, 0x6E, 0x79, 0x75,
0x73, 0x62, 0x20, 0x6D, 0x73, 0x63, 0x46, 0x41, 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
[510] = 0x55, [511] = 0xAA // FAT magic code
},
//------------- FAT12 Table -------------//
[1] =
{
0xF8, 0xFF, 0xFF, 0xFF, 0x0F // // first 2 entries must be F8FF, third entry is cluster end of readme file
},
//------------- Root Directory -------------//
[2] =
{
// first entry is volume label
0x54, 0x49, 0x4E, 0x59, 0x55, 0x53, 0x42, 0x20, 0x4D, 0x53, 0x43, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0x6D, 0x65, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// second entry is readme file
'R' , 'E' , 'A' , 'D' , 'M' , 'E' , ' ' , ' ' , 'T' , 'X' , 'T' , 0x20, 0x00, 0xC6, 0x52, 0x6D,
0x65, 0x43, 0x65, 0x43, 0x00, 0x00, 0x88, 0x6D, 0x65, 0x43, 0x02, 0x00,
sizeof(README_CONTENTS)-1, 0x00, 0x00, 0x00 // readme's filesize (4 Bytes)
},
//------------- Readme Content -------------//
[3] = README_CONTENTS
};
//--------------------------------------------------------------------+
// IMPLEMENTATION
//--------------------------------------------------------------------+
int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
{
(void) rhport; (void) lun;
uint8_t* addr = msc_device_ramdisk[lba] + offset;
memcpy(buffer, (uint8_t*) addr, bufsize);
return bufsize;
}
int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
{
(void) rhport; (void) lun;
uint8_t* addr = msc_device_ramdisk[lba] + offset;
memcpy(addr, buffer, bufsize);
return bufsize;
}
#endif

View File

@ -1,119 +0,0 @@
/**************************************************************************/
/*!
@file msc_device_romdisk.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 "msc_device_app.h"
#if CFG_TUD_MSC && defined (MSCD_APP_ROMDISK)
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
const uint8_t msc_device_app_rommdisk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] =
{
//------------- Boot Sector -------------//
// byte_per_sector = DISK_BLOCK_SIZE; fat12_sector_num_16 = DISK_BLOCK_NUM;
// sector_per_cluster = 1; reserved_sectors = 1;
// fat_num = 1; fat12_root_entry_num = 16;
// sector_per_fat = 1; sector_per_track = 1; head_num = 1; hidden_sectors = 0;
// drive_number = 0x80; media_type = 0xf8; extended_boot_signature = 0x29;
// filesystem_type = "FAT12 "; volume_serial_number = 0x1234; volume_label = "tinyusb msc";
[0] =
{
0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53, 0x35, 0x2E, 0x30, 0x00, 0x02, 0x01, 0x01, 0x00,
0x01, 0x10, 0x00, 0x10, 0x00, 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x29, 0x34, 0x12, 0x00, 0x00, 0x74, 0x69, 0x6E, 0x79, 0x75,
0x73, 0x62, 0x20, 0x6D, 0x73, 0x63, 0x46, 0x41, 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
[510] = 0x55, [511] = 0xAA // FAT magic code
},
//------------- FAT12 Table -------------//
[1] =
{
0xF8, 0xFF, 0xFF, 0xFF, 0x0F // first 2 entries must be F8FF, third entry is cluster end of readme file
},
//------------- Root Directory -------------//
[2] =
{
// first entry is volume label
0x54, 0x49, 0x4E, 0x59, 0x55, 0x53, 0x42, 0x20, 0x4D, 0x53, 0x43, 0x08, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0x6D, 0x65, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// second entry is readme file
0x52, 0x45, 0x41, 0x44, 0x4D, 0x45, 0x20, 0x20, 0x54, 0x58, 0x54, 0x20, 0x00, 0xC6, 0x52, 0x6D,
0x65, 0x43, 0x65, 0x43, 0x00, 0x00, 0x88, 0x6D, 0x65, 0x43, 0x02, 0x00,
sizeof(README_CONTENTS)-1, 0x00, 0x00, 0x00 // readme's filesize
},
//------------- Readme Content -------------//
[3] = README_CONTENTS
};
//--------------------------------------------------------------------+
// IMPLEMENTATION
//--------------------------------------------------------------------+
int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
{
(void) rhport; (void) lun;
uint8_t* addr = msc_device_ramdisk[lba] + offset;
memcpy(buffer, (uint8_t*) addr, bufsize);
return bufsize;
}
// Stall write10 by return 0, as this is readonly disk
int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
{
(void) rhport; (void) lun;
// let host know that this is read-only disk
mscd_sense_data.sense_key = SCSI_SENSEKEY_DATA_PROTECT;
return 0;
}
#endif

View File

@ -1,147 +0,0 @@
/**************************************************************************/
/*!
@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_CONFIG_H_
#define _TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------+
// CONTROLLER CONFIGURATION
//--------------------------------------------------------------------+
//#define CFG_TUSB_MCU will be passed from IDE/command line for easy board/mcu switching
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE)
//#define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE)
#define CFG_TUSB_DEBUG 2
/*------------- RTOS -------------*/
//#define CFG_TUSB_OS OPT_OS_NONE // be passed from IDE/command line for easy project switching
//#define CFG_TUD_TASK_PRIO 0
//#define CFG_TUD_TASK_QUEUE_SZ 16
//#define CFG_TUD_TASK_STACK_SZ 150
//--------------------------------------------------------------------+
// DEVICE CONFIGURATION
//--------------------------------------------------------------------+
/*------------- Core -------------*/
#define CFG_TUD_DESC_AUTO 1
// #define CFG_TUD_DESC_VID 0xCAFE
// #define CFG_TUD_DESC_PID 0x0001
#define CFG_TUD_ENDOINT0_SIZE 64
//------------- CLASS -------------//
#define CFG_TUD_MSC 1
#define CFG_TUD_CDC 1
#define CFG_TUD_HID_KEYBOARD 0
#define CFG_TUD_HID_MOUSE 0
/*------------------------------------------------------------------*/
/* CLASS DRIVER
*------------------------------------------------------------------*/
// FIFO size of CDC TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE 128
#define CFG_TUD_CDC_TX_BUFSIZE 128
// Number of supported Logical Unit Number (At least 1)
#define CFG_TUD_MSC_MAXLUN 1
// Buffer size of Device Mass storage
#define CFG_TUD_MSC_BUFSIZE 512
//--------------------------------------------------------------------+
// USB RAM PLACEMENT
//--------------------------------------------------------------------+
#ifdef __CODE_RED // compiled with lpcxpresso
#if (CFG_TUSB_MCU == OPT_MCU_LPC11UXX) || (CFG_TUSB_MCU == OPT_MCU_LPC13XX)
#define CFG_TUSB_MEM_SECTION ATTR_SECTION(.data.$RAM2) ATTR_ALIGNED(64) // lp11u & lp13u requires data to be 64 byte aligned
#elif CFG_TUSB_MCU == OPT_MCU_LPC175X_6X
#define CFG_TUSB_MEM_SECTION // LPC17xx USB DMA can access all
#elif (CFG_TUSB_MCU == OPT_MCU_LPC43XX)
#define CFG_TUSB_MEM_SECTION ATTR_SECTION(.data.$RAM3)
#endif
#elif defined __CC_ARM // Compiled with Keil armcc, USBRAM_SECTION is defined in scatter files
#if (CFG_TUSB_MCU == OPT_MCU_LPC11UXX) || (CFG_TUSB_MCU == OPT_MCU_LPC13XX)
#define CFG_TUSB_MEM_SECTION ATTR_SECTION(USBRAM_SECTION) ATTR_ALIGNED(64) // lp11u & lp13u requires data to be 64 byte aligned
#elif (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X)
#define CFG_TUSB_MEM_SECTION // LPC17xx USB DMA can access all address
#elif (CFG_TUSB_MCU == OPT_MCU_LPC43XX)
#define CFG_TUSB_MEM_SECTION // Use keil tool configure to have AHB SRAM as default memory
#endif
#elif defined __ICCARM__ // compiled with IAR
#if (CFG_TUSB_MCU == OPT_MCU_LPC11UXX) || (CFG_TUSB_MCU == OPT_MCU_LPC13XX)
#define CFG_TUSB_MEM_SECTION _Pragma("location=\"USB_PACKET_MEMORY\"") ATTR_ALIGNED(64)
#elif (CFG_TUSB_MCU == OPT_MCU_LPC175X_6X)
#define CFG_TUSB_MEM_SECTION
#elif (CFG_TUSB_MCU == OPT_MCU_LPC43XX)
#define CFG_TUSB_MEM_SECTION _Pragma("location=\".ahb_sram1\"")
#endif
#else
#error compiler not specified
#endif
// LPC11uxx and LPC13uxx requires each buffer has to be 64-byte alignment
#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(64)
#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
#else
#define CFG_TUSB_MEM_ALIGN
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_CONFIG_H_ */

View File

@ -1,100 +0,0 @@
/**************************************************************************/
/*!
@file tusb_descriptors.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 "tusb.h"
//--------------------------------------------------------------------+
// STRING DESCRIPTORS
//--------------------------------------------------------------------+
#define STRING_LEN_UNICODE(n) (2 + (2*(n))) // also includes 2 byte header
#define ENDIAN_BE16_FROM( high, low) ENDIAN_BE16(high << 8 | low)
// array of pointer to string descriptors
uint16_t const * const string_desc_arr [] =
{
[0] = (uint16_t []) { // supported language
ENDIAN_BE16_FROM( STRING_LEN_UNICODE(1), TUSB_DESC_STRING ),
0x0409 // English
},
[1] = (uint16_t []) { // manufacturer
ENDIAN_BE16_FROM( STRING_LEN_UNICODE(11), TUSB_DESC_STRING),
't', 'i', 'n', 'y', 'u', 's', 'b', '.', 'o', 'r', 'g' // len = 11
},
[2] = (uint16_t []) { // product
ENDIAN_BE16_FROM( STRING_LEN_UNICODE(14), TUSB_DESC_STRING),
't', 'i', 'n', 'y', 'u', 's', 'b', ' ', 'd', 'e', 'v', 'i', 'c', 'e' // len = 14
},
[3] = (uint16_t []) { // serials
ENDIAN_BE16_FROM( STRING_LEN_UNICODE(4), TUSB_DESC_STRING),
'1', '2', '3', '4' // len = 4
},
[4] = (uint16_t []) { // CDC Interface
ENDIAN_BE16_FROM( STRING_LEN_UNICODE(3), TUSB_DESC_STRING),
'c', 'd', 'c' // len = 3
},
[5] = (uint16_t []) { // Keyboard Interface
ENDIAN_BE16_FROM( STRING_LEN_UNICODE(5), TUSB_DESC_STRING),
'm', 'o', 'u', 's', 'e' // len = 5
},
[6] = (uint16_t []) { // Keyboard Interface
ENDIAN_BE16_FROM( STRING_LEN_UNICODE(8), TUSB_DESC_STRING),
'k', 'e', 'y', 'b', 'o', 'a', 'r', 'd' // len = 8
},
[7] = (uint16_t []) { // MSC Interface
ENDIAN_BE16_FROM( STRING_LEN_UNICODE(3), TUSB_DESC_STRING),
'm', 's', 'c' // len = 3
}
};
// tud_desc_set is required by tinyusb stack
// since CFG_TUD_DESC_AUTO is enabled, we only need to set string_arr
tud_desc_set_t tud_desc_set =
{
.device = NULL,
.config = NULL,
.string_arr = (uint8_t const **) string_desc_arr,
.hid_report = NULL
};

View File

@ -1,95 +0,0 @@
# Host Demos #
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**
- [Prerequisites](#prerequisites)
- [Hub](#hub)
- [Human Interface Device (HID)](#human-interface-device-hid)
- [Keyboard](#keyboard)
- [Mouse](#mouse)
- [Mass Storage Class Device (MSC)](#mass-storage-class-device-msc)
- [Communication Class Device (CDC)](#communication-class-device-cdc)
- [Serial](#serial)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
host application code is store at *demos/host/src* containing
File | Description
----- | -------------
main.c | Initialization (board, stack) and a RTOS task scheduler call or just simple a indefinite loop for non OS to invoke class-specific tasks.
tusb_config.h | tinyusb stack configuration.
app_os_prio.h | RTOS task priority definitions
Class-specific | Application files for supported classes.
Firstly connect your ansi-escaped supported terminal (see below) to the UART of the evaluation board since all the user interaction happens there. The default UART configure is
- Baudrate = 115200
- Data = 8 bits
- Parity = none
- Stop = 1 bit
- Flow control = none
The demo will start with the greeting of enabled classes and chosen RTOS then start to blink an LED at 1 Hz. When any of supported devices is plugged or un-plugged either directly or via a hub, demo application will print out a short message. Notes: if usb device is composed of supported and unsupported classes such as a keyboard and a camera, the keyboard interface is still mounted as usual without any issues.
**NOTE** Host demo is quite power hunger, especially when you plug a hub with several devices on it. Make sure you have enough power before filing any bugs.
## Prerequisites ##
In order to run application demo, you would need
- A [supported development board](../../boards/readme.md).
- A supported toolchain: LPCXpresso, Keil, IAR.
- A [ANSI escape](http://en.wikipedia.org/wiki/ANSI_escape_code) supported terminal such as [Tera Term](http://en.sourceforge.jp/projects/ttssh2/) to demonstrate properly.
## Hub
Hub is internally handled by tinyusb stack, application code does not have to worry on how to get hub operated. However, application must be written to handle multiple devices simultaneously.
## Human Interface Device (HID)
### Keyboard
When a keyboard device is enumerated, any keys pressed on the device will be echoed to the UART terminal.
![Host Keyboard Demo](http://docs.tinyusb.org/images/demo_host_keyboard.png)
### Mouse
When a mouse device is enumerated, any movements or clicks on the device will be reflected on the terminal. Only make sure the terminal's windows is active on your host OS and it supports ANSI escape code.
![Host Mouse Demo](http://docs.tinyusb.org/images/demo_host_mouse.png)
## Mass Storage Class Device (MSC)
Mass storage demo application only supports device with FAT file system by the help of fatfs (source in *vendor/fatfs*). In addition, it also includes a minimal command line interface *msc_cli.c* to allow user to navigate and execute several basic file operations. When mass storage device is plugged, CLI will be activated, type "help" for the usage. Some are
Command | Description
----- | -------------
cls | clear screen
ls | List information of the FILEs, only supported current directory.
cd | change the current directory.
cat | display contents of a file.
cp | copy files to another location.
mkdir | create a directory, if it does not already exist.
mv | rename or move a directory or a file.
rm | remove (delete) an empty directory or file
Furthermore, the demo's CLI also supports multiple mass storage devices. You could *cd* between disk drives, and copy a file from one to another.
![Host MSC Demo](http://docs.tinyusb.org/images/demo_host_msc.png)
## Communication Class Device (CDC)
CDC has several subclass, currently tinyusb only supports the popular *Abstract Control Model (ACM)*
### Serial
A virtual serial of CDC-ACM is supported such as those built with tinyusb device stack. The host demo literally does 2 things
- Echo back any thing it received from the device to the terminal
- Receive data from terminal and send it to device.
Notes: FTDI is a vendor-specific class, which is not currently supported.
![Host Serial Demo](http://docs.tinyusb.org/images/demo_host_serial.png)

View File

@ -1,63 +1,3 @@
# Build Demos
# Examples
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**
- [LPCXpresso](#lpcxpresso)
- [Keil](#keil)
- [IAR](#iar)
- [Configure demo](#configure-demo)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## LPCXpresso
LPCXpresso is an eclipse-based IDE, so you will need to create an workspace first then import project files (.cproject & .project) into it. The following step explain how to do just that.
1. Click *File->Import*, then expand the *General* folder and select **Existing Projects into Workspace** and click Next.
![lpcxpresso_import.png](http://docs.tinyusb.org/images/lpcxpresso_import.png)
2. On the next dialog, Click *Browse* and choose the **repo/demos** folder inside the repo. You should see a list of all demo applications. \[**IMPORTANT**\] Make sure the option **Copy projects into workspace** is **CLEAR**, as demo application uses *link folders* and this option may cause problem with the copy import. Then choose any of the demo application and click *Finish*.
![lpcxpresso_import2.png](http://docs.tinyusb.org/images/lpcxpresso_import2.png)
3. Select the configure corresponding to your development board.
![lpcxpresso_select_board.png](http://docs.tinyusb.org/images/lpcxpresso_select_board.png)
4. Then select the correct MCU option from project properties then you are ready to go.
![lpcxpresso_mcu.png](http://docs.tinyusb.org/images/lpcxpresso_mcu.png)
*TIPS* Working with eclipse-based IDE like lpcxpresso, you should change the indexer option in *Preferences->C/C++->Indexer* to "active build" to have a better code viewer. Those lines that are opt out by #if will be gray, I found this extremely helpful.
![lpcpresso_indexer](http://docs.tinyusb.org/images/lpcxpresso_indexer.png)
## Keil
It is relatively simple for Keil
1. Open the desired demo project e.g *demos/host/host\_freertos/host_freertos.uvproj*
2. Select the configure corresponding to your development board and build it.
![keil_select_board.png](http://docs.tinyusb.org/images/keil_select_board.png)
## IAR
IAR is just as easy as Keil
1. Open the desired demo project e.g *demos/host/host\_freertos/host_freertos.eww*
2. Again select the configure corresponding to your development board and build it.
![iar_select_board.png](http://docs.tinyusb.org/images/iar_select_board.png)
## Configure demo
Application demo is written to have the code excluded if its required option is not enabled in [tusb_config.h](). Some of combination may exceed the 32KB limit of IAR/Keil so you may want to re-configure to disable some class support, decrease CFG_TUSB_DEBUG or increase the compiler optimization level.
In addition, there are some configuration you can change such as
- CFG_UART_BAUDRATE in board.h
- CFG_PRINTF_TARGET in the specific board header (e.g board_ea4357.h) to either Semihost, Uart, or SWO.
Build and Run example instructions

View File

@ -46,16 +46,17 @@
void vApplicationMallocFailedHook(void)
{
taskDISABLE_INTERRUPTS();
TU_ASSERT(false, );
taskDISABLE_INTERRUPTS();
TU_ASSERT(false, );
}
void vApplicationStackOverflowHook(xTaskHandle pxTask, signed char *pcTaskName)
{
(void) pxTask;
(void) pxTask;
(void) pcTaskName;
taskDISABLE_INTERRUPTS();
TU_ASSERT(false, );
taskDISABLE_INTERRUPTS();
TU_ASSERT(false, );
}
/* configSUPPORT_STATIC_ALLOCATION is set to 1, so the application must provide an

View File

@ -340,7 +340,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
/*------------- Boot protocol only keyboard & mouse -------------*/
if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT)
{
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, ERR_TUD_INVALID_DESCRIPTOR);
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE);
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD)

View File

@ -238,12 +238,12 @@ bool hidh_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac
#endif
{
// TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL
// Not supported protocol
return false;
}
}else
{
// TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS
// Not supported subclass
return false;
}

View File

@ -57,44 +57,13 @@
ENTRY(TUSB_ERROR_INVALID_PARA )\
ENTRY(TUSB_ERROR_DEVICE_NOT_READY )\
ENTRY(TUSB_ERROR_INTERFACE_IS_BUSY )\
ENTRY(TUSB_ERROR_HCD_FAILED )\
ENTRY(TUSB_ERROR_HCD_OPEN_PIPE_FAILED )\
ENTRY(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND )\
ENTRY(TUSB_ERROR_USBH_MOUNT_CONFIG_DESC_TOO_LONG )\
ENTRY(TUSB_ERROR_USBH_DESCRIPTOR_CORRUPTED )\
ENTRY(TUSB_ERROR_USBH_XFER_STALLED )\
ENTRY(TUSB_ERROR_USBH_XFER_FAILED )\
ENTRY(TUSB_ERROR_OSAL_TIMEOUT )\
ENTRY(TUSB_ERROR_OSAL_WAITING ) /* only used by OSAL_NONE in the subtask */ \
ENTRY(TUSB_ERROR_OSAL_TASK_FAILED )\
ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED )\
ENTRY(TUSB_ERROR_OSAL_SEMAPHORE_FAILED )\
ENTRY(TUSB_ERROR_OSAL_MUTEX_FAILED )\
ENTRY(TUSB_ERROR_EHCI_NOT_ENOUGH_QTD )\
ENTRY(TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE )\
ENTRY(TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL )\
ENTRY(TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS )\
ENTRY(TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS )\
ENTRY(TUSB_ERROR_CDC_UNSUPPORTED_PROTOCOL )\
ENTRY(TUSB_ERROR_CDCH_DEVICE_NOT_MOUNTED )\
ENTRY(TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL )\
ENTRY(TUSB_ERROR_MSCH_UNKNOWN_SCSI_COMMAND )\
ENTRY(TUSB_ERROR_MSCH_DEVICE_NOT_MOUNTED )\
ENTRY(TUSB_ERROR_HUB_FEATURE_NOT_SUPPORTED )\
ENTRY(TUSB_ERROR_DESCRIPTOR_CORRUPTED )\
ENTRY(TUSB_ERROR_DCD_FAILED )\
ENTRY(TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT )\
ENTRY(TUSB_ERROR_DCD_NOT_ENOUGH_QTD )\
ENTRY(TUSB_ERROR_DCD_OPEN_PIPE_FAILED )\
ENTRY(TUSB_ERROR_DCD_EDPT_XFER )\
ENTRY(TUSB_ERROR_NOT_SUPPORTED_YET )\
ENTRY(TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED )\
ENTRY(TUSB_ERROR_NOT_SUPPORTED )\
ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\
ENTRY(TUSB_ERROR_FAILED )\
\
ENTRY(ERR_TUD_INVALID_DESCRIPTOR) \
ENTRY(ERR_TUD_EDPT_OPEN_FAILED) \
/// \brief Error Code returned
typedef enum

View File

@ -48,9 +48,7 @@ static void tu_fifo_lock(tu_fifo_t *f)
{
if (f->mutex)
{
uint32_t err;
(void) err;
osal_mutex_lock(f->mutex, OSAL_TIMEOUT_WAIT_FOREVER, &err);
osal_mutex_lock(f->mutex, OSAL_TIMEOUT_WAIT_FOREVER);
}
}

View File

@ -36,8 +36,6 @@
*/
/**************************************************************************/
// This top level class manages the bus state and delegates events to class-specific drivers.
#include "tusb_option.h"
#if TUSB_OPT_DEVICE_ENABLED
@ -52,15 +50,6 @@
#define CFG_TUD_TASK_QUEUE_SZ 16
#endif
#ifndef CFG_TUD_TASK_STACK_SZ
#define CFG_TUD_TASK_STACK_SZ 150
#endif
#ifndef CFG_TUD_TASK_PRIO
#define CFG_TUD_TASK_PRIO 0
#endif
//--------------------------------------------------------------------+
// Device Data
//--------------------------------------------------------------------+
@ -153,16 +142,14 @@ static usbd_class_driver_t const usbd_class_drivers[] =
#endif
};
enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_driver_t) };
enum { USBD_CLASS_DRIVER_COUNT = TU_ARRAY_SZIE(usbd_class_drivers) };
//--------------------------------------------------------------------+
// DCD Event
//--------------------------------------------------------------------+
OSAL_TASK_DEF(_usbd_task_def, "usbd", usbd_task, CFG_TUD_TASK_PRIO, CFG_TUD_TASK_STACK_SZ);
// Event queue
// role device/host is used by OS NONE for mutex (disable usb isr) only
// OPT_MODE_DEVICE is used by OS NONE for mutex (disable usb isr)
OSAL_QUEUE_DEF(OPT_MODE_DEVICE, _usbd_qdef, CFG_TUD_TASK_QUEUE_SZ, dcd_event_t);
static osal_queue_t _usbd_q;
@ -195,8 +182,6 @@ bool usbd_init (void)
_usbd_q = osal_queue_create(&_usbd_qdef);
TU_ASSERT(_usbd_q != NULL);
osal_task_create(&_usbd_task_def);
// Init class drivers
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init();
@ -221,8 +206,26 @@ static void usbd_reset(uint8_t rhport)
}
}
// Main device task implementation
static void usbd_task_body(void)
/* USB Device Driver task
* This top level thread manages all device controller event and delegates events to class-specific drivers.
* This should be called periodically within the mainloop or rtos thread.
*
@code
int main(void)
{
application_init();
tusb_init();
while(1) // the mainloop
{
application_code();
tud_task(); // tinyusb device task
}
}
@endcode
*/
void tud_task (void)
{
// Loop until there is no more events in the queue
while (1)
@ -297,25 +300,6 @@ static void usbd_task_body(void)
}
}
/* USB device task
* Thread that handles all device events. With an real RTOS, the task must be a forever loop and never return.
* For coding convenience with no RTOS, we use wrapped sub-function for processing to easily return at any time.
*/
void usbd_task( void* param)
{
(void) param;
#if CFG_TUSB_OS != OPT_OS_NONE
while (1) {
#endif
usbd_task_body();
#if CFG_TUSB_OS != OPT_OS_NONE
}
#endif
}
//--------------------------------------------------------------------+
// Control Request Parser & Handling
//--------------------------------------------------------------------+

View File

@ -81,6 +81,7 @@ extern tud_desc_set_t tud_desc_set;
// APPLICATION API
//--------------------------------------------------------------------+
bool tud_mounted(void);
void tud_task (void);
//--------------------------------------------------------------------+
// APPLICATION CALLBACK (WEAK is optional)

View File

@ -52,8 +52,6 @@ extern tud_desc_set_t const* usbd_desc_set;
// INTERNAL API for stack management
//--------------------------------------------------------------------+
bool usbd_init (void);
void usbd_task (void* param);
// Carry out Data and Status stage of control transfer
// - If len = 0, it is equivalent to sending status only

View File

@ -46,15 +46,6 @@
#define CFG_TUH_TASK_QUEUE_SZ 16
#endif
#ifndef CFG_TUH_TASK_STACK_SZ
#define CFG_TUH_TASK_STACK_SZ 200
#endif
#ifndef CFG_TUH_TASK_PRIO
#define CFG_TUH_TASK_PRIO 0
#endif
//--------------------------------------------------------------------+
// INCLUDE
//--------------------------------------------------------------------+
@ -123,9 +114,9 @@ enum { USBH_CLASS_DRIVER_COUNT = TU_ARRAY_SZIE(usbh_class_drivers) };
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address
OSAL_TASK_DEF(_usbh_task_def, "usbh", usbh_task, CFG_TUH_TASK_PRIO, CFG_TUH_TASK_STACK_SZ);
// including zero-address
CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
// Event queue
// role device/host is used by OS NONE for mutex (disable usb isr) only
@ -161,8 +152,6 @@ bool usbh_init(void)
_usbh_q = osal_queue_create( &_usbh_qdef );
TU_ASSERT(_usbh_q != NULL);
osal_task_create(&_usbh_task_def);
//------------- Semaphore, Mutex for Control Pipe -------------//
for(uint8_t i=0; i<CFG_TUSB_HOST_DEVICE_MAX+1; i++) // including address zero
{
@ -610,12 +599,32 @@ bool enum_task(hcd_event_t* event)
return true;
}
bool usbh_task_body(void)
/* USB Host Driver task
* This top level thread manages all host controller event and delegates events to class-specific drivers.
* This should be called periodically within the mainloop or rtos thread.
*
@code
int main(void)
{
application_init();
tusb_init();
while(1) // the mainloop
{
application_code();
tuh_task(); // tinyusb host task
}
}
@endcode
*/
void tuh_task(void)
{
// Loop until there is no more events in the queue
while (1)
{
hcd_event_t event;
if ( !osal_queue_receive(_usbh_q, &event) ) return false;
if ( !osal_queue_receive(_usbh_q, &event) ) return;
switch (event.event_id)
{
@ -629,25 +638,6 @@ bool usbh_task_body(void)
}
}
/* USB Host task
* Thread that handles all device events. With an real RTOS, the task must be a forever loop and never return.
* For coding convenience with no RTOS, we use wrapped sub-function for processing to easily return at any time.
*/
void usbh_task(void* param)
{
(void) param;
#if CFG_TUSB_OS != OPT_OS_NONE
while (1) {
#endif
usbh_task_body();
#if CFG_TUSB_OS != OPT_OS_NONE
}
#endif
}
//--------------------------------------------------------------------+
// INTERNAL HELPER
//--------------------------------------------------------------------+

View File

@ -78,9 +78,9 @@ typedef struct {
//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
//tusb_error_t tusbh_configuration_set (uint8_t dev_addr, uint8_t configure_number) ATTR_WARN_UNUSED_RESULT;
tusb_device_state_t tuh_device_get_state (uint8_t dev_addr) ATTR_WARN_UNUSED_RESULT ATTR_PURE;
static inline bool tuh_device_is_configured(uint8_t dev_addr) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT ATTR_PURE;
void tuh_task(void);
tusb_device_state_t tuh_device_get_state (uint8_t dev_addr);
static inline bool tuh_device_is_configured(uint8_t dev_addr)
{
return tuh_device_get_state(dev_addr) == TUSB_DEVICE_STATE_CONFIGURED;
@ -89,7 +89,7 @@ static inline bool tuh_device_is_configured(uint8_t dev_addr)
//--------------------------------------------------------------------+
// APPLICATION CALLBACK
//--------------------------------------------------------------------+
ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device) ATTR_WARN_UNUSED_RESULT;
ATTR_WEAK uint8_t tuh_device_attached_cb (tusb_desc_device_t const *p_desc_device);
/** Callback invoked when device is mounted (configured) */
ATTR_WEAK void tuh_mount_cb (uint8_t dev_addr);
@ -103,7 +103,6 @@ ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr);
#ifdef _TINY_USB_SOURCE_FILE_
bool usbh_init(void);
void usbh_task(void* param);
bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8_t* data);

View File

@ -68,8 +68,6 @@ typedef void (*osal_task_func_t)( void * );
* uint32_t tusb_hal_millis(void)
*
* Task
* osal_task_def_t
* bool osal_task_create(osal_task_def_t* taskdef)
* void osal_task_delay(uint32_t msec)
*
* Queue

View File

@ -65,27 +65,6 @@ static inline bool in_isr(void)
//--------------------------------------------------------------------+
// TASK API
//--------------------------------------------------------------------+
#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \
static uint8_t _name##_##buf[_stack_sz*sizeof(StackType_t)]; \
osal_task_def_t _name = { .func = _func, .prio = _prio, .stack_sz = _stack_sz, .buf = _name##_##buf, .strname = _str };
typedef struct
{
osal_task_func_t func;
uint16_t prio;
uint16_t stack_sz;
void* buf;
const char* strname;
StaticTask_t stask;
}osal_task_def_t;
static inline bool osal_task_create(osal_task_def_t* taskdef)
{
return NULL != xTaskCreateStatic(taskdef->func, taskdef->strname, taskdef->stack_sz, NULL, taskdef->prio, (StackType_t*) taskdef->buf, &taskdef->stask);
}
static inline void osal_task_delay(uint32_t msec)
{
vTaskDelay( pdMS_TO_TICKS(msec) );

View File

@ -46,27 +46,6 @@
//--------------------------------------------------------------------+
// TASK API
//--------------------------------------------------------------------+
#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) \
static os_stack_t _name##_##buf[_stack_sz]; \
osal_task_def_t _name = { .func = _func, .prio = _prio, .stack_sz = _stack_sz, .buf = _name##_##buf, .strname = _str };
typedef struct
{
struct os_task mynewt_task;
osal_task_func_t func;
uint16_t prio;
uint16_t stack_sz;
void* buf;
const char* strname;
}osal_task_def_t;
static inline bool osal_task_create(osal_task_def_t* taskdef)
{
return OS_OK == os_task_init(&taskdef->mynewt_task, taskdef->strname, taskdef->func, NULL, taskdef->prio, OS_WAIT_FOREVER,
(os_stack_t*) taskdef->buf, taskdef->stack_sz);
}
static inline void osal_task_delay(uint32_t msec)
{
os_time_delay( os_time_ms_to_ticks32(msec) );

View File

@ -51,17 +51,7 @@
//--------------------------------------------------------------------+
// TASK API
// Virtually do nothing in osal none
//--------------------------------------------------------------------+
#define OSAL_TASK_DEF(_name, _str, _func, _prio, _stack_sz) osal_task_def_t _name;
typedef uint8_t osal_task_def_t;
static inline bool osal_task_create(osal_task_def_t* taskdef)
{
(void) taskdef;
return true;
}
static inline void osal_task_delay(uint32_t msec)
{
uint32_t start = tusb_hal_millis();

View File

@ -68,20 +68,6 @@ bool tusb_init(void)
return TUSB_ERROR_NONE;
}
#if CFG_TUSB_OS == OPT_OS_NONE
void tusb_task(void)
{
#if TUSB_OPT_HOST_ENABLED
usbh_task(NULL);
#endif
#if TUSB_OPT_DEVICE_ENABLED
usbd_task(NULL);
#endif
}
#endif
/*------------------------------------------------------------------*/
/* Debug
*------------------------------------------------------------------*/

View File

@ -101,35 +101,24 @@
/** \ingroup group_application_api
* @{ */
// Initialize device/host stack according to tusb_config.h
// return true if success
// Initialize device/host stack
bool tusb_init(void);
#if CFG_TUSB_OS == OPT_OS_NONE
/** \brief Run all tinyusb's internal tasks (e.g host task, device task).
* \note This function is only required when using no RTOS (\ref CFG_TUSB_OS == OPT_OS_NONE). All the stack functions
* & callback are invoked within this function. This should be called periodically within the mainloop
*
@code
int main(void)
{
your_init_code();
tusb_init();
// TODO
// bool tusb_teardown(void);
// other config code
while(1) // the mainloop
{
your_application_code();
// backward compatible only. TODO remove later
static inline void tusb_task(void)
{
#if TUSB_OPT_HOST_ENABLED
tuh_task();
#endif
tusb_task(); // handle tinyusb event, task etc ...
}
}
@endcode
*
*/
void tusb_task(void);
#endif
#if TUSB_OPT_DEVICE_ENABLED
tud_task();
#endif
}
/** @} */

View File

@ -224,11 +224,6 @@
//------------------------------------------------------------------
// Configuration Validation
//------------------------------------------------------------------
#if (CFG_TUSB_OS != OPT_OS_NONE) && !defined (CFG_TUD_TASK_PRIO)
#error CFG_TUD_TASK_PRIO need to be defined (hint: use the highest if possible)
#endif
#if CFG_TUD_ENDOINT0_SIZE > 64
#error Control Endpoint Max Packet Size cannot be larger than 64
#endif