Merge pull request #846 from hathach/house-keeping

House keeping
This commit is contained in:
Ha Thach 2021-05-24 12:07:33 +07:00 committed by GitHub
commit ca8724ee08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 32 deletions

View File

@ -45,7 +45,7 @@ typedef struct
uint8_t ep_out; // optional Out endpoint uint8_t ep_out; // optional Out endpoint
uint8_t itf_protocol; // Boot mouse or keyboard uint8_t itf_protocol; // Boot mouse or keyboard
bool boot_mode; // default = false (Report) uint8_t protocol_mode; // Boot (0) or Report protocol (1)
uint8_t idle_rate; // up to application to handle idle rate uint8_t idle_rate; // up to application to handle idle rate
uint16_t report_desc_len; uint16_t report_desc_len;
@ -112,7 +112,7 @@ uint8_t tud_hid_n_interface_protocol(uint8_t instance)
uint8_t tud_hid_n_get_protocol(uint8_t instance) uint8_t tud_hid_n_get_protocol(uint8_t instance)
{ {
return _hidd_itf[instance].boot_mode ? HID_PROTOCOL_BOOT : HID_PROTOCOL_REPORT; return _hidd_itf[instance].protocol_mode;
} }
bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]) bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
@ -213,7 +213,7 @@ uint16_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint1
if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->itf_protocol = desc_itf->bInterfaceProtocol; if ( desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT ) p_hid->itf_protocol = desc_itf->bInterfaceProtocol;
p_hid->boot_mode = false; // default mode is REPORT p_hid->protocol_mode = HID_PROTOCOL_REPORT; // Per Specs: default is report mode
p_hid->itf_num = desc_itf->bInterfaceNumber; p_hid->itf_num = desc_itf->bInterfaceNumber;
// Use offsetof to avoid pointer to the odd/misaligned address // Use offsetof to avoid pointer to the odd/misaligned address
@ -326,8 +326,7 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
case HID_REQ_CONTROL_GET_PROTOCOL: case HID_REQ_CONTROL_GET_PROTOCOL:
if ( stage == CONTROL_STAGE_SETUP ) if ( stage == CONTROL_STAGE_SETUP )
{ {
uint8_t protocol = (p_hid->boot_mode ? HID_PROTOCOL_BOOT : HID_PROTOCOL_REPORT); tud_control_xfer(rhport, request, &p_hid->protocol_mode, 1);
tud_control_xfer(rhport, request, &protocol, 1);
} }
break; break;
@ -338,10 +337,10 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
} }
else if ( stage == CONTROL_STAGE_ACK ) else if ( stage == CONTROL_STAGE_ACK )
{ {
p_hid->boot_mode = (request->wValue == HID_PROTOCOL_BOOT); p_hid->protocol_mode = (uint8_t) request->wValue;
if (tud_hid_set_protocol_cb) if (tud_hid_set_protocol_cb)
{ {
tud_hid_set_protocol_cb(hid_itf, (uint8_t) request->wValue); tud_hid_set_protocol_cb(hid_itf, p_hid->protocol_mode);
} }
} }
break; break;

View File

@ -241,7 +241,7 @@ void hidh_close(uint8_t dev_addr)
hidh_device_t* hid_dev = get_dev(dev_addr); hidh_device_t* hid_dev = get_dev(dev_addr);
if (tuh_hid_umount_cb) if (tuh_hid_umount_cb)
{ {
for ( uint8_t inst = 0; inst < hid_dev->inst_count; inst++) tuh_hid_umount_cb(dev_addr, inst); for ( uint8_t inst = 0; inst < hid_dev->inst_count; inst++ ) tuh_hid_umount_cb(dev_addr, inst);
} }
tu_memclr(hid_dev, sizeof(hidh_device_t)); tu_memclr(hid_dev, sizeof(hidh_device_t));

View File

@ -297,10 +297,11 @@ void msch_init(void)
void msch_close(uint8_t dev_addr) void msch_close(uint8_t dev_addr)
{ {
msch_interface_t* p_msc = get_itf(dev_addr); msch_interface_t* p_msc = get_itf(dev_addr);
tu_memclr(p_msc, sizeof(msch_interface_t));
// invoke Application Callback // invoke Application Callback
if (tuh_msc_umount_cb) tuh_msc_umount_cb(dev_addr); if (p_msc->mounted && tuh_msc_umount_cb) tuh_msc_umount_cb(dev_addr);
tu_memclr(p_msc, sizeof(msch_interface_t));
} }
bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes) bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)

