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:
hathach 2013-01-22 17:41:06 +07:00
parent cfe7a3d23b
commit 38ce3f7534
25 changed files with 955 additions and 176 deletions

View File

@ -55,17 +55,19 @@
extern "C" {
#endif
#define TUSB_CFG_CONFIGURATION_MAX 1
/// Enable Device Support
#define TUSB_CFG_DEVICE
/// Enable CDC Support
#define TUSB_CFG_DEVICE_CDC
//#define TUSB_CFG_DEVICE_CDC
/// Enable HID Keyboard support
#define TUSB_CFG_DEVICE_HID_KEYBOARD
/// Enable HID Mouse support
#define TUSB_CFG_DEVICE_HID_MOUSE
//#define TUSB_CFG_DEVICE_HID_MOUSE
#define TUSB_CFG_DEBUG 3
#define TUSB_CFG_OS TUSB_OS_NONE

View File

@ -6,7 +6,7 @@
# This sample, therefore, only demonstrates running a collection of unit tests.
:project:
:use_exceptions: FALSE
:use_exceptions: TRUE
:use_test_preprocessor: TRUE
:use_auxiliary_dependencies: TRUE
:use_deep_dependencies: TRUE
@ -69,9 +69,11 @@
:mock_prefix: mock_
:when_no_prototypes: :warn
:enforce_strict_ordering: TRUE
# :callback_include_count: FALSE
:plugins:
- :ignore
- :callback
- :array
:treat_as:
uint8: HEX8
uint16: HEX16

View File

@ -36,21 +36,127 @@
*/
#include "unity.h"
#include "hid.h"
#include "errors.h"
#include "hid_host.h"
#include "mock_osal.h"
#include "mock_usbd_host.h"
tusb_device_info_t usbh_device_pool [2];
tusb_keyboard_report_t sample_key[2] =
{
{
.modifier = TUSB_KEYBOARD_MODIFIER_LEFTCTRL,
.keycode = {TUSB_KEYBOARD_KEYCODE_a}
},
{
.modifier = TUSB_KEYBOARD_MODIFIER_RIGHTALT,
.keycode = {TUSB_KEYBOARD_KEYCODE_z}
}
};
tusb_handle_configure_t config_hdl;
tusb_keyboard_report_t report;
tusb_configure_info_t *p_cfg_info;
void setUp(void)
{
config_hdl = 1; // deviceID = 0 ; Configure = 1
memset(&report, 0, sizeof(tusb_keyboard_report_t));
p_cfg_info = NULL;
usbh_device_pool[0].configuration[0].classes.hid_keyboard.pipe_in = 1;
usbh_device_pool[0].configuration[0].classes.hid_keyboard.qid = 1;
usbh_device_pool[0].configuration[1].classes.hid_keyboard.pipe_in = 0;
usbh_device_pool[0].configuration[1].classes.hid_keyboard.qid = 0;
}
void tearDown(void)
{
}
void test_keyboard_get_invalid_parameter()
tusb_error_t queue_get_stub(osal_queue_id_t qid, uint32_t *data, osal_timeout_t msec, int num_call)
{
tusb_interface_keyboard_handle_t handle;
tusb_keyboard_report_t report;
TEST_ASSERT_FALSE (tusb_host_keyboard_get(NULL, &report));
TEST_ASSERT_FALSE (tusb_host_keyboard_get(&handle, NULL));
memcpy(data, (uint32_t*)(&sample_key[num_call/2]) + (num_call%2), 4);
return TUSB_ERROR_NONE;
}
tusb_error_t get_configure_class_not_support_stub(tusb_handle_configure_t configure_hdl, tusb_configure_info_t **pp_configure_info, int num_call)
{
(*pp_configure_info) = &(usbh_device_pool[0].configuration[1]);
return TUSB_ERROR_NONE;
}
tusb_error_t get_configure_stub(tusb_handle_configure_t configure_hdl, tusb_configure_info_t **pp_configure_info, int num_call)
{
(*pp_configure_info) = &(usbh_device_pool[0].configuration[0]);
return TUSB_ERROR_NONE;
}
void test_keyboard_get_invalid_para()
{
usbh_configure_info_get_IgnoreAndReturn(TUSB_ERROR_INVALID_PARA);
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_get(config_hdl, NULL));
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_get(config_hdl, &report));
}
void test_keyboard_get_class_not_supported()
{
usbh_configure_info_get_StubWithCallback(get_configure_class_not_support_stub);
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_keyboard_get(config_hdl, &report));
}
void test_keyboard_get_from_empty_queue()
{
usbh_configure_info_get_StubWithCallback(get_configure_stub);
osal_queue_get_IgnoreAndReturn(TUSB_ERROR_OSAL_TIMEOUT);
// osal_queue_get_ExpectAndReturn( usbh_device_pool[0].configuration[0].classes.hid_keyboard.qid, );
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, tusbh_keyboard_get(config_hdl, &report));
}
void test_keyboard_get_ok()
{
usbh_configure_info_get_StubWithCallback(get_configure_stub);
osal_queue_get_StubWithCallback(queue_get_stub);
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_get(config_hdl, &report));
TEST_ASSERT_EQUAL_MEMORY(&sample_key[0], &report, sizeof(tusb_keyboard_report_t));
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_get(config_hdl, &report));
TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t));
}
#if 0
void test_keyboard_open_invalid_para()
{
tusb_handle_keyboard_t keyboard_handle;
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(TUSB_CFG_HOST_DEVICE_MAX, 1, &keyboard_handle) );
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, 0, &keyboard_handle) );
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, TUSB_CFG_CONFIGURATION_MAX+1, &keyboard_handle) );
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, 1, NULL) );
}
void test_keyboard_open_succeed()
{
tusb_handle_keyboard_t keyboard_handle = 0;
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_open(0, 1, &keyboard_handle));
TEST_ASSERT_TRUE( 0 != keyboard_handle);
}
void test_keyboard_callback__()
{
TEST_IGNORE();
tusb_handle_device_t device_handle = __LINE__;
tusb_handle_configure_t configure_handle = __LINE__;
tusb_handle_interface_t interface_handle = __LINE__;
uint32_t configure_flags = BIT_(TUSB_CLASS_HID);
tusbh_usbd_device_mounted_cb_ExpectWithArray(TUSB_ERROR_NONE, device_handle, &configure_flags, 1, 1);
}
#endif

