Starting from a clean 1.5.8 USB API

This commit is contained in:
Nico 2014-11-21 18:37:15 +01:00
parent 05643a2145
commit daa80ec7bf
31 changed files with 2015 additions and 3758 deletions

211
CDC.cpp Normal file
View file

@ -0,0 +1,211 @@
/* 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
** 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
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/
#include "USBAPI.h"
#include <avr/wdt.h>
#if defined(USBCON)
#ifdef CDC_ENABLED
typedef struct
{
u32 dwDTERate;
u8 bCharFormat;
u8 bParityType;
u8 bDataBits;
u8 lineState;
} LineInfo;
static volatile LineInfo _usbLineInfo = { 57600, 0x00, 0x00, 0x00, 0x00 };
#define WEAK __attribute__ ((weak))
extern const CDCDescriptor _cdcInterface PROGMEM;
const CDCDescriptor _cdcInterface =
{
D_IAD(0,2,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,1),
// CDC communication interface
D_INTERFACE(CDC_ACM_INTERFACE,1,CDC_COMMUNICATION_INTERFACE_CLASS,CDC_ABSTRACT_CONTROL_MODEL,0),
D_CDCCS(CDC_HEADER,0x10,0x01), // Header (1.10 bcd)
D_CDCCS(CDC_CALL_MANAGEMENT,1,1), // Device handles call management (not)
D_CDCCS4(CDC_ABSTRACT_CONTROL_MANAGEMENT,6), // SET_LINE_CODING, GET_LINE_CODING, SET_CONTROL_LINE_STATE supported
D_CDCCS(CDC_UNION,CDC_ACM_INTERFACE,CDC_DATA_INTERFACE), // Communication interface is master, data interface is slave 0
D_ENDPOINT(USB_ENDPOINT_IN (CDC_ENDPOINT_ACM),USB_ENDPOINT_TYPE_INTERRUPT,0x10,0x40),
// CDC data interface
D_INTERFACE(CDC_DATA_INTERFACE,2,CDC_DATA_INTERFACE_CLASS,0,0),
D_ENDPOINT(USB_ENDPOINT_OUT(CDC_ENDPOINT_OUT),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)
{
interfaceNum[0] += 2; // uses 2
return USB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
}
bool WEAK CDC_Setup(Setup& setup)
{
u8 r = setup.bRequest;
u8 requestType = setup.bmRequestType;
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
{
if (CDC_GET_LINE_CODING == r)
{
USB_SendControl(0,(void*)&_usbLineInfo,7);
return true;
}
}
if (REQUEST_HOSTTODEVICE_CLASS_INTERFACE == requestType)
{
if (CDC_SET_LINE_CODING == r)
{
USB_RecvControl((void*)&_usbLineInfo,7);
}
if (CDC_SET_CONTROL_LINE_STATE == r)
{
_usbLineInfo.lineState = setup.wValueL;
}
if (CDC_SET_LINE_CODING == r || CDC_SET_CONTROL_LINE_STATE == r)
{
// 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
// with a relatively long period so it can finish housekeeping tasks
// like servicing endpoints before the sketch ends
// We check DTR state to determine if host port is open (bit 0 of lineState).
if (1200 == _usbLineInfo.dwDTERate && (_usbLineInfo.lineState & 0x01) == 0)
{
*(uint16_t *)0x0800 = 0x7777;
wdt_enable(WDTO_120MS);
}
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.
wdt_disable();
wdt_reset();
*(uint16_t *)0x0800 = 0x0;
}
}
return true;
}
return false;
}
void Serial_::begin(unsigned long /* baud_count */)
{
peek_buffer = -1;
}
void Serial_::begin(unsigned long /* baud_count */, byte /* config */)
{
peek_buffer = -1;
}
void Serial_::end(void)
{
}
int Serial_::available(void)
{
if (peek_buffer >= 0) {
return 1 + USB_Available(CDC_RX);
}
return USB_Available(CDC_RX);
}
int Serial_::peek(void)
{
if (peek_buffer < 0)
peek_buffer = USB_Recv(CDC_RX);
return peek_buffer;
}
int Serial_::read(void)
{
if (peek_buffer >= 0) {
int c = peek_buffer;
peek_buffer = -1;
return c;
}
return USB_Recv(CDC_RX);
}
void Serial_::flush(void)
{
USB_Flush(CDC_TX);
}
size_t Serial_::write(uint8_t c)
{
return write(&c, 1);
}
size_t Serial_::write(const uint8_t *buffer, size_t size)
{
/* 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 opened and clear lineState when the port is closed.
bytes sent before the user opens the connection or after
the connection is closed are lost - just like with a UART. */
// 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
// or locks up, or host virtual serial port hangs)
if (_usbLineInfo.lineState > 0) {
int r = USB_Send(CDC_TX,buffer,size);
if (r > 0) {
return r;
} else {
setWriteError();
return 0;
}
}
setWriteError();
return 0;
}
// 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
// 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
// actually ready to receive and display the data.
// 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.
Serial_::operator bool() {
bool result = false;
if (_usbLineInfo.lineState > 0)
result = true;
delay(10);
return result;
}
Serial_ Serial;
#endif
#endif /* if defined(USBCON) */

View file

@ -1,71 +0,0 @@
;************************************************************
; Windows USB CDC ACM Setup File
; Copyright (c) 2000 Microsoft Corporation
;************************************************************
[DefaultInstall]
CopyINF="Hoodloader.inf"
[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%MFGNAME%
DriverVer=7/1/2012,10.0.0.0
[Manufacturer]
%MFGNAME%=DeviceList, NTx86, NTamd64, NTia64
[SourceDisksNames]
[SourceDisksFiles]
[DestinationDirs]
DefaultDestDir=12
[DriverInstall]
Include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection
AddReg=DriverInstall.AddReg
[DriverInstall.Services]
Include=mdmcpq.inf
AddService=usbser, 0x00000002, LowerFilter_Service_Inst
[DriverInstall.AddReg]
HKR,,EnumPropPages32,,"msports.dll,SerialPortPropPageProvider"
;------------------------------------------------------------------------------
; Vendor and Product ID Definitions
;------------------------------------------------------------------------------
; When developing your USB device, the VID and PID used in the PC side
; application program and the firmware on the microcontroller must match.
; Modify the below line to use your VID and PID. Use the format as shown below.
; Note: One INF file can be used for multiple devices with different VID and PIDs.
; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line.
;------------------------------------------------------------------------------
[DeviceList]
%hoodloader.name%=DriverInstall, USB\VID_03EB&PID_6E68&MI_00
%hoodloader-lite.name%=DriverInstall, USB\VID_03EB&PID_4E48&MI_00
[DeviceList.NTx86]
%hoodloader.name%=DriverInstall, USB\VID_03EB&PID_6E68&MI_00
%hoodloader-lite.name%=DriverInstall, USB\VID_03EB&PID_4E48&MI_00
[DeviceList.NTamd64]
%hoodloader.name%=DriverInstall, USB\VID_03EB&PID_6E68&MI_00
%hoodloader-lite.name%=DriverInstall, USB\VID_03EB&PID_4E48&MI_00
[DeviceList.NTia64]
%hoodloader.name%=DriverInstall, USB\VID_03EB&PID_6E68&MI_00
%hoodloader-lite.name%=DriverInstall, USB\VID_03EB&PID_4E48&MI_00
;------------------------------------------------------------------------------
; String Definitions
;------------------------------------------------------------------------------
;Modify these strings to customize your device
;------------------------------------------------------------------------------
[Strings]
MFGNAME="NicoHood"
hoodloader.name="Arduino Hoodloader"
hoodloader-lite.name="Arduino Hoodloader-Lite"

View file

@ -1,7 +0,0 @@
Firmwares
=========
[**See installing instructions on the Hoodloader repository**](https://github.com/NicoHood/Hoodloader)
You can also get the latest Hoodloader version or the dev version from this repository (select dev branch).
There are also other/older versions of the Hoodloader and the Lite Version for 8u2. The original firmware can also be found there.

View file

@ -1,98 +0,0 @@
/*
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 GAMEPAD_H
#define GAMEPAD_H
#include "HID.h"
//================================================================================
// HID
//================================================================================
void HID_SendReport(uint8_t id, const void* data, int len);
//================================================================================
// Gamepad
//================================================================================
#define GAMEPAD_DPAD_CENTERED 0
#define GAMEPAD_DPAD_UP 1
#define GAMEPAD_DPAD_UP_RIGHT 2
#define GAMEPAD_DPAD_RIGHT 3
#define GAMEPAD_DPAD_DOWN_RIGHT 4
#define GAMEPAD_DPAD_DOWN 5
#define GAMEPAD_DPAD_DOWN_LEFT 6
#define GAMEPAD_DPAD_LEFT 7
#define GAMEPAD_DPAD_UP_LEFT 8
class Gamepad{
public:
inline Gamepad(uint8_t num){
switch (num){
case 1:
_reportID = HID_REPORTID_Gamepad1Report;
break;
case 2:
_reportID = HID_REPORTID_Gamepad2Report;
break;
case 3:
_reportID = HID_REPORTID_Gamepad3Report;
break;
case 4:
_reportID = HID_REPORTID_Gamepad4Report;
break;
default:
_reportID = HID_REPORTID_NotAReport;
break;
}
}
inline void begin(void){
memset(&_report, 0, sizeof(_report));
HID_SendReport(_reportID, &_report, sizeof(_report));
}
inline void end(void){ begin(); }
inline void write(void){ HID_SendReport(_reportID, &_report, sizeof(_report)); }
inline void press(uint8_t b){ _report.buttons |= (uint32_t)1 << (b - 1); }
inline void release(uint8_t b){ _report.buttons &= ~((uint32_t)1 << (b - 1)); }
inline void releaseAll(void){ memset(&_report, 0x00, sizeof(_report)); }
inline void buttons(uint32_t b){ _report.buttons = b; }
inline void xAxis(int16_t a){ _report.xAxis = a; }
inline void yAxis(int16_t a){ _report.yAxis = a; }
inline void zAxis(int8_t a){ _report.zAxis = a; }
inline void rxAxis(int16_t a){ _report.rxAxis = a; }
inline void ryAxis(int16_t a){ _report.ryAxis = a; }
inline void rzAxis(int8_t a){ _report.rzAxis = a; }
inline void dPad1(int8_t d){ _report.dPad1 = d; }
inline void dPad2(int8_t d){ _report.dPad2 = d; }
private:
HID_GamepadReport_Data_t _report;
uint8_t _reportID;
};
#endif

989
HID.cpp

File diff suppressed because it is too large Load diff

141
HID.h
View file

@ -1,141 +0,0 @@
/*
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 HID_H
#define HID_H
#include <Arduino.h>
// HID Resources
#include "HID_Reports.h"
#include "RawHID.h"
#include "Media.h"
#include "System.h"
#include "Gamepad.h"
#include "Keyboard.h"
#include "Mouse.h"
//================================================================================
//Settings
//================================================================================
// deactive unnecessary stuff for Leonardo/Micro
// reports needs to be <=255 bytes for leonardo/micro!
#define HID_MOUSE_ENABLE 54
#define HID_KEYBOARD_ENABLE 65-18 //18 for missing led out report = 47
//#define HID_RAWKEYBOARD_ENABLE 30
#define HID_MEDIA_ENABLE 25
#define HID_SYSTEM_ENABLE 24
#define HID_GAMEPAD1_ENABLE 71
//#define HID_GAMEPAD2_ENABLE 71
//#define HID_GAMEPAD3_ENABLE 71
//#define HID_GAMEPAD4_ENABLE 71
//#define HID_JOYSTICK1_ENABLE 51
//#define HID_JOYSTICK2_ENABLE 51
// extra delay for raspberry. Only needed for Hoodloader and slow devices
//#define HID_EXTRADELAY 20
//================================================================================
// NHP
//================================================================================
// Start Mask
#define NHP_MASK_START 0xC0 //B11|000000 the two MSB bits
#define NHP_MASK_LEAD 0xC0 //B11|000000
#define NHP_MASK_DATA 0x00 //B0|0000000 only the first MSB is important
#define NHP_MASK_END 0x80 //B10|000000
// Content Mask
#define NHP_MASK_LENGTH 0x38 //B00|111|000
#define NHP_MASK_COMMAND 0x0F //B0000|1111
#define NHP_MASK_DATA_7BIT 0x7F //B0|1111111
#define NHP_MASK_DATA_4BIT 0x0F //B0000|1111
#define NHP_MASK_DATA_3BIT 0x07 //B00000|111
#define NHP_MASK_ADDRESS 0x3F //B00|111111
// Reserved Addresses
#define NHP_ADDRESS_CONTROL 0x01
// Reserved Usages
#define NHP_USAGE_ARDUINOHID 0x01
// Serial to write Protocol data to. Default: Serial
#define HID_SERIAL Serial
#define SERIAL_HID_BAUD 115200
void NHPwriteChecksum(uint8_t address, uint16_t indata);
//================================================================================
// Keyboard Definitions
//================================================================================
//Keyboard fixed/added missing Keys
#define KEY_PRINT 0xCE
#define KEY_SCROLL_LOCK 0xCF
#define KEY_PAUSE 0xD0
//Raw Keyboard definitions
#define RAW_KEYBOARD_LEFT_CTRL B00000001
#define RAW_KEYBOARD_LEFT_SHIFT B00000010
#define RAW_KEYBOARD_LEFT_ALT B00000100
#define RAW_KEYBOARD_LEFT_GUI B00001000
#define RAW_KEYBOARD_RIGHT_CTRL B00010000
#define RAW_KEYBOARD_RIGHT_SHIFT B00100000
#define RAW_KEYBOARD_RIGHT_ALT B01000000
#define RAW_KEYBOARD_RIGHT_GUI B10000000
#define RAW_KEYBOARD_UP_ARROW 0x52
#define RAW_KEYBOARD_DOWN_ARROW 0x51
#define RAW_KEYBOARD_LEFT_ARROW 0x50
#define RAW_KEYBOARD_RIGHT_ARROW 0x4F
#define RAW_KEYBOARD_SPACEBAR 0x2C
#define RAW_KEYBOARD_BACKSPACE 0x2A
#define RAW_KEYBOARD_TAB 0x2B
#define RAW_KEYBOARD_RETURN 0x28
#define RAW_KEYBOARD_ESC 0x29
#define RAW_KEYBOARD_INSERT 0x49
#define RAW_KEYBOARD_DELETE 0x4C
#define RAW_KEYBOARD_PAGE_UP 0x4B
#define RAW_KEYBOARD_PAGE_DOWN 0x4E
#define RAW_KEYBOARD_HOME 0x4A
#define RAW_KEYBOARD_END 0x4D
#define RAW_KEYBOARD_CAPS_LOCK 0x39
#define RAW_KEYBOARD_F1 0x3A
#define RAW_KEYBOARD_F2 0x3B
#define RAW_KEYBOARD_F3 0x3C
#define RAW_KEYBOARD_F4 0x3D
#define RAW_KEYBOARD_F5 0x3E
#define RAW_KEYBOARD_F6 0x3F
#define RAW_KEYBOARD_F7 0x40
#define RAW_KEYBOARD_F8 0x41
#define RAW_KEYBOARD_F9 0x42
#define RAW_KEYBOARD_F10 0x43
#define RAW_KEYBOARD_F11 0x44
#define RAW_KEYBOARD_F12 0x45
#define RAW_KEYBOARD_PRINT 0x46
#define RAW_KEYBOARD_SCROLL_LOCK 0x47
#define RAW_KEYBOARD_PAUSE 0x48
#endif

View file

@ -1,208 +0,0 @@
/*
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 HID_REPORTS_H
#define HID_REPORTS_H
//================================================================================
//Definitions
//================================================================================
#define LSB(_x) ((_x) & 0xFF)
#define MSB(_x) ((_x) >> 8)
#define RAWHID_USAGE_PAGE 0xFFC0 // recommended: 0xFF00 to 0xFFFF
#define RAWHID_USAGE 0x0C00 // recommended: 0x0100 to 0xFFFF
#define RAWHID_TX_SIZE 15 // 1 byte for report ID
#define RAWHID_RX_SIZE 15 // 1 byte for report ID
//================================================================================
//Report Typedefinitions
//================================================================================
typedef union{
// mouse report: 5 buttons, position, wheel
uint8_t whole8[4];
uint16_t whole16[4/2];
uint32_t whole32[4/4];
struct{
uint8_t buttons:5;
uint8_t reserved:3;
int8_t xAxis;
int8_t yAxis;
int8_t wheel;
};
} HID_MouseReport_Data_t;
typedef union{
// Low level key report: up to 6 keys and shift, ctrl etc at once
uint8_t whole8[8];
uint16_t whole16[8/2];
uint32_t whole32[8/4];
struct{
uint8_t modifiers;
uint8_t reserved;
uint8_t keys[6];
};
} HID_KeyboardReport_Data_t;
typedef union{
// a 32 byte buffer for rx or tx
uint8_t whole8[RAWHID_TX_SIZE];
uint16_t whole16[RAWHID_TX_SIZE / 2];
uint32_t whole32[RAWHID_TX_SIZE / 4];
uint8_t buff[RAWHID_TX_SIZE];
} HID_RawKeyboardReport_Data_t;
typedef union{
// every usable media key possible. Only one at the same time.
uint8_t whole8[8];
uint16_t whole16[8/2];
uint32_t whole32[8/4];
struct{
uint16_t key1;
uint16_t key2;
uint16_t key3;
uint16_t key4;
};
} HID_MediaReport_Data_t;
typedef union{
// every usable system control key possible. Only one at the same time.
uint8_t whole8[1];
uint8_t key;
} HID_SystemReport_Data_t;
typedef union {
// 32 Buttons, 6 Axis, 2 D-Pads
uint8_t whole8[15];
uint16_t whole16[15/2];
uint32_t whole32[15/4];
uint32_t buttons;
struct{
uint8_t button1 :1;
uint8_t button2 :1;
uint8_t button3 :1;
uint8_t button4 :1;
uint8_t button5 :1;
uint8_t button6 :1;
uint8_t button7 :1;
uint8_t button8 :1;
uint8_t button9 :1;
uint8_t button10 :1;
uint8_t button11 :1;
uint8_t button12 :1;
uint8_t button13 :1;
uint8_t button14 :1;
uint8_t button15 :1;
uint8_t button16 :1;
uint8_t button17 :1;
uint8_t button18 :1;
uint8_t button19 :1;
uint8_t button20 :1;
uint8_t button21 :1;
uint8_t button22 :1;
uint8_t button23 :1;
uint8_t button24 :1;
uint8_t button25 :1;
uint8_t button26 :1;
uint8_t button27 :1;
uint8_t button28 :1;
uint8_t button29 :1;
uint8_t button30 :1;
uint8_t button31 :1;
uint8_t button32 :1;
int16_t xAxis;
int16_t yAxis;
int16_t rxAxis;
int16_t ryAxis;
int8_t zAxis;
int8_t rzAxis;
uint8_t dPad1: 4;
uint8_t dPad2: 4;
};
} HID_GamepadReport_Data_t;
typedef union{
// 2 Buttons, 2 Axis
uint8_t whole8[3];
uint16_t whole16[3/2];
uint8_t buttons :2;
struct{
uint16_t button1 :1;
uint16_t button2 :1;
uint16_t xAxis :10;
uint16_t yAxis :10;
uint16_t reserved :2;
};
} HID_JoystickReport_Data_t;
typedef union{
HID_MouseReport_Data_t Mouse;
HID_KeyboardReport_Data_t Keyboard;
HID_RawKeyboardReport_Data_t RawKeyboard;
HID_MediaReport_Data_t Media;
HID_GamepadReport_Data_t Gamepad1;
HID_GamepadReport_Data_t Gamepad2;
HID_JoystickReport_Data_t Joystick1;
HID_JoystickReport_Data_t Joystick2;
} HID_HIDReport_Data_t;
/** Enum for the HID report IDs used in the device. */
typedef enum{
HID_REPORTID_NotAReport = 0x00, // first entry is always zero for multireports
HID_REPORTID_MouseReport = 0x01, /**< Report ID for the Mouse report within the device. */
HID_REPORTID_KeyboardReport = 0x02, /**< Report ID for the Keyboard report within the device. */
HID_REPORTID_RawKeyboardReport = 0x03, /**< Report ID for the Raw Keyboard report within the device. */
HID_REPORTID_MediaReport = 0x04, /**< Report ID for the Media report within the device. */
HID_REPORTID_SystemReport = 0x05, /**< Report ID for the Power report within the device. */
HID_REPORTID_Gamepad1Report = 0x06, /**< Report ID for the Gamepad1 report within the device. */
HID_REPORTID_Gamepad2Report = 0x07, /**< Report ID for the Gamepad2 report within the device. */
HID_REPORTID_Gamepad3Report = 0x08, /**< Report ID for the Gamepad3 report within the device. */
HID_REPORTID_Gamepad4Report = 0x09, /**< Report ID for the Gamepad4 report within the device. */
HID_REPORTID_Joystick1Report = 0x10, /**< Report ID for the Joystick1 report within the device. */
HID_REPORTID_Joystick2Report = 0x11, /**< Report ID for the Joystick2 report within the device. */
HID_REPORTID_LastNotAReport, // determinate whats the maximum number of reports -1
} HID_Report_IDs;
#endif

View file

@ -1,291 +0,0 @@
/*
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.
*/
#include "Keyboard.h"
#include "Platform.h"
//================================================================================
// Keyboard
//================================================================================
extern
const uint8_t _asciimap[128] PROGMEM;
#define SHIFT 0x80
const uint8_t _asciimap[128] =
{
0x00, // NUL
0x00, // SOH
0x00, // STX
0x00, // ETX
0x00, // EOT
0x00, // ENQ
0x00, // ACK
0x00, // BEL
0x2a, // BS Backspace
0x2b, // TAB Tab
0x28, // LF Enter
0x00, // VT
0x00, // FF
0x00, // CR
0x00, // SO
0x00, // SI
0x00, // DEL
0x00, // DC1
0x00, // DC2
0x00, // DC3
0x00, // DC4
0x00, // NAK
0x00, // SYN
0x00, // ETB
0x00, // CAN
0x00, // EM
0x00, // SUB
0x00, // ESC
0x00, // FS
0x00, // GS
0x00, // RS
0x00, // US
0x2c, // ' '
0x1e | SHIFT, // !
0x34 | SHIFT, // "
0x20 | SHIFT, // #
0x21 | SHIFT, // $
0x22 | SHIFT, // %
0x24 | SHIFT, // &
0x34, // '
0x26 | SHIFT, // (
0x27 | SHIFT, // )
0x25 | SHIFT, // *
0x2e | SHIFT, // +
0x36, // ,
0x2d, // -
0x37, // .
0x38, // /
0x27, // 0
0x1e, // 1
0x1f, // 2
0x20, // 3
0x21, // 4
0x22, // 5
0x23, // 6
0x24, // 7
0x25, // 8
0x26, // 9
0x33 | SHIFT, // :
0x33, // ;
0x36 | SHIFT, // <
0x2e, // =
0x37 | SHIFT, // >
0x38 | SHIFT, // ?
0x1f | SHIFT, // @
0x04 | SHIFT, // A
0x05 | SHIFT, // B
0x06 | SHIFT, // C
0x07 | SHIFT, // D
0x08 | SHIFT, // E
0x09 | SHIFT, // F
0x0a | SHIFT, // G
0x0b | SHIFT, // H
0x0c | SHIFT, // I
0x0d | SHIFT, // J
0x0e | SHIFT, // K
0x0f | SHIFT, // L
0x10 | SHIFT, // M
0x11 | SHIFT, // N
0x12 | SHIFT, // O
0x13 | SHIFT, // P
0x14 | SHIFT, // Q
0x15 | SHIFT, // R
0x16 | SHIFT, // S
0x17 | SHIFT, // T
0x18 | SHIFT, // U
0x19 | SHIFT, // V
0x1a | SHIFT, // W
0x1b | SHIFT, // X
0x1c | SHIFT, // Y
0x1d | SHIFT, // Z
0x2f, // [
0x31, // bslash
0x30, // ]
0x23 | SHIFT, // ^
0x2d | SHIFT, // _
0x35, // `
0x04, // a
0x05, // b
0x06, // c
0x07, // d
0x08, // e
0x09, // f
0x0a, // g
0x0b, // h
0x0c, // i
0x0d, // j
0x0e, // k
0x0f, // l
0x10, // m
0x11, // n
0x12, // o
0x13, // p
0x14, // q
0x15, // r
0x16, // s
0x17, // t
0x18, // u
0x19, // v
0x1a, // w
0x1b, // x
0x1c, // y
0x1d, // z
0x2f | SHIFT, //
0x31 | SHIFT, // |
0x30 | SHIFT, // }
0x35 | SHIFT, // ~
0 // DEL
};
Keyboard_::Keyboard_(void)
{
}
void Keyboard_::begin(void)
{
#ifndef USBCON
// release all buttons for Hoodloader
releaseAll();
#endif
}
void Keyboard_::end(void)
{
// added here!
releaseAll();
}
void Keyboard_::sendReport(KeyReport* keys)
{
HID_SendReport(HID_REPORTID_KeyboardReport, &_keyReport, sizeof(_keyReport));
}
// removed <--
//uint8_t USBPutChar(uint8_t c);
// press() adds the specified key (printing, non-printing, or modifier)
// to the persistent key report and sends the report. Because of the way
// USB HID works, the host acts like the key remains pressed until we
// call release(), releaseAll(), or otherwise clear the report and resend.
size_t Keyboard_::press(uint8_t k)
{
uint8_t i;
if (k >= 136) { // it's a non-printing key (not a modifier)
k = k - 136;
}
else if (k >= 128) { // it's a modifier key
_keyReport.modifiers |= (1 << (k - 128));
k = 0;
}
else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
setWriteError();
return 0;
}
if (k & 0x80) { // it's a capital letter or other character reached with shift
_keyReport.modifiers |= 0x02; // the left shift modifier
k &= 0x7F;
}
}
// Add k to the key report only if it's not already present
// and if there is an empty slot.
if (_keyReport.keys[0] != k && _keyReport.keys[1] != k &&
_keyReport.keys[2] != k && _keyReport.keys[3] != k &&
_keyReport.keys[4] != k && _keyReport.keys[5] != k) {
for (i = 0; i<6; i++) {
if (_keyReport.keys[i] == 0x00) {
_keyReport.keys[i] = k;
break;
}
}
if (i == 6) {
setWriteError();
return 0;
}
}
sendReport(&_keyReport);
return 1;
}
// release() takes the specified key out of the persistent key report and
// sends the report. This tells the OS the key is no longer pressed and that
// it shouldn't be repeated any more.
size_t Keyboard_::release(uint8_t k)
{
uint8_t i;
if (k >= 136) { // it's a non-printing key (not a modifier)
k = k - 136;
}
else if (k >= 128) { // it's a modifier key
_keyReport.modifiers &= ~(1 << (k - 128));
k = 0;
}
else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
return 0;
}
if (k & 0x80) { // it's a capital letter or other character reached with shift
_keyReport.modifiers &= ~(0x02); // the left shift modifier
k &= 0x7F;
}
}
// Test the key report to see if k is present. Clear it if it exists.
// Check all positions in case the key is present more than once (which it shouldn't be)
for (i = 0; i<6; i++) {
if (0 != k && _keyReport.keys[i] == k) {
_keyReport.keys[i] = 0x00;
}
}
sendReport(&_keyReport);
return 1;
}
void Keyboard_::releaseAll(void)
{
// release all keys
memset(&_keyReport, 0x00, sizeof(_keyReport));
sendReport(&_keyReport);
}
size_t Keyboard_::write(uint8_t c)
{
uint8_t p = press(c); // Keydown
release(c); // Keyup
return (p); // just return the result of press() since release() almost always returns 1
}

