diff --git a/hardware/arduino/sam/cores/arduino/Arduino.h b/hardware/arduino/sam/cores/arduino/Arduino.h index 00b6715b1..ec4274ccb 100644 --- a/hardware/arduino/sam/cores/arduino/Arduino.h +++ b/hardware/arduino/sam/cores/arduino/Arduino.h @@ -194,6 +194,7 @@ extern const PinDescription g_APinDescription[] ; #include "HardwareSerial.h" #include "wiring_pulse.h" +// USB Host #include "Usb.h" #endif // __cplusplus @@ -201,16 +202,13 @@ extern const PinDescription g_APinDescription[] ; // Include board variant #include "variant.h" -#if defined USBCON - #define USB_VID 0x2341 // arduino LLC vid - - #define USB_PID_LEONARDO 0x0034 - #define USB_PID_MICRO 0x0035 - #define USB_PID_DUE 0x003E - - #include "USB/USBDesc.h" - #include "USB/USBCore.h" - #include "USB/USBAPI.h" -#endif // if defined USBCON +// USB Device +#define USB_VID 0x2341 // arduino LLC vid +#define USB_PID_LEONARDO 0x0034 +#define USB_PID_MICRO 0x0035 +#define USB_PID_DUE 0x003E +#include "USB/USBDesc.h" +#include "USB/USBCore.h" +#include "USB/USBAPI.h" #endif // Arduino_h diff --git a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp index 8992a2e63..5c451a5c0 100644 --- a/hardware/arduino/sam/cores/arduino/USB/CDC.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/CDC.cpp @@ -17,8 +17,6 @@ #include "Arduino.h" #include "USBAPI.h" -#if defined(USBCON) - #ifdef CDC_ENABLED #define CDC_SERIAL_BUFFER_SIZE 64 @@ -252,4 +250,3 @@ Serial_::operator bool() Serial_ Serial; #endif -#endif /* if defined(USBCON) */ diff --git a/hardware/arduino/sam/cores/arduino/USB/HID.cpp b/hardware/arduino/sam/cores/arduino/USB/HID.cpp index a02dbec8c..2a4e73b8c 100644 --- a/hardware/arduino/sam/cores/arduino/USB/HID.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/HID.cpp @@ -16,7 +16,6 @@ #include "Arduino.h" -#if defined(USBCON) #ifdef HID_ENABLED //#define RAWHID_ENABLED @@ -509,5 +508,3 @@ size_t Keyboard_::write(uint8_t c) } #endif - -#endif /* if defined(USBCON) */ diff --git a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h index b65d20bb8..592d3a0b1 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBAPI.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBAPI.h @@ -19,7 +19,7 @@ #ifndef __USBAPI__ #define __USBAPI__ -#if defined __cplusplus && defined USBCON +#if defined __cplusplus #include "RingBuffer.h" @@ -214,5 +214,4 @@ void USBD_Flush(uint32_t ep); uint32_t USBD_Connected(void); #endif - -#endif /* if defined USBCON */ +#endif diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 8a9d2410a..51bc6b92f 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -1,5 +1,3 @@ -#ifdef USBCON - /* Copyright (c) 2010, Peter Barrett ** ** Permission to use, copy, modify, and/or distribute this software for @@ -20,8 +18,8 @@ #include "USBAPI.h" #include -//#define TRACE_CORE(x) x -#define TRACE_CORE(x) +#define TRACE_CORE(x) x +//#define TRACE_CORE(x) static const uint32_t EndPoints[] = { @@ -212,14 +210,14 @@ int USBD_SendControl(uint8_t flags, const void* d, uint32_t len) uint32_t sent = 0; uint32_t pos = 0; - TRACE_CORE(printf("=> USBD_SendControl TOTAL len=%d\r\n", len);) + TRACE_CORE(printf("=> USBD_SendControl TOTAL len=%lu\r\n", len);) if (_cmark < _cend) { while (len > 0) { sent = UDD_Send(EP0, data + pos, len); - TRACE_CORE(printf("=> USBD_SendControl sent=%d\r\n", sent);) + TRACE_CORE(printf("=> USBD_SendControl sent=%lu\r\n", sent);) pos += sent; len -= sent; } @@ -540,7 +538,7 @@ uint32_t USBD_Connected(void) //======================================================================= //======================================================================= -//USB_ USB; +USB_ USB; USB_::USB_() { @@ -589,5 +587,3 @@ bool USB_::configured() void USB_::poll() { } - -#endif // USBCON diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.h b/hardware/arduino/sam/cores/arduino/USB/USBCore.h index 68b18ff65..d4dac653e 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.h @@ -301,5 +301,4 @@ _Pragma("pack()") #define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 } #define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 } - #endif diff --git a/hardware/arduino/sam/cores/arduino/USB/USBDesc.h b/hardware/arduino/sam/cores/arduino/USB/USBDesc.h index fb5895adf..275d4862e 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBDesc.h +++ b/hardware/arduino/sam/cores/arduino/USB/USBDesc.h @@ -60,4 +60,3 @@ #define IMANUFACTURER 1 #define IPRODUCT 2 - diff --git a/hardware/arduino/sam/cores/arduino/main.cpp b/hardware/arduino/sam/cores/arduino/main.cpp index 818679f18..69f25f2a5 100644 --- a/hardware/arduino/sam/cores/arduino/main.cpp +++ b/hardware/arduino/sam/cores/arduino/main.cpp @@ -39,9 +39,7 @@ int main( void ) delay(1); -#if defined(USBCON) - //USB.attach(); -#endif + USB.attach(); setup(); @@ -50,5 +48,5 @@ int main( void ) loop(); } -// return 0 ; + return 0; } diff --git a/hardware/arduino/sam/cores/arduino/validation_usb_device/build_gcc/debug.mk b/hardware/arduino/sam/cores/arduino/validation_usb_device/build_gcc/debug.mk index d0716744a..a3cc2337a 100644 --- a/hardware/arduino/sam/cores/arduino/validation_usb_device/build_gcc/debug.mk +++ b/hardware/arduino/sam/cores/arduino/validation_usb_device/build_gcc/debug.mk @@ -8,7 +8,7 @@ # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public diff --git a/hardware/arduino/sam/cores/arduino/validation_usb_device/build_gcc/test_usb_device.mk b/hardware/arduino/sam/cores/arduino/validation_usb_device/build_gcc/test_usb_device.mk index 1fdd9b12c..336bbc609 100644 --- a/hardware/arduino/sam/cores/arduino/validation_usb_device/build_gcc/test_usb_device.mk +++ b/hardware/arduino/sam/cores/arduino/validation_usb_device/build_gcc/test_usb_device.mk @@ -78,6 +78,7 @@ CMSIS_CHIP_PATH=$(CMSIS_ROOT_PATH)/Device/ATMEL/$(CHIP_SERIE) ARDUINO_CORE_PATH=$(PROJECT_BASE_PATH)/.. ARDUINO_USB_PATH=$(PROJECT_BASE_PATH)/../USB +ARDUINO_USB_HOST_PATH=$(PROJECT_BASE_PATH)/../../../system/USBHost # Output directories OUTPUT_PATH = debug_$(VARIANT) @@ -99,7 +100,8 @@ INCLUDES += -I$(SYSTEM_PATH)/libsam INCLUDES += -I$(CMSIS_ARM_PATH) INCLUDES += -I$(CMSIS_ATMEL_PATH) INCLUDES += -I$(CMSIS_CHIP_PATH) -INCLUDES += -I$(PROJECT_BASE_PATH)/../USB +INCLUDES += -I$(ARDUINO_USB_PATH) +INCLUDES += -I$(ARDUINO_USB_HOST_PATH) #------------------------------------------------------------------------------- ifdef DEBUG diff --git a/hardware/arduino/sam/cores/arduino/validation_usb_device/test_usb_device.cpp b/hardware/arduino/sam/cores/arduino/validation_usb_device/test_usb_device.cpp index 1b8fab7d5..e6c07c7e1 100644 --- a/hardware/arduino/sam/cores/arduino/validation_usb_device/test_usb_device.cpp +++ b/hardware/arduino/sam/cores/arduino/validation_usb_device/test_usb_device.cpp @@ -16,8 +16,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#if defined(USBCON) - #include "variant.h" #include @@ -36,7 +34,6 @@ void loop() { Serial.print(inChar); Serial1.print(inChar); } + delay(10); } - -#endif diff --git a/hardware/arduino/sam/cores/arduino/validation_usb_host/test_usb_host.cpp b/hardware/arduino/sam/cores/arduino/validation_usb_host/test_usb_host.cpp index 60583671b..a836acfd5 100644 --- a/hardware/arduino/sam/cores/arduino/validation_usb_host/test_usb_host.cpp +++ b/hardware/arduino/sam/cores/arduino/validation_usb_host/test_usb_host.cpp @@ -2,58 +2,49 @@ #include #include -class KbdRptParser : public KeyboardReportParser +class MouseRptParser : public MouseReportParser { - void PrintKey(uint8_t mod, uint8_t key); - protected: - virtual void OnKeyDown (uint8_t mod, uint8_t key); - virtual void OnKeyUp (uint8_t mod, uint8_t key); - virtual void OnKeyPressed(uint8_t key); + virtual void OnMouseMove (MOUSEINFO *mi); + virtual void OnLeftButtonUp (MOUSEINFO *mi); + virtual void OnLeftButtonDown (MOUSEINFO *mi); + virtual void OnRightButtonUp (MOUSEINFO *mi); + virtual void OnRightButtonDown (MOUSEINFO *mi); + virtual void OnMiddleButtonUp (MOUSEINFO *mi); + virtual void OnMiddleButtonDown (MOUSEINFO *mi); }; - -void KbdRptParser::PrintKey(uint8_t m, uint8_t key) +void MouseRptParser::OnMouseMove(MOUSEINFO *mi) { - MODIFIERKEYS mod; - - *((uint8_t*)&mod) = m; - printf((mod.bmLeftCtrl == 1) ? "C" : " "); - printf((mod.bmLeftShift == 1) ? "S" : " "); - printf((mod.bmLeftAlt == 1) ? "A" : " "); - printf((mod.bmLeftGUI == 1) ? "G" : " "); - - printf("<%c>", key); - - printf((mod.bmRightCtrl == 1) ? "C" : " "); - printf((mod.bmRightShift == 1) ? "S" : " "); - printf((mod.bmRightAlt == 1) ? "A" : " "); - printf((mod.bmRightGUI == 1) ? "G" : " "); + printf("Pos={%d,%d}\r\n", mi->dX, mi->dY); }; - -void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) +void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi) { - printf("DN "); - PrintKey(mod, key); - uint8_t c = OemToAscii(mod, key); - - if (c) - OnKeyPressed(c); -} - -void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) + printf("L Butt Up\r\n"); +}; +void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi) { - printf("UP "); - PrintKey(mod, key); -} - -void KbdRptParser::OnKeyPressed(uint8_t key) + printf("L Butt Dn\r\n"); +}; +void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi) { - printf("ASCII: %c", key); + printf("R Butt Up\r\n"); +}; +void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi) +{ + printf("R Butt Dn\r\n"); +}; +void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi) +{ + printf("M Butt Up\r\n"); +}; +void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi) +{ + printf("M Butt Dn\r\n"); }; USBHost Usb; -HIDBoot Kbd(&Usb); -KbdRptParser Prs; +HIDBoot HostMouse(&Usb); +MouseRptParser Prs; void setup() { @@ -61,7 +52,7 @@ void setup() printf("\r\nProgram started:\r\n"); delay(200); - Kbd.SetReportParser(0, (HIDReportParser*)&Prs); + HostMouse.SetReportParser(0,(HIDReportParser*)&Prs); } void loop() diff --git a/hardware/arduino/sam/system/libsam/source/uotghs_device.c b/hardware/arduino/sam/system/libsam/source/uotghs_device.c index 2f8bb881b..cf439a5d0 100644 --- a/hardware/arduino/sam/system/libsam/source/uotghs_device.c +++ b/hardware/arduino/sam/system/libsam/source/uotghs_device.c @@ -32,8 +32,8 @@ #if SAM3XA_SERIES -//#define TRACE_UOTGHS(x) x -#define TRACE_UOTGHS(x) +#define TRACE_UOTGHS_DEVICE(x) x +//#define TRACE_UOTGHS_DEVICE(x) extern void (*gpf_isr)(void); @@ -83,8 +83,9 @@ uint32_t UDD_Init(void) //while (!Is_otg_clock_usable()) // ; + // Enable High Speed udd_low_speed_disable(); - udd_high_speed_disable(); + udd_high_speed_enable(); //otg_ack_vbus_transition(); // Force Vbus interrupt in case of Vbus always with a high level @@ -102,7 +103,7 @@ void UDD_Attach(void) { irqflags_t flags = cpu_irq_save(); - TRACE_UOTGHS(printf("=> UDD_Attach\r\n");) + TRACE_UOTGHS_DEVICE(printf("=> UDD_Attach\r\n");) otg_unfreeze_clock(); @@ -121,7 +122,7 @@ void UDD_Attach(void) void UDD_Detach(void) { - TRACE_UOTGHS(printf("=> UDD_Detach\r\n");) + TRACE_UOTGHS_DEVICE(printf("=> UDD_Detach\r\n");) UOTGHS->UOTGHS_DEVCTRL |= UOTGHS_DEVCTRL_DETACH; } @@ -129,7 +130,7 @@ 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. - TRACE_UOTGHS(printf("=> UDD_InitEP : init EP %d\r\n", ul_ep_nb);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_InitEP : init EP %lu\r\n", ul_ep_nb);) // Configure EP UOTGHS->UOTGHS_DEVEPTCFG[ul_ep_nb] = ul_ep_cfg; @@ -137,7 +138,7 @@ void UDD_InitEP( uint32_t ul_ep_nb, uint32_t ul_ep_cfg ) udd_enable_endpoint(ul_ep_nb); if (!Is_udd_endpoint_configured(ul_ep_nb)) { - TRACE_UOTGHS(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %d\r\n", ul_ep_nb);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %lu\r\n", ul_ep_nb);) } } @@ -154,7 +155,7 @@ void UDD_InitEndpoints(const uint32_t* eps_table, const uint32_t ul_eps_table_si udd_enable_endpoint(ul_ep_nb); if (!Is_udd_endpoint_configured(ul_ep_nb)) { - TRACE_UOTGHS(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %d\r\n", ul_ep_nb);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_InitEP : ERROR FAILED TO INIT EP %lu\r\n", ul_ep_nb);) } } } @@ -175,7 +176,7 @@ void UDD_WaitOUT(void) // Send packet. void UDD_ClearIN(void) { - TRACE_UOTGHS(printf("=> UDD_ClearIN: sent %d bytes\r\n", ul_send_fifo_ptr[EP0]);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_ClearIN: sent %lu bytes\r\n", ul_send_fifo_ptr[EP0]);) UOTGHS->UOTGHS_DEVEPTICR[EP0] = UOTGHS_DEVEPTICR_TXINIC; ul_send_fifo_ptr[EP0] = 0; @@ -212,7 +213,7 @@ uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len) uint8_t *ptr_dest = (uint8_t *) &udd_get_endpoint_fifo_access8(ep); uint32_t i; - TRACE_UOTGHS(printf("=> UDD_Send (1): ep=%d ul_send_fifo_ptr=%d len=%d\r\n", ep, ul_send_fifo_ptr[ep], len);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_Send (1): ep=%lu ul_send_fifo_ptr=%lu len=%lu\r\n", ep, ul_send_fifo_ptr[ep], len);) if (ep == EP0) { @@ -233,7 +234,7 @@ uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len) 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);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_Send (2): ep=%lu ptr_dest=%lu 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 @@ -256,7 +257,7 @@ void UDD_Send8(uint32_t ep, uint8_t data ) { uint8_t *ptr_dest = (uint8_t *) &udd_get_endpoint_fifo_access8(ep); - TRACE_UOTGHS(printf("=> UDD_Send8 : ul_send_fifo_ptr=%d data=0x%x\r\n", ul_send_fifo_ptr[ep], data);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_Send8 : ul_send_fifo_ptr=%lu 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; @@ -267,7 +268,7 @@ 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]]; - TRACE_UOTGHS(printf("=> UDD_Recv8 : ul_recv_fifo_ptr=%d\r\n", ul_recv_fifo_ptr[ep]);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_Recv8 : ul_recv_fifo_ptr=%lu\r\n", ul_recv_fifo_ptr[ep]);) ul_recv_fifo_ptr[ep] += 1; return data; @@ -299,7 +300,7 @@ uint32_t UDD_FifoByteCount(uint32_t ep) void UDD_ReleaseRX(uint32_t ep) { - TRACE_UOTGHS(puts("=> UDD_ReleaseRX\r\n");) + TRACE_UOTGHS_DEVICE(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; @@ -307,7 +308,7 @@ void UDD_ReleaseRX(uint32_t ep) void UDD_ReleaseTX(uint32_t ep) { - TRACE_UOTGHS(printf("=> UDD_ReleaseTX ep=%d\r\n", ep);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_ReleaseTX ep=%lu\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; @@ -321,7 +322,7 @@ uint32_t UDD_ReadWriteAllowed(uint32_t ep) void UDD_SetAddress(uint32_t addr) { - TRACE_UOTGHS(printf("=> UDD_SetAddress : setting address to %d\r\n", addr);) + TRACE_UOTGHS_DEVICE(printf("=> UDD_SetAddress : setting address to %lu\r\n", addr);) udd_configure_address(addr); udd_enable_address(); diff --git a/hardware/arduino/sam/system/libsam/source/uotghs_host.c b/hardware/arduino/sam/system/libsam/source/uotghs_host.c index 1090c774d..64b75a8ca 100644 --- a/hardware/arduino/sam/system/libsam/source/uotghs_host.c +++ b/hardware/arduino/sam/system/libsam/source/uotghs_host.c @@ -32,8 +32,8 @@ #if SAM3XA_SERIES -#define TRACE_UOTGHS(x) x -//#define TRACE_UOTGHS(x) +#define TRACE_UOTGHS_HOST(x) x +//#define TRACE_UOTGHS_HOST(x) extern void (*gpf_isr)(void); @@ -43,7 +43,7 @@ static void UHD_ISR(void) { // Manage dis/connection event if (Is_uhd_disconnection() && Is_uhd_disconnection_int_enabled()) { - TRACE_UOTGHS(printf(">>> UHD_ISR : Disconnection INT\r\n");) + TRACE_UOTGHS_HOST(printf(">>> UHD_ISR : Disconnection INT\r\n");) uhd_ack_disconnection(); uhd_disable_disconnection_int(); // Stop reset signal, in case of disconnection during reset @@ -59,7 +59,7 @@ static void UHD_ISR(void) return; } if (Is_uhd_connection() && Is_uhd_connection_int_enabled()) { - TRACE_UOTGHS(printf(">>> UHD_ISR : Connection INT\r\n");) + TRACE_UOTGHS_HOST(printf(">>> UHD_ISR : Connection INT\r\n");) uhd_ack_connection(); uhd_disable_connection_int(); uhd_ack_disconnection(); @@ -72,7 +72,7 @@ static void UHD_ISR(void) // Manage Vbus error if (Is_uhd_vbus_error_interrupt()) { - TRACE_UOTGHS(printf(">>> UHD_ISR : VBUS error INT\r\n");) + TRACE_UOTGHS_HOST(printf(">>> UHD_ISR : VBUS error INT\r\n");) uhd_ack_vbus_error_interrupt(); uhd_state = UHD_STATE_ERROR; return; @@ -89,23 +89,23 @@ static void UHD_ISR(void) otg_ack_vbus_transition(); if (Is_otg_vbus_high()) { - TRACE_UOTGHS(printf(">>> UHD_ISR : VBUS transition INT : UHD_STATE_DISCONNECT\r\n");) + TRACE_UOTGHS_HOST(printf(">>> UHD_ISR : VBUS transition INT : UHD_STATE_DISCONNECT\r\n");) uhd_state = UHD_STATE_DISCONNECTED; } else { - TRACE_UOTGHS(printf(">>> UHD_ISR : VBUS transition INT : UHD_STATE_NO_VBUS\r\n");) + TRACE_UOTGHS_HOST(printf(">>> UHD_ISR : VBUS transition INT : UHD_STATE_NO_VBUS\r\n");) otg_freeze_clock(); uhd_state = UHD_STATE_NO_VBUS; } - TRACE_UOTGHS(printf(">>> UHD_ISR : VBUS transition INT : done.\r\n");) + TRACE_UOTGHS_HOST(printf(">>> UHD_ISR : VBUS transition INT : done.\r\n");) return; } // Other errors if (Is_uhd_errors_interrupt()) { - TRACE_UOTGHS(printf(">>> UHD_ISR : Other error INT\r\n");) + TRACE_UOTGHS_HOST(printf(">>> UHD_ISR : Other error INT\r\n");) uhd_ack_errors_interrupt(); return; } @@ -228,7 +228,7 @@ uint32_t UHD_EP0_Alloc(uint32_t ul_add, uint32_t ul_ep_size) { if (ul_ep_size < 8) { - TRACE_UOTGHS(printf("/!\\ UHD_EP0_Alloc : incorrect pipe size!\r\n");) + TRACE_UOTGHS_HOST(printf("/!\\ UHD_EP0_Alloc : incorrect pipe size!\r\n");) return 1; } @@ -251,7 +251,7 @@ uint32_t UHD_EP0_Alloc(uint32_t ul_add, uint32_t ul_ep_size) if (!Is_uhd_pipe_configured(0)) { - TRACE_UOTGHS(printf("/!\\ UHD_EP0_Alloc : incorrect pipe settings!\r\n");) + TRACE_UOTGHS_HOST(printf("/!\\ UHD_EP0_Alloc : incorrect pipe settings!\r\n");) uhd_disable_pipe(0); return 1; } @@ -264,11 +264,21 @@ uint32_t UHD_EP0_Alloc(uint32_t ul_add, uint32_t ul_ep_size) /** * \brief Allocate FIFO for the specified pipe. * + * \param ul_add Address of remote device for pipe 0. + * \param ul_ep_size Actual size of the FIFO in bytes. + * * \retval 0 success. * \retval 1 error. */ uint32_t UHD_EP_Alloc(uint32_t ul_pipe, uint32_t ul_addr, uint32_t ul_interval, uint32_t ul_type, uint32_t ul_dir, uint32_t ul_maxsize, uint32_t ul_bank) { + +/* + * Warning: this is a first implementation, pipe allocation is very limited. + * We should probably check maxsize and if maxsize > current size, then realloc with maxsize. + * If pipe type is changed, a pipe reset and re-configuration is required. + */ + if (Is_uhd_pipe_enabled(ul_pipe)) { // Pipe is already allocated @@ -355,7 +365,7 @@ void UHD_EP_Write(uint32_t ul_ep, uint32_t ul_size, uint8_t* data) if (!Is_uhd_pipe_enabled(ul_ep)) { // Endpoint not valid - TRACE_UOTGHS(printf("/!\\ UHD_EP_Send : pipe is not enabled!\r\n");) + TRACE_UOTGHS_HOST(printf("/!\\ UHD_EP_Send : pipe is not enabled!\r\n");) return; } @@ -370,7 +380,7 @@ void UHD_EP_Send(uint32_t ul_ep, uint32_t ul_token_type) if (!Is_uhd_pipe_enabled(ul_ep)) { // Endpoint not valid - TRACE_UOTGHS(printf("/!\\ UHD_EP_Send : pipe %lu is not enabled!\r\n", ul_ep);) + TRACE_UOTGHS_HOST(printf("/!\\ UHD_EP_Send : pipe %lu is not enabled!\r\n", ul_ep);) return; } diff --git a/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a b/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a index 1a9194c14..ef35d08c6 100644 Binary files a/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a and b/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a differ diff --git a/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a.txt b/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a.txt index 86c0b679d..d4f904640 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a.txt +++ b/hardware/arduino/sam/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a.txt @@ -376,10 +376,12 @@ uotghs_device.o: 00000000 T UDD_WaitOUT U g_interrupt_enabled U gpf_isr + U iprintf U pmc_enable_periph_clk U pmc_enable_udpck U pmc_enable_upll_clock U pmc_switch_udpck_to_upllck + U puts 00000000 b ul_recv_fifo_ptr 00000000 b ul_send_fifo_ptr diff --git a/hardware/arduino/sam/variants/arduino_due_x/variant.h b/hardware/arduino/sam/variants/arduino_due_x/variant.h index 884a4d01f..faf354a42 100644 --- a/hardware/arduino/sam/variants/arduino_due_x/variant.h +++ b/hardware/arduino/sam/variants/arduino_due_x/variant.h @@ -23,9 +23,6 @@ * Headers *----------------------------------------------------------------------------*/ -// We have native USB on this variant -#define USBCON - #include "Arduino.h" #ifdef __cplusplus #include "UARTClass.h"