View File

@ -0,0 +1,52 @@
/*
* test_usbd_host.c
*
* Created on: Jan 21, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 tiny usb stack.
*/
#include "unity.h"
#include "usbd_host.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_()
{
// TEST_IGNORE();
}

View File

@ -56,6 +56,9 @@
#endif
#define TUSB_CFG_HOST
#define TUSB_CFG_HOST_CONTROLLER_NUM 2
#define TUSB_CFG_HOST_DEVICE_MAX 2
#define TUSB_CFG_CONFIGURATION_MAX 2
/// Enable Device Support
//#define TUSB_CFG_DEVICE

View File

@ -35,38 +35,103 @@
* This file is part of the tiny usb stack.
*/
#define _TEST_ASSERT_
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include "unity.h"
#include "CException.h"
#include "common/assertion.h"
#include "errors.h"
CEXCEPTION_T e;
void setUp(void)
{
e = 0;
}
void tearDown(void)
{
}
//--------------------------------------------------------------------+
// Error Status
//--------------------------------------------------------------------+
void test_assert_status(void)
{
Try
{
ASSERT_STATUS(TUSB_ERROR_NONE);
ASSERT_STATUS(TUSB_ERROR_INVALID_PARA);
}
Catch (e)
{
}
}
//--------------------------------------------------------------------+
// Logical
//--------------------------------------------------------------------+
void test_assert_logical_true(void)
{
ASSERT (true , (void)0 );
ASSERT_TRUE (true , (void)0 );
ASSERT_TRUE (false , (void)0 );
TEST_FAIL();
Try
{
ASSERT (true , __LINE__);
ASSERT_TRUE (true , __LINE__);
ASSERT_TRUE (false, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
void test_assert_logical_false(void)
{
ASSERT_FALSE(false , (void)0 );
ASSERT_FALSE(true , (void)0 );
Try
{
ASSERT_FALSE (false, __LINE__);
ASSERT_FALSE (true , 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
//--------------------------------------------------------------------+
// Pointer
//--------------------------------------------------------------------+
void test_assert_pointer_not_null(void)
{
uint32_t n;
TEST_FAIL();
Try
{
ASSERT_PTR_NOT_NULL(&n, __LINE__);
ASSERT_PTR(&n, __LINE__);
ASSERT_PTR(NULL, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
void test_assert_pointer_null(void)
{
uint32_t n;
Try
{
ASSERT_PTR_NULL(NULL, __LINE__);
ASSERT_PTR_NULL(&n, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
//--------------------------------------------------------------------+
@ -74,37 +139,67 @@ void test_assert_logical_false(void)
//--------------------------------------------------------------------+
void test_assert_int_eqal(void)
{
ASSERT_INT (1, 1, (void) 0);
ASSERT_INT_EQUAL (1, 1, (void) 0);
Try
{
ASSERT_INT (1, 1, __LINE__);
ASSERT_INT_EQUAL (1, 1, __LINE__);
uint32_t x = 0;
uint32_t y = 0;
ASSERT_INT (x++, y++, (void) 0); // test side effect
TEST_ASSERT_EQUAL(1, x);
TEST_ASSERT_EQUAL(1, y);
// test side effect
uint32_t x = 0;
uint32_t y = 0;
ASSERT_INT (x++, y++, __LINE__);
TEST_ASSERT_EQUAL(1, x);
TEST_ASSERT_EQUAL(1, y);
ASSERT_INT(0, 1, (void) 0);
TEST_FAIL();
ASSERT_INT (1, 0, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
void test_assert_int_within_succeed(void)
void test_assert_int_within(void)
{
ASSERT_INT_WITHIN (1, 5, 3, (void) 0);
ASSERT_INT_WITHIN (1, 5, 1, (void) 0);
ASSERT_INT_WITHIN (1, 5, 5, (void) 0);
}
Try
{
ASSERT_INT_WITHIN (1, 5, 3, __LINE__);
ASSERT_INT_WITHIN (1, 5, 1, __LINE__);
ASSERT_INT_WITHIN (1, 5, 5, __LINE__);
void test_assert_int_within_less(void)
{
ASSERT_INT_WITHIN (1, 5, 0, (void) 0);
TEST_FAIL();
ASSERT_INT_WITHIN (1, 5, 0, 0);
ASSERT_INT_WITHIN (1, 5, 10, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
void test_assert_int_within_greater(void)
{
ASSERT_INT_WITHIN (1, 5, 10, (void) 0);
TEST_FAIL();
Try
{
ASSERT_INT_WITHIN (1, 5, 10, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
void test_assert_int_within_less(void)
{
Try
{
ASSERT_INT_WITHIN (1, 5, 0, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
//--------------------------------------------------------------------+
@ -112,54 +207,79 @@ void test_assert_int_within_greater(void)
//--------------------------------------------------------------------+
void test_assert_hex_equal(void)
{
ASSERT_HEX (0xffee, 0xffee, (void) 0);
ASSERT_HEX_EQUAL (0xffee, 0xffee, (void) 0);
Try
{
ASSERT_HEX (0xffee, 0xffee, __LINE__);
ASSERT_HEX_EQUAL (0xffee, 0xffee, __LINE__);
uint32_t x = 0xf0f0;
uint32_t y = 0xf0f0;
ASSERT_HEX (x++, y++, (void) 0); // test side effect
TEST_ASSERT_EQUAL(0xf0f1, x);
TEST_ASSERT_EQUAL(0xf0f1, y);
// test side effect
uint32_t x = 0xf0f0;
uint32_t y = 0xf0f0;
ASSERT_HEX (x++, y++, __LINE__);
TEST_ASSERT_EQUAL(0xf0f1, x);
TEST_ASSERT_EQUAL(0xf0f1, y);
ASSERT_HEX(0x1234, 0x4321, (void) 0);
TEST_FAIL();
ASSERT_HEX(0x1234, 0x4321, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
void test_assert_hex_within_succeed(void)
void test_assert_hex_within(void)
{
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff11, (void) 0);
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff00, (void) 0);
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xffff, (void) 0);
Try
{
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff11, __LINE__);
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xff00, __LINE__);
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xffff, __LINE__);
}
Catch (e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
void test_assert_hex_within_less(void)
{
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xeeee, (void) 0);
TEST_FAIL();
Try
{
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0xeeee, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
void test_assert_hex_within_greater(void)
{
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0x1eeee, (void) 0);
TEST_FAIL();
Try
{
ASSERT_HEX_WITHIN (0xff00, 0xffff, 0x1eeee, 0);
}
Catch(e)
{
TEST_ASSERT_EQUAL(0, e);
}
}
//--------------------------------------------------------------------+
// HEX
// BIN
//--------------------------------------------------------------------+
void test_assert_bin_equal(void)
{
// ASSERT_HEX (0xffee, 0xffee, (void) 0);
// ASSERT_HEX_EQUAL (0xffee, 0xffee, (void) 0);
// ASSERT_HEX (0xffee, 0xffee, __LINE__);
// ASSERT_HEX_EQUAL (0xffee, 0xffee, __LINE__);
//
// uint32_t x = 0xf0f0;
// uint32_t y = 0xf0f0;
// ASSERT_HEX (x++, y++, (void) 0); // test side effect
// ASSERT_HEX (x++, y++, __LINE__); // test side effect
// TEST_ASSERT_EQUAL(0xf0f1, x);
// TEST_ASSERT_EQUAL(0xf0f1, y);
//
// ASSERT_HEX(0x1234, 0x4321, (void) 0);
// ASSERT_HEX(0x1234, 0x4321, __LINE__);
TEST_IGNORE();
}

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -71,28 +71,32 @@ extern "C"
#define ASSERT_FILENAME __BASE_FILE__
#define ASSERT_FUNCTION __PRETTY_FUNCTION__
#define ASSERT_STATEMENT _PRINTF("assert at %s: %s :%d :\n", ASSERT_FILENAME, ASSERT_FUNCTION, __LINE__)
#ifndef _TEST_ASSERT_
#define ASSERT_ERROR_HANDLE(x) return (x)
#else
#define ASSERT_ERROR_HANDLE(x) Throw(x)
#endif
#define ASSERT_DEFINE(setup_statement, condition, error, format, ...) \
do{\
setup_statement;\
if (!(condition)) {\
_PRINTF("Assert at %s: %s:%d: " format "\n", ASSERT_FILENAME, ASSERT_FUNCTION, __LINE__, __VA_ARGS__);\
return error;\
ASSERT_ERROR_HANDLE(error);\
}\
}while(0)
//--------------------------------------------------------------------+
// tusb_error_t Status Assert
// tusb_error_t Status Assert TODO use ASSERT_DEFINE
//--------------------------------------------------------------------+
#define ASSERT_STATUS_MESSAGE(sts, message) \
do{\
tusb_error_t status = (tusb_error_t)(sts);\
if (TUSB_ERROR_NONE != status) {\
_PRINTF("Assert at %s line %d: %s %s\n", ASSERT_FILENAME, ASSERT_FUNCTION, __LINE__, TUSB_ErrorStr[status], message); \
return status;\
}\
}while(0)
ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\
TUSB_ERROR_NONE == status, status, "%s: %s", TUSB_ErrorStr[status], message)
#define ASSERT_STATUS(sts) ASSERT_STATUS_MESSAGE(sts, NULL)
#define ASSERT_STATUS(sts) \
ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\
TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
//--------------------------------------------------------------------+
// Logical Assert
@ -102,7 +106,14 @@ extern "C"
#define ASSERT_FALSE(condition , error) ASSERT_DEFINE( ,!(condition), error, "%s", "evaluated to true")
//--------------------------------------------------------------------+
// Integer Assert
// Pointer Assert
//--------------------------------------------------------------------+
#define ASSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__)
#define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL")
#define ASSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is not NULL")
//--------------------------------------------------------------------+
// Integral Assert
//--------------------------------------------------------------------+
#define ASSERT_XXX_EQUAL(type_format, expected, actual, error) \
ASSERT_DEFINE(\
@ -118,6 +129,9 @@ extern "C"
error,\
"expected within " type_format " - " type_format ", actual " type_format, low, up, act)
//--------------------------------------------------------------------+
// Integer Assert
//--------------------------------------------------------------------+
#define ASSERT_INT(...) ASSERT_INT_EQUAL(__VA_ARGS__)
#define ASSERT_INT_EQUAL(...) ASSERT_XXX_EQUAL("%d", __VA_ARGS__)
#define ASSERT_INT_WITHIN(...) ASSERT_XXX_WITHIN("%d", __VA_ARGS__)
@ -130,11 +144,12 @@ extern "C"
#define ASSERT_HEX_WITHIN(...) ASSERT_XXX_WITHIN("0x%x", __VA_ARGS__)
//--------------------------------------------------------------------+
// Pointer Assert
// TODO Bin Assert
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
// TODO Bit Assert
//--------------------------------------------------------------------+
#define ASSSERT_PTR(...) ASSERT_PTR_NOT_NULL(__VA_ARGS__)
#define ASSERT_PTR_NOT_NULL(pointer, error) ASSERT_DEFINE( , NULL != (pointer), error, "%s", "pointer is NULL")
#define ASSSERT_PTR_NULL(pointer, error) ASSERT_DEFINE( , NULL == (pointer), error, "%s", "pointer is NULL")
#ifdef __cplusplus

View File

@ -74,15 +74,22 @@
#include "osal/osal.h"
/// form an uint32_t from 4 x uint8_t
static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) ATTR_ALWAYS_INLINE ATTR_CONST;
static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4)
{
return (b1 << 24) + (b2 << 16) + (b3 << 8) + b4;
}
/// min value
static inline uint32_t min_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE;
static inline uint32_t min_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE ATTR_CONST;
static inline uint32_t min_of(uint32_t x, uint32_t y)
{
return (x < y) ? x : y;
}
/// max value
static inline uint32_t max_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE;
static inline uint32_t max_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE ATTR_CONST;
static inline uint32_t max_of(uint32_t x, uint32_t y)
{
return (x > y) ? x : y;

View File

@ -60,7 +60,10 @@
#define ERROR_TABLE(ENTRY) \
ENTRY(TUSB_ERROR_NONE)\
ENTRY(tERROR_FAILED)\
ENTRY(TUSB_ERROR_INVALID_PARA)\
ENTRY(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT)\
ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\
ENTRY(TUSB_ERROR_FAILED)\
/** \enum tusb_error_t
@ -68,7 +71,7 @@
*/
typedef enum {
ERROR_TABLE(ERROR_ENUM)
ERROR_COUNT
TUSB_ERROR_COUNT
}tusb_error_t;
#if TUSB_CFG_DEBUG == 3

View File

@ -72,7 +72,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t iProduct ; ///< Index of string descriptor describing product.
uint8_t iSerialNumber ; ///< Index of string descriptor describing the device's serial number.
uint8_t bNumConfigurations ; ///< Number of possible configurations.
} USB_Descriptor_Device_t;
} tusb_descriptor_device_t;
/// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */
typedef ATTR_PREPACKED struct ATTR_PACKED {
@ -84,7 +84,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t iConfiguration ; ///< Index of string descriptor describing this configuration
uint8_t bmAttributes ; ///< Configuration characteristics \n D7: Reserved (set to one)\n D6: Self-powered \n D5: Remote Wakeup \n D4...0: Reserved (reset to zero) \n D7 is reserved and must be set to one for historical reasons. \n A device configuration that uses power from the bus and a local source reports a non-zero value in bMaxPower to indicate the amount of bus power required and sets D6. The actual power source at runtime may be determined using the GetStatus(DEVICE) request (see USB 2.0 spec Section 9.4.5). \n If a device configuration supports remote wakeup, D5 is set to one.
uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
} USB_Descriptor_Configuration_t;
} tusb_descriptor_configuration_t;
/// USB Standard Interface Descriptor (section 9.6.1 table 9-12)
typedef ATTR_PREPACKED struct ATTR_PACKED {
@ -97,7 +97,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bInterfaceSubClass ; ///< Subclass code (assigned by the USB-IF). \n These codes are qualified by the value of the bInterfaceClass field. \li If the bInterfaceClass field is reset to zero, this field must also be reset to zero. \li If the bInterfaceClass field is not set to FFH, all values are reserved for assignment by the USB-IF.
uint8_t bInterfaceProtocol ; ///< Protocol code (assigned by the USB). \n These codes are qualified by the value of the bInterfaceClass and the bInterfaceSubClass fields. If an interface supports class-specific requests, this code identifies the protocols that the device uses as defined by the specification of the device class. \li If this field is reset to zero, the device does not use a class-specific protocol on this interface. \li If this field is set to FFH, the device uses a vendor-specific protocol for this interface.
uint8_t iInterface ; ///< Index of string descriptor describing this interface
}USB_Descriptor_Interface_t;
} tusb_descriptor_interface_t;
/// USB Standard Endpoint Descriptor (section 9.6.1 table 9-13)
typedef ATTR_PREPACKED struct ATTR_PACKED {
@ -107,7 +107,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bmAttributes ; ///< This field describes the endpoint's attributes when it is configured using the bConfigurationValue. \n Bits 1..0: Transfer Type \n- 00 = Control \n- 01 = Isochronous \n- 10 = Bulk \n- 11 = Interrupt \n If not an isochronous endpoint, bits 5..2 are reserved and must be set to zero. If isochronous, they are defined as follows: \n Bits 3..2: Synchronization Type \n- 00 = No Synchronization \n- 01 = Asynchronous \n- 10 = Adaptive \n- 11 = Synchronous \n Bits 5..4: Usage Type \n- 00 = Data endpoint \n- 01 = Feedback endpoint \n- 10 = Implicit feedback Data endpoint \n- 11 = Reserved \n Refer to Chapter 5 of USB 2.0 specification for more information. \n All other bits are reserved and must be reset to zero. Reserved bits must be ignored by the host.
uint16_t wMaxPacketSize ; ///< Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. \n For isochronous endpoints, this value is used to reserve the bus time in the schedule, required for the per-(micro)frame data payloads. The pipe may, on an ongoing basis, actually use less bandwidth than that reserved. The device reports, if necessary, the actual bandwidth used via its normal, non-USB defined mechanisms. \n For all endpoints, bits 10..0 specify the maximum packet size (in bytes). \n For high-speed isochronous and interrupt endpoints: \n Bits 12..11 specify the number of additional transaction opportunities per microframe: \n- 00 = None (1 transaction per microframe) \n- 01 = 1 additional (2 per microframe) \n- 10 = 2 additional (3 per microframe) \n- 11 = Reserved \n Bits 15..13 are reserved and must be set to zero.
uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
} USB_Descriptor_Endpoint_t;
} tusb_descriptor_endpoint_t;
/// USB Other Speed Configuration Descriptor (section 9.6.1 table 9-11)
typedef ATTR_PREPACKED struct ATTR_PACKED {
@ -119,7 +119,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t IConfiguration ; ///< Index of string descriptor
uint8_t bmAttributes ; ///< Same as Configuration descriptor
uint8_t bMaxPower ; ///< Same as Configuration descriptor
} USB_Descriptor_OtherSpeed_t;
} tusb_descriptor_other_speed_t;
/// USB Device Qualifier Descriptor (section 9.6.1 table 9-9)
typedef ATTR_PREPACKED struct ATTR_PACKED {
@ -132,7 +132,7 @@ typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bMaxPacketSize0 ; ///< Maximum packet size for other speed
uint8_t bNumConfigurations ; ///< Number of Other-speed Configurations
uint8_t bReserved ; ///< Reserved for future use, must be zero
} USB_Descriptor_DeviceQualifier_t;
} tusb_descriptor_device_qualifier_t;
/// USB Interface Association Descriptor (IAD ECN)
typedef ATTR_PREPACKED struct ATTR_PACKED
@ -148,14 +148,15 @@ typedef ATTR_PREPACKED struct ATTR_PACKED
uint8_t bFunctionProtocol ; ///< Interface protocol ID.
uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
} USB_Descriptor_InterfaceAssociation_t;
} tusb_descriptor_interface_association_t;
/// USB Header Descriptor
typedef ATTR_PREPACKED struct ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
} USB_Descriptor_Header_t;
} tusb_descriptor_header_t;
#ifdef __cplusplus
}

View File

@ -55,56 +55,88 @@
/// defined base on EHCI specs value for Endpoint Speed
typedef enum {
FULL_SPEED =0,
LOWS_PEED,
HIGH_SPEED
}USB_Speed_t;
TUSB_SPEED_FULL = 0,
TUSB_SPEED_LOW ,
TUSB_SPEED_HIGH
}tusb_speed_t;
/// defined base on USB Specs Endpoint's bmAttributes
typedef enum {
CONTROL_TYPE = 0,
ISOCHRONOUS_TYPE,
BULK_TYPE,
INTERRUPT_TYPE
}USB_TransferType_t;
TUSB_XFER_CONTROL = 0 ,
TUSB_XFER_ISOCHRONOUS ,
TUSB_XFER_BULK ,
TUSB_XFER_INTERRUPT
}tusb_transfer_type_t;
/// TBD
typedef enum {
SETUP_TOKEN,
IN_TOKEN,
OUT_TOKEN
}USB_PID_t;
TUSB_PID_SETUP,
TUSB_PID_IN,
TUSB_PID_OUT
}tusb_pid_t;
/// USB Descriptor Types (section 9.4 table 9-5)
typedef enum {
DEVICE_DESC=1 , ///< 1
CONFIGURATIONT_DESC , ///< 2
STRING_DESC , ///< 3
INTERFACE_DESC , ///< 4
ENDPOINT_DESC , ///< 5
DEVICE_QUALIFIER_DESC , ///< 6
OTHER_SPEED_CONFIGURATION_DESC , ///< 7
INTERFACE_POWER_DESC , ///< 8
OTG_DESC , ///< 9
DEBUG_DESCRIPTOR , ///< 10
INTERFACE_ASSOCIATION_DESC ///< 11
}USB_DescriptorType_t;
TUSB_DESC_DEVICE =1 , ///< 1
TUSB_DESC_CONFIGURATION , ///< 2
TUSB_DESC_STRING , ///< 3
TUSB_DESC_INTERFACE , ///< 4
TUSB_DESC_ENDPOINT , ///< 5
TUSB_DESC_DEVICE_QUALIFIER , ///< 6
TUSB_DESC_OTHER_SPEED_CONFIGURATION , ///< 7
TUSB_DESC_INTERFACE_POWER , ///< 8
TUSB_DESC_OTG , ///< 9
TUSB_DESC_DEBUGRIPTOR , ///< 10
TUSB_DESC_INTERFACE_ASSOCIATION ///< 11
}tusb_std_descriptor_type_t;
typedef enum {
REQUEST_GET_STATUS =0 , ///< 0
REQUEST_CLEAR_FEATURE , ///< 1
REQUEST_RESERVED , ///< 2
REQUEST_SET_FEATURE , ///< 3
REQUEST_RESERVED2 , ///< 4
REQUEST_SET_ADDRESS , ///< 5
REQUEST_GET_DESCRIPTOR , ///< 6
REQUEST_SET_DESCRIPTOR , ///< 7
REQUEST_GET_CONFIGURATION , ///< 8
REQUEST_SET_CONFIGURATION , ///< 9
REQUEST_GET_INTERFACE , ///< 10
REQUEST_SET_INTERFACE , ///< 11
REQUEST_SYNCH_FRAME ///< 12
}USB_RequestCode_t;
TUSB_REQUEST_GET_STATUS =0 , ///< 0
TUSB_REQUEST_CLEAR_FEATURE , ///< 1
TUSB_REQUEST_RESERVED , ///< 2
TUSB_REQUEST_SET_FEATURE , ///< 3
TUSB_REQUEST_RESERVED2 , ///< 4
TUSB_REQUEST_SET_ADDRESS , ///< 5
TUSB_REQUEST_GET_DESCRIPTOR , ///< 6
TUSB_REQUEST_SET_DESCRIPTOR , ///< 7
TUSB_REQUEST_GET_CONFIGURATION , ///< 8
TUSB_REQUEST_SET_CONFIGURATION , ///< 9
TUSB_REQUEST_GET_INTERFACE , ///< 10
TUSB_REQUEST_SET_INTERFACE , ///< 11
TUSB_REQUEST_SYNCH_FRAME ///< 12
}tusb_std_request_code_t;
typedef enum {
TUSB_CLASS_UNSPECIFIED = 0 , ///< 0
TUSB_CLASS_AUDIO = 1 , ///< 1
TUSB_CLASS_CDC = 2 , ///< 2
TUSB_CLASS_HID = 3 , ///< 3
TUSB_CLASS_RESERVED_4 = 4 , ///< 4
TUSB_CLASS_PHYSICAL = 5 , ///< 5
TUSB_CLASS_IMAGE = 6 , ///< 6
TUSB_CLASS_PRINTER = 7 , ///< 7
TUSB_CLASS_MSC = 8 , ///< 8
TUSB_CLASS_HUB = 9 , ///< 9
TUSB_CLASS_CDC_DATA = 10 , ///< 10
TUSB_CLASS_SMART_CARD = 11 , ///< 11
TUSB_CLASS_RESERVED_12 = 12 , ///< 12
TUSB_CLASS_CONTENT_SECURITY = 13 , ///< 13
TUSB_CLASS_VIDEO = 14 , ///< 14
TUSB_CLASS_PERSONAL_HEALTHCARE = 15 , ///< 15
TUSB_CLASS_AUDIO_VIDEO = 16 , ///< 16
TUSB_CLASS_DIAGNOSTIC = 0xDC ,
TUSB_CLASS_WIRELESS_CONTROLLER = 0xE0 ,
TUSB_CLASS_MISC = 0xEF ,
TUSB_CLASS_APPLICATION_SPECIFIC = 0xEF ,
TUSB_CLASS_VENDOR_SPECIFIC = 0xFF
}tusb_std_class_code_t;
enum {
TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7),
TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6),
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5)
};
#ifdef __cplusplus
}