View file

@ -1,151 +0,0 @@
/*
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 KEYBOARD_H
#define KEYBOARD_H
#include "HID.h"
//================================================================================
// HID
//================================================================================
void HID_SendReport(uint8_t id, const void* data, int len);
//================================================================================
// Keyboard
//================================================================================
//Keyboard fixed/added missing Keys
#define KEY_PRINT 0xCE
#define KEY_SCROLL_LOCK 0xCF
#define KEY_PAUSE 0xD0
#ifndef USBCON
#define KEY_LEFT_CTRL 0x80
#define KEY_LEFT_SHIFT 0x81
#define KEY_LEFT_ALT 0x82
#define KEY_LEFT_GUI 0x83
#define KEY_RIGHT_CTRL 0x84
#define KEY_RIGHT_SHIFT 0x85
#define KEY_RIGHT_ALT 0x86
#define KEY_RIGHT_GUI 0x87
#define KEY_UP_ARROW 0xDA
#define KEY_DOWN_ARROW 0xD9
#define KEY_LEFT_ARROW 0xD8
#define KEY_RIGHT_ARROW 0xD7
#define KEY_BACKSPACE 0xB2
#define KEY_TAB 0xB3
#define KEY_RETURN 0xB0
#define KEY_ESC 0xB1
#define KEY_INSERT 0xD1
#define KEY_DELETE 0xD4
#define KEY_PAGE_UP 0xD3
#define KEY_PAGE_DOWN 0xD6
#define KEY_HOME 0xD2
#define KEY_END 0xD5
#define KEY_CAPS_LOCK 0xC1
#define KEY_F1 0xC2
#define KEY_F2 0xC3
#define KEY_F3 0xC4
#define KEY_F4 0xC5
#define KEY_F5 0xC6
#define KEY_F6 0xC7
#define KEY_F7 0xC8
#define KEY_F8 0xC9
#define KEY_F9 0xCA
#define KEY_F10 0xCB
#define KEY_F11 0xCC
#define KEY_F12 0xCD
//Raw Keyboard definitions
#define RAW_KEYBOARD_LEFT_CTRL B00000001
#define RAW_KEYBOARD_LEFT_SHIFT B00000010
#define RAW_KEYBOARD_LEFT_ALT B00000100
#define RAW_KEYBOARD_LEFT_GUI B00001000
#define RAW_KEYBOARD_RIGHT_CTRL B00010000
#define RAW_KEYBOARD_RIGHT_SHIFT B00100000
#define RAW_KEYBOARD_RIGHT_ALT B01000000
#define RAW_KEYBOARD_RIGHT_GUI B10000000
#define RAW_KEYBOARD_UP_ARROW 0x52
#define RAW_KEYBOARD_DOWN_ARROW 0x51
#define RAW_KEYBOARD_LEFT_ARROW 0x50
#define RAW_KEYBOARD_RIGHT_ARROW 0x4F
#define RAW_KEYBOARD_SPACEBAR 0x2C
#define RAW_KEYBOARD_BACKSPACE 0x2A
#define RAW_KEYBOARD_TAB 0x2B
#define RAW_KEYBOARD_RETURN 0x28
#define RAW_KEYBOARD_ESC 0x29
#define RAW_KEYBOARD_INSERT 0x49
#define RAW_KEYBOARD_DELETE 0x4C
#define RAW_KEYBOARD_PAGE_UP 0x4B
#define RAW_KEYBOARD_PAGE_DOWN 0x4E
#define RAW_KEYBOARD_HOME 0x4A
#define RAW_KEYBOARD_END 0x4D
#define RAW_KEYBOARD_CAPS_LOCK 0x39
#define RAW_KEYBOARD_F1 0x3A
#define RAW_KEYBOARD_F2 0x3B
#define RAW_KEYBOARD_F3 0x3C
#define RAW_KEYBOARD_F4 0x3D
#define RAW_KEYBOARD_F5 0x3E
#define RAW_KEYBOARD_F6 0x3F
#define RAW_KEYBOARD_F7 0x40
#define RAW_KEYBOARD_F8 0x41
#define RAW_KEYBOARD_F9 0x42
#define RAW_KEYBOARD_F10 0x43
#define RAW_KEYBOARD_F11 0x44
#define RAW_KEYBOARD_F12 0x45
#define RAW_KEYBOARD_PRINT 0x46
#define RAW_KEYBOARD_SCROLL_LOCK 0x47
#define RAW_KEYBOARD_PAUSE 0x48
//Keyboard fixed/added missing Keys
#define KEY_PRINT 0xCE
#define KEY_SCROLL_LOCK 0xCF
#define KEY_PAUSE 0xD0
// typedef this report again because we cannot include the USBAPI
typedef HID_KeyboardReport_Data_t KeyReport;
class Keyboard_ : public Print{
public:
Keyboard_(void);
void begin(void);
void end(void);
virtual size_t write(uint8_t k);
virtual size_t press(uint8_t k);
virtual size_t release(uint8_t k);
virtual void releaseAll(void);
private:
KeyReport _keyReport;
void sendReport(KeyReport* keys);
};
extern Keyboard_ Keyboard;
#endif
#endif

112
Media.h
View file

@ -1,112 +0,0 @@
/*
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 MEDIA_H
#define MEDIA_H
#include "HID.h"
//================================================================================
// HID
//================================================================================
void HID_SendReport(uint8_t id, const void* data, int len);
//================================================================================
// Media
//================================================================================
#define MEDIA_FAST_FORWARD 0xB3
#define MEDIA_REWIND 0xB4
#define MEDIA_NEXT 0xB5
#define MEDIA_PREVIOUS 0xB6
#define MEDIA_STOP 0xB7
#define MEDIA_PLAY_PAUSE 0xCD
#define MEDIA_VOLUME_MUTE 0xE2
#define MEDIA_VOLUME_UP 0xE9
#define MEDIA_VOLUME_DOWN 0xEA
#define MEDIA_EMAIL_READER 0x18A
#define MEDIA_CALCULATOR 0x192
#define MEDIA_EXPLORER 0x194
#define MEDIA_BROWSER_HOME 0x223
#define MEDIA_BROWSER_BACK 0x224
#define MEDIA_BROWSER_FORWARD 0x225
#define MEDIA_BROWSER_REFRESH 0x227
#define MEDIA_BROWSER_BOOKMARKS 0x22A
class Media_{
public:
inline Media_(void){
// empty
}
inline void begin(void){
memset(&_report, 0, sizeof(_report));
HID_SendReport(HID_REPORTID_MediaReport, &_report, sizeof(_report));
}
inline void end(void){
begin();
}
inline void write(uint16_t m){
press(m);
release(m);
}
inline void press(uint16_t m){
// search for a free spot
for (int i = 0; i < sizeof(HID_MediaReport_Data_t) / 2; i++) {
if (_report.whole16[i] == 0x00) {
_report.whole16[i] = m;
break;
}
}
HID_SendReport(HID_REPORTID_MediaReport, &_report, sizeof(_report));
}
inline void release(uint16_t m){
// search and release the keypress
for (int i = 0; i < sizeof(HID_MediaReport_Data_t) / 2; i++) {
if (_report.whole16[i] == m) {
_report.whole16[i] = 0x00;
// no break to delete multiple keys
}
}
HID_SendReport(HID_REPORTID_MediaReport, &_report, sizeof(_report));
}
inline void releaseAll(void){
begin();
}
private:
HID_MediaReport_Data_t _report;
};
extern Media_ Media;
#endif

View file

@ -1,95 +0,0 @@
/*
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.
*/
#include "Mouse.h"
#include "Platform.h"
//================================================================================
//================================================================================
// Mouse
Mouse_::Mouse_(void) :
_buttons(0)
{
}
void Mouse_::begin(void)
{
#ifndef USBCON
// release all buttons for Hoodloader
_buttons = 0;
move(0, 0, 0);
#endif
}
void Mouse_::end(void)
{
// added here!
_buttons = 0;
move(0, 0, 0);
}
void Mouse_::click(uint8_t b)
{
_buttons = b;
move(0, 0, 0);
_buttons = 0;
move(0, 0, 0);
}
void Mouse_::move(signed char x, signed char y, signed char wheel)
{
u8 m[4];
m[0] = _buttons;
m[1] = x;
m[2] = y;
m[3] = wheel;
HID_SendReport(1, m, 4);
}
void Mouse_::buttons(uint8_t b)
{
if (b != _buttons)
{
_buttons = b;
move(0, 0, 0);
}
}
void Mouse_::press(uint8_t b)
{
buttons(_buttons | b);
}
void Mouse_::release(uint8_t b)
{
buttons(_buttons & ~b);
}
bool Mouse_::isPressed(uint8_t b)
{
if ((b & _buttons) > 0)
return true;
return false;
}

