mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
add class mounted callback for hid mouse/keyboard & refractor mouse/keyboard app
This commit is contained in:
parent
c461c72ac2
commit
c303154b7a
@ -140,7 +140,7 @@ OSAL_TASK_FUNCTION( cdcd_serial_app_task ) (void* p_task_para)
|
||||
}
|
||||
}
|
||||
|
||||
// getting next data from host
|
||||
// getting more data from host
|
||||
tusbd_cdc_receive(0, serial_rx_buffer, CDCD_APP_BUFFER_SIZE, true);
|
||||
}
|
||||
|
||||
|
@ -46,22 +46,32 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
OSAL_TASK_DEF(keyboardd_app_task, 128, KEYBOARDD_APP_TASK_PRIO);
|
||||
|
||||
ATTR_USB_MIN_ALIGNMENT hid_keyboard_report_t keyboard_report TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
OSAL_TASK_DEF(keyboardd_app_task, 128, KEYBOARDD_APP_TASK_PRIO);
|
||||
|
||||
ATTR_USB_MIN_ALIGNMENT hid_keyboard_report_t keyboard_report TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
static uint8_t keyboardd_report_count; // number of reports sent each mounted
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// IMPLEMENTATION
|
||||
// tinyusb Callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
void tusbd_hid_keyboard_isr(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tusbd_hid_keyboard_mounted_cb(uint8_t coreid)
|
||||
{
|
||||
keyboardd_report_count = 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CODE
|
||||
//--------------------------------------------------------------------+
|
||||
void keyboardd_app_init(void)
|
||||
{
|
||||
ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(keyboardd_app_task) ), VOID_RETURN);
|
||||
@ -71,14 +81,23 @@ OSAL_TASK_FUNCTION( keyboardd_app_task ) (void* p_task_para)
|
||||
{
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
if (tusbd_is_configured(0))
|
||||
if (tusbd_is_configured(0) && (keyboardd_report_count++ < 5) )
|
||||
{
|
||||
static uint32_t count =0;
|
||||
if (count++ < 10)
|
||||
if (!tusbd_hid_keyboard_is_busy(0))
|
||||
{
|
||||
//------------- Key pressed -------------//
|
||||
keyboard_report.keycode[0] = 0x04;
|
||||
tusbd_hid_keyboard_send(0, &keyboard_report );
|
||||
|
||||
while( tusbd_hid_keyboard_is_busy(0) )
|
||||
{ // delay for transfer complete
|
||||
osal_task_delay(10);
|
||||
}
|
||||
|
||||
//------------- Key released -------------//
|
||||
if (!tusbd_hid_keyboard_is_busy(0))
|
||||
{
|
||||
keyboard_report.keycode[0] = (count%2) ? 0x04 : 0x00;
|
||||
keyboard_report.keycode[0] = 0x00;
|
||||
tusbd_hid_keyboard_send(0, &keyboard_report );
|
||||
}
|
||||
}
|
||||
|
@ -54,14 +54,24 @@ OSAL_TASK_DEF(moused_app_task, 128, MOUSED_APP_TASK_PRIO);
|
||||
|
||||
ATTR_USB_MIN_ALIGNMENT hid_mouse_report_t mouse_report TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
static uint8_t moused_report_count; // number of reports sent each mounted
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// IMPLEMENTATION
|
||||
// tinyusb Callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
void tusbd_hid_mouse_isr(uint8_t coreid, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tusbd_hid_mouse_mounted_cb(uint8_t coreid)
|
||||
{
|
||||
moused_report_count = 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CODE
|
||||
//--------------------------------------------------------------------+
|
||||
void moused_app_init(void)
|
||||
{
|
||||
ASSERT( TUSB_ERROR_NONE == osal_task_create( OSAL_TASK_REF(moused_app_task) ), VOID_RETURN);
|
||||
@ -71,16 +81,13 @@ OSAL_TASK_FUNCTION( moused_app_task ) (void* p_task_para)
|
||||
{
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
if (tusbd_is_configured(0))
|
||||
// only send 5 reports
|
||||
if (tusbd_is_configured(0) && (moused_report_count++ < 5) )
|
||||
{
|
||||
static uint32_t count =0;
|
||||
if (count++ < 10)
|
||||
if ( !tusbd_hid_mouse_is_busy(0) )
|
||||
{
|
||||
if ( !tusbd_hid_mouse_is_busy(0) )
|
||||
{
|
||||
mouse_report.x = mouse_report.y = 20;
|
||||
tusbd_hid_mouse_send(0, &mouse_report );
|
||||
}
|
||||
mouse_report.x = mouse_report.y = 20;
|
||||
tusbd_hid_mouse_send(0, &mouse_report );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ bool tusbd_hid_keyboard_is_busy(uint8_t coreid)
|
||||
|
||||
tusb_error_t tusbd_hid_keyboard_send(uint8_t coreid, hid_keyboard_report_t const *p_report)
|
||||
{
|
||||
//------------- verify data -------------//
|
||||
ASSERT(tusbd_is_configured(coreid), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
|
||||
|
||||
hidd_interface_t * p_kbd = &keyboardd_data; // TODO &keyboardd_data[coreid];
|
||||
|
||||
@ -104,7 +104,7 @@ bool tusbd_hid_mouse_is_busy(uint8_t coreid)
|
||||
|
||||
tusb_error_t tusbd_hid_mouse_send(uint8_t coreid, hid_mouse_report_t const *p_report)
|
||||
{
|
||||
//------------- verify data -------------//
|
||||
ASSERT(tusbd_is_configured(coreid), TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED);
|
||||
|
||||
hidd_interface_t * p_mouse = &moused_data; // TODO &keyboardd_data[coreid];
|
||||
|
||||
@ -226,10 +226,19 @@ tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int
|
||||
|
||||
ASSERT_PTR(p_hid, TUSB_ERROR_FAILED);
|
||||
|
||||
p_hid->interface_number = p_interface_desc->bInterfaceNumber;
|
||||
p_hid->report_length = p_desc_hid->wReportLength;
|
||||
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;
|
||||
|
||||
if (p_interface_desc->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD)
|
||||
{
|
||||
tusbd_hid_keyboard_mounted_cb(coreid);
|
||||
}else
|
||||
{
|
||||
tusbd_hid_mouse_mounted_cb(coreid);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -163,7 +163,7 @@ tusb_error_t usbd_body_subtask(void)
|
||||
{
|
||||
if ( TUSB_REQUEST_GET_DESCRIPTOR == control_request.bRequest )
|
||||
{
|
||||
static uint8_t const * p_buffer = NULL;
|
||||
static uint8_t* p_buffer = NULL;
|
||||
static uint16_t length = 0;
|
||||
|
||||
error = get_descriptor_subtask(coreid, &control_request, &p_buffer, &length);
|
||||
|
@ -105,7 +105,7 @@ static inline uint32_t osal_tick_get(void)
|
||||
ATTR_UNUSED static uint32_t timeout = 0;\
|
||||
static uint16_t state = 0;\
|
||||
switch(state) {\
|
||||
case 0:{\
|
||||
case 0: { \
|
||||
|
||||
#define OSAL_TASK_LOOP_END \
|
||||
default:\
|
||||
|
Loading…
x
Reference in New Issue
Block a user