refractor hidh_keyboard_open
This commit is contained in:
parent
f5e7644a1e
commit
a2031e6218
|
@ -108,24 +108,6 @@ void test_keyboard_no_instances_invalid_para(void)
|
||||||
TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(dev_addr));
|
TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(dev_addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_keyboard_open_ok(void)
|
|
||||||
{
|
|
||||||
uint16_t length=0;
|
|
||||||
pipe_handle_t pipe_hdl = {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 1};
|
|
||||||
|
|
||||||
hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl);
|
|
||||||
|
|
||||||
//------------- Code Under TEST -------------//
|
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_keyboard_open_subtask(dev_addr, (uint8_t*) p_kbd_interface_desc, &length));
|
|
||||||
|
|
||||||
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
|
||||||
TEST_ASSERT_EQUAL(2, tusbh_hid_keyboard_no_instances(dev_addr)); // init set instance number to 1
|
|
||||||
TEST_ASSERT_PIPE_HANDLE(pipe_hdl, p_hidh_kbd_interface->pipe_in);
|
|
||||||
TEST_ASSERT_EQUAL(8, p_hidh_kbd_interface->report_size);
|
|
||||||
TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t),
|
|
||||||
length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_keyboard_init(void)
|
void test_keyboard_init(void)
|
||||||
{
|
{
|
||||||
hidh_keyboard_init();
|
hidh_keyboard_init();
|
||||||
|
@ -134,6 +116,31 @@ void test_keyboard_init(void)
|
||||||
TEST_ASSERT_EQUAL(0, ((uint8_t*)keyboard_data) [i]);
|
TEST_ASSERT_EQUAL(0, ((uint8_t*)keyboard_data) [i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_keyboard_open_ok(void)
|
||||||
|
{
|
||||||
|
uint16_t length=0;
|
||||||
|
pipe_handle_t pipe_hdl = {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 2};
|
||||||
|
keyboard_interface_t* p_new_instance = &keyboard_data[dev_addr-1].instance[instance_num+1];
|
||||||
|
|
||||||
|
hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl);
|
||||||
|
|
||||||
|
//------------- Code Under TEST -------------//
|
||||||
|
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_keyboard_open_subtask(dev_addr, (uint8_t*) p_kbd_interface_desc, &length));
|
||||||
|
|
||||||
|
TEST_ASSERT_PIPE_HANDLE(pipe_hdl, p_new_instance->pipe_in);
|
||||||
|
TEST_ASSERT_EQUAL(8, p_new_instance->report_size);
|
||||||
|
TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t),
|
||||||
|
length);
|
||||||
|
|
||||||
|
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||||
|
TEST_ASSERT_EQUAL(2, tusbh_hid_keyboard_no_instances(dev_addr)); // init set instance number to 1
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_keyboard_close(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// keyboard_get
|
// keyboard_get
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
|
@ -101,27 +101,39 @@ void hidh_keyboard_init(void)
|
||||||
|
|
||||||
tusb_error_t hidh_keyboard_open_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length)
|
tusb_error_t hidh_keyboard_open_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length)
|
||||||
{
|
{
|
||||||
|
keyboard_interface_t *p_keyboard = get_kbd_instance(dev_addr, keyboard_data[dev_addr-1].instance_count);
|
||||||
uint8_t const *p_desc = descriptor;
|
uint8_t const *p_desc = descriptor;
|
||||||
|
|
||||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH]; // skip interface
|
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH]; // skip interface
|
||||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH]; // TODO skip HID, only support std keyboard
|
(*p_length) = p_desc - descriptor; // set ASAP, in case of error, p_length has to be not zero to prevent infinite re-open
|
||||||
|
|
||||||
// set ASAP, in case of error, p_length has to be not zero to prevent infinite re-open
|
//------------- HID descriptor -------------//
|
||||||
|
tusb_hid_descriptor_hid_t* const p_desc_hid = (tusb_hid_descriptor_hid_t* const) p_desc;
|
||||||
|
ASSERT_INT(HID_DESC_HID, p_desc_hid->bDescriptorType, TUSB_ERROR_INVALID_PARA);
|
||||||
|
|
||||||
|
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH]; // TODO skip HID, only support std keyboard
|
||||||
(*p_length) = p_desc - descriptor;
|
(*p_length) = p_desc - descriptor;
|
||||||
|
|
||||||
keyboard_interface_t *p_kbd = get_kbd_instance(dev_addr, keyboard_data[dev_addr-1].instance_count);
|
//------------- Endpoint Descriptor -------------//
|
||||||
|
|
||||||
ASSERT_INT(TUSB_DESC_ENDPOINT, p_desc[DESCRIPTOR_OFFSET_TYPE], TUSB_ERROR_INVALID_PARA);
|
ASSERT_INT(TUSB_DESC_ENDPOINT, p_desc[DESCRIPTOR_OFFSET_TYPE], TUSB_ERROR_INVALID_PARA);
|
||||||
|
|
||||||
p_kbd->pipe_in = hcd_pipe_open(dev_addr, (tusb_descriptor_endpoint_t*) p_desc, TUSB_CLASS_HID);
|
p_keyboard->pipe_in = hcd_pipe_open(dev_addr, (tusb_descriptor_endpoint_t*) p_desc, TUSB_CLASS_HID);
|
||||||
|
|
||||||
|
p_keyboard->report_size = ( ((tusb_descriptor_endpoint_t*) p_desc)->wMaxPacketSize & (BIT_(12)-1) );
|
||||||
|
|
||||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH]; // advance endpoint descriptor
|
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH]; // advance endpoint descriptor
|
||||||
(*p_length) = p_desc - descriptor;
|
(*p_length) = p_desc - descriptor;
|
||||||
|
|
||||||
ASSERT (pipehandle_is_valid(p_kbd->pipe_in), TUSB_ERROR_HCD_FAILED);
|
ASSERT (pipehandle_is_valid(p_keyboard->pipe_in), TUSB_ERROR_HCD_FAILED);
|
||||||
|
|
||||||
keyboard_data[dev_addr-1].instance_count++;
|
keyboard_data[dev_addr-1].instance_count++;
|
||||||
|
|
||||||
return TUSB_ERROR_NONE;
|
return TUSB_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hidh_keyboard_close(uint8_t dev_addr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -88,7 +88,6 @@ typedef struct {
|
||||||
} hidh_keyboard_info_t;
|
} hidh_keyboard_info_t;
|
||||||
|
|
||||||
void hidh_keyboard_init(void);
|
void hidh_keyboard_init(void);
|
||||||
tusb_error_t hidh_keyboard_install(uint8_t dev_addr, uint8_t const *descriptor) ATTR_WARN_UNUSED_RESULT;
|
|
||||||
tusb_error_t hidh_keyboard_open_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
|
tusb_error_t hidh_keyboard_open_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
|
||||||
void hidh_keyboard_close(uint8_t dev_addr);
|
void hidh_keyboard_close(uint8_t dev_addr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue