1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

[sam] intermediate commit

This commit is contained in:
Thibaut VIARD
2012-04-28 20:15:23 +02:00
parent e034de5ea9
commit 46b9f96d4a
12 changed files with 194 additions and 180 deletions

View File

@ -7,10 +7,12 @@ arduino_due_u.upload.maximum_size=49152
arduino_due_u.build.mcu=cortex-m3 arduino_due_u.build.mcu=cortex-m3
arduino_due_u.build.f_cpu=96000000L arduino_due_u.build.f_cpu=96000000L
arduino_due_u.build.core=sam arduino_due_u.build.core=sam
arduino_due_u.build.extra_flags=-D__SAM3U4E__ -mthumb arduino_due_u.build.extra_flags=-D__SAM3U4E__ -mthumb
arduino_due_u.build.ldscript=linker_scripts/gcc/flash.ld arduino_due_u.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_u.build.variant=arduino_due_u arduino_due_u.build.variant=arduino_due_u
arduino_due_u.build.variant_system_lib=libsam_sam3u4e_gcc_rel.a arduino_due_u.build.variant_system_lib=libsam_sam3u4e_gcc_rel.a
arduino_due_u.build.vid=0x2341
arduino_due_u.build.pid=0xcafe
############################################################## ##############################################################
@ -21,7 +23,9 @@ arduino_due_x.upload.maximum_size=49152
arduino_due_x.build.mcu=cortex-m3 arduino_due_x.build.mcu=cortex-m3
arduino_due_x.build.f_cpu=84000000L arduino_due_x.build.f_cpu=84000000L
arduino_due_x.build.core=sam arduino_due_x.build.core=sam
arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb
arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_x.build.variant=arduino_due_x arduino_due_x.build.variant=arduino_due_x
arduino_due_x.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a arduino_due_x.build.variant_system_lib=libsam_sam3x8e_gcc_rel.a
arduino_due_x.build.vid=0x2341
arduino_due_x.build.pid=0xcafe

View File

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2011 Arduino. All right reserved. Copyright (c) 2012 Arduino. All right reserved.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
@ -8,7 +8,7 @@
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of 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. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
@ -198,4 +198,16 @@ extern const PinDescription g_APinDescription[] ;
// Include board variant // Include board variant
#include "variant.h" #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 0xcafe
#include "USBDesc.h"
#include "USBCore.h"
#include "USBAPI.h"
#endif // if defined USBCON
#endif // Arduino_h #endif // Arduino_h

View File

@ -1,19 +0,0 @@
#ifndef __PLATFORM_H__
#define __PLATFORM_H__
#include <inttypes.h>
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
#include "Arduino.h"
#if defined(USBCON)
#include "USBDesc.h"
#include "USBCore.h"
#include "USBAPI.h"
#endif /* if defined(USBCON) */
#endif

View File

