X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/864196c884ef3602aee44f1a68aceb5819a07f21..7602566a05616e55a943422c783e072b49cadb1d:/Projects/Magstripe/Magstripe.c diff --git a/Projects/Magstripe/Magstripe.c b/Projects/Magstripe/Magstripe.c index aaa432d20..88950cc21 100644 --- a/Projects/Magstripe/Magstripe.c +++ b/Projects/Magstripe/Magstripe.c @@ -1,22 +1,22 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Denver Gingerich (denver [at] ossguy [dot] com) - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com) + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -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. @@ -53,12 +56,14 @@ USB_ClassInfo_HID_Device_t Keyboard_HID_Interface = { .Config = { - .InterfaceNumber = 0, + .InterfaceNumber = 0, + + .ReportINEndpointNumber = KEYBOARD_EPNUM, + .ReportINEndpointSize = KEYBOARD_EPSIZE, + .ReportINEndpointDoubleBank = KEYBOARD_EPSIZE, - .ReportINEndpointNumber = KEYBOARD_EPNUM, - .ReportINEndpointSize = KEYBOARD_EPSIZE, - - .ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t), + .PrevReportINBuffer = PrevKeyboardHIDReportBuffer, + .PrevReportINBufferSize = sizeof(PrevKeyboardHIDReportBuffer), }, }; @@ -95,12 +100,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 +140,37 @@ 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[in] ReportType Type of the report to create, either REPORT_ITEM_TYPE_In or REPORT_ITEM_TYPE_Feature + * \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, + const uint8_t ReportType, void* ReportData, uint16_t* ReportSize) { USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData; @@ -179,21 +182,22 @@ uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const H if ((IsKeyReleaseReport) || (CurrentTrackBuffer == &TrackDataBuffers[TOTAL_TRACKS])) { /* No more data to send, or key release report between key presses */ - KeyboardReport->KeyCode = KEY_NONE; + KeyboardReport->KeyCode[0] = KEY_NONE; } else if (!(CurrentTrackBuffer->Elements)) { /* End of current track, send an enter press and change to the next track's buffer */ - KeyboardReport->KeyCode = KEY_ENTER; + KeyboardReport->KeyCode[0] = KEY_ENTER; CurrentTrackBuffer++; } else { /* Still data in the current track; convert next bit to a 1 or 0 keypress */ - KeyboardReport->KeyCode = BitBuffer_GetNextBit(CurrentTrackBuffer) ? KEY_1 : KEY_0; + KeyboardReport->KeyCode[0] = 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.