1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01: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

@ -11,6 +11,8 @@ arduino_due_u.build.extra_flags=-D__SAM3U4E__ -mthumb
arduino_due_u.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_u.build.variant=arduino_due_u
arduino_due_u.build.variant_system_lib=libsam_sam3u4e_gcc_rel.a
arduino_due_u.build.vid=0x2341
arduino_due_u.build.pid=0xcafe
##############################################################
@ -25,3 +27,5 @@ arduino_due_x.build.extra_flags=-D__SAM3X8E__ -mthumb
arduino_due_x.build.ldscript=linker_scripts/gcc/flash.ld
arduino_due_x.build.variant=arduino_due_x
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
modify it under the terms of the GNU Lesser General Public
@ -198,4 +198,16 @@ 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 0xcafe
#include "USBDesc.h"
#include "USBCore.h"
#include "USBAPI.h"
#endif // if defined USBCON
#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,5 +1,3 @@
/* Copyright (c) 2011, Peter Barrett
**
** Permission to use, copy, modify, and/or distribute this software for
@ -16,22 +14,17 @@
** SOFTWARE.
*/
#include "Arduino.h"
#if defined(USBCON)
#include "Platform.h"
#include "USBAPI.h"
#include <avr/wdt.h>
#ifdef CDC_ENABLED
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 64
#endif
#define CDC_SERIAL_BUFFER_SIZE 64
struct ring_buffer
{
unsigned char buffer[SERIAL_BUFFER_SIZE];
unsigned char buffer[CDC_SERIAL_BUFFER_SIZE];
volatile int head;
volatile int tail;
};
@ -40,19 +33,16 @@ ring_buffer cdc_rx_buffer = { { 0 }, 0, 0};
typedef struct
{
u32 dwDTERate;
u8 bCharFormat;
u8 bParityType;
u8 bDataBits;
u8 lineState;
uint32_t dwDTERate;
uint8_t bCharFormat;
uint8_t bParityType;
uint8_t bDataBits;
uint8_t lineState;
} LineInfo;
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
#define WEAK __attribute__ ((weak))
extern const CDCDescriptor _cdcInterface PROGMEM;
const CDCDescriptor _cdcInterface =
static const CDCDescriptor _cdcInterface =
{
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)
};
int WEAK CDC_GetInterface(u8* interfaceNum)
int WEAK CDC_GetInterface(uint8_t* interfaceNum)
{
interfaceNum[0] += 2; // uses 2
return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
@ -78,8 +68,8 @@ int WEAK CDC_GetInterface(u8* interfaceNum)
bool WEAK CDC_Setup(Setup& setup)
{
u8 r = setup.bRequest;
u8 requestType = setup.bmRequestType;
uint8_t r = setup.bRequest;
uint8_t requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
{
@ -108,18 +98,24 @@ bool WEAK CDC_Setup(Setup& setup)
// like servicing endpoints before the sketch ends
if (1200 == _usbLineInfo.dwDTERate) {
// 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;
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
// cancel if DTR goes back high.
/* TODO, AVR Stuff
wdt_disable();
wdt_reset();
*(uint16_t *)0x0800 = 0x0;
*/
}
}
return true;

View File

@ -1,5 +1,3 @@
/* Copyright (c) 2011, Peter Barrett
**
** Permission to use, copy, modify, and/or distribute this software for
@ -16,11 +14,7 @@
** SOFTWARE.
*/
#define USBCON
#include "Platform.h"
#include "USBAPI.h"
#include "USBDesc.h"
#include "Arduino.h"
#if defined(USBCON)
#ifdef HID_ENABLED
@ -45,7 +39,7 @@ Keyboard_ Keyboard;
#define RAWHID_TX_SIZE 64
#define RAWHID_RX_SIZE 64
extern const u8 _hidReportDescriptor[] = {
extern const uint8_t _hidReportDescriptor[] = {
// Mouse
0x05, 0x01, // USAGE_PAGE (Generic Desktop) // 54
0x09, 0x02, // USAGE (Mouse)
@ -139,12 +133,12 @@ extern const HIDDescriptor _hidInterface =
//================================================================================
// Driver
u8 _hid_protocol = 1;
u8 _hid_idle = 1;
uint8_t _hid_protocol = 1;
uint8_t _hid_idle = 1;
#define WEAK __attribute__ ((weak))
int WEAK HID_GetInterface(u8* interfaceNum)
int WEAK HID_GetInterface(uint8_t* interfaceNum)
{
interfaceNum[0] += 1; // uses 1
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));
}
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 | 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)
{
u8 r = setup.bRequest;
u8 requestType = setup.bmRequestType;
uint8_t r = setup.bRequest;
uint8_t requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
{
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)
{
u8 m[4];
uint8_t m[4];
m[0] = _buttons;
m[1] = x;
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__
#define __USBAPI__
#if defined(USBCON)
#if defined __cplusplus && defined USBCON
//================================================================================
//================================================================================
@ -192,4 +208,4 @@ void USB_Flush(uint8_t ep);
#endif
#endif /* if defined(USBCON) */
#endif /* if defined USBCON */

View File

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

View File

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

View File

@ -74,6 +74,9 @@ endif
include $(TOOLCHAIN).mk
CFLAGS += -DUSB_VID=0x2341 -DUSB_PID=0xcafe
CPPFLAGS += -DUSB_VID=0x2341 -DUSB_PID=0xcafe
#-------------------------------------------------------------------------------
ifdef DEBUG
OUTPUT_OBJ=debug
@ -155,12 +158,12 @@ create_output:
-@mkdir $(OUTPUT_PATH) 1>NUL 2>&1
$(addprefix $(OUTPUT_PATH)/,$(C_OBJ)): $(OUTPUT_PATH)/%.o: %.c
# @"$(CC)" -v -c $(CFLAGS) $< -o $@
# "$(CC)" -v -c $(CFLAGS) $< -o $@
@"$(CC)" -c $(CFLAGS) $< -o $@
$(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
@"$(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_OUT (UOTGHS_DEVEPTCFG_EPSIZE_1024_BYTE | UOTGHS_DEVEPTCFG_EPTYPE_ISO | UOTGHS_DEVEPTCFG_EPBK_3_BANK)
#endif /* UOTGHS_H_INCLUDED */

View File

@ -20,8 +20,24 @@
#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)

View File

@ -23,6 +23,9 @@
* Headers
*----------------------------------------------------------------------------*/
// We have native USB on this variant
#define USBCON
#include "Arduino.h"
#ifdef __cplusplus
#include "UARTClass.h"