mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
[SAM] CDC working. Need to check inf file.
This commit is contained in:
parent
2315728358
commit
84e887003d
@ -21,7 +21,12 @@
|
||||
|
||||
#ifdef CDC_ENABLED
|
||||
|
||||
#define CDC_SERIAL_BUFFER_SIZE 64
|
||||
#define CDC_SERIAL_BUFFER_SIZE 64
|
||||
|
||||
#define CDC_LINESTATE_DTR 0x01 // Data Terminal Ready
|
||||
#define CDC_LINESTATE_RTS 0x02 // Ready to Send
|
||||
|
||||
#define CDC_LINESTATE_READY (CDC_LINESTATE_RTS | CDC_LINESTATE_DTR)
|
||||
|
||||
struct ring_buffer
|
||||
{
|
||||
@ -35,17 +40,20 @@ ring_buffer cdc_rx_buffer = { { 0 }, 0, 0};
|
||||
typedef struct
|
||||
{
|
||||
uint32_t dwDTERate;
|
||||
uint8_t bCharFormat;
|
||||
uint8_t bCharFormat;
|
||||
uint8_t bParityType;
|
||||
uint8_t bDataBits;
|
||||
uint8_t lineState;
|
||||
uint8_t lineState;
|
||||
} LineInfo;
|
||||
|
||||
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
_Pragma("pack(1)")
|
||||
static const CDCDescriptor _cdcInterface =
|
||||
{
|
||||
#ifdef HID_ENABLED
|
||||
D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1),
|
||||
#endif
|
||||
|
||||
// CDC communication interface
|
||||
D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
|
||||
@ -60,6 +68,7 @@ static const CDCDescriptor _cdcInterface =
|
||||
D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),USB_ENDPOINT_TYPE_BULK,0x40,0),
|
||||
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0)
|
||||
};
|
||||
_Pragma("pack()")
|
||||
|
||||
int WEAK CDC_GetInterface(uint8_t* interfaceNum)
|
||||
{
|
||||
@ -92,22 +101,22 @@ bool WEAK CDC_Setup(Setup& setup)
|
||||
if (CDC_SET_CONTROL_LINE_STATE == r)
|
||||
{
|
||||
_usbLineInfo.lineState = setup.wValueL;
|
||||
|
||||
// auto-reset into the bootloader is triggered when the port, already
|
||||
// open at 1200 bps, is closed. this is the signal to start the watchdog
|
||||
// with a relatively long period so it can finish housekeeping tasks
|
||||
// like servicing endpoints before the sketch ends
|
||||
if (1200 == _usbLineInfo.dwDTERate) {
|
||||
if (1200 == _usbLineInfo.dwDTERate)
|
||||
{
|
||||
// We check DTR state to determine if host port is open (bit 0 of lineState).
|
||||
if ((_usbLineInfo.lineState & 0x01) == 0)
|
||||
{
|
||||
{
|
||||
/* TODO, AVR Stuff
|
||||
*(uint16_t *)0x0800 = 0x7777;
|
||||
wdt_enable(WDTO_120MS);
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
// Most OSs do some intermediate steps when configuring ports and DTR can
|
||||
// twiggle more than once before stabilizing.
|
||||
// To avoid spurious resets we set the watchdog to 250ms and eventually
|
||||
@ -127,7 +136,7 @@ bool WEAK CDC_Setup(Setup& setup)
|
||||
|
||||
|
||||
int _serialPeek = -1;
|
||||
void Serial_::begin(uint16_t baud_count)
|
||||
void Serial_::begin(uint32_t baud_count)
|
||||
{
|
||||
}
|
||||
|
||||
@ -160,9 +169,13 @@ int Serial_::available(void)
|
||||
int Serial_::peek(void)
|
||||
{
|
||||
ring_buffer *buffer = &cdc_rx_buffer;
|
||||
if (buffer->head == buffer->tail) {
|
||||
|
||||
if (buffer->head == buffer->tail)
|
||||
{
|
||||
return -1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return buffer->buffer[buffer->tail];
|
||||
}
|
||||
}
|
||||
@ -170,10 +183,14 @@ int Serial_::peek(void)
|
||||
int Serial_::read(void)
|
||||
{
|
||||
ring_buffer *buffer = &cdc_rx_buffer;
|
||||
|
||||
// if the head isn't ahead of the tail, we don't have any characters
|
||||
if (buffer->head == buffer->tail) {
|
||||
if (buffer->head == buffer->tail)
|
||||
{
|
||||
return -1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char c = buffer->buffer[buffer->tail];
|
||||
buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
|
||||
return c;
|
||||
@ -196,11 +213,16 @@ size_t Serial_::write(uint8_t c)
|
||||
// TODO - ZE - check behavior on different OSes and test what happens if an
|
||||
// open connection isn't broken cleanly (cable is yanked out, host dies
|
||||
// or locks up, or host virtual serial port hangs)
|
||||
if (_usbLineInfo.lineState > 0) {
|
||||
if (_usbLineInfo.lineState == CDC_LINESTATE_READY)
|
||||
{
|
||||
int r = USBD_Send(CDC_TX,&c,1);
|
||||
if (r > 0) {
|
||||
|
||||
if (r > 0)
|
||||
{
|
||||
USBD_Flush(CDC_TX);
|
||||
return r;
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
@ -216,10 +238,15 @@ size_t Serial_::write(uint8_t c)
|
||||
// actually ready to receive and display the data.
|
||||
// We add a short delay before returning to fix a bug observed by Federico
|
||||
// where the port is configured (lineState != 0) but not quite opened.
|
||||
Serial_::operator bool() {
|
||||
Serial_::operator bool()
|
||||
{
|
||||
bool result = false;
|
||||
if (_usbLineInfo.lineState > 0)
|
||||
|
||||
if (_usbLineInfo.lineState == CDC_LINESTATE_READY)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
delay(10);
|
||||
return result;
|
||||
}
|
||||
|
@ -162,11 +162,8 @@ bool WEAK HID_Setup(Setup& setup)
|
||||
uint8_t r = setup.bRequest;
|
||||
uint8_t requestType = setup.bmRequestType;
|
||||
|
||||
printf("=> HID_Setup\r\n");
|
||||
|
||||
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
|
||||
{
|
||||
printf("=> REQUEST_DEVICETOHOST_CLASS_INTERFACE\r\n");
|
||||
if (HID_GET_REPORT == r)
|
||||
{
|
||||
//HID_GetReport();
|
||||
@ -181,7 +178,6 @@ bool WEAK HID_Setup(Setup& setup)
|
||||
|
||||
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
|
||||
{
|
||||
printf("=> REQUEST_HOSTTODEVICE_CLASS_INTERFACE\r\n");
|
||||
if (HID_SET_PROTOCOL == r)
|
||||
{
|
||||
_hid_protocol = setup.wValueL;
|
||||
@ -289,9 +285,9 @@ extern const uint8_t _asciimap[128] =
|
||||
0x00, // ENQ
|
||||
0x00, // ACK
|
||||
0x00, // BEL
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x2a, // BS Backspace
|
||||
0x2b, // TAB Tab
|
||||
0x28, // LF Enter
|
||||
0x00, // VT
|
||||
0x00, // FF
|
||||
0x00, // CR
|
||||
|
@ -48,7 +48,7 @@ class Serial_ : public Stream
|
||||
private:
|
||||
RingBuffer *_cdc_rx_buffer;
|
||||
public:
|
||||
void begin(uint16_t baud_count);
|
||||
void begin(uint32_t baud_count);
|
||||
void end(void);
|
||||
|
||||
virtual int available(void);
|
||||
|
@ -18,6 +18,9 @@
|
||||
#include "USBAPI.h"
|
||||
#include <stdio.h>
|
||||
|
||||
//#define TRACE_CORE(x) x
|
||||
#define TRACE_CORE(x)
|
||||
|
||||
static const uint32_t EndPoints[] =
|
||||
{
|
||||
EP_TYPE_CONTROL,
|
||||
@ -76,12 +79,22 @@ const uint16_t STRING_IMANUFACTURER[12] = {
|
||||
#define DEVICE_CLASS 0x00
|
||||
#endif
|
||||
|
||||
#if defined CDC_ENABLED && defined HID_ENABLED
|
||||
#define USB_PID_FINAL (USB_PID|0x1001UL)
|
||||
#elif defined HID_ENABLED
|
||||
#define USB_PID_FINAL (USB_PID|0x1000UL)
|
||||
#elif defined CDC_ENABLED
|
||||
#define USB_PID_FINAL (USB_PID|0x0001UL)
|
||||
#endif
|
||||
|
||||
// DEVICE DESCRIPTOR
|
||||
const DeviceDescriptor USB_DeviceDescriptor =
|
||||
D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
|
||||
D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID_FINAL,0x100,IMANUFACTURER,IPRODUCT,0,1);
|
||||
|
||||
const DeviceDescriptor USB_DeviceDescriptorA =
|
||||
D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
|
||||
D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID_FINAL,0x100,IMANUFACTURER,IPRODUCT,0,1);
|
||||
|
||||
|
||||
|
||||
//==================================================================
|
||||
//==================================================================
|
||||
@ -90,7 +103,6 @@ volatile uint32_t _usbConfiguration = 0;
|
||||
volatile uint32_t _usbInitialized = 0;
|
||||
uint32_t _cdcComposite = 0;
|
||||
|
||||
|
||||
//==================================================================
|
||||
//==================================================================
|
||||
|
||||
@ -101,7 +113,6 @@ class LockEP
|
||||
public:
|
||||
LockEP(uint32_t ep) : flags(cpu_irq_save())
|
||||
{
|
||||
//UDD_SetEP(ep & 0xF);
|
||||
}
|
||||
~LockEP()
|
||||
{
|
||||
@ -130,7 +141,7 @@ uint32_t USBD_Recv(uint32_t ep, void* d, uint32_t len)
|
||||
uint8_t* dst = (uint8_t*)d;
|
||||
while (n--)
|
||||
*dst++ = UDD_Recv8(ep & 0xF);
|
||||
if (len && !UDD_FifoByteCount(ep & 0xF)) // release empty buffer
|
||||
if (len && !UDD_FifoByteCount(ep & 0xF)) // release empty buffer
|
||||
UDD_ReleaseRX(ep & 0xF);
|
||||
|
||||
return len;
|
||||
@ -163,7 +174,7 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
|
||||
|
||||
int r = len;
|
||||
const uint8_t* data = (const uint8_t*)d;
|
||||
uint8_t timeout = 250; // 250ms timeout on send? TODO
|
||||
uint8_t timeout = 250; // 250ms timeout on send? TODO
|
||||
|
||||
while (len)
|
||||
{
|
||||
@ -202,30 +213,27 @@ void USBD_InitControl(int end)
|
||||
// Clipped by _cmark/_cend
|
||||
int USBD_SendControl(uint8_t flags, const void* d, uint32_t len)
|
||||
{
|
||||
int sent = len;
|
||||
uint32_t i = 0;
|
||||
const uint8_t* data = (const uint8_t*)d;
|
||||
uint32_t length = len;
|
||||
uint32_t sent = 0;
|
||||
uint32_t pos = 0;
|
||||
|
||||
printf("=> USBD_SendControl TOTAL len=%d\r\n", len);
|
||||
TRACE_CORE(printf("=> USBD_SendControl TOTAL len=%d\r\n", len);)
|
||||
|
||||
for (i = 0; len > 64; ++i, len -= 64, _cmark += 64)
|
||||
if (_cmark < _cend)
|
||||
{
|
||||
if (_cmark < _cend)
|
||||
while (len > 0)
|
||||
{
|
||||
UDD_Send(EP0, data + (i * 64), 64);
|
||||
UDD_ClearIN(); // Fifo is full, release this packet
|
||||
UDD_WaitIN(); // Wait for new FIFO buffer to be ready
|
||||
sent = UDD_Send(EP0, data + pos, len);
|
||||
TRACE_CORE(printf("=> USBD_SendControl sent=%d\r\n", sent);)
|
||||
pos += sent;
|
||||
len -= sent;
|
||||
}
|
||||
}
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
if (_cmark < _cend)
|
||||
UDD_Send(EP0, data + (i * 64), len);
|
||||
_cmark += len;
|
||||
}
|
||||
_cmark += length;
|
||||
|
||||
return sent;
|
||||
return length;
|
||||
}
|
||||
|
||||
// Does not timeout or cross fifo boundaries
|
||||
@ -234,7 +242,7 @@ int USBD_SendControl(uint8_t flags, const void* d, uint32_t len)
|
||||
int USBD_RecvControl(void* d, uint32_t len)
|
||||
{
|
||||
UDD_WaitOUT() ;
|
||||
UDD_Recv(EP0, (uint8_t*)d, len ) ; // WILL NOT WORK WITH CDC
|
||||
UDD_Recv(EP0, (uint8_t*)d, len ) ;
|
||||
UDD_ClearOUT() ;
|
||||
|
||||
return len ;
|
||||
@ -245,7 +253,7 @@ bool USBD_ClassInterfaceRequest(Setup& setup)
|
||||
{
|
||||
uint8_t i = setup.wIndex;
|
||||
|
||||
printf("=> USBD_ClassInterfaceRequest\r\n");
|
||||
TRACE_CORE(printf("=> USBD_ClassInterfaceRequest\r\n");)
|
||||
|
||||
#ifdef CDC_ENABLED
|
||||
if ( CDC_ACM_INTERFACE == i )
|
||||
@ -277,7 +285,8 @@ int USBD_SendInterfaces(void)
|
||||
total += HID_GetInterface(&interfaces) ;
|
||||
#endif
|
||||
|
||||
printf("=> USBD_SendInterfaces, total=%d interfaces=%d\r\n", total, interfaces);
|
||||
total = total; // Get rid of compiler warning
|
||||
TRACE_CORE(printf("=> USBD_SendInterfaces, total=%d interfaces=%d\r\n", total, interfaces);)
|
||||
return interfaces;
|
||||
}
|
||||
|
||||
@ -288,17 +297,17 @@ static bool USBD_SendConfiguration(int maxlen)
|
||||
{
|
||||
// Count and measure interfaces
|
||||
USBD_InitControl(0);
|
||||
printf("=> USBD_SendConfiguration _cmark1=%d\r\n", _cmark);
|
||||
//TRACE_CORE(printf("=> USBD_SendConfiguration _cmark1=%d\r\n", _cmark);)
|
||||
int interfaces = USBD_SendInterfaces();
|
||||
printf("=> USBD_SendConfiguration _cmark2=%d\r\n", _cmark);
|
||||
printf("=> USBD_SendConfiguration sizeof=%d\r\n", sizeof(ConfigDescriptor));
|
||||
//TRACE_CORE(printf("=> USBD_SendConfiguration _cmark2=%d\r\n", _cmark);)
|
||||
//TRACE_CORE(printf("=> USBD_SendConfiguration sizeof=%d\r\n", sizeof(ConfigDescriptor));)
|
||||
|
||||
_Pragma("pack(1)")
|
||||
ConfigDescriptor config = D_CONFIG(_cmark + sizeof(ConfigDescriptor),interfaces);
|
||||
_Pragma("pack()")
|
||||
printf("=> USBD_SendConfiguration clen=%d\r\n", config.clen);
|
||||
//TRACE_CORE(printf("=> USBD_SendConfiguration clen=%d\r\n", config.clen);)
|
||||
|
||||
printf("=> USBD_SendConfiguration maxlen=%d\r\n", maxlen);
|
||||
//TRACE_CORE(printf("=> USBD_SendConfiguration maxlen=%d\r\n", maxlen);)
|
||||
|
||||
// Now send them
|
||||
USBD_InitControl(maxlen);
|
||||
@ -315,7 +324,7 @@ static bool USBD_SendDescriptor(Setup& setup)
|
||||
|
||||
if ( USB_CONFIGURATION_DESCRIPTOR_TYPE == t )
|
||||
{
|
||||
printf("=> USBD_SendDescriptor : USB_CONFIGURATION_DESCRIPTOR_TYPE length=%d\r\n", setup.wLength);
|
||||
TRACE_CORE(printf("=> USBD_SendDescriptor : USB_CONFIGURATION_DESCRIPTOR_TYPE length=%d\r\n", setup.wLength);)
|
||||
return USBD_SendConfiguration(setup.wLength);
|
||||
}
|
||||
|
||||
@ -323,14 +332,14 @@ static bool USBD_SendDescriptor(Setup& setup)
|
||||
#ifdef HID_ENABLED
|
||||
if ( HID_REPORT_DESCRIPTOR_TYPE == t )
|
||||
{
|
||||
puts("=> USBD_SendDescriptor : HID_REPORT_DESCRIPTOR_TYPE\r\n");
|
||||
TRACE_CORE(puts("=> USBD_SendDescriptor : HID_REPORT_DESCRIPTOR_TYPE\r\n");)
|
||||
return HID_GetDescriptor( t ) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (USB_DEVICE_DESCRIPTOR_TYPE == t)
|
||||
{
|
||||
puts("=> USBD_SendDescriptor : USB_DEVICE_DESCRIPTOR_TYPE\r\n");
|
||||
TRACE_CORE(puts("=> USBD_SendDescriptor : USB_DEVICE_DESCRIPTOR_TYPE\r\n");)
|
||||
if ( setup.wLength == 8 )
|
||||
{
|
||||
_cdcComposite = 1;
|
||||
@ -339,7 +348,7 @@ static bool USBD_SendDescriptor(Setup& setup)
|
||||
}
|
||||
else if (USB_STRING_DESCRIPTOR_TYPE == t)
|
||||
{
|
||||
puts("=> USBD_SendDescriptor : USB_STRING_DESCRIPTOR_TYPE\r\n");
|
||||
TRACE_CORE(puts("=> USBD_SendDescriptor : USB_STRING_DESCRIPTOR_TYPE\r\n");)
|
||||
if (setup.wValueL == 0)
|
||||
desc_addr = (const uint8_t*)&STRING_LANGUAGE;
|
||||
else if (setup.wValueL == IPRODUCT)
|
||||
@ -360,7 +369,7 @@ static bool USBD_SendDescriptor(Setup& setup)
|
||||
desc_length = *desc_addr;
|
||||
}
|
||||
|
||||
printf("=> USBD_SendDescriptor : desc_addr=%x desc_length=%d\r\n", desc_addr, desc_length);
|
||||
TRACE_CORE(printf("=> USBD_SendDescriptor : desc_addr=%x desc_length=%d\r\n", desc_addr, desc_length);)
|
||||
USBD_SendControl(0, desc_addr, desc_length);
|
||||
|
||||
return true;
|
||||
@ -372,46 +381,37 @@ static void USB_ISR(void)
|
||||
// End of Reset
|
||||
if (Is_udd_reset())
|
||||
{
|
||||
printf(">>> End of Reset\r\n");
|
||||
TRACE_CORE(printf(">>> End of Reset\r\n");)
|
||||
|
||||
// Reset USB address to 0
|
||||
udd_configure_address(0);
|
||||
udd_enable_address();
|
||||
|
||||
// Configure EP 0
|
||||
//UDD_SetEP(0);
|
||||
UDD_InitEP(0, EP_TYPE_CONTROL);
|
||||
udd_enable_setup_received_interrupt(0);
|
||||
udd_enable_endpoint_interrupt(0);
|
||||
|
||||
_usbConfiguration = 0;
|
||||
udd_ack_reset(); /* /!\/!\/!\ TAKEN FROM ASF TO CLEAR ISR /!\/!\/!\ */
|
||||
udd_ack_reset();
|
||||
}
|
||||
|
||||
// Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too
|
||||
if (Is_udd_sof())
|
||||
{
|
||||
//printf(">>> Start of Frame\r\n");
|
||||
#ifdef CDC_ENABLED
|
||||
USBD_Flush(CDC_TX); // Send a tx frame if found
|
||||
while (USBD_Available(CDC_RX)) // Handle received bytes (if any)
|
||||
if (Is_udd_endpoint_interrupt(CDC_RX))
|
||||
{
|
||||
udd_ack_out_received(CDC_RX);
|
||||
|
||||
// Handle received bytes
|
||||
while (USBD_Available(CDC_RX))
|
||||
Serial.accept();
|
||||
|
||||
udd_ack_fifocon(CDC_RX) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
// check whether the one-shot period has elapsed. if so, turn off the LED
|
||||
/*if (TxLEDPulse && !(--TxLEDPulse))
|
||||
TXLED0;
|
||||
if (RxLEDPulse && !(--RxLEDPulse))
|
||||
RXLED0;*/
|
||||
|
||||
udd_ack_sof(); /* /!\/!\/!\ TAKEN FROM ASF TO CLEAR ISR /!\/!\/!\ */
|
||||
}
|
||||
|
||||
// EP 0 Interrupt
|
||||
if (Is_udd_endpoint_interrupt(0))
|
||||
{
|
||||
//UDD_SetEP(0);
|
||||
|
||||
//printf(">>> EP0 Int: 0x%x\r\n", UOTGHS->UOTGHS_DEVEPTISR[0]);
|
||||
|
||||
if ( !UDD_ReceivedSetupInt() )
|
||||
{
|
||||
@ -422,17 +422,15 @@ static void USB_ISR(void)
|
||||
UDD_Recv(EP0, (uint8_t*)&setup, 8);
|
||||
UDD_ClearSetupInt();
|
||||
|
||||
//printf(">>> EP0 Int: AP clear: 0x%x\r\n", UOTGHS->UOTGHS_DEVEPTISR[0]);
|
||||
|
||||
uint8_t requestType = setup.bmRequestType;
|
||||
if (requestType & REQUEST_DEVICETOHOST)
|
||||
{
|
||||
printf(">>> EP0 Int: IN Request\r\n");
|
||||
TRACE_CORE(printf(">>> EP0 Int: IN Request\r\n");)
|
||||
UDD_WaitIN();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(">>> EP0 Int: OUT Request\r\n");
|
||||
TRACE_CORE(printf(">>> EP0 Int: OUT Request\r\n");)
|
||||
UDD_ClearIN();
|
||||
}
|
||||
|
||||
@ -441,12 +439,12 @@ static void USB_ISR(void)
|
||||
bool ok = true ;
|
||||
if (REQUEST_STANDARD == (requestType & REQUEST_TYPE))
|
||||
{
|
||||
// Standard Requests
|
||||
// Standard Requests
|
||||
uint8_t r = setup.bRequest;
|
||||
if (GET_STATUS == r)
|
||||
{
|
||||
puts(">>> EP0 Int: GET_STATUS\r\n");
|
||||
UDD_Send8(EP0, 0); // TODO
|
||||
TRACE_CORE(puts(">>> EP0 Int: GET_STATUS\r\n");)
|
||||
UDD_Send8(EP0, 0); // TODO
|
||||
UDD_Send8(EP0, 0);
|
||||
}
|
||||
else if (CLEAR_FEATURE == r)
|
||||
@ -457,65 +455,70 @@ static void USB_ISR(void)
|
||||
}
|
||||
else if (SET_ADDRESS == r)
|
||||
{
|
||||
puts(">>> EP0 Int: SET_ADDRESS\r\n");
|
||||
TRACE_CORE(puts(">>> EP0 Int: SET_ADDRESS\r\n");)
|
||||
UDD_WaitIN();
|
||||
UDD_SetAddress(setup.wValueL);
|
||||
}
|
||||
else if (GET_DESCRIPTOR == r)
|
||||
{
|
||||
puts(">>> EP0 Int: GET_DESCRIPTOR\r\n");
|
||||
TRACE_CORE(puts(">>> EP0 Int: GET_DESCRIPTOR\r\n");)
|
||||
ok = USBD_SendDescriptor(setup);
|
||||
}
|
||||
else if (SET_DESCRIPTOR == r)
|
||||
{
|
||||
puts(">>> EP0 Int: SET_DESCRIPTOR\r\n");
|
||||
TRACE_CORE(puts(">>> EP0 Int: SET_DESCRIPTOR\r\n");)
|
||||
ok = false;
|
||||
}
|
||||
else if (GET_CONFIGURATION == r)
|
||||
{
|
||||
puts(">>> EP0 Int: GET_CONFIGURATION\r\n");
|
||||
TRACE_CORE(puts(">>> EP0 Int: GET_CONFIGURATION\r\n");)
|
||||
UDD_Send8(EP0, 1);
|
||||
}
|
||||
else if (SET_CONFIGURATION == r)
|
||||
{
|
||||
if (REQUEST_DEVICE == (requestType & REQUEST_RECIPIENT))
|
||||
{
|
||||
printf(">>> EP0 Int: SET_CONFIGURATION REQUEST_DEVICE %d\r\n", setup.wValueL);
|
||||
TRACE_CORE(printf(">>> EP0 Int: SET_CONFIGURATION REQUEST_DEVICE %d\r\n", setup.wValueL);)
|
||||
|
||||
UDD_InitEndpoints(EndPoints, (sizeof(EndPoints) / sizeof(EndPoints[0])));
|
||||
_usbConfiguration = setup.wValueL;
|
||||
|
||||
#ifdef CDC_ENABLED
|
||||
// Enable interrupt for CDC reception from host (OUT packet)
|
||||
udd_enable_out_received_interrupt(CDC_RX);
|
||||
udd_enable_endpoint_interrupt(CDC_RX);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
puts(">>> EP0 Int: SET_CONFIGURATION failed!\r\n");
|
||||
TRACE_CORE(puts(">>> EP0 Int: SET_CONFIGURATION failed!\r\n");)
|
||||
ok = false;
|
||||
}
|
||||
}
|
||||
else if (GET_INTERFACE == r)
|
||||
{
|
||||
puts(">>> EP0 Int: GET_INTERFACE\r\n");
|
||||
TRACE_CORE(puts(">>> EP0 Int: GET_INTERFACE\r\n");)
|
||||
}
|
||||
else if (SET_INTERFACE == r)
|
||||
{
|
||||
puts(">>> EP0 Int: SET_INTERFACE\r\n");
|
||||
TRACE_CORE(puts(">>> EP0 Int: SET_INTERFACE\r\n");)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
puts(">>> EP0 Int: ClassInterfaceRequest\r\n");
|
||||
USBD_InitControl(setup.wLength); // Max length of transfer
|
||||
TRACE_CORE(puts(">>> EP0 Int: ClassInterfaceRequest\r\n");)
|
||||
USBD_InitControl(setup.wLength); // Max length of transfer
|
||||
ok = USBD_ClassInterfaceRequest(setup);
|
||||
}
|
||||
|
||||
if (ok)
|
||||
{
|
||||
puts(">>> EP0 Int: Send packet\r\n");
|
||||
UDD_ClearOUT(); // rajouté par moi, pe pas nécessaire car la fifo est suffisament grande
|
||||
TRACE_CORE(puts(">>> EP0 Int: Send packet\r\n");)
|
||||
UDD_ClearIN();
|
||||
}
|
||||
else
|
||||
{
|
||||
puts(">>> EP0 Int: Stall\r\n");
|
||||
TRACE_CORE(puts(">>> EP0 Int: Stall\r\n");)
|
||||
UDD_Stall();
|
||||
}
|
||||
}
|
||||
@ -523,7 +526,6 @@ static void USB_ISR(void)
|
||||
|
||||
void USBD_Flush(uint32_t ep)
|
||||
{
|
||||
//UDD_SetEP(ep);
|
||||
if (UDD_FifoByteCount(ep))
|
||||
UDD_ReleaseTX(ep);
|
||||
}
|
||||
|
@ -234,8 +234,10 @@ typedef struct
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#ifdef HID_ENABLED
|
||||
// IAD
|
||||
IADDescriptor iad; // Only needed on compound device
|
||||
#endif
|
||||
|
||||
// Control
|
||||
InterfaceDescriptor cif; //
|
||||
|
@ -16,8 +16,8 @@
|
||||
** SOFTWARE.
|
||||
*/
|
||||
|
||||
//#define CDC_ENABLED
|
||||
#define HID_ENABLED
|
||||
#define CDC_ENABLED
|
||||
//#define HID_ENABLED
|
||||
|
||||
|
||||
#ifdef CDC_ENABLED
|
||||
|
102
hardware/arduino/sam/cores/sam/arduino_due_cdc.inf
Normal file
102
hardware/arduino/sam/cores/sam/arduino_due_cdc.inf
Normal file
@ -0,0 +1,102 @@
|
||||
;
|
||||
; Windows USB CDC Driver Setup File for ARDUINO Due
|
||||
;
|
||||
; On Windows 7, right click to update driver software. It may take a while to
|
||||
; get this option, even if you cancel the auto driver search.
|
||||
; choose "browse my computer for driver software",
|
||||
; choose "let me pick from a list of device drivers on my computer",
|
||||
; Click "have disk" and browse to this .inf file
|
||||
; If there is a problem, right click and uninstall, checking delete driver software.
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
[Version]
|
||||
Signature="$Windows NT$"
|
||||
Class=Ports
|
||||
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
|
||||
Provider=%ARDUINO%
|
||||
LayoutFile=layout.inf
|
||||
|
||||
DriverVer= 03/09/2011,2.0.0.0
|
||||
|
||||
[Manufacturer]
|
||||
%ARDUINO%=DeviceList,NTamd64
|
||||
|
||||
[DestinationDirs]
|
||||
DefaultDestDir=12
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Windows 2000/XP/Vista32 Support
|
||||
;------------------------------------------------------------------------------
|
||||
[DriverInstall.nt]
|
||||
include=mdmcpq.inf
|
||||
CopyFiles=DriverCopyFiles.nt
|
||||
AddReg=DriverInstall.nt.AddReg
|
||||
|
||||
[DriverCopyFiles.nt]
|
||||
usbser.sys,,,0x20
|
||||
|
||||
[DriverInstall.nt.AddReg]
|
||||
HKR,,DevLoader,,*ntkern
|
||||
HKR,,NTMPDriver,,usbser.sys
|
||||
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
|
||||
|
||||
[DriverInstall.nt.Services]
|
||||
AddService=usbser, 0x00000002, DriverService.nt
|
||||
|
||||
[DriverService.nt]
|
||||
DisplayName=%USBtoSerialConverter%
|
||||
ServiceType=1
|
||||
StartType=3
|
||||
ErrorControl=1
|
||||
ServiceBinary=%12%\usbser.sys
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; Windows Vista64 Support
|
||||
;------------------------------------------------------------------------------
|
||||
|
||||
[DriverInstall.NTamd64]
|
||||
include=mdmcpq.inf
|
||||
CopyFiles=DriverCopyFiles.NTamd64
|
||||
AddReg=DriverInstall.NTamd64.AddReg
|
||||
|
||||
[DriverCopyFiles.NTamd64]
|
||||
usbser.sys,,,0x20
|
||||
|
||||
[DriverInstall.NTamd64.AddReg]
|
||||
HKR,,DevLoader,,*ntkern
|
||||
HKR,,NTMPDriver,,usbser.sys
|
||||
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"
|
||||
|
||||
[DriverInstall.NTamd64.Services]
|
||||
AddService=usbser, 0x00000002, DriverService.NTamd64
|
||||
|
||||
[DriverService.NTamd64]
|
||||
DisplayName=%USBtoSerialConverter%
|
||||
ServiceType=1
|
||||
StartType=3
|
||||
ErrorControl=1
|
||||
ServiceBinary=%12%\usbser.sys
|
||||
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; VID/PID Settings
|
||||
;------------------------------------------------------------------------------
|
||||
[SourceDisksFiles]
|
||||
[SourceDisksNames]
|
||||
[DeviceList]
|
||||
%USBtoSerialConverter%=DriverInstall, USB\VID_2341&PID_CAFF ; CDC
|
||||
%USBtoSerialConverter%=DriverInstall, USB\VID_2341&PID_DAFF&MI_00 ; HID + CDC
|
||||
|
||||
[DeviceList.NTamd64]
|
||||
%USBtoSerialConverter%=DriverInstall, USB\VID_2341&PID_CAFF ; CDC
|
||||
%USBtoSerialConverter%=DriverInstall, USB\VID_2341&PID_DAFF&MI_00 ; HID + CDC
|
||||
|
||||
;------------------------------------------------------------------------------
|
||||
; String Definitions
|
||||
;------------------------------------------------------------------------------
|
||||
[Strings]
|
||||
|
||||
ARDUINO="ARDUINO LLC" ; String value for the ARDUINO symbol
|
||||
USBtoSerialConverter="Arduino USB to Serial Converter" ; String value for the USBtoSerialConverter symbol
|
Binary file not shown.
@ -177,8 +177,8 @@ create_output:
|
||||
|
||||
$(addprefix $(OUTPUT_PATH)/,$(CPP_OBJ)): $(OUTPUT_PATH)/%.o: %.cpp
|
||||
# @"$(CC)" -c $(CPPFLAGS) $< -o $@
|
||||
# @"$(CXX)" -c $(CPPFLAGS) $< -o $@
|
||||
@"$(CXX)" -v -c $(CPPFLAGS) $< -o $@
|
||||
@"$(CXX)" -c $(CPPFLAGS) $< -o $@
|
||||
# @"$(CXX)" -v -c $(CPPFLAGS) $< -o $@
|
||||
|
||||
$(OUTPUT_BIN): $(addprefix $(OUTPUT_PATH)/, $(C_OBJ)) $(addprefix $(OUTPUT_PATH)/, $(CPP_OBJ)) $(addprefix $(OUTPUT_PATH)/, $(A_OBJ))
|
||||
@"$(CC)" $(LIB_PATH) $(LDFLAGS) -T"$(VARIANT_PATH)/linker_scripts/gcc/flash.ld" -Wl,-Map,$(OUTPUT_PATH)/$@.map -o $(OUTPUT_PATH)/$@.elf $^ $(LIBS)
|
||||
|
@ -30,7 +30,7 @@ int range = 5; // output range of X or Y movement; affects movement
|
||||
int responseDelay = 10; // response delay of the mouse, in ms
|
||||
|
||||
|
||||
void setup() {
|
||||
//void setup() {
|
||||
// initialize the buttons' inputs:
|
||||
/* pinMode(upButton, INPUT);
|
||||
pinMode(downButton, INPUT);
|
||||
@ -38,10 +38,10 @@ void setup() {
|
||||
pinMode(rightButton, INPUT);
|
||||
pinMode(mouseButton, INPUT);*/
|
||||
// initialize mouse control:
|
||||
Mouse.begin();
|
||||
}
|
||||
// Mouse.begin();
|
||||
//}
|
||||
|
||||
void loop() {
|
||||
//void loop() {
|
||||
// read the buttons:
|
||||
/* int upState = digitalRead(upButton);
|
||||
int downState = digitalRead(downButton);
|
||||
@ -72,10 +72,10 @@ void loop() {
|
||||
Mouse.release(MOUSE_LEFT);
|
||||
}
|
||||
}*/
|
||||
Mouse.move(10, 0, 0);
|
||||
/*Mouse.move(10, 0, 0);
|
||||
// a delay so the mouse doesn't move too fast:
|
||||
delay(1000);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
@ -100,3 +100,32 @@ void loop() {
|
||||
printf("loop...\r\n");
|
||||
}*/
|
||||
|
||||
|
||||
void setup() {
|
||||
// open the serial port:
|
||||
Serial.begin(57600);
|
||||
// initialize control over the keyboard:
|
||||
// Keyboard.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check for incoming serial data:
|
||||
//if (Serial.available() > 0) {
|
||||
// read incoming serial data:
|
||||
//char inChar = Serial.read();
|
||||
// Type the next ASCII value from what you received:
|
||||
// Keyboard.write(inChar+1);
|
||||
//Serial.print("toto\r\n");
|
||||
// check for incoming serial data:
|
||||
|
||||
if (Serial.available() > 0) {
|
||||
// read incoming serial data:
|
||||
char inChar = Serial.read();
|
||||
// Type the next ASCII value from what you received:
|
||||
Serial.print(inChar);
|
||||
Serial1.print(inChar);
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ extern uint8_t UDD_GetConfiguration(void) ;
|
||||
|
||||
|
||||
|
||||
extern void UDD_Send(uint32_t ep, const void* data, uint32_t len);
|
||||
extern uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len);
|
||||
extern void UDD_Send8(uint32_t ep, uint8_t data );
|
||||
extern uint8_t UDD_Recv8(uint32_t ep);
|
||||
extern void UDD_Recv(uint32_t ep, uint8_t* data, uint32_t len);
|
||||
|
@ -21,8 +21,9 @@
|
||||
|
||||
|
||||
#define MAX_ENDPOINTS 10
|
||||
|
||||
#define EP0 0
|
||||
#define EP0_SIZE 64
|
||||
#define EPX_SIZE 1024
|
||||
|
||||
#define EP_SINGLE_64 (0x32UL) // EP0
|
||||
#define EP_DOUBLE_64 (0x36UL) // Other endpoints
|
||||
|
@ -21,9 +21,10 @@
|
||||
|
||||
#if SAM3XA_SERIES
|
||||
|
||||
static void (*gpf_isr)(void) = (0UL);
|
||||
//#define TRACE_UOTGHS(x) x
|
||||
#define TRACE_UOTGHS(x)
|
||||
|
||||
//static volatile uint32_t ul_ep = (0UL);
|
||||
static void (*gpf_isr)(void) = (0UL);
|
||||
|
||||
static volatile uint32_t ul_send_fifo_ptr[MAX_ENDPOINTS];
|
||||
static volatile uint32_t ul_recv_fifo_ptr[MAX_ENDPOINTS];
|
||||
@ -94,19 +95,12 @@ uint32_t UDD_Init(void)
|
||||
|
||||
void UDD_Attach(void)
|
||||
{
|
||||
//USBCON = ((1<<USBE)|(1<<OTGPADE)); // start USB clock
|
||||
//UDIEN = (1<<EORSTE)|(1<<SOFE); // Enable interrupts for EOR (End of Reset) and SOF (start of frame)
|
||||
//UDCON = 0; // enable attach resistor
|
||||
|
||||
irqflags_t flags = cpu_irq_save();
|
||||
|
||||
//printf("=> UDD_Attach\r\n");
|
||||
|
||||
TRACE_UOTGHS(printf("=> UDD_Attach\r\n");)
|
||||
|
||||
otg_unfreeze_clock();
|
||||
|
||||
// This section of clock check can be improved with a chek of
|
||||
// USB clock source via sysclk()
|
||||
// Check USB clock because the source can be a PLL
|
||||
while (!Is_otg_clock_usable());
|
||||
|
||||
@ -115,52 +109,30 @@ void UDD_Attach(void)
|
||||
|
||||
// Enable USB line events
|
||||
udd_enable_reset_interrupt();
|
||||
//udd_enable_suspend_interrupt();
|
||||
//udd_enable_wake_up_interrupt();
|
||||
|
||||
|
||||
//////////////udd_enable_sof_interrupt();
|
||||
|
||||
|
||||
|
||||
// Reset following interupts flag
|
||||
//udd_ack_reset();
|
||||
//udd_ack_sof();
|
||||
|
||||
|
||||
// The first suspend interrupt must be forced
|
||||
// The first suspend interrupt is not detected else raise it
|
||||
//udd_raise_suspend();
|
||||
|
||||
//udd_ack_wake_up();
|
||||
//otg_freeze_clock();
|
||||
//udd_enable_sof_interrupt();
|
||||
|
||||
cpu_irq_restore(flags);
|
||||
}
|
||||
|
||||
void UDD_Detach(void)
|
||||
{
|
||||
//printf("=> UDD_Detach\r\n");
|
||||
TRACE_UOTGHS(printf("=> UDD_Detach\r\n");)
|
||||
UOTGHS->UOTGHS_DEVCTRL |= UOTGHS_DEVCTRL_DETACH;
|
||||
}
|
||||
|
||||
void UDD_InitEP( uint32_t ul_ep_nb, uint32_t ul_ep_cfg )
|
||||
{
|
||||
|
||||
ul_ep_nb = ul_ep_nb & 0xF; // EP range is 0..9, hence mask is 0xF.
|
||||
//printf("=> UDD_InitEP : init EP %d\r\n", ul_ep_nb);
|
||||
|
||||
// Reset EP
|
||||
//UOTGHS->UOTGHS_DEVEPT = (UOTGHS_DEVEPT_EPRST0 << ul_ep_nb);
|
||||
TRACE_UOTGHS(printf("=> UDD_InitEP : init EP %d\r\n", ul_ep_nb);)
|
||||
|
||||
// Configure EP
|
||||
UOTGHS->UOTGHS_DEVEPTCFG[ul_ep_nb] = ul_ep_cfg;
|
||||
// Allocate memory
|
||||
//udd_allocate_memory(ul_ep_nb);
|
||||
// Enable EP
|
||||
// UOTGHS->UOTGHS_DEVEPT |= (UOTGHS_DEVEPT_EPEN0 << ul_ep_nb);
|
||||
udd_enable_endpoint(ul_ep_nb);
|
||||
udd_enable_endpoint(ul_ep_nb);
|
||||
|
||||
if (!Is_udd_endpoint_configured(ul_ep_nb)) {
|
||||
//printf("=> UDD_InitEP : ############################## ERROR FAILED TO INIT EP %d\r\n", ul_ep_nb);
|
||||
TRACE_UOTGHS(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %d\r\n", ul_ep_nb);)
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,67 +141,28 @@ void UDD_InitEndpoints(const uint32_t* eps_table, const uint32_t ul_eps_table_si
|
||||
{
|
||||
uint32_t ul_ep_nb ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for (ul_ep_nb = 1; ul_ep_nb < ul_eps_table_size; ul_ep_nb++)
|
||||
|
||||
|
||||
/*void UDD_InitEndpoints(const uint32_t eps_table[])
|
||||
{
|
||||
uint32_t ul_ep_nb ;
|
||||
|
||||
|
||||
//printf("=> UDD_InitEndpoints : Taille tableau %d %d\r\n", sizeof(eps_table), (sizeof(eps_table) / sizeof(eps_table[0])));
|
||||
|
||||
for (ul_ep_nb = 1; ul_ep_nb < sizeof(eps_table) / sizeof(eps_table[0]); ul_ep_nb++)*/
|
||||
{
|
||||
// Reset Endpoint Fifos
|
||||
/* UOTGHS->UOTGHS_DEVEPTISR[ul_EP].UDPHS_EPTCLRSTA = UDPHS_EPTCLRSTA_TOGGLESQ | UDPHS_EPTCLRSTA_FRCESTALL;
|
||||
UOTGHS->UOTGHS_DEVEPT = 1<<ul_EP;
|
||||
|
||||
//UECONX = 1;
|
||||
//UECFG0X = pgm_read_byte(_initEndpoints+ul_EP);
|
||||
UOTGHS->UDPHS_EPT[ul_EP].UDPHS_EPTCFG = _initEndpoints[ul_EP];
|
||||
|
||||
while( (signed int)UDPHS_EPTCFG_EPT_MAPD != (signed int)((UOTGHS->UDPHS_EPT[ul_EP].UDPHS_EPTCFG) & (unsigned int)UDPHS_EPTCFG_EPT_MAPD) )
|
||||
;
|
||||
UOTGHS->UDPHS_EPT[ul_EP].UDPHS_EPTCTLENB = UDPHS_EPTCTLENB_EPT_ENABL;
|
||||
|
||||
// UECFG1X = EP_DOUBLE_64;
|
||||
}*/
|
||||
|
||||
//printf("=> UDD_InitEndpoints : init EP %d\r\n", ul_ep_nb);
|
||||
|
||||
|
||||
// Reset EP
|
||||
//UOTGHS->UOTGHS_DEVEPT = (UOTGHS_DEVEPT_EPRST0 << ul_ep_nb);
|
||||
// Configure EP
|
||||
UOTGHS->UOTGHS_DEVEPTCFG[ul_ep_nb] = eps_table[ul_ep_nb];
|
||||
// Allocate memory
|
||||
//udd_allocate_memory(ul_ep_nb);
|
||||
// Enable EP
|
||||
//UOTGHS->UOTGHS_DEVEPT |= (UOTGHS_DEVEPT_EPEN0 << ul_ep_nb);
|
||||
udd_enable_endpoint(ul_ep_nb);
|
||||
udd_enable_endpoint(ul_ep_nb);
|
||||
|
||||
if (!Is_udd_endpoint_configured(ul_ep_nb)) {
|
||||
//printf("=> UDD_InitEP : ############################## ERROR FAILED TO INIT EP %d\r\n", ul_ep_nb);
|
||||
TRACE_UOTGHS(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %d\r\n", ul_ep_nb);)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Wait until ready to accept IN packet.
|
||||
void UDD_WaitIN(void)
|
||||
{
|
||||
//while (!(UEINTX & (1<<TXINI)));
|
||||
while (!(UOTGHS->UOTGHS_DEVEPTISR[EP0] & UOTGHS_DEVEPTISR_TXINI))
|
||||
;
|
||||
}
|
||||
|
||||
void UDD_WaitOUT(void)
|
||||
{
|
||||
//while (!(UEINTX & (1<<RXOUTI)));
|
||||
while (!(UOTGHS->UOTGHS_DEVEPTISR[EP0] & UOTGHS_DEVEPTISR_RXOUTI))
|
||||
;
|
||||
}
|
||||
@ -237,15 +170,14 @@ void UDD_WaitOUT(void)
|
||||
// Send packet.
|
||||
void UDD_ClearIN(void)
|
||||
{
|
||||
//printf("=> UDD_ClearIN: sent %d bytes\r\n", ul_send_index);
|
||||
// UEINTX = ~(1<<TXINI);
|
||||
TRACE_UOTGHS(printf("=> UDD_ClearIN: sent %d bytes\r\n", ul_send_fifo_ptr[EP0]);)
|
||||
|
||||
UOTGHS->UOTGHS_DEVEPTICR[EP0] = UOTGHS_DEVEPTICR_TXINIC;
|
||||
ul_send_fifo_ptr[EP0] = 0;
|
||||
}
|
||||
|
||||
void UDD_ClearOUT(void)
|
||||
{
|
||||
// UEINTX = ~(1<<RXOUTI);
|
||||
UOTGHS->UOTGHS_DEVEPTICR[EP0] = UOTGHS_DEVEPTICR_RXOUTIC;
|
||||
ul_recv_fifo_ptr[EP0] = 0;
|
||||
}
|
||||
@ -254,8 +186,6 @@ void UDD_ClearOUT(void)
|
||||
// Return true if new IN FIFO buffer available.
|
||||
uint32_t UDD_WaitForINOrOUT(void)
|
||||
{
|
||||
//while (!(UEINTX & ((1<<TXINI)|(1<<RXOUTI))));
|
||||
//return (UEINTX & (1<<RXOUTI)) == 0;
|
||||
while (!(UOTGHS->UOTGHS_DEVEPTISR[EP0] & (UOTGHS_DEVEPTISR_TXINI | UOTGHS_DEVEPTISR_RXOUTI)))
|
||||
;
|
||||
return ((UOTGHS->UOTGHS_DEVEPTISR[EP0] & UOTGHS_DEVEPTISR_RXOUTI) == 0);
|
||||
@ -268,29 +198,61 @@ uint32_t UDD_ReceivedSetupInt(void)
|
||||
|
||||
void UDD_ClearSetupInt(void)
|
||||
{
|
||||
//UEINTX = ~((1<<RXSTPI) | (1<<RXOUTI) | (1<<TXINI));
|
||||
//UOTGHS->UOTGHS_DEVEPTICR[ul_ep] = (UOTGHS_DEVEPTICR_RXSTPIC | UOTGHS_DEVEPTICR_RXOUTIC | UOTGHS_DEVEPTICR_TXINIC);
|
||||
UOTGHS->UOTGHS_DEVEPTICR[EP0] = (UOTGHS_DEVEPTICR_RXSTPIC);
|
||||
}
|
||||
|
||||
void UDD_Send(uint32_t ep, const void* data, uint32_t len)
|
||||
uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len)
|
||||
{
|
||||
const uint8_t *ptr_src = data;
|
||||
uint8_t *ptr_dest = (uint8_t *) &udd_get_endpoint_fifo_access8(ep);
|
||||
uint32_t i;
|
||||
|
||||
//printf("=> UDD_Send : ep=%d ptr_dest=%d len=%d\r\n", ep, ul_send_fifo_ptr[ep], len);
|
||||
TRACE_UOTGHS(printf("=> UDD_Send (1): ep=%d ul_send_fifo_ptr=%d len=%d\r\n", ep, ul_send_fifo_ptr[ep], len);)
|
||||
|
||||
if (ep == EP0)
|
||||
{
|
||||
if (ul_send_fifo_ptr[ep] + len > EP0_SIZE)
|
||||
len = EP0_SIZE - ul_send_fifo_ptr[ep];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ul_send_fifo_ptr[ep] + len > EPX_SIZE)
|
||||
len = EPX_SIZE - ul_send_fifo_ptr[ep];
|
||||
}
|
||||
|
||||
for (i = 0, ptr_dest += ul_send_fifo_ptr[ep]; i < len; ++i)
|
||||
*ptr_dest++ = *ptr_src++;
|
||||
|
||||
ul_send_fifo_ptr[ep] += i;
|
||||
|
||||
|
||||
if (ep == EP0)
|
||||
{
|
||||
TRACE_UOTGHS(printf("=> UDD_Send (2): ep=%d ptr_dest=%d maxlen=%d\r\n", ep, ul_send_fifo_ptr[ep], EP0_SIZE);)
|
||||
if (ul_send_fifo_ptr[ep] == EP0_SIZE)
|
||||
{
|
||||
UDD_ClearIN(); // Fifo is full, release this packet
|
||||
UDD_WaitIN(); // Wait for new FIFO buffer to be ready
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ul_send_fifo_ptr[ep] == EPX_SIZE)
|
||||
{
|
||||
UDD_ClearIN(); // Fifo is full, release this packet
|
||||
UDD_WaitIN(); // Wait for new FIFO buffer to be ready
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void UDD_Send8(uint32_t ep, uint8_t data )
|
||||
{
|
||||
uint8_t *ptr_dest = (uint8_t *) &udd_get_endpoint_fifo_access8(ep);
|
||||
//printf("=> UDD_Send8 : ul_send_index=%d data=0x%x\r\n", ul_send_index, data);
|
||||
|
||||
TRACE_UOTGHS(printf("=> UDD_Send8 : ul_send_fifo_ptr=%d data=0x%x\r\n", ul_send_fifo_ptr[ep], data);)
|
||||
|
||||
ptr_dest[ul_send_fifo_ptr[ep]] = data;
|
||||
ul_send_fifo_ptr[ep] += 1;
|
||||
}
|
||||
@ -299,7 +261,9 @@ uint8_t UDD_Recv8(uint32_t ep)
|
||||
{
|
||||
uint8_t *ptr_dest = (uint8_t *) &udd_get_endpoint_fifo_access8(ep);
|
||||
uint8_t data = ptr_dest[ul_recv_fifo_ptr[ep]];
|
||||
////printf("=> UDD_Recv8 : ul_recv_index=%d\r\n", ul_recv_index);
|
||||
|
||||
TRACE_UOTGHS(printf("=> UDD_Recv8 : ul_recv_fifo_ptr=%d\r\n", ul_recv_fifo_ptr[ep]);)
|
||||
|
||||
ul_recv_fifo_ptr[ep] += 1;
|
||||
return data;
|
||||
}
|
||||
@ -318,7 +282,6 @@ void UDD_Recv(uint32_t ep, uint8_t* data, uint32_t len)
|
||||
|
||||
void UDD_Stall(void)
|
||||
{
|
||||
//UECONX = (1<<STALLRQ) | (1<<EPEN);
|
||||
UOTGHS->UOTGHS_DEVEPT = (UOTGHS_DEVEPT_EPEN0 << EP0);
|
||||
UOTGHS->UOTGHS_DEVEPTIER[EP0] = UOTGHS_DEVEPTIER_STALLRQS;
|
||||
}
|
||||
@ -331,12 +294,7 @@ uint32_t UDD_FifoByteCount(uint32_t ep)
|
||||
|
||||
void UDD_ReleaseRX(uint32_t ep)
|
||||
{
|
||||
/* UEINTX = 0x6B; // FIFOCON=0 NAKINI=1 RWAL=1 NAKOUTI=0 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=1
|
||||
clear fifocon = send and switch bank
|
||||
nakouti a clearer
|
||||
rxouti/killbank a clearer*/
|
||||
|
||||
//puts("=> UDD_ReleaseRX\r\n");
|
||||
TRACE_UOTGHS(puts("=> UDD_ReleaseRX\r\n");)
|
||||
UOTGHS->UOTGHS_DEVEPTICR[ep] = (UOTGHS_DEVEPTICR_NAKOUTIC | UOTGHS_DEVEPTICR_RXOUTIC);
|
||||
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
|
||||
ul_recv_fifo_ptr[ep] = 0;
|
||||
@ -344,13 +302,7 @@ void UDD_ReleaseRX(uint32_t ep)
|
||||
|
||||
void UDD_ReleaseTX(uint32_t ep)
|
||||
{
|
||||
/* UEINTX = 0x3A; // FIFOCON=0 NAKINI=0 RWAL=1 NAKOUTI=1 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=0
|
||||
clear fifocon = send and switch bank
|
||||
nakini a clearer
|
||||
rxouti/killbank a clearer
|
||||
txini a clearer*/
|
||||
|
||||
//puts("=> UDD_ReleaseTX\r\n");
|
||||
TRACE_UOTGHS(printf("=> UDD_ReleaseTX ep=%d\r\n", ep);)
|
||||
UOTGHS->UOTGHS_DEVEPTICR[ep] = (UOTGHS_DEVEPTICR_NAKINIC | UOTGHS_DEVEPTICR_RXOUTIC | UOTGHS_DEVEPTICR_TXINIC);
|
||||
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
|
||||
ul_send_fifo_ptr[ep] = 0;
|
||||
@ -364,7 +316,8 @@ uint32_t UDD_ReadWriteAllowed(uint32_t ep)
|
||||
|
||||
void UDD_SetAddress(uint32_t addr)
|
||||
{
|
||||
//printf("=> UDD_SetAddress : setting address to %d\r\n", addr);
|
||||
TRACE_UOTGHS(printf("=> UDD_SetAddress : setting address to %d\r\n", addr);)
|
||||
|
||||
udd_configure_address(addr);
|
||||
udd_enable_address();
|
||||
}
|
||||
|
Binary file not shown.
@ -19,12 +19,59 @@ pio.o:
|
||||
00000000 T PIO_SetPeripheral
|
||||
|
||||
pmc.o:
|
||||
00000000 T PMC_DisablePeripheral
|
||||
00000000 T PMC_EnablePeripheral
|
||||
00000000 T PMC_IsPeripheralEnabled
|
||||
00000000 T pmc_clr_fast_startup_input
|
||||
00000000 T pmc_disable_all_pck
|
||||
00000000 T pmc_disable_all_periph_clk
|
||||
00000000 T pmc_disable_interrupt
|
||||
00000000 T pmc_disable_pck
|
||||
00000000 T pmc_disable_periph_clk
|
||||
00000000 T pmc_disable_pllack
|
||||
00000000 T pmc_disable_udpck
|
||||
00000000 T pmc_disable_upll_clock
|
||||
00000000 T pmc_enable_all_pck
|
||||
00000000 T pmc_enable_all_periph_clk
|
||||
00000000 T pmc_enable_backupmode
|
||||
00000000 T pmc_enable_interrupt
|
||||
00000000 T pmc_enable_pck
|
||||
00000000 T pmc_enable_periph_clk
|
||||
00000000 T pmc_enable_pllack
|
||||
00000000 T pmc_enable_sleepmode
|
||||
00000000 T pmc_enable_udpck
|
||||
00000000 T pmc_enable_upll_clock
|
||||
00000000 T pmc_enable_waitmode
|
||||
00000000 T pmc_get_interrupt_mask
|
||||
00000000 T pmc_get_status
|
||||
00000000 T pmc_get_writeprotect_status
|
||||
00000000 T pmc_is_locked_pllack
|
||||
00000000 T pmc_is_locked_upll
|
||||
00000000 T pmc_is_pck_enabled
|
||||
00000000 T pmc_is_periph_clk_enabled
|
||||
00000000 T pmc_mck_set_prescaler
|
||||
00000000 T pmc_mck_set_source
|
||||
00000000 T pmc_osc_disable_fastrc
|
||||
00000000 T pmc_osc_disable_xtal
|
||||
00000000 T pmc_osc_enable_fastrc
|
||||
00000000 T pmc_osc_is_ready_32kxtal
|
||||
00000000 T pmc_osc_is_ready_mainck
|
||||
00000000 T pmc_pck_set_prescaler
|
||||
00000000 T pmc_pck_set_source
|
||||
00000000 T pmc_set_fast_startup_input
|
||||
00000000 T pmc_set_writeprotect
|
||||
00000000 T pmc_switch_mainck_to_fastrc
|
||||
00000000 T pmc_switch_mainck_to_xtal
|
||||
00000000 T pmc_switch_mck_to_mainck
|
||||
00000000 T pmc_switch_mck_to_pllack
|
||||
00000000 T pmc_switch_mck_to_sclk
|
||||
00000000 T pmc_switch_mck_to_upllck
|
||||
00000000 T pmc_switch_pck_to_mainck
|
||||
00000000 T pmc_switch_pck_to_pllack
|
||||
00000000 T pmc_switch_pck_to_sclk
|
||||
00000000 T pmc_switch_pck_to_upllck
|
||||
00000000 T pmc_switch_sclk_to_32kxtal
|
||||
00000000 T pmc_switch_udpck_to_pllack
|
||||
00000000 T pmc_switch_udpck_to_upllck
|
||||
|
||||
pwmc.o:
|
||||
00000000 r C.9.6937
|
||||
00000000 t FindClockConfiguration
|
||||
00000000 T PWMC_ConfigureChannel
|
||||
00000000 T PWMC_ConfigureChannelExt
|
||||
@ -52,14 +99,14 @@ pwmc.o:
|
||||
00000000 T PWMC_SetSyncChannelUpdateUnlock
|
||||
00000000 T PWMC_WriteBuffer
|
||||
U __assert_func
|
||||
00000000 r __func__.5717
|
||||
00000000 r __func__.5728
|
||||
00000000 r __func__.5743
|
||||
00000000 r __func__.5754
|
||||
00000000 r __func__.5765
|
||||
00000000 r __func__.5772
|
||||
00000000 r __func__.5856
|
||||
00000000 r __func__.5862
|
||||
00000000 r __func__.3192
|
||||
00000000 r __func__.3203
|
||||
00000000 r __func__.3218
|
||||
00000000 r __func__.3229
|
||||
00000000 r __func__.3240
|
||||
00000000 r __func__.3247
|
||||
00000000 r __func__.3331
|
||||
00000000 r __func__.3337
|
||||
|
||||
rtc.o:
|
||||
00000000 T RTC_ClearSCCR
|
||||
@ -75,9 +122,9 @@ rtc.o:
|
||||
00000000 T RTC_SetTime
|
||||
00000000 T RTC_SetTimeAlarm
|
||||
U __assert_func
|
||||
00000000 r __func__.5714
|
||||
00000000 r __func__.5723
|
||||
00000000 r __func__.5728
|
||||
00000000 r __func__.3189
|
||||
00000000 r __func__.3198
|
||||
00000000 r __func__.3203
|
||||
|
||||
rtt.o:
|
||||
00000000 T RTT_EnableIT
|
||||
@ -86,11 +133,10 @@ rtt.o:
|
||||
00000000 T RTT_SetAlarm
|
||||
00000000 T RTT_SetPrescaler
|
||||
U __assert_func
|
||||
00000000 r __func__.5721
|
||||
00000000 r __func__.5729
|
||||
00000000 r __func__.3196
|
||||
00000000 r __func__.3204
|
||||
|
||||
spi.o:
|
||||
U PMC_EnablePeripheral
|
||||
00000000 T SPI_Configure
|
||||
00000000 T SPI_ConfigureNPCS
|
||||
00000000 T SPI_Disable
|
||||
@ -101,6 +147,7 @@ spi.o:
|
||||
00000000 T SPI_IsFinished
|
||||
00000000 T SPI_Read
|
||||
00000000 T SPI_Write
|
||||
U pmc_enable_periph_clk
|
||||
|
||||
tc.o:
|
||||
00000000 T TC_Configure
|
||||
@ -108,9 +155,9 @@ tc.o:
|
||||
00000000 T TC_Start
|
||||
00000000 T TC_Stop
|
||||
U __assert_func
|
||||
00000000 r __func__.5716
|
||||
00000000 r __func__.5722
|
||||
00000000 r __func__.5728
|
||||
00000000 r __func__.3191
|
||||
00000000 r __func__.3197
|
||||
00000000 r __func__.3203
|
||||
|
||||
timetick.o:
|
||||
00000000 T GetTickCount
|
||||
@ -137,18 +184,18 @@ twi.o:
|
||||
00000000 T TWI_TransferComplete
|
||||
00000000 T TWI_WriteByte
|
||||
U __assert_func
|
||||
00000000 r __func__.6089
|
||||
00000000 r __func__.6104
|
||||
00000000 r __func__.6108
|
||||
00000000 r __func__.6115
|
||||
00000000 r __func__.6119
|
||||
00000000 r __func__.6124
|
||||
00000000 r __func__.6132
|
||||
00000000 r __func__.6146
|
||||
00000000 r __func__.6151
|
||||
00000000 r __func__.6155
|
||||
00000000 r __func__.6160
|
||||
00000000 r __func__.6164
|
||||
00000000 r __func__.3556
|
||||
00000000 r __func__.3571
|
||||
00000000 r __func__.3575
|
||||
00000000 r __func__.3582
|
||||
00000000 r __func__.3586
|
||||
00000000 r __func__.3591
|
||||
00000000 r __func__.3599
|
||||
00000000 r __func__.3613
|
||||
00000000 r __func__.3618
|
||||
00000000 r __func__.3622
|
||||
00000000 r __func__.3627
|
||||
00000000 r __func__.3631
|
||||
|
||||
usart.o:
|
||||
00000000 T USART_Configure
|
||||
@ -167,7 +214,7 @@ usart.o:
|
||||
00000000 T USART_Write
|
||||
00000000 T USART_WriteBuffer
|
||||
U __assert_func
|
||||
00000000 r __func__.6010
|
||||
00000000 r __func__.3477
|
||||
|
||||
wdt.o:
|
||||
00000000 T WDT_Disable
|
||||
@ -296,3 +343,39 @@ udp.o:
|
||||
udphs.o:
|
||||
|
||||
uotghs.o:
|
||||
00000000 T UDD_Attach
|
||||
00000000 T UDD_ClearIN
|
||||
00000000 T UDD_ClearOUT
|
||||
00000000 T UDD_ClearSetupInt
|
||||
00000000 T UDD_Detach
|
||||
00000000 T UDD_FifoByteCount
|
||||
00000000 T UDD_GetFrameNumber
|
||||
00000000 T UDD_Init
|
||||
00000000 T UDD_InitEP
|
||||
00000000 T UDD_InitEndpoints
|
||||
00000000 T UDD_ReadWriteAllowed
|
||||
00000000 T UDD_ReceivedSetupInt
|
||||
00000000 T UDD_Recv
|
||||
00000000 T UDD_Recv8
|
||||
00000000 T UDD_ReleaseRX
|
||||
00000000 T UDD_ReleaseTX
|
||||
00000000 T UDD_Send
|
||||
00000000 T UDD_Send8
|
||||
00000000 T UDD_SetAddress
|
||||
00000000 T UDD_SetStack
|
||||
00000000 T UDD_Stall
|
||||
00000000 T UDD_WaitForINOrOUT
|
||||
00000000 T UDD_WaitIN
|
||||
00000000 T UDD_WaitOUT
|
||||
00000000 T UOTGHS_Handler
|
||||
U g_interrupt_enabled
|
||||
00000000 b gpf_isr
|
||||
U pmc_enable_periph_clk
|
||||
U pmc_enable_udpck
|
||||
U pmc_enable_upll_clock
|
||||
U pmc_switch_udpck_to_upllck
|
||||
00000000 b ul_recv_fifo_ptr
|
||||
00000000 b ul_send_fifo_ptr
|
||||
|
||||
interrupt_sam_nvic.o:
|
||||
00000000 D g_interrupt_enabled
|
||||
|
Loading…
x
Reference in New Issue
Block a user