start to support
- usbd host - osal some global define #define TUSB_CFG_HOST_CONTROLLER_NUM #define TUSB_CFG_HOST_DEVICE_MAX #define TUSB_CFG_CONFIGURATION_MAX rename & refractor HID type structure & enum use CException to test asssertion library add test for hid_host_keyboard with usbd configure get & osal queue get stubs update test for assertion library refractor ASSERT_STATUS in assertion library update tusb_error_t values rename usb basic type & enum in tusb_types.h and std_descriptors.h
This commit is contained in:
@@ -287,10 +287,10 @@ tusb_error_t tusb_cdc_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *c
|
||||
ASSERT (pControlIntfDesc && pDataIntfDesc, ERR_FAILED);
|
||||
|
||||
/* register Bulk IN & OUT endpoint interrupt handler */
|
||||
ASSERT ( LPC_OK == USBD_API->core->RegisterEpHandler (hUsb , ((CDC_DATA_EP_IN & 0x0F) << 1) +1 , CDC_BulkIn_Hdlr , NULL), tERROR_FAILED );
|
||||
ASSERT ( LPC_OK == USBD_API->core->RegisterEpHandler (hUsb , (CDC_DATA_EP_OUT & 0x0F) << 1 , CDC_BulkOut_Hdlr , NULL), tERROR_FAILED );
|
||||
ASSERT ( LPC_OK == USBD_API->core->RegisterEpHandler (hUsb , ((CDC_DATA_EP_IN & 0x0F) << 1) +1 , CDC_BulkIn_Hdlr , NULL), TUSB_ERROR_FAILED );
|
||||
ASSERT ( LPC_OK == USBD_API->core->RegisterEpHandler (hUsb , (CDC_DATA_EP_OUT & 0x0F) << 1 , CDC_BulkOut_Hdlr , NULL), TUSB_ERROR_FAILED );
|
||||
|
||||
ASSERT ( LPC_OK == USBD_API->cdc->init(hUsb, &cdc_param, &g_hCdc), tERROR_FAILED);
|
||||
ASSERT ( LPC_OK == USBD_API->cdc->init(hUsb, &cdc_param, &g_hCdc), TUSB_ERROR_FAILED);
|
||||
|
||||
/* update memory variables */
|
||||
*mem_base = cdc_param.mem_base;
|
||||
|
||||
@@ -45,7 +45,7 @@ static volatile bool bKeyChanged = false;
|
||||
#endif
|
||||
|
||||
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
|
||||
USB_HID_MouseReport_t hid_mouse_report;
|
||||
tusb_mouse_report_t hid_mouse_report;
|
||||
static volatile bool bMouseChanged = false;
|
||||
#endif
|
||||
|
||||
@@ -80,7 +80,7 @@ ErrorCode_t HID_GetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t
|
||||
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
|
||||
case HID_PROTOCOL_MOUSE:
|
||||
*pBuffer = (uint8_t*) &hid_mouse_report;
|
||||
*plength = sizeof(USB_HID_MouseReport_t);
|
||||
*plength = sizeof(tusb_mouse_report_t);
|
||||
|
||||
if (!bMouseChanged)
|
||||
{
|
||||
@@ -142,9 +142,9 @@ ErrorCode_t HID_EpIn_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
|
||||
case HID_PROTOCOL_MOUSE:
|
||||
if (!bMouseChanged)
|
||||
{
|
||||
memset(&hid_mouse_report, 0, sizeof(USB_HID_MouseReport_t));
|
||||
memset(&hid_mouse_report, 0, sizeof(tusb_mouse_report_t));
|
||||
}
|
||||
USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_mouse_report, sizeof(USB_HID_MouseReport_t));
|
||||
USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_mouse_report, sizeof(tusb_mouse_report_t));
|
||||
bMouseChanged = false;
|
||||
break;
|
||||
#endif
|
||||
@@ -206,7 +206,7 @@ tusb_error_t tusb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *c
|
||||
|
||||
ASSERT( (pIntfDesc != NULL) && (pIntfDesc->bInterfaceClass == USB_DEVICE_CLASS_HUMAN_INTERFACE), ERR_FAILED);
|
||||
|
||||
ASSERT( LPC_OK == USBD_API->hid->init(hUsb, &hid_param), tERROR_FAILED );
|
||||
ASSERT( LPC_OK == USBD_API->hid->init(hUsb, &hid_param), TUSB_ERROR_FAILED );
|
||||
|
||||
/* update memory variables */
|
||||
*mem_base += (*mem_size - hid_param.mem_size);
|
||||
@@ -227,7 +227,7 @@ tusb_error_t tusb_hid_configured(USBD_HANDLE_T hUsb)
|
||||
#endif
|
||||
|
||||
#ifdef TUSB_CFG_DEVICE_HID_MOUSE
|
||||
USBD_API->hw->WriteEP(hUsb , HID_MOUSE_EP_IN , (uint8_t* ) &hid_mouse_report , sizeof(USB_HID_MouseReport_t) ); // initial packet for IN endpoint, will not work if omitted
|
||||
USBD_API->hw->WriteEP(hUsb , HID_MOUSE_EP_IN , (uint8_t* ) &hid_mouse_report , sizeof(tusb_mouse_report_t) ); // initial packet for IN endpoint, will not work if omitted
|
||||
#endif
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
@@ -280,14 +280,14 @@ tusb_error_t tusb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], ui
|
||||
|
||||
if (bKeyChanged)
|
||||
{
|
||||
return tERROR_FAILED;
|
||||
return TUSB_ERROR_FAILED;
|
||||
}
|
||||
|
||||
ASSERT(keycodes && numkey && numkey <=6, ERR_FAILED);
|
||||
|
||||
hid_keyboard_report.Modifier = modifier;
|
||||
memset(hid_keyboard_report.KeyCode, 0, 6);
|
||||
memcpy(hid_keyboard_report.KeyCode, keycodes, numkey);
|
||||
hid_keyboard_report.modifier = modifier;
|
||||
memset(hid_keyboard_report.keycode, 0, 6);
|
||||
memcpy(hid_keyboard_report.keycode, keycodes, numkey);
|
||||
|
||||
bKeyChanged = true;
|
||||
|
||||
@@ -304,9 +304,9 @@ tusb_error_t tusb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], ui
|
||||
Indicate which button(s) are being pressed (see
|
||||
USB_HID_MOUSE_BUTTON_CODE)
|
||||
@param[in] x
|
||||
Position adjustment on the X scale
|
||||
Position adjustment on the x scale
|
||||
@param[in] y
|
||||
Position adjustment on the Y scale
|
||||
Position adjustment on the y scale
|
||||
|
||||
@section EXAMPLE
|
||||
|
||||
@@ -314,7 +314,7 @@ tusb_error_t tusb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], ui
|
||||
|
||||
if (usb_isConfigured())
|
||||
{
|
||||
// Move the mouse +10 in the X direction and + 10 in the Y direction
|
||||
// Move the mouse +10 in the x direction and + 10 in the y direction
|
||||
tusb_hid_mouse_send(0x00, 10, 10);
|
||||
}
|
||||
|
||||
@@ -331,12 +331,12 @@ tusb_error_t tusb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y)
|
||||
|
||||
if (bMouseChanged)
|
||||
{
|
||||
return tERROR_FAILED;
|
||||
return TUSB_ERROR_FAILED;
|
||||
}
|
||||
|
||||
hid_mouse_report.Button = buttons;
|
||||
hid_mouse_report.X = x;
|
||||
hid_mouse_report.Y = y;
|
||||
hid_mouse_report.buttons = buttons;
|
||||
hid_mouse_report.x = x;
|
||||
hid_mouse_report.y = y;
|
||||
|
||||
bMouseChanged = true;
|
||||
|
||||
|
||||
@@ -58,17 +58,17 @@
|
||||
// TODO refractor
|
||||
#include "common/common.h"
|
||||
|
||||
/** \struct USB_HID_MouseReport_t
|
||||
/** \struct tusb_mouse_report_t
|
||||
* \brief Standard HID Boot Protocol Mouse Report.
|
||||
*
|
||||
* Type define for a standard Boot Protocol Mouse report
|
||||
*/
|
||||
typedef ATTR_PREPACKED struct
|
||||
{
|
||||
uint8_t Button; /**< Button mask for currently pressed buttons in the mouse. */
|
||||
int8_t X; /**< Current delta X movement of the mouse. */
|
||||
int8_t Y; /**< Current delta Y movement on the mouse. */
|
||||
} ATTR_PACKED USB_HID_MouseReport_t;
|
||||
uint8_t buttons; /**< buttons mask for currently pressed buttons in the mouse. */
|
||||
int8_t x; /**< Current delta x movement of the mouse. */
|
||||
int8_t y; /**< Current delta y movement on the mouse. */
|
||||
} ATTR_PACKED tusb_mouse_report_t;
|
||||
|
||||
/** \struct tusb_keyboard_report_t
|
||||
* \brief Standard HID Boot Protocol Keyboard Report.
|
||||
@@ -77,13 +77,13 @@ typedef ATTR_PREPACKED struct
|
||||
*/
|
||||
typedef ATTR_PREPACKED struct
|
||||
{
|
||||
uint8_t Modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of HID_KEYBOARD_MODIFER_* masks). */
|
||||
uint8_t Reserved; /**< Reserved for OEM use, always set to 0. */
|
||||
uint8_t KeyCode[6]; /**< Key codes of the currently pressed keys. */
|
||||
uint8_t modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of HID_KEYBOARD_MODIFER_* masks). */
|
||||
uint8_t reserved; /**< Reserved for OEM use, always set to 0. */
|
||||
uint8_t keycode[6]; /**< Key codes of the currently pressed keys. */
|
||||
} ATTR_PACKED tusb_keyboard_report_t;
|
||||
|
||||
/** \enum USB_HID_MOUSE_BUTTON_CODE
|
||||
* \brief Button codes for HID mouse
|
||||
* \brief buttons codes for HID mouse
|
||||
*/
|
||||
enum USB_HID_MOUSE_BUTTON_CODE
|
||||
{
|
||||
@@ -95,16 +95,26 @@ enum USB_HID_MOUSE_BUTTON_CODE
|
||||
/** \enum USB_HID_KB_KEYMODIFIER_CODE
|
||||
* \brief KB modifier codes for HID KB
|
||||
*/
|
||||
enum USB_HID_KB_KEYMODIFIER_CODE
|
||||
enum TUSB_KEYBOARD_MODIFIER_CODE
|
||||
{
|
||||
HID_KEYMODIFIER_LEFTCTRL = 0,
|
||||
HID_KEYMODIFIER_LEFTSHIFT,
|
||||
HID_KEYMODIFIER_LEFTALT,
|
||||
HID_KEYMODIFIER_LEFTGUI,
|
||||
HID_KEYMODIFIER_RIGHTCTRL,
|
||||
HID_KEYMODIFIER_RIGHTSHIFT,
|
||||
HID_KEYMODIFIER_RIGHTALT,
|
||||
HID_KEYMODIFIER_RIGHTGUI
|
||||
TUSB_KEYBOARD_MODIFIER_LEFTCTRL = BIN8(00000001),
|
||||
TUSB_KEYBOARD_MODIFIER_LEFTSHIFT = BIN8(00000010),
|
||||
TUSB_KEYBOARD_MODIFIER_LEFTALT = BIN8(00000100),
|
||||
TUSB_KEYBOARD_MODIFIER_LEFTGUI = BIN8(00001000),
|
||||
TUSB_KEYBOARD_MODIFIER_RIGHTCTRL = BIN8(00010000),
|
||||
TUSB_KEYBOARD_MODIFIER_RIGHTSHIFT = BIN8(00100000),
|
||||
TUSB_KEYBOARD_MODIFIER_RIGHTALT = BIN8(01000000),
|
||||
TUSB_KEYBOARD_MODIFIER_RIGHTGUI = BIN8(10000000)
|
||||
};
|
||||
|
||||
enum TUSB_KEYBOARD_KEYCODE
|
||||
{
|
||||
TUSB_KEYBOARD_KEYCODE_a = 0x04,
|
||||
TUSB_KEYBOARD_KEYCODE_z = 0x1d,
|
||||
|
||||
TUSB_KEYBOARD_KEYCODE_1 = 0x1e,
|
||||
TUSB_KEYBOARD_KEYCODE_0 = 0x27
|
||||
// TODO complete keycode table
|
||||
};
|
||||
|
||||
/** \enum USB_HID_LOCAL_CODE
|
||||
@@ -156,7 +166,7 @@ enum USB_HID_LOCAL_CODE
|
||||
#endif
|
||||
|
||||
#ifdef TUSB_CFG_HOST
|
||||
#include "host/hcd.h"
|
||||
#include "host/usbd_host.h"
|
||||
#include "hid_host.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -39,12 +39,24 @@
|
||||
|
||||
#if defined DEVICE_CLASS_HID && defined TUSB_CFG_HOST
|
||||
|
||||
bool tusb_host_keyboard_get(tusb_interface_keyboard_handle_t const * const handle, tusb_keyboard_report_t * const report)
|
||||
tusb_error_t tusbh_keyboard_get(tusb_handle_configure_t const config_hdl, tusb_keyboard_report_t * const report)
|
||||
{
|
||||
ASSSERT_PTR(handle, false);
|
||||
ASSSERT_PTR(report, false);
|
||||
tusb_configure_info_t *p_cfg_info;
|
||||
|
||||
return true;
|
||||
pipe_handle_t pipe_in;
|
||||
osal_queue_id_t qid;
|
||||
|
||||
ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT_STATUS( usbh_configure_info_get(config_hdl, &p_cfg_info) );
|
||||
|
||||
pipe_in = p_cfg_info->classes.hid_keyboard.pipe_in;
|
||||
qid = p_cfg_info->classes.hid_keyboard.qid;
|
||||
|
||||
ASSERT(0 != pipe_in, TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT);
|
||||
ASSERT_STATUS( osal_queue_get(qid, (uint32_t*)report, OSAL_TIMEOUT_WAIT_FOREVER) );
|
||||
ASSERT_STATUS( osal_queue_get(qid, ((uint32_t*)report)+1, OSAL_TIMEOUT_WAIT_FOREVER) );
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -57,9 +57,7 @@
|
||||
|
||||
#include "hid.h"
|
||||
|
||||
typedef uint32_t tusb_interface_keyboard_handle_t;
|
||||
|
||||
bool tusb_host_keyboard_get(tusb_interface_keyboard_handle_t const * const handle, tusb_keyboard_report_t *report);
|
||||
tusb_error_t tusbh_keyboard_get(tusb_handle_configure_t const handle, tusb_keyboard_report_t * const report);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user