69
Mouse.h
View file

@ -1,69 +0,0 @@
/*
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 MOUSE_H
#define MOUSE_H
#include "HID.h"
//================================================================================
// HID
//================================================================================
void HID_SendReport(uint8_t id, const void* data, int len);
//================================================================================
// Mouse
//================================================================================
#ifndef USBCON
#define MOUSE_LEFT 0x01
#define MOUSE_RIGHT 0x02
#define MOUSE_MIDDLE 0x04
#define MOUSE_PREV 0x08
#define MOUSE_NEXT 0x10
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE | MOUSE_PREV | MOUSE_NEXT)
class Mouse_
{
private:
uint8_t _buttons;
void buttons(uint8_t b);
public:
Mouse_(void);
void begin(void);
void end(void);
void click(uint8_t b = MOUSE_LEFT);
void move(signed char x, signed char y, signed char wheel = 0);
void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
};
extern Mouse_ Mouse;
#endif
#endif

View file

@ -1,78 +0,0 @@
/*
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 DEFAULT_H
#define DEFAULT_H
#include "HID.h"
//================================================================================
// HID
//================================================================================
void HID_SendReport(uint8_t id, const void* data, int len);
//================================================================================
// RawHID
//================================================================================
class RawHID_ : public Print{
public:
inline RawHID_(void){
// empty
}
inline void begin(void){
// empty
}
inline void end(void){
// empty
}
using Print::write; // to get the String version of write
inline size_t write(uint8_t b){
write(&b, 1);
}
inline size_t write(const uint8_t *buffer, size_t size){
size_t bytesleft = size;
// first work through the buffer thats already there
while (bytesleft >= RAWHID_RX_SIZE){
HID_SendReport(HID_REPORTID_RawKeyboardReport, &buffer[size - bytesleft], RAWHID_RX_SIZE);
bytesleft -= RAWHID_RX_SIZE;
}
// write down the other bytes and fill with zeros
if (bytesleft){
uint8_t rest[RAWHID_RX_SIZE];
memcpy(rest, &buffer[size - bytesleft], bytesleft);
memset(&rest[bytesleft], 0, RAWHID_RX_SIZE - bytesleft);
HID_SendReport(HID_REPORTID_RawKeyboardReport, &rest, RAWHID_RX_SIZE);
}
}
};
extern RawHID_ RawHID;
#endif

330
Readme.md
View file

@ -1,330 +0,0 @@
Arduino HID Project
===================
Dont you always wanted to turn your Arduino in a Generic HID device like a Keyboard or a Gamepad?
Disappointed that the Uno doesnt support this at all and the Micro/Leonardo only Mouse + Keyboard?
Introducing the Arduino HID Project that **enables enhanced USB functionality to Arduino Uno, Mega, Leonardo, Micro.**
No need for extra hardware. You just need one of the Arduinos and an USB cable.
**Main difference is that you can upload new sketches to the Uno/Mega and dont need to reflash the firmware over and over again.**
Before you had to upload a sketch, flash the firmware, test, flash the firmware, upload, flash again. Thats all gone!
**For the Leonardo/Micro it is 'just' new HID devices, no need for a bootloader (like on Uno/Mega).**
Note: [Hoodloader Repository moved here.](https://github.com/NicoHood/Hoodloader)
Features
========
Use your **Arduino Uno, Mega, Micro, Leonardo or (Pro)Micro** as Generic HID Device and still be able to upload sketches how you are used to do.
This project provides HID libraries for Arduino Uno/Mega (with a new 16u2 bootloader) and Micro/Leonardo.
I also corrected some bugs in the original sources.
**Software includes:**
* Arduino HID Uno/Mega library
* Arduino HID Micro/Leonardo library
* Arduino HID Bootloader (Hoodloader) + driver for Uno/Mega
* Arduino as ISP with the 16u2 (Hoodloader only, [more information](https://github.com/NicoHood/Hoodloader))
* Compatible with Linux/Mac/Windows XP/7/8.1
* Compatible with IDE 1.0.x - 1.5.7
**The following devices are supported:**
* Keyboard (modifiers + 6 keys pressed at the same time)
* Mouse (5 buttons, move, wheel)
* Media Keys (4 keys for music player, webbrowser and more)
* System Key (for PC standby/shutdown)
* 4 Gamepads (32 buttons, 4 16bit axis, 2 8bit axis, 2 D-Pads)
**Projects can be found here:**
* [Gamecube to PC adapter](https://github.com/NicoHood/Nintendo)
* [Other projects](http://nicohood.wordpress.com/)
Version differences
===================
| Arduino Uno/Mega | Arduino Leonardo/(Pro)Micro |
|:---------------------------------------|:-----------------------------------|
| HID via Hoodloader on 16u2 | Uses USB core with main MCU (32u4) |
| Serial0 without HID fully usable | Serial0 fully usable |
| Serial0 with HID at baud 115200 only | Serial0 slow + buggy |
| Serial0 with HID fully usable via USB | |
| Serial0 with HID not usable via extern | |
| Uses less flash (Serial Protocol only) | Uses more flash (full USB core) |
| ISP function | No ISP function |
Over all the Uno/Mega solution gives you more opportunities except that the Serial0 is limited when you use HID.
Installation Leonardo/Micro/Uno/Mega
====================================
#### Leonardo/Micro only
Download the library and [install it](http://arduino.cc/en/pmwiki.php?n=Guide/Libraries) like you are used to.
**For the whole Project IDE 1.5.7 or higher is recommended!**
**Edit HID.h to de/activate usb functions.**
By default Mouse, Keyboard, Media, System, Gamepad1 is activated.
Each function will take some flash,
so if you want to save flash deactivate everything you dont need.
You cannot use more than 255 bytes HID report on the Leonardo/Micro.
The number after each definition tells you the size of each report.
I have no idea why you cannot use more than 255 bytes (yet), its a bug in the Arduino code.
#### Uno/Mega onl
Download the library and [install it](http://arduino.cc/en/pmwiki.php?n=Guide/Libraries) like you are used to.
**For the whole Project IDE 1.5.7 or higher is recommended!**
To install the new bootloader connect your Arduino to your PC via USB and see
[Hoodloader installing instructions](https://github.com/NicoHood/Hoodloader).
No special programmer needed, just an USB cable.
**You can always switch back to the original firmware, nothing to break.**
Edit HID.h to add an extra delay for raspberry pi. This is a workaround to fix this for slower PCs. There is still a problem with Raspberry.
Usage
=====
You are ready to use the libraries. **Just have a look at the examples and test it out.** They are pretty much self explaining.
All examples use a button on pin 8 and show the basic usage of the libraries.
The libraries will work for all Arduinos listed above but it will use 2 different HID libraries (automatically).
For Keyboard + Mouse usage also see the [official documentation](http://arduino.cc/en/pmwiki.php?n=Reference/MouseKeyboard).
**#include <HID.h> is now needed for every device.**
**On Arduino/Mega you can only use baud 115200 for HID** due to speed/programming reasons.
Use Serial.begin(SERIAL_HID_BAUD); as typedef to start Serial at baud 115200.
Its not bad anyway because its the fastest baud and you want fast HID recognition.
You still can **fully use any other baud** for normal sketches but HID wont work.
If you try nevertheless it will output Serial crap to the monitor.
**Always release buttons to not cause any erros.** Replug USB cable to reset the values if anything went wrong.
On Windows every USB report will reset when you open the lock screen.
See [deactivate HID function (Hoodloader only)](https://github.com/NicoHood/Hoodloader) how to disable HID again.
For Arduino as ISP usage (optional, Hoodloader only, has nothing to do with HID function)
see [Hoodloader repository](https://github.com/NicoHood/Hoodloader).
Updating to a newer Version
===========================
HID library:
To upgrade to v1.8 you need to redownload the Arduino IDE files, restore the original files and install the library like you are used to.
You library is now located in sketchbook/libraries/HID/<files>
Its now way easier to install the library, no need to replace system files. For further releases just replace all files again.
**Restart the IDE**
Hoodloader (Not needed for Leonardo/Micro):
Just upload the new hex file and check the HID Project if the HID library code has changed and replace the new files too.
You normally dont need to reinstall the drivers for windows if the changelog dosnt note anything.
Versions below 1.5 might need the new drivers.
How it works
============
For the Leonardo/Micro its just a modified version of the HID descriptor and Classes for the new devices.
Its not that complicated, everything you need is in the main 4 .h/cpp files.
For the Uno/Mega you need a special Bootloader. Why? See [Hoodloader repository](https://github.com/NicoHood/Hoodloader).
To sum it up: Serial information is grabbed by the "man in the middle, 16u2" and you dont have to worry to get any wrong Serial stuff via USB.
Thatswhy you need a special baud (115200) that both sides can communicate with each other.
Every USB command is send via a special [NicoHood Protocol](https://github.com/NicoHood/NicoHoodProtocol)
that's filtered out by the 16u2. If you use Serial0 for extern devices it cannot filter the signal of course.
You can still use the NHP, just dont use the reserved Address 1.
This project wouldnt be possible without
========================================
* [Lufa 140302 from Dean Camera](http://www.fourwalledcubicle.com/LUFA.php)
* [Darran's HID Projects] (https://github.com/harlequin-tech/arduino-usb)
* [Connor's Joystick for the Leonardo](http://www.imaginaryindustries.com/blog/?p=80)
* [Stefan Jones Multimedia Keys Example](http://stefanjones.ca/blog/arduino-leonardo-remote-multimedia-keys/)
* [Athanasios Douitsis Multimedia Keys Example](https://github.com/aduitsis/ardumultimedia)
* [The Original Arduino Sources](https://github.com/arduino/Arduino/tree/master/hardware/arduino/firmwares/atmegaxxu2/arduino-usbserial)
* [USBlyzer](http://www.usblyzer.com/)
* A lot of searching through the web
* The awesome official Arduino IRC chat!
* [The NicoHood Protocol ^.^](https://github.com/NicoHood/NicoHoodProtocol)
* For donations please contact me on my blog :)
Ideas for the future
====================
* Add more devices (even more?)
* Add Midi (no more free Endpoints, possible on 32u4)
* Add HID rumble support (very hard)
* Add Xbox Support (too hard)
* Add Report Out function (for Keyboard Leds etc)
Known Bugs
==========
See [Hoodloader repository](https://github.com/NicoHood/Hoodloader) for Hoodloader related Bugs/Issues.
System Wakeup is currently not working on all versions!
System Shutdown is only working on Windows systems.
RawHID only works on Uno/Mega. It still has some bugs.
Feel free to open an Issue on Github if you find a bug. Or message me via my [blog](http://nicohood.wordpress.com/)!
Known Issues
============
**Do not name your sketch HID.ino, this wont work!**
Opening the examples with doubleclick doesnt work, starting from IDE does.
**Do not use HID in interrupts because it uses Serial (Hoodloader only). Your Arduino can crash!**
**If you get a checksum error after uploading please message me and send me the whole project.**
Same if your Arduino crashes and dont want to upload sketches anymore (Replug usb fixes this).
These bugs occurred while developing the bootloader and should be fixed. Just in case it happens again I noted it here.
USB can behave weird, so please check your code for errors first. If you cannot find a mistake open a Github issue.
**If You have weird Problems especially with controllers, let me know.**
Sometimes the problem is just that Windows messes up the PID so you might want to compile the hoodloader with a different PID
or reinstall the drivers.
XBMC 13.1 (a Media Center) uses Gamepad input. Its seems to not work and may cause weird errors.
Even with a standard Gamepad I have these errors. Just want to mention it here.
Not tested on the 8u2, lite version should work with flashing via ISP.
Not tested on the Due (message me if it works!)
The USB implementation of the Leonardo/Micro is not that good it can cause errors or disconnects with massiv Serial input.
This has nothing to do with this library! For example Adalight dosnt work well for me,
so you better use an Arduino Uno with Hoodloader for Mediacenter control and Ambilight.
Version History
===============
```
1.8 Beta Release (26.08.2014)
* Changes in the Hoodloader:
* **Huge improvements**, see [Hoodloader repository](https://github.com/NicoHood/Hoodloader)
* Reworked the whole library, easy installation now
* HID fixes for Media Keys/Ubuntu
* Removed Joystick, added 4 Gamepads
1.7.3 Beta Release (10.08.2014)
* Changes in the Hoodloader:
* Fixed HID flush bug (1.6 - 1.7.2)
1.7.2 Beta Release (10.08.2014)
* Changes in the Hoodloader:
* Added Lite version for 8u2
* Added Versions that show up as Uno/Mega (not recommended)
* Makefile and structure changes
1.7.1 Beta Release (10.08.2014)
* Changes in the Hoodloader:
* Fixed HID deactivation bug
1.7 Beta Release (10.08.2014)
* Changes in the Hoodloader:
* Works as ISP now. See the [Hoodloader Repository](https://github.com/NicoHood/Hoodloader) for more information.
* Exceeded 8kb limit. For flashing a 8u2 use v1.6 please!
* Changed Readme text
1.6 Beta Release (09.08.2014)
* Bugfixes in the Hoodloader:
* Changed HID management (not blocking that much, faster)
* added RawHID in/out (HID to Serial)
* Added RawHID Class and example
1.5 Beta Release (21.07.2014)
* Moved Hoodloader source to a [separate Github page](https://github.com/NicoHood/Hoodloader)
* Bugfixes in the Hoodloader:
* Firmware is still available here
* Overall a lot of ram improvements, now with a big global union of ram
* Removed USBtoUSART buffer (not needed, saved 128/500 bytes)
* Removed Lite version because of better ram usage not needed
* Separated different modes better to not cause any errors in default mode
* Improved the deactivate option
* Integrated NHP directly
* Replaced LightweightRingbuffer with native Lufa Ringbuffer
* Improved writing to CDC Host
* Fixed a bug in checkNHPProtocol: & needs to be a ==
* General structure changes
* Improved stability
* Fixed Arduino as ISP bug
1.4.1 Beta Release (10.07.2014)
* #define Bugfix in USBAPI.h
1.4 Beta Release (10.07.2014)
* Bugfixes in the Hoodloader:
* Added Lite Version with less ram usage
* Changed PIDs, edited driver file
* merged v1.0.x and v1.5.x together (both are compatible!)
* added IDE v1.5.7 support
* added Tutorials
1.3 Beta Release (01.07.2014)
* Bugfixes in the Hoodloader:
* Improved ram usage (you can get even better but that messes up code and increases flash)
* **Important NHP fix inside the HID Class for Uno/Mega**
1.2 Beta Release (22.06.2014)
* Added 1.0.x/1.5.x support
* Bugfixes in the Hoodloader:
* Sometimes HID Devices weren't updating when using more than 1 Device (set forcewrite to true)
* Fast updates crashed the bootloader (too much ram usage, set CDC buffer from 128b to 100b each)
* Minor file structure changes
1.1 Beta Release (05.06.2014)
* Added Leonardo/Micro support
* Included NicoHoodProtocol
* Minor fixes
1.0 Beta Release (03.06.2014)
```
Licence and Copyright
=====================
If you use this library for any cool project let me know!
```
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.
```
For Developers
==============
If you deactivate some reports it can occur that windows will cause problems and recognize it as different device.
While developing I had that much trouble that I had to change the PID. No way to repair the broken windows driver settings.
So be careful if you change the source on your own with important PIDs. (Therefore I made a 2nd Lite Version with a different PID and more ram)
Therefore reinstall the divers for any device or just dont touch the HID reports in the Bootloader.
The Leonardo/Micro version worked fine till now.
See this how to uninstall the drivers:
https://support.microsoft.com/kb/315539
The Hootloader was coded with Windows7 and Visual Studio and compiled with a Raspberry Pi.
Lufa version 140302 is included!
**To recompile see instructions in [Hoodloader Repository](https://github.com/NicoHood/Hoodloader).**
The difference between the Leonardo/Micro and Uno/Mega is that the HID Class is different. All other classes are the same.
The Leonardo/Micro Version uses USBAPI.h and no Serial while the Uno/Mega Version uses Serial.
You can also modify the library to send HID reports to other devices/other serials.
Just modify the HID Class (#define HID_SERIAL Serial).

View file

@ -1,79 +0,0 @@
/*
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 SYSTEM_H
#define SYSTEM_H
#include "HID.h"
//================================================================================
// HID
//================================================================================
void HID_SendReport(uint8_t id, const void* data, int len);
//================================================================================
// System
//================================================================================
#define SYSTEM_POWER_DOWN 0x81
#define SYSTEM_SLEEP 0x82
#define SYSTEM_WAKE_UP 0x83
class System_{
public:
inline System_(void){
// empty
}
inline void begin(void){
uint8_t _report = 0;
HID_SendReport(HID_REPORTID_SystemReport, &_report, sizeof(_report));
}
inline void end(void){
begin();
}
inline void write(uint8_t s){
press(s);
release();
}
inline void press(uint8_t s){
HID_SendReport(HID_REPORTID_SystemReport, &s, sizeof(s));
}
inline void release(void){
begin();
}
inline void releaseAll(void){
begin();
}
};
extern System_ System;
#endif

244
USBAPI.h Normal file
View file

@ -0,0 +1,244 @@
/*
USBAPI.h
Copyright (c) 2005-2014 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__
#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"
#if defined(USBCON)
#include "USBDesc.h"
#include "USBCore.h"
//================================================================================
//================================================================================
// 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)
struct ring_buffer;
#if (RAMEND < 1000)
#define SERIAL_BUFFER_SIZE 16
#else
#define SERIAL_BUFFER_SIZE 64
#endif
class Serial_ : public Stream
{
private:
int peek_buffer;
public:
Serial_() { peek_buffer = -1; };
void begin(unsigned long);
void begin(unsigned long, uint8_t);
void end(void);
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t*, size_t);
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool();
volatile uint8_t _rx_buffer_head;
volatile uint8_t _rx_buffer_tail;
unsigned char _rx_buffer[SERIAL_BUFFER_SIZE];
};
extern Serial_ Serial;
#define HAVE_CDCSERIAL
//================================================================================
//================================================================================
// Mouse
#define MOUSE_LEFT 1
#define MOUSE_RIGHT 2
#define MOUSE_MIDDLE 4
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
class Mouse_
{
private:
uint8_t _buttons;
void buttons(uint8_t b);
public:
Mouse_(void);
void begin(void);
void end(void);
void click(uint8_t b = MOUSE_LEFT);
void move(signed char x, signed char y, signed char wheel = 0);
void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
};
extern Mouse_ Mouse;
//================================================================================
//================================================================================
// Keyboard
#define KEY_LEFT_CTRL 0x80
#define KEY_LEFT_SHIFT 0x81
#define KEY_LEFT_ALT 0x82
#define KEY_LEFT_GUI 0x83
#define KEY_RIGHT_CTRL 0x84
#define KEY_RIGHT_SHIFT 0x85
#define KEY_RIGHT_ALT 0x86
#define KEY_RIGHT_GUI 0x87
#define KEY_UP_ARROW 0xDA
#define KEY_DOWN_ARROW 0xD9
#define KEY_LEFT_ARROW 0xD8
#define KEY_RIGHT_ARROW 0xD7
#define KEY_BACKSPACE 0xB2
#define KEY_TAB 0xB3
#define KEY_RETURN 0xB0
#define KEY_ESC 0xB1
#define KEY_INSERT 0xD1
#define KEY_DELETE 0xD4
#define KEY_PAGE_UP 0xD3
#define KEY_PAGE_DOWN 0xD6
#define KEY_HOME 0xD2
#define KEY_END 0xD5
#define KEY_CAPS_LOCK 0xC1
#define KEY_F1 0xC2
#define KEY_F2 0xC3
#define KEY_F3 0xC4
#define KEY_F4 0xC5
#define KEY_F5 0xC6
#define KEY_F6 0xC7
#define KEY_F7 0xC8
#define KEY_F8 0xC9
#define KEY_F9 0xCA
#define KEY_F10 0xCB
#define KEY_F11 0xCC
#define KEY_F12 0xCD
// Low level key report: up to 6 keys and shift, ctrl etc at once
typedef struct
{
uint8_t modifiers;
uint8_t reserved;
uint8_t keys[6];
} KeyReport;
class Keyboard_ : public Print
{
private:
KeyReport _keyReport;
void sendReport(KeyReport* keys);
public:
Keyboard_(void);
void begin(void);
void end(void);
virtual size_t write(uint8_t k);
virtual size_t press(uint8_t k);
virtual size_t release(uint8_t k);
virtual void releaseAll(void);
};
extern Keyboard_ Keyboard;
//================================================================================
//================================================================================
// 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'
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) */

