fix potential issue with stall endpoints
NOTE: cannot able to STALL control OUT endpoints --> unsupported with data out request may got to an issue. clean up configure, add max string descriptor configure as windows sometimes ask for string @ index 238 !!!
This commit is contained in:
		@@ -75,25 +75,16 @@
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// DEVICE CONFIGURATION
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
#define TUSB_CFG_DEVICE_FULLSPEED       1 // TODO refractor
 | 
			
		||||
 | 
			
		||||
#define TUSB_CFG_DEVICE_USE_ROM_DRIVER  0
 | 
			
		||||
 | 
			
		||||
//------------- descriptors -------------//
 | 
			
		||||
#define TUSB_CFG_DEVICE_STRING_MANUFACTURER   "tinyusb.org"
 | 
			
		||||
#define TUSB_CFG_DEVICE_STRING_PRODUCT        "Device Example"
 | 
			
		||||
#define TUSB_CFG_DEVICE_STRING_SERIAL         "1234"
 | 
			
		||||
#define TUSB_CFG_DEVICE_VENDORID              0x1FC9 // NXP
 | 
			
		||||
//#define TUSB_CFG_DEVICE_PRODUCTID           0x4567
 | 
			
		||||
 | 
			
		||||
#define TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE    64
 | 
			
		||||
#define TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT 4
 | 
			
		||||
#define TUSB_CFG_DEVICE_FULLSPEED       1 // TODO refractor, remove
 | 
			
		||||
 | 
			
		||||
//------------- CLASS -------------//
 | 
			
		||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD  0
 | 
			
		||||
#define TUSB_CFG_DEVICE_HID_KEYBOARD  1
 | 
			
		||||
#define TUSB_CFG_DEVICE_HID_MOUSE     0
 | 
			
		||||
#define TUSB_CFG_DEVICE_HID_GENERIC   0
 | 
			
		||||
#define TUSB_CFG_DEVICE_MSC           0
 | 
			
		||||
#define TUSB_CFG_DEVICE_CDC           1
 | 
			
		||||
#define TUSB_CFG_DEVICE_CDC           0
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// COMMON CONFIGURATION
 | 
			
		||||
 
 | 
			
		||||
@@ -151,8 +151,8 @@ tusb_descriptor_device_t app_tusb_desc_device =
 | 
			
		||||
 | 
			
		||||
    .bMaxPacketSize0    = TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE,
 | 
			
		||||
 | 
			
		||||
    .idVendor           = TUSB_CFG_DEVICE_VENDORID,
 | 
			
		||||
    .idProduct          = TUSB_CFG_PRODUCT_ID,
 | 
			
		||||
    .idVendor           = CFG_VENDORID,
 | 
			
		||||
    .idProduct          = CFG_PRODUCTID,
 | 
			
		||||
    .bcdDevice          = 0x0100,
 | 
			
		||||
 | 
			
		||||
    .iManufacturer      = 0x01,
 | 
			
		||||
@@ -432,7 +432,7 @@ tusb_descriptor_string_t desc_str_serial =
 | 
			
		||||
    .unicode_string  = { '1', '2', '3', '4' } // len = 4
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
tusb_descriptor_string_t * const desc_str_table [] =
 | 
			
		||||
