2014-09-12 12:27:39 +02:00
|
|
|
/*
|
|
|
|
USBAPI.h
|
|
|
|
Copyright (c) 2005-2014 Arduino. All right reserved.
|
2011-08-11 14:08:38 -04:00
|
|
|
|
2014-09-12 12:27:39 +02:00
|
|
|
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
|
|
|
|
*/
|
2011-08-11 14:08:38 -04:00
|
|
|
|
|
|
|
#ifndef __USBAPI__
|
|
|
|
#define __USBAPI__
|
|
|
|
|
2014-09-12 12:27:39 +02:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
#include <avr/eeprom.h>
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
|
|
|
|
typedef unsigned char u8;
|
|
|
|
typedef unsigned short u16;
|
|
|
|
typedef unsigned long u32;
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
2011-08-30 11:50:08 -04:00
|
|
|
#if defined(USBCON)
|
|
|
|
|
2014-09-12 12:27:39 +02:00
|
|
|
#include "USBDesc.h"
|
|
|
|
#include "USBCore.h"
|
|
|
|
|
2011-08-11 14:08:38 -04:00
|
|
|
//================================================================================
|
|
|
|
//================================================================================
|
|
|
|
// USB
|
|
|
|
|
2015-06-05 17:34:56 +02:00
|
|
|
#define EP_TYPE_CONTROL 0x00
|
|
|
|
#define EP_TYPE_BULK_IN 0x81
|
|
|
|
#define EP_TYPE_BULK_OUT 0x80
|
|
|
|
#define EP_TYPE_INTERRUPT_IN 0xC1
|
|
|
|
#define EP_TYPE_INTERRUPT_OUT 0xC0
|
|
|
|
#define EP_TYPE_ISOCHRONOUS_IN 0x41
|
|
|
|
#define EP_TYPE_ISOCHRONOUS_OUT 0x40
|
|
|
|
|
2012-05-01 11:18:15 -04:00
|
|
|
class USBDevice_
|
2011-08-11 14:08:38 -04:00
|
|
|
{
|
|
|
|
public:
|
2012-05-01 11:18:15 -04:00
|
|
|
USBDevice_();
|
2011-08-11 14:08:38 -04:00
|
|
|
bool configured();
|
|
|
|
|
|
|
|
void attach();
|
|
|
|
void detach(); // Serial port goes down too...
|
|
|
|
void poll();
|
2015-06-26 15:05:57 +02:00
|
|
|
bool wakeupHost(); // returns false, when wakeup cannot be processed
|
2011-08-11 14:08:38 -04:00
|
|
|
};
|
2012-05-01 11:18:15 -04:00
|
|
|
extern USBDevice_ USBDevice;
|
2011-08-11 14:08:38 -04:00
|
|
|
|
|
|
|
//================================================================================
|
|
|
|
//================================================================================
|
|
|
|
// Serial over CDC (Serial1 is the physical port)
|
|
|
|
|
2013-07-26 12:50:17 +02:00
|
|
|
struct ring_buffer;
|
|
|
|
|
2015-02-02 20:27:17 +01:00
|
|
|
#ifndef SERIAL_BUFFER_SIZE
|
2013-07-27 12:06:42 +02:00
|
|
|
#if (RAMEND < 1000)
|
|
|
|
#define SERIAL_BUFFER_SIZE 16
|
|
|
|
#else
|
|
|
|
#define SERIAL_BUFFER_SIZE 64
|
|
|
|
#endif
|
2015-02-02 20:27:17 +01:00
|
|
|
#endif
|
|
|
|
#if (SERIAL_BUFFER_SIZE>256)
|
|
|
|
#error Please lower the CDC Buffer size
|
|
|
|
#endif
|
2013-07-27 12:06:42 +02:00
|
|
|
|
2011-08-11 14:08:38 -04:00
|
|
|
class Serial_ : public Stream
|
|
|
|
{
|
2011-12-18 17:52:35 -05:00
|
|
|
private:
|
2014-06-19 16:52:48 +02:00
|
|
|
int peek_buffer;
|
2011-08-11 14:08:38 -04:00
|
|
|
public:
|
2014-06-19 16:52:48 +02:00
|
|
|
Serial_() { peek_buffer = -1; };
|
2013-09-02 18:58:28 +01:00
|
|
|
void begin(unsigned long);
|
2013-09-02 19:15:12 +01:00
|
|
|
void begin(unsigned long, uint8_t);
|
2011-08-11 14:08:38 -04:00
|
|
|
void end(void);
|
|
|
|
|
|
|
|
virtual int available(void);
|
|
|
|
virtual int peek(void);
|
|
|
|
virtual int read(void);
|
|
|
|
virtual void flush(void);
|
2011-08-30 11:04:34 -04:00
|
|
|
virtual size_t write(uint8_t);
|
2014-03-18 14:15:41 -07:00
|
|
|
virtual size_t write(const uint8_t*, size_t);
|
2012-06-14 15:53:27 +01:00
|
|
|
using Print::write; // pull in write(str) and write(buf, size) from Print
|
2012-04-01 12:54:35 -04:00
|
|
|
operator bool();
|
2013-07-27 12:06:42 +02:00
|
|
|
|
|
|
|
volatile uint8_t _rx_buffer_head;
|
|
|
|
volatile uint8_t _rx_buffer_tail;
|
|
|
|
unsigned char _rx_buffer[SERIAL_BUFFER_SIZE];
|
2011-08-11 14:08:38 -04:00
|
|
|
};
|
|
|
|
extern Serial_ Serial;
|
|
|
|
|
2013-12-01 17:21:54 +01:00
|
|
|
#define HAVE_CDCSERIAL
|
|
|
|
|
2011-08-11 14:08:38 -04:00
|
|
|
//================================================================================
|
|
|
|
//================================================================================
|
2015-06-05 17:33:38 +02:00
|
|
|
// Low level API
|
2011-08-11 14:08:38 -04:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t bmRequestType;
|
|
|
|
uint8_t bRequest;
|
|
|
|
uint8_t wValueL;
|
|
|
|
uint8_t wValueH;
|
|
|
|
uint16_t wIndex;
|
|
|
|
uint16_t wLength;
|
2015-07-01 16:56:14 +02:00
|
|
|
} USBSetup;
|
2011-08-11 14:08:38 -04:00
|
|
|
|
|
|
|
//================================================================================
|
|
|
|
//================================================================================
|
|
|
|
// MSC 'Driver'
|
|
|
|
|
|
|
|
int MSC_GetInterface(uint8_t* interfaceNum);
|
|
|
|
int MSC_GetDescriptor(int i);
|
2015-07-01 16:56:14 +02:00
|
|
|
bool MSC_Setup(USBSetup& setup);
|
2011-08-11 14:08:38 -04:00
|
|
|
bool MSC_Data(uint8_t rx,uint8_t tx);
|
|
|
|
|
|
|
|
//================================================================================
|
|
|
|
//================================================================================
|
|
|
|
// CSC 'Driver'
|
|
|
|
|
|
|
|
int CDC_GetInterface(uint8_t* interfaceNum);
|
|
|
|
int CDC_GetDescriptor(int i);
|
2015-07-01 16:56:14 +02:00
|
|
|
bool CDC_Setup(USBSetup& setup);
|
2011-08-11 14:08:38 -04:00
|
|
|
|
|
|
|
//================================================================================
|
|
|
|
//================================================================================
|
|
|
|
|
|
|
|
#define TRANSFER_PGM 0x80
|
|
|
|
#define TRANSFER_RELEASE 0x40
|
|
|
|
#define TRANSFER_ZERO 0x20
|
|
|
|
|
|
|
|
int USB_SendControl(uint8_t flags, const void* d, int len);
|
|
|
|
int USB_RecvControl(void* d, int len);
|
|
|
|
|
|
|
|
uint8_t USB_Available(uint8_t ep);
|
|
|
|
int USB_Send(uint8_t ep, const void* data, int len); // blocking
|
|
|
|
int USB_Recv(uint8_t ep, void* data, int len); // non-blocking
|
|
|
|
int USB_Recv(uint8_t ep); // non-blocking
|
|
|
|
void USB_Flush(uint8_t ep);
|
|
|
|
|
2011-08-30 11:50:08 -04:00
|
|
|
#endif
|
|
|
|
|
2013-07-26 12:50:17 +02:00
|
|
|
#endif /* if defined(USBCON) */
|