699
USBCore.cpp Normal file
View file

@ -0,0 +1,699 @@
/* Copyright (c) 2010, 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
** 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
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/
#include "USBAPI.h"
#if defined(USBCON)
#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
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
#define TX_RX_LED_PULSE_MS 100
volatile u8 TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
volatile u8 RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
//==================================================================
//==================================================================
extern const u16 STRING_LANGUAGE[] PROGMEM;
extern const u8 STRING_PRODUCT[] PROGMEM;
extern const u8 STRING_MANUFACTURER[] PROGMEM;
extern const DeviceDescriptor USB_DeviceDescriptor PROGMEM;
extern const DeviceDescriptor USB_DeviceDescriptorA PROGMEM;
const u16 STRING_LANGUAGE[2] = {
(3<<8) | (2+2),
0x0409 // English
};
#ifndef USB_PRODUCT
// If no product is provided, use USB IO Board
#define USB_PRODUCT "USB IO Board"
#endif
const u8 STRING_PRODUCT[] PROGMEM = USB_PRODUCT;
#if USB_VID == 0x2341
# if defined(USB_MANUFACTURER)
# undef USB_MANUFACTURER
# endif
# define USB_MANUFACTURER "Arduino LLC"
#elif USB_VID == 0x1b4f
# if defined(USB_MANUFACTURER)
# undef USB_MANUFACTURER
# endif
# define USB_MANUFACTURER "SparkFun"
#elif !defined(USB_MANUFACTURER)
// Fall through to unknown if no manufacturer name was provided in a macro
# define USB_MANUFACTURER "Unknown"
#endif
const u8 STRING_MANUFACTURER[] PROGMEM = USB_MANUFACTURER;
#ifdef CDC_ENABLED
#define DEVICE_CLASS 0x02
#else
#define DEVICE_CLASS 0x00
#endif
// DEVICE DESCRIPTOR
const DeviceDescriptor USB_DeviceDescriptor =
D_DEVICE(0x00,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
const DeviceDescriptor USB_DeviceDescriptorA =
D_DEVICE(DEVICE_CLASS,0x00,0x00,64,USB_VID,USB_PID,0x100,IMANUFACTURER,IPRODUCT,0,1);
//==================================================================
//==================================================================
volatile u8 _usbConfiguration = 0;
static inline void WaitIN(void)
{
while (!(UEINTX & (1<<TXINI)))
;
}
static inline void ClearIN(void)
{
UEINTX = ~(1<<TXINI);
}
static inline void WaitOUT(void)
{
while (!(UEINTX & (1<<RXOUTI)))
;
}
static inline u8 WaitForINOrOUT()
{
while (!(UEINTX & ((1<<TXINI)|(1<<RXOUTI))))
;
return (UEINTX & (1<<RXOUTI)) == 0;
}
static inline void ClearOUT(void)
{
UEINTX = ~(1<<RXOUTI);
}
void Recv(volatile u8* data, u8 count)
{
while (count--)
*data++ = UEDATX;
RXLED1; // light the RX LED
RxLEDPulse = TX_RX_LED_PULSE_MS;
}
static inline u8 Recv8()
{
RXLED1; // light the RX LED
RxLEDPulse = TX_RX_LED_PULSE_MS;
return UEDATX;
}
static inline void Send8(u8 d)
{
UEDATX = d;
}
static inline void SetEP(u8 ep)
{
UENUM = ep;
}
static inline u8 FifoByteCount()
{
return UEBCLX;
}
static inline u8 ReceivedSetupInt()
{
return UEINTX & (1<<RXSTPI);
}
static inline void ClearSetupInt()
{
UEINTX = ~((1<<RXSTPI) | (1<<RXOUTI) | (1<<TXINI));
}
static inline void Stall()
{
UECONX = (1<<STALLRQ) | (1<<EPEN);
}
static inline u8 ReadWriteAllowed()
{
return UEINTX & (1<<RWAL);
}
static inline u8 Stalled()
{
return UEINTX & (1<<STALLEDI);
}
static inline u8 FifoFree()
{
return UEINTX & (1<<FIFOCON);
}
static inline void ReleaseRX()
{
UEINTX = 0x6B; // FIFOCON=0 NAKINI=1 RWAL=1 NAKOUTI=0 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=1
}
static inline void ReleaseTX()
{
UEINTX = 0x3A; // FIFOCON=0 NAKINI=0 RWAL=1 NAKOUTI=1 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=0
}
static inline u8 FrameNumber()
{
return UDFNUML;
}
//==================================================================
//==================================================================
u8 USBGetConfiguration(void)
{
return _usbConfiguration;
}
#define USB_RECV_TIMEOUT
class LockEP
{
u8 _sreg;
public:
LockEP(u8 ep) : _sreg(SREG)
{
cli();
SetEP(ep & 7);
}
~LockEP()
{
SREG = _sreg;
}
};
// Number of bytes, assumes a rx endpoint
u8 USB_Available(u8 ep)
{
LockEP lock(ep);
return FifoByteCount();
}
// Non Blocking receive
// Return number of bytes read
int USB_Recv(u8 ep, void* d, int len)
{
if (!_usbConfiguration || len < 0)
return -1;
LockEP lock(ep);
u8 n = FifoByteCount();
len = min(n,len);
n = len;
u8* dst = (u8*)d;
while (n--)
*dst++ = Recv8();
if (len && !FifoByteCount()) // release empty buffer
ReleaseRX();
return len;
}
// Recv 1 byte if ready
int USB_Recv(u8 ep)
{
u8 c;
if (USB_Recv(ep,&c,1) != 1)
return -1;
return c;
}
// Space in send EP
u8 USB_SendSpace(u8 ep)
{
LockEP lock(ep);
if (!ReadWriteAllowed())
return 0;
return 64 - FifoByteCount();
}
// Blocking Send of data to an endpoint
int USB_Send(u8 ep, const void* d, int len)
{
if (!_usbConfiguration)
return -1;
int r = len;
const u8* data = (const u8*)d;
u8 timeout = 250; // 250ms timeout on send? TODO
while (len)
{
u8 n = USB_SendSpace(ep);
if (n == 0)
{
if (!(--timeout))
return -1;
delay(1);
continue;
}
if (n > len)
n = len;
{
LockEP lock(ep);
// Frame may have been released by the SOF interrupt handler
if (!ReadWriteAllowed())
continue;
len -= n;
if (ep & TRANSFER_ZERO)
{
while (n--)
Send8(0);
}
else if (ep & TRANSFER_PGM)
{
while (n--)
Send8(pgm_read_byte(data++));
}
else
{
while (n--)
Send8(*data++);
}
if (!ReadWriteAllowed() || ((len == 0) && (ep & TRANSFER_RELEASE))) // Release full buffer
ReleaseTX();
}
}
TXLED1; // light the TX LED
TxLEDPulse = TX_RX_LED_PULSE_MS;
return r;
}
extern const u8 _initEndpoints[] PROGMEM;
const u8 _initEndpoints[] =
{
0,
#ifdef CDC_ENABLED
EP_TYPE_INTERRUPT_IN, // CDC_ENDPOINT_ACM
EP_TYPE_BULK_OUT, // CDC_ENDPOINT_OUT
EP_TYPE_BULK_IN, // CDC_ENDPOINT_IN
#endif
#ifdef HID_ENABLED
EP_TYPE_INTERRUPT_IN // HID_ENDPOINT_INT
#endif
};
#define EP_SINGLE_64 0x32 // EP0
#define EP_DOUBLE_64 0x36 // Other endpoints
static
void InitEP(u8 index, u8 type, u8 size)
{
UENUM = index;
UECONX = 1;
UECFG0X = type;
UECFG1X = size;
}
static
void InitEndpoints()
{
for (u8 i = 1; i < sizeof(_initEndpoints); i++)
{
UENUM = i;
UECONX = 1;
UECFG0X = pgm_read_byte(_initEndpoints+i);
UECFG1X = EP_DOUBLE_64;
}
UERST = 0x7E; // And reset them
UERST = 0;
}
// Handle CLASS_INTERFACE requests
static
bool ClassInterfaceRequest(Setup& setup)
{
u8 i = setup.wIndex;
#ifdef CDC_ENABLED
if (CDC_ACM_INTERFACE == i)
return CDC_Setup(setup);
#endif
#ifdef HID_ENABLED
if (HID_INTERFACE == i)
return HID_Setup(setup);
#endif
return false;
}
int _cmark;
int _cend;
void InitControl(int end)
{
SetEP(0);
_cmark = 0;
_cend = end;
}
static
bool SendControl(u8 d)
{
if (_cmark < _cend)
{
if (!WaitForINOrOUT())
return false;
Send8(d);
if (!((_cmark + 1) & 0x3F))
ClearIN(); // Fifo is full, release this packet
}
_cmark++;
return true;
};
// Clipped by _cmark/_cend
int USB_SendControl(u8 flags, const void* d, int len)
{
int sent = len;
const u8* data = (const u8*)d;
bool pgm = flags & TRANSFER_PGM;
while (len--)
{
u8 c = pgm ? pgm_read_byte(data++) : *data++;
if (!SendControl(c))
return -1;
}
return sent;
}
// Send a USB descriptor string. The string is stored in PROGMEM as a
// plain ASCII string but is sent out as UTF-16 with the correct 2-byte
// prefix
static bool USB_SendStringDescriptor(const u8*string_P, u8 string_len) {
SendControl(2 + string_len * 2);
SendControl(3);
for(u8 i = 0; i < string_len; i++) {
bool r = SendControl(pgm_read_byte(&string_P[i]));
r &= SendControl(0); // high byte
if(!r) {
return false;
}
}
return true;
}
// Does not timeout or cross fifo boundaries
// Will only work for transfers <= 64 bytes
// TODO
int USB_RecvControl(void* d, int len)
{
WaitOUT();
Recv((u8*)d,len);
ClearOUT();
return len;
}
int SendInterfaces()
{
int total = 0;
u8 interfaces = 0;
#ifdef CDC_ENABLED
total = CDC_GetInterface(&interfaces);
#endif
#ifdef HID_ENABLED
total += HID_GetInterface(&interfaces);
#endif
return interfaces;
}
// Construct a dynamic configuration descriptor
// This really needs dynamic endpoint allocation etc
// TODO
static
bool SendConfiguration(int maxlen)
{
// Count and measure interfaces
InitControl(0);
int interfaces = SendInterfaces();
ConfigDescriptor config = D_CONFIG(_cmark + sizeof(ConfigDescriptor),interfaces);
// Now send them
InitControl(maxlen);
USB_SendControl(0,&config,sizeof(ConfigDescriptor));
SendInterfaces();
return true;
}
u8 _cdcComposite = 0;
static
bool SendDescriptor(Setup& setup)
{
u8 t = setup.wValueH;
if (USB_CONFIGURATION_DESCRIPTOR_TYPE == t)
return SendConfiguration(setup.wLength);
InitControl(setup.wLength);
#ifdef HID_ENABLED
if (HID_REPORT_DESCRIPTOR_TYPE == t)
return HID_GetDescriptor(t);
#endif
const u8* desc_addr = 0;
if (USB_DEVICE_DESCRIPTOR_TYPE == t)
{
if (setup.wLength == 8)
_cdcComposite = 1;
desc_addr = _cdcComposite ? (const u8*)&USB_DeviceDescriptorA : (const u8*)&USB_DeviceDescriptor;
}
else if (USB_STRING_DESCRIPTOR_TYPE == t)
{
if (setup.wValueL == 0) {
desc_addr = (const u8*)&STRING_LANGUAGE;
}
else if (setup.wValueL == IPRODUCT) {
return USB_SendStringDescriptor(STRING_PRODUCT, strlen(USB_PRODUCT));
}
else if (setup.wValueL == IMANUFACTURER) {
return USB_SendStringDescriptor(STRING_MANUFACTURER, strlen(USB_MANUFACTURER));
}
else
return false;
}
if (desc_addr == 0)
return false;
u8 desc_length = pgm_read_byte(desc_addr);
USB_SendControl(TRANSFER_PGM,desc_addr,desc_length);
return true;
}
// Endpoint 0 interrupt
ISR(USB_COM_vect)
{
SetEP(0);
if (!ReceivedSetupInt())
return;
Setup setup;
Recv((u8*)&setup,8);
ClearSetupInt();
u8 requestType = setup.bmRequestType;
if (requestType & REQUEST_DEVICETOHOST)
WaitIN();
else
ClearIN();
bool ok = true;
if (REQUEST_STANDARD == (requestType & REQUEST_TYPE))
{
// Standard Requests
u8 r = setup.bRequest;
if (GET_STATUS == r)
{
Send8(0); // TODO
Send8(0);
}
else if (CLEAR_FEATURE == r)
{
}
else if (SET_FEATURE == r)
{
}
else if (SET_ADDRESS == r)
{
WaitIN();
UDADDR = setup.wValueL | (1<<ADDEN);
}
else if (GET_DESCRIPTOR == r)
{
ok = SendDescriptor(setup);
}
else if (SET_DESCRIPTOR == r)
{
ok = false;
}
else if (GET_CONFIGURATION == r)
{
Send8(1);
}
else if (SET_CONFIGURATION == r)
{
if (REQUEST_DEVICE == (requestType & REQUEST_RECIPIENT))
{
InitEndpoints();
_usbConfiguration = setup.wValueL;
} else
ok = false;
}
else if (GET_INTERFACE == r)
{
}
else if (SET_INTERFACE == r)
{
}
}
else
{
InitControl(setup.wLength); // Max length of transfer
ok = ClassInterfaceRequest(setup);
}
if (ok)
ClearIN();
else
{
Stall();
}
}
void USB_Flush(u8 ep)
{
SetEP(ep);
if (FifoByteCount())
ReleaseTX();
}
// General interrupt
ISR(USB_GEN_vect)
{
u8 udint = UDINT;
UDINT = 0;
// End of Reset
if (udint & (1<<EORSTI))
{
InitEP(0,EP_TYPE_CONTROL,EP_SINGLE_64); // init ep0
_usbConfiguration = 0; // not configured yet
UEIENX = 1 << RXSTPE; // Enable interrupts for ep0
}
// Start of Frame - happens every millisecond so we use it for TX and RX LED one-shot timing, too
if (udint & (1<<SOFI))
{
#ifdef CDC_ENABLED
USB_Flush(CDC_TX); // Send a tx frame if found
#endif
// check whether the one-shot period has elapsed. if so, turn off the LED
if (TxLEDPulse && !(--TxLEDPulse))
TXLED0;
if (RxLEDPulse && !(--RxLEDPulse))
RXLED0;
}
}
// VBUS or counting frames
// Any frame counting?
u8 USBConnected()
{
u8 f = UDFNUML;
delay(3);
return f != UDFNUML;
}
//=======================================================================
//=======================================================================
USBDevice_ USBDevice;
USBDevice_::USBDevice_()
{
}
void USBDevice_::attach()
{
_usbConfiguration = 0;
UHWCON = 0x01; // power internal reg
USBCON = (1<<USBE)|(1<<FRZCLK); // clock frozen, usb enabled
#if F_CPU == 16000000UL
PLLCSR = 0x12; // Need 16 MHz xtal
#elif F_CPU == 8000000UL
PLLCSR = 0x02; // Need 8 MHz xtal
#endif
while (!(PLLCSR & (1<<PLOCK))) // wait for lock pll
;
// Some tests on specific versions of macosx (10.7.3), reported some
// strange behaviuors when the board is reset using the serial
// port touch at 1200 bps. This delay fixes this behaviour.
delay(1);
USBCON = ((1<<USBE)|(1<<OTGPADE)); // start USB clock
UDIEN = (1<<EORSTE)|(1<<SOFE); // Enable interrupts for EOR (End of Reset) and SOF (start of frame)
UDCON = 0; // enable attach resistor
TX_RX_LED_INIT;
}
void USBDevice_::detach()
{
}
// Check for interrupts
// TODO: VBUS detection
bool USBDevice_::configured()
{
return _usbConfiguration;
}
void USBDevice_::poll()
{
}
#endif /* if defined(USBCON) */

