Reworked library completely + HID fixes
This commit is contained in:
parent
ea39ad5ca6
commit
e2aaa54532
25 changed files with 1513 additions and 1487 deletions
63
Firmwares/Joystick.cpp
Normal file
63
Firmwares/Joystick.cpp
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
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 "Joystick.h"
|
||||
|
||||
//================================================================================
|
||||
// Joystick
|
||||
//================================================================================
|
||||
|
||||
Joystick_ Joystick1(HID_REPORTID_Joystick1Report);
|
||||
Joystick_ Joystick2(HID_REPORTID_Joystick2Report);
|
||||
|
||||
Joystick_::Joystick_(uint8_t reportID){
|
||||
_reportID = reportID;
|
||||
}
|
||||
|
||||
void Joystick_::begin(void){
|
||||
memset(&_report, 0, sizeof(_report));
|
||||
HID_SendReport(_reportID, &_report, sizeof(_report));
|
||||
}
|
||||
|
||||
void Joystick_::end(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
void Joystick_::write(void){
|
||||
HID_SendReport(_reportID, &_report, sizeof(_report));;
|
||||
}
|
||||
|
||||
void Joystick_::press(uint8_t b){
|
||||
if (b == 1) _report.button1 = 1;
|
||||
else if (b == 2) _report.button2 = 1;
|
||||
}
|
||||
|
||||
void Joystick_::release(uint8_t b){
|
||||
if (b == 1) _report.button1 = 0;
|
||||
else if (b == 2) _report.button2 = 0;
|
||||
}
|
||||
|
||||
void Joystick_::releaseAll(void){
|
||||
_report.button1 = 0;
|
||||
_report.button2 = 0;
|
||||
}
|
||||
55
Firmwares/Joystick.h
Normal file
55
Firmwares/Joystick.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
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 JOYSTICK_H
|
||||
#define JOYSTICK_H
|
||||
|
||||
#include "HID.h"
|
||||
|
||||
//================================================================================
|
||||
// Joystick
|
||||
//================================================================================
|
||||
|
||||
class Joystick_{
|
||||
public:
|
||||
Joystick_(uint8_t reportID);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void write(void);
|
||||
void press(uint8_t b);
|
||||
void release(uint8_t b);
|
||||
void releaseAll(void);
|
||||
inline void buttons(uint8_t b){ _report.buttons = b; }
|
||||
inline void xAxis(uint16_t a){ _report.xAxis = a; }
|
||||
inline void yAxis(uint16_t a){ _report.yAxis = a; }
|
||||
|
||||
private:
|
||||
HID_JoystickReport_Data_t _report;
|
||||
uint8_t _reportID;
|
||||
};
|
||||
extern Joystick_ Joystick1;
|
||||
extern Joystick_ Joystick2;
|
||||
|
||||
#endif
|
||||
|
||||
88
Gamepad.h
Normal file
88
Gamepad.h
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
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
|
||||
//================================================================================
|
||||
|
||||
class Gamepad{
|
||||
public:
|
||||
inline Gamepad(uint8_t num){
|
||||
switch (num){
|
||||
case 1:
|
||||
_reportID = HID_REPORTID_Gamepad1Report;
|
||||
break;
|
||||
case 2:
|
||||
_reportID = HID_REPORTID_Gamepad1Report;
|
||||
break;
|
||||
case 3:
|
||||
_reportID = HID_REPORTID_Gamepad1Report;
|
||||
break;
|
||||
case 4:
|
||||
_reportID = HID_REPORTID_Gamepad1Report;
|
||||
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){ _report.buttons = 0;}
|
||||
|
||||
inline void buttons(uint32_t b){ _report.buttons = b; }
|
||||
inline void xAxis(uint16_t a){ _report.xAxis = a; }
|
||||
inline void yAxis(uint16_t a){ _report.yAxis = a; }
|
||||
inline void zAxis(uint8_t a){ _report.zAxis = a; }
|
||||
inline void rxAxis(uint16_t a){ _report.rxAxis = a; }
|
||||
inline void ryAxis(uint16_t a){ _report.ryAxis = a; }
|
||||
inline void rzAxis(uint8_t a){ _report.rzAxis = a; }
|
||||
inline void dPad1(uint8_t d){ _report.dPad1 = d; }
|
||||
inline void dPad2(uint8_t d){ _report.dPad2 = d; }
|
||||
private:
|
||||
HID_GamepadReport_Data_t _report;
|
||||
uint8_t _reportID;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -23,30 +23,120 @@ THE SOFTWARE.
|
|||
|
||||
#include "HID.h"
|
||||
|
||||
//================================================================================
|
||||
// Mouse
|
||||
//================================================================================
|
||||
|
||||
Mouse_ Mouse;
|
||||
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
//================================================================================
|
||||
|
||||
Keyboard_ Keyboard;
|
||||
|
||||
//================================================================================
|
||||
// RawHID
|
||||
//================================================================================
|
||||
|
||||
RawHID_ RawHID;
|
||||
|
||||
//================================================================================
|
||||
// Media
|
||||
//================================================================================
|
||||
|
||||
Media_ Media;
|
||||
|
||||
//================================================================================
|
||||
// System
|
||||
//================================================================================
|
||||
|
||||
System_ System;
|
||||
|
||||
//================================================================================
|
||||
// HID Uno/Mega
|
||||
//================================================================================
|
||||
|
||||
#ifndef USBCON
|
||||
|
||||
void HID_SendReport(uint8_t id, const void* data, int len)
|
||||
{
|
||||
// write the Report via Protocol and checksum. 16bit for each sending
|
||||
// send control address
|
||||
NHPwriteChecksum(NHP_ADDRESS_CONTROL, (NHP_USAGE_ARDUINOHID << 8) | id);
|
||||
const uint8_t* report = (const uint8_t*)data;
|
||||
for (int i = 0; i < len; i++){
|
||||
uint8_t data0 = report[i++];
|
||||
uint8_t data1 = 0;
|
||||
if (i != len)
|
||||
data1 = report[i];
|
||||
// valid HID reports start at Address 2
|
||||
NHPwriteChecksum(2 + i / 2, (data1 << 8) | data0);
|
||||
}
|
||||
}
|
||||
|
||||
// simple copy/modification of the NicoHoodProtocol writechecksum function
|
||||
void NHPwriteChecksum(uint8_t address, uint16_t indata){
|
||||
// writes two bytes with its inverse
|
||||
uint32_t temp = ~indata;
|
||||
uint32_t data = (temp << 16) | indata;
|
||||
|
||||
// buffer for write operation
|
||||
uint8_t writebuffer[6];
|
||||
|
||||
// start with the maximum size of blocks
|
||||
uint8_t blocks = 7;
|
||||
|
||||
// check for the first 7 bit block that doesnt fit into the first 3 bits
|
||||
while (blocks > 2){
|
||||
uint8_t nextvalue = (data >> (7 * (blocks - 3)));
|
||||
|
||||
if (nextvalue > NHP_MASK_DATA_3BIT){
|
||||
// special case for the MSB
|
||||
if (blocks == 7) {
|
||||
writebuffer[0] = nextvalue;
|
||||
blocks--;
|
||||
}
|
||||
// this block is too big, write this into the next data block
|
||||
break;
|
||||
}
|
||||
else{
|
||||
// write the possible first 3 bits and check again after if zero
|
||||
writebuffer[0] = nextvalue;
|
||||
blocks--;
|
||||
// we have our first bits, stop (nonzero)
|
||||
if (nextvalue)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// write the rest of the data bits
|
||||
uint8_t datablocks = blocks - 2;
|
||||
while (datablocks > 0){
|
||||
writebuffer[datablocks] = data & NHP_MASK_DATA_7BIT;
|
||||
data >>= 7;
|
||||
datablocks--;
|
||||
}
|
||||
|
||||
// write lead + length mask
|
||||
writebuffer[0] |= NHP_MASK_LEAD | (blocks << 3);
|
||||
|
||||
// write end mask
|
||||
writebuffer[blocks - 1] = NHP_MASK_END | ((address - 1) & NHP_MASK_ADDRESS);
|
||||
|
||||
// write the buffer
|
||||
HID_SERIAL.write(writebuffer, blocks);
|
||||
}
|
||||
|
||||
#else // #ifdef USBCON
|
||||
|
||||
//================================================================================
|
||||
// HID Leonardo/Micro
|
||||
//================================================================================
|
||||
|
||||
#if defined(USBCON)
|
||||
|
||||
HID_ HID;
|
||||
|
||||
HID_::HID_(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
void HID_::begin(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
void HID_::end(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
void HID_::sendReport(uint8_t ReportID, const void* HIDReport, uint8_t length){
|
||||
HID_SendReport(ReportID, HIDReport, length);
|
||||
}
|
||||
|
||||
#include "Platform.h"
|
||||
#include "USBAPI.h"
|
||||
#include "USBDesc.h"
|
||||
|
||||
#ifdef HID_ENABLED
|
||||
|
||||
|
|
@ -357,7 +447,7 @@ const u8 _hidReportDescriptor[] = {
|
|||
0x95, 0x01, // REPORT_COUNT (1)
|
||||
0x81, 0x03, // INPUT (Cnst,Var,Abs)
|
||||
0xc0, // END_COLLECTION
|
||||
0xc0 // END_COLLECTION
|
||||
0xc0, // END_COLLECTION
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
@ -391,6 +481,7 @@ int WEAK HID_GetDescriptor(int /* i */)
|
|||
|
||||
void WEAK HID_SendReport(u8 id, const void* data, int len)
|
||||
{
|
||||
|
||||
USB_Send(HID_TX, &id, 1);
|
||||
USB_Send(HID_TX | TRANSFER_RELEASE, data, len);
|
||||
}
|
||||
|
|
@ -430,598 +521,6 @@ bool WEAK HID_Setup(Setup& setup)
|
|||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // #ifdef HID_ENABLED
|
||||
|
||||
//================================================================================
|
||||
// HID Uno/Mega
|
||||
//================================================================================
|
||||
|
||||
#else /* if defined(USBCON) */
|
||||
|
||||
HID_ HID;
|
||||
|
||||
HID_::HID_(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
void HID_::begin(void){
|
||||
HID_SERIAL.begin(115200);
|
||||
}
|
||||
|
||||
void HID_::end(void){
|
||||
HID_SERIAL.end();
|
||||
}
|
||||
|
||||
void HID_::sendReport(uint8_t ReportID, const void* HIDReport, uint8_t length){
|
||||
// write the Report via Protocol and checksum. 16bit for each sending
|
||||
// send control address
|
||||
NHPwriteChecksum(NHP_ADDRESS_CONTROL, (NHP_USAGE_ARDUINOHID << 8) | ReportID);
|
||||
const uint8_t* report = (const uint8_t*)HIDReport;
|
||||
for (int i = 0; i < length; i++){
|
||||
uint8_t data0 = report[i++];
|
||||
uint8_t data1 = 0;
|
||||
if (i != length)
|
||||
data1 = report[i];
|
||||
// valid HID reports start at Address 2
|
||||
NHPwriteChecksum(2 + i / 2, (data1 << 8) | data0);
|
||||
}
|
||||
}
|
||||
#endif /* if defined(USBCON) */
|
||||
|
||||
// simple copy/modification of the NicoHoodProtocol writechecksum function
|
||||
void HID_::NHPwriteChecksum(uint8_t address, uint16_t indata){
|
||||
// writes two bytes with its inverse
|
||||
uint32_t temp = ~indata;
|
||||
uint32_t data = (temp << 16) | indata;
|
||||
|
||||
// buffer for write operation
|
||||
uint8_t writebuffer[6];
|
||||
|
||||
// start with the maximum size of blocks
|
||||
uint8_t blocks = 7;
|
||||
|
||||
// check for the first 7 bit block that doesnt fit into the first 3 bits
|
||||
while (blocks > 2){
|
||||
uint8_t nextvalue = (data >> (7 * (blocks - 3)));
|
||||
|
||||
if (nextvalue > NHP_MASK_DATA_3BIT){
|
||||
// special case for the MSB
|
||||
if (blocks == 7) {
|
||||
writebuffer[0] = nextvalue;
|
||||
blocks--;
|
||||
}
|
||||
// this block is too big, write this into the next data block
|
||||
break;
|
||||
}
|
||||
else{
|
||||
// write the possible first 3 bits and check again after if zero
|
||||
writebuffer[0] = nextvalue;
|
||||
blocks--;
|
||||
// we have our first bits, stop (nonzero)
|
||||
if (nextvalue)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// write the rest of the data bits
|
||||
uint8_t datablocks = blocks - 2;
|
||||
while (datablocks > 0){
|
||||
writebuffer[datablocks] = data & NHP_MASK_DATA_7BIT;
|
||||
data >>= 7;
|
||||
datablocks--;
|
||||
}
|
||||
|
||||
// write lead + length mask
|
||||
writebuffer[0] |= NHP_MASK_LEAD | (blocks << 3);
|
||||
|
||||
// write end mask
|
||||
writebuffer[blocks - 1] = NHP_MASK_END | ((address - 1) & NHP_MASK_ADDRESS);
|
||||
|
||||
// write the buffer
|
||||
HID_SERIAL.write(writebuffer, blocks);
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// Mouse
|
||||
//================================================================================
|
||||
|
||||
Mouse_ Mouse;
|
||||
|
||||
Mouse_::Mouse_(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
void Mouse_::begin(void){
|
||||
memset(&_report, 0, sizeof(_report));
|
||||
HID.sendReport(HID_REPORTID_MouseReport, &_report, sizeof(_report));
|
||||
}
|
||||
|
||||
void Mouse_::end(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
void Mouse_::click(uint8_t b){
|
||||
_report.buttons = b;
|
||||
move(0, 0, 0);
|
||||
_report.buttons = 0;
|
||||
move(0, 0, 0);
|
||||
}
|
||||
|
||||
void Mouse_::move(signed char x, signed char y, signed char wheel){
|
||||
_report.xAxis = x;
|
||||
_report.yAxis = y;
|
||||
_report.wheel = wheel;
|
||||
HID.sendReport(HID_REPORTID_MouseReport, &_report, sizeof(HID_MouseReport_Data_t));
|
||||
}
|
||||
|
||||
void Mouse_::buttons(uint8_t b){
|
||||
if (b != _report.buttons) {
|
||||
_report.buttons = b;
|
||||
move(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Mouse_::press(uint8_t b){
|
||||
buttons(_report.buttons | b);
|
||||
}
|
||||
|
||||
void Mouse_::release(uint8_t b){
|
||||
buttons(_report.buttons & ~b);
|
||||
}
|
||||
|
||||
void Mouse_::releaseAll(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
bool Mouse_::isPressed(uint8_t b){
|
||||
if ((b & _report.buttons) > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// Keyboard
|
||||
//================================================================================
|
||||
|
||||
Keyboard_ Keyboard;
|
||||
|
||||
Keyboard_::Keyboard_(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
void Keyboard_::begin(void){
|
||||
memset(&_report, 0, sizeof(_report));
|
||||
HID.sendReport(HID_REPORTID_KeyboardReport, &_report, sizeof(_report));
|
||||
}
|
||||
|
||||
void Keyboard_::end(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
// removed <--
|
||||
//uint8_t USBPutChar(uint8_t c);
|
||||
|
||||
size_t Keyboard_::write(uint8_t c)
|
||||
{
|
||||
uint8_t p = press(c); // Keydown
|
||||
//uint8_t r =
|
||||
release(c); // Keyup
|
||||
return (p); // just return the result of press() since release() almost always returns 1
|
||||
}
|
||||
|
||||
// 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
|
||||
_report.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
|
||||
_report.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 (_report.keys[0] != k && _report.keys[1] != k &&
|
||||
_report.keys[2] != k && _report.keys[3] != k &&
|
||||
_report.keys[4] != k && _report.keys[5] != k) {
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (_report.keys[i] == 0x00) {
|
||||
_report.keys[i] = k;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 6) {
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
HID.sendReport(HID_REPORTID_KeyboardReport, &_report, sizeof(_report));
|
||||
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
|
||||
_report.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
|
||||
_report.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 && _report.keys[i] == k) {
|
||||
_report.keys[i] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
HID.sendReport(HID_REPORTID_KeyboardReport, &_report, sizeof(_report));
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Keyboard_::releaseAll(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// RawHID
|
||||
//================================================================================
|
||||
|
||||
RawHID_ RawHID;
|
||||
|
||||
RawHID_::RawHID_(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
size_t RawHID_::write(uint8_t b){
|
||||
write(&b, 1);
|
||||
}
|
||||
|
||||
size_t RawHID_::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);
|
||||
}
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// Media
|
||||
//================================================================================
|
||||
|
||||
Media_ Media;
|
||||
|
||||
Media_::Media_(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
void Media_::begin(void){
|
||||
memset(&_report, 0, sizeof(_report));
|
||||
HID.sendReport(HID_REPORTID_MediaReport, &_report, sizeof(_report));
|
||||
}
|
||||
|
||||
void Media_::end(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
void Media_::write(uint16_t m){
|
||||
press(m);
|
||||
release(m);
|
||||
}
|
||||
|
||||
void Media_::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));
|
||||
}
|
||||
|
||||
void Media_::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));
|
||||
}
|
||||
|
||||
void Media_::releaseAll(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// System
|
||||
//================================================================================
|
||||
|
||||
System_ System;
|
||||
|
||||
System_::System_(void){
|
||||
// empty
|
||||
}
|
||||
|
||||
void System_::begin(void){
|
||||
uint8_t _report = 0;
|
||||
HID.sendReport(HID_REPORTID_SystemReport, &_report, sizeof(_report));
|
||||
}
|
||||
|
||||
void System_::end(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
void System_::write(uint8_t s){
|
||||
press(s);
|
||||
release();
|
||||
}
|
||||
|
||||
void System_::press(uint8_t s){
|
||||
HID.sendReport(HID_REPORTID_SystemReport, &s, sizeof(s));
|
||||
}
|
||||
|
||||
void System_::release(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
void System_::releaseAll(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// Gamepad
|
||||
//================================================================================
|
||||
|
||||
Gamepad_ Gamepad1(HID_REPORTID_Gamepad1Report);
|
||||
Gamepad_ Gamepad2(HID_REPORTID_Gamepad2Report);
|
||||
|
||||
Gamepad_::Gamepad_(uint8_t reportID){
|
||||
_reportID = reportID;
|
||||
// empty
|
||||
}
|
||||
|
||||
void Gamepad_::begin(void){
|
||||
memset(&_report, 0, sizeof(_report));
|
||||
HID.sendReport(_reportID, &_report, sizeof(_report));
|
||||
}
|
||||
|
||||
void Gamepad_::end(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
void Gamepad_::write(void){
|
||||
HID.sendReport(_reportID, &_report, sizeof(_report));
|
||||
}
|
||||
|
||||
void Gamepad_::press(uint8_t b){
|
||||
_report.buttons |= (uint32_t)1 << (b - 1);
|
||||
}
|
||||
|
||||
void Gamepad_::release(uint8_t b){
|
||||
_report.buttons &= ~((uint32_t)1 << (b - 1));
|
||||
}
|
||||
|
||||
void Gamepad_::releaseAll(void){
|
||||
_report.buttons = 0;
|
||||
}
|
||||
|
||||
//================================================================================
|
||||
// Joystick
|
||||
//================================================================================
|
||||
|
||||
Joystick_ Joystick1(HID_REPORTID_Joystick1Report);
|
||||
Joystick_ Joystick2(HID_REPORTID_Joystick2Report);
|
||||
|
||||
Joystick_::Joystick_(uint8_t reportID){
|
||||
_reportID = reportID;
|
||||
// empty
|
||||
}
|
||||
|
||||
void Joystick_::begin(void){
|
||||
memset(&_report, 0, sizeof(_report));
|
||||
HID.sendReport(_reportID, &_report, sizeof(_report));
|
||||
}
|
||||
|
||||
void Joystick_::end(void){
|
||||
begin();
|
||||
}
|
||||
|
||||
void Joystick_::write(void){
|
||||
HID.sendReport(_reportID, &_report, sizeof(_report));;
|
||||
}
|
||||
|
||||
void Joystick_::press(uint8_t b){
|
||||
if (b == 1) _report.button1 = 1;
|
||||
else if (b == 2) _report.button2 = 1;
|
||||
}
|
||||
|
||||
void Joystick_::release(uint8_t b){
|
||||
if (b == 1) _report.button1 = 0;
|
||||
else if (b == 2) _report.button2 = 0;
|
||||
}
|
||||
|
||||
void Joystick_::releaseAll(void){
|
||||
_report.button1 = 0;
|
||||
_report.button2 = 0;
|
||||
}
|
||||
#endif /* if defined(USBCON) */
|
||||
136
HID.h
Normal file
136
HID.h
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
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_JOYSTICK1_ENABLE 51
|
||||
//#define HID_JOYSTICK2_ENABLE 51
|
||||
|
||||
//================================================================================
|
||||
// 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
|
||||
|
||||
|
|
@ -33,8 +33,8 @@ THE SOFTWARE.
|
|||
|
||||
#define RAWHID_USAGE_PAGE 0xFFC0 // recommended: 0xFF00 to 0xFFFF
|
||||
#define RAWHID_USAGE 0x0C00 // recommended: 0x0100 to 0xFFFF
|
||||
#define RAWHID_TX_SIZE 63 // 1 byte for report ID
|
||||
#define RAWHID_RX_SIZE 63 // 1 byte for report ID
|
||||
#define RAWHID_TX_SIZE 15 // 1 byte for report ID
|
||||
#define RAWHID_RX_SIZE 15 // 1 byte for report ID
|
||||
|
||||
//================================================================================
|
||||
//Report Typedefinitions
|
||||
|
|
@ -43,12 +43,12 @@ THE SOFTWARE.
|
|||
typedef union{
|
||||
// mouse report: 5 buttons, position, wheel
|
||||
uint8_t whole8[4];
|
||||
uint16_t whole16[4/2];
|
||||
uint32_t whole32[4/4];
|
||||
uint16_t whole16[4 / 2];
|
||||
uint32_t whole32[4 / 4];
|
||||
|
||||
struct{
|
||||
uint8_t buttons:5;
|
||||
uint8_t reserved:3;
|
||||
uint8_t buttons : 5;
|
||||
uint8_t reserved : 3;
|
||||
int8_t xAxis;
|
||||
int8_t yAxis;
|
||||
int8_t wheel;
|
||||
|
|
@ -59,8 +59,8 @@ typedef union{
|
|||
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];
|
||||
uint16_t whole16[8 / 2];
|
||||
uint32_t whole32[8 / 4];
|
||||
|
||||
struct{
|
||||
uint8_t modifiers;
|
||||
|
|
@ -82,8 +82,8 @@ typedef union{
|
|||
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];
|
||||
uint16_t whole16[8 / 2];
|
||||
uint32_t whole32[8 / 4];
|
||||
|
||||
struct{
|
||||
uint16_t key1;
|
||||
|
|
@ -103,63 +103,58 @@ typedef union{
|
|||
|
||||
typedef union {
|
||||
// 32 Buttons, 6 Axis, 2 D-Pads
|
||||
uint8_t whole8[17];
|
||||
uint16_t whole16[17/2];
|
||||
uint32_t whole32[17/4];
|
||||
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 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 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 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;
|
||||
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;
|
||||
|
||||
uint16_t xAxis;
|
||||
uint16_t yAxis;
|
||||
uint16_t zAxis;
|
||||
uint8_t zAxis;
|
||||
|
||||
uint16_t rxAxis;
|
||||
uint16_t ryAxis;
|
||||
uint16_t rzAxis;
|
||||
|
||||
uint8_t dPad1: 4;
|
||||
uint8_t dPad2: 4;
|
||||
|
||||
// deactivated because windows only supports 7 axis. should be enough.
|
||||
//uint8_t throttle;
|
||||
//uint8_t rudder;
|
||||
uint8_t rzAxis;
|
||||
|
||||
uint8_t dPad1 : 4;
|
||||
uint8_t dPad2 : 4;
|
||||
};
|
||||
} HID_GamepadReport_Data_t;
|
||||
|
||||
|
|
@ -167,15 +162,15 @@ typedef union {
|
|||
typedef union{
|
||||
// 2 Buttons, 2 Axis
|
||||
uint8_t whole8[3];
|
||||
uint16_t whole16[3/2];
|
||||
uint8_t buttons :2;
|
||||
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;
|
||||
uint16_t button1 : 1;
|
||||
uint16_t button2 : 1;
|
||||
uint16_t xAxis : 10;
|
||||
uint16_t yAxis : 10;
|
||||
uint16_t reserved : 2;
|
||||
};
|
||||
} HID_JoystickReport_Data_t;
|
||||
|
||||
|
|
@ -194,15 +189,17 @@ typedef union{
|
|||
|
||||
/** Enum for the HID report IDs used in the device. */
|
||||
typedef enum{
|
||||
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_Joystick1Report = 0x08, /**< Report ID for the Joystick1 report within the device. */
|
||||
HID_REPORTID_Joystick2Report = 0x09, /**< Report ID for the Joystick2 report within the device. */
|
||||
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_Joystick1Report = 0x08, /**< Report ID for the Joystick1 report within the device. */
|
||||
HID_REPORTID_Joystick2Report = 0x09, /**< Report ID for the Joystick2 report within the device. */
|
||||
HID_REPORTID_LastNotAReport, // determinate whats the maximum number of reports -1
|
||||
} HID_Report_IDs;
|
||||
|
||||
#endif
|
||||
359
HID_Source/HID.h
359
HID_Source/HID.h
|
|
@ -1,359 +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>
|
||||
#include "HID_Reports.h"
|
||||
|
||||
#ifdef USBCON
|
||||
#include "Platform.h"
|
||||
#include "USBAPI.h"
|
||||
#include "USBDesc.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_JOYSTICK1_ENABLE 51
|
||||
//#define HID_JOYSTICK2_ENABLE 51
|
||||
|
||||
#endif
|
||||
|
||||
//================================================================================
|
||||
// HID
|
||||
//================================================================================
|
||||
|
||||
//NHP Definitions
|
||||
|
||||
// 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
|
||||
|
||||
class HID_{
|
||||
public:
|
||||
HID_(void);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
|
||||
// everything public for your own modifications
|
||||
void sendReport(uint8_t ReportID, const void* HIDReport, uint8_t length);
|
||||
private:
|
||||
// simple copy/modification of the NicoHoodProtocol writechecksum function
|
||||
void NHPwriteChecksum(uint8_t address, uint16_t indata);
|
||||
};
|
||||
extern HID_ HID;
|
||||
|
||||
//================================================================================
|
||||
// Mouse
|
||||
//================================================================================
|
||||
|
||||
#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_{
|
||||
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
|
||||
void releaseAll(void);
|
||||
bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
|
||||
private:
|
||||
void buttons(uint8_t b);
|
||||
HID_MouseReport_Data_t _report;
|
||||
};
|
||||
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
|
||||
|
||||
//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
|
||||
|
||||
//Keyboard fixed/added missing Keys
|
||||
#define KEY_PRINT 0xCE
|
||||
#define KEY_SCROLL_LOCK 0xCF
|
||||
#define KEY_PAUSE 0xD0
|
||||
|
||||
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:
|
||||
HID_KeyboardReport_Data_t _report;
|
||||
};
|
||||
extern Keyboard_ Keyboard;
|
||||
|
||||
//================================================================================
|
||||
// RawHID
|
||||
//================================================================================
|
||||
|
||||
class RawHID_ : public Print{
|
||||
public:
|
||||
RawHID_(void);
|
||||
inline void begin(void){ /*empty*/ }
|
||||
inline void end(void){ /*empty*/ }
|
||||
using Print::write; // to get the String version of write
|
||||
size_t write(uint8_t b);
|
||||
size_t write(const uint8_t *buffer, size_t size);
|
||||
};
|
||||
extern RawHID_ RawHID;
|
||||
|
||||
//================================================================================
|
||||
// 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:
|
||||
Media_(void);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void write(uint16_t m);
|
||||
void press(uint16_t m);
|
||||
void release(uint16_t m);
|
||||
void releaseAll(void);
|
||||
private:
|
||||
HID_MediaReport_Data_t _report;
|
||||
};
|
||||
extern Media_ Media;
|
||||
|
||||
//================================================================================
|
||||
// System
|
||||
//================================================================================
|
||||
|
||||
#define SYSTEM_POWER_DOWN 0x81
|
||||
#define SYSTEM_SLEEP 0x82
|
||||
#define SYSTEM_WAKE_UP 0x83
|
||||
|
||||
class System_{
|
||||
public:
|
||||
System_(void);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void write(uint8_t s);
|
||||
void press(uint8_t s);
|
||||
void release(void);
|
||||
void releaseAll(void);
|
||||
};
|
||||
extern System_ System;
|
||||
|
||||
//================================================================================
|
||||
// Gamepad
|
||||
//================================================================================
|
||||
|
||||
class Gamepad_{
|
||||
public:
|
||||
Gamepad_(uint8_t reportID);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void write(void);
|
||||
void press(uint8_t b);
|
||||
void release(uint8_t b);
|
||||
void releaseAll(void);
|
||||
inline void buttons(uint32_t b){ _report.buttons = b; }
|
||||
inline void xAxis(uint16_t a){ _report.xAxis = a; }
|
||||
inline void yAxis(uint16_t a){ _report.yAxis = a; }
|
||||
inline void zAxis(uint16_t a){ _report.zAxis = a; }
|
||||
inline void rxAxis(uint16_t a){ _report.rxAxis = a; }
|
||||
inline void ryAxis(uint16_t a){ _report.ryAxis = a; }
|
||||
inline void rzAxis(uint16_t a){ _report.rzAxis = a; }
|
||||
inline void dPad1(uint8_t d){ _report.dPad1 = d; }
|
||||
inline void dPad2(uint8_t d){ _report.dPad2 = d; }
|
||||
private:
|
||||
HID_GamepadReport_Data_t _report;
|
||||
uint8_t _reportID;
|
||||
};
|
||||
extern Gamepad_ Gamepad1;
|
||||
extern Gamepad_ Gamepad2;
|
||||
|
||||
//================================================================================
|
||||
// Joystick
|
||||
//================================================================================
|
||||
|
||||
class Joystick_{
|
||||
public:
|
||||
Joystick_(uint8_t reportID);
|
||||
void begin(void);
|
||||
void end(void);
|
||||
void write(void);
|
||||
void press(uint8_t b);
|
||||
void release(uint8_t b);
|
||||
void releaseAll(void);
|
||||
inline void buttons(uint8_t b){ _report.buttons = b; }
|
||||
inline void xAxis(uint16_t a){ _report.xAxis = a; }
|
||||
inline void yAxis(uint16_t a){ _report.yAxis = a; }
|
||||
|
||||
private:
|
||||
HID_JoystickReport_Data_t _report;
|
||||
uint8_t _reportID;
|
||||
};
|
||||
extern Joystick_ Joystick1;
|
||||
extern Joystick_ Joystick2;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
HID Source
|
||||
==========
|
||||
|
||||
**Move and replace** these files to (depending on your version and path):
|
||||
```
|
||||
C:\Arduino\arduino-1.0.5\hardware\arduino\cores\arduino
|
||||
C:\Arduino\arduino-1.5.6-r2\hardware\arduino\avr\cores\arduino
|
||||
C:\Arduino\arduino-1.5.7\hardware\arduino\avr\cores\arduino
|
||||
```
|
||||
|
||||
Restart the IDE!
|
||||
|
|
@ -1,202 +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 __USBAPI__
|
||||
#define __USBAPI__
|
||||
|
||||
#if defined(USBCON)
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// USB
|
||||
|
||||
class USBDevice_
|
||||
{
|
||||
public:
|
||||
USBDevice_();
|
||||
bool configured();
|
||||
|
||||
void attach();
|
||||
void detach(); // Serial port goes down too...
|
||||
void poll();
|
||||
};
|
||||
extern USBDevice_ USBDevice;
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Serial over CDC (Serial1 is the physical port)
|
||||
|
||||
// v1.5.7 or newer
|
||||
#if ARDUINO >= 157
|
||||
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
|
||||
|
||||
// v1.5.0 - v1.5.6
|
||||
#elif ARDUINO >= 150
|
||||
struct ring_buffer;
|
||||
|
||||
#if (RAMEND < 1000)
|
||||
#define SERIAL_BUFFER_SIZE 16
|
||||
#else
|
||||
#define SERIAL_BUFFER_SIZE 64
|
||||
#endif
|
||||
|
||||
class Serial_ : public Stream
|
||||
{
|
||||
public:
|
||||
void begin(unsigned long);
|
||||
void begin(unsigned long, uint8_t);
|
||||
void end(void);
|
||||
|
||||
virtual int available(void);
|
||||
virtual void accept(void);
|
||||
virtual int peek(void);
|
||||
virtual int read(void);
|
||||
virtual void flush(void);
|
||||
virtual size_t write(uint8_t);
|
||||
using Print::write; // pull in write(str) and write(buf, size) from Print
|
||||
operator bool();
|
||||
|
||||
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
|
||||
|
||||
// v1.0.1 - v1.0.x
|
||||
#elif ARDUINO > 100
|
||||
class Serial_ : public Stream
|
||||
{
|
||||
private:
|
||||
ring_buffer *_cdc_rx_buffer;
|
||||
public:
|
||||
void begin(uint16_t baud_count);
|
||||
void end(void);
|
||||
|
||||
virtual int available(void);
|
||||
virtual void accept(void);
|
||||
virtual int peek(void);
|
||||
virtual int read(void);
|
||||
virtual void flush(void);
|
||||
virtual size_t write(uint8_t);
|
||||
using Print::write; // pull in write(str) and write(buf, size) from Print
|
||||
operator bool();
|
||||
};
|
||||
extern Serial_ Serial;
|
||||
#endif
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// Low level API
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t bmRequestType;
|
||||
uint8_t bRequest;
|
||||
uint8_t wValueL;
|
||||
uint8_t wValueH;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
} Setup;
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// HID 'Driver'
|
||||
|
||||
#include "HID.h"
|
||||
|
||||
int HID_GetInterface(uint8_t* interfaceNum);
|
||||
int HID_GetDescriptor(int i);
|
||||
bool HID_Setup(Setup& setup);
|
||||
void HID_SendReport(uint8_t id, const void* data, int len);
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// MSC 'Driver'
|
||||
|
||||
int MSC_GetInterface(uint8_t* interfaceNum);
|
||||
int MSC_GetDescriptor(int i);
|
||||
bool MSC_Setup(Setup& setup);
|
||||
bool MSC_Data(uint8_t rx,uint8_t tx);
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
// CSC 'Driver'
|
||||
|
||||
int CDC_GetInterface(uint8_t* interfaceNum);
|
||||
int CDC_GetDescriptor(int i);
|
||||
bool CDC_Setup(Setup& setup);
|
||||
|
||||
//================================================================================
|
||||
//================================================================================
|
||||
|
||||
#define TRANSFER_PGM 0x80
|
||||
#define TRANSFER_RELEASE 0x40
|
||||
#define TRANSFER_ZERO 0x20
|
||||
|
||||
int USB_SendControl(uint8_t flags, const void* d, int len);
|
||||
int USB_RecvControl(void* d, int len);
|
||||
|
||||
uint8_t USB_Available(uint8_t ep);
|
||||
int USB_Send(uint8_t ep, const void* data, int len); // blocking
|
||||
int USB_Recv(uint8_t ep, void* data, int len); // non-blocking
|
||||
int USB_Recv(uint8_t ep); // non-blocking
|
||||
void USB_Flush(uint8_t ep);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* if defined(USBCON) */
|
||||
291
Keyboard.cpp
Normal file
291
Keyboard.cpp
Normal file
|
|
@ -0,0 +1,291 @@
|
|||
/*
|
||||
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
|
||||
}
|
||||
151
Keyboard.h
Normal file
151
Keyboard.h
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
/*
|
||||
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
|
||||
//================================================================================
|
||||
|
||||
#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
|
||||
|
||||
//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
|
||||
|
||||
//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
Normal file
112
Media.h
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
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
|
||||
|
||||
95
Mouse.cpp
Normal file
95
Mouse.cpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
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
Normal file
69
Mouse.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
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
|
||||
|
||||
78
RawHID.h
Normal file
78
RawHID.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
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
|
||||
|
||||
124
Readme.md
124
Readme.md
|
|
@ -1,32 +1,32 @@
|
|||
Arduino HID Project BETA 1.7
|
||||
============================
|
||||
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.**
|
||||
**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 device stuff, no need for a bootloader.**
|
||||
**For the Leonardo/Micro it is 'just' new HID devices, no need for a bootloader.**
|
||||
|
||||
[Hoodloader Repository moved here.](https://github.com/NicoHood/Hoodloader)
|
||||
Note: [Hoodloader Repository moved here.](https://github.com/NicoHood/Hoodloader)
|
||||
|
||||
Features
|
||||
========
|
||||
Use your **Arduino Uno, Mega, Micro, Leonardo or Micro Pro** as Generic HID Device and still be able to upload sketches how you are used to do.
|
||||
This project provides a new bootloader (Hoodloader) for the 8u2/16u2 and HID libraries Arduino Uno/Mega and Micro/Leonardo.
|
||||
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
|
||||
* 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 (newer versions might need an update)
|
||||
* Compatible with Linux/Mac/Windows XP/7/8.1
|
||||
* Compatible with IDE 1.0.x - 1.5.7
|
||||
|
||||
**The following devices are supported:**
|
||||
|
||||
|
|
@ -41,20 +41,26 @@ I also corrected some bugs in the original sources.
|
|||
* [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
|
||||
====================================
|
||||
Download the library and install like you are used to (access the examples, keywords.txt with IDE).
|
||||
Then **move and replace** all files from "HID_Source" to the folder that matches your Arduino IDE version to one of these paths
|
||||
(depending on your version):
|
||||
```
|
||||
C:\Arduino\arduino-1.0.5\hardware\arduino\cores\arduino
|
||||
C:\Arduino\arduino-1.5.6-r2\hardware\arduino\avr\cores\arduino
|
||||
C:\Arduino\arduino-1.5.7\hardware\arduino\avr\cores\arduino
|
||||
```
|
||||
The installation path may differ to yours. Newer Versions than 1.5.7 may not work.
|
||||
Restart the IDE!
|
||||
Download the library and [install it](http://arduino.cc/en/pmwiki.php?n=Guide/Libraries) like you are used to.
|
||||
|
||||
**I strongly recommend to install the library like this. Otherwise it wont work.**
|
||||
**For the whole Project IDE 1.5.7 or higher is recommended!**
|
||||
|
||||
#### Leonardo/Micro only
|
||||
**Edit HID.h to de/activate usb functions.**
|
||||
|
|
@ -62,37 +68,49 @@ 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.
|
||||
By default Mouse, Keyboard, Media, System, Gamepad1 is activated.
|
||||
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 only
|
||||
To **install the new bootloader** connect your Arduino to your PC via USB and see
|
||||
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.**
|
||||
|
||||
For Arduino Mega2560 I recommend (in general) the IDE 1.5.7 or higher. [See Issue on Github.](https://github.com/arduino/Arduino/issues/1071)
|
||||
[Or this Issue.)(http://forum.arduino.cc/index.php?topic=126160.0)
|
||||
|
||||
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).
|
||||
|
||||
The HID include and HID.begin() is not needed for **Leonardo/Micro** but I'd recommend
|
||||
to use it every time so you can port the library from one to another device.
|
||||
**#include <HID.h> is now needed for every device.**
|
||||
|
||||
**On Arduino/Mega you can only use baud 115200 for HID** due to programming reasons. Its not bad anyway
|
||||
because its the fastest baud and you want fast HID recognition. You still can use any other baud for
|
||||
normal sketches without but HID wont work. If you try nevertheless it will output Serial crap to the Monitor.
|
||||
HID.begin() starts the Serial at baud 115200 on Arduino Uno/Mega. Do not call Serial.begin() again.
|
||||
**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.
|
||||
See [Deactivate HID function](https://github.com/NicoHood/Hoodloader) if you need to fully disable HID again.
|
||||
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, has nothing to do with HID function) see [Hoodloader repository](https://github.com/NicoHood/Hoodloader).
|
||||
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 ide files, replace the original files and install the library like you are used to.
|
||||
|
||||
Hoodloader:
|
||||
|
||||
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
|
||||
============
|
||||
|
|
@ -101,8 +119,12 @@ 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 library wouldnt be possible without
|
||||
This project wouldnt be possible without
|
||||
========================================
|
||||
|
||||
* [Lufa 140302 from Dean Camera](http://www.fourwalledcubicle.com/LUFA.php)
|
||||
|
|
@ -120,22 +142,22 @@ This library wouldnt be possible without
|
|||
Ideas for the future
|
||||
====================
|
||||
* Add more devices (even more?)
|
||||
* Add Midi (no more free Endpoints)
|
||||
* Add Led/SPI support (discarded, not needed, too slow)
|
||||
* 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, maybe the 4 pin header?)
|
||||
* Add Report Out function (for Keyboard Leds etc)
|
||||
|
||||
Known Bugs
|
||||
==========
|
||||
See [Hoodloader repository](https://github.com/NicoHood/Hoodloader) for Hoodloader related Bugs/Issues.
|
||||
|
||||
Opening the examples with doubleclick doesnt work, starting from IDE does.
|
||||
|
||||
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.
|
||||
|
||||
Programming Arduino Mega with ISP doesnt work because of fuses. Burning Bootloader error is fixed with IDE 1.5.7 or higher (avrdude bug)!
|
||||
See this for more information: http://forum.arduino.cc/index.php?topic=126160.0
|
||||
|
||||
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
|
||||
|
|
@ -143,7 +165,7 @@ Known Issues
|
|||
|
||||
**Do not name your sketch HID.ino, this wont work!**
|
||||
|
||||
**Do not use HID in interrupts because it uses the Serial. Your Arduino can crash!**
|
||||
**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).
|
||||
|
|
@ -151,27 +173,29 @@ These bugs occurred while developing the bootloader and should be fixed. Just in
|
|||
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
|
||||
|
||||
HID only works with baud 115200 (on Uno/Mega) because there is no "programming finished" indicator.
|
||||
If you dont use HID you can still choose the baud of your choice.
|
||||
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 (should only work without DFU and v1.6 due to size. message me if it works!)
|
||||
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 massive Serial information.
|
||||
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.
|
||||
|
||||
Oh and by the way: I also removed some bugs from the official firmware.
|
||||
|
||||
Version History
|
||||
===============
|
||||
```
|
||||
1.8 Beta Release (xx.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
|
||||
|
||||
1.7.3 Beta Release (10.08.2014)
|
||||
* Changes in the Hoodloader:
|
||||
* Fixed HID flush bug (1.6 - 1.7.2)
|
||||
|
|
|
|||
79
System.h
Normal file
79
System.h
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
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
|
||||
|
||||
|
|
@ -10,15 +10,13 @@
|
|||
Definitions from HID_Reports.h:
|
||||
RAWHID_USAGE_PAGE 0xFFC0 // recommended: 0xFF00 to 0xFFFF
|
||||
RAWHID_USAGE 0x0C00 // recommended: 0x0100 to 0xFFFF
|
||||
RAWHID_TX_SIZE 63 // 1 byte for report ID
|
||||
RAWHID_RX_SIZE 63 // 1 byte for report ID
|
||||
RAWHID_TX_SIZE 15 // 1 byte for report ID
|
||||
RAWHID_RX_SIZE 15 // 1 byte for report ID
|
||||
*/
|
||||
|
||||
// not needed for Leonardo/Micro
|
||||
// include HID library
|
||||
#include <HID.h>
|
||||
|
||||
// for Leonardo/Micro: make sure to activate desired USB functions in HID_Reports.h
|
||||
|
||||
const int pinLed = 13;
|
||||
const int pinButton = 8;
|
||||
|
||||
|
|
@ -26,12 +24,11 @@ void setup() {
|
|||
pinMode(pinLed, OUTPUT);
|
||||
pinMode(pinButton, INPUT_PULLUP);
|
||||
|
||||
// Starts Serial at baud 115200. end just ends the Serial
|
||||
// Make sure to end your special HIDs before, this does not clear them!
|
||||
// You need this baud for the HID library but still can use other bauds
|
||||
// without HID functions.
|
||||
// not needed for Leonado/Micro, Serial will not be set
|
||||
HID.begin();
|
||||
// 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() {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@ Gamepad example
|
|||
Press a button and demonstrate Gamepad actions
|
||||
*/
|
||||
|
||||
// not needed for Leonardo/Micro
|
||||
// include HID library
|
||||
#include <HID.h>
|
||||
|
||||
// for Leonardo/Micro: make sure to activate desired USB functions in HID_Reports.h
|
||||
// create a new Gamepad instance (1-4)
|
||||
Gamepad Gamepad1(1);
|
||||
|
||||
const int pinLed = 13;
|
||||
const int pinButton = 8;
|
||||
|
|
@ -18,22 +19,13 @@ void setup() {
|
|||
pinMode(pinLed, OUTPUT);
|
||||
pinMode(pinButton, INPUT_PULLUP);
|
||||
|
||||
// Starts Serial at baud 115200. end just ends the Serial
|
||||
// Make sure to end your special HIDs before, this does not clear them!
|
||||
// You need this baud for the HID library but still can use other bauds
|
||||
// without HID functions.
|
||||
// not needed for Leonado/Micro, Serial will not be set
|
||||
HID.begin();
|
||||
// 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 clear report to avoid strange bugs.
|
||||
// its exactly the same like the end() function.
|
||||
// You can also unplug the device if anything goes wrong.
|
||||
// To prevent the 16u2 to send more reports just pull the Serial TX (pin1) low
|
||||
// or see readme for turning off HID functions.
|
||||
// If you did anything wrong (keyboard is doing weird stuff)
|
||||
// just logout (no shutdown needed).
|
||||
// so you want to start with a clean report to avoid strange bugs after reset.
|
||||
Gamepad1.begin();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 2014 NicoHood
|
||||
See the readme for credit to other people.
|
||||
|
||||
Joystick example
|
||||
Press a button and demonstrate Joystick actions
|
||||
*/
|
||||
|
||||
// not needed for Leonardo/Micro
|
||||
#include <HID.h>
|
||||
|
||||
// for Leonardo/Micro: make sure to activate desired USB functions in HID_Reports.h
|
||||
|
||||
const int pinLed = 13;
|
||||
const int pinButton = 8;
|
||||
|
||||
void setup() {
|
||||
pinMode(pinLed, OUTPUT);
|
||||
pinMode(pinButton, INPUT_PULLUP);
|
||||
|
||||
// Starts Serial at baud 115200. end just ends the Serial
|
||||
// Make sure to end your special HIDs before, this does not clear them!
|
||||
// You need this baud for the HID library but still can use other bauds
|
||||
// without HID functions.
|
||||
// not needed for Leonardo/Micro, Serial will not be set
|
||||
HID.begin();
|
||||
|
||||
// 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 clear report to avoid strange bugs.
|
||||
// its exactly the same like the end() function.
|
||||
// You can also unplug the device if anything goes wrong.
|
||||
// To prevent the 16u2 to send more reports just pull the Serial TX (pin1) low
|
||||
// or see readme for turning off HID functions.
|
||||
// If you did anything wrong (keyboard is doing weird stuff)
|
||||
// just logout (no shutdown needed).
|
||||
Joystick1.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!digitalRead(pinButton)) {
|
||||
digitalWrite(pinLed, HIGH);
|
||||
|
||||
// press button 1-2 and reset
|
||||
static uint8_t count = 0;
|
||||
if (++count == 3) {
|
||||
count = 0;
|
||||
Joystick1.releaseAll();
|
||||
}
|
||||
else
|
||||
Joystick1.press(count);
|
||||
|
||||
// move x/y Axis to a new position (10bit)
|
||||
Joystick1.xAxis(random(1023));
|
||||
Joystick1.yAxis(analogRead(A0));
|
||||
|
||||
// functions before only set the values
|
||||
// this writes the report to the host
|
||||
Joystick1.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 xAxis(uint16_t a);
|
||||
void yAxis(uint16_t a);
|
||||
|
||||
*/
|
||||
|
|
@ -3,15 +3,13 @@ Copyright (c) 2014 NicoHood
|
|||
See the readme for credit to other people.
|
||||
|
||||
Keyboard example
|
||||
Press a button to write some text to your pc. After 10 button presses it will pres ctrl+alt+del.
|
||||
Press a button to write some text to your pc.
|
||||
See official documentation for more infos
|
||||
*/
|
||||
|
||||
// not needed for Leonardo/Micro
|
||||
// include HID library
|
||||
#include <HID.h>
|
||||
|
||||
// for Leonardo/Micro: make sure to activate desired USB functions in HID_Reports.h
|
||||
|
||||
const int pinLed = 13;
|
||||
const int pinButton = 8;
|
||||
|
||||
|
|
@ -19,22 +17,13 @@ void setup() {
|
|||
pinMode(pinLed, OUTPUT);
|
||||
pinMode(pinButton, INPUT_PULLUP);
|
||||
|
||||
// Starts Serial at baud 115200. end just ends the Serial
|
||||
// Make sure to end your special HIDs before, this does not clear them!
|
||||
// You need this baud for the HID library but still can use other bauds
|
||||
// without HID functions.
|
||||
// not needed for Leonardo/Micro, Serial will not be set
|
||||
HID.begin();
|
||||
// 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 clear report to avoid strange bugs.
|
||||
// its exactly the same like the end() function.
|
||||
// You can also unplug the device if anything goes wrong.
|
||||
// To prevent the 16u2 to send more reports just pull the Serial TX (pin1) low
|
||||
// or see readme for turning off HID functions.
|
||||
// If you did anything wrong (keyboard is doing weird stuff)
|
||||
// just logout (no shutdown needed).
|
||||
// so you want to start with a clean report to avoid strange bugs after reset.
|
||||
Keyboard.begin();
|
||||
}
|
||||
|
||||
|
|
@ -47,16 +36,6 @@ void loop() {
|
|||
Keyboard.println("This message was sent with my Arduino.");
|
||||
Serial.println("Serial port is still working and not glitching out");
|
||||
|
||||
// you can press any key, see list below
|
||||
static uint8_t count = 0;
|
||||
if (++count == 10) {
|
||||
Keyboard.press(KEY_LEFT_CTRL);
|
||||
Keyboard.press(KEY_LEFT_ALT);
|
||||
Keyboard.press(KEY_DELETE);
|
||||
Keyboard.releaseAll();
|
||||
count = 0;
|
||||
}
|
||||
|
||||
// simple debounce
|
||||
delay(300);
|
||||
digitalWrite(pinLed, LOW);
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@ Media example
|
|||
Press a button to play/pause music player
|
||||
*/
|
||||
|
||||
// not needed for Leonardo/Micro
|
||||
// include HID library
|
||||
#include <HID.h>
|
||||
|
||||
// for Leonardo/Micro: make sure to activate desired USB functions in HID_Reports.h
|
||||
|
||||
const int pinLed = 13;
|
||||
const int pinButton = 8;
|
||||
|
||||
|
|
@ -18,22 +16,13 @@ void setup() {
|
|||
pinMode(pinLed, OUTPUT);
|
||||
pinMode(pinButton, INPUT_PULLUP);
|
||||
|
||||
// Starts Serial at baud 115200. end just ends the Serial
|
||||
// Make sure to end your special HIDs before, this does not clear them!
|
||||
// You need this baud for the HID library but still can use other bauds
|
||||
// without HID functions.
|
||||
// not needed for Leonardo/Micro, Serial will not be set
|
||||
HID.begin();
|
||||
// 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 clear report to avoid strange bugs.
|
||||
// its exactly the same like the end() function.
|
||||
// You can also unplug the device if anything goes wrong.
|
||||
// To prevent the 16u2 to send more reports just pull the Serial TX (pin1) low
|
||||
// or see readme for turning off HID functions.
|
||||
// If you did anything wrong (keyboard is doing weird stuff)
|
||||
// just logout (no shutdown needed).
|
||||
// so you want to start with a clean report to avoid strange bugs after reset.
|
||||
Media.begin();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@ Copyright (c) 2014 NicoHood
|
|||
Press a button to click with mouse. See official documentation for more infos
|
||||
*/
|
||||
|
||||
// not needed for Leonardo/Micro
|
||||
// include HID library
|
||||
#include <HID.h>
|
||||
|
||||
// for Leonardo/Micro: make sure to activate desired USB functions in HID_Reports.h
|
||||
|
||||
const int pinLed = 13;
|
||||
const int pinButton = 8;
|
||||
|
||||
|
|
@ -18,22 +16,13 @@ void setup() {
|
|||
pinMode(pinLed, OUTPUT);
|
||||
pinMode(pinButton, INPUT_PULLUP);
|
||||
|
||||
// Starts Serial at baud 115200. end just ends the Serial
|
||||
// Make sure to end your special HIDs before, this does not clear them!
|
||||
// You need this baud for the HID library but still can use other bauds
|
||||
// without HID functions.
|
||||
// not needed for Leonardo/Micro, Serial will not be set
|
||||
HID.begin();
|
||||
// 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 clear report to avoid strange bugs.
|
||||
// its exactly the same like the end() function.
|
||||
// You can also unplug the device if anything goes wrong.
|
||||
// To prevent the 16u2 to send more reports just pull the Serial TX (pin1) low
|
||||
// or see readme for turning off HID functions.
|
||||
// If you did anything wrong (keyboard is doing weird stuff)
|
||||
// just logout (no shutdown needed).
|
||||
// so you want to start with a clean report to avoid strange bugs after reset.
|
||||
Mouse.begin();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,11 +6,9 @@ System example
|
|||
Press a button to put pc into standby mode
|
||||
*/
|
||||
|
||||
// not needed for Leonardo/Micro
|
||||
// include HID library
|
||||
#include <HID.h>
|
||||
|
||||
// for Leonardo/Micro: make sure to activate desired USB functions in HID_Reports.h
|
||||
|
||||
const int pinLed = 13;
|
||||
const int pinButton = 8;
|
||||
|
||||
|
|
@ -18,22 +16,13 @@ void setup() {
|
|||
pinMode(pinLed, OUTPUT);
|
||||
pinMode(pinButton, INPUT_PULLUP);
|
||||
|
||||
// Starts Serial at baud 115200. end just ends the Serial
|
||||
// Make sure to end your special HIDs before, this does not clear them!
|
||||
// You need this baud for the HID library but still can use other bauds
|
||||
// without HID functions.
|
||||
// not needed for Leonardo/Micro, Serial will not be set
|
||||
HID.begin();
|
||||
// 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 clear report to avoid strange bugs.
|
||||
// its exactly the same like the end() function.
|
||||
// You can also unplug the device if anything goes wrong.
|
||||
// To prevent the 16u2 to send more reports just pull the Serial TX (pin1) low
|
||||
// or see readme for turning off HID functions.
|
||||
// If you did anything wrong (keyboard is doing weird stuff)
|
||||
// just logout (no shutdown needed).
|
||||
// so you want to start with a clean report to avoid strange bugs after reset.
|
||||
System.begin();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ Media KEYWORD3
|
|||
System KEYWORD3
|
||||
Gamepad1 KEYWORD3
|
||||
Gamepad2 KEYWORD3
|
||||
Gamepad3 KEYWORD3
|
||||
Gamepad4 KEYWORD3
|
||||
Joystick1 KEYWORD3
|
||||
Joystick2 KEYWORD3
|
||||
|
||||
|
|
@ -52,6 +54,9 @@ Joystick2 KEYWORD3
|
|||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
#General
|
||||
SERIAL_HID_BAUD LITERAL1
|
||||
|
||||
#Mouse
|
||||
|
||||
MOUSE_LEFT LITERAL1
|
||||
|
|
|
|||
Loading…
Reference in a new issue