add coreid to hidd_init
temporarily implement hidd_init using dcd from lpc17xx add more test for dcd lp176x implement dcd_endpoint_configure
This commit is contained in:
parent
ee57a6f13f
commit
4103cc374f
|
@ -93,7 +93,7 @@ void led_blinking_task(void * p_para)
|
|||
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
void keyboard_device_app_task(void * p_para)
|
||||
{
|
||||
#if 1
|
||||
#if 0
|
||||
if (tusb_device_is_configured())
|
||||
{
|
||||
static uint32_t count =0;
|
||||
|
|
|
@ -44,12 +44,16 @@
|
|||
#include "mock_usbd_dcd.h"
|
||||
#include "dcd_lpc175x_6x.h"
|
||||
|
||||
LPC_USB_TypeDef lpc_usb;
|
||||
usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER];
|
||||
extern dcd_dma_descriptor_t* dcd_udca[32];
|
||||
extern dcd_dma_descriptor_t dcd_dd[DCD_MAX_DD];
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
|
||||
memclr_(dcd_udca, 32*4);
|
||||
memclr_(dcd_dd, sizeof(dcd_dma_descriptor_t)*DCD_MAX_DD);
|
||||
memclr_(&lpc_usb, sizeof(LPC_USB_TypeDef));
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
|
@ -88,3 +92,69 @@ void test_dd_structure(void)
|
|||
//------------- word 4 -------------//
|
||||
}
|
||||
|
||||
void test_dcd_init(void)
|
||||
{
|
||||
|
||||
//------------- Code Under Test -------------//
|
||||
dcd_init();
|
||||
|
||||
//------------- slave check -------------//
|
||||
TEST_ASSERT_EQUAL_HEX( BIN8(11), LPC_USB->USBEpIntEn );
|
||||
TEST_ASSERT_EQUAL_HEX( DEV_INT_DEVICE_STATUS_MASK | DEV_INT_ENDPOINT_SLOW_MASK | DEV_INT_ERROR_MASK,
|
||||
LPC_USB->USBDevIntEn );
|
||||
TEST_ASSERT_EQUAL_HEX( 0, LPC_USB->USBEpIntPri);
|
||||
|
||||
//------------- DMA check -------------//
|
||||
for (uint32_t i=0; i<32; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_HEX(dcd_dd+i, dcd_udca[i]);
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL_HEX(dcd_udca, LPC_USB->USBUDCAH);
|
||||
TEST_ASSERT_EQUAL_HEX(DMA_INT_END_OF_XFER_MASK | DMA_INT_NEW_DD_REQUEST_MASK | DMA_INT_ERROR_MASK,
|
||||
LPC_USB->USBDMAIntEn);
|
||||
|
||||
}
|
||||
|
||||
void test_dcd_configure_endpoint_in(void)
|
||||
{
|
||||
tusb_descriptor_endpoint_t const desc_endpoint =
|
||||
{
|
||||
.bLength = sizeof(tusb_descriptor_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_TYPE_ENDPOINT,
|
||||
.bEndpointAddress = 0x83,
|
||||
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
|
||||
.wMaxPacketSize = { .size = 0x08 },
|
||||
.bInterval = 0x0A
|
||||
};
|
||||
|
||||
dcd_init();
|
||||
memclr_(&lpc_usb, sizeof(LPC_USB_TypeDef)); // clear to examine register after CUT
|
||||
|
||||
//------------- Code Under Test -------------//
|
||||
dcd_endpoint_configure(0, &desc_endpoint);
|
||||
|
||||
uint8_t const phy_ep = 2*3 + 1;
|
||||
TEST_ASSERT_EQUAL_HEX( BIT_(phy_ep), LPC_USB->USBReEp);
|
||||
TEST_ASSERT_EQUAL_HEX( phy_ep, LPC_USB->USBEpInd);
|
||||
TEST_ASSERT_EQUAL( desc_endpoint.wMaxPacketSize.size, LPC_USB->USBMaxPSize);
|
||||
|
||||
TEST_ASSERT_FALSE( dcd_dd[phy_ep].is_next_valid );
|
||||
TEST_ASSERT_EQUAL_HEX( 0, dcd_dd[phy_ep].next );
|
||||
TEST_ASSERT_EQUAL( 0, dcd_dd[phy_ep].mode);
|
||||
TEST_ASSERT_FALSE( dcd_dd[phy_ep].is_isochronous );
|
||||
TEST_ASSERT_EQUAL( 0, dcd_dd[phy_ep].buffer_length);
|
||||
TEST_ASSERT_EQUAL_HEX( 0, dcd_dd[phy_ep].buffer_start_addr);
|
||||
TEST_ASSERT_TRUE( dcd_dd[phy_ep].is_retired );
|
||||
TEST_ASSERT_EQUAL( DD_STATUS_NOT_SERVICED, dcd_dd[phy_ep].status);
|
||||
TEST_ASSERT_FALSE( dcd_dd[phy_ep].iso_last_packet_valid );
|
||||
TEST_ASSERT_FALSE( dcd_dd[phy_ep].atle_is_lsb_extracted );
|
||||
TEST_ASSERT_FALSE( dcd_dd[phy_ep].atle_is_msb_extracted );
|
||||
TEST_ASSERT_FALSE( dcd_dd[phy_ep].atle_message_length_position );
|
||||
TEST_ASSERT_FALSE( dcd_dd[phy_ep].present_count );
|
||||
}
|
||||
|
||||
void test_dcd_configure_endpoint_out(void)
|
||||
{
|
||||
TEST_IGNORE();
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ tusb_error_t stub_hidd_init(tusb_descriptor_interface_t const* p_interface_desc,
|
|||
void class_init_epxect(void)
|
||||
{
|
||||
#if DEVICE_CLASS_HID
|
||||
hidd_init_StubWithCallback(stub_hidd_init);
|
||||
// hidd_init_StubWithCallback(stub_hidd_init);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,55 @@
|
|||
#include "hid_device.h"
|
||||
#include "tusb_descriptors.h"
|
||||
|
||||
|
||||
|
||||
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
|
||||
{
|
||||
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
|
||||
|
||||
//------------- HID descriptor -------------//
|
||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
|
||||
tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||
ASSERT_INT(HID_DESC_TYPE_HID, p_desc_hid->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
|
||||
//------------- Endpoint Descriptor -------------//
|
||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
|
||||
tusb_descriptor_endpoint_t const *p_desc_endpoint = (tusb_descriptor_endpoint_t const *) p_desc;
|
||||
ASSERT_INT(TUSB_DESC_TYPE_ENDPOINT, p_desc_endpoint->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
|
||||
if (p_interface_desc->bInterfaceSubClass == HID_SUBCLASS_BOOT)
|
||||
{
|
||||
switch(p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
case HID_PROTOCOL_KEYBOARD:
|
||||
ASSERT_STATUS( dcd_endpoint_configure(coreid, p_desc_endpoint) );
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_DEVICE_HID_MOUSE
|
||||
case HID_PROTOCOL_MOUSE:
|
||||
ASSERT_STATUS( hidd_interface_init(p_interface_desc,
|
||||
app_tusb_mouse_desc_report, p_desc_hid->wReportLength,
|
||||
hidd_mouse_buffer , sizeof(hidd_mouse_buffer)) );
|
||||
break;
|
||||
#endif
|
||||
|
||||
default: // TODO unknown, unsupported protocol --> skip this interface
|
||||
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
|
||||
}
|
||||
*p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
|
||||
}else
|
||||
{
|
||||
// open generic
|
||||
*p_length = 0;
|
||||
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
|
||||
}
|
||||
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
#if defined(CAP_DEVICE_ROMDRIVER) && TUSB_CFG_DEVICE_USE_ROM_DRIVER
|
||||
#include "device/dcd_nxp_romdriver.h" // TODO remove rom driver dependency
|
||||
|
||||
|
@ -70,8 +119,8 @@ static volatile bool bMouseChanged = false;
|
|||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
static tusb_error_t hidd_interface_init(tusb_descriptor_interface_t const *pIntfDesc, uint8_t const * const pHIDReportDesc,
|
||||
uint32_t ReportDescLength, uint8_t* mem_base, uint32_t mem_size);
|
||||
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);
|
||||
|
@ -186,13 +235,13 @@ tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc, uin
|
|||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
tusb_error_t hidd_interface_init(tusb_descriptor_interface_t const *pIntfDesc, uint8_t const * const pHIDReportDesc,
|
||||
uint32_t ReportDescLength, uint8_t* mem_base, uint32_t mem_size)
|
||||
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*) pHIDReportDesc,
|
||||
.len = ReportDescLength,
|
||||
.desc = (uint8_t*) p_report_desc,
|
||||
.len = report_length,
|
||||
.idle_time = 0,
|
||||
};
|
||||
|
||||
|
@ -201,7 +250,7 @@ tusb_error_t hidd_interface_init(tusb_descriptor_interface_t const *pIntfDesc, u
|
|||
.mem_base = (uint32_t) mem_base,
|
||||
.mem_size = mem_size,
|
||||
|
||||
.intf_desc = (uint8_t*)pIntfDesc,
|
||||
.intf_desc = (uint8_t*)p_interface_desc,
|
||||
.report_data = &reports_data,
|
||||
.max_reports = 1,
|
||||
|
||||
|
@ -212,7 +261,6 @@ tusb_error_t hidd_interface_init(tusb_descriptor_interface_t const *pIntfDesc, u
|
|||
.HID_EpOut_Hdlr = HID_EpOut_Hdlr
|
||||
};
|
||||
|
||||
ASSERT( (pIntfDesc != NULL) && (pIntfDesc->bInterfaceClass == USB_DEVICE_CLASS_HUMAN_INTERFACE), ERR_FAILED);
|
||||
ASSERT( LPC_OK == ROM_API->hid->init(romdriver_hdl, &hid_param), TUSB_ERROR_FAILED );
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
|
|
|
@ -65,7 +65,7 @@ tusb_error_t tusbd_hid_mouse_send_report(tusb_mouse_report_t *p_mouse_report);
|
|||
//--------------------------------------------------------------------+
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
tusb_error_t hidd_configured(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
STATIC_ dcd_dma_descriptor_t* dcd_udca[32] ATTR_ALIGNED(128) TUSB_CFG_ATTR_USBRAM;
|
||||
STATIC_ dcd_dma_descriptor_t dcd_dd[DCD_MAX_DD];
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
|
@ -71,7 +72,9 @@ static inline void sie_commamd_code (uint8_t phase, uint8_t code_data)
|
|||
LPC_USB->USBCmdCode = (phase << 8) | (code_data << 16);
|
||||
|
||||
uint32_t const wait_flag = (phase == SIE_CMDPHASE_READ) ? DEV_INT_COMMAND_DATA_FULL_MASK : DEV_INT_COMMAND_CODE_EMPTY_MASK;
|
||||
#ifndef _TEST_
|
||||
while ((LPC_USB->USBDevIntSt & wait_flag) == 0); // TODO blocking forever potential
|
||||
#endif
|
||||
LPC_USB->USBDevIntClr = wait_flag;
|
||||
}
|
||||
|
||||
|
@ -195,7 +198,10 @@ tusb_error_t dcd_init(void)
|
|||
// step 6 : set up control endpoint
|
||||
endpoint_set_max_packet_size(0, TUSB_CFG_DEVICE_CONTROL_PACKET_SIZE);
|
||||
endpoint_set_max_packet_size(1, TUSB_CFG_DEVICE_CONTROL_PACKET_SIZE);
|
||||
|
||||
#ifndef _TEST_
|
||||
while ((LPC_USB->USBDevIntSt & DEV_INT_ENDPOINT_REALIZED_MASK) == 0);
|
||||
#endif
|
||||
|
||||
// step 7 : slave mode set up
|
||||
LPC_USB->USBEpIntEn = (uint32_t) BIN8(11); // control endpoint cannot use DMA, non-control all use DMA
|
||||
|
@ -215,7 +221,7 @@ tusb_error_t dcd_init(void)
|
|||
|
||||
for (uint8_t index = 0; index < DCD_MAX_DD; index++)
|
||||
{
|
||||
dcd_udca[index] = 0;
|
||||
dcd_udca[index] = dcd_dd + index;
|
||||
}
|
||||
LPC_USB->USBUDCAH = (uint32_t) dcd_udca;
|
||||
LPC_USB->USBDMAIntEn = (DMA_INT_END_OF_XFER_MASK | DMA_INT_NEW_DD_REQUEST_MASK | DMA_INT_ERROR_MASK );
|
||||
|
@ -227,8 +233,35 @@ tusb_error_t dcd_init(void)
|
|||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
static inline uint8_t endpoint_address_to_physical_index(uint8_t ep_address) ATTR_ALWAYS_INLINE ATTR_CONST;
|
||||
static inline uint8_t endpoint_address_to_physical_index(uint8_t ep_address)
|
||||
{
|
||||
return (ep_address << 1) + (ep_address & 0x80 ? 1 : 0 );
|
||||
}
|
||||
|
||||
tusb_error_t dcd_endpoint_configure(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc)
|
||||
{
|
||||
uint8_t phy_ep = endpoint_address_to_physical_index( p_endpoint_desc->bEndpointAddress );
|
||||
|
||||
//------------- Realize Endpoint with Max Packet Size -------------//
|
||||
LPC_USB->USBReEp |= BIT_(phy_ep);
|
||||
endpoint_set_max_packet_size(phy_ep, p_endpoint_desc->wMaxPacketSize.size);
|
||||
|
||||
#ifndef _TEST_
|
||||
while ((LPC_USB->USBDevIntSt & DEV_INT_ENDPOINT_REALIZED_MASK) == 0) {} // TODO can be omitted
|
||||
#endif
|
||||
LPC_USB->USBDevIntClr = DEV_INT_ENDPOINT_REALIZED_MASK;
|
||||
|
||||
//------------- DMA set up -------------//
|
||||
memclr_(dcd_dd + phy_ep, sizeof(dcd_dma_descriptor_t));
|
||||
dcd_dd[phy_ep].is_isochronous = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) ? 1 : 0;
|
||||
dcd_dd[phy_ep].max_packet_size = p_endpoint_desc->wMaxPacketSize.size;
|
||||
dcd_dd[phy_ep].is_retired = 1; // dd is not active at first
|
||||
|
||||
LPC_USB->USBEpDMAEn = BIT_(phy_ep);
|
||||
|
||||
sie_command_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+phy_ep, 1, 0); // clear all endpoint status
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
@ -276,6 +309,7 @@ tusb_error_t dcd_pipe_control_read(uint8_t coreid)
|
|||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
// TODO inline function
|
||||
void dcd_pipe_control_write_zero_length(uint8_t coreid)
|
||||
{
|
||||
dcd_pipe_control_write(coreid, NULL, 0);
|
||||
|
|
|
@ -59,7 +59,7 @@ typedef struct
|
|||
uint32_t next;
|
||||
|
||||
//------------- Word 1 -------------//
|
||||
uint16_t mode : 2; // either normal or ATLE(auto length extraction)
|
||||
uint16_t mode : 2; // either 00 normal or 01 ATLE(auto length extraction)
|
||||
uint16_t is_next_valid : 1;
|
||||
uint16_t : 1;
|
||||
uint16_t is_isochronous : 1; // is an iso endpoint
|
||||
|
@ -83,11 +83,12 @@ typedef struct
|
|||
// uint32_t iso_packet_size_addr; // iso only, can be omitted for non-iso
|
||||
} ATTR_ALIGNED(4) dcd_dma_descriptor_t;
|
||||
|
||||
#define DCD_MAX_DD 10 // TODO scale with configure
|
||||
typedef struct {
|
||||
dcd_dma_descriptor_t dd[DCD_MAX_DD];
|
||||
#define DCD_MAX_DD 32 // TODO scale with configure
|
||||
|
||||
}dcd_data_t;
|
||||
//typedef struct {
|
||||
// dcd_dma_descriptor_t dd[DCD_MAX_DD];
|
||||
//
|
||||
//}dcd_data_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Register Interface
|
||||
|
@ -188,6 +189,16 @@ enum {
|
|||
SIE_ENDPOINT_STATUS_BUFFER2_FULL_MASK = BIT_(6)
|
||||
};
|
||||
|
||||
//------------- DMA Descriptor Status -------------//
|
||||
enum {
|
||||
DD_STATUS_NOT_SERVICED = 0,
|
||||
DD_STATUS_BEING_SERVICED,
|
||||
DD_STATUS_NORMAL,
|
||||
DD_STATUS_DATA_UNDERUN, // short packet
|
||||
DD_STATUS_DATA_OVERRUN,
|
||||
DD_STATUS_SYSTEM_ERROR
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -158,11 +158,11 @@ tusb_error_t usbd_init (void)
|
|||
|
||||
uint16_t length = 0;
|
||||
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
ASSERT_STATUS( hidd_init(&app_tusb_desc_configuration.keyboard_interface, &length) );
|
||||
ASSERT_STATUS( hidd_init(0, &app_tusb_desc_configuration.keyboard_interface, &length) );
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_DEVICE_HID_MOUSE
|
||||
ASSERT_STATUS( hidd_init(&app_tusb_desc_configuration.mouse_interface, &length) );
|
||||
#if TUSB_CFG_DEVICE_HID_MOUSE && 0
|
||||
ASSERT_STATUS( hidd_init(0, &app_tusb_desc_configuration.mouse_interface, &length) );
|
||||
#endif
|
||||
|
||||
usbd_bus_reset(0);
|
||||
|
|
Loading…
Reference in New Issue