303
USBCore.h Normal file
View file

@ -0,0 +1,303 @@
// Copyright (c) 2010, 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
** 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
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/
#ifndef __USBCORE_H__
#define __USBCORE_H__
// Standard requests
#define GET_STATUS 0
#define CLEAR_FEATURE 1
#define SET_FEATURE 3
#define SET_ADDRESS 5
#define GET_DESCRIPTOR 6
#define SET_DESCRIPTOR 7
#define GET_CONFIGURATION 8
#define SET_CONFIGURATION 9
#define GET_INTERFACE 10
#define SET_INTERFACE 11
// bmRequestType
#define REQUEST_HOSTTODEVICE 0x00
#define REQUEST_DEVICETOHOST 0x80
#define REQUEST_DIRECTION 0x80
#define REQUEST_STANDARD 0x00
#define REQUEST_CLASS 0x20
#define REQUEST_VENDOR 0x40
#define REQUEST_TYPE 0x60
#define REQUEST_DEVICE 0x00
#define REQUEST_INTERFACE 0x01
#define REQUEST_ENDPOINT 0x02
#define REQUEST_OTHER 0x03
#define REQUEST_RECIPIENT 0x03
#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE)
#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE)
// Class requests
#define CDC_SET_LINE_CODING 0x20
#define CDC_GET_LINE_CODING 0x21
#define CDC_SET_CONTROL_LINE_STATE 0x22
#define MSC_RESET 0xFF
#define MSC_GET_MAX_LUN 0xFE
#define HID_GET_REPORT 0x01
#define HID_GET_IDLE 0x02
#define HID_GET_PROTOCOL 0x03
#define HID_SET_REPORT 0x09
#define HID_SET_IDLE 0x0A
#define HID_SET_PROTOCOL 0x0B
// Descriptors
#define USB_DEVICE_DESC_SIZE 18
#define USB_CONFIGUARTION_DESC_SIZE 9
#define USB_INTERFACE_DESC_SIZE 9
#define USB_ENDPOINT_DESC_SIZE 7
#define USB_DEVICE_DESCRIPTOR_TYPE 1
#define USB_CONFIGURATION_DESCRIPTOR_TYPE 2
#define USB_STRING_DESCRIPTOR_TYPE 3
#define USB_INTERFACE_DESCRIPTOR_TYPE 4
#define USB_ENDPOINT_DESCRIPTOR_TYPE 5
#define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
#define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
#define USB_DEVICE_CLASS_STORAGE 0x08
#define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
#define USB_CONFIG_POWERED_MASK 0x40
#define USB_CONFIG_BUS_POWERED 0x80
#define USB_CONFIG_SELF_POWERED 0xC0
#define USB_CONFIG_REMOTE_WAKEUP 0x20
// bMaxPower in Configuration Descriptor
#define USB_CONFIG_POWER_MA(mA) ((mA)/2)
// bEndpointAddress in Endpoint Descriptor
#define USB_ENDPOINT_DIRECTION_MASK 0x80
#define USB_ENDPOINT_OUT(addr) ((addr) | 0x00)
#define USB_ENDPOINT_IN(addr) ((addr) | 0x80)
#define USB_ENDPOINT_TYPE_MASK 0x03
#define USB_ENDPOINT_TYPE_CONTROL 0x00
#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
#define USB_ENDPOINT_TYPE_BULK 0x02
#define USB_ENDPOINT_TYPE_INTERRUPT 0x03
#define TOBYTES(x) ((x) & 0xFF),(((x) >> 8) & 0xFF)
#define CDC_V1_10 0x0110
#define CDC_COMMUNICATION_INTERFACE_CLASS 0x02
#define CDC_CALL_MANAGEMENT 0x01
#define CDC_ABSTRACT_CONTROL_MODEL 0x02
#define CDC_HEADER 0x00
#define CDC_ABSTRACT_CONTROL_MANAGEMENT 0x02
#define CDC_UNION 0x06
#define CDC_CS_INTERFACE 0x24
#define CDC_CS_ENDPOINT 0x25
#define CDC_DATA_INTERFACE_CLASS 0x0A
#define MSC_SUBCLASS_SCSI 0x06
#define MSC_PROTOCOL_BULK_ONLY 0x50
#define HID_HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESCRIPTOR_TYPE 0x22
#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23
// 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;
} DeviceDescriptor;
// Config
typedef struct {
u8 len; // 9
u8 dtype; // 2
u16 clen; // total length
u8 numInterfaces;
u8 config;
u8 iconfig;
u8 attributes;
u8 maxPower;
} ConfigDescriptor;
// String
// Interface
typedef struct
{
u8 len; // 9
u8 dtype; // 4
u8 number;
u8 alternate;
u8 numEndpoints;
u8 interfaceClass;
u8 interfaceSubClass;
u8 protocol;
u8 iInterface;
} InterfaceDescriptor;
// Endpoint
typedef struct
{
u8 len; // 7
u8 dtype; // 5
u8 addr;
u8 attr;
u16 packetSize;
u8 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;
} IADDescriptor;
// CDC CS interface descriptor
typedef struct
{
u8 len; // 5
u8 dtype; // 0x24
u8 subtype;
u8 d0;
u8 d1;
} CDCCSInterfaceDescriptor;
typedef struct
{
u8 len; // 4
u8 dtype; // 0x24
u8 subtype;
u8 d0;
} CDCCSInterfaceDescriptor4;
typedef struct
{
u8 len;
u8 dtype; // 0x24
u8 subtype; // 1
u8 bmCapabilities;
u8 bDataInterface;
} CMFunctionalDescriptor;
typedef struct
{
u8 len;
u8 dtype; // 0x24
u8 subtype; // 1
u8 bmCapabilities;
} ACMFunctionalDescriptor;
typedef struct
{
// IAD
IADDescriptor iad; // Only needed on compound device
// Control
InterfaceDescriptor cif; //
CDCCSInterfaceDescriptor header;
CMFunctionalDescriptor callManagement; // Call Management
ACMFunctionalDescriptor controlManagement; // ACM
CDCCSInterfaceDescriptor functionalDescriptor; // CDC_UNION
EndpointDescriptor cifin;
// Data
InterfaceDescriptor dif;
EndpointDescriptor in;
EndpointDescriptor out;
} CDCDescriptor;
typedef struct
{
InterfaceDescriptor msc;
EndpointDescriptor in;
EndpointDescriptor out;
} MSCDescriptor;
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;
} HIDDescDescriptor;
typedef struct
{
InterfaceDescriptor hid;
HIDDescDescriptor desc;
EndpointDescriptor in;
} HIDDescriptor;
#define D_DEVICE(_class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs) \
{ 18, 1, 0x200, _class,_subClass,_proto,_packetSize0,_vid,_pid,_version,_im,_ip,_is,_configs }
#define D_CONFIG(_totalLength,_interfaces) \
{ 9, 2, _totalLength,_interfaces, 1, 0, USB_CONFIG_BUS_POWERED, USB_CONFIG_POWER_MA(500) }
#define D_INTERFACE(_n,_numEndpoints,_class,_subClass,_protocol) \
{ 9, 4, _n, 0, _numEndpoints, _class,_subClass, _protocol, 0 }
#define D_ENDPOINT(_addr,_attr,_packetSize, _interval) \
{ 7, 5, _addr,_attr,_packetSize, _interval }
#define D_IAD(_firstInterface, _count, _class, _subClass, _protocol) \
{ 8, 11, _firstInterface, _count, _class, _subClass, _protocol, 0 }
#define D_HIDREPORT(_descriptorLength) \
{ 9, 0x21, 0x1, 0x1, 0, 1, 0x22, _descriptorLength, 0 }
#define D_CDCCS(_subtype,_d0,_d1) { 5, 0x24, _subtype, _d0, _d1 }
#define D_CDCCS4(_subtype,_d0) { 4, 0x24, _subtype, _d0 }
#endif

63
USBDesc.h Normal file
View file

@ -0,0 +1,63 @@
/* 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
** 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
** WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR
** BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
** OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
** ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
** SOFTWARE.
*/
#define CDC_ENABLED
#define HID_ENABLED
#ifdef CDC_ENABLED
#define CDC_INTERFACE_COUNT 2
#define CDC_ENPOINT_COUNT 3
#else
#define CDC_INTERFACE_COUNT 0
#define CDC_ENPOINT_COUNT 0
#endif
#ifdef HID_ENABLED
#define HID_INTERFACE_COUNT 1
#define HID_ENPOINT_COUNT 1
#else
#define HID_INTERFACE_COUNT 0
#define HID_ENPOINT_COUNT 0
#endif
#define CDC_ACM_INTERFACE 0 // CDC ACM
#define CDC_DATA_INTERFACE 1 // CDC Data
#define CDC_FIRST_ENDPOINT 1
#define CDC_ENDPOINT_ACM (CDC_FIRST_ENDPOINT) // CDC First
#define CDC_ENDPOINT_OUT (CDC_FIRST_ENDPOINT+1)
#define CDC_ENDPOINT_IN (CDC_FIRST_ENDPOINT+2)
#define HID_INTERFACE (CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT) // HID Interface
#define HID_FIRST_ENDPOINT (CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT)
#define HID_ENDPOINT_INT (HID_FIRST_ENDPOINT)
#define INTERFACE_COUNT (MSC_INTERFACE + MSC_INTERFACE_COUNT)
#ifdef CDC_ENABLED
#define CDC_RX CDC_ENDPOINT_OUT
#define CDC_TX CDC_ENDPOINT_IN
#endif
#ifdef HID_ENABLED
#define HID_TX HID_ENDPOINT_INT
#endif
#define IMANUFACTURER 1
#define IPRODUCT 2

View file

@ -1,55 +0,0 @@
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
Advanced Gamepad example
*/
// include HID library
#include <HID.h>
const int pinLed = 13;
const int pinButton = 8;
// see HID_Reports.h for all data structures
HID_GamepadReport_Data_t Gamepadreport;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
// Sends a clean report to the host. This is important because
// the 16u2 of the Uno/Mega is not turned off while programming
// so you want to start with a clean report to avoid strange bugs after reset.
memset(&Gamepadreport, 0, sizeof(Gamepadreport));
HID_SendReport(HID_REPORTID_Gamepad1Report, &Gamepadreport, sizeof(Gamepadreport));
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// This demo is actually made for advanced users to show them how they can write an own report.
// This might be useful for a Gamepad if you want to edit the values direct on your own.
// count with buttons binary
static uint32_t count = 0;
Gamepadreport.whole32[0] = count++;
// move x/y Axis to a new position (16bit)
Gamepadreport.whole16[2] = (random(0xFFFF));
// functions before only set the values
// this writes the report to the host
HID_SendReport(HID_REPORTID_Gamepad1Report, &Gamepadreport, sizeof(Gamepadreport));
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}

View file

@ -1,99 +0,0 @@
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
Advanced Keyboard example
*/
// include HID library
#include <HID.h>
const int pinLed = 13;
const int pinButton = 8;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
// Sends a clean report to the host. This is important because
// the 16u2 of the Uno/Mega is not turned off while programming
// so you want to start with a clean report to avoid strange bugs after reset.
pressRawKeyboard(0, 0);
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// This demo is actually made for advanced users to show them how they can write an own report.
// This might be useful for a Keyboard if you only use one key,
// because the library has a lot of code for simple use
// press STRG + ALT + DEL on keyboard (see usb documentation)
//pressRawKeyboard(0, 4); //modifiers + 4
//pressRawKeyboard(0, 29); //modifiers + z
pressRawKeyboard(RAW_KEYBOARD_LEFT_CTRL | RAW_KEYBOARD_LEFT_ALT , RAW_KEYBOARD_DELETE); //modifiers + key
pressRawKeyboard(0, 0); // release! Important
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
void pressRawKeyboard(uint8_t modifiers, uint8_t key) {
uint8_t keys[8] = {
modifiers, 0, key, 0, 0, 0, 0, 0 }; //modifiers, reserved, key[0]
HID_SendReport(HID_REPORTID_KeyboardReport, keys, sizeof(keys));
}
/*
See Hut1_12v2.pdf Chapter 10 (Page 53) for more Keys
(especially a-z, a=0x04 z=29)
Definitions:
RAW_KEYBOARD_LEFT_CTRL
RAW_KEYBOARD_LEFT_SHIFT
RAW_KEYBOARD_LEFT_ALT
RAW_KEYBOARD_LEFT_GUI
RAW_KEYBOARD_RIGHT_CTRL
RAW_KEYBOARD_RIGHT_SHIFT
RAW_KEYBOARD_RIGHT_ALT
RAW_KEYBOARD_RIGHT_GUI
RAW_KEYBOARD_UP_ARROW
RAW_KEYBOARD_DOWN_ARROW
RAW_KEYBOARD_LEFT_ARROW
RAW_KEYBOARD_RIGHT_ARROW
RAW_KEYBOARD_SPACEBAR
RAW_KEYBOARD_BACKSPACE
RAW_KEYBOARD_TAB
RAW_KEYBOARD_RETURN
RAW_KEYBOARD_ESC
RAW_KEYBOARD_INSERT
RAW_KEYBOARD_DELETE
RAW_KEYBOARD_PAGE_UP
RAW_KEYBOARD_PAGE_DOWN
RAW_KEYBOARD_HOME
RAW_KEYBOARD_END
RAW_KEYBOARD_CAPS_LOCK
RAW_KEYBOARD_F1
RAW_KEYBOARD_F2
RAW_KEYBOARD_F3
RAW_KEYBOARD_F4
RAW_KEYBOARD_F5
RAW_KEYBOARD_F6
RAW_KEYBOARD_F7
RAW_KEYBOARD_F8
RAW_KEYBOARD_F9
RAW_KEYBOARD_F10
RAW_KEYBOARD_F11
RAW_KEYBOARD_F12
RAW_KEYBOARD_PRINT
RAW_KEYBOARD_SCROLL_LOCK
RAW_KEYBOARD_PAUSE
*/

View file

@ -1,114 +0,0 @@
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
Advanced RawHID example
Shows how to send bytes via raw HID
Press a button to send some example values.
Keep in mind that you can only send full data packets, the rest is filled with zero!
Definitions from HID_Reports.h:
RAWHID_USAGE_PAGE 0xFFC0 // recommended: 0xFF00 to 0xFFFF
RAWHID_USAGE 0x0C00 // recommended: 0x0100 to 0xFFFF
RAWHID_TX_SIZE 15 // 1 byte for report ID
RAWHID_RX_SIZE 15 // 1 byte for report ID
*/
// include HID library
#include <HID.h>
const int pinLed = 13;
const int pinButton = 8;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
// no begin function needed for RawHID
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// direct without library. Always send RAWHID_RX_SIZE bytes!
uint8_t buff[RAWHID_RX_SIZE]; // unitialized, has random values
HID_SendReport(HID_REPORTID_RawKeyboardReport, buff, sizeof(buff));
// with library
memset(&buff, 42, sizeof(buff));
RawHID.write(buff, sizeof(buff));
// write a single byte, will fill the rest with zeros
RawHID.write(0xCD);
// huge buffer with library, will fill the rest with zeros
uint8_t megabuff[64];
for (int i = 0; i < sizeof(megabuff); i++)
megabuff[i] = i;
RawHID.write(megabuff, sizeof(megabuff));
// You can use print too, but better dont use a linefeed
RawHID.println("Hello World");
// And compare it to write:
RawHID.write("Hello World\r\n");
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
/*
Expected output:
// manual with unintialized buff
recv 15 bytes:
01 55 C1 FF 01 01 01 00 00 01 00 00 01 00 20
// filled buff
recv 15 bytes:
2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A 2A
// single byte filled with zero
recv 15 bytes:
CD 00 00 00 00 00 00 00 00 00 00 00 00 00 00
// huge buffer filled with zero at the end
recv 15 bytes:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E
recv 15 bytes:
0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D
recv 15 bytes:
1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C
recv 15 bytes:
2D 2E 2F 30 31 32 33 34 35 36 37 38 39 3A 3B
recv 15 bytes:
3C 3D 3E 3F 00 00 00 00 00 00 00 00 00 00 00
// print
recv 15 bytes:
48 65 6C 6C 6F 20 57 6F 72 6C 64 00 00 00 00
//\r
recv 15 bytes:
0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//\n
recv 15 bytes:
0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//write
recv 15 bytes:
48 65 6C 6C 6F 20 57 6F 72 6C 64 0D 0A 00 00
*/

View file

