128 lines
No EOL
4 KiB
C++
128 lines
No EOL
4 KiB
C++
/*
|
|
Copyright (c) 2014 NicoHood
|
|
See the readme for credit to other people.
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
THE SOFTWARE.
|
|
*/
|
|
|
|
#ifndef __USBAPI__
|
|
#define __USBAPI__
|
|
|
|
#if defined(USBCON)
|
|
|
|
//================================================================================
|
|
//================================================================================
|
|
// USB
|
|
|
|
class USBDevice_
|
|
{
|
|
public:
|
|
USBDevice_();
|
|
bool configured();
|
|
|
|
void attach();
|
|
void detach(); // Serial port goes down too...
|
|
void poll();
|
|
};
|
|
extern USBDevice_ USBDevice;
|
|
|
|
//================================================================================
|
|
//================================================================================
|
|
// Serial over CDC (Serial1 is the physical port)
|
|
|
|
class Serial_ : public Stream
|
|
{
|
|
private:
|
|
ring_buffer *_cdc_rx_buffer;
|
|
public:
|
|
void begin(uint16_t baud_count);
|
|
void end(void);
|
|
|
|
virtual int available(void);
|
|
virtual void accept(void);
|
|
virtual int peek(void);
|
|
virtual int read(void);
|
|
virtual void flush(void);
|
|
virtual size_t write(uint8_t);
|
|
using Print::write; // pull in write(str) and write(buf, size) from Print
|
|
operator bool();
|
|
};
|
|
extern Serial_ Serial;
|
|
|
|
//================================================================================
|
|
//================================================================================
|
|
// Low level API
|
|
|
|
typedef struct
|
|
{
|
|
uint8_t bmRequestType;
|
|
uint8_t bRequest;
|
|
uint8_t wValueL;
|
|
uint8_t wValueH;
|
|
uint16_t wIndex;
|
|
uint16_t wLength;
|
|
} Setup;
|
|
|
|
//================================================================================
|
|
//================================================================================
|
|
// HID 'Driver'
|
|
|
|
#include "HID.h"
|
|
|
|
int HID_GetInterface(uint8_t* interfaceNum);
|
|
int HID_GetDescriptor(int i);
|
|
bool HID_Setup(Setup& setup);
|
|
void HID_SendReport(uint8_t id, const void* data, int len);
|
|
|
|
//================================================================================
|
|
//================================================================================
|
|
// MSC 'Driver'
|
|
|
|
int MSC_GetInterface(uint8_t* interfaceNum);
|
|
int MSC_GetDescriptor(int i);
|
|
bool MSC_Setup(Setup& setup);
|
|
bool MSC_Data(uint8_t rx,uint8_t tx);
|
|
|
|
//================================================================================
|
|
//================================================================================
|
|
// CSC 'Driver'
|
|
|
|
int CDC_GetInterface(uint8_t* interfaceNum);
|
|
int CDC_GetDescriptor(int i);
|
|
bool CDC_Setup(Setup& setup);
|
|
|
|
//================================================================================
|
|
//================================================================================
|
|
|
|
#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);
|
|
|
|
#endif
|
|
|
|
#endif /* if defined(USBCON) */ |