mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
update dcd samd21
This commit is contained in:
parent
155edc7b00
commit
a0ce92bcfd
@ -45,8 +45,6 @@
|
|||||||
#include "device/usbd.h"
|
#include "device/usbd.h"
|
||||||
#include "device/usbd_pvt.h" // to use defer function helper
|
#include "device/usbd_pvt.h" // to use defer function helper
|
||||||
|
|
||||||
#include "class/msc/msc_device.h"
|
|
||||||
|
|
||||||
#include "sam.h"
|
#include "sam.h"
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
@ -58,9 +56,8 @@ enum
|
|||||||
MAX_PACKET_SIZE = 64,
|
MAX_PACKET_SIZE = 64,
|
||||||
};
|
};
|
||||||
|
|
||||||
UsbDeviceDescBank sram_registers[8][2];
|
static UsbDeviceDescBank sram_registers[8][2];
|
||||||
ATTR_ALIGNED(4) uint8_t control_out_buffer[64];
|
static ATTR_ALIGNED(4) uint8_t _setup_packet[8];
|
||||||
ATTR_ALIGNED(4) uint8_t control_in_buffer[64];
|
|
||||||
|
|
||||||
volatile uint32_t setup_count = 0;
|
volatile uint32_t setup_count = 0;
|
||||||
|
|
||||||
@ -76,7 +73,8 @@ static void bus_reset(void) {
|
|||||||
ep->EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(0x1) | USB_DEVICE_EPCFG_EPTYPE1(0x1);
|
ep->EPCFG.reg = USB_DEVICE_EPCFG_EPTYPE0(0x1) | USB_DEVICE_EPCFG_EPTYPE1(0x1);
|
||||||
ep->EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT0 | USB_DEVICE_EPINTENSET_TRCPT1 | USB_DEVICE_EPINTENSET_RXSTP;
|
ep->EPINTENSET.reg = USB_DEVICE_EPINTENSET_TRCPT0 | USB_DEVICE_EPINTENSET_TRCPT1 | USB_DEVICE_EPINTENSET_RXSTP;
|
||||||
|
|
||||||
dcd_edpt_xfer(0, 0, control_out_buffer, 64);
|
// Prepare for setup packet
|
||||||
|
dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
|
||||||
setup_count = 0;
|
setup_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +105,7 @@ void dcd_disconnect (uint8_t rhport)
|
|||||||
void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
|
void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
(void) rhport;
|
(void) rhport;
|
||||||
dcd_edpt_xfer (0, TUSB_DIR_IN_MASK, NULL, 0);
|
|
||||||
// Wait for EP0 to finish before switching the address.
|
// Wait for EP0 to finish before switching the address.
|
||||||
while (USB->DEVICE.DeviceEndpoint[0].EPSTATUS.bit.BK1RDY == 1) {}
|
while (USB->DEVICE.DeviceEndpoint[0].EPSTATUS.bit.BK1RDY == 1) {}
|
||||||
USB->DEVICE.DADD.reg = USB_DEVICE_DADD_DADD(dev_addr) | USB_DEVICE_DADD_ADDEN;
|
USB->DEVICE.DADD.reg = USB_DEVICE_DADD_DADD(dev_addr) | USB_DEVICE_DADD_ADDEN;
|
||||||
@ -121,20 +119,9 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
/* Control
|
/* DCD Endpoint port
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
|
|
||||||
bool dcd_control_xfer (uint8_t rhport, uint8_t dir, uint8_t * buffer, uint16_t length)
|
|
||||||
{
|
|
||||||
(void) rhport;
|
|
||||||
uint8_t ep_addr = 0;
|
|
||||||
if (dir == TUSB_DIR_IN) {
|
|
||||||
ep_addr |= TUSB_DIR_IN_MASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dcd_edpt_xfer (rhport, ep_addr, buffer, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
||||||
{
|
{
|
||||||
(void) rhport;
|
(void) rhport;
|
||||||
@ -163,7 +150,6 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
|||||||
ep->EPCFG.bit.EPTYPE1 = desc_edpt->bmAttributes.xfer + 1;
|
ep->EPCFG.bit.EPTYPE1 = desc_edpt->bmAttributes.xfer + 1;
|
||||||
ep->EPINTENSET.bit.TRCPT1 = true;
|
ep->EPINTENSET.bit.TRCPT1 = true;
|
||||||
}
|
}
|
||||||
__ISB(); __DSB();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -222,9 +208,12 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
|||||||
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
|
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
|
||||||
} else {
|
} else {
|
||||||
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
|
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
|
||||||
}
|
|
||||||
|
|
||||||
__ISB(); __DSB();
|
// for control, stall both IN & OUT
|
||||||
|
if (ep_addr == 0) {
|
||||||
|
ep->EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
||||||
@ -266,7 +255,6 @@ static bool maybe_handle_setup_packet(void) {
|
|||||||
|
|
||||||
// This copies the data elsewhere so we can reuse the buffer.
|
// This copies the data elsewhere so we can reuse the buffer.
|
||||||
dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
|
dcd_event_setup_received(0, (uint8_t*) sram_registers[0][0].ADDR.reg, true);
|
||||||
dcd_edpt_xfer(0, 0, control_out_buffer, 64);
|
|
||||||
setup_count += 1;
|
setup_count += 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -287,12 +275,14 @@ void maybe_transfer_complete(void) {
|
|||||||
|
|
||||||
uint32_t epintflag = ep->EPINTFLAG.reg;
|
uint32_t epintflag = ep->EPINTFLAG.reg;
|
||||||
|
|
||||||
|
uint16_t total_transfer_size;
|
||||||
|
|
||||||
// Handle IN completions
|
// Handle IN completions
|
||||||
if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
|
if ((epintflag & USB_DEVICE_EPINTFLAG_TRCPT1) != 0) {
|
||||||
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
|
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT1;
|
||||||
|
|
||||||
UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_IN];
|
UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_IN];
|
||||||
uint16_t total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
||||||
|
|
||||||
uint8_t ep_addr = epnum | TUSB_DIR_IN_MASK;
|
uint8_t ep_addr = epnum | TUSB_DIR_IN_MASK;
|
||||||
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, DCD_XFER_SUCCESS, true);
|
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, DCD_XFER_SUCCESS, true);
|
||||||
@ -303,13 +293,15 @@ void maybe_transfer_complete(void) {
|
|||||||
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
|
ep->EPINTFLAG.reg = USB_DEVICE_EPINTFLAG_TRCPT0;
|
||||||
|
|
||||||
UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_OUT];
|
UsbDeviceDescBank* bank = &sram_registers[epnum][TUSB_DIR_OUT];
|
||||||
uint16_t total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
total_transfer_size = bank->PCKSIZE.bit.BYTE_COUNT;
|
||||||
|
|
||||||
uint8_t ep_addr = epnum;
|
uint8_t ep_addr = epnum;
|
||||||
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, DCD_XFER_SUCCESS, true);
|
dcd_event_xfer_complete(0, ep_addr, total_transfer_size, DCD_XFER_SUCCESS, true);
|
||||||
if (epnum == 0) {
|
|
||||||
dcd_edpt_xfer(0, 0, control_out_buffer, 64);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// just finished status stage (total size = 0), prepare for next setup packet
|
||||||
|
if (epnum == 0 && total_transfer_size == 0) {
|
||||||
|
dcd_edpt_xfer(0, 0, _setup_packet, sizeof(_setup_packet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user