@ -1,100 +0,0 @@
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
Gamepad example
Press a button and demonstrate Gamepad actions
*/
// include HID library
#include <HID.h>
// create a new Gamepad instance (1-4)
Gamepad Gamepad1(1);
//Gamepad Gamepad2(2);
//Gamepad Gamepad3(3);
//Gamepad Gamepad4(4);
const int pinLed = 13;
const int pinButton = 8;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
// Sends a clean report to the host. This is important because
// the 16u2 of the Uno/Mega is not turned off while programming
// so you want to start with a clean report to avoid strange bugs after reset.
Gamepad1.begin();
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// press button 1-32 and reset (34 becaue its written later)
static uint8_t count = 1;
Gamepad1.press(count++);
if (count == 34) {
Gamepad1.releaseAll();
count = 1;
}
// move x/y Axis to a new position (16bit)
Gamepad1.xAxis(random(0xFFFF));
Gamepad1.yAxis(analogRead(A0) << 6);
// go through all dPad positions
// values: 0-8 (0==centred)
static uint8_t dpad1 = GAMEPAD_DPAD_CENTERED;
Gamepad1.dPad1(dpad1++);
if(dpad1>GAMEPAD_DPAD_UP_LEFT) dpad1 = GAMEPAD_DPAD_CENTERED;
static int8_t dpad2 = GAMEPAD_DPAD_CENTERED;
Gamepad1.dPad2(dpad2--);
if(dpad2<GAMEPAD_DPAD_CENTERED) dpad2 = GAMEPAD_DPAD_UP_LEFT;
// functions before only set the values
// this writes the report to the host
Gamepad1.write();
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
/*
Prototypes:
void begin(void);
void end(void);
void write(void);
void press(uint8_t b);
void release(uint8_t b);
void releaseAll(void);
void buttons(uint32_t b);
void xAxis(int16_t a);
void yAxis(int16_t a);
void rxAxis(int16_t a);
void ryAxis(int16_t a);
void zAxis(int8_t a);
void rzAxis(int8_t a);
void dPad1(int8_t d);
void dPad2(int8_t d);
Definitions:
GAMEPAD_DPAD_CENTERED 0
GAMEPAD_DPAD_UP 1
GAMEPAD_DPAD_UP_RIGHT 2
GAMEPAD_DPAD_RIGHT 3
GAMEPAD_DPAD_DOWN_RIGHT 4
GAMEPAD_DPAD_DOWN 5
GAMEPAD_DPAD_DOWN_LEFT 6
GAMEPAD_DPAD_LEFT 7
GAMEPAD_DPAD_UP_LEFT 8
*/

View file

@ -1,88 +0,0 @@
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
Keyboard example
Press a button to write some text to your pc.
See official documentation for more infos
*/
// include HID library
#include <HID.h>
const int pinLed = 13;
const int pinButton = 8;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
// Sends a clean report to the host. This is important because
// the 16u2 of the Uno/Mega is not turned off while programming
// so you want to start with a clean report to avoid strange bugs after reset.
Keyboard.begin();
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// Same use as the official library, pretty much self explaining
Keyboard.println("This message was sent with my Arduino.");
Serial.println("Serial port is still working and not glitching out");
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
/*
Definitions:
KEY_LEFT_CTRL
KEY_LEFT_SHIFT
KEY_LEFT_ALT
KEY_LEFT_GUI
KEY_RIGHT_CTRL
KEY_RIGHT_SHIFT
KEY_RIGHT_ALT
KEY_RIGHT_GUI
KEY_UP_ARROW
KEY_DOWN_ARROW
KEY_LEFT_ARROW
KEY_RIGHT_ARROW
KEY_BACKSPACE
KEY_TAB
KEY_RETURN
KEY_ESC
KEY_INSERT
KEY_DELETE
KEY_PAGE_UP
KEY_PAGE_DOWN
KEY_HOME
KEY_END
KEY_CAPS_LOCK
KEY_F1
KEY_F2
KEY_F3
KEY_F4
KEY_F5
KEY_F6
KEY_F7
KEY_F8
KEY_F9
KEY_F10
KEY_F11
KEY_F12
KEY_PRINT
KEY_SCROLL_LOCK
KEY_PAUSE
*/

View file

@ -1,65 +0,0 @@
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
Media example
Press a button to play/pause music player
*/
// include HID library
#include <HID.h>
const int pinLed = 13;
const int pinButton = 8;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
// Sends a clean report to the host. This is important because
// the 16u2 of the Uno/Mega is not turned off while programming
// so you want to start with a clean report to avoid strange bugs after reset.
Media.begin();
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// See list below for more definitions or the official usb documentation
Media.write(MEDIA_PLAY_PAUSE);
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
/*
Definitions:
MEDIA_FAST_FORWARD
MEDIA_REWIND
MEDIA_NEXT
MEDIA_PREVIOUS
MEDIA_STOP
MEDIA_PLAY_PAUSE
MEDIA_VOLUME_MUTE
MEDIA_VOLUME_UP
MEDIA_VOLUME_DOWN
MEDIA_EMAIL_READER
MEDIA_CALCULATOR
MEDIA_EXPLORER
MEDIA_BROWSER_HOME
MEDIA_BROWSER_BACK
MEDIA_BROWSER_FORWARD
MEDIA_BROWSER_REFRESH
MEDIA_BROWSER_BOOKMARKS
*/

View file

@ -1,52 +0,0 @@
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
Mouse example
Press a button to click with mouse. See official documentation for more infos
*/
// include HID library
#include <HID.h>
const int pinLed = 13;
const int pinButton = 8;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
// Sends a clean report to the host. This is important because
// the 16u2 of the Uno/Mega is not turned off while programming
// so you want to start with a clean report to avoid strange bugs after reset.
Mouse.begin();
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// Same use as the official library, pretty much self explaining
Mouse.click();
Serial.println("Serial port is still working and not glitching out");
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
/*
Definitions:
MOUSE_LEFT
MOUSE_RIGHT
MOUSE_MIDDLE
MOUSE_PREV
MOUSE_NEXT
*/

View file

@ -1,4 +0,0 @@
Examples
========
Just try these examples once the HID Source is installed. Its pretty much self explaining.

View file

@ -1,48 +0,0 @@
/*
Copyright (c) 2014 NicoHood
See the readme for credit to other people.
System example
Press a button to put pc into standby mode
*/
// include HID library
#include <HID.h>
const int pinLed = 13;
const int pinButton = 8;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
// Starts Serial at baud 115200 otherwise HID wont work on Uno/Mega.
// This is not needed for Leonado/(Pro)Micro but make sure to activate desired USB functions in HID.h
Serial.begin(SERIAL_HID_BAUD);
// Sends a clean report to the host. This is important because
// the 16u2 of the Uno/Mega is not turned off while programming
// so you want to start with a clean report to avoid strange bugs after reset.
System.begin();
}
void loop() {
if (!digitalRead(pinButton)) {
digitalWrite(pinLed, HIGH);
// See list below for more definitions or the official usb documentation
System.write(SYSTEM_SLEEP);
// simple debounce
delay(300);
digitalWrite(pinLed, LOW);
}
}
/*
Definitions:
SYSTEM_POWER_DOWN
SYSTEM_SLEEP
SYSTEM_WAKE_UP
*/

View file

