Fixed SerialStream driver not setting stdin to the created serial stream.
[pub/USBasp.git] / Projects / Magstripe / Magstripe.c
index f0fd8a7..88950cc 100644 (file)
@@ -1,22 +1,22 @@
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Denver Gingerich (denver [at] ossguy [dot] com)\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
-\r
-  Permission to use, copy, modify, and distribute this software\r
-  and its documentation for any purpose and without fee is hereby\r
-  granted, provided that the above copyright notice appear in all\r
-  copies and that both that the copyright notice and this\r
-  permission notice and warranty disclaimer appear in supporting\r
-  documentation, and that the name of the author not be used in\r
-  advertising or publicity pertaining to distribution of the\r
+  Copyright 2010  Denver Gingerich (denver [at] ossguy [dot] com)\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+  Permission to use, copy, modify, distribute, and sell this \r
+  software and its documentation for any purpose is hereby granted\r
+  without fee, provided that the above copyright notice appear in \r
+  all copies and that both that the copyright notice and this\r
+  permission notice and warranty disclaimer appear in supporting \r
+  documentation, and that the name of the author not be used in \r
+  advertising or publicity pertaining to distribution of the \r
   software without specific, written prior permission.\r
 \r
   The author disclaim all warranties with regard to this\r
@@ -56,13 +56,14 @@ USB_ClassInfo_HID_Device_t Keyboard_HID_Interface =
        {\r
                .Config =\r
                        {\r
-                               .InterfaceNumber         = 0,\r
+                               .InterfaceNumber            = 0,\r
 \r
-                               .ReportINEndpointNumber  = KEYBOARD_EPNUM,\r
-                               .ReportINEndpointSize    = KEYBOARD_EPSIZE,\r
+                               .ReportINEndpointNumber     = KEYBOARD_EPNUM,\r
+                               .ReportINEndpointSize       = KEYBOARD_EPSIZE,\r
+                               .ReportINEndpointDoubleBank = KEYBOARD_EPSIZE,\r
 \r
-                               .PrevReportINBuffer      = PrevKeyboardHIDReportBuffer,\r
-                               .PrevReportINBufferSize  = sizeof(PrevKeyboardHIDReportBuffer),\r
+                               .PrevReportINBuffer         = PrevKeyboardHIDReportBuffer,\r
+                               .PrevReportINBufferSize     = sizeof(PrevKeyboardHIDReportBuffer),\r
                        },\r
        };\r
 \r
@@ -99,12 +100,6 @@ void SetupHardware(void)
        /* Hardware Initialization */\r
        Magstripe_Init();\r
        USB_Init();\r
-\r
-       /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */\r
-       OCR0A  = ((F_CPU / 64) / 1000);\r
-       TCCR0A = (1 << WGM01);\r
-       TCCR0B = ((1 << CS01) | (1 << CS00));\r
-       TIMSK0 = (1 << OCIE0A);\r
 }\r
 \r
 /** Determines if a card has been inserted, and if so reads in each track's contents into the bit buffers\r
@@ -145,19 +140,21 @@ void ReadMagstripeData(void)
 }\r
 \r
 /** Event handler for the library USB Configuration Changed event. */\r
-void EVENT_USB_ConfigurationChanged(void)\r
+void EVENT_USB_Device_ConfigurationChanged(void)\r
 {\r
        HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface);\r
+       \r
+       USB_Device_EnableSOFEvents();\r
 }\r
 \r
 /** Event handler for the library USB Unhandled Control Packet event. */\r
-void EVENT_USB_UnhandledControlPacket(void)\r
+void EVENT_USB_Device_UnhandledControlRequest(void)\r
 {\r
-       HID_Device_ProcessControlPacket(&Keyboard_HID_Interface);\r
+       HID_Device_ProcessControlRequest(&Keyboard_HID_Interface);\r
 }\r
 \r
-/** Timer 0 CTC ISR, firing once each millisecond to keep track of elapsed idle time in the HID interface. */\r
-ISR(TIMER0_COMPA_vect, ISR_BLOCK)\r
+/** Event handler for the USB device Start Of Frame event. */\r
+void EVENT_USB_Device_StartOfFrame(void)\r
 {\r
        HID_Device_MillisecondElapsed(&Keyboard_HID_Interface);\r
 }\r
@@ -166,13 +163,14 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
  *\r
  *  \param[in] HIDInterfaceInfo  Pointer to the HID class interface configuration structure being referenced\r
  *  \param[in,out] ReportID  Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID\r
+ *  \param[in] ReportType  Type of the report to create, either REPORT_ITEM_TYPE_In or REPORT_ITEM_TYPE_Feature\r
  *  \param[out] ReportData  Pointer to a buffer where the created report should be stored\r
  *  \param[out] ReportSize  Number of bytes written in the report (or zero if no report is to be sent\r
  *\r
  *  \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent\r
  */\r
 bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID,\r
-                                         void* ReportData, uint16_t* ReportSize)\r
+                                         const uint8_t ReportType, void* ReportData, uint16_t* ReportSize)\r
 {\r
        USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData;\r
 \r
@@ -184,18 +182,18 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
        if ((IsKeyReleaseReport) || (CurrentTrackBuffer == &TrackDataBuffers[TOTAL_TRACKS]))\r
        {\r
                /* No more data to send, or key release report between key presses */\r
-               KeyboardReport->KeyCode = KEY_NONE;\r
+               KeyboardReport->KeyCode[0] = KEY_NONE;\r
        }\r
        else if (!(CurrentTrackBuffer->Elements))\r
        {\r
                /* End of current track, send an enter press and change to the next track's buffer */\r
-               KeyboardReport->KeyCode = KEY_ENTER;\r
+               KeyboardReport->KeyCode[0] = KEY_ENTER;\r
                CurrentTrackBuffer++;\r
        }\r
        else\r
        {\r
                /* Still data in the current track; convert next bit to a 1 or 0 keypress */\r
-               KeyboardReport->KeyCode = BitBuffer_GetNextBit(CurrentTrackBuffer) ? KEY_1 : KEY_0;\r
+               KeyboardReport->KeyCode[0] = BitBuffer_GetNextBit(CurrentTrackBuffer) ? KEY_1 : KEY_0;\r
        }\r
        \r
        *ReportSize = sizeof(USB_KeyboardReport_Data_t);\r