summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/class/cdc/cdc_device.c10
-rw-r--r--src/class/cdc/cdc_device.h8
-rw-r--r--src/class/hid/hid.h111
-rw-r--r--src/class/hid/hid_device.c106
-rw-r--r--src/class/hid/hid_device.h170
-rw-r--r--src/class/msc/msc_device.c24
-rw-r--r--src/class/msc/msc_device.h14
-rw-r--r--src/common/tusb_types.h4
-rw-r--r--src/device/usbd.c20
-rw-r--r--src/device/usbd.h20
-rw-r--r--src/device/usbd_pvt.h3
-rw-r--r--src/osal/osal.h67
-rw-r--r--src/portable/nordic/nrf5x/dcd_nrf5x.c4
13 files changed, 292 insertions, 269 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index c194aacd8..7a0380e6b 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -71,7 +71,7 @@ typedef struct
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
-CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC] = { { 0 } };
+CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
// TODO will be replaced by dcd_edpt_busy()
bool pending_read_from_host;
@@ -289,14 +289,12 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
(TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) )
{
// next to endpoint descriptor
- (*p_length) += tu_desc_len(p_desc);
p_desc = tu_desc_next(p_desc);
- // Open endpoint pair with usbd helper
- tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in) );
+ // Open endpoint pair
+ TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &p_cdc->ep_out, &p_cdc->ep_in) );
- (*p_length) += 2*sizeof(tusb_desc_endpoint_t);
+ (*p_length) += sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
}
// Prepare for incoming data
diff --git a/src/class/cdc/cdc_device.h b/src/class/cdc/cdc_device.h
index 6c59bac7a..18d6f842f 100644
--- a/src/class/cdc/cdc_device.h
+++ b/src/class/cdc/cdc_device.h
@@ -89,9 +89,17 @@ static inline bool tud_cdc_write_flush (void)
//--------------------------------------------------------------------+
// APPLICATION CALLBACK API (WEAK is optional)
//--------------------------------------------------------------------+
+
+// Invoked when received new data
ATTR_WEAK void tud_cdc_rx_cb(uint8_t itf);
+
+// Invoked when received `wanted_char`
ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
+
+// Invoked when line state DTR & RTS are changed via SET_CONTROL_LINE_STATE
ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
+
+// Invoked when line coding is change via SET_LINE_CODING
ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
/** @} */
diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h
index 637f13295..7c702f4de 100644
--- a/src/class/hid/hid.h
+++ b/src/class/hid/hid.h
@@ -43,6 +43,20 @@
/** \defgroup ClassDriver_HID_Common Common Definitions
* @{ */
+ /// USB HID Descriptor
+typedef struct ATTR_PACKED
+{
+ uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
+ uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
+
+ uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
+ uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
+ uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
+
+ uint8_t bReportType; /**< Type of HID class report. */
+ uint16_t wReportLength; /**< the total size of the Report descriptor. */
+} tusb_hid_descriptor_hid_t;
+
/// HID Subclass
typedef enum
{
@@ -69,9 +83,10 @@ typedef enum
/// HID Request Report Type
typedef enum
{
- HID_REPORT_TYPE_INPUT = 1, ///< Input
- HID_REPORT_TYPE_OUTPUT, ///< Output
- HID_REPORT_TYPE_FEATURE ///< Feature
+ HID_REPORT_TYPE_INVALID = 0,
+ HID_REPORT_TYPE_INPUT, ///< Input
+ HID_REPORT_TYPE_OUTPUT, ///< Output
+ HID_REPORT_TYPE_FEATURE ///< Feature
}hid_report_type_t;
/// HID Class Specific Control Request
@@ -85,59 +100,45 @@ typedef enum
HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol
}hid_request_type_t;
-/// USB HID Descriptor
-typedef struct ATTR_PACKED
-{
- uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
- uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */
-
- uint16_t bcdHID; /**< Numeric expression identifying the HID Class Specification release */
- uint8_t bCountryCode; /**< Numeric expression identifying country code of the localized hardware. */
- uint8_t bNumDescriptors; /**< Numeric expression specifying the number of class descriptors */
-
- uint8_t bReportType; /**< Type of HID class report. */
- uint16_t wReportLength; /**< the total size of the Report descriptor. */
-} tusb_hid_descriptor_hid_t;
-
/// HID Country Code
typedef enum
{
- HID_Local_NotSupported = 0 , ///< NotSupported
- HID_Local_Arabic , ///< Arabic
- HID_Local_Belgian , ///< Belgian
- HID_Local_Canadian_Bilingual , ///< Canadian_Bilingual
- HID_Local_Canadian_French , ///< Canadian_French
- HID_Local_Czech_Republic , ///< Czech_Republic
- HID_Local_Danish , ///< Danish
- HID_Local_Finnish , ///< Finnish
- HID_Local_French , ///< French
- HID_Local_German , ///< German
- HID_Local_Greek , ///< Greek
- HID_Local_Hebrew , ///< Hebrew
- HID_Local_Hungary , ///< Hungary
- HID_Local_International , ///< International
- HID_Local_Italian , ///< Italian
- HID_Local_Japan_Katakana , ///< Japan_Katakana
- HID_Local_Korean , ///< Korean
- HID_Local_Latin_American , ///< Latin_American
- HID_Local_Netherlands_Dutch , ///< Netherlands/Dutch
- HID_Local_Norwegian , ///< Norwegian
- HID_Local_Persian_Farsi , ///< Persian (Farsi)
- HID_Local_Poland , ///< Poland
- HID_Local_Portuguese , ///< Portuguese
- HID_Local_Russia , ///< Russia
- HID_Local_Slovakia , ///< Slovakia
- HID_Local_Spanish , ///< Spanish
- HID_Local_Swedish , ///< Swedish
- HID_Local_Swiss_French , ///< Swiss/French
- HID_Local_Swiss_German , ///< Swiss/German
- HID_Local_Switzerland , ///< Switzerland
- HID_Local_Taiwan , ///< Taiwan
- HID_Local_Turkish_Q , ///< Turkish-Q
- HID_Local_UK , ///< UK
- HID_Local_US , ///< US
- HID_Local_Yugoslavia , ///< Yugoslavia
- HID_Local_Turkish_F ///< Turkish-F
+ HID_LOCAL_NotSupported = 0 , ///< NotSupported
+ HID_LOCAL_Arabic , ///< Arabic
+ HID_LOCAL_Belgian , ///< Belgian
+ HID_LOCAL_Canadian_Bilingual , ///< Canadian_Bilingual
+ HID_LOCAL_Canadian_French , ///< Canadian_French
+ HID_LOCAL_Czech_Republic , ///< Czech_Republic
+ HID_LOCAL_Danish , ///< Danish
+ HID_LOCAL_Finnish , ///< Finnish
+ HID_LOCAL_French , ///< French
+ HID_LOCAL_German , ///< German
+ HID_LOCAL_Greek , ///< Greek
+ HID_LOCAL_Hebrew , ///< Hebrew
+ HID_LOCAL_Hungary , ///< Hungary
+ HID_LOCAL_International , ///< International
+ HID_LOCAL_Italian , ///< Italian
+ HID_LOCAL_Japan_Katakana , ///< Japan_Katakana
+ HID_LOCAL_Korean , ///< Korean
+ HID_LOCAL_Latin_American , ///< Latin_American
+ HID_LOCAL_Netherlands_Dutch , ///< Netherlands/Dutch
+ HID_LOCAL_Norwegian , ///< Norwegian
+ HID_LOCAL_Persian_Farsi , ///< Persian (Farsi)
+ HID_LOCAL_Poland , ///< Poland
+ HID_LOCAL_Portuguese , ///< Portuguese
+ HID_LOCAL_Russia , ///< Russia
+ HID_LOCAL_Slovakia , ///< Slovakia
+ HID_LOCAL_Spanish , ///< Spanish
+ HID_LOCAL_Swedish , ///< Swedish
+ HID_LOCAL_Swiss_French , ///< Swiss/French
+ HID_LOCAL_Swiss_German , ///< Swiss/German
+ HID_LOCAL_Switzerland , ///< Switzerland
+ HID_LOCAL_Taiwan , ///< Taiwan
+ HID_LOCAL_Turkish_Q , ///< Turkish-Q
+ HID_LOCAL_UK , ///< UK
+ HID_LOCAL_US , ///< US
+ HID_LOCAL_Yugoslavia , ///< Yugoslavia
+ HID_LOCAL_Turkish_F ///< Turkish-F
} hid_country_code_t;
/** @} */
@@ -155,7 +156,7 @@ typedef struct ATTR_PACKED
int8_t x; /**< Current delta x movement of the mouse. */
int8_t y; /**< Current delta y movement on the mouse. */
int8_t wheel; /**< Current delta wheel movement on the mouse. */
-// int8_t pan;
+ int8_t pan; // using AC Pan
} hid_mouse_report_t;
/// Standard Mouse Buttons Bitmap
@@ -461,7 +462,7 @@ enum {
HID_USAGE_PAGE_MSR = 0x8e,
HID_USAGE_PAGE_CAMERA = 0x90,
HID_USAGE_PAGE_ARCADE = 0x91,
- HID_USAGE_PAGE_VENDOR = 0xFFFF // 0xFF00 - 0xFFFF
+ HID_USAGE_PAGE_VENDOR = 0xFF00 // 0xFF00 - 0xFFFF
};
/// HID Usage Table - Table 6: Generic Desktop Page
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index 78def53f0..e82932e1f 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -38,24 +38,19 @@
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
-
-#ifndef CFG_TUD_HID_BUFSIZE
-#define CFG_TUD_HID_BUFSIZE 16
-#endif
-
typedef struct
{
uint8_t itf_num;
uint8_t ep_in;
+ uint8_t ep_out; // optional Out endpoint
uint8_t boot_protocol; // Boot mouse or keyboard
- bool boot_mode;
-
+ bool boot_mode; // default = false (Report)
+ uint8_t idle_rate; // up to application to handle idle rate
uint16_t reprot_desc_len;
- uint8_t idle_rate; // Idle Rate = 0 : only send report if there is changes, i.e skip duplication
- // Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
- uint8_t mouse_button; // caching button for using with tud_hid_mouse_ API
- CFG_TUSB_MEM_ALIGN uint8_t report_buf[CFG_TUD_HID_BUFSIZE];
+ CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_HID_BUFSIZE];
+ CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_HID_BUFSIZE];
+
}hidd_interface_t;
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID];
@@ -91,15 +86,15 @@ bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
// If report id = 0, skip ID field
if (report_id)
{
- p_hid->report_buf[0] = report_id;
- memcpy(p_hid->report_buf+1, report, len);
+ p_hid->epin_buf[0] = report_id;
+ memcpy(p_hid->epin_buf+1, report, len);
+ len++;
}else
{
- memcpy(p_hid->report_buf, report, len);
+ memcpy(p_hid->epin_buf, report, len);
}
- // TODO skip duplication ? and or idle rate
- return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->report_buf, len + (report_id ? 1 : 0) );
+ return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
}
bool tud_hid_boot_mode(void)
@@ -125,47 +120,26 @@ bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycod
tu_memclr(report.keycode, 6);
}
- // TODO skip duplication ? and or idle rate
return tud_hid_report(report_id, &report, sizeof(report));
}
//--------------------------------------------------------------------+
// MOUSE APPLICATION API
//--------------------------------------------------------------------+
-bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan)
+bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
{
- (void) pan;
hid_mouse_report_t report =
{
.buttons = buttons,
.x = x,
.y = y,
- .wheel = scroll,
- //.pan = pan
+ .wheel = vertical,
+ .pan = horizontal
};
- uint8_t itf = 0;
- _hidd_itf[itf].mouse_button = buttons;
-
return tud_hid_report(report_id, &report, sizeof(report));
}
-bool tud_hid_mouse_move(uint8_t report_id, int8_t x, int8_t y)
-{
- uint8_t itf = 0;
- uint8_t const button = _hidd_itf[itf].mouse_button;
-
- return tud_hid_mouse_report(report_id, button, x, y, 0, 0);
-}
-
-bool tud_hid_mouse_scroll(uint8_t report_id, int8_t scroll, int8_t pan)
-{
- uint8_t itf = 0;
- uint8_t const button = _hidd_itf[itf].mouse_button;
-
- return tud_hid_mouse_report(report_id, button, 0, 0, scroll, pan);
-}
-
//--------------------------------------------------------------------+
// USBD-CLASS API
//--------------------------------------------------------------------+
@@ -184,6 +158,10 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
{
uint8_t const *p_desc = (uint8_t const *) desc_itf;
+ // TODO support multiple HID interface
+ uint8_t const itf = 0;
+ hidd_interface_t * p_hid = &_hidd_itf[itf];
+
//------------- HID descriptor -------------//
p_desc = tu_desc_next(p_desc);
tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
@@ -191,24 +169,19 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
//------------- Endpoint Descriptor -------------//
p_desc = tu_desc_next(p_desc);
- tusb_desc_endpoint_t const *desc_edpt = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT(TUSB_DESC_ENDPOINT == desc_edpt->bDescriptorType);
-
- TU_ASSERT(dcd_edpt_open(rhport, desc_edpt));
-
- // TODO support multiple HID interface
- uint8_t itf = 0;
- hidd_interface_t * p_hid = &_hidd_itf[itf];
+ TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, desc_itf->bNumEndpoints, TUSB_XFER_INTERRUPT, &p_hid->ep_out, &p_hid->ep_in));
if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->boot_protocol = desc_itf->bInterfaceProtocol;
p_hid->boot_mode = false; // default mode is REPORT
p_hid->itf_num = desc_itf->bInterfaceNumber;
- p_hid->ep_in = desc_edpt->bEndpointAddress;
p_hid->reprot_desc_len = desc_hid->wReportLength;
*p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
+ // Prepare for output endpoint
+ if (p_hid->ep_out) TU_ASSERT(dcd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
+
return true;
}
@@ -245,20 +218,25 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
uint8_t const report_type = tu_u16_high(p_request->wValue);
uint8_t const report_id = tu_u16_low(p_request->wValue);
- uint16_t xferlen = tud_hid_get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->report_buf, p_request->wLength);
+ uint16_t xferlen = tud_hid_get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epin_buf, p_request->wLength);
TU_ASSERT( xferlen > 0 );
- usbd_control_xfer(rhport, p_request, p_hid->report_buf, xferlen);
+ usbd_control_xfer(rhport, p_request, p_hid->epin_buf, xferlen);
}
break;
case HID_REQ_CONTROL_SET_REPORT:
- usbd_control_xfer(rhport, p_request, p_hid->report_buf, p_request->wLength);
+ usbd_control_xfer(rhport, p_request, p_hid->epout_buf, p_request->wLength);
break;
case HID_REQ_CONTROL_SET_IDLE:
- // TODO idle rate of report
p_hid->idle_rate = tu_u16_high(p_request->wValue);
+ if ( tud_hid_set_idle_cb )
+ {
+ // stall request if callback return false
+ if ( !tud_hid_set_idle_cb(p_hid->idle_rate) ) return false;
+ }
+
usbd_control_status(rhport, p_request);
break;
@@ -277,7 +255,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
case HID_REQ_CONTROL_SET_PROTOCOL:
p_hid->boot_mode = 1 - p_request->wValue; // 0 is Boot, 1 is Report protocol
- if (tud_hid_mode_changed_cb) tud_hid_mode_changed_cb(p_hid->boot_mode);
+ if (tud_hid_boot_mode_cb) tud_hid_boot_mode_cb(p_hid->boot_mode);
usbd_control_status(rhport, p_request);
break;
@@ -307,19 +285,25 @@ bool hidd_control_request_complete(uint8_t rhport, tusb_control_request_t const
uint8_t const report_type = tu_u16_high(p_request->wValue);
uint8_t const report_id = tu_u16_low(p_request->wValue);
- tud_hid_set_report_cb(report_id, (hid_report_type_t) report_type, p_hid->report_buf, p_request->wLength);
+ tud_hid_set_report_cb(report_id, (hid_report_type_t) report_type, p_hid->epout_buf, p_request->wLength);
}
return true;
}
-bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
+bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
{
- // nothing to do
- (void) rhport;
- (void) ep_addr;
- (void) event;
- (void) xferred_bytes;
+ (void) result;
+
+ // TODO support multiple HID interface
+ uint8_t const itf = 0;
+ hidd_interface_t * p_hid = &_hidd_itf[itf];
+
+ if (ep_addr == p_hid->ep_out)
+ {
+ tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
+ TU_ASSERT(dcd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
+ }
return true;
}
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index 13a213277..825be2181 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -39,6 +39,9 @@
// Class Driver Default Configure & Validation
//--------------------------------------------------------------------+
+#ifndef CFG_TUD_HID_BUFSIZE
+#define CFG_TUD_HID_BUFSIZE 16
+#endif
//--------------------------------------------------------------------+
// Application API
@@ -53,51 +56,34 @@ bool tud_hid_boot_mode(void);
// Send report to host
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
-/*------------- Callbacks (Weak is optional) -------------*/
-
-// Invoked when receiving GET_REPORT control request
-// Application must fill buffer report's content and return its length.
-// Return zero will cause the stack to STALL request
-uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
-
-// Invoked when receiving SET_REPORT control request
-void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
-
-// Invoked when host switch mode Boot <-> Report via SET_PROTOCOL request
-void tud_hid_mode_changed_cb(uint8_t boot_mode) ATTR_WEAK;
-
-//--------------------------------------------------------------------+
-// KEYBOARD API
-// Convenient helper to send keyboard report if application use standard/boot
-// layout report as defined by hid_keyboard_report_t
-//--------------------------------------------------------------------+
-
+// KEYBOARD: convenient helper to send keyboard report if application
+// use template layout report as defined by hid_keyboard_report_t
bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
-static inline bool tud_hid_keyboard_key_release(uint8_t report_id)
-{
- return tud_hid_keyboard_report(report_id, 0, NULL);
-}
+// MOUSE: convenient helper to send mouse report if application
+// use template layout report as defined by hid_mouse_report_t
+bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
//--------------------------------------------------------------------+
-// MOUSE API
-// Convenient helper to send mouse report if application use standard/boot
-// layout report as defined by hid_mouse_report_t
+// Callbacks (Weak is optional)
//--------------------------------------------------------------------+
-bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan);
-bool tud_hid_mouse_move(uint8_t report_id, int8_t x, int8_t y);
-bool tud_hid_mouse_scroll(uint8_t report_id, int8_t scroll, int8_t pan);
+// Invoked when received GET_REPORT control request
+// Application must fill buffer report's content and return its length.
+// Return zero will cause the stack to STALL request
+uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
+
+// Invoked when received SET_REPORT control request or
+// received data on OUT endpoint ( Report ID = 0, Type = 0 )
+void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
-static inline bool tud_hid_mouse_button_press(uint8_t report_id, uint8_t buttons)
-{
- return tud_hid_mouse_report(report_id, buttons, 0, 0, 0, 0);
-}
+// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
+ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
-static inline bool tud_hid_mouse_button_release(uint8_t report_id)
-{
- return tud_hid_mouse_report(report_id, 0, 0, 0, 0, 0);
-}
+// Invoked when received SET_IDLE request. return false will stall the request
+// - Idle Rate = 0 : only send report if there is changes, i.e skip duplication
+// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
+ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
/* --------------------------------------------------------------------+
* HID Report Descriptor Template
@@ -107,23 +93,24 @@ static inline bool tud_hid_mouse_button_release(uint8_t report_id)
* empty if multiple reports is not used
*
* - Only 1 report: no parameter
- * uint8_t const report_desc[] = { HID_REPORT_DESC_KEYBOARD() };
+ * uint8_t const report_desc[] = { TUD_HID_REPORT_DESC_KEYBOARD() };
*
* - Multiple Reports: "HID_REPORT_ID(ID)," must be passed to template
* uint8_t const report_desc[] =
* {
- * HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1), ) ,
- * HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(2), )
+ * TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1), ) ,
+ * TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(2), )
* };
*--------------------------------------------------------------------*/
// Keyboard Report Descriptor Template
-#define HID_REPORT_DESC_KEYBOARD(...) \
+#define TUD_HID_REPORT_DESC_KEYBOARD(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ) ,\
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
- /* 8 bits Modifier Keys (Shfit, Control, Alt) */ \
+ /* Report ID if any */\
__VA_ARGS__ \
+ /* 8 bits Modifier Keys (Shfit, Control, Alt) */ \
HID_USAGE_PAGE ( HID_USAGE_PAGE_KEYBOARD ) ,\
HID_USAGE_MIN ( 224 ) ,\
HID_USAGE_MAX ( 231 ) ,\
@@ -159,50 +146,60 @@ static inline bool tud_hid_mouse_button_release(uint8_t report_id)
HID_COLLECTION_END \
// Mouse Report Descriptor Template
-#define HID_REPORT_DESC_MOUSE(...) \
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\
- HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
+#define TUD_HID_REPORT_DESC_MOUSE(...) \
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
+ HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\
+ HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
+ /* Report ID if any */\
__VA_ARGS__ \
- HID_USAGE ( HID_USAGE_DESKTOP_POINTER ) ,\
- HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\
- HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
- HID_USAGE_MIN ( 1 ) ,\
- HID_USAGE_MAX ( 3 ) ,\
- HID_LOGICAL_MIN ( 0 ) ,\
- HID_LOGICAL_MAX ( 1 ) ,\
- /* Left, Right, Middle, Backward, Forward mouse buttons */ \
- HID_REPORT_COUNT ( 3 ) ,\
- HID_REPORT_SIZE ( 1 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
+ HID_USAGE ( HID_USAGE_DESKTOP_POINTER ) ,\
+ HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
+ HID_USAGE_MIN ( 1 ) ,\
+ HID_USAGE_MAX ( 5 ) ,\
+ HID_LOGICAL_MIN ( 0 ) ,\
+ HID_LOGICAL_MAX ( 1 ) ,\
+ /* Left, Right, Middle, Backward, Forward buttons */ \
+ HID_REPORT_COUNT( 5 ) ,\
+ HID_REPORT_SIZE ( 1 ) ,\
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
/* 3 bit padding */ \
- HID_REPORT_COUNT ( 1 ) ,\
- HID_REPORT_SIZE ( 5 ) ,\
- HID_INPUT ( HID_CONSTANT ) ,\
- HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
+ HID_REPORT_COUNT( 1 ) ,\
+ HID_REPORT_SIZE ( 3 ) ,\
+ HID_INPUT ( HID_CONSTANT ) ,\
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
/* X, Y position [-127, 127] */ \
- HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
- HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
- HID_LOGICAL_MIN ( 0x81 ) ,\
- HID_LOGICAL_MAX ( 0x7f ) ,\
- HID_REPORT_COUNT ( 2 ) ,\
- HID_REPORT_SIZE ( 8 ) ,\
- HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
- /* Mouse scroll [-127, 127] */ \
+ HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
+ HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
+ HID_LOGICAL_MIN ( 0x81 ) ,\
+ HID_LOGICAL_MAX ( 0x7f ) ,\
+ HID_REPORT_COUNT( 2 ) ,\
+ HID_REPORT_SIZE ( 8 ) ,\
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
+ /* Verital wheel scroll [-127, 127] */ \
HID_USAGE ( HID_USAGE_DESKTOP_WHEEL ) ,\
HID_LOGICAL_MIN ( 0x81 ) ,\
HID_LOGICAL_MAX ( 0x7f ) ,\
HID_REPORT_COUNT( 1 ) ,\
HID_REPORT_SIZE ( 8 ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\
- HID_COLLECTION_END ,\
+ HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ), \
+ /* Horizontal wheel scroll [-127, 127] */ \
+ HID_USAGE_N ( HID_USAGE_CONSUMER_AC_PAN, 2 ), \
+ HID_LOGICAL_MIN ( 0x81 ), \
+ HID_LOGICAL_MAX ( 0x7f ), \
+ HID_REPORT_COUNT( 1 ), \
+ HID_REPORT_SIZE ( 8 ), \
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ), \
+ HID_COLLECTION_END , \
HID_COLLECTION_END \
// Consumer Control Report Descriptor Template
-#define HID_REPORT_DESC_CONSUMER(...) \
+#define TUD_HID_REPORT_DESC_CONSUMER(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ) ,\
HID_USAGE ( HID_USAGE_CONSUMER_CONTROL ) ,\
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
+ /* Report ID if any */\
__VA_ARGS__ \
HID_LOGICAL_MIN ( 0x00 ) ,\
HID_LOGICAL_MAX_N( 0x03FF, 2 ) ,\
@@ -219,10 +216,11 @@ static inline bool tud_hid_mouse_button_release(uint8_t report_id)
* 0x02 - Standby
* 0x04 - Wake Host
*/
-#define HID_REPORT_DESC_SYSTEM_CONTROL(...) \
+#define TUD_HID_REPORT_DESC_SYSTEM_CONTROL(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_SYSTEM_CONTROL ) ,\
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
+ /* Report ID if any */\
__VA_ARGS__ \
/* 2 bit system power control */ \
HID_LOGICAL_MIN ( 1 ) ,\
@@ -242,10 +240,11 @@ static inline bool tud_hid_mouse_button_release(uint8_t report_id)
// Gamepad Report Descriptor Template
// with 16 buttons and 2 joysticks with following layout
// | Button Map (2 bytes) | X | Y | Z | Rz
-#define HID_REPORT_DESC_GAMEPAD(...) \
+#define TUD_HID_REPORT_DESC_GAMEPAD(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
+ /* Report ID if any */\
__VA_ARGS__ \
/* 16 bit Button Map */ \
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
@@ -269,6 +268,31 @@ static inline bool tud_hid_mouse_button_release(uint8_t report_id)
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
HID_COLLECTION_END \
+// HID Generic Input & Output
+// - 1st parameter is report size (mandatory)
+// - 2nd parameter is report id HID_REPORT_ID(n) (optional)
+#define TUD_HID_REPORT_DESC_GENERIC_INOUT(report_size, ...) \
+ HID_USAGE_PAGE_N ( HID_USAGE_PAGE_VENDOR, 2 ),\
+ HID_USAGE ( 0x01 ),\
+ HID_COLLECTION ( HID_COLLECTION_APPLICATION ),\
+ /* Report ID if any */\
+ __VA_ARGS__ \
+ /* Input */ \
+ HID_USAGE ( 0x02 ),\
+ HID_LOGICAL_MIN ( 0x00 ),\
+ HID_LOGICAL_MAX ( 0xff ),\
+ HID_REPORT_SIZE ( 8 ),\
+ HID_REPORT_COUNT( report_size ),\
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\
+ /* Output */ \
+ HID_USAGE ( 0x03 ),\
+ HID_LOGICAL_MIN ( 0x00 ),\
+ HID_LOGICAL_MAX ( 0xff ),\
+ HID_REPORT_SIZE ( 8 ),\
+ HID_REPORT_COUNT( report_size ),\
+ HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ),\
+ HID_COLLECTION_END \
+
/*--------------------------------------------------------------------
* ASCII to KEYCODE Conversion
* Expand to array of [128][2] (shift, keycode)
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index e2cf92324..f980e941e 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -42,13 +42,9 @@ enum
MSC_STAGE_STATUS
};
-typedef struct {
- CFG_TUSB_MEM_ALIGN msc_cbw_t cbw;
-
-//#if defined (__ICCARM__) && (CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX)
-// uint8_t padding1[64-sizeof(msc_cbw_t)]; // IAR cannot align struct's member
-//#endif
-
+typedef struct
+{
+ CFG_TUSB_MEM_ALIGN msc_cbw_t cbw;
CFG_TUSB_MEM_ALIGN msc_csw_t csw;
uint8_t itf_num;
@@ -66,7 +62,7 @@ typedef struct {
uint8_t add_sense_qualifier;
}mscd_interface_t;
-CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf = { 0 };
+CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static mscd_interface_t _mscd_itf;
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t _mscd_buf[CFG_TUD_MSC_BUFSIZE];
//--------------------------------------------------------------------+
@@ -135,9 +131,8 @@ bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
mscd_interface_t * p_msc = &_mscd_itf;
- // Open endpoint pair with usbd helper
- tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( itf_desc );
- TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in) );
+ // Open endpoint pair
+ TU_ASSERT( usbd_open_edpt_pair(rhport, tu_desc_next(itf_desc), 2, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in) );
p_msc->itf_num = itf_desc->bInterfaceNumber;
(*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
@@ -163,9 +158,12 @@ bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
case MSC_REQ_GET_MAX_LUN:
{
+ uint8_t maxlun = 1;
+ if (tud_msc_maxlun_cb) maxlun = tud_msc_maxlun_cb();
+ TU_VERIFY(maxlun);
+
// MAX LUN is minus 1 by specs
- uint8_t maxlun = 0;
- if (tud_msc_maxlun_cb) maxlun = tud_msc_maxlun_cb() -1;
+ maxlun--;
usbd_control_xfer(rhport, p_request, &maxlun, 1);
}
diff --git a/src/class/msc/msc_device.h b/src/class/msc/msc_device.h
index 6e3aef8bb..b1e7e8da1 100644
--- a/src/class/msc/msc_device.h
+++ b/src/class/msc/msc_device.h
@@ -64,10 +64,11 @@ TU_VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct");
bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier);
//--------------------------------------------------------------------+
-// APPLICATION CALLBACK (WEAK is optional)
+// Application Callbacks (WEAK is optional)
//--------------------------------------------------------------------+
+
/**
- * Callback invoked when received \ref SCSI_CMD_READ_10 command
+ * Invoked when received \ref SCSI_CMD_READ_10 command
* \param[in] lun Logical unit number
* \param[in] lba Logical Block Address to be read
* \param[in] offset Byte offset from LBA
@@ -86,7 +87,7 @@ bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, u
int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
/**
- * Callback invoked when received \ref SCSI_CMD_WRITE_10 command
+ * Invoked when received \ref SCSI_CMD_WRITE_10 command
* \param[in] lun Logical unit number
* \param[in] lba Logical Block Address to be write
* \param[in] offset Byte offset from LBA
@@ -104,7 +105,8 @@ int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buf
*/
int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize);
-// Invoked to determine the disk size
+// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
+// Application update block count and block size
void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size);
/**
@@ -128,13 +130,13 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
/*------------- Optional callbacks -------------*/
-// Invoked to determine max LUN
+// Invoked when received GET_MAX_LUN request
ATTR_WEAK uint8_t tud_msc_maxlun_cb(void);
// Invoked when Read10 command is complete
ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun);
-// Invoke when Write10 command is complete
+// Invoke when Write10 command is complete, can be used to flush flash caching
ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun);
// Invoked when command in tud_msc_scsi_cb is complete
diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h
index 7d57a7950..909deffa8 100644
--- a/src/common/tusb_types.h
+++ b/src/common/tusb_types.h
@@ -169,7 +169,7 @@ enum {
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
-/// Device State
+/// Device State TODO remove
typedef enum
{
TUSB_DEVICE_STATE_UNPLUG = 0 ,
@@ -184,7 +184,7 @@ typedef enum
XFER_RESULT_STALLED,
}xfer_result_t;
-enum
+enum // TODO remove
{
DESC_OFFSET_LEN = 0,
DESC_OFFSET_TYPE = 1
diff --git a/src/device/usbd.c b/src/device/usbd.c
index f02b21208..d811c471a 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -702,25 +702,25 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_
// Helper
//--------------------------------------------------------------------+
-// Helper to parse an pair of endpoint descriptors (IN & OUT)
-bool usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_desc, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
+// Parse consecutive endpoint descriptors (IN & OUT)
+bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
{
- for(int i=0; i<2; i++)
+ for(int i=0; i<ep_count; i++)
{
- TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType &&
- xfer_type == ep_desc->bmAttributes.xfer );
+ tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT(dcd_edpt_open(rhport, ep_desc));
+ TU_VERIFY(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
+ TU_ASSERT(dcd_edpt_open(rhport, desc_ep));
- if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
+ if ( tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN )
{
- (*ep_in) = ep_desc->bEndpointAddress;
+ (*ep_in) = desc_ep->bEndpointAddress;
}else
{
- (*ep_out) = ep_desc->bEndpointAddress;
+ (*ep_out) = desc_ep->bEndpointAddress;
}
- ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc);
+ p_desc = tu_desc_next(p_desc);
}
return true;
diff --git a/src/device/usbd.h b/src/device/usbd.h
index de59731a2..8debbf535 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -107,7 +107,7 @@ ATTR_WEAK void tud_resume_cb(void);
#define TUD_CDC_DESC_LEN (8+9+5+5+4+5+7+9+7+7)
// CDC Descriptor Template
-// interface number, string index, EP notification address and size, EP data address (out,in) and size.
+// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
/* Interface Associate */\
8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0,\
@@ -149,15 +149,31 @@ ATTR_WEAK void tud_resume_cb(void);
// Length of template descriptor: 25 bytes
#define TUD_HID_DESC_LEN (9 + 9 + 7)
+// HID Input only descriptor
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
#define TUD_HID_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epin, _epsize, _ep_interval) \
/* Interface */\
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_HID, (_boot_protocol) ? HID_SUBCLASS_BOOT : 0, _boot_protocol, _stridx,\
/* HID descriptor */\
9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
- /* Endpoint descriptor */\
+ /* Endpoint In */\
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
+// Length of template descriptor: 32 bytes
+#define TUD_HID_INOUT_DESC_LEN (9 + 9 + 7 + 7)
+
+// HID Input & Output descriptor
+// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
+#define TUD_HID_INOUT_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epin, _epout, _epsize, _ep_interval) \
+ /* Interface */\
+ 9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_HID, (_boot_protocol) ? HID_SUBCLASS_BOOT : 0, _boot_protocol, _stridx,\
+ /* HID descriptor */\
+ 9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
+ /* Endpoint In */\
+ 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval,\
+ /* Endpoint Out */\
+ 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
+
#ifdef __cplusplus
}
#endif
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h
index 8518ee209..fb3672359 100644
--- a/src/device/usbd_pvt.h
+++ b/src/device/usbd_pvt.h
@@ -53,9 +53,8 @@ bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr);
/*------------------------------------------------------------------*/
/* Helper
*------------------------------------------------------------------*/
-// helper to parse an pair of In and Out endpoint descriptors. They must be consecutive
-bool usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in);
+bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in);
void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr );
diff --git a/src/osal/osal.h b/src/osal/osal.h
index cdeaa2974..7304fdbd2 100644
--- a/src/osal/osal.h
+++ b/src/osal/osal.h
@@ -47,56 +47,49 @@ enum
typedef void (*osal_task_func_t)( void * );
+#if CFG_TUSB_OS == OPT_OS_NONE
+ #include "osal_none.h"
+#elif CFG_TUSB_OS == OPT_OS_FREERTOS
+ #include "osal_freertos.h"
+#elif CFG_TUSB_OS == OPT_OS_MYNEWT
+ #include "osal_mynewt.h"
+#else
+ #error OS is not supported yet
+#endif
+
//--------------------------------------------------------------------+
// OSAL Porting API
//--------------------------------------------------------------------+
-#if 0
-void osal_task_delay(uint32_t msec);
+static inline void osal_task_delay(uint32_t msec);
//------------- Semaphore -------------//
-osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
-bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr);
-bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec);
+static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef);
+static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr);
+static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec);
-void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed
+static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl); // TODO removed
//------------- Mutex -------------//
-osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef);
-bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec);
-bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
+static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef);
+static inline bool osal_mutex_lock (osal_mutex_t sem_hdl, uint32_t msec);
+static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
//------------- Queue -------------//
-osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
-bool osal_queue_receive(osal_queue_t const qhdl, void* data);
-bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr);
-#endif
-
-#if CFG_TUSB_OS == OPT_OS_NONE
- #include "osal_none.h"
-#else
- #if CFG_TUSB_OS == OPT_OS_FREERTOS
- #include "osal_freertos.h"
- #elif CFG_TUSB_OS == OPT_OS_MYNEWT
- #include "osal_mynewt.h"
- #else
- #error CFG_TUSB_OS is not defined or OS is not supported yet
- #endif
-
- // TODO remove subtask related macros later
-
- //------------- Sub Task -------------//
- #define OSAL_SUBTASK_BEGIN
- #define OSAL_SUBTASK_END return TUSB_ERROR_NONE;
+static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
+static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data);
+static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr);
- #define STASK_RETURN(_error) return _error;
- #define STASK_INVOKE(_subtask, _status) (_status) = _subtask
+#if 0 // TODO remove subtask related macros later
+// Sub Task
+#define OSAL_SUBTASK_BEGIN
+#define OSAL_SUBTASK_END return TUSB_ERROR_NONE;
- //------------- Sub Task Assert -------------//
- #define STASK_ASSERT_ERR(_err) TU_VERIFY_ERR(_err)
- #define STASK_ASSERT_ERR_HDLR(_err, _func) TU_VERIFY_ERR_HDLR(_err, _func)
+#define STASK_RETURN(_error) return _error;
+#define STASK_INVOKE(_subtask, _status) (_status) = _subtask
- #define STASK_ASSERT(_cond) TU_VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED)
- #define STASK_ASSERT_HDLR(_cond, _func) TU_VERIFY_HDLR(_cond, _func)
+// Sub Task Assert
+#define STASK_ASSERT_ERR(_err) TU_VERIFY_ERR(_err)
+#define STASK_ASSERT(_cond) TU_VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED)
#endif
#ifdef __cplusplus
diff --git a/src/portable/nordic/nrf5x/dcd_nrf5x.c b/src/portable/nordic/nrf5x/dcd_nrf5x.c
index 1f8e94420..3e5f69f79 100644
--- a/src/portable/nordic/nrf5x/dcd_nrf5x.c
+++ b/src/portable/nordic/nrf5x/dcd_nrf5x.c
@@ -489,7 +489,7 @@ void USBD_IRQHandler(void)
{
xfer->total_len = xfer->actual_len;
- // BULK/INT OUT complete
+ // CBI OUT complete
dcd_event_xfer_complete(0, epnum, xfer->actual_len, XFER_RESULT_SUCCESS, true);
}
}
@@ -524,7 +524,7 @@ void USBD_IRQHandler(void)
xact_in_prepare(epnum);
} else
{
- // Bulk/Int IN complete
+ // CBI IN complete
dcd_event_xfer_complete(0, epnum | TUSB_DIR_IN_MASK, xfer->actual_len, XFER_RESULT_SUCCESS, true);
}
}