From 5ab195a73d58bcf8d104a7b49d2674368c292792 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 29 Oct 2013 15:09:16 +0700 Subject: [PATCH] temporarily implementation of dcd_pipe_is_busy --- demos/device/keyboard/main.c | 23 ++++++++++++----------- tinyusb/class/hid_device.c | 5 +++++ tinyusb/class/hid_device.h | 18 ++++++++++++++++-- tinyusb/device/dcd_lpc43xx.c | 28 +++++++++++++++++----------- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/demos/device/keyboard/main.c b/demos/device/keyboard/main.c index 5f1ee860..733aab3d 100644 --- a/demos/device/keyboard/main.c +++ b/demos/device/keyboard/main.c @@ -85,17 +85,18 @@ void led_blinking_task(void * p_para) hid_keyboard_report_t keyboard_report TUSB_CFG_ATTR_USBRAM; void keyboard_device_app_task(void * p_para) { -// if (tusbd_is_configured(0)) -// { -// static uint32_t count =0; -// if (count < 10) -// { -// count++; -// -// keyboard_report.keycode[0] = 0x04; -// tusbd_hid_keyboard_send(0, &keyboard_report ); -// } -// } + if (tusbd_is_configured(0)) + { + static uint32_t count =0; + if (count++ < 10) + { + keyboard_report.keycode[0] = (count%2) ? 0x04 : 0x00; + if (!tusbd_hid_keyboard_is_busy(0)) + { + tusbd_hid_keyboard_send(0, &keyboard_report ); + } + } + } } #endif diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c index b2733978..14258c49 100644 --- a/tinyusb/class/hid_device.c +++ b/tinyusb/class/hid_device.c @@ -351,6 +351,11 @@ ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event) //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ +bool tusbd_hid_keyboard_is_busy(uint8_t coreid) +{ + return dcd_pipe_is_busy(keyboardd_data.ept_handle); +} + tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const *p_kbd_report) { //------------- verify data -------------// diff --git a/tinyusb/class/hid_device.h b/tinyusb/class/hid_device.h index 9c63e2dd..c74148d2 100644 --- a/tinyusb/class/hid_device.h +++ b/tinyusb/class/hid_device.h @@ -47,22 +47,36 @@ extern "C" { #endif + //--------------------------------------------------------------------+ // KEYBOARD Application API //--------------------------------------------------------------------+ /** \addtogroup ClassDriver_HID_Keyboard Keyboard * @{ */ - /** \defgroup Keyboard_Device Device - * The interface API includes status checking function, data transferring function and callback functions * @{ */ +bool tusbd_hid_keyboard_is_busy(uint8_t coreid); tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const *p_kbd_report); + +/** @} */ +/** @} */ + +//--------------------------------------------------------------------+ +// MOUSE APPLICATION API +//--------------------------------------------------------------------+ +/** \addtogroup ClassDriver_HID_Mouse Mouse + * @{ */ +/** \defgroup Mouse_Device Device + * @{ */ + tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_mouse_report); /** @} */ /** @} */ + + //--------------------------------------------------------------------+ // USBD-CLASS DRIVER API //--------------------------------------------------------------------+ diff --git a/tinyusb/device/dcd_lpc43xx.c b/tinyusb/device/dcd_lpc43xx.c index cd2e79c9..f10383d9 100644 --- a/tinyusb/device/dcd_lpc43xx.c +++ b/tinyusb/device/dcd_lpc43xx.c @@ -247,6 +247,12 @@ static inline uint8_t endpoint_to_pos(uint8_t logical_endpoint, tusb_direction_t return logical_endpoint + (dir == TUSB_DIR_HOST_TO_DEV ? 0 : 16); } +static inline uint8_t endpoint_phy2pos(uint8_t physical_endpoint) ATTR_CONST ATTR_ALWAYS_INLINE; +static inline uint8_t endpoint_phy2pos(uint8_t physical_endpoint) +{ + return physical_endpoint/2 + ( (physical_endpoint%2) ? 16 : 0); +} + static inline uint8_t endpoint_log2phy(uint8_t logical_endpoint, tusb_direction_t dir) ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint8_t endpoint_log2phy(uint8_t logical_endpoint, tusb_direction_t dir) { @@ -288,7 +294,7 @@ tusb_error_t dcd_pipe_control_xfer(uint8_t coreid, tusb_direction_t dir, void * qtd_init(p_data, buffer, length); dcd_data.qhd[endpoint_data].qtd_overlay.next = (uint32_t) p_data; - LPC_USB0->ENDPTPRIME |= BIT_(endpoint_to_pos(0, dir)); + LPC_USB0->ENDPTPRIME |= BIT_( endpoint_phy2pos(endpoint_data) ); } //------------- Status Phase (other endpoint, opposite direction) -------------// @@ -296,7 +302,7 @@ tusb_error_t dcd_pipe_control_xfer(uint8_t coreid, tusb_direction_t dir, void * qtd_init(p_status, NULL, 0); // zero length xfer dcd_data.qhd[1 - endpoint_data].qtd_overlay.next = (uint32_t) p_status; - LPC_USB0->ENDPTPRIME |= BIT_(endpoint_to_pos(0, 1-dir)); + LPC_USB0->ENDPTPRIME |= BIT_( endpoint_phy2pos(1 - endpoint_data) ); return TUSB_ERROR_NONE; } @@ -332,6 +338,14 @@ STATIC_ INLINE_ dcd_qhd_t* qhd_get_from_endpoint_handle(endpoint_handle_t edpt_ return &dcd_data.qhd[edpt_hdl.index]; } +bool dcd_pipe_is_busy(endpoint_handle_t edpt_hdl) +{ + dcd_qhd_t* p_qhd = qhd_get_from_endpoint_handle(edpt_hdl); + + // LPC_USB0->ENDPTSTAT & endpoint_phy2pos(edpt_hdl.index) + return !p_qhd->qtd_overlay.halted && p_qhd->qtd_overlay.active; +} + tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) { dcd_qhd_t* p_qhd = qhd_get_from_endpoint_handle(edpt_hdl); @@ -339,21 +353,13 @@ tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, uint8_t buffer[], uint16 ASSERT(edpt_hdl.xfer_type != TUSB_XFER_ISOCHRONOUS, TUSB_ERROR_NOT_SUPPORTED_YET); - // TODO pipe is busy -// DeviceTransferDescriptor* pDTD = (DeviceTransferDescriptor*) &dTransferDescriptor[PhyEP]; -// while ( lpc_usb->ENDPTSTAT & _BIT( EP_Physical2BitPosition(PhyEP) ) ) /* Endpoint is already primed */ -// { -// } - //------------- Prepare qtd -------------// qtd_init(p_qtd, buffer, total_bytes); p_qtd->int_on_complete = int_on_complete; p_qhd->qtd_overlay.next = (uint32_t) p_qtd; -#define EP_Physical2Pos(n) ( (n)/2 + ((n)%2 ? 16 : 0 ) ) - - LPC_USB0->ENDPTPRIME |= BIT_( EP_Physical2Pos(edpt_hdl.index) ) ; + LPC_USB0->ENDPTPRIME |= BIT_( endpoint_phy2pos(edpt_hdl.index) ) ; return TUSB_ERROR_NONE; }