tusb_descriptor_string_t * const desc_str_table [TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT] =
 | 
			
		||||
{
 | 
			
		||||
    &desc_str_language,
 | 
			
		||||
    &desc_str_manufacturer,
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,10 @@
 | 
			
		||||
 | 
			
		||||
#include "tusb.h"
 | 
			
		||||
 | 
			
		||||
#define CFG_VENDORID            0x1FC9 // NXP
 | 
			
		||||
//#define CFG_PRODUCTID           0x4567 // use auto product id to prevent conflict with pc's driver
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define ENDPOINT_OUT_LOGICAL_TO_PHYSICAL(addr)      (addr)
 | 
			
		||||
#define ENDPOINT_IN_LOGICAL_TO_PHYSICAL(addr)       ((addr) | 0x80)
 | 
			
		||||
 | 
			
		||||
@@ -74,10 +78,10 @@
 | 
			
		||||
 | 
			
		||||
// each combination of interfaces need to have different productid, as windows will bind & remember device driver after the
 | 
			
		||||
// first plug.
 | 
			
		||||
#ifndef TUSB_CFG_PRODUCT_ID
 | 
			
		||||
#ifndef CFG_PRODUCTID
 | 
			
		||||
// Bitmap: MassStorage | Generic | Mouse | Key | CDC
 | 
			
		||||
#define PRODUCTID_BITMAP(interface, n)  ( (TUSB_CFG_DEVICE_##interface) << (n) )
 | 
			
		||||
#define TUSB_CFG_PRODUCT_ID             (0x4000 | ( PRODUCTID_BITMAP(CDC, 0) | PRODUCTID_BITMAP(HID_KEYBOARD, 1) | \
 | 
			
		||||
#define CFG_PRODUCTID                   (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
 | 
			
		||||
@@ -134,7 +138,7 @@ typedef ATTR_PACKED_STRUCT(struct)
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// STRINGS DESCRIPTOR
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
tusb_descriptor_string_t * const desc_str_table [];
 | 
			
		||||
tusb_descriptor_string_t * const desc_str_table[TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT];
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// Export descriptors
 | 
			
		||||
 
 | 
			
		||||
@@ -51,14 +51,14 @@
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// MACRO CONSTANT TYPEDEF
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
ATTR_USB_MIN_ALIGNMENT uint8_t set_report[ MAX_OF(sizeof(hid_keyboard_report_t), sizeof(hid_mouse_report_t)) ];
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  uint8_t const * p_report_desc;
 | 
			
		||||
  uint16_t report_length;
 | 
			
		||||
 | 
			
		||||
  endpoint_handle_t ept_handle;
 | 
			
		||||
  uint8_t interface_number;
 | 
			
		||||
 | 
			
		||||
  hid_keyboard_report_t report;  // need to be in usb ram
 | 
			
		||||
}hidd_interface_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -170,7 +170,7 @@ tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const *
 | 
			
		||||
        hid_request_report_type_t report_type = u16_high_u8(p_request->wValue);
 | 
			
		||||
        uint8_t report_id = u16_low_u8(p_request->wValue);
 | 
			
		||||
 | 
			
		||||
        dcd_pipe_control_xfer(coreid, TUSB_DIR_HOST_TO_DEV, &p_hid->report, p_request->wLength);
 | 
			
		||||
        dcd_pipe_control_xfer(coreid, TUSB_DIR_HOST_TO_DEV, &set_report, p_request->wLength);
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
 | 
			
		||||
@@ -260,9 +260,7 @@ void hidd_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_b
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if defined(CAP_DEVICE_ROMDRIVER) && TUSB_CFG_DEVICE_USE_ROM_DRIVER
 | 
			
		||||
#include "device/dcd_nxp_romdriver.h" // TODO remove rom driver dependency
 | 
			
		||||
 | 
			
		||||
#if defined(CAP_DEVICE_ROMDRIVER)
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// MACRO CONSTANT TYPEDEF
 | 
			
		||||
@@ -279,18 +277,6 @@ TUSB_CFG_ATTR_USBRAM hid_mouse_report_t hid_mouse_report;
 | 
			
		||||
static volatile bool bMouseChanged = false;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// INTERNAL OBJECT & FUNCTION DECLARATION
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
static tusb_error_t hidd_interface_init(tusb_descriptor_interface_t const *p_interface_desc, uint8_t const * const p_report_desc,
 | 
			
		||||
                                 uint32_t report_length, uint8_t* mem_base, uint32_t mem_size);
 | 
			
		||||
 | 
			
		||||
ErrorCode_t HID_GetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* plength);
 | 
			
		||||
ErrorCode_t HID_SetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length);
 | 
			
		||||
