mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
[sam] enabling High Speed support for USB Device stack
This commit is contained in:
parent
c4198b3a6c
commit
21ee4f0774
@ -194,6 +194,7 @@ extern const PinDescription g_APinDescription[] ;
|
|||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include "wiring_pulse.h"
|
#include "wiring_pulse.h"
|
||||||
|
|
||||||
|
// USB Host
|
||||||
#include "Usb.h"
|
#include "Usb.h"
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
@ -201,16 +202,13 @@ extern const PinDescription g_APinDescription[] ;
|
|||||||
// Include board variant
|
// Include board variant
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
|
||||||
#if defined USBCON
|
// USB Device
|
||||||
#define USB_VID 0x2341 // arduino LLC vid
|
#define USB_VID 0x2341 // arduino LLC vid
|
||||||
|
#define USB_PID_LEONARDO 0x0034
|
||||||
#define USB_PID_LEONARDO 0x0034
|
#define USB_PID_MICRO 0x0035
|
||||||
#define USB_PID_MICRO 0x0035
|
#define USB_PID_DUE 0x003E
|
||||||
#define USB_PID_DUE 0x003E
|
#include "USB/USBDesc.h"
|
||||||
|
#include "USB/USBCore.h"
|
||||||
#include "USB/USBDesc.h"
|
#include "USB/USBAPI.h"
|
||||||
#include "USB/USBCore.h"
|
|
||||||
#include "USB/USBAPI.h"
|
|
||||||
#endif // if defined USBCON
|
|
||||||
|
|
||||||
#endif // Arduino_h
|
#endif // Arduino_h
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "USBAPI.h"
|
#include "USBAPI.h"
|
||||||
|
|
||||||
#if defined(USBCON)
|
|
||||||
|
|
||||||
#ifdef CDC_ENABLED
|
#ifdef CDC_ENABLED
|
||||||
|
|
||||||
#define CDC_SERIAL_BUFFER_SIZE 64
|
#define CDC_SERIAL_BUFFER_SIZE 64
|
||||||
@ -252,4 +250,3 @@ Serial_::operator bool()
|
|||||||
Serial_ Serial;
|
Serial_ Serial;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif /* if defined(USBCON) */
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#if defined(USBCON)
|
|
||||||
#ifdef HID_ENABLED
|
#ifdef HID_ENABLED
|
||||||
|
|
||||||
//#define RAWHID_ENABLED
|
//#define RAWHID_ENABLED
|
||||||
@ -509,5 +508,3 @@ size_t Keyboard_::write(uint8_t c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* if defined(USBCON) */
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
#ifndef __USBAPI__
|
#ifndef __USBAPI__
|
||||||
#define __USBAPI__
|
#define __USBAPI__
|
||||||
|
|
||||||
#if defined __cplusplus && defined USBCON
|
#if defined __cplusplus
|
||||||
|
|
||||||
#include "RingBuffer.h"
|
#include "RingBuffer.h"
|
||||||
|
|
||||||
@ -214,5 +214,4 @@ void USBD_Flush(uint32_t ep);
|
|||||||
uint32_t USBD_Connected(void);
|
uint32_t USBD_Connected(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#endif /* if defined USBCON */
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#ifdef USBCON
|
|
||||||
|
|
||||||
/* Copyright (c) 2010, Peter Barrett
|
/* Copyright (c) 2010, Peter Barrett
|
||||||
**
|
**
|
||||||
** Permission to use, copy, modify, and/or distribute this software for
|
** Permission to use, copy, modify, and/or distribute this software for
|
||||||
@ -20,8 +18,8 @@
|
|||||||
#include "USBAPI.h"
|
#include "USBAPI.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
//#define TRACE_CORE(x) x
|
#define TRACE_CORE(x) x
|
||||||
#define TRACE_CORE(x)
|
//#define TRACE_CORE(x)
|
||||||
|
|
||||||
static const uint32_t EndPoints[] =
|
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 sent = 0;
|
||||||
uint32_t pos = 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)
|
if (_cmark < _cend)
|
||||||
{
|
{
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
{
|
{
|
||||||
sent = UDD_Send(EP0, data + pos, len);
|
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;
|
pos += sent;
|
||||||
len -= sent;
|
len -= sent;
|
||||||
}
|
}
|
||||||
@ -540,7 +538,7 @@ uint32_t USBD_Connected(void)
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
//USB_ USB;
|
USB_ USB;
|
||||||
|
|
||||||
USB_::USB_()
|
USB_::USB_()
|
||||||
{
|
{
|
||||||
@ -589,5 +587,3 @@ bool USB_::configured()
|
|||||||
void USB_::poll()
|
void USB_::poll()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // USBCON
|
|
||||||
|
@ -301,5 +301,4 @@ _Pragma("pack()")
|
|||||||
#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
|
#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
|
||||||
#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
|
#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -60,4 +60,3 @@
|
|||||||
|
|
||||||
#define IMANUFACTURER 1
|
#define IMANUFACTURER 1
|
||||||
#define IPRODUCT 2
|
#define IPRODUCT 2
|
||||||
|
|
||||||
|
@ -39,9 +39,7 @@ int main( void )
|
|||||||
|
|
||||||
delay(1);
|
delay(1);
|
||||||
|
|
||||||
#if defined(USBCON)
|
USB.attach();
|
||||||
//USB.attach();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
@ -50,5 +48,5 @@ int main( void )
|
|||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// return 0 ;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,7 @@ CMSIS_CHIP_PATH=$(CMSIS_ROOT_PATH)/Device/ATMEL/$(CHIP_SERIE)
|
|||||||
|
|
||||||
ARDUINO_CORE_PATH=$(PROJECT_BASE_PATH)/..
|
ARDUINO_CORE_PATH=$(PROJECT_BASE_PATH)/..
|
||||||
ARDUINO_USB_PATH=$(PROJECT_BASE_PATH)/../USB
|
ARDUINO_USB_PATH=$(PROJECT_BASE_PATH)/../USB
|
||||||
|
ARDUINO_USB_HOST_PATH=$(PROJECT_BASE_PATH)/../../../system/USBHost
|
||||||
|
|
||||||
# Output directories
|
# Output directories
|
||||||
OUTPUT_PATH = debug_$(VARIANT)
|
OUTPUT_PATH = debug_$(VARIANT)
|
||||||
@ -99,7 +100,8 @@ INCLUDES += -I$(SYSTEM_PATH)/libsam
|
|||||||
INCLUDES += -I$(CMSIS_ARM_PATH)
|
INCLUDES += -I$(CMSIS_ARM_PATH)
|
||||||
INCLUDES += -I$(CMSIS_ATMEL_PATH)
|
INCLUDES += -I$(CMSIS_ATMEL_PATH)
|
||||||
INCLUDES += -I$(CMSIS_CHIP_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
|
ifdef DEBUG
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(USBCON)
|
|
||||||
|
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -36,7 +34,6 @@ void loop() {
|
|||||||
Serial.print(inChar);
|
Serial.print(inChar);
|
||||||
Serial1.print(inChar);
|
Serial1.print(inChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -2,58 +2,49 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <hidboot.h>
|
#include <hidboot.h>
|
||||||
|
|
||||||
class KbdRptParser : public KeyboardReportParser
|
class MouseRptParser : public MouseReportParser
|
||||||
{
|
{
|
||||||
void PrintKey(uint8_t mod, uint8_t key);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnKeyDown (uint8_t mod, uint8_t key);
|
virtual void OnMouseMove (MOUSEINFO *mi);
|
||||||
virtual void OnKeyUp (uint8_t mod, uint8_t key);
|
virtual void OnLeftButtonUp (MOUSEINFO *mi);
|
||||||
virtual void OnKeyPressed(uint8_t key);
|
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 MouseRptParser::OnMouseMove(MOUSEINFO *mi)
|
||||||
void KbdRptParser::PrintKey(uint8_t m, uint8_t key)
|
|
||||||
{
|
{
|
||||||
MODIFIERKEYS mod;
|
printf("Pos={%d,%d}\r\n", mi->dX, mi->dY);
|
||||||
|
|
||||||
*((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" : " ");
|
|
||||||
};
|
};
|
||||||
|
void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
|
||||||
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
|
|
||||||
{
|
{
|
||||||
printf("DN ");
|
printf("L Butt Up\r\n");
|
||||||
PrintKey(mod, key);
|
};
|
||||||
uint8_t c = OemToAscii(mod, key);
|
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
|
||||||
|
|
||||||
if (c)
|
|
||||||
OnKeyPressed(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key)
|
|
||||||
{
|
{
|
||||||
printf("UP ");
|
printf("L Butt Dn\r\n");
|
||||||
PrintKey(mod, key);
|
};
|
||||||
}
|
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
|
||||||
|
|
||||||
void KbdRptParser::OnKeyPressed(uint8_t key)
|
|
||||||
{
|
{
|
||||||
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;
|
USBHost Usb;
|
||||||
HIDBoot<HID_PROTOCOL_KEYBOARD> Kbd(&Usb);
|
HIDBoot<HID_PROTOCOL_MOUSE> HostMouse(&Usb);
|
||||||
KbdRptParser Prs;
|
MouseRptParser Prs;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@ -61,7 +52,7 @@ void setup()
|
|||||||
printf("\r\nProgram started:\r\n");
|
printf("\r\nProgram started:\r\n");
|
||||||
delay(200);
|
delay(200);
|
||||||
|
|
||||||
Kbd.SetReportParser(0, (HIDReportParser*)&Prs);
|
HostMouse.SetReportParser(0,(HIDReportParser*)&Prs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
|
|
||||||
#if SAM3XA_SERIES
|
#if SAM3XA_SERIES
|
||||||
|
|
||||||
//#define TRACE_UOTGHS(x) x
|
#define TRACE_UOTGHS_DEVICE(x) x
|
||||||
#define TRACE_UOTGHS(x)
|
//#define TRACE_UOTGHS_DEVICE(x)
|
||||||
|
|
||||||
extern void (*gpf_isr)(void);
|
extern void (*gpf_isr)(void);
|
||||||
|
|
||||||
@ -83,8 +83,9 @@ uint32_t UDD_Init(void)
|
|||||||
//while (!Is_otg_clock_usable())
|
//while (!Is_otg_clock_usable())
|
||||||
// ;
|
// ;
|
||||||
|
|
||||||
|
// Enable High Speed
|
||||||
udd_low_speed_disable();
|
udd_low_speed_disable();
|
||||||
udd_high_speed_disable();
|
udd_high_speed_enable();
|
||||||
|
|
||||||
//otg_ack_vbus_transition();
|
//otg_ack_vbus_transition();
|
||||||
// Force Vbus interrupt in case of Vbus always with a high level
|
// 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();
|
irqflags_t flags = cpu_irq_save();
|
||||||
|
|
||||||
TRACE_UOTGHS(printf("=> UDD_Attach\r\n");)
|
TRACE_UOTGHS_DEVICE(printf("=> UDD_Attach\r\n");)
|
||||||
|
|
||||||
otg_unfreeze_clock();
|
otg_unfreeze_clock();
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ void UDD_Attach(void)
|
|||||||
|
|
||||||
void UDD_Detach(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;
|
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.
|
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
|
// Configure EP
|
||||||
UOTGHS->UOTGHS_DEVEPTCFG[ul_ep_nb] = ul_ep_cfg;
|
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);
|
udd_enable_endpoint(ul_ep_nb);
|
||||||
|
|
||||||
if (!Is_udd_endpoint_configured(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);
|
udd_enable_endpoint(ul_ep_nb);
|
||||||
|
|
||||||
if (!Is_udd_endpoint_configured(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.
|
// Send packet.
|
||||||
void UDD_ClearIN(void)
|
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;
|
UOTGHS->UOTGHS_DEVEPTICR[EP0] = UOTGHS_DEVEPTICR_TXINIC;
|
||||||
ul_send_fifo_ptr[EP0] = 0;
|
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);
|
uint8_t *ptr_dest = (uint8_t *) &udd_get_endpoint_fifo_access8(ep);
|
||||||
uint32_t i;
|
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)
|
if (ep == EP0)
|
||||||
{
|
{
|
||||||
@ -233,7 +234,7 @@ uint32_t UDD_Send(uint32_t ep, const void* data, uint32_t len)
|
|||||||
|
|
||||||
if (ep == EP0)
|
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)
|
if (ul_send_fifo_ptr[ep] == EP0_SIZE)
|
||||||
{
|
{
|
||||||
UDD_ClearIN(); // Fifo is full, release this packet
|
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);
|
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;
|
ptr_dest[ul_send_fifo_ptr[ep]] = data;
|
||||||
ul_send_fifo_ptr[ep] += 1;
|
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 *ptr_dest = (uint8_t *) &udd_get_endpoint_fifo_access8(ep);
|
||||||
uint8_t data = ptr_dest[ul_recv_fifo_ptr[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;
|
ul_recv_fifo_ptr[ep] += 1;
|
||||||
return data;
|
return data;
|
||||||
@ -299,7 +300,7 @@ uint32_t UDD_FifoByteCount(uint32_t ep)
|
|||||||
|
|
||||||
void UDD_ReleaseRX(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_DEVEPTICR[ep] = (UOTGHS_DEVEPTICR_NAKOUTIC | UOTGHS_DEVEPTICR_RXOUTIC);
|
||||||
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
|
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
|
||||||
ul_recv_fifo_ptr[ep] = 0;
|
ul_recv_fifo_ptr[ep] = 0;
|
||||||
@ -307,7 +308,7 @@ void UDD_ReleaseRX(uint32_t ep)
|
|||||||
|
|
||||||
void UDD_ReleaseTX(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_DEVEPTICR[ep] = (UOTGHS_DEVEPTICR_NAKINIC | UOTGHS_DEVEPTICR_RXOUTIC | UOTGHS_DEVEPTICR_TXINIC);
|
||||||
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
|
UOTGHS->UOTGHS_DEVEPTIDR[ep] = UOTGHS_DEVEPTIDR_FIFOCONC;
|
||||||
ul_send_fifo_ptr[ep] = 0;
|
ul_send_fifo_ptr[ep] = 0;
|
||||||
@ -321,7 +322,7 @@ uint32_t UDD_ReadWriteAllowed(uint32_t ep)
|
|||||||
|
|
||||||
void UDD_SetAddress(uint32_t addr)
|
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_configure_address(addr);
|
||||||
udd_enable_address();
|
udd_enable_address();
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
|
|
||||||
#if SAM3XA_SERIES
|
#if SAM3XA_SERIES
|
||||||
|
|
||||||
#define TRACE_UOTGHS(x) x
|
#define TRACE_UOTGHS_HOST(x) x
|
||||||
//#define TRACE_UOTGHS(x)
|
//#define TRACE_UOTGHS_HOST(x)
|
||||||
|
|
||||||
extern void (*gpf_isr)(void);
|
extern void (*gpf_isr)(void);
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ static void UHD_ISR(void)
|
|||||||
{
|
{
|
||||||
// Manage dis/connection event
|
// Manage dis/connection event
|
||||||
if (Is_uhd_disconnection() && Is_uhd_disconnection_int_enabled()) {
|
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_ack_disconnection();
|
||||||
uhd_disable_disconnection_int();
|
uhd_disable_disconnection_int();
|
||||||
// Stop reset signal, in case of disconnection during reset
|
// Stop reset signal, in case of disconnection during reset
|
||||||
@ -59,7 +59,7 @@ static void UHD_ISR(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Is_uhd_connection() && Is_uhd_connection_int_enabled()) {
|
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_ack_connection();
|
||||||
uhd_disable_connection_int();
|
uhd_disable_connection_int();
|
||||||
uhd_ack_disconnection();
|
uhd_ack_disconnection();
|
||||||
@ -72,7 +72,7 @@ static void UHD_ISR(void)
|
|||||||
// Manage Vbus error
|
// Manage Vbus error
|
||||||
if (Is_uhd_vbus_error_interrupt())
|
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_ack_vbus_error_interrupt();
|
||||||
uhd_state = UHD_STATE_ERROR;
|
uhd_state = UHD_STATE_ERROR;
|
||||||
return;
|
return;
|
||||||
@ -89,23 +89,23 @@ static void UHD_ISR(void)
|
|||||||
otg_ack_vbus_transition();
|
otg_ack_vbus_transition();
|
||||||
if (Is_otg_vbus_high())
|
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;
|
uhd_state = UHD_STATE_DISCONNECTED;
|
||||||
}
|
}
|
||||||
else
|
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();
|
otg_freeze_clock();
|
||||||
uhd_state = UHD_STATE_NO_VBUS;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other errors
|
// Other errors
|
||||||
if (Is_uhd_errors_interrupt())
|
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();
|
uhd_ack_errors_interrupt();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -228,7 +228,7 @@ uint32_t UHD_EP0_Alloc(uint32_t ul_add, uint32_t ul_ep_size)
|
|||||||
{
|
{
|
||||||
if (ul_ep_size < 8)
|
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;
|
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))
|
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);
|
uhd_disable_pipe(0);
|
||||||
return 1;
|
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.
|
* \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 0 success.
|
||||||
* \retval 1 error.
|
* \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)
|
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))
|
if (Is_uhd_pipe_enabled(ul_pipe))
|
||||||
{
|
{
|
||||||
// Pipe is already allocated
|
// 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))
|
if (!Is_uhd_pipe_enabled(ul_ep))
|
||||||
{
|
{
|
||||||
// Endpoint not valid
|
// 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;
|
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))
|
if (!Is_uhd_pipe_enabled(ul_ep))
|
||||||
{
|
{
|
||||||
// Endpoint not valid
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
@ -376,10 +376,12 @@ uotghs_device.o:
|
|||||||
00000000 T UDD_WaitOUT
|
00000000 T UDD_WaitOUT
|
||||||
U g_interrupt_enabled
|
U g_interrupt_enabled
|
||||||
U gpf_isr
|
U gpf_isr
|
||||||
|
U iprintf
|
||||||
U pmc_enable_periph_clk
|
U pmc_enable_periph_clk
|
||||||
U pmc_enable_udpck
|
U pmc_enable_udpck
|
||||||
U pmc_enable_upll_clock
|
U pmc_enable_upll_clock
|
||||||
U pmc_switch_udpck_to_upllck
|
U pmc_switch_udpck_to_upllck
|
||||||
|
U puts
|
||||||
00000000 b ul_recv_fifo_ptr
|
00000000 b ul_recv_fifo_ptr
|
||||||
00000000 b ul_send_fifo_ptr
|
00000000 b ul_send_fifo_ptr
|
||||||
|
|
||||||
|
@ -23,9 +23,6 @@
|
|||||||
* Headers
|
* Headers
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// We have native USB on this variant
|
|
||||||
#define USBCON
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include "UARTClass.h"
|
#include "UARTClass.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user