|
|
|
@ -1,58 +1,53 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "main.h" |
|
|
|
#include "main.h" |
|
|
|
|
|
|
|
|
|
|
|
static uint8_t reportBuffer[64]; |
|
|
|
#define DEBUG |
|
|
|
|
|
|
|
|
|
|
|
const PROGMEM char usbHidReportDescriptor[35] = { /* USB report descriptor */ |
|
|
|
#ifdef DEBUG |
|
|
|
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
|
|
|
void tx( char data ){ |
|
|
|
0x09, 0x06, // USAGE (Keyboard)
|
|
|
|
while ( !( UCSR0A & (1<<UDRE0)) ); |
|
|
|
0xa1, 0x01, // COLLECTION (Application)
|
|
|
|
UDR0 = data; |
|
|
|
0x05, 0x07, // USAGE_PAGE (Keyboard)
|
|
|
|
} |
|
|
|
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
|
|
|
|
|
|
|
|
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
|
|
|
|
void sendstr( char* str){ |
|
|
|
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
|
|
|
while(str[0]!=0){ |
|
|
|
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
|
|
|
tx(str[0]); |
|
|
|
0x75, 0x01, // REPORT_SIZE (1)
|
|
|
|
str++; |
|
|
|
0x95, 0x08, // REPORT_COUNT (8)
|
|
|
|
|
|
|
|
0x81, 0x02, // INPUT (Data,Var,Abs)
|
|
|
|
|
|
|
|
0x95, 0x01, // REPORT_COUNT (1)
|
|
|
|
|
|
|
|
0x75, 0x08, // REPORT_SIZE (8)
|
|
|
|
|
|
|
|
0x25, 0x65, // LOGICAL_MAXIMUM (101)
|
|
|
|
|
|
|
|
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
|
|
|
|
|
|
|
|
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
|
|
|
|
|
|
|
|
0x81, 0x00, // INPUT (Data,Ary,Abs)
|
|
|
|
|
|
|
|
0xc0 // END_COLLECTION
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
usbMsgLen_t usbFunctionSetup(uchar data[8]) { |
|
|
|
|
|
|
|
usbRequest_t *rq = (void *)data; |
|
|
|
|
|
|
|
usbMsgPtr = reportBuffer; |
|
|
|
|
|
|
|
if((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS) { /* HID class request */ |
|
|
|
|
|
|
|
if(rq->bRequest == USBRQ_HID_GET_REPORT) { /* wValue: ReportType (highbyte), ReportID (lowbyte) */ |
|
|
|
|
|
|
|
/* since we have only one report type, we can ignore the report-ID */ |
|
|
|
|
|
|
|
//buildReport();
|
|
|
|
|
|
|
|
return sizeof(reportBuffer);
|
|
|
|
|
|
|
|
}/*else if(rq->bRequest == USBRQ_HID_GET_IDLE){
|
|
|
|
|
|
|
|
usbMsgPtr = &idleRate; |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
}else if(rq->bRequest == USBRQ_HID_SET_IDLE){ |
|
|
|
|
|
|
|
idleRate = rq->wValue.bytes[1]; |
|
|
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
/* ignore vendor type requests, we don't use any */ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void sendunum(uint32_t num){ |
|
|
|
|
|
|
|
char text[11] = {0,0,0,0,0,0,0,0,0,0,0}; |
|
|
|
|
|
|
|
uint32_t tmp=1; |
|
|
|
|
|
|
|
char leadingzero=0; |
|
|
|
|
|
|
|
char digit=0; |
|
|
|
|
|
|
|
char i; |
|
|
|
|
|
|
|
if(num==0){ |
|
|
|
|
|
|
|
tx('0'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for(i=1;i<=10;i++){ |
|
|
|
|
|
|
|
digit = '0'+((num/tmp)%10); |
|
|
|
|
|
|
|
tmp*=10; |
|
|
|
|
|
|
|
if(digit=='0'){ |
|
|
|
|
|
|
|
leadingzero++;
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
leadingzero=0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
text[10-i]=digit; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
sendstr( text+leadingzero ); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char rx( void ){ |
|
|
|
|
|
|
|
while ( !(UCSR0A & (1<<RXC0)) ); |
|
|
|
|
|
|
|
return UDR0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif //DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
int main(void) __attribute__((noreturn)); |
|
|
|
int main(void) __attribute__((noreturn)); |
|
|
|
int __attribute__((OS_main)) main(void) { |
|
|
|
int __attribute__((OS_main)) main(void) { |
|
|
|
usbDeviceDisconnect(); |
|
|
|
sendstr("Hello"); |
|
|
|
_delay_ms(200); |
|
|
|
|
|
|
|
usbDeviceConnect(); |
|
|
|
|
|
|
|
usbInit();
|
|
|
|
|
|
|
|
//printf("OTP: %d\n", get_otp_from_cnt(7,6) );
|
|
|
|
|
|
|
|
for(;;){ |
|
|
|
for(;;){ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|