@ -1,642 +0,0 @@
:1000000099C10000B3C10000B1C10000AFC1000040
:10001000ADC10000ABC10000A9C10000A7C1000034
:10002000A5C10000A3C10000A1C100000C94B80D3F
:100030000C94640E9BC1000099C1000097C10000A0
:1000400095C1000093C1000091C100008FC1000064
:100050008DC100008BC1000089C1000057C30000A2
:1000600085C1000083C1000081C100007FC1000084
:100070007DC100003003410072006400750069001A
:100080006E006F00200048006F006F0064006C007D
:100090006F0061006400650072002000420065008E
:1000A00074006100000012034E00690063006F00DD
:1000B00048006F006F006400000004030904090297
:1000C0005F00030100C032080B00020202010009B8
:1000D00004000001020201000524001001042402B2
:1000E000060524060001070582030800FF09040134
:1000F00000020A0000000705040240000107058312
:10010000024000010904020001030000000921115E
:1001100001000122040207058103100001120110F1
:1001200001EF020108EB03686E80010102DC0105AA
:10013000010902A1010901A100850105091901298F
:10014000051500250195057501810295017503814D
:100150000305010930093109381581257F75089596
:10016000038106C0C005010906A101850205071922
:10017000E029E715002501750195088102950175B3
:1001800008810395067508150025650507190029DE
:1001900065810005081901290595057501910295EC
:1001A0000175039103C006C0FF0A000CA10185037D
:1001B0007508150026FF00950F09018102950F09AA
:1001C000029102C0050C0901A1018504150026FF5A
:1001D0000319002AFF03950475108100C005010969
:1001E00080A1018505150026FF00190029FF950152
:1001F00075088100C005010904A1018506050919DA
:10020000012920150025017501952081020501A114
:1002100000093009310933093416008026FF7F7543
:100220001095048102093209351580257F750895DE
:10023000028102C005010939093915012508950215
:1002400075048102C005010904A10185070509198A
:10025000012920150025017501952081020501A1C4
:1002600000093009310933093416008026FF7F75F3
:100270001095048102093209351580257F7508958E
:10028000028102C009390939150125089502750452
:100290008102C005010904A1018508050919012988
:1002A00020150025017501952081020501A1000995
:1002B0003009310933093416008026FF7F75109507
:1002C000048102093209351580257F750895028160
:1002D00002C005010939093915012508950275047F
:1002E0008102C005010904A1018509050919012937
:1002F00020150025017501952081020501A1000945
:100300003009310933093416008026FF7F751095B6
:10031000048102093209351580257F75089502810F
:1003200002C005010939093915012508950275042E
:100330008102C00011241FBECFEFD2E0DEBFCDBFCF
:1003400011E0A0E0B1E0EAECF7E202C005900D9206
:10035000AE33B107D9F711E0AEE3B1E001C01D92B1
:10036000A63FB107E1F773D00C94E31349CEEEE357
:10037000F1E05FB7F894208131812115310519F042
:100380004481411104C05FBF2FEF3FEF11C0828154
:1003900090E0841B910997FF03C06381860F911D34
:1003A000D901A80FB91F2C91415044835FBF30E0A1
:1003B000C9010895EEE3F1E04FB7F894208131814F
:1003C0002115310509F41DC0828190E05481851BFF
:1003D0009109019797FF03C05381850F911DD901A2
:1003E000A80FB91F6C9384819381891308C09281EF
:1003F000911101C0828382818150828302C08F5F0C
:1004000084834FBF089584B7877F84BF88E10FB688
:10041000F89480936000109260000FBE539A5A9A2D
:1004200080E191E00E94D00A1092CA018AB18063F3
:100430008AB98BB180638BB90E94A90D84E085BD18
:100440005F9A579A25982D9A26982E9A089580910A
:10045000CB01807F8093CB011092DB011092DC01F5
:100460002DD4D1DF789410E213B980E191E00E949D
:10047000B51097FD1BC0409124015091250160915A
:10048000260170912701413051056105710511F474
:10049000AFD60CC05C989091CA019C609093CA0141
:1004A0009091C80095FFFCCF8093CE002FB7F894B1
:1004B00080913E0190913F01892B19F0809142017A
:1004C00001C080E02FBF90E0009719F4A89981C087
:1004D00002C15D982091CA0123602093CA01209136
:1004E00011012F702093E9002091E80020FFEECF4A
:1004F0008034910510F08FE390E0F82EC0E0D0E05A
:1005000065C08091240190912501A0912601B091B0
:1005100027012091E80121110CC082309105A1052D
:10052000B10528F08115924CA140B10511F41D9937
:1005300043C08091200180FD0AC0222341F08EE358
:1005400091E015DF8091E80181112DC03EC07FB799
:10055000F89420913E0130913F012115310541F081
:1005600040914201442321F050E01416150624F076
:100570007FBF6FEF7FEF10C08091400190E0841B40
:10058000950B97FF04C040914101840F911DF90123
:10059000E80FF91F60817FBF80E191E00E944D105C
:1005A000882369F293CF81508093E8018091CA013A
:1005B00080638093CA0109C08091CA0180638093DF
:1005C000CA018EE391E0D3DEA1D22196FC1299CF2D
:1005D0007DCFA89A9091CA01892F807309F459C0E0
:1005E000892F82958F708D5F8370282F2295207FB1
:1005F0009F7C922B9093CA0181114BC0E091DD0149
:10060000E6FF15C0E695E695E695E770F0E0EE5159
:10061000FE4F60818EE391E0CDDE8091DD0186FBAF
:10062000882780F99091E801890F8093E8018091F3
:10063000DD0187FD2AC08695869586958770C0E086
:10064000D0E0E82EF12C8EE3C82E81E0D82ECE0C1F
:10065000DF1C09C0F601EC0FFD1FEC55FF4F608158
:100660008EE391E0A7DE2197CE01809590958E15BF
:100670009F0584F38091DD01869586958695877028
:100680009091E801890F8093E8018DED91E070D69B
:100690000AD29091CA01892F837049F081508370EA
:1006A0009C7F982B9093CA01811101C05D9A909113
:1006B000CA01892F8C7079F0892F869586958D5F78
:1006C0008370282F220F220F937F922B9093CA01C1
:1006D000811101C05C9A80E091E00E94E01280E10B
:1006E00091E00E949F100E940C10BECE08950895C4
:1006F00080E091E00E94CB1280E191E00E942810FE
:10070000E2EEF0E080818460808308951F920F9272
:100710000FB60F9211242F933F934F935F938F93B4
:100720009F93AF93BF93EF93FF934091CE0080913F
:10073000ED018430E9F4EEE3F1E02FB7F894808125
:1007400091810097A1F054813381531301C00FC0F0
:100750003281DC01A30FB11D4C93832F8F5F828305
:100760009381891301C0128284818F5F84832FBF9C
:10077000FF91EF91BF91AF919F918F915F914F91B9
:100780003F912F910F900FBE0F901F90189580E111
:1007900091E00E94E31080E091E00C94941180912C
:1007A0000E0190910F01009729F0019790930F018E
:1007B00080930E010895292F332723303105B1F09E
:1007C0004CF42130310509F439C02230310509F0EB
:1007D0003AC007C02132310539F12232310549F1E1
:1007E00032C0EFE5F0E08EEB90E031C09927813028
:1007F000910561F08230910581F0892B21F5EAEBBA
:10080000F0E0E491F0E08AEB90E021C0E6EAF0E06D
:10081000E491F0E086EA90E01AC0E4E7F0E0E491C9
:10082000F0E084E790E013C0E9E0F0E08DE091E0D3
:100830000EC0E4E0F2E08FE291E009C0E2E1F0E016
:100840008DE191E004C0E0E0F0E080E090E0DA01CA
:100850008D939C93CF010895FF920F931F93CF9395
:10086000DF9320E030E050E0640F751FCEE3D1E06D
:100870002CC0FB01E21BF30B31970081FE011FB777
:10088000F894A081B181109709F41CC0828190E096
:10089000F4808F199109019797FF03C0F3808F0DA2
:1008A000911DA80FB91F0C9384819381891308C0EF
:1008B0009281911101C0828382818150828302C022
:1008C0008F5F84831FBF2F5F3F4F241735078CF244
:1008D000DF91CF911F910F91FF900895089504C06B
:1008E00080E091E00E94E0128091DC0187FDF8CF6A
:1008F00008958150813130F4E82FF0E0E55DFE4F3E
:100900008081089580E00895EF92FF921F93CF9326
:10091000DF931F92CDB7DEB7182FE82EF12C21E020
:10092000E21AF1082091DB018091DC01382F3F773A
:100930000E2C02C0359527950A94E2F720FF36C0A9
:10094000812FD7DF882391F18983C9DF1F709091B0
:10095000CB01907F912B9093CB012CEC31E08981DE
:10096000482F50E060E070E0C9010E94DC138091E4
:10097000DC0180688093DC01B2DF81E090E002C09E
:10098000880F991FEA94E2F7809590952091DB01FA
:100990004091DC01342F3F77822393238093DB0146
:1009A0009F77842F8078892B8093DC010F90DF91D3
:1009B000CF911F91FF90EF900895CF938091DB012D
:1009C0002091DC01922F9F77892B31F0C1E08C2F91
:1009D0009BDFCF5FC231D9F7CF910895CF92DF92DD
:1009E000EF92FF920F931F93CF93DF9300D0CDB779
:1009F000DEB77B01932F68017091DC01672F60786F
:100A000009F440C0E091CB01EF70E330B1F0F0E0C9
:100A1000319741E050E002C0440F551FEA95E2F7DC
:100A2000E091DB01F72FFF774E2B5F2B4093DB012B
:100A3000452F4F77462B4093DC018091CB018F707F
:100A400029839A8356DF182FECECF1E0482F50E011
:100A5000BF012981822F9A810E94D3139091CB01EB
:100A60009F70F7019083F601108311828091DC0161
:100A70008F778093DC018091CB01807F8093CB01C5
:100A800081E006C0F7011082F8011182108280E037
:100A90000F900F90DF91CF911F910F91FF90EF90EA
:100AA000DF90CF9008951F93CF93DF9300D000D0B5
:100AB00000D0CDB7DEB713DF8091CB01682F6F7008
:100AC000B1F0807FA1F470E07160AE014F5F5F4FC5
:100AD00081E024D5182F482FBE016F5F7F4F8EE332
:100AE00091E0BADE9091E801910F9093E801809136
:100AF000CB01807F8093CB0126960FB6F894DEBFA2
:100B00000FBECDBFDF91CF911F910895CF936DEDB3
:100B100071E0E1D4882309F48AC087FD70C0813078
:100B2000C1F49091DF019130A1F4D9DEC091DE01D2
:100B30008091CB018F708093CB01B5DFCF70809116
:100B4000CB01807F8C2B8093CB018F7009F06FC01D
:100B50006CC02091CB01922F9F7009F450C099274F
:100B600087FD909522952F7030E02E5F3F4F359591
:100B700027952F5F3F4F8217930709F040C0AFDEE4
:100B8000C091CB018C2F8F70B4DE2C2F22952F704B
:100B90009091DE013091DF01E22FF0E0E453FE4F4F
:100BA0009083E22FEF5FEF704E2F4295407F909140
:100BB000CB019F70942B9093CB018E1769F0F0E0DE
:100BC000E453FE4F30832E5F2295207F9091CB011E
:100BD0009F70922B9093CB012091CB0122952F7087
:100BE00030E090E02817390711F58091DC0180682A
:100BF0008093DC0180E091E0CF910C94E012409171
:100C0000DD01469546954695477062EE71E08EE3AC
:100C100091E022DE8091DD0186958695869587702C
:100C20009091E801890F8093E801CF913CCFCF915B
:100C30000895682F80E191E00E944D108823D9F03B
:100C400080E191E00E949F100E940C105C982FEFB1
:100C500081EE94E0215080409040E1F700C0000018
:100C60005C982FEF81EE94E0215080409040E1F7B6
:100C700000C00000EBCF089580E191E00E94B51024
:100C800097FDFACF0895EF92FF920F931F93CF93A2
:100C9000DF937C0103E411E0C0E0D0E005C0ECDFAD
:100CA000F80181938F012196CE15DF05C4F3DF9102
:100CB000CF911F910F91FF90EF9008952398229864
:100CC0002198249820981092C5011092C401109286
:100CD000C7011092C6011092C9011092C80110926A
:100CE000C301EEE3F1E02FB7F89483E491E0918340
:100CF0008083128280E8838314822FBF1092E801E0
:100D00008DED91E035C3CF93C82FB6DF803239F433
:100D100084E18FDF8C2F8DDF80E1CF918ACF85E159
:100D200088DF8091C301982F9F5F9F778078892B00
:100D30008093C301CF9108959FDF803221F484E135
:100D400078DF80E176CF85E174DF8091C301982F51
:100D50009F5F9F778078892B8093C30108958138A6
:100D600059F018F4803871F405C0823839F08339AD
:100D700049F406C082E007C081E005C082E103C0FB
:100D800083E501C080E0BFCF84E190E07CDF9091FB
:100D90004F0180E020915001820F911D9093C70177
:100DA0008093C6019091510180E020915201820F01
:100DB000911D9093C9018093C801089583E58CBD6E
:100DC0008DB58EB508950DB407FEFDCF08958EBD87
:100DD000FADF8EB50895CF93DF9300D01F92CDB781
:100DE000DEB72B834A836983F2DF6981862FEFDFC9
:100DF0004A81842FECDF2B81822F0F900F900F9070
:100E0000DF91CF91E4CF38DF803259F08091C30178
:100E1000982F9F5F9F778078892B8093C30185E10E
:100E200015C084E106DF20E040E060E080E3D3DF2E
:100E300000DF20E041E060E080E3CDDFFADE20E08B
:100E400042E060E080E3C7DFF4DE80E1F2CE84E0E0
:100E500090E019DF209146014091450160914401E5
:100E600080914301B8DF4FCF209A289AA7DF249AB8
:100E70002C9A219A29982FEF80E792E02150804008
:100E80009040E1F700C000002C982FEF80E792E03F
:100E9000215080409040E1F700C000002398229A42
:100EA00020E040E063E58CEA96DFE3ECF1E080814E
:100EB0008068808382DDEEE3F1E08FB7F8941182E1
:100EC00010821282138214828FBF1092CA018BB1DA
:100ED00080638BB90895962F672F242F492F7BCFDE
:100EE000EF92FF920F931F93CF93DF93C5DE182FDE
:100EF000C3DED82FC1DEC82FBFDE803259F080910B
:100F0000C301982F9F5F9F778078892B8093C301BF
:100F100085E144C0312F20E07901ED0EF11C84E120
:100F200088DEC63419F51BC06091C4017091C501FB
:100F300040E080E2D0DF7DDE6091C4017091C501A8
:100F400040E088E2C8DF75DE8091C4019091C50160
:100F500001969093C5018093C401229602C0C0E01F
:100F6000D0E0CE15DF0504F380E118C0C534A9F444
:100F70000091C4011091C501000F111FC0E0D0E025
:100F800008C0BE01600F711F4FEF80EAA4DF51DE81
:100F90002196CE15DF05ACF3E7CF81E1DF91CF914C
:100FA0001F910F91FF90EF9044CE8091C6019091D8
:100FB000C7012091C4013091C5018032910511F41F
:100FC000207F0EC08034910511F4207E09C0803846
:100FD000910511F4207C04C08115914009F420781A
:100FE000C90108955D9A40E0BC018CE474DF2FEFE5
:100FF00086E791E0215080409040E1F700C000007A
:101000005D980895CF92DF92EF92FF920F931F9316
:10101000CF93DF937B01CB0136DEC7DF8C01C0E0CD
:10102000D0E029C09EE3C92E91E0D92ECC0EDD1E62
:101030006091C4017091C501F601458180E44BDFE8
:1010400022966091C4017091C501F601468188E441
:1010500042DF2091C4013091C5012F5F3F4F309393
:10106000C5012093C401A1DF0817190721F0C801A9
:10107000B9DF9BDF8C01CE15DF05A4F280E1DF91A3
:10108000CF911F910F91FF90EF90DF90CF90089537
:101090000F931F93CF93DF93C091C401D091C501EB
:1010A000CC0FDD1F8C0108C060E870E0CE01AADF24
:1010B000C058DF4F0058110901381105A8F7B801D1
:1010C000CE01A0DF80E1DF91CF911F910F910895B4
:1010D000CF92DF92EF92FF920F931F93CF93DF9304
:1010E0006C018B01CB01CFDD5D9A33E4E32E31E05F
:1010F000F32EC0E0D0E012C0F70141917F01BE01A4
:101100006C0D7D1D80ECE7DEFFE722E382E0F1500D
:1011100020408040E1F700C000002196C017D107B1
:101120005CF35D9880E1DF91CF911F910F91FF906B
:10113000EF90DF90CF9008950F931F93CF93DF939D
:10114000C091C401D091C5012091C8013091C9015D
:101150002817390724F0CC0FDD1F8C0113C08091B4
:10116000C301982F9F5F9F778078892B8093C3015D
:1011700081E10FC060E870E0CE01AADFC058DF4F08
:101180000058110901381105A8F7B801CE01A0DFF8
:1011900080E1DF91CF911F910F910895CF93DF935D
:1011A0006BDDD82F80E0C82F67DDC80FD11D64DD4F
:1011B000863419F4CE016CDF04C08534A9F4CE0165
:1011C000BBDFC82F59DD803221F484E132DD8C2F62
:1011D0000CC08091C301982F9F5F9F778078892BE7
:1011E0008093C30185E101C081E1DF91CF9121CDE1
:1011F000CF93DF932091C30127FF02C05D9801C008
:101200005D9A2F7711F05C9801C05C9A97FDADC094
:101210008135910509F483C0E4F48134910509F422
:1012200053C054F48033910599F181339105B1F1A4
:10123000809709F088C07DC08534910509F44CC0C1
:101240008035910509F44CC08234910509F07BC0CA
:101250003FC08136910509F457C06CF4863591057D
:1012600009F45AC08036910509F44DC085359105C1
:1012700009F069C037C08437910509F44AC0853741
:10128000910509F453C08436910509F05CC03EC055
:101290008091C30180788093C3011BC0EDDC803254
:1012A00009F063C084E1C5DC81E4C3DC86E5C1DC10
:1012B00082E5BFDC80E2BDDC89E4BBDC83E5B9DC30
:1012C00080E5B7DC80E14EC0D7DCDF91CF9147CD20
:1012D0005BDDDF91CF9130CD85E090E0D4DCF9CFBC
:1012E000C3DDF7CFC9DCC82FD0E0D093C501C093D0
:1012F000C401C2DC382F20E02C0F3D1F3093C50104
:101300002093C401E6CFB8DCB7DCE3CFDF91CF9107
:1013100045CFDF91CF91E4CDDF91CF9198CD8091F2
:10132000C30180788093C301C9DCD3CFDF91CF9113
:101330006ACD8091C301982F9F5F9F778078892B1A
:101340008093C3010EC08091C301982F9F5F9F7748
:101350008078892B8093C3018FDC803211F482E185
:1013600001C085E1DF91CF9164CCDF91CF910895E9
:10137000FC01208120682F7B208308950F931F9309
:10138000FB01908196FF0FC0292F26952695269563
:101390002770DB01A20FB11D15962C912583977C38
:1013A00098609F7B03C097FF02C0907C90839081E0
:1013B0009695969596959770DF01A90FB11D159694
:1013C0008C93292F2F5F2770220F220F220F40812D
:1013D000477C422B4083282F207C342F37702038C5
:1013E00009F463C0203C09F045C0282F28732695D6
:1013F00026952695332349F0990F990F990F477C2D
:10140000492B406440839EEF01C090E0223098F465
:10141000908196FB222720F9892F869586958695BF
:10142000820F8770880F880F880F977C982B9F7B7F
:1014300090839FEF3FC0273059F4082F0F7010E0C2
:1014400020E030E0018312832383348325E00AC047
:10145000482F477050E060E070E04183528363831F
:101460007483215027708081887F822B8083992309
:1014700029F120C0032F10E00230110524F1395F5B
:101480003770487F432B408341815281638174814F
:1014900097E0440F551F661F771F9A95D1F7482B89
:1014A000418352836383748309C0313071F4982F70
:1014B0009F739F5F80818068808309C080818F7760
:1014C000808390E004C09DEFF5CF9CEFF3CF892F90
:1014D0001F910F9108950F931F93CF93DF93EB010B
:1014E0004DDF1816B4F409811A812B813C81A901C2
:1014F000662777272227332740275127622773271C
:101500004F3F5F4F6105710521F0888180688883B6
:101510008BEFDF91CF911F910F910895FA012CE18C
:1015200030E097E0AB01022E02C0569547950A9431
:10153000E2F7483028F0973059F4408396E008C02D
:1015400040839150411104C027503109923051F726
:10155000492F42500DC0DF01A40FB11D9B012F7711
:1015600033272C93660F672F661F770B71954150B9
:101570004111F1CF492F50E09A0163E0220F331F50
:101580006A95E1F7206C3F6F3081322B3083E40F96
:10159000F51F319781508F7380688083892F08955C
:1015A000CF92DF92EF92FF92CF93DF93EC01809185
:1015B000C30187FD83DB01DACC88DD88EE88FF88F4
:1015C00082E0C816D104E104F10420F0988D8A8DE0
:1015D000E98D09C0E0E088E090E0C12C32ECD32E28
:1015E000EE24E394F12CE150E23028F4F0E0E45CE6
:1015F000FE4FC08101C0C0E0923009F4C86087305E
:1016000031F0883031F0863029F4C26003C0C46004
:1016100001C0C6605B9A1092C9001092C800109277
:10162000CA00C11481EED806E104F10489F0C701B3
:10163000B601969587957795679560587B47814E5B
:101640009F4FA70196010E94A4132150310902C0A7
:1016500020E130E03093CD002093CC00C093CA004D
:10166000C11481EED806E104F10411F480E001C058
:1016700082E08093C80088E98093C9005B98DF917D
:10168000CF91FF90EF90DF90CF900895CF93DF93AD
:10169000EC0193D91E9B03C0888980FF02C05F982C
:1016A00006C05F9A1092CA018BB180638BB9DF913B
:1016B000CF910895BF92CF92DF92EF92FF920F9356
:1016C0001F93CF93DF937C018B01EA01D7D1B82E12
:1016D000811132C0209731F028813981021B130B10
:1016E000E20EF31EC12CD12C22C08091E80085FDB2
:1016F00014C08091E8008E778093E800209749F02D
:10170000888199818C0D9D1D9983888325E0B22E57
:1017100013C0B4D1882359F00EC0F70181917F0125
:101720008093F10001501109FFEFCF1ADF0A011574
:101730001105D9F601C0B82E8B2DDF91CF911F91E5
:101740000F91FF90EF90DF90CF90BF900895209180
:10175000F4013091F5012617370748F0611571053E
:1017600039F42091E8002E772093E80001C0B901F8
:101770009C0180E034C09091ED01992309F443C0AD
:10178000953009F442C09091E80093FD3AC09091E1
:10179000E80092FD30C09091E80090FF20C0809159
:1017A000F20090E0F901821B930B05C02191209378
:1017B000F100615071099F01280F391F61157105F2
:1017C00019F02830310590F381E02830310509F017
:1017D00080E09091E8009E779093E8009F0161156A
:1017E000710549F68111C7CF06C08091ED018823AC
:1017F00051F0853051F08091E80082FFF6CF80E013
:10180000089581E0089582E0089583E008956115C8
:10181000710529F42091E8002B772093E8009C01C2
:1018200021C08091ED01882381F1853041F18091C3
:10183000E80083FD26C08091E80082FFF2CFF90125
:1018400007C08091F10081939F016150710929F0D7
:101850009F018091F2008111F4CF8091E8008B7795
:101860008093E80061157105E1F68091E80080FD44
:101870000AC08091ED01882341F08530B1F783E003
:10188000089581E0089580E0089582E00895209110
:10189000F4013091F5012617370748F061157105FD
:1018A00039F42091E8002E772093E80001C0B901B7
:1018B0009C0180E035C09091ED01992309F444C06A
:1018C000953009F443C09091E80093FD3BC090919E
:1018D000E80092FD31C09091E80090FF21C0809116
:1018E000F20090E0F901821B930B06C02491209333
:1018F000F1003196615071099C012E0F3F1F611557
:10190000710519F02830310588F381E02830310560
:1019100009F080E09091E8009E779093E8009F01A5
:101920006115710541F68111C6CF06C08091ED01A8
:10193000882351F0853051F08091E80082FFF6CF86
:1019400080E0089581E0089582E0089583E008959D
:10195000982F2CC09093E900981739F07091EC0003
:101960002091ED005091F00003C0242F762F50E01D
:1019700021FD02C09F5F1AC03091EB003E7F309383
:10198000EB003091ED003D7F3093ED003091EB00A6
:1019900031603093EB007093EC002093ED00509396
:1019A000F0002091EE0027FDE5CF07C0953090F2C2
:1019B0008F708093E90081E0089580E008950F938F
:1019C0001F93CF93DF93062FEC0110E02EC0988178
:1019D000911103C01F5F259628C02C81E981FA81EF
:1019E0006B81892F8F70853010F080E021C022300C
:1019F00010F056E001C052E028E030E040E003C0C3
:101A00004F5F220F331F2E173F07D0F34295407FC1
:101A1000452B991F9927991F6295660F660F607C69
:101A2000692B96DF8111D6CFE0CF1013D0CF81E0A4
:101A3000DF91CF911F910F9108958091EE0187FD65
:101A400005C08091E80080FF0EC012C08091E800C0
:101A500082FD05C08091ED018111F8CF089580913C
:101A6000E8008B7708C08091ED018111EACF0895DD
:101A70008091E8008E778093E80008958091E400DB
:101A80009091E50045E62091EC0020FD1FC023C0A9
:101A90002091ED01222391F0253091F02091EB006F
:101AA00025FD10C02091E4003091E500281739078A
:101AB00051F34150C90139F784E0089582E0089557
:101AC00083E0089581E0089580E008952091E80082
:101AD00020FFDECFF9CF2091E80022FFD9CFF4CF4D
:101AE00041D043D08091D8008F778093D8008091E7
:101AF000D80080688093D8008091D8008F7D809333
:101B0000D80084E089BD86E089BD09B400FEFDCF20
:101B10001092ED011092E9011092EB011092EA018E
:101B200042E060E080E014DF8091E1008E7F8093EE
:101B3000E1008091E20081608093E2008091E20008
:101B400088608093E2008091E0008E7F8093E000C7
:101B50000895E3E6F0E080818E7F808381E08093CA
:101B6000EC01BECF1092E20008951092E1000895BA
:101B70001F920F920FB60F9211242F933F934F9302
:101B80005F936F937F938F939F93AF93BF93EF93E5
:101B9000FF938091E10082FF0BC08091E20082FF01
:101BA00007C08091E1008B7F8093E1000E94CF030A
:101BB0008091E10080FF18C08091E20080FF14C096
:101BC0008091E2008E7F8093E2008091E20080614C
:101BD0008093E2008091D80080628093D80019BC85
:101BE0001092ED010E9477038091E10084FF30C0E4
:101BF0008091E20084FF2CC084E089BD86E089BD2D
:101C000009B400FEFDCF8091D8008F7D8093D8006D
:101C10008091E1008F7E8093E1008091E2008F7ED1
:101C20008093E2008091E20081608093E2008091E5
:101C3000E901882311F084E007C08091E30087FF69
:101C400002C083E001C081E08093ED010E94760331
:101C50008091E10083FF27C08091E20083FF23C0D1
:101C60008091E100877F8093E10082E08093ED0125
:101C70001092E9018091E1008E7F8093E1008091D4
:101C8000E2008E7F8093E2008091E2008061809389
:101C9000E20042E060E080E05BDE8091F00088607E
:101CA0008093F000B8D1FF91EF91BF91AF919F91D8
:101CB0008F917F916F915F914F913F912F910F90F5
:101CC0000FBE0F901F9018951F920F920FB60F9294
:101CD00011242F933F934F935F936F937F938F9331
:101CE0009F93AF93BF93CF93EF93FF938091E900BE
:101CF0008F709091EC0090FF02C090E801C090E0DE
:101D0000C92FC82B1092E9008091F000877F809343
:101D1000F00078941CD01092E9008091F000886067
:101D20008093F000CF70C093E900FF91EF91CF91C5
:101D3000BF91AF919F918F917F916F915F914F91E3
:101D40003F912F910F900FBE0F901F9018951F93EA
:101D5000CF93DF93CDB7DEB7AC970FB6F894DEBF65
:101D60000FBECDBFEEEEF1E08091F100819321E056
:101D7000E63FF207C9F70E94C7038091E80083FF9E
:101D800032C18091EE019091EF01953009F487C046
:101D900038F49130B1F170F0933009F024C131C0C2
:101DA000983009F4F4C0993009F400C1963009F074
:101DB0001AC19BC0803821F0823809F014C108C0D4
:101DC0008091EA019091EB01992389F082600FC024
:101DD0008091F2019091F3018F7099278093E9002F
:101DE0008091EB0085FB882780F91092E9009091A3
:101DF000E800977F9093E8008093F1001092F10043
:101E0000D1C0882319F0823009F0EDC08F7121F024
:101E1000823009F0E8C00BC08091F001813009F0F8
:101E2000E2C0933009F080E08093EB012FC08091F5
:101E3000F00181112BC08091F2019091F3018F701C
:101E40009927009709F4CFC08093E9002091EB0017
:101E500020FF1CC02091EF01233021F48091EB0082
:101E6000806212C09091EB0090619093EB0021E0B2
:101E700030E001C0220F8A95EAF72093EA00109221
:101E8000EA008091EB0088608093EB001092E900FB
:101E90008091E800877F8093E800CFDDA4C08111A6
:101EA000A2C08091F0019091F1018F779927182FAE
:101EB0009091E3009078982B9093E3008091E80054
:101EC000877F8093E800B9DD8091E80080FFFCCF38
:101ED0008091E30080688093E300112311F083E098
:101EE00001C082E08093ED017EC08058823008F00E
:101EF0007AC08091F0019091F1018C3D23E092072E
:101F000071F583E08A838AE289834FB7F894DE0112
:101F1000139620E03EE051E2E32FF0E050935700AB
:101F2000E49120FF03C0E295EF703F5FEF708E2FCA
:101F300090E0EA3010F0C79601C0C0968D939D9353
:101F40002F5F243149F74FBF8091E800877F80934E
:101F5000E8006AE270E0CE010196F9DB12C0AE0142
:101F6000455D5F4F6091F2010E94DB030097D9F15C
:101F70002091E800277F2093E800BC018BA59CA559
:101F800086DC8091E8008B778093E8002CC0803855
:101F900051F58091E800877F8093E8008091E90106
:101FA0008093F1008091E8008E7775CF81111BC07E
:101FB0009091F0019230B8F48091E800877F80938F
:101FC000E8009093E90139DD8091E901811104C0B5
:101FD0008091E30087FF02C084E001C081E080932C
:101FE000ED010E9478038091E80083FF0AC0809190
:101FF000E800877F8093E8008091EB008062809307
:10200000EB00AC960FB6F894DEBF0FBECDBFDF91EC
:10201000CF911F9108950895CF938091ED0188236A
:10202000A9F08091E9008F709091EC0090FF02C0C0
:1020300090E801C090E0C92FC82B1092E900809170
:10204000E80083FD84DECF70C093E900CF9108954E
:10205000CF93DF93EC014096FC018BE0DF011D92F2
:102060008A95E9F782E08C83898783E08E8761E037
:10207000CE010196A4DC882361F061E0CE010696D2
:102080009EDC882331F061E0CE010B96DF91CF9189
:1020900096CC80E0DF91CF910895CF93C62F209109
:1020A000ED012430F1F4FC01448955896689778972
:1020B000452B462B472BA9F081818F708093E90037
:1020C0008091E80085FF04C0C093F10080E00AC061
:1020D0008091E8008E778093E800D0DC8823A1F31C
:1020E00001C082E0CF9108952091ED01243029F5BF
:1020F000FC014489558966897789452B462B472BF6
:10210000E1F081818F708093E9008091F20081116C
:1021100002C080E008959091E8008091E8008E77F9
:102120008093E80095FDF5CFA9DC811107C090915F
:10213000E8009E779093E800089582E0089520914A
:10214000ED01243089F4FC01448955896689778939
:10215000452B462B472B41F021812F702093E9001E
:102160002091E80020FDC0CF08952091ED0124309A
:1021700019F02FEF3FEF24C0FC014489558966898F
:102180007789452B462B472BA1F386818F7080934F
:10219000E9008091E80082FFECCF8091F200882373
:1021A00021F02091F10030E002C02FEF3FEF80914D
:1021B000F200811105C08091E8008B778093E800E0
:1021C000C90108950895CF93DF93EC018091E80051
:1021D00083FFA7C0888190E02091F2013091F30144
:1021E0002817390709F09DC08091EF01813261F015
:1021F00020F4803209F095C03DC0823209F46DC0F0
:10220000833209F08EC07DC08091EE01813A09F0E1
:1022100088C08091E800877F8093E8008091E80083
:1022200080FFFCCF4C895D896E897F894093F100E6
:10223000BB27A72F962F852F8093F100CB01AA27CC
:10224000BB278093F100472F5527662777274093B8
:10225000F100888D8093F100898D8093F1008A8D43
:102260008093F1008091E8008E778093E800DF9101
:10227000CF91E3CB8091EE01813209F052C0809181
:10228000E800877F8093E80005C08091ED018823F6
:1022900009F447C08091E80082FFF7CF3091F10048
:1022A0002091F1009091F1008091F1003C8B2D8BF9
:1022B0009E8B8F8B8091F100888F8091F100898FA8
:1022C0008091F1008A8F8091E8008B778093E800FD
:1022D000B4DBCE01DF91CF9163C98091EE018132F1
:1022E00001F58091E800877F8093E800A6DB80916C
:1022F000F0019091F101998B888BCE01DF91CF9104
:10230000C5C98091EE01813261F48091E800877F38
:102310008093E80092DB6091F001CE01DF91CF91D4
:1023200051CFDF91CF9108956F927F928F929F92BC
:10233000AF92BF92CF92DF92EF92FF920F931F93D3
:10234000CF93DF9300D01F92CDB7DEB77C01ADB63F
:10235000BEB68091E80083FF07C1F701808190E05D
:102360002091F2013091F3012817390709F0FCC0E0
:102370008091EF01833009F49EC030F4813071F018
:10238000823009F0F1C0D4C08A3009F4B9C08B3072
:1023900009F4A2C0893009F0E7C04CC08091EE0179
:1023A000813A09F0E1C08DB69EB61A8219828091F9
:1023B000F0011091F1018B83F70140858DB79EB735
:1023C000841B91090FB6F8949EBF0FBE8DBFCDB68A
:1023D000DEB6EFEFCE1ADE0A360150E060E070E0C4
:1023E000C601EAD1412F41508E010F5F1F4F960168
:1023F000BE016D5F7F4FC7010E94EE04F701268189
:1024000037812115310529F0408550E0B601C90119
:10241000CAD11092E9008091E800877F8093E8009C
:1024200069817A81C30193D98091E8008B77809389
:10243000E80039C08091EE01813209F095C08DB677
:102440009EB60091F4011091F5017090F00160903A
:10245000F1018DB79EB7801B910B0FB6F8949EBF0C
:102460000FBE8DBFCDB6DEB6EFEFCE1ADE0A80917D
:10247000E800877F8093E800B801C601C8D9809141
:10248000E8008E778093E80021E0711001C020E021
:1024900030E0021B130B2C0D3D1D462D4150672DC6
:1024A000C7010E946E04882D992D0FB6F8949EBF27
:1024B0000FBE8DBF59C08091EE01813A09F054C022
:1024C0008091E800877F8093E8008091E80080FF9A
:1024D000FCCFF701818540C08091EE01813209F087
:1024E00043C08091E800877F8093E800A6DA90914E
:1024F000F00181E0911101C080E0F701818734C0D3
:102500008091EE01813281F58091E800877F809390
:10251000E80093DA8091F0019091F101882736E08C
:10252000969587953A95E1F7F701958784871CC0C2
:102530008091EE01813AC1F48091E800877F809319
:10254000E8008091E80080FFFCCFF7018485958545
:1025500096958795969587958093F1008091E800F0
:102560008E778093E80069DA0FB6F894BEBE0FBE8E
:10257000ADBE0F900F900F90DF91CF911F910F91F3
:10258000FF90EF90DF90CF90BF90AF909F908F9093
:102590007F906F9008959C01275F3F4FF90127E0DE
:1025A000DF011D922A95E9F721E0FC01218724EF44
:1025B00031E03587248723E0248361E00196FFC959
:1025C0004F925F926F927F928F929F92AF92BF9243
:1025D000CF92DF92EF92FF920F931F93CF93DF93EF
:1025E00000D01F92CDB7DEB77C01ADB6BEB68091EC
:1025F000ED01843009F08FC08091E4009091E500F6
:10260000F701228533852817390709F484C08181B1
:102610008F708093E9008091E80085FF7CC06DB6E3
:102620007EB640858DB79EB7841B91090FB6F8948E
:102630009EBF0FBE8DBFCDB6DEB6EFEFCE1ADE0A5F
:102640001B821A821982460150E060E070E0C601E8
:10265000B3D08E010F5F1F4F960140E0BE016D5F4A
:102660007F4FC7010E94EE04582EF701848595859F
:10267000892B31F001E010E086859785892B11F0D8
:1026800000E010E0F701C680D780C114D10489F0C2
:1026900049815A81B601C40179D0442443940097FA
:1026A00009F4412CF701408550E0B401C6017BD00C
:1026B00001C0412C89819A81892BF9F0511004C005
:1026C000411002C000FF19C0F701848595859787E6
:1026D000868781818F708093E9008B81811180933F
:1026E000F10069817A8140E050E0C4010E945A0BF8
:1026F0008091E8008E778093E8008091E4009091CB
:10270000E500F70193878287862D972D0FB6F89401
:102710009EBF0FBE8DBF0FB6F894BEBE0FBEADBE3E
:102720000F900F900F90DF91CF911F910F91FF901D
:10273000EF90DF90CF90BF90AF909F908F907F9061
:102740006F905F904F900895A1E21A2EAA1BBB1BB9
:10275000FD010DC0AA1FBB1FEE1FFF1FA217B3076D
:10276000E407F50720F0A21BB30BE40BF50B661F83
:10277000771F881F991F1A9469F760957095809547
:1027800090959B01AC01BD01CF010895FB01DC01D7
:1027900004C08D910190801921F441505040C8F738
:1027A000881B990B0895FB01DC0102C001900D927A
:1027B00041505040D8F70895DC0101C06D9341505D
:0A27C0005040E0F70895F894FFCFB1
:1027CA0002811000000100000F000000000000005C
:1027DA00008340000001044000000182080000015B
:1027EA00000000000000000000000004080F0801BB
:0E27FA000F0F0F0F000000000000030330203F
:00000001FF

