summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/class/cdc_device.c8
-rw-r--r--tinyusb/class/cdc_rndis_host.c4
-rw-r--r--tinyusb/class/hid_device.c933
-rw-r--r--tinyusb/class/hid_host.c2
-rw-r--r--tinyusb/class/msc_device.c8
-rw-r--r--tinyusb/class/msc_host.c4
-rw-r--r--tinyusb/common/compiler/compiler.h4
-rw-r--r--tinyusb/common/compiler/compiler_iar.h12
-rw-r--r--tinyusb/common/fifo.h5
-rw-r--r--tinyusb/device/dcd.h14
-rw-r--r--tinyusb/device/dcd_lpc175x_6x.c8
-rw-r--r--tinyusb/device/dcd_lpc43xx.c4
-rw-r--r--tinyusb/device/dcd_lpc_11uxx_13uxx.c2
-rw-r--r--tinyusb/host/ehci/ehci.c6
-rw-r--r--tinyusb/host/hub.c4
-rw-r--r--tinyusb/host/ohci/ohci.c2
-rw-r--r--tinyusb/host/usbh.c4
17 files changed, 510 insertions, 514 deletions
diff --git a/tinyusb/class/cdc_device.c b/tinyusb/class/cdc_device.c
index b4e63d1fa..247c72180 100644
--- a/tinyusb/class/cdc_device.c
+++ b/tinyusb/class/cdc_device.c
@@ -50,8 +50,8 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
-ATTR_USB_MIN_ALIGNMENT
-static cdc_line_coding_t cdcd_line_coding[CONTROLLER_DEVICE_NUMBER] TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM ATTR_USB_MIN_ALIGNMENT
+static cdc_line_coding_t cdcd_line_coding[CONTROLLER_DEVICE_NUMBER];
typedef struct {
uint8_t interface_number;
@@ -191,12 +191,12 @@ tusb_error_t cdcd_control_request_subtask(uint8_t coreid, tusb_control_request_t
{
case CDC_REQUEST_GET_LINE_CODING:
dcd_pipe_control_xfer(coreid, p_request->bmRequestType_bit.direction,
- &cdcd_line_coding[coreid], min16_of(sizeof(cdc_line_coding_t), p_request->wLength), false );
+ (uint8_t*) &cdcd_line_coding[coreid], min16_of(sizeof(cdc_line_coding_t), p_request->wLength), false );
break;
case CDC_REQUEST_SET_LINE_CODING:
dcd_pipe_control_xfer(coreid, p_request->bmRequestType_bit.direction,
- &cdcd_line_coding[coreid], min16_of(sizeof(cdc_line_coding_t), p_request->wLength), false );
+ (uint8_t*) &cdcd_line_coding[coreid], min16_of(sizeof(cdc_line_coding_t), p_request->wLength), false );
// TODO notify application on xfer completea
break;
diff --git a/tinyusb/class/cdc_rndis_host.c b/tinyusb/class/cdc_rndis_host.c
index 106f2095c..0e31fcc9a 100644
--- a/tinyusb/class/cdc_rndis_host.c
+++ b/tinyusb/class/cdc_rndis_host.c
@@ -54,8 +54,8 @@
//--------------------------------------------------------------------+
#define RNDIS_MSG_PAYLOAD_MAX (1024*4)
-static uint8_t msg_notification[TUSB_CFG_HOST_DEVICE_MAX][8] TUSB_CFG_ATTR_USBRAM;
-ATTR_ALIGNED(4) static uint8_t msg_payload[RNDIS_MSG_PAYLOAD_MAX] TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM static uint8_t msg_notification[TUSB_CFG_HOST_DEVICE_MAX][8];
+TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) static uint8_t msg_payload[RNDIS_MSG_PAYLOAD_MAX];
STATIC_VAR rndish_data_t rndish_data[TUSB_CFG_HOST_DEVICE_MAX];
diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c
index 0b413329c..36062e392 100644
--- a/tinyusb/class/hid_device.c
+++ b/tinyusb/class/hid_device.c
@@ -1,466 +1,467 @@
-/**************************************************************************/
-/*!
- @file hid_device.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 && DEVICE_CLASS_HID)
-
-#define _TINY_USB_SOURCE_FILE_
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "common/common.h"
-#include "hid_device.h"
-#include "tusb_descriptors.h"
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-
-enum {
- HIDD_NUMBER_OF_SUBCLASS = 3
-};
-
-typedef struct {
- uint16_t report_length;
-
- endpoint_handle_t ept_handle;
- uint8_t interface_number;
-}hidd_interface_t;
-
-typedef struct {
- uint8_t const * const p_report_desc;
- hidd_interface_t * const p_interface;
- void (* const mounted_cb) (uint8_t coreid);
- void (* const unmounted_cb) (uint8_t coreid);
- void (* const xfer_cb) (uint8_t, tusb_event_t, uint32_t);
- uint16_t (* const get_report_cb) (uint8_t, hid_request_report_type_t, void**, uint16_t );
- void (* const set_report_cb) (uint8_t, hid_request_report_type_t, uint8_t[], uint16_t);
-}hidd_class_driver_t;
-
-extern ATTR_WEAK hidd_interface_t keyboardd_data;
-extern ATTR_WEAK hidd_interface_t moused_data;
-
-static hidd_class_driver_t const hidd_class_driver[HIDD_NUMBER_OF_SUBCLASS] =
-{
-// [HID_PROTOCOL_NONE] = for HID Generic
-
-#if TUSB_CFG_DEVICE_HID_KEYBOARD
- [HID_PROTOCOL_KEYBOARD] =
- {
- .p_report_desc = app_tusb_keyboard_desc_report,
- .p_interface = &keyboardd_data,
- .mounted_cb = tusbd_hid_keyboard_mounted_cb,
- .unmounted_cb = tusbd_hid_keyboard_unmounted_cb,
- .xfer_cb = tusbd_hid_keyboard_cb,
- .get_report_cb = tusbd_hid_keyboard_get_report_cb,
- .set_report_cb = tusbd_hid_keyboard_set_report_cb
- },
-#endif
-
-#if TUSB_CFG_DEVICE_HID_MOUSE
- [HID_PROTOCOL_MOUSE] =
- {
- .p_report_desc = app_tusb_mouse_desc_report,
- .p_interface = &moused_data,
- .mounted_cb = tusbd_hid_mouse_mounted_cb,
- .unmounted_cb = tusbd_hid_mouse_unmounted_cb,
- .xfer_cb = tusbd_hid_mouse_cb,
- .get_report_cb = tusbd_hid_mouse_get_report_cb,
- .set_report_cb = tusbd_hid_mouse_set_report_cb
- }
-#endif
-};
-
-#if TUSB_CFG_DEVICE_HID_KEYBOARD || TUSB_CFG_DEVICE_HID_MOUSE
-ATTR_USB_MIN_ALIGNMENT uint8_t m_control_data[ MAX_OF(sizeof(hid_keyboard_report_t), sizeof(hid_mouse_report_t)) ] TUSB_CFG_ATTR_USBRAM;
-#endif
-
-//--------------------------------------------------------------------+
-// KEYBOARD APPLICATION API
-//--------------------------------------------------------------------+
-#if TUSB_CFG_DEVICE_HID_KEYBOARD
-STATIC_VAR TUSB_CFG_ATTR_USBRAM hidd_interface_t keyboardd_data;
-
-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_report)
-{
- ASSERT(tusbd_is_configured(coreid), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
-
- hidd_interface_t * p_kbd = &keyboardd_data; // TODO &keyboardd_data[coreid];
-
- ASSERT_STATUS( dcd_pipe_xfer(p_kbd->ept_handle, p_report, sizeof(hid_keyboard_report_t), true) ) ;
-
- return TUSB_ERROR_NONE;
-}
-#endif
-
-//--------------------------------------------------------------------+
-// MOUSE APPLICATION API
-//--------------------------------------------------------------------+
-#if TUSB_CFG_DEVICE_HID_MOUSE
-STATIC_VAR TUSB_CFG_ATTR_USBRAM hidd_interface_t moused_data;
-
-bool tusbd_hid_mouse_is_busy(uint8_t coreid)
-{
- return dcd_pipe_is_busy(moused_data.ept_handle);
-}
-
-tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_report)
-{
- ASSERT(tusbd_is_configured(coreid), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
-
- hidd_interface_t * p_mouse = &moused_data; // TODO &keyboardd_data[coreid];
-
- ASSERT_STATUS( dcd_pipe_xfer(p_mouse->ept_handle, p_report, sizeof(hid_mouse_report_t), true) ) ;
-
- return TUSB_ERROR_NONE;
-}
-#endif
-
-//--------------------------------------------------------------------+
-// USBD-CLASS API
-//--------------------------------------------------------------------+
-static void interface_clear(hidd_interface_t * p_interface)
-{
- if ( p_interface != NULL )
- {
- memclr_(p_interface, sizeof(hidd_interface_t));
- p_interface->interface_number = INTERFACE_INVALID_NUMBER;
- }
-}
-
-void hidd_init(void)
-{
- for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
- {
- interface_clear( hidd_class_driver[i].p_interface );
- }
-}
-
-void hidd_close(uint8_t coreid)
-{
- for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
- {
- interface_clear(hidd_class_driver[i].p_interface);
- if ( hidd_class_driver[i].unmounted_cb )
- {
- hidd_class_driver[i].unmounted_cb(coreid);
- }
- }
-}
-
-tusb_error_t hidd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * p_request)
-{
- uint8_t subclass_idx;
- for(subclass_idx=0; subclass_idx<HIDD_NUMBER_OF_SUBCLASS; subclass_idx++)
- {
- hidd_interface_t * const p_interface = hidd_class_driver[subclass_idx].p_interface;
- if ( (p_interface != NULL) && (p_request->wIndex == p_interface->interface_number) )
- {
- break;
- }
- }
-
- ASSERT(subclass_idx < HIDD_NUMBER_OF_SUBCLASS, TUSB_ERROR_FAILED);
-
- hidd_class_driver_t const * const p_driver = &hidd_class_driver[subclass_idx];
- hidd_interface_t* const p_hid = p_driver->p_interface;
-
- //------------- STD Request -------------//
- if (p_request->bmRequestType_bit.type == TUSB_REQUEST_TYPE_STANDARD)
- {
- uint8_t const desc_type = u16_high_u8(p_request->wValue);
- uint8_t const desc_index = u16_low_u8 (p_request->wValue);
-
- (void) desc_index;
-
- ASSERT ( p_request->bRequest == TUSB_REQUEST_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT,
- TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT);
-
- dcd_pipe_control_xfer(coreid, TUSB_DIR_DEV_TO_HOST, p_driver->p_report_desc, p_hid->report_length, false);
- }
- //------------- Class Specific Request -------------//
- else if (p_request->bmRequestType_bit.type == TUSB_REQUEST_TYPE_CLASS)
- {
- OSAL_SUBTASK_BEGIN
-
- if( (HID_REQUEST_CONTROL_GET_REPORT == p_request->bRequest) && (p_driver->get_report_cb != NULL) )
- {
- // wValue = Report Type | Report ID
- void* p_buffer = NULL;
-
- uint16_t actual_length = p_driver->get_report_cb(coreid, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
- &p_buffer, p_request->wLength);
- SUBTASK_ASSERT( p_buffer != NULL && actual_length > 0 );
-
- dcd_pipe_control_xfer(coreid, p_request->bmRequestType_bit.direction, p_buffer, actual_length, false);
- }
- else if ( (HID_REQUEST_CONTROL_SET_REPORT == p_request->bRequest) && (p_driver->set_report_cb != NULL) )
- {
- // return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard)
- // wValue = Report Type | Report ID
- tusb_error_t error;
-
- dcd_pipe_control_xfer(coreid, p_request->bmRequestType_bit.direction, &m_control_data, p_request->wLength, true);
-
- osal_semaphore_wait(usbd_control_xfer_sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // wait for control xfer complete
- SUBTASK_ASSERT_STATUS(error);
-
- p_driver->set_report_cb(coreid, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
- &m_control_data, p_request->wLength);
- }
- else if (HID_REQUEST_CONTROL_SET_IDLE == p_request->bRequest)
- {
- // uint8_t idle_rate = u16_high_u8(p_request->wValue);
- }else
- {
-// HID_REQUEST_CONTROL_GET_IDLE:
-// HID_REQUEST_CONTROL_GET_PROTOCOL:
-// HID_REQUEST_CONTROL_SET_PROTOCOL:
- return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
- }
-
- OSAL_SUBTASK_END
- }else
- {
- return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
- }
-
- return TUSB_ERROR_NONE;
-}
-
-tusb_error_t hidd_open(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)
- {
- case HID_PROTOCOL_KEYBOARD:
- case HID_PROTOCOL_MOUSE:
- {
- hidd_class_driver_t const * const p_driver = &hidd_class_driver[p_interface_desc->bInterfaceProtocol];
- hidd_interface_t * const p_hid = p_driver->p_interface;
-
- ASSERT_PTR(p_hid, TUSB_ERROR_FAILED);
-
- p_hid->ept_handle = dcd_pipe_open(coreid, p_desc_endpoint, p_interface_desc->bInterfaceClass);
- ASSERT( endpointhandle_is_valid(p_hid->ept_handle), TUSB_ERROR_DCD_FAILED);
-
- p_hid->interface_number = p_interface_desc->bInterfaceNumber;
- p_hid->report_length = p_desc_hid->wReportLength;
-
- p_driver->mounted_cb(coreid);
- }
- break;
-
- 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;
-}
-
-tusb_error_t hidd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes)
-{
- for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
- {
- hidd_interface_t * const p_interface = hidd_class_driver[i].p_interface;
- if ( (p_interface != NULL) && endpointhandle_is_equal(edpt_hdl, p_interface->ept_handle) )
- {
- hidd_class_driver[i].xfer_cb(edpt_hdl.coreid, event, xferred_bytes);
- }
- }
-
- return TUSB_ERROR_NONE;
-}
-
-#if defined(CAP_DEVICE_ROMDRIVER)
-
-//--------------------------------------------------------------------+
-// MACRO CONSTANT TYPEDEF
-//--------------------------------------------------------------------+
-#if TUSB_CFG_DEVICE_HID_KEYBOARD
-TUSB_CFG_ATTR_USBRAM uint8_t hidd_keyboard_buffer[1024]; // TODO memory reduce
-TUSB_CFG_ATTR_USBRAM hid_keyboard_report_t hid_keyboard_report;
-static volatile bool bKeyChanged = false;
-#endif
-
-#if TUSB_CFG_DEVICE_HID_MOUSE
-TUSB_CFG_ATTR_USBRAM uint8_t hidd_mouse_buffer[1024]; // TODO memory reduce
-TUSB_CFG_ATTR_USBRAM hid_mouse_report_t hid_mouse_report;
-static volatile bool bMouseChanged = false;
-#endif
-
-//--------------------------------------------------------------------+
-// APPLICATION API
-//--------------------------------------------------------------------+
-
-//--------------------------------------------------------------------+
-// IMPLEMENTATION
-//--------------------------------------------------------------------+
-ErrorCode_t HID_GetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* plength)
-{
- USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*) hHid;
-
- /* ReportID = SetupPacket.wValue.WB.L; */
- if (pSetup->wValue.WB.H == HID_REQUEST_REPORT_INPUT)
- return (ERR_USBD_STALL); /* Not Supported */
-
- switch (pHidCtrl->protocol)
- {
- #if TUSB_CFG_DEVICE_HID_KEYBOARD
- case HID_PROTOCOL_KEYBOARD:
- *pBuffer = (uint8_t*) &hid_keyboard_report;
- *plength = sizeof(hid_keyboard_report_t);
-
- if (!bKeyChanged)
- {
- memset(pBuffer, 0, *plength);
- }
- bKeyChanged = false;
- break;
- #endif
-
- #if TUSB_CFG_DEVICE_HID_MOUSE
- case HID_PROTOCOL_MOUSE:
- *pBuffer = (uint8_t*) &hid_mouse_report;
- *plength = sizeof(hid_mouse_report_t);
-
- if (!bMouseChanged)
- {
- memset(pBuffer, 0, *plength);
- }
- bMouseChanged = false;
- break;
- #endif
-
- default:
- break;
- }
-
- return (LPC_OK);
-}
-
-ErrorCode_t HID_SetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length)
-{
- /* we will reuse standard EP0Buf */
- if (length == 0)
- return LPC_OK;
-
- /* ReportID = SetupPacket.wValue.WB.L; */
- if (pSetup->wValue.WB.H != HID_REQUEST_REPORT_OUTPUT)
- return (ERR_USBD_STALL); /* Not Supported */
-
- return (LPC_OK);
-}
-
-ErrorCode_t HID_EpIn_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
-{
- if (USB_EVT_IN == event)
- {
- USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;
- switch(pHidCtrl->protocol)
- {
- #if TUSB_CFG_DEVICE_HID_KEYBOARD
- case HID_PROTOCOL_KEYBOARD:
- if (!bKeyChanged)
- {
- memset(&hid_keyboard_report, 0, sizeof(hid_keyboard_report_t));
- }
- ROM_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_keyboard_report, sizeof(hid_keyboard_report_t));
- bKeyChanged = false;
- break;
- #endif
-
- #if TUSB_CFG_DEVICE_HID_MOUSE
- case HID_PROTOCOL_MOUSE:
- if (!bMouseChanged)
- {
- memset(&hid_mouse_report, 0, sizeof(hid_mouse_report_t));
- }
- ROM_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_mouse_report, sizeof(hid_mouse_report_t));
- bMouseChanged = false;
- break;
- #endif
-
- default:
- break;
- }
- }
-
- return LPC_OK;
-}
-
-ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
-{
- if (USB_EVT_OUT == event)
- {
- // not used yet
- // uint8_t outreport[8];
- // USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;
- // ROM_API->hw->ReadEP(hUsb, pHidCtrl->epout_adr, outreport);
- }
- return LPC_OK;
-}
-
-#endif
-
-#endif
+/**************************************************************************/
+/*!
+ @file hid_device.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 && DEVICE_CLASS_HID)
+
+#define _TINY_USB_SOURCE_FILE_
+//--------------------------------------------------------------------+
+// INCLUDE
+//--------------------------------------------------------------------+
+#include "common/common.h"
+#include "hid_device.h"
+#include "tusb_descriptors.h"
+
+//--------------------------------------------------------------------+
+// MACRO CONSTANT TYPEDEF
+//--------------------------------------------------------------------+
+
+enum {
+ HIDD_NUMBER_OF_SUBCLASS = 3
+};
+
+typedef struct {
+ uint16_t report_length;
+
+ endpoint_handle_t ept_handle;
+ uint8_t interface_number;
+}hidd_interface_t;
+
+typedef struct {
+ uint8_t const * const p_report_desc;
+ hidd_interface_t * const p_interface;
+ void (* const mounted_cb) (uint8_t coreid);
+ void (* const unmounted_cb) (uint8_t coreid);
+ void (* const xfer_cb) (uint8_t, tusb_event_t, uint32_t);
+ uint16_t (* const get_report_cb) (uint8_t, hid_request_report_type_t, void**, uint16_t );
+ void (* const set_report_cb) (uint8_t, hid_request_report_type_t, uint8_t[], uint16_t);
+}hidd_class_driver_t;
+
+extern ATTR_WEAK hidd_interface_t keyboardd_data;
+extern ATTR_WEAK hidd_interface_t moused_data;
+
+static hidd_class_driver_t const hidd_class_driver[HIDD_NUMBER_OF_SUBCLASS] =
+{
+// [HID_PROTOCOL_NONE] = for HID Generic
+
+#if TUSB_CFG_DEVICE_HID_KEYBOARD
+ [HID_PROTOCOL_KEYBOARD] =
+ {
+ .p_report_desc = app_tusb_keyboard_desc_report,
+ .p_interface = &keyboardd_data,
+ .mounted_cb = tusbd_hid_keyboard_mounted_cb,
+ .unmounted_cb = tusbd_hid_keyboard_unmounted_cb,
+ .xfer_cb = tusbd_hid_keyboard_cb,
+ .get_report_cb = tusbd_hid_keyboard_get_report_cb,
+ .set_report_cb = tusbd_hid_keyboard_set_report_cb
+ },
+#endif
+
+#if TUSB_CFG_DEVICE_HID_MOUSE
+ [HID_PROTOCOL_MOUSE] =
+ {
+ .p_report_desc = app_tusb_mouse_desc_report,
+ .p_interface = &moused_data,
+ .mounted_cb = tusbd_hid_mouse_mounted_cb,
+ .unmounted_cb = tusbd_hid_mouse_unmounted_cb,
+ .xfer_cb = tusbd_hid_mouse_cb,
+ .get_report_cb = tusbd_hid_mouse_get_report_cb,
+ .set_report_cb = tusbd_hid_mouse_set_report_cb
+ }
+#endif
+};
+
+#if TUSB_CFG_DEVICE_HID_KEYBOARD || TUSB_CFG_DEVICE_HID_MOUSE
+TUSB_CFG_ATTR_USBRAM ATTR_USB_MIN_ALIGNMENT
+uint8_t m_control_data[ MAX_OF(sizeof(hid_keyboard_report_t), sizeof(hid_mouse_report_t)) ];
+#endif
+
+//--------------------------------------------------------------------+
+// KEYBOARD APPLICATION API
+//--------------------------------------------------------------------+
+#if TUSB_CFG_DEVICE_HID_KEYBOARD
+TUSB_CFG_ATTR_USBRAM STATIC_VAR hidd_interface_t keyboardd_data;
+
+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_report)
+{
+ ASSERT(tusbd_is_configured(coreid), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
+
+ hidd_interface_t * p_kbd = &keyboardd_data; // TODO &keyboardd_data[coreid];
+
+ ASSERT_STATUS( dcd_pipe_xfer(p_kbd->ept_handle, (void*) p_report, sizeof(hid_keyboard_report_t), true) ) ;
+
+ return TUSB_ERROR_NONE;
+}
+#endif
+
+//--------------------------------------------------------------------+
+// MOUSE APPLICATION API
+//--------------------------------------------------------------------+
+#if TUSB_CFG_DEVICE_HID_MOUSE
+TUSB_CFG_ATTR_USBRAM STATIC_VAR hidd_interface_t moused_data;
+
+bool tusbd_hid_mouse_is_busy(uint8_t coreid)
+{
+ return dcd_pipe_is_busy(moused_data.ept_handle);
+}
+
+tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_report)
+{
+ ASSERT(tusbd_is_configured(coreid), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
+
+ hidd_interface_t * p_mouse = &moused_data; // TODO &keyboardd_data[coreid];
+
+ ASSERT_STATUS( dcd_pipe_xfer(p_mouse->ept_handle, (void*) p_report, sizeof(hid_mouse_report_t), true) ) ;
+
+ return TUSB_ERROR_NONE;
+}
+#endif
+
+//--------------------------------------------------------------------+
+// USBD-CLASS API
+//--------------------------------------------------------------------+
+static void interface_clear(hidd_interface_t * p_interface)
+{
+ if ( p_interface != NULL )
+ {
+ memclr_(p_interface, sizeof(hidd_interface_t));
+ p_interface->interface_number = INTERFACE_INVALID_NUMBER;
+ }
+}
+
+void hidd_init(void)
+{
+ for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
+ {
+ interface_clear( hidd_class_driver[i].p_interface );
+ }
+}
+
+void hidd_close(uint8_t coreid)
+{
+ for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
+ {
+ interface_clear(hidd_class_driver[i].p_interface);
+ if ( hidd_class_driver[i].unmounted_cb )
+ {
+ hidd_class_driver[i].unmounted_cb(coreid);
+ }
+ }
+}
+
+tusb_error_t hidd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * p_request)
+{
+ uint8_t subclass_idx;
+ for(subclass_idx=0; subclass_idx<HIDD_NUMBER_OF_SUBCLASS; subclass_idx++)
+ {
+ hidd_interface_t * const p_interface = hidd_class_driver[subclass_idx].p_interface;
+ if ( (p_interface != NULL) && (p_request->wIndex == p_interface->interface_number) )
+ {
+ break;
+ }
+ }
+
+ ASSERT(subclass_idx < HIDD_NUMBER_OF_SUBCLASS, TUSB_ERROR_FAILED);
+
+ hidd_class_driver_t const * const p_driver = &hidd_class_driver[subclass_idx];
+ hidd_interface_t* const p_hid = p_driver->p_interface;
+
+ //------------- STD Request -------------//
+ if (p_request->bmRequestType_bit.type == TUSB_REQUEST_TYPE_STANDARD)
+ {
+ uint8_t const desc_type = u16_high_u8(p_request->wValue);
+ uint8_t const desc_index = u16_low_u8 (p_request->wValue);
+
+ (void) desc_index;
+
+ ASSERT ( p_request->bRequest == TUSB_REQUEST_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT,
+ TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT);
+
+ dcd_pipe_control_xfer(coreid, TUSB_DIR_DEV_TO_HOST, (uint8_t*) p_driver->p_report_desc, p_hid->report_length, false);
+ }
+ //------------- Class Specific Request -------------//
+ else if (p_request->bmRequestType_bit.type == TUSB_REQUEST_TYPE_CLASS)
+ {
+ OSAL_SUBTASK_BEGIN
+
+ if( (HID_REQUEST_CONTROL_GET_REPORT == p_request->bRequest) && (p_driver->get_report_cb != NULL) )
+ {
+ // wValue = Report Type | Report ID
+ void* p_buffer = NULL;
+
+ uint16_t actual_length = p_driver->get_report_cb(coreid, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
+ &p_buffer, p_request->wLength);
+ SUBTASK_ASSERT( p_buffer != NULL && actual_length > 0 );
+
+ dcd_pipe_control_xfer(coreid, p_request->bmRequestType_bit.direction, p_buffer, actual_length, false);
+ }
+ else if ( (HID_REQUEST_CONTROL_SET_REPORT == p_request->bRequest) && (p_driver->set_report_cb != NULL) )
+ {
+ // return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard)
+ // wValue = Report Type | Report ID
+ tusb_error_t error;
+
+ dcd_pipe_control_xfer(coreid, p_request->bmRequestType_bit.direction, m_control_data, p_request->wLength, true);
+
+ osal_semaphore_wait(usbd_control_xfer_sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // wait for control xfer complete
+ SUBTASK_ASSERT_STATUS(error);
+
+ p_driver->set_report_cb(coreid, (hid_request_report_type_t) u16_high_u8(p_request->wValue),
+ m_control_data, p_request->wLength);
+ }
+ else if (HID_REQUEST_CONTROL_SET_IDLE == p_request->bRequest)
+ {
+ // uint8_t idle_rate = u16_high_u8(p_request->wValue);
+ }else
+ {
+// HID_REQUEST_CONTROL_GET_IDLE:
+// HID_REQUEST_CONTROL_GET_PROTOCOL:
+// HID_REQUEST_CONTROL_SET_PROTOCOL:
+ return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
+ }
+
+ OSAL_SUBTASK_END
+ }else
+ {
+ return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
+ }
+
+ return TUSB_ERROR_NONE;
+}
+
+tusb_error_t hidd_open(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)
+ {
+ case HID_PROTOCOL_KEYBOARD:
+ case HID_PROTOCOL_MOUSE:
+ {
+ hidd_class_driver_t const * const p_driver = &hidd_class_driver[p_interface_desc->bInterfaceProtocol];
+ hidd_interface_t * const p_hid = p_driver->p_interface;
+
+ ASSERT_PTR(p_hid, TUSB_ERROR_FAILED);
+
+ p_hid->ept_handle = dcd_pipe_open(coreid, p_desc_endpoint, p_interface_desc->bInterfaceClass);
+ ASSERT( endpointhandle_is_valid(p_hid->ept_handle), TUSB_ERROR_DCD_FAILED);
+
+ p_hid->interface_number = p_interface_desc->bInterfaceNumber;
+ p_hid->report_length = p_desc_hid->wReportLength;
+
+ p_driver->mounted_cb(coreid);
+ }
+ break;
+
+ 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;
+}
+
+tusb_error_t hidd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes)
+{
+ for(uint8_t i=0; i<HIDD_NUMBER_OF_SUBCLASS; i++)
+ {
+ hidd_interface_t * const p_interface = hidd_class_driver[i].p_interface;
+ if ( (p_interface != NULL) && endpointhandle_is_equal(edpt_hdl, p_interface->ept_handle) )
+ {
+ hidd_class_driver[i].xfer_cb(edpt_hdl.coreid, event, xferred_bytes);
+ }
+ }
+
+ return TUSB_ERROR_NONE;
+}
+
+#if defined(CAP_DEVICE_ROMDRIVER)
+
+//--------------------------------------------------------------------+
+// MACRO CONSTANT TYPEDEF
+//--------------------------------------------------------------------+
+#if TUSB_CFG_DEVICE_HID_KEYBOARD
+TUSB_CFG_ATTR_USBRAM uint8_t hidd_keyboard_buffer[1024]; // TODO memory reduce
+TUSB_CFG_ATTR_USBRAM hid_keyboard_report_t hid_keyboard_report;
+static volatile bool bKeyChanged = false;
+#endif
+
+#if TUSB_CFG_DEVICE_HID_MOUSE
+TUSB_CFG_ATTR_USBRAM uint8_t hidd_mouse_buffer[1024]; // TODO memory reduce
+TUSB_CFG_ATTR_USBRAM hid_mouse_report_t hid_mouse_report;
+static volatile bool bMouseChanged = false;
+#endif
+
+//--------------------------------------------------------------------+
+// APPLICATION API
+//--------------------------------------------------------------------+
+
+//--------------------------------------------------------------------+
+// IMPLEMENTATION
+//--------------------------------------------------------------------+
+ErrorCode_t HID_GetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* plength)
+{
+ USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*) hHid;
+
+ /* ReportID = SetupPacket.wValue.WB.L; */
+ if (pSetup->wValue.WB.H == HID_REQUEST_REPORT_INPUT)
+ return (ERR_USBD_STALL); /* Not Supported */
+
+ switch (pHidCtrl->protocol)
+ {
+ #if TUSB_CFG_DEVICE_HID_KEYBOARD
+ case HID_PROTOCOL_KEYBOARD:
+ *pBuffer = (uint8_t*) &hid_keyboard_report;
+ *plength = sizeof(hid_keyboard_report_t);
+
+ if (!bKeyChanged)
+ {
+ memset(pBuffer, 0, *plength);
+ }
+ bKeyChanged = false;
+ break;
+ #endif
+
+ #if TUSB_CFG_DEVICE_HID_MOUSE
+ case HID_PROTOCOL_MOUSE:
+ *pBuffer = (uint8_t*) &hid_mouse_report;
+ *plength = sizeof(hid_mouse_report_t);
+
+ if (!bMouseChanged)
+ {
+ memset(pBuffer, 0, *plength);
+ }
+ bMouseChanged = false;
+ break;
+ #endif
+
+ default:
+ break;
+ }
+
+ return (LPC_OK);
+}
+
+ErrorCode_t HID_SetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length)
+{
+ /* we will reuse standard EP0Buf */
+ if (length == 0)
+ return LPC_OK;
+
+ /* ReportID = SetupPacket.wValue.WB.L; */
+ if (pSetup->wValue.WB.H != HID_REQUEST_REPORT_OUTPUT)
+ return (ERR_USBD_STALL); /* Not Supported */
+
+ return (LPC_OK);
+}
+
+ErrorCode_t HID_EpIn_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
+{
+ if (USB_EVT_IN == event)
+ {
+ USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;
+ switch(pHidCtrl->protocol)
+ {
+ #if TUSB_CFG_DEVICE_HID_KEYBOARD
+ case HID_PROTOCOL_KEYBOARD:
+ if (!bKeyChanged)
+ {
+ memset(&hid_keyboard_report, 0, sizeof(hid_keyboard_report_t));
+ }
+ ROM_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_keyboard_report, sizeof(hid_keyboard_report_t));
+ bKeyChanged = false;
+ break;
+ #endif
+
+ #if TUSB_CFG_DEVICE_HID_MOUSE
+ case HID_PROTOCOL_MOUSE:
+ if (!bMouseChanged)
+ {
+ memset(&hid_mouse_report, 0, sizeof(hid_mouse_report_t));
+ }
+ ROM_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, (uint8_t*) &hid_mouse_report, sizeof(hid_mouse_report_t));
+ bMouseChanged = false;
+ break;
+ #endif
+
+ default:
+ break;
+ }
+ }
+
+ return LPC_OK;
+}
+
+ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
+{
+ if (USB_EVT_OUT == event)
+ {
+ // not used yet
+ // uint8_t outreport[8];
+ // USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;
+ // ROM_API->hw->ReadEP(hUsb, pHidCtrl->epout_adr, outreport);
+ }
+ return LPC_OK;
+}
+
+#endif
+
+#endif
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index e61590eab..fb50a6e03 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -180,7 +180,7 @@ void hidh_init(void)
}
#if 0
-uint8_t report_descriptor[256] TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM uint8_t report_descriptor[256];
#endif
tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length)
diff --git a/tinyusb/class/msc_device.c b/tinyusb/class/msc_device.c
index 6a9251d19..997145499 100644
--- a/tinyusb/class/msc_device.c
+++ b/tinyusb/class/msc_device.c
@@ -62,7 +62,7 @@ typedef struct {
ATTR_USB_MIN_ALIGNMENT msc_cmd_status_wrapper_t csw;
}mscd_interface_t;
-STATIC_VAR mscd_interface_t mscd_data TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM STATIC_VAR mscd_interface_t mscd_data;
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
@@ -109,7 +109,7 @@ tusb_error_t mscd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int
(*p_length) += sizeof(tusb_descriptor_interface_t) + 2*sizeof(tusb_descriptor_endpoint_t);
//------------- Queue Endpoint OUT for Command Block Wrapper -------------//
- ASSERT_STATUS( dcd_pipe_xfer(p_msc->edpt_out, &p_msc->cbw, sizeof(msc_cmd_block_wrapper_t), true) );
+ ASSERT_STATUS( dcd_pipe_xfer(p_msc->edpt_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cmd_block_wrapper_t), true) );
return TUSB_ERROR_NONE;
}
@@ -202,10 +202,10 @@ tusb_error_t mscd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32
// Either bulk in & out can be stalled in the data phase, dcd must make sure these queued transfer will be resumed after host clear stall
if (!is_waiting_read10_write10)
{
- ASSERT_STATUS( dcd_pipe_xfer( p_msc->edpt_in , p_csw, sizeof(msc_cmd_status_wrapper_t), false) );
+ ASSERT_STATUS( dcd_pipe_xfer( p_msc->edpt_in , (uint8_t*) p_csw, sizeof(msc_cmd_status_wrapper_t), false) );
//------------- Queue the next CBW -------------//
- ASSERT_STATUS( dcd_pipe_xfer( p_msc->edpt_out, p_cbw, sizeof(msc_cmd_block_wrapper_t), true) );
+ ASSERT_STATUS( dcd_pipe_xfer( p_msc->edpt_out, (uint8_t*) p_cbw, sizeof(msc_cmd_block_wrapper_t), true) );
}
return TUSB_ERROR_NONE;
diff --git a/tinyusb/class/msc_host.c b/tinyusb/class/msc_host.c
index ac62e5d9a..dcb3fff6f 100644
--- a/tinyusb/class/msc_host.c
+++ b/tinyusb/class/msc_host.c
@@ -51,7 +51,7 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
-STATIC_VAR msch_interface_t msch_data[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM STATIC_VAR msch_interface_t msch_data[TUSB_CFG_HOST_DEVICE_MAX];
//------------- Initalization Data -------------//
@@ -59,7 +59,7 @@ OSAL_SEM_DEF(msch_semaphore);
static osal_semaphore_handle_t msch_sem_hdl;
// buffer used to read scsi information when mounted, largest response data currently is inquiry
-ATTR_ALIGNED(4) STATIC_VAR uint8_t msch_buffer[sizeof(scsi_inquiry_data_t)] TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) STATIC_VAR uint8_t msch_buffer[sizeof(scsi_inquiry_data_t)];
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
diff --git a/tinyusb/common/compiler/compiler.h b/tinyusb/common/compiler/compiler.h
index 738711416..4c81047c7 100644
--- a/tinyusb/common/compiler/compiler.h
+++ b/tinyusb/common/compiler/compiler.h
@@ -49,6 +49,7 @@
#ifndef _TEST_
#define STATIC_ static
#define INLINE_ inline
+ #define ATTR_TEST_WEAK
#if TUSB_CFG_DEBUG == 3
#define ATTR_ALWAYS_INLINE // no inline for debug = 3
@@ -56,12 +57,13 @@
#else
#define STATIC_VAR static
#endif
- #define ATTR_TEST_WEAK
+
#else
#define ATTR_ALWAYS_INLINE
#define STATIC_
#define STATIC_VAR
#define INLINE_
+
#endif
#if defined(__GNUC__)
diff --git a/tinyusb/common/compiler/compiler_iar.h b/tinyusb/common/compiler/compiler_iar.h
index cd94f5b2f..7103ee092 100644
--- a/tinyusb/common/compiler/compiler_iar.h
+++ b/tinyusb/common/compiler/compiler_iar.h
@@ -57,17 +57,9 @@
#define ATTR_PACKED_STRUCT(x) __packed x
#define ATTR_PREPACKED __packed
#define ATTR_PACKED
+//#define ATTR_SECTION(section) _Pragma((#section))
-#define ATTR_ALIGNED(Bytes) ATTR_ALIGNED_##Bytes
-#define ATTR_ALIGNED_4096 _Pragma("data_alignment=4096")
-#define ATTR_ALIGNED_2048 _Pragma("data_alignment=2048")
-#define ATTR_ALIGNED_256 _Pragma("data_alignment=256")
-#define ATTR_ALIGNED_128 _Pragma("data_alignment=128")
-#define ATTR_ALIGNED_64 _Pragma("data_alignment=64")
-#define ATTR_ALIGNED_48 _Pragma("data_alignment=48")
-#define ATTR_ALIGNED_32 _Pragma("data_alignment=32")
-#define ATTR_ALIGNED_16 _Pragma("data_alignment=16")
-#define ATTR_ALIGNED_4 _Pragma("data_alignment=4")
+#define ATTR_ALIGNED(bytes) _Pragma(XSTRING_(data_alignment=##bytes))
#ifndef ATTR_ALWAYS_INLINE
/// Generally, functions are not inlined unless optimization is specified. For functions declared inline, this attribute inlines the function even if no optimization level is specified
diff --git a/tinyusb/common/fifo.h b/tinyusb/common/fifo.h
index daef4a84a..4a518ca0c 100644
--- a/tinyusb/common/fifo.h
+++ b/tinyusb/common/fifo.h
@@ -55,23 +55,24 @@
*/
typedef struct
{
+ uint8_t* const buffer ; ///< buffer pointer
uint16_t const depth ; ///< max items
uint16_t const item_size ; ///< size of each item
volatile uint16_t count ; ///< number of items in queue
volatile uint16_t wr_idx ; ///< write pointer
volatile uint16_t rd_idx ; ///< read pointer
bool overwritable ;
- uint8_t buffer[] ; ///< buffer pointer
// IRQn_Type irq;
} fifo_t;
#define FIFO_DEF(name, ff_depth, type, is_overwritable) /*, irq_mutex)*/ \
+ uint8_t name##_buffer[ff_depth*sizeof(type)];\
fifo_t name = {\
+ .buffer = name##_buffer,\
.depth = ff_depth,\
.item_size = sizeof(type),\
.overwritable = is_overwritable,\
/*.irq = irq_mutex*/\
- .buffer = { [ff_depth*sizeof(type) - 1] = 0 },\
}
bool fifo_write(fifo_t* f, void const * p_data);
diff --git a/tinyusb/device/dcd.h b/tinyusb/device/dcd.h
index f84a26d95..95eef8fce 100644
--- a/tinyusb/device/dcd.h
+++ b/tinyusb/device/dcd.h
@@ -75,18 +75,18 @@ tusb_error_t dcd_init(void) ATTR_WARN_UNUSED_RESULT;
void dcd_isr(uint8_t coreid);
//------------- Controller API -------------//
-void dcd_controller_connect(uint8_t coreid);
-void dcd_controller_disconnect(uint8_t coreid);
-void dcd_controller_set_address(uint8_t coreid, uint8_t dev_addr);
-void dcd_controller_set_configuration(uint8_t coreid);
+void dcd_controller_connect (uint8_t coreid);
+void dcd_controller_disconnect (uint8_t coreid);
+void dcd_controller_set_address (uint8_t coreid, uint8_t dev_addr);
+void dcd_controller_set_configuration (uint8_t coreid);
//------------- PIPE API -------------//
-tusb_error_t dcd_pipe_control_xfer(uint8_t coreid, tusb_direction_t dir, void * p_buffer, uint16_t length, bool int_on_complete);
+tusb_error_t dcd_pipe_control_xfer(uint8_t coreid, tusb_direction_t dir, uint8_t * p_buffer, uint16_t length, bool int_on_complete);
void dcd_pipe_control_stall(uint8_t coreid);
endpoint_handle_t dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, uint8_t class_code) ATTR_WARN_UNUSED_RESULT;
-tusb_error_t dcd_pipe_queue_xfer(endpoint_handle_t edpt_hdl, void * buffer, uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet
-tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, void * buffer, uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
+tusb_error_t dcd_pipe_queue_xfer(endpoint_handle_t edpt_hdl, uint8_t * buffer, uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet
+tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, uint8_t * buffer, uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT;
tusb_error_t dcd_pipe_stall(endpoint_handle_t edpt_hdl) ATTR_WARN_UNUSED_RESULT;
bool dcd_pipe_is_busy(endpoint_handle_t edpt_hdl) ATTR_WARN_UNUSED_RESULT ;
diff --git a/tinyusb/device/dcd_lpc175x_6x.c b/tinyusb/device/dcd_lpc175x_6x.c
index 058891e54..df6c49154 100644
--- a/tinyusb/device/dcd_lpc175x_6x.c
+++ b/tinyusb/device/dcd_lpc175x_6x.c
@@ -68,7 +68,7 @@ typedef struct {
}dcd_data_t;
-STATIC_ dcd_data_t dcd_data TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM STATIC_ dcd_data_t dcd_data;
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
@@ -372,7 +372,7 @@ void dcd_pipe_control_stall(uint8_t coreid)
sie_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+0, 1, SIE_SET_ENDPOINT_STALLED_MASK | SIE_SET_ENDPOINT_CONDITION_STALLED_MASK);
}
-tusb_error_t dcd_pipe_control_xfer(uint8_t coreid, tusb_direction_t dir, void * p_buffer, uint16_t length, bool int_on_complete)
+tusb_error_t dcd_pipe_control_xfer(uint8_t coreid, tusb_direction_t dir, uint8_t * p_buffer, uint16_t length, bool int_on_complete)
{
(void) coreid;
@@ -473,7 +473,7 @@ void dd_xfer_init(dcd_dma_descriptor_t* p_dd, void* buffer, uint16_t total_bytes
p_dd->present_count = 0;
}
-tusb_error_t dcd_pipe_queue_xfer(endpoint_handle_t edpt_hdl, void * buffer, uint16_t total_bytes)
+tusb_error_t dcd_pipe_queue_xfer(endpoint_handle_t edpt_hdl, uint8_t * buffer, uint16_t total_bytes)
{ // NOTE for sure the qhd has no dds
dcd_dma_descriptor_t* const p_fixed_dd = &dcd_data.dd[edpt_hdl.index][0]; // always queue with the fixed DD
@@ -484,7 +484,7 @@ tusb_error_t dcd_pipe_queue_xfer(endpoint_handle_t edpt_hdl, void * buffer, uint
return TUSB_ERROR_NONE;
}
-tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, void * buffer, uint16_t total_bytes, bool int_on_complete)
+tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, uint8_t* buffer, uint16_t total_bytes, bool int_on_complete)
{
dcd_dma_descriptor_t* const p_first_dd = &dcd_data.dd[edpt_hdl.index][0];
diff --git a/tinyusb/device/dcd_lpc43xx.c b/tinyusb/device/dcd_lpc43xx.c
index c5d6eb666..05e47fd11 100644
--- a/tinyusb/device/dcd_lpc43xx.c
+++ b/tinyusb/device/dcd_lpc43xx.c
@@ -168,11 +168,11 @@ typedef struct {
}dcd_data_t;
#if (TUSB_CFG_CONTROLLER_0_MODE & TUSB_MODE_DEVICE)
-ATTR_ALIGNED(2048) dcd_data_t dcd_data0 TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(2048) dcd_data_t dcd_data0;
#endif
#if (TUSB_CFG_CONTROLLER_1_MODE & TUSB_MODE_DEVICE)
-ATTR_ALIGNED(2048) dcd_data_t dcd_data1 TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(2048) dcd_data_t dcd_data1;
#endif
static LPC_USB0_Type * const LPC_USB[2] = { LPC_USB0, ((LPC_USB0_Type*) LPC_USB1_BASE) };
diff --git a/tinyusb/device/dcd_lpc_11uxx_13uxx.c b/tinyusb/device/dcd_lpc_11uxx_13uxx.c
index c68248461..0b2e539fb 100644
--- a/tinyusb/device/dcd_lpc_11uxx_13uxx.c
+++ b/tinyusb/device/dcd_lpc_11uxx_13uxx.c
@@ -133,7 +133,7 @@ typedef struct {
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-ATTR_ALIGNED(256) static dcd_11u_13u_data_t dcd_data TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(256) static dcd_11u_13u_data_t dcd_data;
static inline uint16_t addr_offset(void const * p_buffer) ATTR_CONST ATTR_ALWAYS_INLINE;
static inline uint16_t addr_offset(void const * p_buffer)
diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c
index d98773e78..9d606e183 100644
--- a/tinyusb/host/ehci/ehci.c
+++ b/tinyusb/host/ehci/ehci.c
@@ -57,12 +57,12 @@
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-STATIC_VAR ehci_data_t ehci_data TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM STATIC_VAR ehci_data_t ehci_data;
#if EHCI_PERIODIC_LIST
#if (TUSB_CFG_CONTROLLER_0_MODE & TUSB_MODE_HOST)
- ATTR_ALIGNED(4096) STATIC_VAR ehci_link_t period_frame_list0[EHCI_FRAMELIST_SIZE] TUSB_CFG_ATTR_USBRAM;
+ TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4096) STATIC_VAR ehci_link_t period_frame_list0[EHCI_FRAMELIST_SIZE];
#ifndef __ICCARM__ // IAR cannot able to determine the alignment with datalignment pragma
STATIC_ASSERT( ALIGN_OF(period_frame_list0) == 4096, "Period Framelist must be 4k alginment"); // validation
@@ -70,7 +70,7 @@ STATIC_VAR ehci_data_t ehci_data TUSB_CFG_ATTR_USBRAM;
#endif
#if (TUSB_CFG_CONTROLLER_1_MODE & TUSB_MODE_HOST)
- STATIC_VAR ehci_link_t period_frame_list1[EHCI_FRAMELIST_SIZE] ATTR_ALIGNED(4096) TUSB_CFG_ATTR_USBRAM;
+ TUSB_CFG_ATTR_USBRAM STATIC_VAR ehci_link_t period_frame_list1[EHCI_FRAMELIST_SIZE] ATTR_ALIGNED(4096);
#ifndef __ICCARM__ // IAR cannot able to determine the alignment with datalignment pragma
STATIC_ASSERT( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment"); // validation
diff --git a/tinyusb/host/hub.c b/tinyusb/host/hub.c
index 99cebc292..e87ce62f0 100644
--- a/tinyusb/host/hub.c
+++ b/tinyusb/host/hub.c
@@ -58,8 +58,8 @@ typedef struct {
uint8_t status_change; // data from status change interrupt endpoint
}usbh_hub_t;
-usbh_hub_t hub_data[TUSB_CFG_HOST_DEVICE_MAX] TUSB_CFG_ATTR_USBRAM;
-uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)] TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM usbh_hub_t hub_data[TUSB_CFG_HOST_DEVICE_MAX];
+TUSB_CFG_ATTR_USBRAM uint8_t hub_enum_buffer[sizeof(descriptor_hub_desc_t)];
//OSAL_SEM_DEF(hub_enum_semaphore);
//static osal_semaphore_handle_t hub_enum_sem_hdl;
diff --git a/tinyusb/host/ohci/ohci.c b/tinyusb/host/ohci/ohci.c
index 8bcde4d21..ab27c6e5a 100644
--- a/tinyusb/host/ohci/ohci.c
+++ b/tinyusb/host/ohci/ohci.c
@@ -135,7 +135,7 @@ enum {
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-STATIC_VAR ohci_data_t ohci_data TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM STATIC_VAR ohci_data_t ohci_data;
static ohci_ed_t * const p_ed_head[] =
{
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c
index b149c0f3a..f15cdfebb 100644
--- a/tinyusb/host/usbh.c
+++ b/tinyusb/host/usbh.c
@@ -106,14 +106,14 @@ static host_class_driver_t const usbh_class_drivers[TUSB_CLASS_MAPPED_INDEX_END]
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1] TUSB_CFG_ATTR_USBRAM; // including zero-address
+TUSB_CFG_ATTR_USBRAM usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; // including zero-address
//------------- Enumeration Task Data -------------//
OSAL_TASK_DEF(usbh_enumeration_task, 200, TUSB_CFG_OS_TASK_PRIO);
OSAL_QUEUE_DEF(enum_queue_def, ENUM_QUEUE_DEPTH, uint32_t);
static osal_queue_handle_t enum_queue_hdl;
-ATTR_ALIGNED(4) STATIC_VAR uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE] TUSB_CFG_ATTR_USBRAM;
+TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) STATIC_VAR uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE];
//------------- Reporter Task Data -------------//