X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/864196c884ef3602aee44f1a68aceb5819a07f21..0fdc1a2bc66f97048b94b967e80cd294189fca62:/Projects/Magstripe/Magstripe.c?ds=inline diff --git a/Projects/Magstripe/Magstripe.c b/Projects/Magstripe/Magstripe.c index aaa432d20..3ea505296 100644 --- a/Projects/Magstripe/Magstripe.c +++ b/Projects/Magstripe/Magstripe.c @@ -45,6 +45,9 @@ BitBuffer_t TrackDataBuffers[TOTAL_TRACKS]; /** Pointer to the current track buffer being sent to the host. */ BitBuffer_t* CurrentTrackBuffer = &TrackDataBuffers[TOTAL_TRACKS]; +/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */ +uint8_t PrevKeyboardHIDReportBuffer[sizeof(USB_KeyboardReport_Data_t)]; + /** LUFA HID Class driver interface configuration and state information. This structure is * passed to all HID Class driver functions, so that multiple instances of the same class * within a device can be differentiated from one another. @@ -57,8 +60,9 @@ USB_ClassInfo_HID_Device_t Keyboard_HID_Interface = .ReportINEndpointNumber = KEYBOARD_EPNUM, .ReportINEndpointSize = KEYBOARD_EPSIZE, - - .ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t), + + .PrevReportINBuffer = PrevKeyboardHIDReportBuffer, + .PrevReportINBufferSize = sizeof(PrevKeyboardHIDReportBuffer), }, }; @@ -95,12 +99,6 @@ void SetupHardware(void) /* Hardware Initialization */ Magstripe_Init(); USB_Init(); - - /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */ - OCR0A = ((F_CPU / 64) / 1000); - TCCR0A = (1 << WGM01); - TCCR0B = ((1 << CS01) | (1 << CS00)); - TIMSK0 = (1 << OCIE0A); } /** Determines if a card has been inserted, and if so reads in each track's contents into the bit buffers @@ -141,33 +139,36 @@ void ReadMagstripeData(void) } /** Event handler for the library USB Configuration Changed event. */ -void EVENT_USB_ConfigurationChanged(void) +void EVENT_USB_Device_ConfigurationChanged(void) { HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface); + + USB_Device_EnableSOFEvents(); } /** Event handler for the library USB Unhandled Control Packet event. */ -void EVENT_USB_UnhandledControlPacket(void) +void EVENT_USB_Device_UnhandledControlRequest(void) { - HID_Device_ProcessControlPacket(&Keyboard_HID_Interface); + HID_Device_ProcessControlRequest(&Keyboard_HID_Interface); } -/** Timer 0 CTC ISR, firing once each millisecond to keep track of elapsed idle time in the HID interface. */ -ISR(TIMER0_COMPA_vect, ISR_BLOCK) +/** Event handler for the USB device Start Of Frame event. */ +void EVENT_USB_Device_StartOfFrame(void) { - if (Keyboard_HID_Interface.State.IdleMSRemaining) - Keyboard_HID_Interface.State.IdleMSRemaining--; + HID_Device_MillisecondElapsed(&Keyboard_HID_Interface); } -/** HID Class driver callback function for the creation of a HID report for the host. +/** HID class driver callback function for the creation of HID reports to the host. * - * \param[in] HIDInterfaceInfo Pointer to the HID interface structure for the HID interface being referenced - * \param[in,out] ReportID Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID - * \param[out] ReportData Pointer to the preallocated report buffer where the created report should be stored + * \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced + * \param[in,out] ReportID Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID + * \param[out] ReportData Pointer to a buffer where the created report should be stored + * \param[out] ReportSize Number of bytes written in the report (or zero if no report is to be sent * - * \return Number of bytes in the created report + * \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent */ -uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, void* ReportData) +bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, + void* ReportData, uint16_t* ReportSize) { USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData; @@ -193,7 +194,8 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const H KeyboardReport->KeyCode = BitBuffer_GetNextBit(CurrentTrackBuffer) ? KEY_1 : KEY_0; } - return sizeof(USB_KeyboardReport_Data_t); + *ReportSize = sizeof(USB_KeyboardReport_Data_t); + return false; } /** HID Class driver callback function for the processing of a received HID report from the host.