ErrorCode_t HID_EpIn_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event);
 | 
			
		||||
ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// APPLICATION API
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
@@ -338,54 +324,6 @@ tusb_error_t tusbd_hid_mouse_send_report(hid_mouse_report_t *p_mouse_report)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// CLASS-USBH API (don't require to verify parameters)
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
tusb_error_t hidd_configured(void)
 | 
			
		||||
{
 | 
			
		||||
  #if  TUSB_CFG_DEVICE_HID_KEYBOARD
 | 
			
		||||
    ROM_API->hw->WriteEP(romdriver_hdl , HID_KEYBOARD_EP_IN , (uint8_t* ) &hid_keyboard_report , sizeof(hid_keyboard_report_t) ); // initial packet for IN endpoint , will not work if omitted
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  #if  TUSB_CFG_DEVICE_HID_MOUSE
 | 
			
		||||
    ROM_API->hw->WriteEP(romdriver_hdl , HID_MOUSE_EP_IN    , (uint8_t* ) &hid_mouse_report    , sizeof(hid_mouse_report_t) ); // initial packet for IN endpoint, will not work if omitted
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  return TUSB_ERROR_NONE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
tusb_error_t hidd_interface_init(tusb_descriptor_interface_t const *p_interface_desc, uint8_t const * const p_report_desc,
 | 
			
		||||
                                 uint32_t report_length, uint8_t* mem_base, uint32_t mem_size)
 | 
			
		||||
{
 | 
			
		||||
  USB_HID_REPORT_T reports_data =
 | 
			
		||||
  {
 | 
			
		||||
      .desc      = (uint8_t*) p_report_desc,
 | 
			
		||||
      .len       = report_length,
 | 
			
		||||
      .idle_time = 0,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  USBD_HID_INIT_PARAM_T hid_param =
 | 
			
		||||
  {
 | 
			
		||||
      .mem_base       = (uint32_t) mem_base,
 | 
			
		||||
      .mem_size       = mem_size,
 | 
			
		||||
 | 
			
		||||
      .intf_desc      = (uint8_t*)p_interface_desc,
 | 
			
		||||
      .report_data    = &reports_data,
 | 
			
		||||
      .max_reports    = 1,
 | 
			
		||||
 | 
			
		||||
      /* user defined functions */
 | 
			
		||||
      .HID_GetReport  = HID_GetReport,
 | 
			
		||||
      .HID_SetReport  = HID_SetReport,
 | 
			
		||||
      .HID_EpIn_Hdlr  = HID_EpIn_Hdlr,
 | 
			
		||||
      .HID_EpOut_Hdlr = HID_EpOut_Hdlr
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  ASSERT( LPC_OK == ROM_API->hid->init(romdriver_hdl, &hid_param), TUSB_ERROR_FAILED );
 | 
			
		||||
 | 
			
		||||
  return TUSB_ERROR_NONE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// IMPLEMENTATION
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
 
 | 
			
		||||
@@ -92,6 +92,8 @@
 | 
			
		||||
#define STRING_CONCAT_(a, b) a##b                  // concat without expand
 | 
			
		||||
#define XSTRING_CONCAT_(a, b) STRING_CONCAT_(a, b) // expand then concat
 | 
			
		||||
 | 
			
		||||
#define MAX_OF(a, b)  ( (a) > (b) ? (a) : (b) )
 | 
			
		||||
 | 
			
		||||
#define U16_HIGH_U8(u16) ((uint8_t) (((u16) >> 8) & 0x00ff))
 | 
			
		||||
#define U16_LOW_U8(u16)  ((uint8_t) ((u16)       & 0x00ff))
 | 
			
		||||
#define U16_TO_U8S_BE(u16)  U16_HIGH_U8(u16), U16_LOW_U8(u16)
 | 
			
		||||
 
 | 
			
		||||
@@ -38,118 +38,7 @@
 | 
			
		||||
 | 
			
		||||
#include "dcd.h"
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
#if MODE_DEVICE_SUPPORTED
 | 
			
		||||
 | 
			
		||||
#include "descriptors.h" // TODO refractor later
 | 
			
		||||
 | 
			
		||||
#define USB_ROM_SIZE (1024*2) // TODO dcd abstract later
 | 
			
		||||
uint8_t usb_RomDriver_buffer[USB_ROM_SIZE] ATTR_ALIGNED(2048) TUSB_CFG_ATTR_USBRAM;
 | 
			
		||||
USBD_HANDLE_T romdriver_hdl;
 | 
			
		||||
static volatile bool isConfigured = false;
 | 
			
		||||
 | 
			
		||||
/**************************************************************************/
 | 
			
		||||
/*!
 | 
			
		||||
    @brief Handler for the USB Configure Event
 | 
			
		||||
*/
 | 
			
		||||
/**************************************************************************/
 | 
			
		||||
ErrorCode_t USB_Configure_Event (USBD_HANDLE_T hUsb)
 | 
			
		||||
{
 | 
			
		||||
  USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*)hUsb;
 | 
			
		||||
  if (pCtrl->config_value)
 | 
			
		||||
  {
 | 
			
		||||
    #if defined(DEVICE_CLASS_HID)
 | 
			
		||||
    ASSERT( TUSB_ERROR_NONE == tusb_hid_configured(hUsb), ERR_FAILED );
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #ifdef TUSB_CFG_DEVICE_CDC
 | 
			
		||||
    ASSERT( TUSB_ERROR_NONE == tusb_cdc_configured(hUsb), ERR_FAILED );
 | 
			
		||||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  isConfigured = true;
 | 
			
		||||
 | 
			
		||||
  return LPC_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**************************************************************************/
 | 
			
		||||
/*!
 | 
			
		||||
    @brief Handler for the USB Reset Event
 | 
			
		||||
*/
 | 
			
		||||
/**************************************************************************/
 | 
			
		||||
ErrorCode_t USB_Reset_Event (USBD_HANDLE_T hUsb)
 | 
			
		||||
{
 | 
			
		||||
  isConfigured = false;
 | 
			
		||||
  return LPC_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tusb_error_t dcd_init(uint8_t coreid)
 | 
			
		||||
{
 | 
			
		||||
#ifdef DEVICE_ROMDRIVER // TODO refractor later
 | 
			
		||||
  /* ROM DRIVER INIT */
 | 
			
		||||
  uint32_t membase = (uint32_t) usb_RomDriver_buffer;
 | 
			
		||||
  uint32_t memsize = USB_ROM_SIZE;
 | 
			
		||||
 | 
			
		||||
  USBD_API_INIT_PARAM_T usb_param =
 | 
			
		||||
  {
 | 
			
		||||
    .usb_reg_base        = NXP_ROMDRIVER_REG_BASE,
 | 
			
		||||
    .max_num_ep          = USB_MAX_EP_NUM,
 | 
			
		||||
    .mem_base            = membase,
 | 
			
		||||
    .mem_size            = memsize,
 | 
			
		||||
 | 
			
		||||
    .USB_Configure_Event = USB_Configure_Event,
 | 
			
		||||
    .USB_Reset_Event     = USB_Reset_Event
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  USB_CORE_DESCS_T DeviceDes =
 | 
			
		||||
  {
 | 
			
		||||
    .device_desc      = (uint8_t*) &USB_DeviceDescriptor,
 | 
			
		||||
    .string_desc      = (uint8_t*) &USB_StringDescriptor,
 | 
			
		||||
    .full_speed_desc  = (uint8_t*) &USB_FsConfigDescriptor,
 | 
			
		||||
    .high_speed_desc  = (uint8_t*) &USB_FsConfigDescriptor,
 | 
			
		||||
    .device_qualifier = NULL
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  /* USB hardware core initialization */
 | 
			
		||||
  ASSERT(LPC_OK == ROM_API->hw->Init(&romdriver_hdl, &DeviceDes, &usb_param), TUSB_ERROR_FAILED);
 | 
			
		||||
 | 
			
		||||
  membase += (memsize - usb_param.mem_size);
 | 
			
		||||
  memsize = usb_param.mem_size;
 | 
			
		||||
 | 
			
		||||
  /* Initialise the class driver(s) */
 | 
			
		||||
  #ifdef TUSB_CFG_DEVICE_CDC
 | 
			
		||||
  ASSERT_STATUS( tusb_cdc_init(romdriver_hdl, &USB_FsConfigDescriptor.CDC_CCI_Interface,
 | 
			
		||||
            &USB_FsConfigDescriptor.CDC_DCI_Interface, &membase, &memsize) );
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  #ifdef TUSB_CFG_DEVICE_HID_KEYBOARD
 | 
			
		||||
  ASSERT_STATUS( tusb_hid_init(romdriver_hdl , &USB_FsConfigDescriptor.HID_KeyboardInterface ,
 | 
			
		||||
            HID_KeyboardReportDescriptor, USB_FsConfigDescriptor.HID_KeyboardHID.DescriptorList[0].wDescriptorLength,
 | 
			
		||||
            &membase , &memsize) );
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  #ifdef TUSB_CFG_DEVICE_HID_MOUSE
 | 
			
		||||
  ASSERT_STATUS( tusb_hid_init(romdriver_hdl , &USB_FsConfigDescriptor.HID_MouseInterface    ,
 | 
			
		||||
            HID_MouseReportDescriptor, USB_FsConfigDescriptor.HID_MouseHID.DescriptorList[0].wDescriptorLength,
 | 
			
		||||
            &membase , &memsize) );
 | 
			
		||||
  #endif
 | 
			
		||||
 | 
			
		||||
  hal_interrupt_enable(); /* Enable the USB interrupt */
 | 
			
		||||
 | 
			
		||||
  /* Perform USB soft connect */
 | 
			
		||||
  ROM_API->hw->Connect(romdriver_hdl, 1);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  return TUSB_ERROR_NONE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**************************************************************************/
 | 
			
		||||
/*!
 | 
			
		||||
    @brief Indicates whether USB is configured or not
 | 
			
		||||
*/
 | 
			
		||||
/**************************************************************************/
 | 
			
		||||
bool usb_isConfigured(void)
 | 
			
		||||
{
 | 
			
		||||
  return isConfigured;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -234,6 +234,10 @@ void dcd_isr(uint8_t coreid)
 | 
			
		||||
  { // received control request from host
 | 
			
		||||
    // copy setup request & acknowledge so that the next setup can be received by hw
 | 
			
		||||
    tusb_control_request_t control_request =  dcd_data.setup_request;
 | 
			
		||||
 | 
			
		||||
    // NXP control flowchart clear Active & Stall on both Control IN/OUT endpoints
 | 
			
		||||
    dcd_data.qhd[0][0].stall = dcd_data.qhd[1][0].stall = 0;
 | 
			
		||||
 | 
			
		||||
    LPC_USB->DEVCMDSTAT |= CMDSTAT_MASK_SETUP_RECEIVED;
 | 
			
		||||
    dcd_data.qhd[0][1].buff_addr_offset = addr_offset(&dcd_data.setup_request);
 | 
			
		||||
 | 
			
		||||
@@ -264,9 +268,10 @@ void dcd_isr(uint8_t coreid)
 | 
			
		||||
// CONTROL PIPE API
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
void dcd_pipe_control_stall(uint8_t coreid)
 | 
			
		||||
{ // only need to stall IN Control endpoint
 | 
			
		||||
{ // TODO cannot able to STALL Control OUT endpoint !!!!!
 | 
			
		||||
  (void) coreid;
 | 
			
		||||
  dcd_data.qhd[1][0].stall = 1;
 | 
			
		||||
 | 
			
		||||
  dcd_data.qhd[0][0].stall = dcd_data.qhd[1][0].stall = 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// control transfer does not need to use qtd find function
 | 
			
		||||
@@ -340,6 +345,7 @@ tusb_error_t dcd_pipe_clear_stall(uint8_t coreid, uint8_t edpt_addr)
 | 
			
		||||
 | 
			
		||||
  dcd_data.qhd[ep_id][0].stall           = 0;
 | 
			
		||||
  dcd_data.qhd[ep_id][0].toggle_reset    = 1;
 | 
			
		||||
  dcd_data.qhd[ep_id][0].feedback_toggle = 0;
 | 
			
		||||
 | 
			
		||||
  return TUSB_ERROR_NONE;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,170 +0,0 @@
 | 
			
		||||
/**************************************************************************/
 | 
			
		||||
/*!
 | 
			
		||||
    @file     dcd_nxp_romdriver.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_option.h"
 | 
			
		||||
 | 
			
		||||
#if MODE_DEVICE_SUPPORTED && (defined(CAP_DEVICE_ROMDRIVER) && TUSB_CFG_DEVICE_USE_ROM_DRIVER)
 | 
			
		||||
 | 
			
		||||
#define _TINY_USB_SOURCE_FILE_
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// INCLUDE
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
#include "dcd.h"
 | 
			
		||||
#include "dcd_nxp_romdriver.h"
 | 
			
		||||
#include "tusb_descriptors.h"
 | 
			
		||||
 | 
			
		||||
#define USB_ROM_SIZE (1024*2) // TODO dcd abstract later
 | 
			
		||||
uint8_t usb_RomDriver_buffer[USB_ROM_SIZE] ATTR_ALIGNED(2048) TUSB_CFG_ATTR_USBRAM;
 | 
			
		||||
 | 
			
		||||
USBD_HANDLE_T romdriver_hdl;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  volatile uint8_t state;
 | 
			
		||||
}usbd_info_t; // TODO rename
 | 
			
		||||
 | 
			
		||||
usbd_info_t usbd_info; // TODO rename
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// MACRO CONSTANT TYPEDEF
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// INTERNAL OBJECT & FUNCTION DECLARATION
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
// IMPLEMENTATION
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
ErrorCode_t USB_Configure_Event (USBD_HANDLE_T hUsb)
 | 
			
		||||
{
 | 
			
		||||
  USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*)hUsb;
 | 
			
		||||
 | 
			
		||||
  if (pCtrl->config_value)
 | 
			
		||||
  {
 | 
			
		||||
    usbd_info.state = TUSB_DEVICE_STATE_CONFIGURED;
 | 
			
		||||
 | 
			
		||||
    #if DEVICE_CLASS_HID
 | 
			
		||||
    ASSERT( TUSB_ERROR_NONE == hidd_configured(), ERR_FAILED );
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    #if TUSB_CFG_DEVICE_CDC
 | 
			
		||||
    ASSERT( TUSB_ERROR_NONE == tusb_cdc_configured(hUsb), ERR_FAILED );
 | 
			
		||||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return LPC_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ErrorCode_t USB_Reset_Event (USBD_HANDLE_T hUsb)
 | 
			
		||||
{
 | 
			
		||||
  usbd_info.state = TUSB_DEVICE_STATE_UNPLUG;
 | 
			
		||||
  return LPC_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ErrorCode_t USB_Interface_Event (USBD_HANDLE_T hUsb)
 | 
			
		||||
{
 | 
			
		||||
  return LPC_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ErrorCode_t USB_Error_Event (USBD_HANDLE_T hUsb, uint32_t param1)
 | 
			
		||||
{
 | 
			
		||||
  (void) param1;
 | 
			
		||||
  return LPC_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tusb_error_t dcd_init(void)
 | 
			
		||||
{
 | 
			
		||||
  USBD_API_INIT_PARAM_T usb_param =
 | 
			
		||||
  {
 | 
			
		||||
    .usb_reg_base        = NXP_ROMDRIVER_REG_BASE,
 | 
			
		||||
    .max_num_ep          = USB_MAX_EP_NUM,
 | 
			
		||||
    .mem_base            = (uint32_t) usb_RomDriver_buffer,
 | 
			
		||||
    .mem_size            = USB_ROM_SIZE,
 | 
			
		||||
 | 
			
		||||
    .USB_Configure_Event = USB_Configure_Event,
 | 
			
		||||
    .USB_Reset_Event     = USB_Reset_Event,
 | 
			
		||||
    .USB_Error_Event     = USB_Error_Event,
 | 
			
		||||
    .USB_Interface_Event = USB_Interface_Event
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  USB_CORE_DESCS_T desc_core =
 | 
			
		||||
  {
 | 
			
		||||
    .device_desc      = (uint8_t*) &app_tusb_desc_device,
 | 
			
		||||
    .string_desc      = (uint8_t*) &app_tusb_desc_strings,
 | 
			
		||||
    .full_speed_desc  = (uint8_t*) &app_tusb_desc_configuration,
 | 
			
		||||
    .high_speed_desc  = (uint8_t*) &app_tusb_desc_configuration,
 | 
			
		||||
    .device_qualifier = NULL
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  /* USB hardware core initialization */
 | 
			
		||||
  ASSERT_INT(LPC_OK, ROM_API->hw->Init(&romdriver_hdl, &desc_core, &usb_param), TUSB_ERROR_FAILED);
 | 
			
		||||
 | 
			
		||||
  // TODO need to confirm the mem_size is reduced by the number of byte used
 | 
			
		||||
//  membase += (memsize - usb_param.mem_size);
 | 
			
		||||
//  memsize = usb_param.mem_size;
 | 
			
		||||
 | 
			
		||||
  return TUSB_ERROR_NONE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool tusb_device_is_configured(void)
 | 
			
		||||
{
 | 
			
		||||
  return usbd_info.state == TUSB_DEVICE_STATE_CONFIGURED;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
tusb_error_t dcd_controller_reset(uint8_t coreid)
 | 
			
		||||
{
 | 
			
		||||
//TODO merge with hcd_controller_reset
 | 
			
		||||
// default mode is device ?
 | 
			
		||||
  return TUSB_ERROR_NONE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dcd_controller_connect(uint8_t coreid)
 | 
			
		||||
{
 | 
			
		||||
  ROM_API->hw->Connect(romdriver_hdl, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dcd_isr(uint8_t coreid)
 | 
			
		||||
{
 | 
			
		||||
  ROM_API->hw->ISR(romdriver_hdl);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@@ -1,78 +0,0 @@
 | 
			
		||||
/**************************************************************************/
 | 
			
		||||
/*!
 | 
			
		||||
    @file     dcd_nxp_romdriver.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_DCD_NXP_ROMDRIVER_H_
 | 
			
		||||
#define _TUSB_DCD_NXP_ROMDRIVER_H_
 | 
			
		||||
 | 
			
		||||
#include "common/common.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
 extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define USB_MAX_IF_NUM          8 // maximum interface number supported, should be fixed to 8
 | 
			
		||||
 | 
			
		||||
#if (MCU == MCU_LPC18XX) || (MCU == MCU_LPC43XX)
 | 
			
		||||
  #define ROM_API                 ( * ((USBD_API_T**) NXP_ROMDRIVER_FUNCTION_ADDR) )
 | 
			
		||||
  #define USB_MAX_EP_NUM          6
 | 
			
		||||
#elif (MCU == MCU_LPC13UXX) || (MCU == MCU_LPC11UXX)
 | 
			
		||||
  #define ROM_API                 ( * (*((USBD_API_T***) NXP_ROMDRIVER_FUNCTION_ADDR)) )
 | 
			
		||||
  #define USB_MAX_EP_NUM          5
 | 
			
		||||
#else
 | 
			
		||||
  #error forgot something, thach ?
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "romdriver/mw_usbd_rom_api.h"
 | 
			
		||||
 | 
			
		||||
extern USBD_HANDLE_T romdriver_hdl;
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
 }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif /* _TUSB_DCD_NXP_ROMDRIVER_H_ */
 | 
			
		||||
 | 
			
		||||
/** @} */
 | 
			
		||||
@@ -199,6 +199,8 @@ tusb_error_t std_get_descriptor(uint8_t coreid, tusb_control_request_t * p_reque
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
    case TUSB_DESC_TYPE_STRING:
 | 
			
		||||
      if ( ! (desc_index < TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT) ) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
 | 
			
		||||
 | 
			
		||||
      dcd_pipe_control_xfer(coreid, TUSB_DIR_DEV_TO_HOST, desc_str_table[desc_index], desc_str_table[desc_index]->bLength);
 | 
			
		||||
    break;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -164,11 +164,6 @@
 | 
			
		||||
//--------------------------------------------------------------------+
 | 
			
		||||
#if MODE_DEVICE_SUPPORTED
 | 
			
		||||
 | 
			
		||||
// TODO only support non rom driver
 | 
			
		||||
//#if defined(CAP_DEVICE_ROMDRIVER) && !TUSB_CFG_DEVICE_USE_ROM_DRIVER
 | 
			
		||||
//  #error only rom driver for these mcu are supported now
 | 
			
		||||
//#endif
 | 
			
		||||
 | 
			
		||||
#define DEVICE_CLASS_HID ( TUSB_CFG_DEVICE_HID_KEYBOARD + TUSB_CFG_DEVICE_HID_MOUSE + TUSB_CFG_DEVICE_HID_GENERIC )
 | 
			
		||||
 | 
			
		||||
#if TUSB_CFG_DEVICE_CONTROL_ENDOINT_SIZE > 64
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user