@ -1,37 +1,30 @@
/* Copyright (c) 2011, Peter Barrett
**
/* Copyright (c) 2011, Peter Barrett ** Permission to use, copy, modify, and/or distribute this software for
** ** any purpose with or without fee is hereby granted, provided that the
** Permission to use, copy, modify, and/or distribute this software for ** above copyright notice and this permission notice appear in all copies.
** any purpose with or without fee is hereby granted, provided that the **
** above copyright notice and this permission notice appear in all copies. ** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
** ** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL ** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
** WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED ** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR ** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES ** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ** SOFTWARE.
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/ */
#include "Arduino.h"
#if defined(USBCON) #if defined(USBCON)
#include "Platform.h"
#include "USBAPI.h"
#include <avr/wdt.h>
#ifdef CDC_ENABLED #ifdef CDC_ENABLED
#if (RAMEND < 1000) #define CDC_SERIAL_BUFFER_SIZE 64
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 64
#endif
struct ring_buffer struct ring_buffer
{ {
unsigned char buffer[SERIAL_BUFFER_SIZE]; unsigned char buffer[CDC_SERIAL_BUFFER_SIZE];
volatile int head; volatile int head;
volatile int tail; volatile int tail;
}; };
@ -40,19 +33,16 @@ ring_buffer cdc_rx_buffer = { { 0 }, 0, 0};
typedef struct typedef struct
{ {
u32 dwDTERate; uint32_t dwDTERate;
u8 bCharFormat; uint8_t bCharFormat;
u8 bParityType; uint8_t bParityType;
u8 bDataBits; uint8_t bDataBits;
u8 lineState; uint8_t lineState;
} LineInfo; } LineInfo;
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 }; static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
#define WEAK __attribute__ ((weak)) static const CDCDescriptor _cdcInterface =
extern const CDCDescriptor _cdcInterface PROGMEM;
const CDCDescriptor _cdcInterface =
{ {
D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1), D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1),
@ -70,7 +60,7 @@ const CDCDescriptor _cdcInterface =
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0) D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_IN ),USB_ENDPOINT_TYPE_BULK,0x40,0)
}; };
int WEAK CDC_GetInterface(u8* interfaceNum) int WEAK CDC_GetInterface(uint8_t* interfaceNum)
{ {
interfaceNum[0] += 2; // uses 2 interfaceNum[0] += 2; // uses 2
return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface)); return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
@ -78,8 +68,8 @@ int WEAK CDC_GetInterface(u8* interfaceNum)
bool WEAK CDC_Setup(Setup& setup) bool WEAK CDC_Setup(Setup& setup)
{ {
u8 r = setup.bRequest; uint8_t r = setup.bRequest;
u8 requestType = setup.bmRequestType; uint8_t requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType) if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
{ {
@ -102,24 +92,30 @@ bool WEAK CDC_Setup(Setup& setup)
{ {
_usbLineInfo.lineState = setup.wValueL; _usbLineInfo.lineState = setup.wValueL;
// auto-reset into the bootloader is triggered when the port, already // 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 // 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 // with a relatively long period so it can finish housekeeping tasks
// like servicing endpoints before the sketch ends // 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). // We check DTR state to determine if host port is open (bit 0 of lineState).
if ((_usbLineInfo.lineState & 0x01) == 0) { if ((_usbLineInfo.lineState & 0x01) == 0)
{
/* TODO, AVR Stuff
*(uint16_t *)0x0800 = 0x7777; *(uint16_t *)0x0800 = 0x7777;
wdt_enable(WDTO_120MS); wdt_enable(WDTO_120MS);
} else { */
}
else
{
// Most OSs do some intermediate steps when configuring ports and DTR can // Most OSs do some intermediate steps when configuring ports and DTR can
// twiggle more than once before stabilizing. // twiggle more than once before stabilizing.
// To avoid spurious resets we set the watchdog to 250ms and eventually // To avoid spurious resets we set the watchdog to 250ms and eventually
// cancel if DTR goes back high. // cancel if DTR goes back high.
/* TODO, AVR Stuff
wdt_disable(); wdt_disable();
wdt_reset(); wdt_reset();
*(uint16_t *)0x0800 = 0x0; *(uint16_t *)0x0800 = 0x0;
*/
} }
} }
return true; return true;
@ -138,12 +134,12 @@ void Serial_::end(void)
{ {
} }
void Serial_::accept(void) void Serial_::accept(void)
{ {
ring_buffer *buffer = &cdc_rx_buffer; ring_buffer *buffer = &cdc_rx_buffer;
int c = USB_Recv(CDC_RX); int c = USB_Recv(CDC_RX);
int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE; int i = (unsigned int)(buffer->head+1) % SERIAL_BUFFER_SIZE;
// if we should be storing the received character into the location // if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the // just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer // current location of the tail), we're about to overflow the buffer
@ -180,7 +176,7 @@ int Serial_::read(void)
unsigned char c = buffer->buffer[buffer->tail]; unsigned char c = buffer->buffer[buffer->tail];
buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE; buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
return c; return c;
} }
} }
void Serial_::flush(void) void Serial_::flush(void)
@ -190,12 +186,12 @@ void Serial_::flush(void)
size_t Serial_::write(uint8_t c) size_t Serial_::write(uint8_t c)
{ {
/* only try to send bytes if the high-level CDC connection itself /* only try to send bytes if the high-level CDC connection itself
is open (not just the pipe) - the OS should set lineState when the port is open (not just the pipe) - the OS should set lineState when the port
is opened and clear lineState when the port is closed. is opened and clear lineState when the port is closed.
bytes sent before the user opens the connection or after bytes sent before the user opens the connection or after
the connection is closed are lost - just like with a UART. */ the connection is closed are lost - just like with a UART. */
// TODO - ZE - check behavior on different OSes and test what happens if an // 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 // open connection isn't broken cleanly (cable is yanked out, host dies
// or locks up, or host virtual serial port hangs) // or locks up, or host virtual serial port hangs)
@ -214,14 +210,14 @@ size_t Serial_::write(uint8_t c)
// This operator is a convenient way for a sketch to check whether the // This operator is a convenient way for a sketch to check whether the
// port has actually been configured and opened by the host (as opposed // port has actually been configured and opened by the host (as opposed
// to just being connected to the host). It can be used, for example, in // to just being connected to the host). It can be used, for example, in
// setup() before printing to ensure that an application on the host is // setup() before printing to ensure that an application on the host is
// actually ready to receive and display the data. // actually ready to receive and display the data.
// We add a short delay before returning to fix a bug observed by Federico // 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. // where the port is configured (lineState != 0) but not quite opened.
Serial_::operator bool() { Serial_::operator bool() {
bool result = false; bool result = false;
if (_usbLineInfo.lineState > 0) if (_usbLineInfo.lineState > 0)
result = true; result = true;
delay(10); delay(10);
return result; return result;

View File

@ -1,5 +1,3 @@
/* Copyright (c) 2011, Peter Barrett /* Copyright (c) 2011, Peter Barrett
** **
** Permission to use, copy, modify, and/or distribute this software for ** Permission to use, copy, modify, and/or distribute this software for
@ -16,11 +14,7 @@
** SOFTWARE. ** SOFTWARE.
*/ */
#define USBCON #include "Arduino.h"
#include "Platform.h"
#include "USBAPI.h"
#include "USBDesc.h"
#if defined(USBCON) #if defined(USBCON)
#ifdef HID_ENABLED #ifdef HID_ENABLED
@ -45,7 +39,7 @@ Keyboard_ Keyboard;
#define RAWHID_TX_SIZE 64 #define RAWHID_TX_SIZE 64
#define RAWHID_RX_SIZE 64 #define RAWHID_RX_SIZE 64
extern const u8 _hidReportDescriptor[] = { extern const uint8_t _hidReportDescriptor[] = {
// Mouse // Mouse
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54 0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54
0x09, 0x02, // USAGE (Mouse) 0x09, 0x02, // USAGE (Mouse)
@ -139,12 +133,12 @@ extern const HIDDescriptor _hidInterface =
//================================================================================ //================================================================================
// Driver // Driver
u8 _hid_protocol = 1; uint8_t _hid_protocol = 1;
u8 _hid_idle = 1; uint8_t _hid_idle = 1;
#define WEAK __attribute__ ((weak)) #define WEAK __attribute__ ((weak))
int WEAK HID_GetInterface(u8* interfaceNum) int WEAK HID_GetInterface(uint8_t* interfaceNum)
{ {
interfaceNum[0] += 1; // uses 1 interfaceNum[0] += 1; // uses 1
return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface)); return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface));
@ -155,7 +149,7 @@ int WEAK HID_GetDescriptor(int i)
return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor)); return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor));
} }
void WEAK HID_SendReport(u8 id, const void* data, int len) void WEAK HID_SendReport(uint8_t id, const void* data, int len)
{ {
USB_Send(HID_TX, &id, 1); USB_Send(HID_TX, &id, 1);
USB_Send(HID_TX | TRANSFER_RELEASE,data,len); USB_Send(HID_TX | TRANSFER_RELEASE,data,len);
@ -163,8 +157,8 @@ void WEAK HID_SendReport(u8 id, const void* data, int len)
bool WEAK HID_Setup(Setup& setup) bool WEAK HID_Setup(Setup& setup)
{ {
u8 r = setup.bRequest; uint8_t r = setup.bRequest;
u8 requestType = setup.bmRequestType; uint8_t requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType) if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
{ {
if (HID_GET_REPORT == r) if (HID_GET_REPORT == r)
@ -222,7 +216,7 @@ void Mouse_::click(uint8_t b)
void Mouse_::move(signed char x, signed char y, signed char wheel) void Mouse_::move(signed char x, signed char y, signed char wheel)
{ {
u8 m[4]; uint8_t m[4];
m[0] = _buttons; m[0] = _buttons;
m[1] = x; m[1] = x;
m[2] = y; m[2] = y;

View File

@ -1,9 +1,25 @@
/*
Copyright (c) 2012 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
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.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __USBAPI__ #ifndef __USBAPI__
#define __USBAPI__ #define __USBAPI__
#if defined(USBCON) #if defined __cplusplus && defined USBCON
//================================================================================ //================================================================================
//================================================================================ //================================================================================
@ -192,4 +208,4 @@ void USB_Flush(uint8_t ep);
#endif #endif
#endif /* if defined(USBCON) */ #endif /* if defined USBCON */

View File

@ -1,5 +1,3 @@
/* 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
@ -15,17 +13,9 @@
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS ** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE. ** SOFTWARE.
*/ */
#define USBCON
#include "Platform.h" #include "Arduino.h"
#include "USBAPI.h"
#include "USBDesc.h"
#include "USBCore.h"
#if defined(USBCON)
extern const uint8_t _initEndpoints[] ;
const uint8_t _initEndpoints[] = const uint8_t _initEndpoints[] =
{ {
0, 0,
@ -366,7 +356,7 @@ void USB_ISR()
{ {
if (REQUEST_DEVICE == (requestType & REQUEST_RECIPIENT)) if (REQUEST_DEVICE == (requestType & REQUEST_RECIPIENT))
{ {
InitEndpoints(); InitEndpoints(_initEndpoints, sizeof(_initEndpoints)/sizeof(_initEndpoints[0]));
_usbConfiguration = setup.wValueL; _usbConfiguration = setup.wValueL;
} }
else else
@ -447,7 +437,9 @@ ISR(USB_GEN_vect)
uint8_t USBD_Connected(void) uint8_t USBD_Connected(void)
{ {
uint8_t f = UDFNUML; uint8_t f = UDFNUML;
delay(3); delay(3);
return f != UDFNUML; return f != UDFNUML;
} }
@ -503,5 +495,3 @@ bool USB_::configured()
void USB_::poll() void USB_::poll()
{ {
} }
#endif /* if defined(USBCON) */

View File

@ -127,32 +127,32 @@
// Device // Device
typedef struct { typedef struct {
u8 len; // 18 uint8_t len; // 18
u8 dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE uint8_t dtype; // 1 USB_DEVICE_DESCRIPTOR_TYPE
u16 usbVersion; // 0x200 uint16_t usbVersion; // 0x200
u8 deviceClass; uint8_t deviceClass;
u8 deviceSubClass; uint8_t deviceSubClass;
u8 deviceProtocol; uint8_t deviceProtocol;
u8 packetSize0; // Packet 0 uint8_t packetSize0; // Packet 0
u16 idVendor; uint16_t idVendor;
u16 idProduct; uint16_t idProduct;
u16 deviceVersion; // 0x100 uint16_t deviceVersion; // 0x100
u8 iManufacturer; uint8_t iManufacturer;
u8 iProduct; uint8_t iProduct;
u8 iSerialNumber; uint8_t iSerialNumber;
u8 bNumConfigurations; uint8_t bNumConfigurations;
} DeviceDescriptor; } DeviceDescriptor;
// Config // Config
typedef struct { typedef struct {
u8 len; // 9 uint8_t len; // 9
u8 dtype; // 2 uint8_t dtype; // 2
u16 clen; // total length uint16_t clen; // total length
u8 numInterfaces; uint8_t numInterfaces;
u8 config; uint8_t config;
u8 iconfig; uint8_t iconfig;
u8 attributes; uint8_t attributes;
u8 maxPower; uint8_t maxPower;
} ConfigDescriptor; } ConfigDescriptor;
// String // String
@ -160,75 +160,75 @@ typedef struct {
// Interface // Interface
typedef struct typedef struct
{ {
u8 len; // 9 uint8_t len; // 9
u8 dtype; // 4 uint8_t dtype; // 4
u8 number; uint8_t number;
u8 alternate; uint8_t alternate;
u8 numEndpoints; uint8_t numEndpoints;
u8 interfaceClass; uint8_t interfaceClass;
u8 interfaceSubClass; uint8_t interfaceSubClass;
u8 protocol; uint8_t protocol;
u8 iInterface; uint8_t iInterface;
} InterfaceDescriptor; } InterfaceDescriptor;
// Endpoint // Endpoint
typedef struct typedef struct
{ {
u8 len; // 7 uint8_t len; // 7
u8 dtype; // 5 uint8_t dtype; // 5
u8 addr; uint8_t addr;
u8 attr; uint8_t attr;
u16 packetSize; uint16_t packetSize;
u8 interval; uint8_t interval;
} EndpointDescriptor; } EndpointDescriptor;
// Interface Association Descriptor // Interface Association Descriptor
// Used to bind 2 interfaces together in CDC compostite device // Used to bind 2 interfaces together in CDC compostite device
typedef struct typedef struct
{ {
u8 len; // 8 uint8_t len; // 8
u8 dtype; // 11 uint8_t dtype; // 11
u8 firstInterface; uint8_t firstInterface;
u8 interfaceCount; uint8_t interfaceCount;
u8 functionClass; uint8_t functionClass;
u8 funtionSubClass; uint8_t funtionSubClass;
u8 functionProtocol; uint8_t functionProtocol;
u8 iInterface; uint8_t iInterface;
} IADDescriptor; } IADDescriptor;
// CDC CS interface descriptor // CDC CS interface descriptor
typedef struct typedef struct
{ {
u8 len; // 5 uint8_t len; // 5
u8 dtype; // 0x24 uint8_t dtype; // 0x24
u8 subtype; uint8_t subtype;
u8 d0; uint8_t d0;
u8 d1; uint8_t d1;
} CDCCSInterfaceDescriptor; } CDCCSInterfaceDescriptor;
typedef struct typedef struct
{ {
u8 len; // 4 uint8_t len; // 4
u8 dtype; // 0x24 uint8_t dtype; // 0x24
u8 subtype; uint8_t subtype;
u8 d0; uint8_t d0;
} CDCCSInterfaceDescriptor4; } CDCCSInterfaceDescriptor4;
typedef struct typedef struct
{ {
u8 len; uint8_t len;
u8 dtype; // 0x24 uint8_t dtype; // 0x24
u8 subtype; // 1 uint8_t subtype; // 1
u8 bmCapabilities; uint8_t bmCapabilities;
u8 bDataInterface; uint8_t bDataInterface;
} CMFunctionalDescriptor; } CMFunctionalDescriptor;
typedef struct typedef struct
{ {
u8 len; uint8_t len;
u8 dtype; // 0x24 uint8_t dtype; // 0x24
u8 subtype; // 1 uint8_t subtype; // 1
u8 bmCapabilities; uint8_t bmCapabilities;
} ACMFunctionalDescriptor; } ACMFunctionalDescriptor;
typedef struct typedef struct
@ -259,15 +259,15 @@ typedef struct
typedef struct typedef struct
{ {
u8 len; // 9 uint8_t len; // 9
u8 dtype; // 0x21 uint8_t dtype; // 0x21
u8 addr; uint8_t addr;
u8 versionL; // 0x101 uint8_t versionL; // 0x101
u8 versionH; // 0x101 uint8_t versionH; // 0x101
u8 country; uint8_t country;
u8 desctype; // 0x22 report uint8_t desctype; // 0x22 report
u8 descLenL; uint8_t descLenL;
u8 descLenH; uint8_t descLenH;
} HIDDescDescriptor; } HIDDescDescriptor;
typedef struct typedef struct

View File

@ -74,6 +74,9 @@ endif
include $(TOOLCHAIN).mk include $(TOOLCHAIN).mk
CFLAGS += -DUSB_VID=0x2341 -DUSB_PID=0xcafe
CPPFLAGS += -DUSB_VID=0x2341 -DUSB_PID=0xcafe
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
ifdef DEBUG ifdef DEBUG
OUTPUT_OBJ=debug OUTPUT_OBJ=debug
@ -155,12 +158,12 @@ create_output:
-@mkdir $(OUTPUT_PATH) 1>NUL 2>&1 -@mkdir $(OUTPUT_PATH) 1>NUL 2>&1
$(addprefix $(OUTPUT_PATH)/,$(C_OBJ)): $(OUTPUT_PATH)/%.o: %.c $(addprefix $(OUTPUT_PATH)/,$(C_OBJ)): $(OUTPUT_PATH)/%.o: %.c
# @"$(CC)" -v -c $(CFLAGS) $< -o $@ # "$(CC)" -v -c $(CFLAGS) $< -o $@
@"$(CC)" -c $(CFLAGS) $< -o $@ @"$(CC)" -c $(CFLAGS) $< -o $@
$(addprefix $(OUTPUT_PATH)/,$(CPP_OBJ)): $(OUTPUT_PATH)/%.o: %.cpp $(addprefix $(OUTPUT_PATH)/,$(CPP_OBJ)): $(OUTPUT_PATH)/%.o: %.cpp
# @"$(CC)" -c $(CPPFLAGS) $< -o $@ "$(CC)" -xc++ -c $(CPPFLAGS) $< -o $@
@"$(CC)" -xc++ -c $(CPPFLAGS) $< -o $@ # @"$(CC)" -xc++ -c $(CPPFLAGS) $< -o $@
$(addprefix $(OUTPUT_PATH)/,$(A_OBJ)): $(OUTPUT_PATH)/%.o: %.s $(addprefix $(OUTPUT_PATH)/,$(A_OBJ)): $(OUTPUT_PATH)/%.o: %.s
@"$(AS)" -c $(ASFLAGS) $< -o $@ @"$(AS)" -c $(ASFLAGS) $< -o $@

View File

@ -43,5 +43,4 @@
#define EP_TYPE_ISOCHRONOUS_IN (UOTGHS_DEVEPTCFG_EPSIZE_1024_BYTE | UOTGHS_DEVEPTCFG_EPDIR_IN | UOTGHS_DEVEPTCFG_EPTYPE_ISO | UOTGHS_DEVEPTCFG_EPBK_3_BANK) #define EP_TYPE_ISOCHRONOUS_IN (UOTGHS_DEVEPTCFG_EPSIZE_1024_BYTE | UOTGHS_DEVEPTCFG_EPDIR_IN | UOTGHS_DEVEPTCFG_EPTYPE_ISO | UOTGHS_DEVEPTCFG_EPBK_3_BANK)
#define EP_TYPE_ISOCHRONOUS_OUT (UOTGHS_DEVEPTCFG_EPSIZE_1024_BYTE | UOTGHS_DEVEPTCFG_EPTYPE_ISO | UOTGHS_DEVEPTCFG_EPBK_3_BANK) #define EP_TYPE_ISOCHRONOUS_OUT (UOTGHS_DEVEPTCFG_EPSIZE_1024_BYTE | UOTGHS_DEVEPTCFG_EPTYPE_ISO | UOTGHS_DEVEPTCFG_EPBK_3_BANK)
#endif /* UOTGHS_H_INCLUDED */ #endif /* UOTGHS_H_INCLUDED */

View File

@ -20,8 +20,24 @@
#if SAM3XA_SERIES #if SAM3XA_SERIES
void USBD_InitEndpoints(void) void USBD_InitEndpoints( uint8_t* puc_EndPoints, uint32_t ul_EndPoints )
{ {
for (uint8_t i = 1; i < sizeof(_initEndpoints); i++)
{
// Reset Endpoint Fifos
UOTGHS->UOTGHS_DEVEPTISR[i].UDPHS_EPTCLRSTA = UDPHS_EPTCLRSTA_TOGGLESQ | UDPHS_EPTCLRSTA_FRCESTALL;
UOTGHS->UDPHS_EPTRST = 1<<i;
//UECONX = 1;
//UECFG0X = pgm_read_byte(_initEndpoints+i);
UOTGHS->UDPHS_EPT[i].UDPHS_EPTCFG = _initEndpoints[i];
while( (signed int)UDPHS_EPTCFG_EPT_MAPD != (signed int)((UOTGHS->UDPHS_EPT[i].UDPHS_EPTCFG) & (unsigned int)UDPHS_EPTCFG_EPT_MAPD) )
;
UOTGHS->UDPHS_EPT[i].UDPHS_EPTCTLENB = UDPHS_EPTCTLENB_EPT_ENABL;
// UECFG1X = EP_DOUBLE_64;
}
} }
uint32_t USBD_Init(void) uint32_t USBD_Init(void)

View File

@ -23,6 +23,9 @@
* 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"