View file

@ -1,196 +0,0 @@
#######################################
# Syntax Coloring Map For HID
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
#######################################
# Methods and Functions (KEYWORD2)
#######################################
begin KEYWORD2
end KEYWORD2
click KEYWORD2
move KEYWORD2
write KEYWORD2
press KEYWORD2
isPressed KEYWORD2
releaseAll KEYWORD2
buttons KEYWORD2
xAxis KEYWORD2
yAxis KEYWORD2
zAxis KEYWORD2
rxAxis KEYWORD2
ryAxis KEYWORD2
rzAxis KEYWORD2
dPad1 KEYWORD2
dPad2 KEYWORD2
HID_SendReport KEYWORD2
#######################################
# Classes (KEYWORD3)
#######################################
HID KEYWORD3
Mouse KEYWORD3
Keyboard KEYWORD3
RawHID KEYWORD3
Media KEYWORD3
System KEYWORD3
Gamepad1 KEYWORD3
Gamepad2 KEYWORD3
Gamepad3 KEYWORD3
Gamepad4 KEYWORD3
Joystick1 KEYWORD3
Joystick2 KEYWORD3
#######################################
# Instances (KEYWORD2)
#######################################
#######################################
# Constants (LITERAL1)
#######################################
#General
SERIAL_HID_BAUD LITERAL1
#Mouse
MOUSE_LEFT LITERAL1
MOUSE_RIGHT LITERAL1
MOUSE_MIDDLE LITERAL1
MOUSE_PREV LITERAL1
MOUSE_NEXT LITERAL1
#Keyboard
KEY_LEFT_CTRL LITERAL1
KEY_LEFT_SHIFT LITERAL1
KEY_LEFT_ALT LITERAL1
KEY_LEFT_GUI LITERAL1
KEY_RIGHT_CTRL LITERAL1
KEY_RIGHT_SHIFT LITERAL1
KEY_RIGHT_ALT LITERAL1
KEY_RIGHT_GUI LITERAL1
KEY_UP_ARROW LITERAL1
KEY_DOWN_ARROW LITERAL1
KEY_LEFT_ARROW LITERAL1
KEY_RIGHT_ARROW LITERAL1
KEY_BACKSPACE LITERAL1
KEY_TAB LITERAL1
KEY_RETURN LITERAL1
KEY_ESC LITERAL1
KEY_INSERT LITERAL1
KEY_DELETE LITERAL1
KEY_PAGE_UP LITERAL1
KEY_PAGE_DOWN LITERAL1
KEY_HOME LITERAL1
KEY_END LITERAL1
KEY_CAPS_LOCK LITERAL1
KEY_F1 LITERAL1
KEY_F2 LITERAL1
KEY_F3 LITERAL1
KEY_F4 LITERAL1
KEY_F5 LITERAL1
KEY_F6 LITERAL1
KEY_F7 LITERAL1
KEY_F8 LITERAL1
KEY_F9 LITERAL1
KEY_F10 LITERAL1
KEY_F11 LITERAL1
KEY_F12 LITERAL1
KEY_PRINT LITERAL1
KEY_SCROLL_LOCK LITERAL1
KEY_PAUSE LITERAL1
#Raw Keyboard definitions
RAW_KEYBOARD_LEFT_CTRL LITERAL1
RAW_KEYBOARD_LEFT_SHIFT LITERAL1
RAW_KEYBOARD_LEFT_ALT LITERAL1
RAW_KEYBOARD_LEFT_GUI LITERAL1
RAW_KEYBOARD_RIGHT_CTRL LITERAL1
RAW_KEYBOARD_RIGHT_SHIFT LITERAL1
RAW_KEYBOARD_RIGHT_ALT LITERAL1
RAW_KEYBOARD_RIGHT_GUI LITERAL1
RAW_KEYBOARD_UP_ARROW LITERAL1
RAW_KEYBOARD_DOWN_ARROW LITERAL1
RAW_KEYBOARD_LEFT_ARROW LITERAL1
RAW_KEYBOARD_RIGHT_ARROW LITERAL1
RAW_KEYBOARD_SPACEBAR LITERAL1
RAW_KEYBOARD_BACKSPACE LITERAL1
RAW_KEYBOARD_TAB LITERAL1
RAW_KEYBOARD_RETURN LITERAL1
RAW_KEYBOARD_ESC LITERAL1
RAW_KEYBOARD_INSERT LITERAL1
RAW_KEYBOARD_DELETE LITERAL1
RAW_KEYBOARD_PAGE_UP LITERAL1
RAW_KEYBOARD_PAGE_DOWN LITERAL1
RAW_KEYBOARD_HOME LITERAL1
RAW_KEYBOARD_END LITERAL1
RAW_KEYBOARD_CAPS_LOCK LITERAL1
RAW_KEYBOARD_F1 LITERAL1
RAW_KEYBOARD_F2 LITERAL1
RAW_KEYBOARD_F3 LITERAL1
RAW_KEYBOARD_F4 LITERAL1
RAW_KEYBOARD_F5 LITERAL1
RAW_KEYBOARD_F6 LITERAL1
RAW_KEYBOARD_F7 LITERAL1
RAW_KEYBOARD_F8 LITERAL1
RAW_KEYBOARD_F9 LITERAL1
RAW_KEYBOARD_F10 LITERAL1
RAW_KEYBOARD_F11 LITERAL1
RAW_KEYBOARD_F12 LITERAL1
RAW_KEYBOARD_PRINT LITERAL1
RAW_KEYBOARD_SCROLL_LOCK LITERAL1
RAW_KEYBOARD_PAUSE LITERAL1
#RawHID
RAWHID_RX_SIZE LITERAL1
RAWHID_TX_SIZE LITERAL1
#Media
MEDIA_FAST_FORWARD LITERAL1
MEDIA_REWIND LITERAL1
MEDIA_NEXT LITERAL1
MEDIA_PREVIOUS LITERAL1
MEDIA_STOP LITERAL1
MEDIA_PLAY_PAUSE LITERAL1
MEDIA_VOLUME_MUTE LITERAL1
MEDIA_VOLUME_UP LITERAL1
MEDIA_VOLUME_DOWN LITERAL1
MEDIA_EMAIL_READER LITERAL1
MEDIA_CALCULATOR LITERAL1
MEDIA_EXPLORER LITERAL1
MEDIA_BROWSER_HOME LITERAL1
MEDIA_BROWSER_BACK LITERAL1
MEDIA_BROWSER_FORWARD LITERAL1
MEDIA_BROWSER_REFRESH LITERAL1
MEDIA_BROWSER_BOOKMARKS LITERAL1
#System
SYSTEM_POWER_DOWN LITERAL1
SYSTEM_SLEEP LITERAL1
SYSTEM_WAKE_UP LITERAL1
#Gamepad
GAMEPAD_DPAD_CENTERED LITERAL1
GAMEPAD_DPAD_UP LITERAL1
GAMEPAD_DPAD_UP_RIGHT LITERAL1
GAMEPAD_DPAD_RIGHT LITERAL1
GAMEPAD_DPAD_DOWN_RIGHT LITERAL1
GAMEPAD_DPAD_DOWN LITERAL1
GAMEPAD_DPAD_DOWN_LEFT LITERAL1
GAMEPAD_DPAD_LEFT LITERAL1
GAMEPAD_DPAD_UP_LEFT LITERAL1

71
wiring_private.h Normal file
View file

@ -0,0 +1,71 @@
/*
wiring_private.h - Internal header file.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
*/
#ifndef WiringPrivate_h
#define WiringPrivate_h
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include <stdarg.h>
#include "Arduino.h"
#ifdef __cplusplus
extern "C"{
#endif
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define EXTERNAL_INT_0 0
#define EXTERNAL_INT_1 1
#define EXTERNAL_INT_2 2
#define EXTERNAL_INT_3 3
#define EXTERNAL_INT_4 4
#define EXTERNAL_INT_5 5
#define EXTERNAL_INT_6 6
#define EXTERNAL_INT_7 7
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega128RFA1__) || defined(__AVR_ATmega256RFR2__)
#define EXTERNAL_NUM_INTERRUPTS 8
#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
#define EXTERNAL_NUM_INTERRUPTS 3
#elif defined(__AVR_ATmega32U4__)
#define EXTERNAL_NUM_INTERRUPTS 5
#else
#define EXTERNAL_NUM_INTERRUPTS 2
#endif
typedef void (*voidFuncPtr)(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif