mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-22 15:40:06 +00:00
clean up some & add code for managing control request targeting interface
This commit is contained in:
parent
77e0834f34
commit
357e8d32ec
@ -66,6 +66,7 @@ tusb_error_t tusbd_hid_mouse_send_report(tusb_mouse_report_t *p_mouse_report);
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
tusb_error_t hidd_control_request(uint8_t coreid, tusb_std_request_t const * p_request);
|
||||
tusb_error_t hidd_configured(void);
|
||||
|
||||
#endif
|
||||
|
@ -106,7 +106,7 @@ void endpoint_control_isr(uint8_t coreid)
|
||||
(void) coreid; // suppress compiler warning
|
||||
uint32_t const endpoint_int_status = LPC_USB->USBEpIntSt & LPC_USB->USBEpIntEn;
|
||||
|
||||
// control OUT
|
||||
//------------- control OUT -------------//
|
||||
if (endpoint_int_status & BIT_(0))
|
||||
{
|
||||
uint32_t const endpoint_status = sie_command_read(SIE_CMDCODE_ENDPOINT_SELECT+0, 1);
|
||||
@ -118,14 +118,14 @@ void endpoint_control_isr(uint8_t coreid)
|
||||
usbd_isr(0, TUSB_EVENT_SETUP_RECEIVED);
|
||||
}else
|
||||
{
|
||||
// RxPLen should be zero for zero-length status phase. Current not support any out control with data yet
|
||||
ASSERT(LPC_USB->USBRxPLen == 0, (void) 0);
|
||||
// Current not support any out control with data yet
|
||||
// dcd_pipe_control_read(0,..
|
||||
}
|
||||
sie_command_write(SIE_CMDCODE_ENDPOINT_SELECT+0, 0, 0);
|
||||
sie_command_write(SIE_CMDCODE_BUFFER_CLEAR, 0, 0);
|
||||
}
|
||||
|
||||
// control IN
|
||||
//------------- control IN -------------//
|
||||
if (endpoint_int_status & BIT_(1))
|
||||
{
|
||||
(void) endpoint_int_status;
|
||||
@ -149,13 +149,8 @@ void dcd_isr(uint8_t coreid)
|
||||
}
|
||||
|
||||
// TODO invoke some callbacks
|
||||
if (dev_status_reg & SIE_DEV_STATUS_CONNECT_CHANGE_MASK)
|
||||
{
|
||||
|
||||
}
|
||||
if (dev_status_reg & SIE_DEV_STATUS_SUSPEND_CHANGE_MASK)
|
||||
{
|
||||
|
||||
if (dev_status_reg & SIE_DEV_STATUS_CONNECT_CHANGE_MASK) { }
|
||||
if (dev_status_reg & SIE_DEV_STATUS_SUSPEND_CHANGE_MASK) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,38 +214,6 @@ tusb_error_t dcd_init(void)
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
static inline uint8_t endpoint_address_to_physical_index(uint8_t ep_address) ATTR_ALWAYS_INLINE ATTR_CONST;
|
||||
static inline uint8_t endpoint_address_to_physical_index(uint8_t ep_address)
|
||||
{
|
||||
return (ep_address << 1) + (ep_address & 0x80 ? 1 : 0 );
|
||||
}
|
||||
|
||||
tusb_error_t dcd_endpoint_configure(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc)
|
||||
{
|
||||
uint8_t phy_ep = endpoint_address_to_physical_index( p_endpoint_desc->bEndpointAddress );
|
||||
|
||||
//------------- Realize Endpoint with Max Packet Size -------------//
|
||||
LPC_USB->USBReEp |= BIT_(phy_ep);
|
||||
endpoint_set_max_packet_size(phy_ep, p_endpoint_desc->wMaxPacketSize.size);
|
||||
|
||||
#ifndef _TEST_
|
||||
while ((LPC_USB->USBDevIntSt & DEV_INT_ENDPOINT_REALIZED_MASK) == 0) {} // TODO can be omitted, or move to set max packet size
|
||||
LPC_USB->USBDevIntClr = DEV_INT_ENDPOINT_REALIZED_MASK;
|
||||
#endif
|
||||
|
||||
//------------- DMA set up -------------//
|
||||
memclr_(dcd_dd + phy_ep, sizeof(dcd_dma_descriptor_t));
|
||||
dcd_dd[phy_ep].is_isochronous = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) ? 1 : 0;
|
||||
dcd_dd[phy_ep].max_packet_size = p_endpoint_desc->wMaxPacketSize.size;
|
||||
dcd_dd[phy_ep].is_retired = 1; // dd is not active at first
|
||||
|
||||
LPC_USB->USBEpDMAEn = BIT_(phy_ep);
|
||||
|
||||
sie_command_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+phy_ep, 1, 0); // clear all endpoint status
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
void dcd_controller_connect(uint8_t coreid)
|
||||
{
|
||||
sie_command_write(SIE_CMDCODE_DEVICE_STATUS, 1, 1);
|
||||
@ -267,6 +230,9 @@ void dcd_device_set_configuration(uint8_t coreid, uint8_t config_num)
|
||||
sie_command_write(SIE_CMDCODE_CONFIGURE_DEVICE, 1, 1);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PIPE API
|
||||
//--------------------------------------------------------------------+
|
||||
static inline uint16_t length_unit_byte2dword(uint16_t length_in_bytes) ATTR_ALWAYS_INLINE ATTR_CONST;
|
||||
static inline uint16_t length_unit_byte2dword(uint16_t length_in_bytes)
|
||||
{
|
||||
@ -319,4 +285,38 @@ void dcd_pipe_control_write_zero_length(uint8_t coreid)
|
||||
dcd_pipe_control_write(coreid, NULL, 0);
|
||||
}
|
||||
|
||||
static inline uint8_t endpoint_address_to_physical_index(uint8_t ep_address) ATTR_ALWAYS_INLINE ATTR_CONST;
|
||||
static inline uint8_t endpoint_address_to_physical_index(uint8_t ep_address)
|
||||
{
|
||||
return (ep_address << 1) + (ep_address & 0x80 ? 1 : 0 );
|
||||
}
|
||||
|
||||
tusb_error_t dcd_endpoint_configure(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc)
|
||||
{
|
||||
uint8_t phy_ep = endpoint_address_to_physical_index( p_endpoint_desc->bEndpointAddress );
|
||||
|
||||
//------------- Realize Endpoint with Max Packet Size -------------//
|
||||
LPC_USB->USBReEp |= BIT_(phy_ep);
|
||||
endpoint_set_max_packet_size(phy_ep, p_endpoint_desc->wMaxPacketSize.size);
|
||||
|
||||
#ifndef _TEST_
|
||||
while ((LPC_USB->USBDevIntSt & DEV_INT_ENDPOINT_REALIZED_MASK) == 0) {} // TODO can be omitted, or move to set max packet size
|
||||
LPC_USB->USBDevIntClr = DEV_INT_ENDPOINT_REALIZED_MASK;
|
||||
#endif
|
||||
|
||||
//------------- DMA set up -------------//
|
||||
memclr_(dcd_dd + phy_ep, sizeof(dcd_dma_descriptor_t));
|
||||
dcd_dd[phy_ep].is_isochronous = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) ? 1 : 0;
|
||||
dcd_dd[phy_ep].max_packet_size = p_endpoint_desc->wMaxPacketSize.size;
|
||||
dcd_dd[phy_ep].is_retired = 1; // dd is not active at first
|
||||
|
||||
LPC_USB->USBEpDMAEn = BIT_(phy_ep);
|
||||
|
||||
sie_command_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+phy_ep, 1, 0); // clear all endpoint status
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
//tusb_error_t dcd_pipe_xfer()
|
||||
|
||||
#endif
|
||||
|
@ -55,11 +55,12 @@
|
||||
usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER];
|
||||
|
||||
// TODO fix/compress number of class driver
|
||||
static device_class_driver_t const usbh_class_drivers[TUSB_CLASS_MAX_CONSEC_NUMBER] =
|
||||
static device_class_driver_t const usbd_class_drivers[TUSB_CLASS_MAX_CONSEC_NUMBER] =
|
||||
{
|
||||
#if DEVICE_CLASS_HID
|
||||
[TUSB_CLASS_HID] = {
|
||||
.init = hidd_init,
|
||||
.init = hidd_init,
|
||||
.control_request = hidd_control_request,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
@ -127,6 +128,13 @@ void usbd_setup_received(uint8_t coreid)
|
||||
if ( p_device->setup_packet.bmRequestType.recipient == TUSB_REQUEST_RECIPIENT_INTERFACE)
|
||||
{
|
||||
// TODO detect which class
|
||||
// ASSERT( p_device->setup_packet.wIndex < USBD_MAX_INTERFACE, (void) 0);
|
||||
// tusb_std_class_code_t const class_code = usbd_devices[coreid].interface2class[ p_device->setup_packet.wIndex ];
|
||||
// if ( usbd_class_drivers[class_code].control_request != NULL )
|
||||
// {
|
||||
// usbd_class_drivers[class_code].control_request(coreid, &p_device->setup_packet);
|
||||
//
|
||||
// }
|
||||
hidd_control_request(coreid, &p_device->setup_packet);
|
||||
}else
|
||||
{
|
||||
@ -169,7 +177,9 @@ tusb_error_t usbd_init (void)
|
||||
|
||||
uint16_t length = 0;
|
||||
#if TUSB_CFG_DEVICE_HID_KEYBOARD
|
||||
ASSERT_STATUS( hidd_init(0, &app_tusb_desc_configuration.keyboard_interface, &length) );
|
||||
tusb_descriptor_interface_t const * p_interface = &app_tusb_desc_configuration.keyboard_interface;
|
||||
ASSERT_STATUS( hidd_init(0, p_interface, &length) );
|
||||
usbd_devices[0].interface2class[p_interface->bInterfaceNumber] = p_interface->bInterfaceClass;
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_DEVICE_HID_MOUSE && 0
|
||||
|
@ -65,7 +65,8 @@
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
tusb_error_t (* const init)(tusb_descriptor_interface_t const *, uint16_t*);
|
||||
tusb_error_t (* const init)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*);
|
||||
tusb_error_t (* const control_request) (uint8_t, tusb_std_request_t const *);
|
||||
// void (* const isr) (pipe_handle_t, tusb_event_t);
|
||||
// void (* const close) (uint8_t);
|
||||
} device_class_driver_t;
|
||||
|
@ -55,11 +55,14 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define USBD_MAX_INTERFACE 10 // TODO refractor later
|
||||
#define USBD_MAX_ENDPOINT 32 // TODO refractor later
|
||||
typedef struct {
|
||||
volatile uint8_t state;
|
||||
uint8_t address;
|
||||
tusb_std_request_t setup_packet;
|
||||
|
||||
uint8_t interface2class[USBD_MAX_INTERFACE]; // determine interface number belongs to which class
|
||||
uint8_t endpoint_idx2class[USBD_MAX_ENDPOINT]; // determine endpoint index belongs to which class
|
||||
}usbd_device_info_t;
|
||||
|
||||
extern usbd_device_info_t usbd_devices[CONTROLLER_DEVICE_NUMBER];
|
||||
|
Loading…
x
Reference in New Issue
Block a user