add windows driver for cdc
add simple echo cdc serial demo add cdc device send/receive API refractor descriptor refractor cdc.h add usbd driver function - init - bus_reset
This commit is contained in:
106
demos/device/device_os_none/WinCDCdriver.inf
Normal file
106
demos/device/device_os_none/WinCDCdriver.inf
Normal file
@@ -0,0 +1,106 @@
|
||||
;************************************************************
|
||||
; 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_1FC9&PID_4001, USB\VID_1FC9&PID_4001&MI_00, USB\VID_1FC9&PID_4003&MI_00, USB\VID_1FC9&PID_4005&MI_00, USB\VID_1FC9&PID_4007&MI_00, USB\VID_1FC9&PID_4009&MI_00, USB\VID_1FC9&PID_400b&MI_00, USB\VID_1FC9&PID_400d&MI_00, USB\VID_1FC9&PID_400f&MI_00, USB\VID_1FC9&PID_4011&MI_00, USB\VID_1FC9&PID_4013&MI_00, USB\VID_1FC9&PID_4015&MI_00, USB\VID_1FC9&PID_4017&MI_00, USB\VID_1FC9&PID_4019&MI_00, USB\VID_1FC9&PID_401b&MI_00, USB\VID_1FC9&PID_401d&MI_00, USB\VID_1FC9&PID_401f&MI_00, USB\VID_1FC9&PID_4021&MI_00, USB\VID_1FC9&PID_4023&MI_00, USB\VID_1FC9&PID_4025&MI_00, USB\VID_1FC9&PID_4027&MI_00, USB\VID_1FC9&PID_4029&MI_00, USB\VID_1FC9&PID_402b&MI_00, USB\VID_1FC9&PID_402d&MI_00, USB\VID_1FC9&PID_402f&MI_00, USB\VID_1FC9&PID_4031&MI_00, USB\VID_1FC9&PID_4033&MI_00, USB\VID_1FC9&PID_4035&MI_00, USB\VID_1FC9&PID_4037&MI_00, USB\VID_1FC9&PID_4039&MI_00, USB\VID_1FC9&PID_403b&MI_00, USB\VID_1FC9&PID_403d&MI_00, USB\VID_1FC9&PID_403f&MI_00
|
||||
|
||||
|
||||
[DeviceList.NTamd64]
|
||||
%DESCRIPTION%=DriverInstall, USB\VID_1FC9&PID_4001, USB\VID_1FC9&PID_4001&MI_00, USB\VID_1FC9&PID_4003&MI_00, USB\VID_1FC9&PID_4005&MI_00, USB\VID_1FC9&PID_4007&MI_00, USB\VID_1FC9&PID_4009&MI_00, USB\VID_1FC9&PID_400b&MI_00, USB\VID_1FC9&PID_400d&MI_00, USB\VID_1FC9&PID_400f&MI_00, USB\VID_1FC9&PID_4011&MI_00, USB\VID_1FC9&PID_4013&MI_00, USB\VID_1FC9&PID_4015&MI_00, USB\VID_1FC9&PID_4017&MI_00, USB\VID_1FC9&PID_4019&MI_00, USB\VID_1FC9&PID_401b&MI_00, USB\VID_1FC9&PID_401d&MI_00, USB\VID_1FC9&PID_401f&MI_00, USB\VID_1FC9&PID_4021&MI_00, USB\VID_1FC9&PID_4023&MI_00, USB\VID_1FC9&PID_4025&MI_00, USB\VID_1FC9&PID_4027&MI_00, USB\VID_1FC9&PID_4029&MI_00, USB\VID_1FC9&PID_402b&MI_00, USB\VID_1FC9&PID_402d&MI_00, USB\VID_1FC9&PID_402f&MI_00, USB\VID_1FC9&PID_4031&MI_00, USB\VID_1FC9&PID_4033&MI_00, USB\VID_1FC9&PID_4035&MI_00, USB\VID_1FC9&PID_4037&MI_00, USB\VID_1FC9&PID_4039&MI_00, USB\VID_1FC9&PID_403b&MI_00, USB\VID_1FC9&PID_403d&MI_00, USB\VID_1FC9&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"
|
||||
138
demos/device/device_os_none/cdcd_app.c
Normal file
138
demos/device/device_os_none/cdcd_app.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file cdcd_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 "cdcd_app.h"
|
||||
|
||||
#if TUSB_CFG_DEVICE_CDC
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
enum {
|
||||
CDCD_APP_BUFFER_SIZE = 16
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
OSAL_TASK_DEF(cdcd_serial_app_task, 128, CDCD_SERIAL_APP_TASK_PRIO);
|
||||
OSAL_SEM_DEF(cdcd_semaphore);
|
||||
|
||||
static osal_semaphore_handle_t sem_hdl;
|
||||
|
||||
static uint8_t cdcd_app_recv_buffer[CDCD_APP_BUFFER_SIZE] TUSB_CFG_ATTR_USBRAM;
|
||||
static uint8_t cdcd_app_send_buffer[CDCD_APP_BUFFER_SIZE] TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
static uint16_t received_bytes; // set by transfer complete callback
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// IMPLEMENTATION
|
||||
//--------------------------------------------------------------------+
|
||||
void cdcd_serial_app_init(void)
|
||||
{
|
||||
sem_hdl = osal_semaphore_create( OSAL_SEM_REF(cdcd_semaphore) );
|
||||
ASSERT_PTR( sem_hdl, VOID_RETURN);
|
||||
|
||||
ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(cdcd_serial_app_task) ), VOID_RETURN);
|
||||
}
|
||||
|
||||
void tusbd_cdc_mounted_cb(uint8_t coreid)
|
||||
{
|
||||
osal_semaphore_reset(sem_hdl);
|
||||
|
||||
received_bytes = 0;
|
||||
tusbd_cdc_receive(coreid, cdcd_app_recv_buffer, CDCD_APP_BUFFER_SIZE, true);
|
||||
}
|
||||
|
||||
void tusbd_cdc_xfer_isr(uint8_t coreid, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
|
||||
{
|
||||
switch ( pipe_id )
|
||||
{
|
||||
case CDC_PIPE_DATA_OUT:
|
||||
switch(event)
|
||||
{
|
||||
case TUSB_EVENT_XFER_COMPLETE:
|
||||
received_bytes = min16_of(xferred_bytes, CDCD_APP_BUFFER_SIZE); // discard overflow bytes
|
||||
osal_semaphore_post(sem_hdl); // notify main task
|
||||
break;
|
||||
|
||||
case TUSB_EVENT_XFER_ERROR:
|
||||
xferred_bytes = 0; // ignore
|
||||
break;
|
||||
|
||||
case TUSB_EVENT_XFER_STALLED:
|
||||
default :
|
||||
ASSERT(false, VOID_RETURN);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case CDC_PIPE_DATA_IN:
|
||||
case CDC_PIPE_NOTIFICATION:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OSAL_TASK_FUNCTION( cdcd_serial_app_task ) (void* p_task_para)
|
||||
{
|
||||
tusb_error_t error;
|
||||
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error);
|
||||
|
||||
if ( tusbd_cdc_is_configured(0) )
|
||||
{
|
||||
if ( received_bytes )
|
||||
{ // echo back
|
||||
memcpy(cdcd_app_send_buffer, cdcd_app_recv_buffer, received_bytes);
|
||||
tusbd_cdc_send(0, cdcd_app_send_buffer, received_bytes, false);
|
||||
received_bytes = 0;
|
||||
}
|
||||
|
||||
tusbd_cdc_receive(0, cdcd_app_recv_buffer, CDCD_APP_BUFFER_SIZE, true);
|
||||
}
|
||||
|
||||
OSAL_TASK_LOOP_END
|
||||
}
|
||||
|
||||
#endif
|
||||
75
demos/device/device_os_none/cdcd_app.h
Normal file
75
demos/device/device_os_none/cdcd_app.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@file cdcd_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_APP_H_
|
||||
#define _TUSB_CDCD_APP_H_
|
||||
|
||||
#include "boards/board.h"
|
||||
#include "tusb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_DEVICE_CDC
|
||||
|
||||
void cdcd_serial_app_init(void);
|
||||
OSAL_TASK_FUNCTION( cdcd_serial_app_task ) (void* p_task_para);
|
||||
|
||||
#else
|
||||
|
||||
#define cdcd_serial_app_init()
|
||||
#define cdcd_serial_app_task(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_CDCD_APP_H_ */
|
||||
|
||||
/** @} */
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "mscd_app.h"
|
||||
#include "keyboardd_app.h"
|
||||
#include "moused_app.h"
|
||||
#include "cdcd_app.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
@@ -68,16 +69,12 @@ void os_none_start_scheduler(void)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
// tusb_task_runner();
|
||||
tusb_task_runner();
|
||||
led_blinking_task(NULL);
|
||||
|
||||
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
keyboardd_app_task(NULL);
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_DEVICE_HID_MOUSE
|
||||
moused_app_task(NULL);
|
||||
#endif
|
||||
cdcd_serial_app_task(NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -95,6 +92,7 @@ int main(void)
|
||||
msc_dev_app_init();
|
||||
keyboardd_app_init();
|
||||
moused_app_init();
|
||||
cdcd_serial_app_init();
|
||||
|
||||
//------------- start OS scheduler (never return) -------------//
|
||||
#if TUSB_CFG_OS == TUSB_OS_FREERTOS
|
||||
@@ -112,39 +110,6 @@ int main(void)
|
||||
|
||||
while(1) { } // should not be reached here
|
||||
|
||||
#if TUSB_CFG_DEVICE_CDC && 0
|
||||
if (tusb_device_is_configured())
|
||||
{
|
||||
uint8_t cdc_char;
|
||||
if( tusb_cdc_getc(&cdc_char) )
|
||||
{
|
||||
switch (cdc_char)
|
||||
{
|
||||
#ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
case '1' :
|
||||
{
|
||||
uint8_t keys[6] = {HID_USAGE_KEYBOARD_aA + 'e' - 'a'};
|
||||
tusbd_hid_keyboard_send_report(0x08, keys, 1); // windows + E --> open explorer
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
|
||||
case '2' :
|
||||
tusb_hid_mouse_send(0, 10, 10);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default :
|
||||
cdc_char = toupper(cdc_char);
|
||||
tusb_cdc_putc(cdc_char);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -139,8 +139,8 @@ tusb_descriptor_device_t app_tusb_desc_device =
|
||||
.bDeviceClass = USB_DEVICE_CLASS_IAD,
|
||||
.bDeviceSubClass = USB_DEVICE_SUBCLASS_IAD,
|
||||
.bDeviceProtocol = USB_DEVICE_PROTOCOL_IAD,
|
||||
#elif defined CFG_USB_CDC
|
||||
.bDeviceClass = CDC_COMMUNICATION_INTERFACE_CLASS,
|
||||
#elif TUSB_CFG_DEVICE_CDC
|
||||
.bDeviceClass = TUSB_CLASS_CDC,
|
||||
.bDeviceSubClass = 0x00,
|
||||
.bDeviceProtocol = 0x00,
|
||||
#else
|
||||
@@ -379,7 +379,7 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
|
||||
{
|
||||
.bLength = sizeof(tusb_descriptor_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
|
||||
.bEndpointAddress = 0x83,
|
||||
.bEndpointAddress = MSC_EDPT_IN,
|
||||
.bmAttributes = { .xfer = TUSB_XFER_BULK },
|
||||
.wMaxPacketSize = { .size = TUSB_CFG_DEVICE_FULLSPEED ? 64 : 512 },
|
||||
.bInterval = 1
|
||||
@@ -389,7 +389,7 @@ app_descriptor_configuration_t app_tusb_desc_configuration =
|
||||
{
|
||||
.bLength = sizeof(tusb_descriptor_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
|
||||
.bEndpointAddress = 0x03,
|
||||
.bEndpointAddress = MSC_EDPT_OUT,
|
||||
.bmAttributes = { .xfer = TUSB_XFER_BULK },
|
||||
.wMaxPacketSize = { .size = TUSB_CFG_DEVICE_FULLSPEED ? 64 : 512 },
|
||||
.bInterval = 1
|
||||
|
||||
@@ -41,6 +41,9 @@
|
||||
|
||||
#include "tusb.h"
|
||||
|
||||
#define ENDPOINT_OUT_LOGICAL_TO_PHYSICAL(addr) (addr)
|
||||
#define ENDPOINT_IN_LOGICAL_TO_PHYSICAL(addr) ((addr) | 0x80)
|
||||
|
||||
#define INTERFACE_INDEX_CDC 0
|
||||
#define INTERFACE_INDEX_HID_KEYBOARD (INTERFACE_INDEX_CDC + 2*TUSB_CFG_DEVICE_CDC )
|
||||
#define INTERFACE_INDEX_HID_MOUSE (INTERFACE_INDEX_HID_KEYBOARD + TUSB_CFG_DEVICE_HID_KEYBOARD )
|
||||
@@ -50,10 +53,20 @@
|
||||
#define TOTAL_INTEFACES (2*TUSB_CFG_DEVICE_CDC + TUSB_CFG_DEVICE_HID_KEYBOARD + TUSB_CFG_DEVICE_HID_MOUSE + \
|
||||
TUSB_CFG_DEVICE_HID_GENERIC + TUSB_CFG_DEVICE_MSC)
|
||||
|
||||
// USB Interface Assosication Descriptor
|
||||
#define USB_DEVICE_CLASS_IAD USB_DEVICE_CLASS_MISCELLANEOUS
|
||||
#define USB_DEVICE_SUBCLASS_IAD 0x02
|
||||
#define USB_DEVICE_PROTOCOL_IAD 0x01
|
||||
/* HID In/Out Endpoint Address */
|
||||
#define HID_KEYBOARD_EP_IN ENDPOINT_IN_LOGICAL_TO_PHYSICAL(1)
|
||||
#define HID_MOUSE_EP_IN ENDPOINT_IN_LOGICAL_TO_PHYSICAL(4)
|
||||
|
||||
/* CDC Endpoint Address */
|
||||
#define CDC_NOTIFICATION_EP ENDPOINT_IN_LOGICAL_TO_PHYSICAL(2)
|
||||
#define CDC_DATA_EP_OUT ENDPOINT_OUT_LOGICAL_TO_PHYSICAL(3)
|
||||
#define CDC_DATA_EP_IN ENDPOINT_IN_LOGICAL_TO_PHYSICAL(3)
|
||||
|
||||
#define CDC_NOTIFICATION_EP_MAXPACKETSIZE 8
|
||||
#define CDC_DATA_EP_MAXPACKET_SIZE 16
|
||||
|
||||
#define MSC_EDPT_IN ENDPOINT_IN_LOGICAL_TO_PHYSICAL(3)
|
||||
#define MSC_EDPT_OUT ENDPOINT_OUT_LOGICAL_TO_PHYSICAL(3)
|
||||
|
||||
// Interface Assosication Descriptor if device is CDC + other class
|
||||
#define IAD_DESC_REQUIRED ( TUSB_CFG_DEVICE_CDC && (TOTAL_INTEFACES > 2) )
|
||||
@@ -64,7 +77,7 @@
|
||||
#ifndef TUSB_CFG_PRODUCT_ID
|
||||
// Bitmap: MassStorage | Generic | Mouse | Key | CDC
|
||||
#define PRODUCTID_BITMAP(interface, n) ( (TUSB_CFG_DEVICE_##interface) << (n) )
|
||||
#define TUSB_CFG_PRODUCT_ID (0x2000 | ( PRODUCTID_BITMAP(CDC, 0) | PRODUCTID_BITMAP(HID_KEYBOARD, 1) | \
|
||||
#define TUSB_CFG_PRODUCT_ID (0x4000 | ( PRODUCTID_BITMAP(CDC, 0) | PRODUCTID_BITMAP(HID_KEYBOARD, 1) | \
|
||||
PRODUCTID_BITMAP(HID_MOUSE, 2) | PRODUCTID_BITMAP(HID_GENERIC, 3) | \
|
||||
PRODUCTID_BITMAP(MSC, 4) ) )
|
||||
#endif
|
||||
|
||||
@@ -81,27 +81,32 @@ void tusbh_cdc_unmounted_cb(uint8_t dev_addr)
|
||||
|
||||
void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_id, uint32_t xferred_bytes)
|
||||
{
|
||||
if ( pipe_id == CDC_PIPE_DATA_IN )
|
||||
switch ( pipe_id )
|
||||
{
|
||||
switch(event)
|
||||
{
|
||||
case TUSB_EVENT_XFER_COMPLETE:
|
||||
received_bytes = xferred_bytes;
|
||||
osal_semaphore_post(sem_hdl); // notify main task
|
||||
break;
|
||||
case CDC_PIPE_DATA_IN:
|
||||
switch(event)
|
||||
{
|
||||
case TUSB_EVENT_XFER_COMPLETE:
|
||||
received_bytes = xferred_bytes;
|
||||
osal_semaphore_post(sem_hdl); // notify main task
|
||||
break;
|
||||
|
||||
case TUSB_EVENT_XFER_ERROR:
|
||||
xferred_bytes = 0; // ignore
|
||||
break;
|
||||
case TUSB_EVENT_XFER_ERROR:
|
||||
xferred_bytes = 0; // ignore
|
||||
break;
|
||||
|
||||
case TUSB_EVENT_XFER_STALLED:
|
||||
default :
|
||||
ASSERT(false, VOID_RETURN);
|
||||
break;
|
||||
}
|
||||
case TUSB_EVENT_XFER_STALLED:
|
||||
default :
|
||||
ASSERT(false, VOID_RETURN);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case CDC_PIPE_DATA_OUT:
|
||||
case CDC_PIPE_NOTIFICATION:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
else if (pipe_id == CDC_PIPE_DATA_OUT) { }
|
||||
else if (pipe_id == CDC_PIPE_NOTIFICATION) { }
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
Reference in New Issue
Block a user