Update 1.3

This commit is contained in:
NicoHood 2014-07-01 22:13:53 +02:00
parent 69a87890e3
commit 0bddc26e19
16 changed files with 1308 additions and 894 deletions

View file

@ -369,9 +369,9 @@ const u8 _hidReportDescriptor[] = {
extern const HIDDescriptor _hidInterface PROGMEM;
const HIDDescriptor _hidInterface =
{
D_INTERFACE(HID_INTERFACE,1,3,0,0),
D_INTERFACE(HID_INTERFACE, 1, 3, 0, 0),
D_HIDREPORT(sizeof(_hidReportDescriptor)),
D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01)
D_ENDPOINT(USB_ENDPOINT_IN(HID_ENDPOINT_INT), USB_ENDPOINT_TYPE_INTERRUPT, 0x40, 0x01)
};
//================================================================================
@ -386,18 +386,18 @@ u8 _hid_idle = 1;
int WEAK HID_GetInterface(u8* interfaceNum)
{
interfaceNum[0] += 1; // uses 1
return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface));
return USB_SendControl(TRANSFER_PGM, &_hidInterface, sizeof(_hidInterface));
}
int WEAK HID_GetDescriptor(int /* i */)
{
return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor));
return USB_SendControl(TRANSFER_PGM, _hidReportDescriptor, sizeof(_hidReportDescriptor));
}
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);
USB_Send(HID_TX | TRANSFER_RELEASE, data, len);
}
bool WEAK HID_Setup(Setup& setup)
@ -450,25 +450,25 @@ HID_::HID_(void){
}
void HID_::begin(void){
Serial.begin(115200);
HID_SERIAL.begin(115200);
}
void HID_::end(void){
Serial.end();
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);
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];
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);
NHPwriteChecksum(2 + i / 2, (data1 << 8) | data0);
}
}
#endif /* if defined(USBCON) */
@ -476,49 +476,54 @@ void HID_::sendReport(uint8_t ReportID, const void* HIDReport, uint8_t length){
// 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;
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;
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){
while (blocks > 2){
uint8_t nextvalue = (data >> (7 * (blocks - 3)));
if (nextvalue > NHP_MASK_DATA_3BIT){
// special case for the MSB
if(blocks==7) {
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
// 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){
uint8_t datablocks = blocks - 2;
while (datablocks > 0){
writebuffer[datablocks] = data & NHP_MASK_DATA_7BIT;
data>>=7;
data >>= 7;
datablocks--;
}
// write lead + length mask
writebuffer[0] |= NHP_MASK_LEAD | (blocks <<3);
writebuffer[0] |= NHP_MASK_LEAD | (blocks << 3);
// write end mask
writebuffer[blocks-1] = NHP_MASK_END | ((address-1) & NHP_MASK_ADDRESS);
writebuffer[blocks - 1] = NHP_MASK_END | ((address - 1) & NHP_MASK_ADDRESS);
// write the buffer
Serial.write(writebuffer, blocks);
HID_SERIAL.write(writebuffer, blocks);
}
//================================================================================
@ -542,22 +547,22 @@ void Mouse_::end(void){
void Mouse_::click(uint8_t b){
_report.buttons = b;
move(0,0,0);
move(0, 0, 0);
_report.buttons = 0;
move(0,0,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;
_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);
move(0, 0, 0);
}
}
@ -574,7 +579,7 @@ void Mouse_::releaseAll(void){
}
bool Mouse_::isPressed(uint8_t b){
if ((b & _report.buttons) > 0)
if ((b & _report.buttons) > 0)
return true;
return false;
}
@ -599,7 +604,7 @@ void Keyboard_::end(void){
}
extern
const uint8_t _asciimap[128] PROGMEM;
const uint8_t _asciimap[128] PROGMEM;
#define SHIFT 0x80
const uint8_t _asciimap[128] =
@ -638,17 +643,17 @@ const uint8_t _asciimap[128] =
0x00, // US
0x2c, // ' '
0x1e|SHIFT, // !
0x34|SHIFT, // "
0x20|SHIFT, // #
0x21|SHIFT, // $
0x22|SHIFT, // %
0x24|SHIFT, // &
0x1e | SHIFT, // !
0x34 | SHIFT, // "
0x20 | SHIFT, // #
0x21 | SHIFT, // $
0x22 | SHIFT, // %
0x24 | SHIFT, // &
0x34, // '
0x26|SHIFT, // (
0x27|SHIFT, // )
0x25|SHIFT, // *
0x2e|SHIFT, // +
0x26 | SHIFT, // (
0x27 | SHIFT, // )
0x25 | SHIFT, // *
0x2e | SHIFT, // +
0x36, // ,
0x2d, // -
0x37, // .
@ -663,44 +668,44 @@ const uint8_t _asciimap[128] =
0x24, // 7
0x25, // 8
0x26, // 9
0x33|SHIFT, // :
0x33 | SHIFT, // :
0x33, // ;
0x36|SHIFT, // <
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
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, // _
0x23 | SHIFT, // ^
0x2d | SHIFT, // _
0x35, // `
0x04, // a
0x05, // b
@ -728,10 +733,10 @@ const uint8_t _asciimap[128] =
0x1b, // x
0x1c, // y
0x1d, // z
0x2f|SHIFT, //
0x31|SHIFT, // |
0x30|SHIFT, // }
0x35|SHIFT, // ~
0x2f | SHIFT, //
0x31 | SHIFT, // |
0x30 | SHIFT, // }
0x35 | SHIFT, // ~
0 // DEL
};
@ -739,7 +744,7 @@ const uint8_t _asciimap[128] =
//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
@ -750,15 +755,17 @@ size_t Keyboard_::write(uint8_t c)
// 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)
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));
}
else if (k >= 128) { // it's a modifier key
_report.modifiers |= (1 << (k - 128));
k = 0;
} else { // it's a printing key
}
else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
setWriteError();
@ -772,20 +779,20 @@ size_t Keyboard_::press(uint8_t k)
// 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 &&
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;
}
for (i = 0; i < 6; i++) {
if (_report.keys[i] == 0x00) {
_report.keys[i] = k;
break;
}
if (i == 6) {
setWriteError();
return 0;
}
}
if (i == 6) {
setWriteError();
return 0;
}
}
HID.sendReport(HID_REPORTID_KeyboardReport, &_report, sizeof(_report));
return 1;
@ -794,15 +801,17 @@ size_t Keyboard_::press(uint8_t k)
// 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)
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));
}
else if (k >= 128) { // it's a modifier key
_report.modifiers &= ~(1 << (k - 128));
k = 0;
} else { // it's a printing key
}
else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
return 0;
@ -815,7 +824,7 @@ size_t Keyboard_::release(uint8_t k)
// 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++) {
for (i = 0; i < 6; i++) {
if (0 != k && _report.keys[i] == k) {
_report.keys[i] = 0x00;
}
@ -855,8 +864,8 @@ void Media_::write(uint16_t 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) {
for (int i = 0; i < sizeof(HID_MediaReport_Data_t) / 2; i++) {
if (_report.whole16[i] == 0x00) {
_report.whole16[i] = m;
break;
}
@ -866,7 +875,7 @@ void Media_::press(uint16_t m){
void Media_::release(uint16_t m){
// search and release the keypress
for (int i=0; i<sizeof(HID_MediaReport_Data_t)/2; i++) {
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
@ -941,15 +950,15 @@ void Gamepad_::write(void){
}
void Gamepad_::press(uint8_t b){
_report.buttons|=(uint32_t)1<<(b-1);
_report.buttons |= (uint32_t)1 << (b - 1);
}
void Gamepad_::release(uint8_t b){
_report.buttons&=~((uint32_t)1<<(b-1));
_report.buttons &= ~((uint32_t)1 << (b - 1));
}
void Gamepad_::releaseAll(void){
_report.buttons=0;
_report.buttons = 0;
}
//================================================================================
@ -978,16 +987,16 @@ void Joystick_::write(void){
}
void Joystick_::press(uint8_t b){
if(b==1) _report.button1=1;
else if(b==2) _report.button2=1;
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;
if (b == 1) _report.button1 = 0;
else if (b == 2) _report.button2 = 0;
}
void Joystick_::releaseAll(void){
_report.button1=0;
_report.button2=0;
_report.button1 = 0;
_report.button2 = 0;
}

View file

@ -77,6 +77,9 @@ THE SOFTWARE.
// Reserved Usages
#define NHP_USAGE_ARDUINOHID 0x01
// Serial to write Protocol data to. Default: Serial
#define HID_SERIAL Serial
class HID_{
public:
HID_(void);

View file

@ -369,9 +369,9 @@ const u8 _hidReportDescriptor[] = {
extern const HIDDescriptor _hidInterface PROGMEM;
const HIDDescriptor _hidInterface =
{
D_INTERFACE(HID_INTERFACE,1,3,0,0),
D_INTERFACE(HID_INTERFACE, 1, 3, 0, 0),
D_HIDREPORT(sizeof(_hidReportDescriptor)),
D_ENDPOINT(USB_ENDPOINT_IN (HID_ENDPOINT_INT),USB_ENDPOINT_TYPE_INTERRUPT,0x40,0x01)
D_ENDPOINT(USB_ENDPOINT_IN(HID_ENDPOINT_INT), USB_ENDPOINT_TYPE_INTERRUPT, 0x40, 0x01)
};
//================================================================================
@ -386,18 +386,18 @@ u8 _hid_idle = 1;
int WEAK HID_GetInterface(u8* interfaceNum)
{
interfaceNum[0] += 1; // uses 1
return USB_SendControl(TRANSFER_PGM,&_hidInterface,sizeof(_hidInterface));
return USB_SendControl(TRANSFER_PGM, &_hidInterface, sizeof(_hidInterface));
}
int WEAK HID_GetDescriptor(int /* i */)
{
return USB_SendControl(TRANSFER_PGM,_hidReportDescriptor,sizeof(_hidReportDescriptor));
return USB_SendControl(TRANSFER_PGM, _hidReportDescriptor, sizeof(_hidReportDescriptor));
}
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);
USB_Send(HID_TX | TRANSFER_RELEASE, data, len);
}
bool WEAK HID_Setup(Setup& setup)
@ -450,25 +450,25 @@ HID_::HID_(void){
}
void HID_::begin(void){
Serial.begin(115200);
HID_SERIAL.begin(115200);
}
void HID_::end(void){
Serial.end();
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);
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];
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);
NHPwriteChecksum(2 + i / 2, (data1 << 8) | data0);
}
}
#endif /* if defined(USBCON) */
@ -476,49 +476,54 @@ void HID_::sendReport(uint8_t ReportID, const void* HIDReport, uint8_t length){
// 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;
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;
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){
while (blocks > 2){
uint8_t nextvalue = (data >> (7 * (blocks - 3)));
if (nextvalue > NHP_MASK_DATA_3BIT){
// special case for the MSB
if(blocks==7) {
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
// 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){
uint8_t datablocks = blocks - 2;
while (datablocks > 0){
writebuffer[datablocks] = data & NHP_MASK_DATA_7BIT;
data>>=7;
data >>= 7;
datablocks--;
}
// write lead + length mask
writebuffer[0] |= NHP_MASK_LEAD | (blocks <<3);
writebuffer[0] |= NHP_MASK_LEAD | (blocks << 3);
// write end mask
writebuffer[blocks-1] = NHP_MASK_END | ((address-1) & NHP_MASK_ADDRESS);
writebuffer[blocks - 1] = NHP_MASK_END | ((address - 1) & NHP_MASK_ADDRESS);
// write the buffer
Serial.write(writebuffer, blocks);
HID_SERIAL.write(writebuffer, blocks);
}
//================================================================================
@ -542,22 +547,22 @@ void Mouse_::end(void){
void Mouse_::click(uint8_t b){
_report.buttons = b;
move(0,0,0);
move(0, 0, 0);
_report.buttons = 0;
move(0,0,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;
_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);
move(0, 0, 0);
}
}
@ -574,7 +579,7 @@ void Mouse_::releaseAll(void){
}
bool Mouse_::isPressed(uint8_t b){
if ((b & _report.buttons) > 0)
if ((b & _report.buttons) > 0)
return true;
return false;
}
@ -599,7 +604,7 @@ void Keyboard_::end(void){
}
extern
const uint8_t _asciimap[128] PROGMEM;
const uint8_t _asciimap[128] PROGMEM;
#define SHIFT 0x80
const uint8_t _asciimap[128] =
@ -638,17 +643,17 @@ const uint8_t _asciimap[128] =
0x00, // US
0x2c, // ' '
0x1e|SHIFT, // !
0x34|SHIFT, // "
0x20|SHIFT, // #
0x21|SHIFT, // $
0x22|SHIFT, // %
0x24|SHIFT, // &
0x1e | SHIFT, // !
0x34 | SHIFT, // "
0x20 | SHIFT, // #
0x21 | SHIFT, // $
0x22 | SHIFT, // %
0x24 | SHIFT, // &
0x34, // '
0x26|SHIFT, // (
0x27|SHIFT, // )
0x25|SHIFT, // *
0x2e|SHIFT, // +
0x26 | SHIFT, // (
0x27 | SHIFT, // )
0x25 | SHIFT, // *
0x2e | SHIFT, // +
0x36, // ,
0x2d, // -
0x37, // .
@ -663,44 +668,44 @@ const uint8_t _asciimap[128] =
0x24, // 7
0x25, // 8
0x26, // 9
0x33|SHIFT, // :
0x33 | SHIFT, // :
0x33, // ;
0x36|SHIFT, // <
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
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, // _
0x23 | SHIFT, // ^
0x2d | SHIFT, // _
0x35, // `
0x04, // a
0x05, // b
@ -728,10 +733,10 @@ const uint8_t _asciimap[128] =
0x1b, // x
0x1c, // y
0x1d, // z
0x2f|SHIFT, //
0x31|SHIFT, // |
0x30|SHIFT, // }
0x35|SHIFT, // ~
0x2f | SHIFT, //
0x31 | SHIFT, // |
0x30 | SHIFT, // }
0x35 | SHIFT, // ~
0 // DEL
};
@ -739,7 +744,7 @@ const uint8_t _asciimap[128] =
//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
@ -750,15 +755,17 @@ size_t Keyboard_::write(uint8_t c)
// 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)
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));
}
else if (k >= 128) { // it's a modifier key
_report.modifiers |= (1 << (k - 128));
k = 0;
} else { // it's a printing key
}
else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
setWriteError();
@ -772,20 +779,20 @@ size_t Keyboard_::press(uint8_t k)
// 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 &&
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;
}
for (i = 0; i < 6; i++) {
if (_report.keys[i] == 0x00) {
_report.keys[i] = k;
break;
}
if (i == 6) {
setWriteError();
return 0;
}
}
if (i == 6) {
setWriteError();
return 0;
}
}
HID.sendReport(HID_REPORTID_KeyboardReport, &_report, sizeof(_report));
return 1;
@ -794,15 +801,17 @@ size_t Keyboard_::press(uint8_t k)
// 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)
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));
}
else if (k >= 128) { // it's a modifier key
_report.modifiers &= ~(1 << (k - 128));
k = 0;
} else { // it's a printing key
}
else { // it's a printing key
k = pgm_read_byte(_asciimap + k);
if (!k) {
return 0;
@ -815,7 +824,7 @@ size_t Keyboard_::release(uint8_t k)
// 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++) {
for (i = 0; i < 6; i++) {
if (0 != k && _report.keys[i] == k) {
_report.keys[i] = 0x00;
}
@ -855,8 +864,8 @@ void Media_::write(uint16_t 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) {
for (int i = 0; i < sizeof(HID_MediaReport_Data_t) / 2; i++) {
if (_report.whole16[i] == 0x00) {
_report.whole16[i] = m;
break;
}
@ -866,7 +875,7 @@ void Media_::press(uint16_t m){
void Media_::release(uint16_t m){
// search and release the keypress
for (int i=0; i<sizeof(HID_MediaReport_Data_t)/2; i++) {
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
@ -941,15 +950,15 @@ void Gamepad_::write(void){
}
void Gamepad_::press(uint8_t b){
_report.buttons|=(uint32_t)1<<(b-1);
_report.buttons |= (uint32_t)1 << (b - 1);
}
void Gamepad_::release(uint8_t b){
_report.buttons&=~((uint32_t)1<<(b-1));
_report.buttons &= ~((uint32_t)1 << (b - 1));
}
void Gamepad_::releaseAll(void){
_report.buttons=0;
_report.buttons = 0;
}
//================================================================================
@ -978,16 +987,16 @@ void Joystick_::write(void){
}
void Joystick_::press(uint8_t b){
if(b==1) _report.button1=1;
else if(b==2) _report.button2=1;
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;
if (b == 1) _report.button1 = 0;
else if (b == 2) _report.button2 = 0;
}
void Joystick_::releaseAll(void){
_report.button1=0;
_report.button2=0;
_report.button1 = 0;
_report.button2 = 0;
}

View file

@ -77,6 +77,9 @@ THE SOFTWARE.
// Reserved Usages
#define NHP_USAGE_ARDUINOHID 0x01
// Serial to write Protocol data to. Default: Serial
#define HID_SERIAL Serial
class HID_{
public:
HID_(void);

View file

@ -1,9 +1,9 @@
:1000000073C100008DC100008BC1000089C10000D8
:1000100087C1000085C1000083C1000081C10000CC
:100020007FC100007DC100007BC100000C948408EA
:100030000C942D0975C1000073C1000071C100004E
:100020007FC100007DC100007BC100000C94AA08C4
:100030000C94530975C1000073C1000071C1000028
:100040006FC100006DC100006BC1000069C10000FC
:1000500067C1000065C1000063C10000C3C30000A8
:1000500067C1000065C1000063C10000ECC300007F
:100060005FC100005DC100005BC1000059C100001C
:1000700057C1000030034100720064007500690040
:100080006E006F00200048006F006F0064006C007D
@ -16,7 +16,7 @@
:1000F00000020A0000000705040240000107058312
:10010000024000010904020001030000000921115E
:1001100001000122B801070581032000011201102E
:1001200001EF020108EB03684E12000102DC010539
:1001200001EF020108EB03684E13000102DC010538
:10013000010902A1010901A100850105091901298F
:10014000051500250195057501810295017503814D
:100150000305010930093109381581257F75089596
@ -45,430 +45,435 @@
:1002C0001901290215002501750195028102050118
:1002D00009300931150026FF03750A950281027560
:1002E0000295018103C0C00011241FBECFEFD2E0F0
:1002F000DEBFCDBF11E0A0E0B1E0EAE5FDE102C064
:1002F000DEBFCDBF11E0A0E0B1E0E6EAFDE102C063
:1003000005900D92AE32B107D9F712E0AEE2B1E03E
:1003100001C01D92AF34B107E1F70DD10C94AB0EC3
:1003100001C01D92AD34B107E1F736D10C94D10E76
:100320006FCECF93DF9384B7877F84BF28E10FB66A
:10033000F89420936000109260000FBE80E190E07E
:100340009093CD008093CC00CAECD0E096E09883E7
:10035000A8ECB0E082E08C93E9ECF0E02083539AC3
:100360005A9A5B9A10821C92188298838C9388E91F
:1003700080835B988AB180638AB98BB180638BB9C3
:10038000B4D684E085BD5F9A579A22982A9ADF9165
:10039000CF9108950F931F93CF93DF93C1E3D2E0E2
:10038000DAD684E085BD5F9A579A22982A9ADF913F
:10039000CF9108950F931F93CF93DF93CFE2D2E0D5
:1003A000082F10E00AC08091200180FF05C06881FD
:1003B00080E191E00E94130B2196CE01815392407F
:1003B00080E191E00E94390B2196CE018F5292404C
:1003C0008017910784F3DF91CF911F910F910895CA
:1003D000CF93DF9380910502882319F010920302D6
:1003E0001DC06091030270E0716081E01BD4CAE21D
:1003F000D2E00AC08091200180FF05C0688180E1C1
:1004000091E00E94130B21969E012A523240809166
:10041000290290E0281739076CF3E0CFDF91CF91E4
:1004200008951F93CF93DF938AD3882309F47FC065
:100430001A9B7DC0A6D2813009F03CC0B1D280FFAA
:1004400039C0809103028111C3DFA7D280930302D8
:100450001092050291E1E7E0F2E0DF01292F1D9201
:100460002A95E9F78530C1F038F4823071F0843094
:1004700061F08130D1F405C0883090F08A30A8F462
:1004800012C094E09093040204C088E080930402B8
:1004900081E0809306020AC081E080930402F9CFD4
:1004A00090930402F5CF83E0F1CF92DFDF91CF91FB
:1004B0001F9163C2809103028823C9F162D2109117
:1004C0000502C12FD0E090E09E012E5F3F4F359591
:1004D00027952F5F3F4F8217930729F55ED2C95F9B
:1004E000DD4F8883C12FCF5FC09305028091040246
:1004F0008C1749F055D2EC2FF0E0E95FFD4F808377
:100500001E5F1093050290910402809105029813DA
:10051000CDCF04C080E091E00E94A80D809103023D
:100520008111F8CFC3CFDF91CF911F9151CFDF91D0
:10053000CF911F910895F5DE2FB7F89481E391E0F4
:1005400090939601809395019093980180939701E1
:100550002FBF2FB7F8948AE991E09093FF01809321
:10056000FE0190930102809300022FBF78941092B5
:10057000050210920302C1E3D1E08C0153E0E52EA5
:100580009FB7F894809199019FBF843619F180E15B
:1005900091E00E947B0B97FD1DC0E0919501F091C9
:1005A0009601808380919501909196010196909398
:1005B0009601809395018559914021F4D09396013D
:1005C000C09395019FB7F894809199018F5F8093B4
:1005D00099019FBF8FB7F894F09002028FBFA8993E
:1005E00004C084E48F1508F056C0A89A80910202D6
:1005F000882341F15D98E0922E0124C0D4D1877FF9
:1006000039F0809103028111E3DE80913002C2DE75
:10061000E0910002F09101028191F0930102E093D8
:100620000002EE5FF14021F41093010200930002FA
:100630002FB7F894909102029150909302022FBF2D
:10064000F0DEFA94F110DACF80912E018823B9F010
:1006500080912E01815080932E01811110C08091D4
:1006600003028111B5DE9FD183FD07C0F0903002F7
:100670009AD187FDF3948F2D8DDE7FD15D9A809185
:100680002F01882341F080912F01815080932F0109
:10069000811101C05C9A9FB7F894809199019FBF26
:1006A000882309F1E0919701F09198019191F093DD
:1006B0009801E0939701E559F14021F4D093980116
:1006C000C09397012FB7F89480919901815080933E
:1006D00099012FBF8091C80085FFFCCF9093CE0079
:1006E0005C98E0922F0180E191E0EFD75BD748CF93
:1006F00008950895CF9380E091E00E94930DC82F54
:1007000080E191E06BD79091E20094609093E200D9
:10071000882321F0CC2311F080E001C080E39BB15D
:100720008095906389238BB9CF9108951F93CF93C0
:10073000DF93EC01E98DE150E23028F4F0E0E45D74
:10074000FE4F108101C010E0888D823009F41860DE
:100750008A8D873031F0883031F0863029F412608C
:1007600003C0146001C016605B9A1092C900109219
:10077000C8001092CA002C893D894E895F892115D5
:1007800081EE38074105510579F0CA01B901969506
:1007900087957795679560587B47814E9F4F0E945C
:1007A0006C0E2150310902C020E130E03093CD00C1
:1007B0002093CC001093CA008C899D89AE89BF8993
:1007C0008115914EA105B10511F480E001C082E0D0
:1007D0008093C80088E98093C9005B98DF91CF912E
:1007E0001F9108951F920F920FB60F9211242F930D
:1007F0008F939F93EF93FF938091CE009091460249
:100800009430F1F4E091FE01F091FF018083E091DA
:10081000FE01F091FF01CF0101969093FF018093BB
:10082000FE018E5F914021F48AE991E092838183F9
:100830009FB7F894809102028F5F809302029FBF5E
:10084000FF91EF919F918F912F910F900FBE0F907D
:100850001F901895FC01208920FF02C05F98089521
:100860005F9A8BB180638BB9089580E191E071D775
:1008700080E091E00C945C0C80910E0190910F014E
:10088000009729F0019790930F0180930E0108952E
:10089000EF92FF920F931F93CF93DF937B01C901D8
:1008A000E80110910402E7E0F2E0412F50E0BF01BF
:1008B0000E949B0EE3E0F2E08081D7018C931883C5
:1008C0001982108280910602DF91CF911F910F91C2
:1008D000FF90EF9008950895292F33272330310595
:1008E000B1F04CF42130310509F439C02230310522
:1008F00009F03AC007C02132310539F12232310501
:1009000049F132C0EFE5F0E08EEB90E031C099277D
:100910008130910561F08230910581F0892B21F5BC
:10092000EAEBF0E0E491F0E08AEB90E021C0E6EA47
:10093000F0E0E491F0E086EA90E01AC0E4E7F0E04D
:10094000E491F0E084E790E013C0E9E0F0E08DE0AE
:1009500091E00EC0E8EBF1E08FE291E009C0E2E146
:10096000F0E08DE191E004C0E0E0F0E080E090E0B4
:10097000DA018D939C93CF01089588E080932B0139
:1009800008958091380208956091390270913A0279
:1009900080913B0290913C02089580913902089524
:1009A00080913A02089580912B010895982F8091AB
:1009B0002B018823E9F083FF0AC010923D021092B8
:1009C0003E0210923F02109240021092410287FFB5
:1009D0000DC040913002E42FF0E0EF5CFD4F8081CC
:1009E0008093310281E08093300202C01092300285
:1009F00010923702109238021092390210923A0285
:100A000010923B0210923C0210922B012091300276
:100A1000E22FF0E0EF5CFD4F9083822F8F5F809399
:100A20003002392F307C80913D02303809F440C0CB
:100A3000303C09F05EC0882329F080E980932B01C7
:100A400020933002292F287326952695269522304B
:100A500018F02730E1F40AC09F709F5F909337022F
:100A600010923D0280912B0185603DC0492F4F704F
:100A700050E060E070E040933E0250933F0260938C
:100A800040027093410285E080933D0256C0892F59
:100A9000877090E0A0E0B0E080933E0290933F0228
:100AA000A0934002B0934102215020933D0245C0E3
:100AB000282F215020933D028130C9F49F739F5FFE
:100AC0009093380280913E0290913F02A0914002A3
:100AD000B09141028093390290933A02A0933B0275
:100AE000B0933C0283E080932B0181E0089580E580
:100AF00007C0282F215020933D02823030F480E33C
:100B000080932B0110923D0218C040913E025091FB
:100B10003F02609140027091410287E0440F551FEF
:100B2000661F771F8A95D1F7492B40933E02509359
:100B30003F02609340027093410280E008950F935A
:100B40001F9334DF8823A9F01CDF882391F01CDF7A
:100B50008C0122273327DC01CB01AA27BB270827DA
:100B600019272A273B2781E00F3F1F4F2105310519
:100B700009F080E01F910F9108950F931F93A091AA
:100B80002A02ECE1F0E097E08A019B010E2E04C0FE
:100B900036952795179507950A94D2F7083040F0B7
:100BA000A0932A02973059F400932A0296E007C0D6
:100BB00091503797A02F923039F700932A02A92F2E
:100BC000A25013C0EA2FF0E0E65DFD4F8A019B01C1
:100BD0000F771127222733270083E7E07695679563
:100BE00057954795EA95D1F7A150A111EBCF492F21
:100BF00050E09A0163E0220F331F6A95E1F7206C01
:100C00003F6F30912A02322B30932A02FA01E75DBE
:100C1000FD4F81508F7380688083909329021F91CC
:100C20000F9108950F931F938B01AB014095509541
:100C300060E070E0BA015527442720E030E0402B07
:100C4000512B622B732B1F910F9197CFBF92CF9295
:100C5000DF92EF92FF920F931F93CF93DF937C016C
:100C60008B01EA01D7D1B82E811132C0209731F023
:100C700028813981021B130BE20EF31EC12CD12CEB
:100C800022C08091E80085FD14C08091E8008E7735
:100C90008093E800209749F0888199818C0D9D1DF3
:100CA0009983888325E0B22E13C0B4D1882359F0EC
:100CB0000EC0F70181917F018093F100015011096D
:100CC000FFEFCF1ADF0A01151105D9F601C0B82EC2
:100CD0008B2DDF91CF911F910F91FF90EF90DF90BF
:100CE000CF90BF90089520914D0230914E0226176B
:100CF000370748F06115710539F42091E8002E7727
:100D00002093E80001C0B9019C0180E034C09091BB
:100D10004602992309F443C0953009F442C09091EA
:100D2000E80093FD3AC09091E80092FD30C09091A8
:100D3000E80090FF20C08091F20090E0F901821B52
:100D4000930B05C021912093F100615071099F011F
:100D5000280F391F6115710519F02830310590F3FE
:100D600081E02830310509F080E09091E8009E771D
:100D70009093E8009F016115710549F68111C7CF75
:100D800006C080914602882351F0853051F0809151
:100D9000E80082FFF6CF80E0089581E0089582E0C8
:100DA000089583E008956115710529F42091E80004
:100DB0002B772093E8009C0121C080914602882374
:100DC00081F1853041F18091E80083FD26C080915A
:100DD000E80082FFF2CFF90107C08091F100819312
:100DE0009F016150710929F09F018091F2008111EA
:100DF000F4CF8091E8008B778093E800611571054E
:100E0000E1F68091E80080FD0AC0809146028823C7
:100E100041F08530B1F783E0089581E0089580E0E6
:100E2000089582E0089520914D0230914E022617D8
:100E3000370748F06115710539F42091E8002E77E5
:100E40002093E80001C0B9019C0180E035C0909179
:100E50004602992309F444C0953009F443C09091A7
:100E6000E80093FD3BC09091E80092FD31C0909165
:100E7000E80090FF21C08091F20090E0F901821B10
:100E8000930B06C024912093F100319661507109B3
:100E90009C012E0F3F1F6115710519F02830310597
:100EA00088F381E02830310509F080E09091E80076
:100EB0009E779093E8009F016115710541F68111BD
:100EC000C6CF06C080914602882351F0853051F08C
:100ED0008091E80082FFF6CF80E0089581E00895D8
:100EE00082E0089583E00895982F2CC09093E90044
:100EF000981739F07091EC002091ED005091F000BE
:100F000003C0242F762F50E021FD02C09F5F1AC03E
:100F10003091EB003E7F3093EB003091ED003D7F50
:100F20003093ED003091EB0031603093EB00709323
:100F3000EC002093ED005093F0002091EE0027FD8F
:100F4000E5CF07C0953090F28F708093E90081E083
:100F5000089580E008950F931F93CF93DF93062F9A
:100F6000EC0110E02EC09881911103C01F5F2596FF
:100F700028C02C81E981FA816B81892F8F7085309F
:100F800010F080E021C0223010F056E001C052E0A5
:100F900028E030E040E003C04F5F220F331F2E17E0
:100FA0003F07D0F34295407F452B991F9927991F02
:100FB0006295660F660F607C692B96DF8111D6CF34
:100FC000E0CF1013D0CF81E0DF91CF911F910F912F
:100FD00008958091470287FD05C08091E80080FF59
:100FE0000EC012C08091E80082FD05C080914602CB
:100FF0008111F8CF08958091E8008B7708C0809127
:1010000046028111EACF08958091E8008E7780939F
:10101000E80008958091E4009091E50045E6209174
:10102000EC0020FD1FC023C020914602222391F036
:10103000253091F02091EB0025FD10C02091E400B7
:101040003091E5002817390751F34150C90139F7AC
:1010500084E0089582E0089583E0089581E0089592
:1010600080E008952091E80020FFDECFF9CF2091A5
:10107000E80022FFD9CFF4CF41D043D08091D800EF
:101080008F778093D8008091D80080688093D800B3
:101090008091D8008F7D8093D80084E089BD86E060
:1010A00089BD09B400FEFDCF1092460210924202A3
:1010B000109244021092430242E060E080E014DFAC
:1010C0008091E1008E7F8093E1008091E200816059
:1010D0008093E2008091E20088608093E20080913A
:1010E000E0008E7F8093E0000895E3E6F0E08081E9
:1010F0008E7F808381E080934502BECF1092E20014
:1011000008951092E10008951F920F920FB60F926A
:1011100011242F933F934F935F936F937F938F93FC
:101120009F93AF93BF93EF93FF938091E10082FF72
:101130000AC08091E20082FF06C08091E1008B7FAF
:101140008093E10099DB8091E10080FF17C08091DE
:10115000E20080FF13C08091E2008E7F8093E20066
:101160008091E20080618093E2008091D8008062EB
:101170008093D80019BC10924602BBDA8091E1003E
:1011800084FF2FC08091E20084FF2BC084E089BDE2
:1011900086E089BD09B400FEFDCF8091D8008F7D27
:1011A0008093D8008091E1008F7E8093E100809150
:1011B000E2008F7E8093E2008091E2008160809364
:1011C000E20080914202882311F084E007C0809100
:1011D000E30087FF02C083E001C081E08093460204
:1011E00087DA8091E10083FF27C08091E20083FFCE
:1011F00023C08091E100877F8093E10082E08093AB
:101200004602109242028091E1008E7F8093E100BD
:101210008091E2008E7F8093E2008091E200806105
:101220008093E20042E060E080E05EDE8091F000CA
:1012300088608093F000B5D1FF91EF91BF91AF919D
:101240009F918F917F916F915F914F913F912F91DE
:101250000F900FBE0F901F9018951F920F920FB610
:101260000F9211242F933F934F935F936F937F932C
:101270008F939F93AF93BF93CF93EF93FF938091FF
:10128000E9008F709091EC0090FF02C090E801C0DF
:1012900090E0C92FC82B1092E9008091F000877F61
:1012A0008093F00078941CD01092E9008091F000B7
:1012B00088608093F000CF70C093E900FF91EF91B8
:1012C000CF91BF91AF919F918F917F916F915F91DE
:1012D0004F913F912F910F900FBE0F901F90189537
:1012E0001F93CF93DF93CDB7DEB7AC970FB6F894CB
:1012F000DEBF0FBECDBFE7E4F2E08091F100819345
:1013000022E0EF34F207C9F7B0DA8091E80083FFFA
:1013100030C18091470290914802953009F487C00E
:1013200038F49130B1F170F0933009F022C131C03E
:10133000983009F4F3C0993009F4FFC0963009F0F1
:1013400018C19BC0803821F0823809F012C108C052
:101350008091430290914402992389F082600FC0EA
:1013600080914B0290914C028F7099278093E900F5
:101370008091EB0085FB882780F91092E90090911D
:10138000E800977F9093E8008093F1001092F100BD
:10139000D0C0882319F0823009F0EBC08F7121F0A2
:1013A000823009F0E6C00BC080914902813009F01B
:1013B000E0C0933009F080E0809344022FC0809118
:1013C000490281112BC080914B0290914C028F7089
:1013D0009927009709F4CDC08093E9002091EB0094
:1013E00020FF1CC020914802233021F48091EB00A3
:1013F000806212C09091EB0090619093EB0021E02D
:1014000030E001C0220F8A95EAF72093EA0010929B
:10141000EA008091EB0088608093EB001092E90075
:101420008091E800877F8093E800D3DDA2C081111E
:10143000A0C08091490290914A028F779927182F76
:101440009091E3009078982B9093E3008091E800CE
:10145000877F8093E800BDDD8091E80080FFFCCFAE
:101460008091E30080688093E300112311F083E012
:1014700001C082E0809346027CC08058823008F030
:1014800078C08091490290914A028C3D23E09207F6
:1014900071F583E08A838AE289834FB7F894DE018D
:1014A000139620E03EE051E2E32FF0E05093570026
:1014B000E49120FF03C0E295EF703F5FEF708E2F45
:1014C00090E0EA3010F0C79601C0C0968D939D93CE
:1014D0002F5F243149F74FBF8091E800877F8093C9
:1014E000E8006AE270E0CE010196FDDB11C0AE01BA
:1014F000455D5F4F60914B02EFD90097D1F120918C
:10150000E800277F2093E800BC018BA59CA58BDC1D
:101510008091E8008B778093E8002BC0803849F5F4
:101520008091E800877F8093E80080914202809359
:10153000F1008091E8008E7776CF81111AC09091EA
:1015400049029230B0F48091E800877F8093E800F0
:10155000909342023EDD80914202811104C080914D
:10156000E30087FF02C084E001C081E0809346026F
:10157000C1D88091E80083FF0AC08091E800877F8E
:101580008093E8008091EB0080628093EB00AC9642
:101590000FB6F894DEBF0FBECDBFDF91CF911F9184
:1015A00008950895CF93809146028823A9F08091F1
:1015B000E9008F709091EC0090FF02C090E801C0AC
:1015C00090E0C92FC82B1092E9008091E80083FDBC
:1015D00087DECF70C093E900CF910895CF93DF935A
:1015E000EC014096FC018BE0DF011D928A95E9F742
:1015F00082E08C83898783E08E8761E0CE0101964B
:10160000AADC882361F061E0CE010696A4DC882381
:1016100031F061E0CE010B96DF91CF919CCC80E060
:10162000DF91CF910895CF93C62F209146022430A9
:10163000F1F4FC014489558966897789452B462B4D
:10164000472BA9F081818F708093E9008091E80099
:1016500085FF04C0C093F10080E00AC08091E800DB
:101660008E778093E800D6DC8823A1F301C082E066
:10167000CF91089520914602243029F5FC01448938
:10168000558966897789452B462B472BE1F0818167
:101690008F708093E9008091F200811102C080E098
:1016A00008959091E8008091E8008E778093E8009B
:1016B00095FDF5CFAFDC811107C09091E8009E77D2
:1016C0009093E800089582E0089520914602243026
:1016D00089F4FC014489558966897789452B462B15
:1016E000472B41F021812F702093E9002091E800E1
:1016F00020FDC0CF089520914602243019F02FEF2D
:101700003FEF24C0FC014489558966897789452BC0
:10171000462B472BA1F386818F708093E90080913F
:10172000E80082FFECCF8091F200882321F0209125
:10173000F10030E002C02FEF3FEF8091F200811105
:1017400005C08091E8008B778093E800C901089577
:101750000895CF93DF93EC018091E80083FFA9C047
:10176000888190E020914B0230914C022817390774
:1017700009F09FC080914802813261F020F48032EC
:1017800009F097C03DC0823209F46EC0833209F07F
:1017900090C07FC080914702813A09F08AC0809151
:1017A000E800877F8093E8008091E80080FFFCCF0D
:1017B0004C895D896E897F894093F100BB27A72FF3
:1017C000962F852F8093F100CB01AA27BB2780930A
:1017D000F100472F5527662777274093F100888D22
:1017E0008093F100898D8093F1008A8D8093F100C0
:1017F0008091E8008E778093E800DF91CF91E9CB6C
:1018000080914702813209F054C08091E800877FBF
:101810008093E80005C080914602882309F449C0FE
:101820008091E80082FFF7CF3091F1002091F10024
:101830009091F1008091F1003C8B2D8B9E8B8F8BD2
:101840008091F100888F8091F100898F8091F10063
:101850008A8F8091E8008B778093E800BADBCE0115
:10186000DF91CF910C94960380914702813209F564
:101870008091E800877F8093E800ABDB809149028C
:1018800090914A02998B888BCE01DF91CF910C9475
:101890002A0480914702813261F48091E800877FB9
:1018A0008093E80096DB60914902CE01DF91CF91F1
:1018B0004FCFDF91CF9108956F927F928F929F9239
:1018C000AF92BF92CF92DF92EF92FF920F931F934E
:1018D000CF93DF9300D01F92CDB7DEB77C01ADB6BA
:1018E000BEB68091E80083FF07C1F701808190E0D8
:1018F00020914B0230914C022817390709F0FCC0A7
:1019000080914802833009F49EC030F4813071F038
:10191000823009F0F1C0D4C08A3009F4B9C08B30EC
:1019200009F4A2C0893009F0E7C04CC08091470299
:10193000813A09F0E1C08DB69EB61A821982809173
:10194000490210914A028B83F70140858DB79EB7FB
:10195000841B91090FB6F8949EBF0FBE8DBFCDB604
:10196000DEB6EFEFCE1ADE0A360150E060E070E03E
:10197000C601EAD1412F41508E010F5F1F4F9601E2
:10198000BE016D5F7F4FC7010E944804F7012681A9
:1019900037812115310529F0408550E0B601C90194
:1019A000CAD11092E9008091E800877F8093E80017
:1019B00069817A81C30197D98091E8008B77809300
:1019C000E80039C080914702813209F095C08DB698
:1019D0009EB600914D0210914E02709049026090A7
:1019E0004A028DB79EB7801B910B0FB6F8949EBF2D
:1019F0000FBE8DBFCDB6DEB6EFEFCE1ADE0A8091F8
:101A0000E800877F8093E800B801C601CCD98091B7
:101A1000E8008E778093E80021E0711001C020E09B
:101A200030E0021B130B2C0D3D1D462D4150672D40
:101A3000C7010E946B04882D992D0FB6F8949EBFA4
:101A40000FBE8DBF59C080914702813A09F054C042
:101A50008091E800877F8093E8008091E80080FF14
:101A6000FCCFF701818540C080914702813209F0A7
:101A700043C08091E800877F8093E800AADA9091C4
:101A8000490281E0911101C080E0F701818734C0F3
:101A900080914702813281F58091E800877F8093B1
:101AA000E80097DA8091490290914A02882736E04F
:101AB000969587953A95E1F7F701958784871CC03D
:101AC00080914702813AC1F48091E800877F80933A
:101AD000E8008091E80080FFFCCFF70184859585C0
:101AE00096958795969587958093F1008091E8006B
:101AF0008E778093E8006DDA0FB6F894BEBE0FBE05
:101B0000ADBE0F900F900F90DF91CF911F910F916D
:101B1000FF90EF90DF90CF90BF90AF909F908F900D
:101B20007F906F9008959C01275F3F4FF90127E058
:101B3000DF011D922A95E9F721E0FC01218724EFBE
:101B400031E03587248723E0248361E0019603CACE
:101B50004F925F926F927F928F929F92AF92BF92BD
:101B6000CF92DF92EF92FF920F931F93CF93DF9369
:101B700000D01F92CDB7DEB77C01ADB6BEB6809166
:101B80004602843009F08FC08091E4009091E50016
:101B9000F701228533852817390709F484C081812C
:101BA0008F708093E9008091E80085FF7CC06DB65E
:101BB0007EB640858DB79EB7841B91090FB6F89409
:101BC0009EBF0FBE8DBFCDB6DEB6EFEFCE1ADE0ADA
:101BD0001B821A821982460150E060E070E0C60163
:101BE000B3D08E010F5F1F4F960140E0BE016D5FC5
:101BF0007F4FC7010E944804582EF70184859585C0
:101C0000892B31F001E010E086859785892B11F052
:101C100000E010E0F701C680D780C114D10489F03C
:101C200049815A81B601C40179D044244394009774
:101C300009F4412CF701408550E0B401C6017BD086
:101C400001C0412C89819A81892BF9F0511004C07F
:101C5000411002C000FF19C0F70184859585978760
:101C6000868781818F708093E9008B8181118093B9
:101C7000F10069817A8140E050E0C4010E942606AB
:101C80008091E8008E778093E8008091E400909145
:101C9000E500F70193878287862D972D0FB6F8947C
:101CA0009EBF0FBE8DBF0FB6F894BEBE0FBEADBEB9
:101CB0000F900F900F90DF91CF911F910F91FF9098
:101CC000EF90DF90CF90BF90AF909F908F907F90DC
:101CD0006F905F904F900895A1E21A2EAA1BBB1B34
:101CE000FD010DC0AA1FBB1FEE1FFF1FA217B307E8
:101CF000E407F50720F0A21BB30BE40BF50B661FFE
:101D0000771F881F991F1A9469F7609570958095C1
:101D100090959B01AC01BD01CF010895FB01DC0151
:101D200004C08D910190801921F441505040C8F7B2
:101D3000881B990B0895FB01DC0102C001900D92F4
:101D400041505040D8F70895DC0101C06D934150D7
:0A1D50005040E0F70895F894FFCF2B
:101D5A0002812000000118021100000000000000AA
:101D6A0000834000000104400000018208000001D5
:0E1D7A00000000000000000000000008302003
:1003D000CF92DF92EF92FF920F931F93CF93DF9311
:1003E00000D000D000D0CDB7DEB780911C028111C3
:1003F00022C060911A0270E07160AE014F5F5F4FE2
:1004000081E034D48E010F5F1F4F6801E82EF12C7C
:100410000CC08091200180FF06C0F801608180E15E
:1004200091E00E94390B0F5F1F4FC8018C199D0985
:100430008E159F0574F310921A0210921C022696D4
:100440000FB6F894DEBF0FBECDBFDF91CF911F91E5
:100450000F91FF90EF90DF90CF9008951F93CF936F
:10046000DF9397D3882309F48BC01A9B89C08091AE
:10047000240190912501A0912601B09127018115B9
:1004800022EC920721E0A207B10529F0892B8A2BE3
:100490008B2B09F075C09FD28130A9F5ABD280FFBC
:1004A00032C080911A02811193DFA1D280931A0287
:1004B00010921C0291E1EDE1F2E0DF01292F1D9283
:1004C0002A95E9F7853099F038F4823061F084306C
:1004D00051F0813099F405C0883058F08A3070F4BA
:1004E0000BC084E001C088E080931B0208C081E05B
:1004F000FBCF90931B0203C083E0F6CF69DFDF914F
:10050000CF911F9164C280911A028823C9F163D2EE
:1005100010911C02C12FD0E090E09E012E5F3F4F52
:10052000359527952F5F3F4F8217930729F55FD2A7
:10053000C35EDD4F8883C12FCF5FC0931C028091C3
:100540001B028C1749F056D2EC2FF0E0E35EFD4F12
:1005500080831E5F10931C0290911B0280911C02ED
:100560009813CDCF04C080E091E00E94CE0D809121
:100570001A028111F8CFC3CFDF91CF911F9128CFFD
:10058000DF91CF911F910895CCDE2FB7F89480E3CF
:1005900091E09093A1018093A0019093A301809397
:1005A000A2012FBF2FB7F89485EA91E0909316022D
:1005B0008093150290931802809317022FBF7894AE
:1005C00010921C0210921A02C0E3D1E08C0153E099
:1005D000E52E9FB7F8948091A4019FBF803719F151
:1005E00080E191E00E94A10B97FD1DC0E091A00168
:1005F000F091A10180838091A0019091A1010196C9
:100600009093A1018093A001805A914021F4D0934E
:10061000A101C093A0019FB7F8948091A4018F5FBE
:100620008093A4019FBF8FB7F894F09019028FBFF9
:10063000A89904C080E58F1508F056C0A89A80914B
:100640001902882341F15D98E0922E0124C0D5D192
:10065000877F39F080911A028111BADE80912E02D3
:1006600099DEE0911702F09118028191F09318023F
:10067000E0931702E551F24021F410931802009321
:1006800017022FB7F8949091190291509093190284
:100690002FBFE4DEFA94F110DACF80912E01882387
:1006A000B9F080912E01815080932E01811110C0EC
:1006B00080911A0281118CDEA0D183FD07C0F090D9
:1006C0002E029BD187FDF3948F2D64DE80D15D9A3D
:1006D00080912F01882341F080912F0181508093D8
:1006E0002F01811101C05C9A9FB7F8948091A401F9
:1006F0009FBF882309F1E091A201F091A30191919C
:10070000F093A301E093A201E05AF14021F4D093C9
:10071000A301C093A2012FB7F8948091A401815046
:100720008093A4012FBF8091C80085FFFCCF9093D8
:10073000CE005C98E0922F0180E191E0ECD758D791
:1007400048CF08950895CF9380E091E00E94B90DBD
:10075000C82F80E191E068D79091E2009460909377
:10076000E200882321F0CC2311F080E001C080E377
:100770009BB18095906389238BB9CF9108951F9386
:10078000CF93DF93EC01E98DE150E23028F4F0E003
:10079000E45DFE4F108101C010E0888D823009F4C5
:1007A00018608A8D873031F0883031F0863029F436
:1007B000126003C0146001C016605B9A1092C900F9
:1007C0001092C8001092CA002C893D894E895F8919
:1007D000211581EE38074105510579F0CA01B901AB
:1007E000969587957795679560587B47814E9F4F83
:1007F0000E94920E2150310902C020E130E0309376
:10080000CD002093CC001093CA008C899D89AE89BD
:10081000BF898115914EA105B10511F480E001C099
:1008200082E08093C80088E98093C9005B98DF91DB
:10083000CF911F9108951F920F920FB60F9211241E
:100840002F938F939F93EF93FF938091CE0090917E
:1008500044029430F1F4E0911502F0911602808385
:10086000E0911502F0911602CF01019690931602C5
:10087000809315028551924021F485EA91E092839C
:1008800081839FB7F894809119028F5F809319023A
:100890009FBFFF91EF919F918F912F910F900FBE6E
:1008A0000F901F901895FC01208920FF02C05F98CF
:1008B00008955F9A8BB180638BB9089580E191E0D0
:1008C0006ED780E091E00C94820C80910E019091A3
:1008D0000F01009729F0019790930F0180930E016B
:1008E0000895EF92FF920F931F93CF93DF937B01B5
:1008F000C901E80110911B02EDE1F2E0412F50E047
:10090000BF010E94C10EEAE1F2E08081D7018C9321
:1009100018831982108210921C0281E0DF91CF911E
:100920001F910F91FF90EF9008950895292F33277D
:1009300023303105B1F04CF42130310509F439C0D0
:100940002230310509F03AC007C02132310539F1B2
:100950002232310549F132C0EFE5F0E08EEB90E054
:1009600031C099278130910561F08230910581F085
:10097000892B21F5EAEBF0E0E491F0E08AEB90E0DE
:1009800021C0E6EAF0E0E491F0E086EA90E01AC0E7
:10099000E4E7F0E0E491F0E084E790E013C0E9E000
:1009A000F0E08DE091E00EC0E8EBF1E08FE291E045
:1009B00009C0E2E1F0E08DE191E004C0E0E0F0E0A8
:1009C00080E090E0DA018D939C93CF01089588E058
:1009D00080932B010895809136020895609137022B
:1009E000709138028091390290913A020895809175
:1009F0003702089580913802089580912B0108955F
:100A0000982F80912B018823E9F083FF0AC0109270
:100A10003B0210923C0210923D0210923E02109254
:100A20003F0287FF0DC040912E02E42FF0E0E15D10
:100A3000FD4F808180932F0281E080932E0202C0BF
:100A400010922E0210923502109236021092370246
:100A5000109238021092390210923A0210922B0131
:100A600020912E02E22FF0E0E15DFD4F9083822F76
:100A70008F5F80932E02392F307C80913B0230387B
:100A800009F440C0303C09F05EC0882329F080E9B9
:100A900080932B0120932E02292F287326952695CB
:100AA0002695223018F02730E1F40AC09F709F5F2E
:100AB0009093350210923B0280912B0185603DC0DE
:100AC000492F4F7050E060E070E040933C0250933B
:100AD0003D0260933E0270933F0285E080933B02AB
:100AE00056C0892F877090E0A0E0B0E080933C0270
:100AF00090933D02A0933E02B0933F022150209379
:100B00003B0245C0282F215020933B028130C9F47D
:100B10009F739F5F9093360280913C0290913D02BB
:100B2000A0913E02B0913F02809337029093380229
:100B3000A0933902B0933A0283E080932B0181E0C5
:100B4000089580E507C0282F215020933B02823072
:100B500030F480E380932B0110923B0218C0409147
:100B60003C0250913D0260913E0270913F0287E04D
:100B7000440F551F661F771F8A95D1F7492B409365
:100B80003C0250933D0260933E0270933F0280E02E
:100B900008950F931F9334DF8823A9F01CDF882367
:100BA00091F01CDF8C0122273327DC01CB01AA271F
:100BB000BB27082719272A273B2781E00F3F1F4F14
:100BC0002105310509F080E01F910F9108950F93E1
:100BD0001F93CF93F901ACE1B0E097E08A019B014C
:100BE0000A2E04C036952795179507950A94D2F7D3
:100BF000083028F0973051F4008396E007C0008356
:100C00009150011103C01797923041F7C92FC2507C
:100C100012C0DF01AC0FB11D8A019B010F771127B4
:100C2000222733270C93A7E076956795579547952C
:100C3000AA95D1F7C150C111ECCF492F50E09A01CC
:100C400063E0220F331F6A95E1F7206C3F6F30811C
:100C5000322B3083E40FF51F319781508F738068FA
:100C60008083892FCF911F910F9108950F931F9328
:100C70008B01FA01AB014095509560E070E0BA013C
:100C80005527442720E030E0402B512B622B732B5B
:100C90009F011F910F919BCFBF92CF92DF92EF9256
:100CA000FF920F931F93CF93DF937C018B01EA0197
:100CB000D7D1B82E811132C0209731F028813981E7
:100CC000021B130BE20EF31EC12CD12C22C080910B
:100CD000E80085FD14C08091E8008E778093E800DD
:100CE000209749F0888199818C0D9D1D9983888377
:100CF00025E0B22E13C0B4D1882359F00EC0F701FD
:100D000081917F018093F10001501109FFEFCF1A0B
:100D1000DF0A01151105D9F601C0B82E8B2DDF9120
:100D2000CF911F910F91FF90EF90DF90CF90BF90E8
:100D3000089520914B0230914C022617370748F056
:100D40006115710539F42091E8002E772093E800B1
:100D500001C0B9019C0180E034C090914402992304
:100D600009F443C0953009F442C09091E80093FD26
:100D70003AC09091E80092FD30C09091E80090FF59
:100D800020C08091F20090E0F901821B930B05C016
:100D900021912093F100615071099F01280F391FA3
:100DA0006115710519F02830310590F381E0283084
:100DB000310509F080E09091E8009E779093E8007B
:100DC0009F016115710549F68111C7CF06C0809159
:100DD0004402882351F0853051F08091E80082FF71
:100DE000F6CF80E0089581E0089582E0089583E0E1
:100DF00008956115710529F42091E8002B7720935F
:100E0000E8009C0121C080914402882381F1853053
:100E100041F18091E80083FD26C08091E80082FFC7
:100E2000F2CFF90107C08091F10081939F016150D9
:100E3000710929F09F018091F2008111F4CF809116
:100E4000E8008B778093E80061157105E1F68091E9
:100E5000E80080FD0AC080914402882341F085307B
:100E6000B1F783E0089581E0089580E0089582E07D
:100E7000089520914B0230914C022617370748F015
:100E80006115710539F42091E8002E772093E80070
:100E900001C0B9019C0180E035C0909144029923C2
:100EA00009F444C0953009F443C09091E80093FDE3
:100EB0003BC09091E80092FD31C09091E80090FF16
:100EC00021C08091F20090E0F901821B930B06C0D3
:100ED00024912093F1003196615071099C012E0FED
:100EE0003F1F6115710519F02830310588F381E045
:100EF0002830310509F080E09091E8009E779093CA
:100F0000E8009F016115710541F68111C6CF06C049
:100F100080914402882351F0853051F08091E8009F
:100F200082FFF6CF80E0089581E0089582E0089581
:100F300083E00895982F2CC09093E900981739F01A
:100F40007091EC002091ED005091F00003C0242F2F
:100F5000762F50E021FD02C09F5F1AC03091EB0058
:100F60003E7F3093EB003091ED003D7F3093ED00FC
:100F70003091EB0031603093EB007093EC002093E4
:100F8000ED005093F0002091EE0027FDE5CF07C063
:100F9000953090F28F708093E90081E0089580E0B1
:100FA00008950F931F93CF93DF93062FEC0110E06A
:100FB0002EC09881911103C01F5F259628C02C81F7
:100FC000E981FA816B81892F8F70853010F080E084
:100FD00021C0223010F056E001C052E028E030E09D
:100FE00040E003C04F5F220F331F2E173F07D0F39F
:100FF0004295407F452B991F9927991F6295660F4F
:10100000660F607C692B96DF8111D6CFE0CF10137D
:10101000D0CF81E0DF91CF911F910F910895809102
:10102000450287FD05C08091E80080FF0EC012C018
:101030008091E80082FD05C0809144028111F8CFC3
:1010400008958091E8008B7708C080914402811157
:10105000EACF08958091E8008E778093E8000895A4
:101060008091E4009091E50045E62091EC0020FDA0
:101070001FC023C020914402222391F0253091F01B
:101080002091EB0025FD10C02091E4003091E50097
:101090002817390751F34150C90139F784E0089501
:1010A00082E0089583E0089581E0089580E0089546
:1010B0002091E80020FFDECFF9CF2091E80022FF49
:1010C000D9CFF4CF41D043D08091D8008F7780938F
:1010D000D8008091D80080688093D8008091D80093
:1010E0008F7D8093D80084E089BD86E089BD09B4F6
:1010F00000FEFDCF10924402109240021092420274
:101100001092410242E060E080E014DF8091E10053
:101110008E7F8093E1008091E20081608093E20005
:101120008091E20088608093E2008091E0008E7FF1
:101130008093E0000895E3E6F0E080818E7F808375
:1011400081E080934302BECF1092E2000895109296
:10115000E10008951F920F920FB60F9211242F9362
:101160003F934F935F936F937F938F939F93AF932F
:10117000BF93EF93FF938091E10082FF0AC08091BB
:10118000E20082FF06C08091E1008B7F8093E10046
:101190009CDB8091E10080FF17C08091E20080FF1E
:1011A00013C08091E2008E7F8093E2008091E20084
:1011B00080618093E2008091D80080628093D800A3
:1011C00019BC10924402BEDA8091E10084FF2FC066
:1011D0008091E20084FF2BC084E089BD86E089BD58
:1011E00009B400FEFDCF8091D8008F7D8093D80098
:1011F0008091E1008F7E8093E1008091E2008F7EFC
:101200008093E2008091E20081608093E20080910F
:101210004002882311F084E007C08091E30087FF3B
:1012200002C083E001C081E0809344028ADA8091A9
:10123000E10083FF27C08091E20083FF23C08091FB
:10124000E100877F8093E10082E080934402109266
:1012500040028091E1008E7F8093E1008091E20066
:101260008E7F8093E2008091E20080618093E200B3
:1012700042E060E080E05EDE8091F0008860809374
:10128000F000B5D1FF91EF91BF91AF919F918F91F8
:101290007F916F915F914F913F912F910F900FBE72
:1012A0000F901F9018951F920F920FB60F92112456
:1012B0002F933F934F935F936F937F938F939F935E
:1012C000AF93BF93CF93EF93FF938091E9008F701B
:1012D0009091EC0090FF02C090E801C090E0C92F0F
:1012E000C82B1092E9008091F000877F8093F00076
:1012F00078941CD01092E9008091F000886080936F
:10130000F000CF70C093E900FF91EF91CF91BF91B2
:10131000AF919F918F917F916F915F914F913F918D
:101320002F910F900FBE0F901F9018951F93CF9382
:10133000DF93CDB7DEB7AC970FB6F894DEBF0FBE24
:10134000CDBFE5E4F2E08091F100819322E0ED343D
:10135000F207C9F7B3DA8091E80083FF30C18091CA
:10136000450290914602953009F487C038F49130D7
:10137000B1F170F0933009F022C131C0983009F416
:10138000F3C0993009F4FFC0963009F018C19BC032
:10139000803821F0823809F012C108C080914102E2
:1013A00090914202992389F082600FC08091490296
:1013B00090914A028F7099278093E9008091EB0009
:1013C00085FB882780F91092E9009091E800977FCB
:1013D0009093E8008093F1001092F100D0C0882330
:1013E00019F0823009F0EBC08F7121F0823009F0E2
:1013F000E6C00BC080914702813009F0E0C0933015
:1014000009F080E0809342022FC080914702811151
:101410002BC08091490290914A028F7099270097C2
:1014200009F4CDC08093E9002091EB0020FF1CC09F
:1014300020914602233021F48091EB00806212C09B
:101440009091EB0090619093EB0021E030E001C0BF
:10145000220F8A95EAF72093EA001092EA00809121
:10146000EB0088608093EB001092E9008091E80027
:10147000877F8093E800D3DDA2C08111A0C0809156
:101480004702909148028F779927182F9091E30097
:101490009078982B9093E3008091E800877F809369
:1014A000E800BDDD8091E80080FFFCCF8091E30083
:1014B00080688093E300112311F083E001C082E093
:1014C000809344027CC08058823008F078C08091BC
:1014D0004702909148028C3D23E0920771F583E02A
:1014E0008A838AE289834FB7F894DE01139620E05D
:1014F0003EE051E2E32FF0E050935700E49120FFEB
:1015000003C0E295EF703F5FEF708E2F90E0EA30FE
:1015100010F0C79601C0C0968D939D932F5F243124
:1015200049F74FBF8091E800877F8093E8006AE227
:1015300070E0CE010196FDDB11C0AE01455D5F4F4D
:1015400060914902F3D90097D1F12091E800277FFB
:101550002093E800BC018BA59CA58BDC8091E80062
:101560008B778093E8002BC0803849F58091E800A4
:10157000877F8093E800809140028093F100809102
:10158000E8008E7776CF81111AC090914702923091
:10159000B0F48091E800877F8093E8009093400248
:1015A0003EDD80914002811104C08091E30087FFFD
:1015B00002C084E001C081E080934402C4D88091DD
:1015C000E80083FF0AC08091E800877F8093E800ED
:1015D0008091EB0080628093EB00AC960FB6F8949C
:1015E000DEBF0FBECDBFDF91CF911F91089508954B
:1015F000CF93809144028823A9F08091E9008F70F5
:101600009091EC0090FF02C090E801C090E0C92FDB
:10161000C82B1092E9008091E80083FD87DECF702F
:10162000C093E900CF910895CF93DF93EC014096EA
:10163000FC018BE0DF011D928A95E9F782E08C8343
:10164000898783E08E8761E0CE010196AADC88233A
:1016500061F061E0CE010696A4DC882331F061E000
:10166000CE010B96DF91CF919CCC80E0DF91CF91A2
:101670000895CF93C62F209144022430F1F4FC0149
:101680004489558966897789452B462B472BA9F0D4
:1016900081818F708093E9008091E80085FF04C00C
:1016A000C093F10080E00AC08091E8008E778093BB
:1016B000E800D6DC8823A1F301C082E0CF91089531
:1016C00020914402243029F5FC014489558966891A
:1016D0007789452B462B472BE1F081818F708093D2
:1016E000E9008091F200811102C080E0089590919C
:1016F000E8008091E8008E778093E80095FDF5CFB3
:10170000AFDC811107C09091E8009E779093E800CC
:10171000089582E0089520914402243089F4FC0168
:101720004489558966897789452B462B472B41F09B
:1017300021812F702093E9002091E80020FDC0CF87
:10174000089520914402243019F02FEF3FEF24C078
:10175000FC014489558966897789452B462B472B9F
:10176000A1F386818F708093E9008091E80082FF69
:10177000ECCF8091F200882321F02091F10030E03D
:1017800002C02FEF3FEF8091F200811105C08091E0
:10179000E8008B778093E800C90108950895CF93FE
:1017A000DF93EC018091E80083FFA9C0888190E07D
:1017B0002091490230914A022817390709F09FC049
:1017C00080914602813261F020F4803209F097C0A6
:1017D0003DC0823209F46EC0833209F090C07FC0F0
:1017E00080914502813A09F08AC08091E800877FA4
:1017F0008093E8008091E80080FFFCCF4C895D89F0
:101800006E897F894093F100BB27A72F962F852FE4
:101810008093F100CB01AA27BB278093F100472FCB
:101820005527662777274093F100888D8093F10034
:10183000898D8093F1008A8D8093F1008091E8007A
:101840008E778093E800DF91CF91E9CB80914502BC
:10185000813209F054C08091E800877F8093E800CE
:1018600005C080914402882309F449C08091E800B2
:1018700082FFF7CF3091F1002091F1009091F100BB
:101880008091F1003C8B2D8B9E8B8F8B8091F10092
:10189000888F8091F100898F8091F1008A8F8091EB
:1018A000E8008B778093E800BADBCE01DF91CF911F
:1018B0000C94BF0380914502813209F58091E800C4
:1018C000877F8093E800ABDB8091470290914802CC
:1018D000998B888BCE01DF91CF910C94530480912A
:1018E0004502813261F48091E800877F8093E800AF
:1018F00096DB60914702CE01DF91CF914FCFDF9110
:10190000CF9108956F927F928F929F92AF92BF92E4
:10191000CF92DF92EF92FF920F931F93CF93DF93BB
:1019200000D01F92CDB7DEB77C01ADB6BEB68091B8
:10193000E80083FF07C1F701808190E02091490210
:1019400030914A022817390709F0FCC080914602FD
:10195000833009F49EC030F4813071F0823009F098
:10196000F1C0D4C08A3009F4B9C08B3009F4A2C0E8
:10197000893009F0E7C04CC080914502813A09F0F6
:10198000E1C08DB69EB61A821982809147021091ED
:1019900048028B83F70140858DB79EB7841B910960
:1019A0000FB6F8949EBF0FBE8DBFCDB6DEB6EFEF7B
:1019B000CE1ADE0A360150E060E070E0C601EAD1DE
:1019C000412F41508E010F5F1F4F9601BE016D5F89
:1019D0007F4FC7010E947104F701268137812115CD
:1019E000310529F0408550E0B601C901CAD11092F5
:1019F000E9008091E800877F8093E80069817A811F
:101A0000C30197D98091E8008B778093E80039C0B3
:101A100080914502813209F095C08DB69EB6009145
:101A20004B0210914C0270904702609048028DB7B3
:101A30009EB7801B910B0FB6F8949EBF0FBE8DBF53
:101A4000CDB6DEB6EFEFCE1ADE0A8091E800877FD2
:101A50008093E800B801C601CCD98091E8008E7768
:101A60008093E80021E0711001C020E030E0021B0B
:101A7000130B2C0D3D1D462D4150672DC7010E94B3
:101A80009504882D992D0FB6F8949EBF0FBE8DBF7B
:101A900059C080914502813A09F054C08091E80014
:101AA000877F8093E8008091E80080FFFCCFF701FA
:101AB000818540C080914502813209F043C0809108
:101AC000E800877F8093E800AADA9091470281E0DE
:101AD000911101C080E0F701818734C080914502F7
:101AE000813281F58091E800877F8093E80097DA62
:101AF0008091470290914802882736E09695879515
:101B00003A95E1F7F701958784871CC080914502DB
:101B1000813AC1F48091E800877F8093E80080914A
:101B2000E80080FFFCCFF701848595859695879521
:101B3000969587958093F1008091E8008E77809349
:101B4000E8006DDA0FB6F894BEBE0FBEADBE0F90C2
:101B50000F900F90DF91CF911F910F91FF90EF9019
:101B6000DF90CF90BF90AF909F908F907F906F90BD
:101B700008959C01275F3F4FF90127E0DF011D9287
:101B80002A95E9F721E0FC01218724EF31E0358730
:101B9000248723E0248361E0019603CA4F925F9279
:101BA0006F927F928F929F92AF92BF92CF92DF926D
:101BB000EF92FF920F931F93CF93DF9300D01F926A
:101BC000CDB7DEB77C01ADB6BEB68091440284309D
:101BD00009F08FC08091E4009091E500F701228523
:101BE00033852817390709F484C081818F70809369
:101BF000E9008091E80085FF7CC06DB67EB6408527
:101C00008DB79EB7841B91090FB6F8949EBF0FBE87
:101C10008DBFCDB6DEB6EFEFCE1ADE0A1B821A827A
:101C20001982460150E060E070E0C601B3D08E0139
:101C30000F5F1F4F960140E0BE016D5F7F4FC701F0
:101C40000E947104582EF70184859585892B31F007
:101C500001E010E086859785892B11F000E010E007
:101C6000F701C680D780C114D10489F049815A8117
:101C7000B601C40179D044244394009709F4412C5F
:101C8000F701408550E0B401C6017BD001C0412C72
:101C900089819A81892BF9F0511004C0411002C04A
:101CA00000FF19C0F7018485958597878687818114
:101CB0008F708093E9008B8181118093F10069819D
:101CC0007A8140E050E0C4010E944C068091E80017
:101CD0008E778093E8008091E4009091E500F70111
:101CE00093878287862D972D0FB6F8949EBF0FBEDF
:101CF0008DBF0FB6F894BEBE0FBEADBE0F900F9055
:101D00000F90DF91CF911F910F91FF90EF90DF9097
:101D1000CF90BF90AF909F908F907F906F905F908B
:101D20004F900895A1E21A2EAA1BBB1BFD010DC006
:101D3000AA1FBB1FEE1FFF1FA217B307E407F5077B
:101D400020F0A21BB30BE40BF50B661F771F881F57
:101D5000991F1A9469F760957095809590959B01ED
:101D6000AC01BD01CF010895FB01DC0104C08D91E0
:101D70000190801921F441505040C8F7881B990BFD
:101D80000895FB01DC0102C001900D9241505040CA
:101D9000D8F70895DC0101C06D9341505040E0F741
:061DA0000895F894FFCF46
:101DA6000281200000010000110000000000000078
:101DB6000083400000010440000001820800000189
:0E1DC6000000000000000000000000083020B7
:00000001FF

View file

@ -376,7 +376,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
//.VendorID = 0x2341, // Arduino
//.ProductID = 0x0043, // Arduino Uno
.ReleaseNumber = VERSION_BCD(0,1,2),
.ReleaseNumber = VERSION_BCD(0,1,3),
.ManufacturerStrIndex = STRING_ID_Manufacturer,
.ProductStrIndex = STRING_ID_Product,

View file

@ -39,11 +39,10 @@ static RingBuff_t USARTtoUSB_Buffer;
/** Pulse generation counters to keep track of the number of milliseconds remaining for each pulse type */
//new important ram fix!! <--
static volatile struct
{
static volatile struct{
uint8_t TxLEDPulse; /**< Milliseconds remaining for data Tx LED pulse */
uint8_t RxLEDPulse; /**< Milliseconds remaining for data Rx LED pulse */
uint8_t PingPongLEDPulse; /**< Milliseconds remaining for enumeration Tx/Rx ping-pong LED pulse */
//uint8_t PingPongLEDPulse; /**< Milliseconds remaining for enumeration Tx/Rx ping-pong LED pulse */
} PulseMSRemaining;
@ -55,32 +54,28 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
{
.Config =
{
.ControlInterfaceNumber = INTERFACE_ID_CDC_CCI,
.DataINEndpoint =
.ControlInterfaceNumber = INTERFACE_ID_CDC_CCI,
.DataINEndpoint =
{
.Address = CDC_TX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
.Address = CDC_TX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
},
.DataOUTEndpoint =
.DataOUTEndpoint =
{
.Address = CDC_RX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
.Address = CDC_RX_EPADDR,
.Size = CDC_TXRX_EPSIZE,
.Banks = 1,
},
.NotificationEndpoint =
.NotificationEndpoint =
{
.Address = CDC_NOTIFICATION_EPADDR,
.Size = CDC_NOTIFICATION_EPSIZE,
.Banks = 1,
.Address = CDC_NOTIFICATION_EPADDR,
.Size = CDC_NOTIFICATION_EPSIZE,
.Banks = 1,
},
},
};
/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */
static uint8_t PrevHIDReportBuffer[sizeof(HID_HIDReport_Data_t)];
static uint8_t CurrentHIDReportBuffer[sizeof(HID_HIDReport_Data_t)];
static struct{
// variable to perform a "HID flush" and to indicate what report should be written down
uint8_t ID;
@ -89,7 +84,7 @@ static struct{
// number of bytes received
uint8_t recvlength;
// should the report been written even if nothing changed? important for mouse
bool forcewrite;
//bool forcewrite; // always true, removed
} HIDReportState;
/** LUFA HID Class driver interface configuration and state information. This structure is
@ -100,18 +95,21 @@ USB_ClassInfo_HID_Device_t Device_HID_Interface =
{
.Config =
{
.InterfaceNumber = INTERFACE_ID_HID,
.ReportINEndpoint =
.InterfaceNumber = INTERFACE_ID_HID,
.ReportINEndpoint =
{
.Address = HID_IN_EPADDR,
.Size = HID_EPSIZE,
.Banks = 1,
.Address = HID_IN_EPADDR,
.Size = HID_EPSIZE,
.Banks = 1,
},
.PrevReportINBuffer = PrevHIDReportBuffer,
.PrevReportINBufferSize = sizeof(PrevHIDReportBuffer),
.PrevReportINBuffer = NULL,
.PrevReportINBufferSize = sizeof(HID_HIDReport_Data_t),
},
};
/** Buffer to hold the previously generated HID report, for comparison purposes inside the HID class driver. */
static uint8_t HIDReportBuffer[sizeof(HID_HIDReport_Data_t)];
/** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.
*/
@ -125,8 +123,8 @@ int main(void)
GlobalInterruptEnable();
// HID Setup
HIDReportState.recvlength=0;
HIDReportState.ID=0;
HIDReportState.recvlength = 0;
HIDReportState.ID = 0;
// Debug
//DDRB |= 0x08; //led out
@ -139,7 +137,7 @@ int main(void)
{
// Only try to read in bytes from the CDC interface if the transmit buffer is not full
if (!(RingBuffer_IsFull(&USBtoUSART_Buffer)))
{
{
int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
// Read bytes from the USB OUT endpoint into the USART transmit buffer
@ -163,15 +161,15 @@ int main(void)
//new Protocol check<--
// if a reading finished succesfull without valid checksum or an error occured (ignore a reset)
if(NHPgetErrorLevel()&(~NHP_INPUT_RESET)){
if (NHPgetErrorLevel()&(~NHP_INPUT_RESET)){
// check if previous reading was a valid Control Address and write it down
if(HIDReportState.ID)
if (HIDReportState.ID)
checkNHPControlAddressError();
// Write the last invalid signals. This will not write a possible new lead to keep
// it for the next reading. This is implemented in the Protocol itself.
writeNHPreadBuffer(NHPreadlength);
}
}
//read newest byte and check for Protocol
RingBuff_Data_t b = RingBuffer_Remove(&USARTtoUSB_Buffer);
@ -183,15 +181,15 @@ int main(void)
if (PulseMSRemaining.TxLEDPulse && !(--PulseMSRemaining.TxLEDPulse)){
// check if previous reading was a valid Control Address and write it down
if(HIDReportState.ID)
if (HIDReportState.ID)
checkNHPControlAddressError();
// only write if there is input (ignore a reset)
if(!(NHPgetErrorLevel() & NHP_INPUT_RESET)){
if (!(NHPgetErrorLevel() & NHP_INPUT_RESET)){
// Lead errors are not in the buff length to keep them for next reading.
// But we want to write it down now after timeout.
uint8_t len= NHPreadlength;
if(NHPgetErrorLevel()& NHP_ERR_LEAD) len++;
uint8_t len = NHPreadlength;
if (NHPgetErrorLevel()& NHP_ERR_LEAD) len++;
writeNHPreadBuffer(len);
}
// do not write again in the while loop above anyways
@ -238,6 +236,8 @@ void SetupHardware(void)
UCSR1A = 0;
UCSR1C = 0;
// these are values for 115200 i just read them from manual change
// its needed to start with baud 115200 on powerup
UCSR1C = ((1 << UCSZ11) | (1 << UCSZ10)); //C: 0x06
UCSR1A = (1 << U2X1); //A: 0x02
UCSR1B = ((1 << RXCIE1) | (1 << TXEN1) | (1 << RXEN1)); //B: 0x98
@ -251,7 +251,7 @@ void SetupHardware(void)
/* Pull target /RESET line high */
AVR_RESET_LINE_PORT |= AVR_RESET_LINE_MASK;
AVR_RESET_LINE_DDR |= AVR_RESET_LINE_MASK;
AVR_RESET_LINE_DDR |= AVR_RESET_LINE_MASK;
// Hardwaresetup to turn off the HID function with shorting the MOSI pin with GND next to it
AVR_NO_HID_DDR &= ~AVR_NO_HID_MASK; // Input
@ -260,66 +260,68 @@ void SetupHardware(void)
/** Writes the NHP read buffer with the given length */
void writeNHPreadBuffer(uint8_t length){
for(int i=0; i<length;i++){
for (int i = 0; i < length; i++){
bool CurrentDTRState = (VirtualSerial_CDC_Interface.State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR); //new <--
if(CurrentDTRState)
if (CurrentDTRState)
CDC_Device_SendByte(&VirtualSerial_CDC_Interface, NHPreadbuffer[i]);
}
}
/** Checks for a valid protocol input and writes HID report */
void checkNHPProtocol(RingBuff_Data_t input){
if(NHPreadChecksum(input)){
if (NHPreadChecksum(input)){
// only process signal if HID is turned on
// make sure that no report is still active (like holding down a keyboard key)!
// remove later? <--
if(!(AVR_NO_HID_PIN & AVR_NO_HID_MASK))
// Or dont recognize if baud is not 115200 to ensure that there is no conflict with other bauds
// Secound != 0 is for starting from powerup when no lineEncoding is set
if (!(AVR_NO_HID_PIN & AVR_NO_HID_MASK) ||
VirtualSerial_CDC_Interface.State.LineEncoding.BaudRateBPS != 115200 && VirtualSerial_CDC_Interface.State.LineEncoding.BaudRateBPS != 0)
return;
// nearly the same priciple like the Protocol itself: check for control address
if(NHPgetAddress()==NHP_ADDRESS_CONTROL && NHPgetChecksumData1() & NHP_USAGE_ARDUINOHID){
if (NHPgetAddress() == NHP_ADDRESS_CONTROL && NHPgetChecksumData1() & NHP_USAGE_ARDUINOHID){
// check if previous reading was a valid Control Address and write it down
if(HIDReportState.ID)
if (HIDReportState.ID)
checkNHPControlAddressError();
// get the new report ID and reset the buffer
HIDReportState.ID = NHPgetChecksumData0();
HIDReportState.recvlength=0;
memset(CurrentHIDReportBuffer, 0, sizeof(CurrentHIDReportBuffer));
HIDReportState.recvlength = 0;
memset(HIDReportBuffer, 0, sizeof(HIDReportBuffer));
/* Determine which interface must have its report generated */
switch(HIDReportState.ID){
switch (HIDReportState.ID){
case HID_REPORTID_MouseReport:
HIDReportState.length=sizeof(HID_MouseReport_Data_t);
HIDReportState.forcewrite=true;
HIDReportState.length = sizeof(HID_MouseReport_Data_t);
//HIDReportState.forcewrite = true;
break;
case HID_REPORTID_KeyboardReport:
HIDReportState.length=sizeof(HID_KeyboardReport_Data_t);
HIDReportState.forcewrite=true; // set to true because of some bugs with joystick 1+2
HIDReportState.length = sizeof(HID_KeyboardReport_Data_t);
//HIDReportState.forcewrite = true; // set to true because of some bugs with joystick 1+2
break;
case HID_REPORTID_MediaReport:
HIDReportState.length=sizeof(HID_MediaReport_Data_t);
HIDReportState.forcewrite=true;
HIDReportState.length = sizeof(HID_MediaReport_Data_t);
//HIDReportState.forcewrite = true;
break;
case HID_REPORTID_SystemReport:
HIDReportState.length=sizeof(HID_SystemReport_Data_t);
HIDReportState.forcewrite=true;
HIDReportState.length = sizeof(HID_SystemReport_Data_t);
//HIDReportState.forcewrite = true;
break;
case HID_REPORTID_Gamepad1Report:
case HID_REPORTID_Gamepad2Report:
HIDReportState.length=sizeof(HID_GamepadReport_Data_t);
HIDReportState.forcewrite=true;
HIDReportState.length = sizeof(HID_GamepadReport_Data_t);
//HIDReportState.forcewrite = true;
break;
case HID_REPORTID_Joystick1Report:
case HID_REPORTID_Joystick2Report:
HIDReportState.length=sizeof(HID_JoystickReport_Data_t);
HIDReportState.forcewrite=true;
HIDReportState.length = sizeof(HID_JoystickReport_Data_t);
//HIDReportState.forcewrite = true;
break;
// not supported yet <--
@ -328,7 +330,7 @@ void checkNHPProtocol(RingBuff_Data_t input){
//HID_Report_ForceWrite=false;
//break;
default :
default:
// error
checkNHPControlAddressError();
break;
@ -339,22 +341,22 @@ void checkNHPProtocol(RingBuff_Data_t input){
NHPreset();
} // end if control address byte
else if(HIDReportState.ID){
else if (HIDReportState.ID){
// check if the new Address is in correct order of HID reports.
// the first 2 bytes are sent with Address 2 and so on.
if(NHPgetAddress()==(((HIDReportState.recvlength+2)/2)+1)){
if (NHPgetAddress() == (((HIDReportState.recvlength + 2) / 2) + 1)){
// save the first byte
CurrentHIDReportBuffer[HIDReportState.recvlength++]=NHPgetChecksumData0();
HIDReportBuffer[HIDReportState.recvlength++] = NHPgetChecksumData0();
// if there is another byte we need (for odd max HID reports important
// to not write over the buff array)
if(HIDReportState.length!=HIDReportState.recvlength)
CurrentHIDReportBuffer[HIDReportState.recvlength++]=NHPgetChecksumData1();
if (HIDReportState.length != HIDReportState.recvlength)
HIDReportBuffer[HIDReportState.recvlength++] = NHPgetChecksumData1();
// we are ready to submit the new report to the usb host
if(HIDReportState.length==HIDReportState.recvlength){
if (HIDReportState.length == HIDReportState.recvlength){
// TODO timeout? <--
while(HIDReportState.ID)
while (HIDReportState.ID)
HID_Device_USBTask(&Device_HID_Interface);
}
// The Protocol received a valid signal with inverse checksum
@ -379,17 +381,19 @@ void checkNHPControlAddressError(void){
// only write if it was just before, maybe it was a random valid address
// but if we already received some data we handle this as corrupted data and just
// discard all the bytes
if(HIDReportState.recvlength==0){
if (HIDReportState.recvlength == 0){
// write the cached buffer (recreate protocol)
NHPwriteChecksum(NHP_ADDRESS_CONTROL, (NHP_USAGE_ARDUINOHID<<8) | HIDReportState.ID);
for(int i = 0; i< NHPwritelength; i++){
uint8_t buff[6];
uint8_t length = NHPwriteChecksum(NHP_ADDRESS_CONTROL, (NHP_USAGE_ARDUINOHID << 8) | HIDReportState.ID, buff);
for (int i = 0; i < length; i++){
bool CurrentDTRState = (VirtualSerial_CDC_Interface.State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR); //new <--
if(CurrentDTRState)
CDC_Device_SendByte(&VirtualSerial_CDC_Interface, NHPwritebuffer[i]);
if (CurrentDTRState)
CDC_Device_SendByte(&VirtualSerial_CDC_Interface, buff[i]);
}
}
// reset any pending HID reports
HIDReportState.ID=0;
HIDReportState.ID = 0;
HIDReportState.recvlength = 0; //just to be sure if you call HID_Task by accident
}
/** Event handler for the library USB Connection event. */
@ -436,10 +440,10 @@ void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCI
switch (CDCInterfaceInfo->State.LineEncoding.ParityType)
{
case CDC_PARITY_Odd:
ConfigMask = ((1 << UPM11) | (1 << UPM10));
ConfigMask = ((1 << UPM11) | (1 << UPM10));
break;
case CDC_PARITY_Even:
ConfigMask = (1 << UPM11);
ConfigMask = (1 << UPM11);
break;
}
@ -465,10 +469,10 @@ void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCI
UCSR1A = 0;
UCSR1C = 0;
/* Special case 57600 baud for compatibility with the ATmega328 bootloader. */
UBRR1 = (CDCInterfaceInfo->State.LineEncoding.BaudRateBPS == 57600)
/* Special case 57600 baud for compatibility with the ATmega328 bootloader. */
UBRR1 = (CDCInterfaceInfo->State.LineEncoding.BaudRateBPS == 57600)
? SERIAL_UBBRVAL(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)
: SERIAL_2X_UBBRVAL(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);
: SERIAL_2X_UBBRVAL(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);
UCSR1C = ConfigMask;
UCSR1A = (CDCInterfaceInfo->State.LineEncoding.BaudRateBPS == 57600) ? 0 : (1 << U2X1);
@ -528,17 +532,20 @@ void EVENT_USB_Device_StartOfFrame(void)
* \return Boolean \c true to force the sending of the report, \c false to let the library determine if it needs to be sent
*/
bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
uint8_t* const ReportID,
const uint8_t ReportType,
void* ReportData,
uint16_t* const ReportSize)
uint8_t* const ReportID,
const uint8_t ReportType,
void* ReportData,
uint16_t* const ReportSize)
{
//write report and reset ID
memcpy(ReportData, CurrentHIDReportBuffer, HIDReportState.length);
*ReportID = HIDReportState.ID;
memcpy(ReportData, HIDReportBuffer, HIDReportState.length);
*ReportID = HIDReportState.ID;
*ReportSize = HIDReportState.length;
HIDReportState.ID=0;
return HIDReportState.forcewrite;
HIDReportState.ID = 0;
HIDReportState.recvlength = 0; //just to be sure if you call HID_Task by accident
// always return true, because we cannot compare with >1 report due to ram limit
// this will forcewrite the report everytime
return true;
}
/** HID class driver callback function for the processing of HID reports from the host.
@ -550,10 +557,10 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
* \param[in] ReportSize Size in bytes of the received HID report
*/
void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo,
const uint8_t ReportID,
const uint8_t ReportType,
const void* ReportData,
const uint16_t ReportSize)
const uint8_t ReportID,
const uint8_t ReportType,
const void* ReportData,
const uint16_t ReportSize)
{
// Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports
// uint8_t* LEDReport = (uint8_t*)ReportData;

View file

@ -44,12 +44,12 @@
/* Defines: */
/** Size of each ring buffer, in data elements - must be between 1 and 255. */
#define BUFFER_SIZE (128-28) //reduced, needed some ram
#define BUFFER_SIZE (128-16) //reduced, needed some ram
/** Maximum number of data elements to buffer before forcing a flush.
* Must be less than BUFFER_SIZE
*/
#define BUFFER_NEARLY_FULL (96-28)
#define BUFFER_NEARLY_FULL (96-16)
/** Type of data to store into the buffer. */
#define RingBuff_Data_t uint8_t

View file

@ -27,54 +27,54 @@ THE SOFTWARE.
// Public variables
//================================================================================
uint8_t NHPreadbuffer[6]={0};
uint8_t NHPreadlength=0;
uint8_t NHPwritebuffer[6]={0};
uint8_t NHPwritelength=0;
uint8_t NHPreadbuffer[6] = { 0 };
uint8_t NHPreadlength = 0;
//uint8_t NHPwritebuffer[6] = { 0 };
//uint8_t NHPwritelength = 0;
//================================================================================
// Private variables
//================================================================================
// Fully read data
static uint8_t mCommand=0;
static uint8_t mAddress=0;
static uint32_t mData=0;
static uint8_t mErrorLevel=NHP_INPUT_RESET;
static uint8_t mCommand = 0;
static uint8_t mAddress = 0;
static uint32_t mData = 0;
static uint8_t mErrorLevel = NHP_INPUT_RESET;
// in progress reading data
static uint8_t mBlocks=0;
static uint32_t mWorkData=0;
static uint8_t mBlocks = 0;
static uint32_t mWorkData = 0;
//================================================================================
//General Functions
//================================================================================
// reset Protocol on the next reading to start a new clean reading
void NHPreset(void){ mErrorLevel=NHP_INPUT_RESET; }
void NHPreset(void){ mErrorLevel = NHP_INPUT_RESET; }
// access for the variables
uint8_t NHPgetCommand() { return mCommand; }
uint8_t NHPgetAddress() { return mAddress; }
uint32_t NHPgetData() { return mData; }
uint16_t NHPgetChecksumData() { return mData; }
uint8_t NHPgetChecksumData0() { return mData; }
uint8_t NHPgetChecksumData1() { return mData>>8;}
uint8_t NHPgetCommand() { return mCommand; }
uint8_t NHPgetAddress() { return mAddress; }
uint32_t NHPgetData() { return mData; }
uint16_t NHPgetChecksumData() { return mData; }
uint8_t NHPgetChecksumData0() { return mData; }
uint8_t NHPgetChecksumData1() { return mData >> 8; }
uint8_t NHPgetErrorLevel(){ return mErrorLevel; }
// reset buffer for read/write operations
void NHPresetreadbuffer() {
while(NHPreadlength){
void NHPresetreadbuffer() {
while (NHPreadlength){
NHPreadlength--;
NHPreadbuffer[NHPreadlength]=0;
}
}
void NHPresetwritebuffer(){
while(NHPwritelength){
NHPwritelength--;
NHPwritebuffer[NHPwritelength]=0;
NHPreadbuffer[NHPreadlength] = 0;
}
}
//void NHPresetwritebuffer(){
// while (NHPwritelength){
// NHPwritelength--;
// NHPwritebuffer[NHPwritelength] = 0;
// }
//}
//================================================================================
//Read
@ -82,110 +82,110 @@ void NHPresetwritebuffer(){
bool NHPread(uint8_t input){
//reset if previous read was with an input/error
if(mErrorLevel){
if (mErrorLevel){
// cancel any pending data reads if a reset was triggered
if(mErrorLevel & NHP_INPUT_RESET){
mBlocks=0;
mWorkData=0;
if (mErrorLevel & NHP_INPUT_RESET){
mBlocks = 0;
mWorkData = 0;
}
// if previous read was a lead error keep this byte
if(mErrorLevel&NHP_ERR_LEAD){
NHPreadbuffer[0]=NHPreadbuffer[NHPreadlength];
NHPreadlength=1;
if (mErrorLevel&NHP_ERR_LEAD){
NHPreadbuffer[0] = NHPreadbuffer[NHPreadlength];
NHPreadlength = 1;
}
else NHPreadlength=0;
else NHPreadlength = 0;
}
// reset fully read data
mCommand=0;
mAddress=0;
mData=0;
mErrorLevel=0;
mCommand = 0;
mAddress = 0;
mData = 0;
mErrorLevel = 0;
//write input to the buffer
NHPreadbuffer[NHPreadlength]=input;
NHPreadbuffer[NHPreadlength] = input;
NHPreadlength++;
// check the lead/end/data indicator
switch(input&NHP_MASK_START){
switch (input&NHP_MASK_START){
case(NHP_MASK_LEAD):
{
// we were still reading! Log an error
if(mBlocks){
mErrorLevel |= NHP_ERR_LEAD | NHP_ERR_READ;
NHPreadlength--;
}
// read command indicator or block length
mBlocks = (input & NHP_MASK_LENGTH)>>3;
switch(mBlocks){
case 0:
case 1:
// save 4 bit command
mCommand=(input & NHP_MASK_COMMAND)+1;
mBlocks = 0;
mErrorLevel |= NHP_INPUT_COMMAND | NHP_INPUT_NEW;
return true;
break;
case 7:
// save block length + first 4 data bits (special case)
mWorkData = input & NHP_MASK_DATA_4BIT;
mBlocks -=2;
break;
default:
// save block length + first 3 data bits
mWorkData = input & NHP_MASK_DATA_3BIT;
mBlocks--;
break;
}
case(NHP_MASK_LEAD) :
{
// we were still reading! Log an error
if (mBlocks){
mErrorLevel |= NHP_ERR_LEAD | NHP_ERR_READ;
NHPreadlength--;
}
break;
case(NHP_MASK_END):
{
if(mBlocks--==1){
// save data + address
mAddress=(input&0x3F)+1;
mData=mWorkData;
mErrorLevel |= NHP_INPUT_ADDRESS | NHP_INPUT_NEW;
return true;
}
else{
// log an error, not ready for an address byte, and reset data counters
mErrorLevel |= NHP_ERR_DATA | NHP_ERR_READ;
mBlocks=0;
}
// read command indicator or block length
mBlocks = (input & NHP_MASK_LENGTH) >> 3;
switch (mBlocks){
case 0:
case 1:
// save 4 bit command
mCommand = (input & NHP_MASK_COMMAND) + 1;
mBlocks = 0;
mErrorLevel |= NHP_INPUT_COMMAND | NHP_INPUT_NEW;
return true;
break;
case 7:
// save block length + first 4 data bits (special case)
mWorkData = input & NHP_MASK_DATA_4BIT;
mBlocks -= 2;
break;
default:
// save block length + first 3 data bits
mWorkData = input & NHP_MASK_DATA_3BIT;
mBlocks--;
break;
}
break;
}
break;
//case NHP_MASK_DATA1/2?? <--
case(NHP_MASK_END) :
{
if (mBlocks-- == 1){
// save data + address
mAddress = (input & 0x3F) + 1;
mData = mWorkData;
mErrorLevel |= NHP_INPUT_ADDRESS | NHP_INPUT_NEW;
return true;
}
else{
// log an error, not ready for an address byte, and reset data counters
mErrorLevel |= NHP_ERR_DATA | NHP_ERR_READ;
mBlocks = 0;
}
}
break;
//case NHP_MASK_DATA1/2?? <--
default: //NHP_MASK_DATA1/2
{
if(mBlocks--<2){
// log an error, expecting an address or header byte
mErrorLevel |= NHP_ERR_END | NHP_ERR_READ;
mBlocks=0;
}
else{
// get next 7 bits of data
mWorkData<<=7;
// dont need &NHP_MASK_DATA_7BIT because first bit is zero!
mWorkData|=input;
}
}
{
if (mBlocks-- < 2){
// log an error, expecting an address or header byte
mErrorLevel |= NHP_ERR_END | NHP_ERR_READ;
mBlocks = 0;
}
else{
// get next 7 bits of data
mWorkData <<= 7;
// dont need &NHP_MASK_DATA_7BIT because first bit is zero!
mWorkData |= input;
}
}
break;
} // end switch
// no new input
return false;
return false;
}
// reads two bytes and check its inverse
bool NHPreadChecksum(uint8_t input){
if(NHPread(input)){
if (NHPread(input)){
// if there is an address input (comand invalid, too insecure)
if(NHPgetAddress() && (((NHPgetData()&0xFFFF) ^ (NHPgetData()>>16))==0xFFFF)){
if (NHPgetAddress() && (((NHPgetData() & 0xFFFF) ^ (NHPgetData() >> 16)) == 0xFFFF)){
// make sure to use getAddress() and getData()&0xFFFF
return true;
}
@ -198,57 +198,60 @@ bool NHPreadChecksum(uint8_t input){
//Write
//================================================================================
void NHPwriteCommand(uint8_t command){
uint8_t NHPwriteCommand(uint8_t command){
// send lead mask 11 + length 00|0 or 00|1 including the last bit for the 4 bit command
NHPwritebuffer[0] = NHP_MASK_LEAD | ((command-1) & NHP_MASK_COMMAND);
NHPwritelength=1;
// return the Command itself
return NHP_MASK_LEAD | ((command - 1) & NHP_MASK_COMMAND);
}
void NHPwriteAddress(uint8_t address, uint32_t data){
uint8_t NHPwriteAddress(uint8_t address, uint32_t data, uint8_t* buff){
// start with the maximum size of blocks
uint8_t blocks=7;
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){
while (blocks > 2){
uint8_t nextvalue = (data >> (7 * (blocks - 3)));
if (nextvalue > NHP_MASK_DATA_3BIT){
// special case for the MSB
if(blocks==7) {
NHPwritebuffer[0] = nextvalue;
if (blocks == 7) {
buff[0] = nextvalue;
blocks--;
}
break;
}
else{
// write the possible first 3 bits and check again after
NHPwritebuffer[0] = nextvalue;
// write the possible first 3 bits and check again after if zero
buff[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){
NHPwritebuffer[datablocks] = data & NHP_MASK_DATA_7BIT;
data>>=7;
uint8_t datablocks = blocks - 2;
while (datablocks > 0){
buff[datablocks] = data & NHP_MASK_DATA_7BIT;
data >>= 7;
datablocks--;
}
// write lead + length mask
NHPwritebuffer[0] |= NHP_MASK_LEAD | (blocks <<3);
buff[0] |= NHP_MASK_LEAD | (blocks << 3);
// write end mask
NHPwritebuffer[blocks-1] = NHP_MASK_END | ((address-1) & NHP_MASK_ADDRESS);
buff[blocks - 1] = NHP_MASK_END | ((address - 1) & NHP_MASK_ADDRESS);
// save the length
NHPwritelength=blocks;
// return the length
return blocks;
}
// writes two bytes with its inverse
void NHPwriteChecksum(uint8_t address, uint16_t data){
uint32_t temp=~data;
uint32_t checksum=(temp<<16)|data;
NHPwriteAddress(address,checksum);
uint8_t NHPwriteChecksum(uint8_t address, uint16_t data, uint8_t* buff){
uint32_t temp = ~data;
uint32_t checksum = (temp << 16) | data;
return NHPwriteAddress(address, checksum, buff);
}

View file

@ -88,17 +88,18 @@ uint8_t NHPgetErrorLevel(void);
// buffer for read/write operations
extern uint8_t NHPreadbuffer[6];
extern uint8_t NHPreadlength;
extern uint8_t NHPwritebuffer[6];
extern uint8_t NHPwritelength;
//extern uint8_t NHPwritebuffer[6];
//extern uint8_t NHPwritelength;
void NHPresetreadbuffer(void);
void NHPresetwritebuffer(void);
//void NHPresetwritebuffer(void);
// general multifunctional read/write functions
void NHPreset(void);
bool NHPread(uint8_t input);
bool NHPreadChecksum(uint8_t input);
void NHPwriteCommand(uint8_t command);
void NHPwriteAddress(uint8_t address, uint32_t data);
void NHPwriteChecksum(uint8_t address, uint16_t data);
uint8_t NHPwriteCommand(uint8_t command); // returns the command
// returns the length, writes data to the passed in buff (6 bytes max)
uint8_t NHPwriteAddress(uint8_t address, uint32_t data, uint8_t* buff);
uint8_t NHPwriteChecksum(uint8_t address, uint16_t data, uint8_t* buff);
#endif

View file

@ -0,0 +1,257 @@
/*
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 "NicoHoodProtocol_c.h"
//================================================================================
// Public variables
//================================================================================
uint8_t NHPreadbuffer[6] = { 0 };
uint8_t NHPreadlength = 0;
uint8_t NHPwritebuffer[6] = { 0 };
uint8_t NHPwritelength = 0;
//================================================================================
// Private variables
//================================================================================
// Fully read data
static uint8_t mCommand = 0;
static uint8_t mAddress = 0;
static uint32_t mData = 0;
static uint8_t mErrorLevel = NHP_INPUT_RESET;
// in progress reading data
static uint8_t mBlocks = 0;
static uint32_t mWorkData = 0;
//================================================================================
//General Functions
//================================================================================
// reset Protocol on the next reading to start a new clean reading
void NHPreset(void){ mErrorLevel = NHP_INPUT_RESET; }
// access for the variables
uint8_t NHPgetCommand() { return mCommand; }
uint8_t NHPgetAddress() { return mAddress; }
uint32_t NHPgetData() { return mData; }
uint16_t NHPgetChecksumData() { return mData; }
uint8_t NHPgetChecksumData0() { return mData; }
uint8_t NHPgetChecksumData1() { return mData >> 8; }
uint8_t NHPgetErrorLevel(){ return mErrorLevel; }
// reset buffer for read/write operations
void NHPresetreadbuffer() {
while (NHPreadlength){
NHPreadlength--;
NHPreadbuffer[NHPreadlength] = 0;
}
}
void NHPresetwritebuffer(){
while (NHPwritelength){
NHPwritelength--;
NHPwritebuffer[NHPwritelength] = 0;
}
}
//================================================================================
//Read
//================================================================================
bool NHPread(uint8_t input){
//reset if previous read was with an input/error
if (mErrorLevel){
// cancel any pending data reads if a reset was triggered
if (mErrorLevel & NHP_INPUT_RESET){
mBlocks = 0;
mWorkData = 0;
}
// if previous read was a lead error keep this byte
if (mErrorLevel&NHP_ERR_LEAD){
NHPreadbuffer[0] = NHPreadbuffer[NHPreadlength];
NHPreadlength = 1;
}
else NHPreadlength = 0;
}
// reset fully read data
mCommand = 0;
mAddress = 0;
mData = 0;
mErrorLevel = 0;
//write input to the buffer
NHPreadbuffer[NHPreadlength] = input;
NHPreadlength++;
// check the lead/end/data indicator
switch (input&NHP_MASK_START){
case(NHP_MASK_LEAD) :
{
// we were still reading! Log an error
if (mBlocks){
mErrorLevel |= NHP_ERR_LEAD | NHP_ERR_READ;
NHPreadlength--;
}
// read command indicator or block length
mBlocks = (input & NHP_MASK_LENGTH) >> 3;
switch (mBlocks){
case 0:
case 1:
// save 4 bit command
mCommand = (input & NHP_MASK_COMMAND) + 1;
mBlocks = 0;
mErrorLevel |= NHP_INPUT_COMMAND | NHP_INPUT_NEW;
return true;
break;
case 7:
// save block length + first 4 data bits (special case)
mWorkData = input & NHP_MASK_DATA_4BIT;
mBlocks -= 2;
break;
default:
// save block length + first 3 data bits
mWorkData = input & NHP_MASK_DATA_3BIT;
mBlocks--;
break;
}
}
break;
case(NHP_MASK_END) :
{
if (mBlocks-- == 1){
// save data + address
mAddress = (input & 0x3F) + 1;
mData = mWorkData;
mErrorLevel |= NHP_INPUT_ADDRESS | NHP_INPUT_NEW;
return true;
}
else{
// log an error, not ready for an address byte, and reset data counters
mErrorLevel |= NHP_ERR_DATA | NHP_ERR_READ;
mBlocks = 0;
}
}
break;
//case NHP_MASK_DATA1/2?? <--
default: //NHP_MASK_DATA1/2
{
if (mBlocks-- < 2){
// log an error, expecting an address or header byte
mErrorLevel |= NHP_ERR_END | NHP_ERR_READ;
mBlocks = 0;
}
else{
// get next 7 bits of data
mWorkData <<= 7;
// dont need &NHP_MASK_DATA_7BIT because first bit is zero!
mWorkData |= input;
}
}
break;
} // end switch
// no new input
return false;
}
// reads two bytes and check its inverse
bool NHPreadChecksum(uint8_t input){
if (NHPread(input)){
// if there is an address input (comand invalid, too insecure)
if (NHPgetAddress() && (((NHPgetData() & 0xFFFF) ^ (NHPgetData() >> 16)) == 0xFFFF)){
// make sure to use getAddress() and getData()&0xFFFF
return true;
}
// else you can forward the buffer or pass -1 as error
}
return false;
}
//================================================================================
//Write
//================================================================================
void NHPwriteCommand(uint8_t command){
// send lead mask 11 + length 00|0 or 00|1 including the last bit for the 4 bit command
NHPwritebuffer[0] = NHP_MASK_LEAD | ((command - 1) & NHP_MASK_COMMAND);
NHPwritelength = 1;
}
void NHPwriteAddress(uint8_t address, uint32_t data){
// 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) {
NHPwritebuffer[0] = nextvalue;
blocks--;
}
break;
}
else{
// write the possible first 3 bits and check again after if zero
NHPwritebuffer[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){
NHPwritebuffer[datablocks] = data & NHP_MASK_DATA_7BIT;
data >>= 7;
datablocks--;
}
// write lead + length mask
NHPwritebuffer[0] |= NHP_MASK_LEAD | (blocks << 3);
// write end mask
NHPwritebuffer[blocks - 1] = NHP_MASK_END | ((address - 1) & NHP_MASK_ADDRESS);
// save the length
NHPwritelength = blocks;
}
// writes two bytes with its inverse
void NHPwriteChecksum(uint8_t address, uint16_t data){
uint32_t temp = ~data;
uint32_t checksum = (temp << 16) | data;
NHPwriteAddress(address, checksum);
}

View file

@ -0,0 +1,104 @@
/*
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 NICOHOODPROTOCOL_C_h
#define NICOHOODPROTOCOL_C_h
#include <stdint.h> //uint_t definitions
#include <stdbool.h> //bool type
//================================================================================
//Settings
//================================================================================
// empty
//================================================================================
//Definitions
//================================================================================
// ErrorLevel
#define NHP_MASK_INPUT 0x0F
#define NHP_INPUT_NO 0x00
#define NHP_INPUT_NEW 0x01
#define NHP_INPUT_ADDRESS 0x02
#define NHP_INPUT_COMMAND 0x04
#define NHP_INPUT_RESET 0x08
#define NHP_MASK_ERR 0xF0
#define NHP_ERR_NO 0x00
#define NHP_ERR_READ 0x10
#define NHP_ERR_END 0x20
#define NHP_ERR_DATA 0x40
#define NHP_ERR_LEAD 0x80
#define NHP_ERR_LIMIT 20 //0-255, only for the user function
// 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
//================================================================================
//Protocol Function Prototypes
//================================================================================
// access for the variables
uint8_t NHPgetCommand(void);
uint8_t NHPgetAddress(void);
uint32_t NHPgetData(void);
uint16_t NHPgetChecksumData(void);
uint8_t NHPgetChecksumData0(void);
uint8_t NHPgetChecksumData1(void);
uint8_t NHPgetErrorLevel(void);
// buffer for read/write operations
extern uint8_t NHPreadbuffer[6];
extern uint8_t NHPreadlength;
extern uint8_t NHPwritebuffer[6];
extern uint8_t NHPwritelength;
void NHPresetreadbuffer(void);
void NHPresetwritebuffer(void);
// general multifunctional read/write functions
void NHPreset(void);
bool NHPread(uint8_t input);
bool NHPreadChecksum(uint8_t input);
void NHPwriteCommand(uint8_t command);
void NHPwriteAddress(uint8_t address, uint32_t data);
void NHPwriteChecksum(uint8_t address, uint16_t data);
#endif

View file

@ -17,4 +17,4 @@ Projects/*
Maintenance/*
BuildTests/*
Bootloaders/*
Documentation/*

View file

@ -19,8 +19,8 @@ MCU_DFU = atmega8u2
F_CPU = 16000000
BOARD = USER
#Vendor ID from lufa
#Product ID created my own
#Vendor ID from lufa 0x03EB
#Product ID created my own 0x4E68
ARDUNIOHID_OPTS = -DHOODLOADER_VID=0x03EB
ARDUNIOHID_OPTS += -DHOODLOADER_PID=0x4E68
#You can also use the native Arduino VID and PID
@ -28,6 +28,7 @@ ARDUNIOHID_OPTS += -DHOODLOADER_PID=0x4E68
#ProductID Arduino Uno 0x0001
#ProductID Arduino Mega 0x0010
ARCH = AVR8
F_USB = $(F_CPU)
OPTIMIZATION = s

View file

@ -1,4 +1,4 @@
Arduino HID Project BETA 1.2
Arduino HID Project BETA 1.3
===================
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?
@ -21,7 +21,8 @@ Software includes:
* Arduino HID Uno/Mega library
* Arduino HID Micro/Leonardo library
* Arduino HID Bootloader (Hoodloader)
* Arduino HID Bootloader (Hoodloader) + driver
*Compatible with Linux/Mac/Windows XP/7/8.1*
The following devices are supported:
@ -33,11 +34,13 @@ The following devices are supported:
* 2 Joysticks (2 buttons, 2 10bit axis)
Projects can be found here:
http://nicohood.wordpress.com/
* [Gamecube to PC adapter](https://github.com/NicoHood/Nintendo)
* [Other projects](http://nicohood.wordpress.com/)
Installation Leonardo/Micro/Uno/Mega
====================================
Download the library and **move and replace** all 4 .h/cpp files from the download folder to:
Download the library and install like you are used to.
Then **move and replace** all files from the folder that matches your Arduino IDE version to one of these paths:
```
C:\Arduino\arduino-1.0.5-r2\hardware\arduino\cores\arduino
C:\Arduino\arduino-1.5.6-r2\hardware\arduino\avr\cores\arduino
@ -127,38 +130,47 @@ Todo
====
* Remove debug stuff (shouldnt effect anything for you)
* Add more devices (even more?)
* Add ICSP Programmer function
* Add Midi (do you want that?)
* Add ICSP Programmer function (ram limit is a problem)
* Add Led/SPI support (discarded, not needed, too slow)
* Add rumble support (very hard)
* Add Xbox Support (too hard)
* Add Midi (do you want that?)
* Add Report Out function (for Keyboard Leds etc, maybe the 4 pin header?)
* RAW HID
Known Bugs
==========
XBMC 13.1 (a Media Center) uses Gamepad input. Its seems to not work and cause weird errors.
Even with a standard Gamepad i have these errors. Just want to mention it here.
System Wakeup is currently not working on all versions!
Not tested on the 8u2 (message me if it works!)
Not tested on the 8u2 (should only work without DFU due to size. message me if it works!)
Not tested on the Due (message me if it works!)
If you get a checksum Error after Uploading please message me and send me the whole project.
Same if your Arduino crashes and dont want to upload sketches anymore (Replug usb fixes this).
These bugs occured while devoloping the bootloader and should be fixed. Just in case it happens again I noted it here.
USB can behave weird, so please check your code for errors first. If you cannot find a mistake open a Github issue.
HID only works with baud 115200 because there is no "programming finished" indicator. If you dont use HID you can still choose the baud of your choice
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.
Oh and by the way: I also removed some bugs from the official firmware.
Version History
===============
```
1.2 Beta Release (xx.06.2014)
1.3 Beta Release (01.07.2014)
* Bugfixes in the Hoodloader:
* Improved ram usage
* **Important NHP fix inside the HID Class**
1.2 Beta Release (22.06.2014)
* Added 1.0.x/1.5.x support
* Bugfixes in the Hoodloader:
* Sometimes HID Devices weren't updating when using more than 1 Device (set forcewrite to true)
* Fast updates crashed the bootloader (ram usage was too much, set CDC buffer from 128 to 100 byte each)
* Sometimes HID Devices weren't updating when using more than 1 Device (set forcewrite to true)
* Fast updates crashed the bootloader (too much ram usage, set CDC buffer from 128b to 100b each)
* Minor file structure changes
1.1 Beta Release (05.06.2014)

View file

@ -1 +1 @@
See http://nicohood.wordpress.com/ for tutorials
See http://nicohood.wordpress.com/ for tutorials and projects