update tinyusb

This commit is contained in:
hathach committed 2019-04-19 21:57:45 +07:00
1 parent a18a1f53b9
commit 756291a13c
12 files changed
+225 -484

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ TinyUSB is an open-source cross-platform USB Host/Device stack for embedded syst
Support multiple device configurations by dynamically changing usb descriptors. Low power functions such as suspend, resume and remote wakeup. Following device classes are supported:
- Communication Class (CDC)
- Human Interface Device (HID): Keyboard, Mouse, Generic
- Human Interface Device (HID): Keyboard, Mouse, Gamepad etc ...
- Mass Storage Class (MSC)
- Musical Instrument Digital Interface (MIDI)
@@ -94,6 +94,9 @@ ATTR_WEAK void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char);
ATTR_WEAK void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts);
ATTR_WEAK void tud_cdc_line_coding_cb(uint8_t itf, cdc_line_coding_t const* p_line_coding);
/** @} */
/** @} */
//--------------------------------------------------------------------+
// INTERNAL USBD-CLASS DRIVER API
//--------------------------------------------------------------------+
@@ -104,43 +107,8 @@ bool cdcd_control_request_complete (uint8_t rhport, tusb_control_request_t const
bool cdcd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
void cdcd_reset (uint8_t rhport);
//--------------------------------------------------------------------+
// Interface Descriptor Template
//--------------------------------------------------------------------+
// Length of template descriptor: 66 bytes
#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.
#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
/* Interface Associate */\
0x08, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 0x02, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0x00,\
/* CDC Control Interface */\
0x09, TUSB_DESC_INTERFACE, _itfnum, 0x00, 0x01, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, _stridx,\
/* CDC Header */\
0x05, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
/* CDC Call */\
0x05, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_CALL_MANAGEMENT, 0x00, (_itfnum) + 1,\
/* CDC ACM: support line request */\
0x04, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 0x02,\
/* CDC Union */\
0x05, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_UNION, _itfnum, (_itfnum) + 1,\
/* Endpoint Notification */\
0x07, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 0x10,\
/* CDC Data Interface */\
0x09, TUSB_DESC_INTERFACE, (_itfnum)+1, 0x00, 0x02, TUSB_CLASS_CDC_DATA, 0x00, 0x00, 0x00,\
/* Endpoint Out */\
0x07, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0x00,\
/* Endpoint In */\
0x07, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0x00
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_CDC_DEVICE_H_ */
/** @} */
/** @} */
+1 -1
View File
@@ -179,7 +179,7 @@ typedef enum
/// Standard HID Boot Protocol Keyboard Report.
typedef struct ATTR_PACKED
{
uint8_t modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of HID_KEYBOARD_MODIFER_* masks). */
uint8_t modifier; /**< Keyboard modifier (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. */
} hid_keyboard_report_t;
+75 -221
View File
@@ -39,61 +39,31 @@
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
// Max report len is keyboard's one with 8 byte + 1 byte report id
#define REPORT_BUFSIZE 12
#define ITF_IDX_BOOT_KBD 0
#define ITF_IDX_BOOT_MSE ( ITF_IDX_BOOT_KBD + (CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT) )
#define ITF_IDX_GENERIC ( ITF_IDX_BOOT_MSE + (CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT) )
#define ITF_COUNT ( ITF_IDX_GENERIC + 1 )
#ifndef CFG_TUD_HID_BUFSIZE
#define CFG_TUD_HID_BUFSIZE 16
#endif
typedef struct
{
uint8_t itf_num;
uint8_t ep_in;
uint8_t boot_protocol; // Boot mouse or keyboard
bool boot_mode;
uint8_t idle_rate; // in unit of 4 ms TODO removed
bool boot_protocol;
uint16_t desc_len;
uint8_t const * desc_report;
CFG_TUSB_MEM_ALIGN uint8_t report_buf[REPORT_BUFSIZE];
// callbacks
uint16_t (*get_report_cb) (uint8_t report_id, hid_report_type_t type, uint8_t* buffer, uint16_t reqlen);
void (*set_report_cb) (uint8_t report_id, hid_report_type_t type, uint8_t const* buffer, uint16_t bufsize);
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];
}hidd_interface_t;
typedef struct
{
uint8_t usage; // HID_USAGE_*
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).
// If idle time is less than interrupt polling then use the polling.
uint8_t report_id;
uint8_t report_len;
hidd_interface_t* itf;
} hidd_report_t ;
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[ITF_COUNT] = { { 0 } };
#if CFG_TUD_HID_KEYBOARD
static hidd_report_t _kbd_rpt;
#endif
#if CFG_TUD_HID_MOUSE
static hidd_report_t _mse_rpt;
#endif
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID];
/*------------- Helpers -------------*/
static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num)
{
for (uint8_t i=0; i < ITF_COUNT; i++ )
for (uint8_t i=0; i < CFG_TUD_HID; i++ )
{
if ( itf_num == _hidd_itf[i].itf_num ) return &_hidd_itf[i];
}
@@ -101,20 +71,22 @@ static inline hidd_interface_t* get_interface_by_itfnum(uint8_t itf_num)
return NULL;
}
//--------------------------------------------------------------------+
// HID GENERIC API
// APPLICATION API
//--------------------------------------------------------------------+
bool tud_hid_generic_ready(void)
bool tud_hid_ready(void)
{
return tud_ready() && (_hidd_itf[ITF_IDX_GENERIC].ep_in != 0) && !dcd_edpt_busy(TUD_OPT_RHPORT, _hidd_itf[ITF_IDX_GENERIC].ep_in);
uint8_t itf = 0;
uint8_t const ep_in = _hidd_itf[itf].ep_in;
return tud_ready() && (ep_in != 0) && !dcd_edpt_busy(TUD_OPT_RHPORT, ep_in);
}
bool tud_hid_generic_report(uint8_t report_id, void const* report, uint8_t len)
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
{
TU_VERIFY( tud_hid_generic_ready() && (len < REPORT_BUFSIZE) );
TU_VERIFY( tud_hid_ready() && (len < CFG_TUD_HID_BUFSIZE) );
hidd_interface_t * p_hid = &_hidd_itf[ITF_IDX_GENERIC];
uint8_t itf = 0;
hidd_interface_t * p_hid = &_hidd_itf[itf];
// If report id = 0, skip ID field
if (report_id)
@@ -126,44 +98,24 @@ bool tud_hid_generic_report(uint8_t report_id, void const* report, uint8_t len)
memcpy(p_hid->report_buf, report, len);
}
// TODO idle rate
return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->report_buf, len + ( report_id ? 1 : 0) );
// 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) );
}
bool tud_hid_boot_mode(void)
{
uint8_t itf = 0;
return _hidd_itf[itf].boot_mode;
}
//--------------------------------------------------------------------+
// KEYBOARD APPLICATION API
// KEYBOARD API
//--------------------------------------------------------------------+
#if CFG_TUD_HID_KEYBOARD
bool tud_hid_keyboard_ready(void)
bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
{
return (_kbd_rpt.itf != NULL) && !dcd_edpt_busy(TUD_OPT_RHPORT, _kbd_rpt.itf->ep_in);
}
hid_keyboard_report_t report;
bool tud_hid_keyboard_is_boot_protocol(void)
{
return (_kbd_rpt.itf != NULL) && _kbd_rpt.itf->boot_protocol;
}
static bool hidd_kbd_report(hid_keyboard_report_t const *p_report)
{
TU_VERIFY( tud_hid_keyboard_ready() );
hidd_interface_t * p_hid = _kbd_rpt.itf;
// only send report if there is changes, i.e skip duplication
// if ( _kbd_rpt.idle_rate == 0 )
// {
// if ( 0 == memcmp(p_hid->report_buf, p_report, sizeof(hid_keyboard_report_t)) ) return true;
// }
memcpy(p_hid->report_buf, p_report, sizeof(hid_keyboard_report_t));
return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->report_buf, sizeof(hid_keyboard_report_t));
}
bool tud_hid_keyboard_keycode(uint8_t modifier, uint8_t keycode[6])
{
hid_keyboard_report_t report = { .modifier = modifier };
report.modifier = modifier;
if ( keycode )
{
@@ -173,12 +125,12 @@ bool tud_hid_keyboard_keycode(uint8_t modifier, uint8_t keycode[6])
tu_memclr(report.keycode, 6);
}
return hidd_kbd_report(&report);
// TODO skip duplication ? and or idle rate
return tud_hid_report(report_id, &report, sizeof(report));
}
#if CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
bool tud_hid_keyboard_key_press(char ch)
bool tud_hid_keyboard_key_press(uint8_t report_id, char ch)
{
uint8_t keycode[6] = { 0 };
uint8_t modifier = 0;
@@ -186,75 +138,47 @@ bool tud_hid_keyboard_key_press(char ch)
if ( HID_ASCII_TO_KEYCODE[(uint8_t)ch].shift ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
keycode[0] = HID_ASCII_TO_KEYCODE[(uint8_t)ch].keycode;
return tud_hid_keyboard_keycode(modifier, keycode);
return tud_hid_keyboard_report(report_id, modifier, keycode);
}
#endif // CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
#endif // CFG_TUD_HID_KEYBOARD
//--------------------------------------------------------------------+
// MOUSE APPLICATION API
//--------------------------------------------------------------------+
#if CFG_TUD_HID_MOUSE
bool tud_hid_mouse_ready(void)
{
return (_mse_rpt.itf != NULL) && !dcd_edpt_busy(TUD_OPT_RHPORT, _mse_rpt.itf->ep_in);
}
bool tud_hid_mouse_is_boot_protocol(void)
{
return (_mse_rpt.itf != NULL) && _mse_rpt.itf->boot_protocol;
}
static bool hidd_mouse_report(hid_mouse_report_t const *p_report)
{
TU_VERIFY( tud_hid_mouse_ready() );
hidd_interface_t * p_hid = _mse_rpt.itf;
// only send report if there is changes, i.e skip duplication
memcpy(p_hid->report_buf, p_report, sizeof(hid_mouse_report_t));
return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->report_buf, sizeof(hid_mouse_report_t));
}
bool tud_hid_mouse_data(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 scroll, int8_t pan)
{
(void) pan;
hid_mouse_report_t report =
{
.buttons = buttons,
.x = x,
.y = y,
.wheel = scroll,
// .pan = pan
.buttons = buttons,
.x = x,
.y = y,
.wheel = scroll,
//.pan = pan
};
return hidd_mouse_report( &report );
uint8_t itf = 0;
_hidd_itf[itf].mouse_button = buttons;
return tud_hid_report(report_id, &report, sizeof(report));
}
bool tud_hid_mouse_move(int8_t x, int8_t y)
bool tud_hid_mouse_move(uint8_t report_id, int8_t x, int8_t y)
{
TU_VERIFY( tud_hid_mouse_ready() );
uint8_t itf = 0;
uint8_t const button = _hidd_itf[itf].mouse_button;
hidd_interface_t * p_hid = _mse_rpt.itf;
uint8_t prev_buttons = p_hid->report_buf[0];
return tud_hid_mouse_data(prev_buttons, x, y, 0, 0);
return tud_hid_mouse_report(report_id, button, x, y, 0, 0);
}
bool tud_hid_mouse_scroll(int8_t vertical, int8_t horizontal)
bool tud_hid_mouse_scroll(uint8_t report_id, int8_t scroll, int8_t pan)
{
TU_VERIFY( tud_hid_mouse_ready() );
uint8_t itf = 0;
uint8_t const button = _hidd_itf[itf].mouse_button;
hidd_interface_t * p_hid = _mse_rpt.itf;
uint8_t prev_buttons = p_hid->report_buf[0];
return tud_hid_mouse_data(prev_buttons, 0, 0, vertical, horizontal);
return tud_hid_mouse_report(report_id, button, 0, 0, scroll, pan);
}
#endif // CFG_TUD_HID_MOUSE
//--------------------------------------------------------------------+
// USBD-CLASS API
//--------------------------------------------------------------------+
@@ -267,23 +191,12 @@ void hidd_reset(uint8_t rhport)
{
(void) rhport;
tu_memclr(_hidd_itf, sizeof(_hidd_itf));
#if CFG_TUD_HID_KEYBOARD
tu_varclr(&_kbd_rpt);
#endif
#if CFG_TUD_HID_MOUSE
tu_varclr(&_mse_rpt);
#endif
}
bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_len)
{
uint8_t const *p_desc = (uint8_t const *) desc_itf;
// TODO support HID OUT Endpoint
TU_ASSERT(desc_itf->bNumEndpoints == 1);
//------------- 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;
@@ -294,65 +207,18 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
tusb_desc_endpoint_t const *desc_edpt = (tusb_desc_endpoint_t const *) p_desc;
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_edpt->bDescriptorType);
hidd_interface_t * p_hid = NULL;
/*------------- Boot protocol only keyboard & mouse -------------*/
if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT)
{
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE);
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD)
{
p_hid = &_hidd_itf[ITF_IDX_BOOT_KBD];
p_hid->desc_report = usbd_desc_set->hid_report.boot_keyboard;
p_hid->get_report_cb = tud_hid_keyboard_get_report_cb;
p_hid->set_report_cb = tud_hid_keyboard_set_report_cb;
hidd_report_t* report = &_kbd_rpt;
report->usage = HID_USAGE_DESKTOP_KEYBOARD;
report->report_id = 0;
report->report_len = 8;
report->itf = p_hid;
}
#endif
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE)
{
p_hid = &_hidd_itf[ITF_IDX_BOOT_MSE];
p_hid->desc_report = usbd_desc_set->hid_report.boot_mouse;
p_hid->get_report_cb = tud_hid_mouse_get_report_cb;
p_hid->set_report_cb = tud_hid_mouse_set_report_cb;
hidd_report_t* report = &_mse_rpt;
report->usage = HID_USAGE_DESKTOP_MOUSE;
report->report_id = 0;
report->report_len = 4;
report->itf = p_hid;
}
#endif
TU_ASSERT(p_hid);
p_hid->boot_protocol = true; // default mode is BOOT
}
/*------------- Generic (multiple report) -------------*/
else
{
// TODO parse report ID for keyboard, mouse
p_hid = &_hidd_itf[ITF_IDX_GENERIC];
p_hid->desc_report = usbd_desc_set->hid_report.generic;
p_hid->get_report_cb = tud_hid_generic_get_report_cb;
p_hid->set_report_cb = tud_hid_generic_set_report_cb;
}
TU_ASSERT(p_hid->desc_report);
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];
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->desc_len = desc_hid->wReportLength;
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);
@@ -375,7 +241,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
{
usbd_control_xfer(rhport, p_request, (void *)p_hid->desc_report, p_hid->desc_len);
usbd_control_xfer(rhport, p_request, (void*) tud_desc_set.hid_report, p_hid->reprot_desc_len);
}else
{
return false; // stall unsupported request
@@ -392,17 +258,9 @@ 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;
if ( p_hid->get_report_cb )
{
xferlen = p_hid->get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->report_buf, p_request->wLength);
}else
{
// For boot Interface only: re-use report_buf -> report has no change
xferlen = p_request->wLength;
}
uint16_t xferlen = tud_hid_get_report_cb(report_id, (hid_report_type_t) report_type, p_hid->report_buf, p_request->wLength);
TU_ASSERT( xferlen > 0 );
usbd_control_xfer(rhport, p_request, p_hid->report_buf, xferlen);
}
break;
@@ -424,13 +282,16 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
case HID_REQ_CONTROL_GET_PROTOCOL:
{
uint8_t protocol = 1-p_hid->boot_protocol; // 0 is Boot, 1 is Report protocol
uint8_t protocol = 1-p_hid->boot_mode; // 0 is Boot, 1 is Report protocol
usbd_control_xfer(rhport, p_request, &protocol, 1);
}
break;
case HID_REQ_CONTROL_SET_PROTOCOL:
p_hid->boot_protocol = 1 - p_request->wValue; // 0 is Boot, 1 is Report 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);
usbd_control_status(rhport, p_request);
break;
@@ -459,10 +320,7 @@ 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);
if ( p_hid->set_report_cb )
{
p_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->report_buf, p_request->wLength);
}
return true;
@@ -480,11 +338,8 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
}
/*------------------------------------------------------------------*/
/* Ascii to Keycode
*------------------------------------------------------------------*/
//------------- Ascii to Keycode Lookup -------------//
#if CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128] =
{
{0, 0 }, // 0x00 Null
@@ -619,7 +474,6 @@ const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128] =
{1, HID_KEY_GRAVE }, // 0x7E ~
{0, HID_KEY_DELETE } // 0x7F Delete
};
#endif
#endif // CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
#endif
+60 -134
View File
@@ -42,47 +42,47 @@
#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 0
#endif
#if !CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
#error CFG_TUD_HID_KEYBOARD must be enabled
#endif
#if !CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
#error CFG_TUD_HID_MOUSE must be enabled
#endif
//--------------------------------------------------------------------+
// HID GENERIC API
// Application API
//--------------------------------------------------------------------+
bool tud_hid_generic_ready(void);
bool tud_hid_generic_report(uint8_t report_id, void const* report, uint8_t len);
// Check if the interface is ready to use
bool tud_hid_ready(void);
// Check if current mode is Boot (true) or Report (false)
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) -------------*/
uint16_t tud_hid_generic_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
void tud_hid_generic_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
// 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
//--------------------------------------------------------------------+
#if CFG_TUD_HID_KEYBOARD
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
* @{ */
/** \defgroup Keyboard_Device Device
* @{ */
/** Check if the interface is ready to use
* \returns true if ready, otherwise interface may not be mounted or still busy transferring data
* \note Application must not perform any action if the interface is not ready
*/
bool tud_hid_keyboard_ready(void);
bool tud_hid_keyboard_is_boot_protocol(void);
bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
bool tud_hid_keyboard_keycode(uint8_t modifier, uint8_t keycode[6]);
static inline bool tud_hid_keyboard_key_release(void) { return tud_hid_keyboard_keycode(0, NULL); }
static inline bool tud_hid_keyboard_key_release(uint8_t report_id)
{
return tud_hid_keyboard_report(report_id, 0, NULL);
}
#if CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
bool tud_hid_keyboard_key_press(char ch);
bool tud_hid_keyboard_key_press(uint8_t report_id, char ch);
typedef struct{
uint8_t shift;
@@ -91,115 +91,45 @@ typedef struct{
extern const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128];
#endif
#endif
/*------------- Callbacks (Weak is optional) -------------*/
/** Callback invoked when USB host request \ref HID_REQ_CONTROL_GET_REPORT.
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[out] buffer data that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_MEM_SECTION)
* \param[in] reqlen number of bytes that host requested
* \retval non-zero Actual number of bytes in the response's buffer.
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
* sending STALL in the data phase.
* \note After this callback, the request is silently executed by the tinyusb stack, thus
* the completion of this control request will not be reported to application.
* For Keyboard, USB host often uses this to turn on/off the LED for CAPLOCKS, NUMLOCK (\ref hid_keyboard_led_bm_t)
*/
ATTR_WEAK uint16_t tud_hid_keyboard_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
/** Callback invoked when USB host request \ref HID_REQ_CONTROL_SET_REPORT.
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[in] buffer containing the report's data
* \param[in] bufsize number of bytes in the \a buffer
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
* Application are free to handle data at its own will.
*/
ATTR_WEAK void tud_hid_keyboard_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
//ATTR_WEAK void tud_hid_keyboard_set_protocol_cb(bool boot_protocol);
/** @} */
/** @} */
//--------------------------------------------------------------------+
// MOUSE API
// Convenient helper to send mouse report if application use standard/boot
// layout report as defined by hid_mouse_report_t
//--------------------------------------------------------------------+
#if CFG_TUD_HID_MOUSE
/** \addtogroup ClassDriver_HID_Mouse Mouse
* @{ */
/** \defgroup Mouse_Device Device
* @{ */
/** \brief Check if the interface is currently busy or not
* \retval true if the interface is busy meaning the stack is still transferring/waiting data from/to host
* \retval false if the interface is not busy meaning the stack successfully transferred data from/to host
* \note This function is primarily used for polling/waiting result after \ref tusbd_hid_mouse_send.
*/
bool tud_hid_mouse_ready(void);
bool tud_hid_mouse_is_boot_protocol(void);
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);
bool tud_hid_mouse_data(uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan);
bool tud_hid_mouse_move(int8_t x, int8_t y);
bool tud_hid_mouse_scroll(int8_t vertical, int8_t horizontal);
static inline bool tud_hid_mouse_button_press(uint8_t buttons)
static inline bool tud_hid_mouse_button_press(uint8_t report_id, uint8_t buttons)
{
return tud_hid_mouse_data(buttons, 0, 0, 0, 0);
return tud_hid_mouse_report(report_id, buttons, 0, 0, 0, 0);
}
static inline bool tud_hid_mouse_button_release(void)
static inline bool tud_hid_mouse_button_release(uint8_t report_id)
{
return tud_hid_mouse_data(0, 0, 0, 0, 0);
return tud_hid_mouse_report(report_id, 0, 0, 0, 0, 0);
}
/*------------- Callbacks (Weak is optional) -------------*/
/**
* Callback function that is invoked when USB host request \ref HID_REQ_CONTROL_GET_REPORT.
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[out] buffer buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_MEM_SECTION)
* \param[in] reqlen number of bytes that host requested
* \retval non-zero Actual number of bytes in the response's buffer.
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
* sending STALL in the data phase.
* \note After this callback, the request is silently executed by the tinyusb stack, thus
* the completion of this control request will not be reported to application
*/
ATTR_WEAK uint16_t tud_hid_mouse_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
/**
* Callback function that is invoked when USB host request \ref HID_REQ_CONTROL_SET_REPORT.
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
* \param[in] buffer buffer containing the report's data
* \param[in] bufsize number of bytes in the \a p_report_data
* \note By the time this callback is invoked, the USB control transfer is already completed in the hardware side.
* Application are free to handle data at its own will.
*/
ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
//ATTR_WEAK void tud_hid_mouse_set_protocol_cb(bool boot_protocol);
#endif
//--------------------------------------------------------------------+
// HID Report Descriptor Template
//--------------------------------------------------------------------+
/* These template should be used as follow
* - Only 1 report : no parameter
* uint8_t report_desc[] = { ID_REPORT_DESC_KEYBOARD() };
/* --------------------------------------------------------------------+
* HID Report Descriptor Template
*
* Convenient for declaring popular HID device (keyboard, mouse, consumer,
* gamepad etc...). Templates take "HID_REPORT_ID(n)," as input, leave
* empty if multiple reports is not used
*
* - Only 1 report: no parameter
* uint8_t const report_desc[] = { HID_REPORT_DESC_KEYBOARD() };
*
* - Multiple Reports: "HID_REPORT_ID(ID)," must be passed to template
* uint8_t report_desc[] = {
* ID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1) ,) ,
* HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(2) ,)
* uint8_t const report_desc[] =
* {
* HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1), ) ,
* HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(2), )
* };
*/
*--------------------------------------------------------------------*/
/*------------- Keyboard Descriptor Template -------------*/
// Keyboard Report Descriptor Template
#define HID_REPORT_DESC_KEYBOARD(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_KEYBOARD ) ,\
@@ -240,7 +170,7 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t
HID_OUTPUT ( HID_CONSTANT ) ,\
HID_COLLECTION_END \
/*------------- Mouse Descriptor Template -------------*/
// Mouse Report Descriptor Template
#define HID_REPORT_DESC_MOUSE(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_MOUSE ) ,\
@@ -280,7 +210,7 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t
HID_COLLECTION_END ,\
HID_COLLECTION_END \
//------------- Consumer Control Report Template -------------//
// Consumer Control Report Descriptor Template
#define HID_REPORT_DESC_CONSUMER(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ) ,\
HID_USAGE ( HID_USAGE_CONSUMER_CONTROL ) ,\
@@ -295,8 +225,8 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t
HID_INPUT ( HID_DATA | HID_ARRAY | HID_ABSOLUTE ) ,\
HID_COLLECTION_END \
//------------- System Control Report Template -------------//
/* 0x00 - do nothing
/* System Control Report Descriptor Template
* 0x00 - do nothing
* 0x01 - Power Off
* 0x02 - Standby
* 0x04 - Wake Host
@@ -321,8 +251,8 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t
HID_INPUT ( HID_CONSTANT ) ,\
HID_COLLECTION_END \
//------------- Gamepad Report Template -------------//
// Gamepad with 16 buttons and 2 joysticks
// 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(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
@@ -351,15 +281,11 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(uint8_t report_id, hid_report_type_t
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
HID_COLLECTION_END \
/** @} */
/** @} */
//--------------------------------------------------------------------+
// INTERNAL API
// Internal Class Driver API
//--------------------------------------------------------------------+
void hidd_init(void);
bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
@@ -113,7 +113,6 @@ bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, u
return true;
}
//--------------------------------------------------------------------+
// USBD-CLASS API
//--------------------------------------------------------------------+
@@ -62,24 +62,6 @@ TU_VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct");
#error CFG_TUD_MSC_PRODUCT_REV 4-byte string must be defined
#endif
//--------------------------------------------------------------------+
// Interface Descriptor Template
//--------------------------------------------------------------------+
// Length of template descriptor: 23 bytes
#define TUD_MSC_DESC_LEN (9 + 7 + 7)
// Interface Number, EP Out & EP In address
#define TUD_MSC_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
/* Interface */\
0x09, TUSB_DESC_INTERFACE, _itfnum, 0x00, 0x02, TUSB_CLASS_MSC, MSC_SUBCLASS_SCSI, MSC_PROTOCOL_BOT, _stridx,\
/* Endpoint Out */\
0x07, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0x00,\
/* Endpoint In */\
0x07, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0x00
/** \addtogroup ClassDriver_MSC
* @{
* \defgroup MSC_Device Device
@@ -107,7 +89,7 @@ bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, u
* \retval negative Indicate error e.g reading disk I/O. tinyusb will \b STALL the corresponding
* endpoint and return failed status in command status wrapper phase.
*/
ATTR_WEAK int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
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
@@ -126,10 +108,10 @@ ATTR_WEAK int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset,
* \retval negative Indicate error writing disk I/O. Tinyusb will \b STALL the corresponding
* endpoint and return failed status in command status wrapper phase.
*/
ATTR_WEAK int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize);
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
ATTR_WEAK void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size);
void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size);
/**
* Callback invoked when received an SCSI command not in built-in list below.
@@ -148,9 +130,9 @@ ATTR_WEAK void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t*
* - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
* - READ10 and WRITE10 has their own callbacks
*/
ATTR_WEAK int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize);
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize);
/*------------- Optional callbacks : Could be used by application to free up resources -------------*/
/*------------- Optional callbacks -------------*/
// Invoked when Read10 command is complete
ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun);
+2 -10
View File
@@ -60,14 +60,6 @@ typedef struct {
static usbd_device_t _usbd_dev = { 0 };
// Auto descriptor is enabled, descriptor set point to auto generated one
#if CFG_TUD_DESC_AUTO
extern tud_desc_set_t const _usbd_auto_desc_set;
tud_desc_set_t const* usbd_desc_set = &_usbd_auto_desc_set;
#else
tud_desc_set_t const* usbd_desc_set = &tud_desc_set;
#endif
//--------------------------------------------------------------------+
// Class Driver
//--------------------------------------------------------------------+
@@ -493,7 +485,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
// This function parse configuration descriptor & open drivers accordingly
static bool process_set_config(uint8_t rhport)
{
tusb_desc_configuration_t const * desc_cfg = (tusb_desc_configuration_t const *) usbd_desc_set->config;
tusb_desc_configuration_t const * desc_cfg = (tusb_desc_configuration_t const *) tud_desc_set.config;
TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
// Parse configuration descriptor
@@ -582,7 +574,7 @@ static void const* get_descriptor(tusb_control_request_t const * p_request, uint
break;
case TUSB_DESC_CONFIGURATION:
desc_data = (uint8_t const *) usbd_desc_set->config;
desc_data = (uint8_t const *) tud_desc_set.config;
len = ((tusb_desc_configuration_t const*) desc_data)->wTotalLength;
break;
+69 -6
View File
@@ -45,15 +45,11 @@ typedef struct {
uint8_t const** string_arr; ///< a array of pointers to string descriptors
uint16_t string_count;
struct {
uint8_t const* generic;
uint8_t const* boot_keyboard;
uint8_t const* boot_mouse;
} hid_report;
uint8_t const* hid_report;
}tud_desc_set_t;
// Must be defined by application
// Descriptor collection set, must be defined by application
extern tud_desc_set_t tud_desc_set;
//--------------------------------------------------------------------+
@@ -95,6 +91,73 @@ ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
// Invoked when usb bus is resumed
ATTR_WEAK void tud_resume_cb(void);
//--------------------------------------------------------------------+
// Interface Descriptor Template
//--------------------------------------------------------------------+
#define TUD_CONFIG_DESC_LEN (9)
// Inteface count, string index, total length, attribute, power in mA
#define TUD_CONFIG_DESCRIPTOR(_itfcount, _stridx, _total_len, _attribute, _power_ma) \
9, TUSB_DESC_CONFIGURATION, U16_TO_U8S_LE(_total_len), _itfcount, 1, _stridx, TU_BIT(7) | _attribute, (_power_ma)/2
//------------- CDC -------------//
// Length of template descriptor: 66 bytes
#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.
#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,\
/* CDC Control Interface */\
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, _stridx,\
/* CDC Header */\
5, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
/* CDC Call */\
5, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (_itfnum) + 1,\
/* CDC ACM: support line request */\
4, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 2,\
/* CDC Union */\
5, TUSB_DESC_CLASS_SPECIFIC, CDC_FUNC_DESC_UNION, _itfnum, (_itfnum) + 1,\
/* Endpoint Notification */\
7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 16,\
/* CDC Data Interface */\
9, TUSB_DESC_INTERFACE, (_itfnum)+1, 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
/* Endpoint Out */\
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
/* Endpoint In */\
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
//------------- MSC -------------//
// Length of template descriptor: 23 bytes
#define TUD_MSC_DESC_LEN (9 + 7 + 7)
// Interface number, string index, EP Out & EP In address, EP size
#define TUD_MSC_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
/* Interface */\
9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_MSC, MSC_SUBCLASS_SCSI, MSC_PROTOCOL_BOT, _stridx,\
/* Endpoint Out */\
7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
/* Endpoint In */\
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
//------------- HID -------------//
// Length of template descriptor: 25 bytes
#define TUD_HID_DESC_LEN (9 + 9 + 7)
// 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 */\
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
#ifdef __cplusplus
}
#endif
@@ -33,9 +33,6 @@
extern "C" {
#endif
// Either point to tud_desc_set or usbd_auto_desc_set depending on CFG_TUD_DESC_AUTO
extern tud_desc_set_t const* usbd_desc_set;
//--------------------------------------------------------------------+
// INTERNAL API for stack management
//--------------------------------------------------------------------+
-20
View File
@@ -157,10 +157,6 @@
#define CFG_TUD_CTRL_BUFSIZE 256
#endif
#ifndef CFG_TUD_DESC_AUTO
#define CFG_TUD_DESC_AUTO 0
#endif
#ifndef CFG_TUD_CDC
#define CFG_TUD_CDC 0
#endif
@@ -169,22 +165,6 @@
#define CFG_TUD_MSC 0
#endif
#ifndef CFG_TUD_HID_KEYBOARD
#define CFG_TUD_HID_KEYBOARD 0
#endif
#ifndef CFG_TUD_HID_MOUSE
#define CFG_TUD_HID_MOUSE 0
#endif
#ifndef CFG_TUD_HID_KEYBOARD_BOOT
#define CFG_TUD_HID_KEYBOARD_BOOT 0
#endif
#ifndef CFG_TUD_HID_MOUSE_BOOT
#define CFG_TUD_HID_MOUSE_BOOT 0
#endif
#endif // TUSB_OPT_DEVICE_ENABLED
//--------------------------------------------------------------------
+9 -29
View File
@@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef _TUSB_CONFIG_H_
#define _TUSB_CONFIG_H_
@@ -42,35 +43,22 @@
#define CFG_TUSB_OS OPT_OS_FREERTOS
#define CFG_TUSB_DEBUG 0
#define CFG_TUSB_MEM_SECTION
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
//--------------------------------------------------------------------
// DEVICE CONFIGURATION
//--------------------------------------------------------------------
#define CFG_TUD_ENDOINT0_SIZE 64
/*------------- Descriptors -------------*/
/* Enable auto generated descriptor, tinyusb will try its best to create
* descriptor ( device, configuration, hid ) that matches enabled CFG_* in this file
*
* Note: All CFG_TUD_DESC_* are relevant only if CFG_TUD_DESC_AUTO is enabled
*/
#define CFG_TUD_DESC_AUTO 0
//------------- CLASS -------------//
#define CFG_TUD_CDC 1
#define CFG_TUD_MSC 1
#define CFG_TUD_HID 0
#define CFG_TUD_HID_KEYBOARD 0
#define CFG_TUD_HID_MOUSE 0
/* Use Boot Protocol for Keyboard, Mouse. Enable this will create separated HID interface
* require more IN endpoints. If disabled, they they are all packed into a single
* multiple report interface called "Generic". */
#define CFG_TUD_HID_KEYBOARD_BOOT 0
#define CFG_TUD_HID_MOUSE_BOOT 0
#define CFG_TUD_MIDI 0
#define CFG_TUD_CUSTOM_CLASS 0
//--------------------------------------------------------------------
// CDC
@@ -103,19 +91,11 @@
// HID
//--------------------------------------------------------------------
/* Use the HID_ASCII_TO_KEYCODE lookup if CFG_TUD_HID_KEYBOARD is enabled.
* This will occupies 256 bytes of ROM. It will also enable the use of 2 extra APIs
/* Use the HID_ASCII_TO_KEYCODE lookup
* This will occupies 256 bytes of ROM. It will also enable the use of extra APIs
* - tud_hid_keyboard_send_char()
* - tud_hid_keyboard_send_string()
*/
#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 1
//--------------------------------------------------------------------
// USB RAM PLACEMENT
//--------------------------------------------------------------------
#define CFG_TUSB_ATTR_USBRAM
#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4)
#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 0
#ifdef __cplusplus
}