View File

@ -24,10 +24,6 @@
* This file is part of the TinyUSB stack. * This file is part of the TinyUSB stack.
*/ */
/** \ingroup group_usbd
* \defgroup group_dcd Device Controller Driver (DCD)
* @{ */
#ifndef _TUSB_DCD_H_ #ifndef _TUSB_DCD_H_
#define _TUSB_DCD_H_ #define _TUSB_DCD_H_
@ -168,5 +164,3 @@ extern void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t x
#endif #endif
#endif /* _TUSB_DCD_H_ */ #endif /* _TUSB_DCD_H_ */
/// @}

View File

@ -24,14 +24,10 @@
* This file is part of the TinyUSB stack. * This file is part of the TinyUSB stack.
*/ */
/** \ingroup group_usbh
* \defgroup Group_HCD Host Controller Driver (HCD)
* @{ */
#ifndef _TUSB_HCD_H_ #ifndef _TUSB_HCD_H_
#define _TUSB_HCD_H_ #define _TUSB_HCD_H_
#include <common/tusb_common.h> #include "common/tusb_common.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -95,27 +91,46 @@ enum {
#endif #endif
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Controller & Port API // Controller API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Initialize controller to host mode
bool hcd_init(uint8_t rhport); bool hcd_init(uint8_t rhport);
// Interrupt Handler
void hcd_int_handler(uint8_t rhport); void hcd_int_handler(uint8_t rhport);
// Enable USB interrupt
void hcd_int_enable (uint8_t rhport); void hcd_int_enable (uint8_t rhport);
// Disable USB interrupt
void hcd_int_disable(uint8_t rhport); void hcd_int_disable(uint8_t rhport);
// Get micro frame number (125 us) // Get micro frame number (125 us)
uint32_t hcd_uframe_number(uint8_t rhport); uint32_t hcd_uframe_number(uint8_t rhport);
// Get frame number (1ms) // Get frame number (1ms)
static inline uint32_t hcd_frame_number(uint8_t rhport) TU_ATTR_ALWAYS_INLINE static inline
uint32_t hcd_frame_number(uint8_t rhport)
{ {
return hcd_uframe_number(rhport) >> 3; return hcd_uframe_number(rhport) >> 3;
} }
/// return the current connect status of roothub port //--------------------------------------------------------------------+
bool hcd_port_connect_status(uint8_t hostid); // Port API
void hcd_port_reset(uint8_t hostid); //--------------------------------------------------------------------+
// Get the current connect status of roothub port
bool hcd_port_connect_status(uint8_t rhport);
// Reset USB bus on the port
void hcd_port_reset(uint8_t rhport);
// TODO implement later
void hcd_port_reset_end(uint8_t rhport); void hcd_port_reset_end(uint8_t rhport);
tusb_speed_t hcd_port_speed_get(uint8_t hostid);
// Get port link speed
tusb_speed_t hcd_port_speed_get(uint8_t rhport);
// HCD closes all opened endpoints belong to this device // HCD closes all opened endpoints belong to this device
void hcd_device_close(uint8_t rhport, uint8_t dev_addr); void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
@ -123,6 +138,7 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Endpoints API // Endpoints API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]); bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]);
bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc);
@ -134,14 +150,12 @@ bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr);
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen); bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// PIPE API // PIPE API - TODO remove later
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// TODO control xfer should be used via usbh layer // TODO control xfer should be used via usbh layer
bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet bool hcd_pipe_queue_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes); // only queue, not transferring yet
bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete); bool hcd_pipe_xfer(uint8_t dev_addr, uint8_t ep_addr, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete);
// tusb_error_t hcd_pipe_cancel();
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Event API (implemented by stack) // Event API (implemented by stack)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -163,5 +177,3 @@ extern void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint32_t
#endif #endif
#endif /* _TUSB_HCD_H_ */ #endif /* _TUSB_HCD_H_ */
/// @}