View File

@ -109,7 +109,7 @@ tusb_error_t dcd_init(uint8_t coreid)
};
/* USB hardware core initialization */
ASSERT(LPC_OK == USBD_API->hw->Init(&g_hUsb, &DeviceDes, &usb_param), tERROR_FAILED);
ASSERT(LPC_OK == USBD_API->hw->Init(&g_hUsb, &DeviceDes, &usb_param), TUSB_ERROR_FAILED);
membase += (memsize - usb_param.mem_size);
memsize = usb_param.mem_size;

View File

@ -43,7 +43,7 @@ tusb_error_t hal_init()
{
/* Set up USB0 clock */
CGU_EnableEntity(CGU_CLKSRC_PLL0, DISABLE); /* Disable PLL first */
ASSERT_INT( CGU_ERROR_SUCCESS, CGU_SetPLL0(), tERROR_FAILED); /* the usb core require output clock = 480MHz */
ASSERT_INT( CGU_ERROR_SUCCESS, CGU_SetPLL0(), TUSB_ERROR_FAILED); /* the usb core require output clock = 480MHz */
CGU_EntityConnect(CGU_CLKSRC_XTAL_OSC, CGU_CLKSRC_PLL0);
CGU_EnableEntity(CGU_CLKSRC_PLL0, ENABLE); /* Enable PLL after all setting is done */
LPC_CREG->CREG0 &= ~(1<<5); /* Turn on the phy */

View File

@ -58,6 +58,9 @@
#include "common/common.h"
#include "core/tusb_types.h"
typedef uint32_t pipe_handle_t;
#if 0
/** \brief Initialize HCD
*
* \param[in] para1
@ -75,6 +78,7 @@ tusb_error_t hcd_init(uint8_t hostid) ATTR_WARN_UNUSED_RESULT;
tusb_error_t hcd_pipe_close()ATTR_WARN_UNUSED_RESULT;
tusb_error_t hcd_pipe_transfer()ATTR_WARN_UNUSED_RESULT;
tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT;
#endif
#ifdef __cplusplus
}

55
tinyusb/host/usbd_host.c Normal file
View File

@ -0,0 +1,55 @@
/*
* usbd_host.c
*
* Created on: Jan 19, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 tiny usb stack.
*/
#include "usbd_host.h"
#ifdef TUSB_CFG_HOST
#if 0
tusb_error_t tusbh_keyboard_open(tusb_handle_device_t device_hdl, uint8_t configure_num, tusb_handle_keyboard_t *keyboard_hdl)
{
ASSERT(device_hdl < TUSB_CFG_HOST_DEVICE_MAX, TUSB_ERROR_INVALID_PARA);
ASSERT_INT_WITHIN(1, TUSB_CFG_CONFIGURATION_MAX, configure_num, TUSB_ERROR_INVALID_PARA);
ASSERT_PTR(keyboard_hdl, TUSB_ERROR_INVALID_PARA);
return TUSB_ERROR_NONE;
}
#endif
tusb_device_info_t usbh_device_pool[TUSB_CFG_HOST_DEVICE_MAX];
#endif

136
tinyusb/host/usbd_host.h Normal file
View File

@ -0,0 +1,136 @@
/*
* usbd_host.h
*
* Created on: Jan 19, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 tiny usb stack.
*/
/** \file
* \brief TBD
*
* \note TBD
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_USBD_HOST_H_
#define _TUSB_USBD_HOST_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "hcd.h"
typedef struct {
pipe_handle_t pipe_in;
osal_queue_id_t qid;
}hid_info_t;
typedef struct {
uint8_t interface_num;
uint8_t attributes;
struct {
hid_info_t hid_keyboard;
// hid_info_t hid_mouse;
// hid_info_t hid_generic;
} classes;
} tusb_configure_info_t;
typedef struct {
uint8_t core_id;
uint8_t configure_num;
uint8_t configure_active; // TODO CONFIG multiple only
#if 0 // TODO allow configure for vendor/product
uint16_t vendor_id;
uint16_t product_id;
#endif
tusb_configure_info_t configuration[TUSB_CFG_CONFIGURATION_MAX];
} tusb_device_info_t;
//--------------------------------------------------------------------+
// Structures & Types
//--------------------------------------------------------------------+
typedef uint32_t tusb_handle_device_t;
typedef uint32_t tusb_handle_configure_t;
typedef struct {
uint8_t device_id;
uint8_t configure_num;
} _tusb_handle_configure_t;
//--------------------------------------------------------------------+
// APPLICATION API
//--------------------------------------------------------------------+
void tusbh_device_mounted_cb (tusb_error_t error, tusb_handle_device_t device_hdl, uint32_t *configure_flags, uint8_t number_of_configure);
tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl, uint8_t const configure_number, tusb_handle_configure_t *configure_hdl);
//tusb_error_t tusbh_configure_get (tusb_handle_device_t device_hdl, uint8_t configure_number, tusb_handle_configure_t *configure_handle);
//tusb_error_t tusbh_class_open (tusb_handle_device_t device_hdl, uint8_t class, tusb_handle_class_t *interface_handle);
//tusb_error_t tusbh_interface_get_info(tusb_handle_interface_t interface_handle, tusb_descriptor_interface_t *interface_desc);
// TODO hiding from application include
//--------------------------------------------------------------------+
// CLASS API
//--------------------------------------------------------------------+
tusb_error_t usbh_configure_info_get (tusb_handle_configure_t configure_hdl, tusb_configure_info_t **pp_configure_info);
#if 0
void tusbh_usbd_mounted(tusb_error_t error, tusb_handle_device_t device_hdl);
tusb_error_t tusbh_usbd_get_configiure (tusb_handle_device_t device_hdl , tusb_handle_configure_t *configure_hdl);
tusb_error_t tusbh_usbd_get_configiure_next (tusb_handle_configure_t prev_hdl , tusb_handle_configure_t *next_hdl);
tusb_error_t tusbh_usbd_get_interface (tusb_handle_configure_t configure_hdl , tusb_handle_interface_t *interface_hdl);
tusb_error_t tusbh_usbd_get_interface_next (tusb_handle_interface_t prev_hdl , tusb_handle_interface_t *next_hdl);
tusb_error_t tusbh_usbd_get_interface_alternate (tusb_handle_interface_t current_hdl , tusb_handle_interface_t *alternate_hdl);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_USBD_HOST_H_ */
/** @} */

93
tinyusb/osal/osal.h Normal file
View File

@ -0,0 +1,93 @@
/*
* osal.h
*
* Created on: Jan 18, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 tiny usb stack.
*/
/** \file
* \brief TBD
*
* \note TBD
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_OSAL_H_
#define _TUSB_OSAL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "common/common.h"
#define TUSB_OS_NONE 1
#define TUSB_OS_CMSIS 2
#define TUSB_OS_FREERTOS 3
#define TUSB_OS_UCOS 4
typedef uint32_t osal_status_t; // TODO OSAL port
typedef uint32_t osal_timeout_t; // TODO OSAL port
enum
{
OSAL_TIMEOUT_WAIT_FOREVER = 0
};
//--------------------------------------------------------------------+
// QUEUE API
//--------------------------------------------------------------------+
typedef uint32_t osal_queue_id_t;
tusb_error_t osal_queue_put(osal_queue_id_t qid, uint32_t data, osal_timeout_t msec);
tusb_error_t osal_queue_get(osal_queue_id_t qid, uint32_t *data, osal_timeout_t msec);
#if TUSB_CFG_OS == TUSB_OS_NONE
#include "osal_none.h"
#else
#error TUSB_CFG_OS is not defined or OS is not supported yet
#endif
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_OSAL_H_ */
/** @} */

43
tinyusb/osal/osal_none.c Normal file
View File

@ -0,0 +1,43 @@
/*
* osal_none.c
*
* Created on: Jan 19, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 tiny usb stack.
*/
#include "osal.h"
#if TUSB_CFG_OS == TUSB_OS_NONE
#endif

68
tinyusb/osal/osal_none.h Normal file
View File

@ -0,0 +1,68 @@
/*
* osal_none.h
*
* Created on: Jan 19, 2013
* Author: hathach
*/
/*
* Software License Agreement (BSD License)
* Copyright (c) 2012, hathach (tinyusb.net)
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 tiny usb stack.
*/
/** \file
* \brief TBD
*
* \note TBD
*/
/** \ingroup TBD
* \defgroup TBD
* \brief TBD
*
* @{
*/
#ifndef _TUSB_OSAL_NONE_H_
#define _TUSB_OSAL_NONE_H_
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------+
// QUEUE API
//--------------------------------------------------------------------+
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_OSAL_NONE_H_ */
/** @} */

View File

@ -63,7 +63,24 @@
#endif
/// Enable Host Support
//#define TUSB_CFG_HOST
#ifdef TUSB_CFG_HOST
#ifndef TUSB_CFG_HOST_CONTROLLER_NUM
#define TUSB_CFG_HOST_CONTROLLER_NUM 1
#warning TUSB_CFG_HOST_CONTROLLER_NUM is not defined, default value is 1
#endif
#ifndef TUSB_CFG_HOST_DEVICE_MAX
#define TUSB_CFG_HOST_DEVICE_MAX 1
#warning TUSB_CFG_HOST_DEVICE_MAX is not defined, default value is 1
#endif
#endif
#ifndef TUSB_CFG_CONFIGURATION_MAX
#define TUSB_CFG_CONFIGURATION_MAX 1
#warning TUSB_CFG_CONFIGURATION_MAX is not defined, default value is 1
#endif
/// Enable Device Support
//#define TUSB_CFG_DEVICE