X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/a67bd74e3e8aad87dcee8cf0c0eaaccbe7d00552..23f3c3deee8bd153d59f2ac4e659c71ee75915f7:/Projects/Magstripe/Magstripe.c?ds=inline diff --git a/Projects/Magstripe/Magstripe.c b/Projects/Magstripe/Magstripe.c index e32397c8b..95c81f342 100644 --- a/Projects/Magstripe/Magstripe.c +++ b/Projects/Magstripe/Magstripe.c @@ -46,14 +46,22 @@ BitBuffer_t TrackDataBuffers[3]; * passed to all HID Class driver functions, so that multiple instances of the same class * within a device can be differentiated from one another. */ -USB_ClassInfo_HID_t Keyboard_HID_Interface = +USB_ClassInfo_HID_Device_t Keyboard_HID_Interface = { - .InterfaceNumber = 0, - - .ReportINEndpointNumber = KEYBOARD_EPNUM, - .ReportINEndpointSize = KEYBOARD_EPSIZE, + .Config = + { + .InterfaceNumber = 0, + + .ReportINEndpointNumber = KEYBOARD_EPNUM, + .ReportINEndpointSize = KEYBOARD_EPSIZE, + + .ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t), + }, - .ReportINBufferSize = sizeof(USB_KeyboardReport_Data_t), + .State = + { + // Leave all state values to their defaults + } }; /** Main program entry point. This routine contains the overall program flow, including initial @@ -71,7 +79,7 @@ int main(void) if (Magstripe_GetStatus() & MAG_CARDPRESENT) ReadMagstripeData(); - USB_HID_USBTask(&Keyboard_HID_Interface); + HID_Device_USBTask(&Keyboard_HID_Interface); USB_USBTask(); } } @@ -134,37 +142,38 @@ void ReadMagstripeData(void) /** Event handler for the library USB Configuration Changed event. */ void EVENT_USB_ConfigurationChanged(void) { - USB_HID_ConfigureEndpoints(&Keyboard_HID_Interface); + HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface); } /** Event handler for the library USB Unhandled Control Packet event. */ void EVENT_USB_UnhandledControlPacket(void) { - USB_HID_ProcessControlPacket(&Keyboard_HID_Interface); + HID_Device_ProcessControlPacket(&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) { - if (Keyboard_HID_Interface.IdleMSRemaining) - Keyboard_HID_Interface.IdleMSRemaining--; + if (Keyboard_HID_Interface.State.IdleMSRemaining) + Keyboard_HID_Interface.State.IdleMSRemaining--; } /** HID Class driver callback function for the creation of a HID report for the host. * - * \param HIDInterfaceInfo Pointer to the HID interface structure for the HID interface being referenced - * \param ReportData Pointer to the preallocated report buffer where the created report should be stored + * \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 * * \return Number of bytes in the created report */ -uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData) +uint16_t CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, void* ReportData) { static bool IsKeyReleaseReport; static bool IsNewlineReport; BitBuffer_t* Buffer = NULL; USB_KeyboardReport_Data_t* KeyboardReport = (USB_KeyboardReport_Data_t*)ReportData; - + /* Key reports must be interleaved with 0 Key Code reports to release the keys, or repeated keys will be ignored */ IsKeyReleaseReport = !IsKeyReleaseReport; @@ -200,11 +209,13 @@ uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t* HIDInterfaceI /** HID Class driver callback function for the processing of a received HID report from the host. * - * \param HIDInterfaceInfo Pointer to the HID interface structure for the HID interface being referenced - * \param ReportData Pointer to the report buffer where the received report is stored - * \param ReportSize Size in bytes of the report received from the host + * \param[in] HIDInterfaceInfo Pointer to the HID interface structure for the HID interface being referenced + * \param[in] ReportID Report ID of the received report from the host + * \param[in] ReportData Pointer to the report buffer where the received report is stored + * \param[in] ReportSize Size in bytes of the report received from the host */ -void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t* HIDInterfaceInfo, void* ReportData, uint16_t ReportSize) +void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, + 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 }