Fixed interrupt driven HID device demos not clearing the interrupt flags in all circu...
[pub/USBasp.git] / Projects / Magstripe / Magstripe.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Denver Gingerich (denver [at] ossguy [dot] com)
11 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12
13 Permission to use, copy, modify, and distribute this software
14 and its documentation for any purpose and without fee is hereby
15 granted, provided that the above copyright notice appear in all
16 copies and that both that the copyright notice and this
17 permission notice and warranty disclaimer appear in supporting
18 documentation, and that the name of the author not be used in
19 advertising or publicity pertaining to distribution of the
20 software without specific, written prior permission.
21
22 The author disclaim all warranties with regard to this
23 software, including all implied warranties of merchantability
24 and fitness. In no event shall the author be liable for any
25 special, indirect or consequential damages or any damages
26 whatsoever resulting from loss of use, data or profits, whether
27 in an action of contract, negligence or other tortious action,
28 arising out of or in connection with the use or performance of
29 this software.
30 */
31
32 /** \file
33 *
34 * Header file for Magstripe.c.
35 */
36
37 #ifndef _MAGSTRIPE_H_
38 #define _MAGSTRIPE_H_
39
40 /* Includes: */
41 #include <avr/io.h>
42 #include <avr/wdt.h>
43 #include <avr/interrupt.h>
44 #include <stdbool.h>
45 #include <string.h>
46
47 #include "Descriptors.h"
48 #include "MagstripeHW.h"
49 #include "CircularBitBuffer.h"
50
51 #include <LUFA/Version.h> // Library Version Information
52 #include <LUFA/Common/ButtLoadTag.h> // PROGMEM tags readable by the ButtLoad project
53 #include <LUFA/Drivers/USB/USB.h> // USB Functionality
54 #include <LUFA/Scheduler/Scheduler.h> // Simple scheduler for task management
55
56
57 /* Task Definitions: */
58 /** Task definition for the keyboard and magnetic card reading task. */
59 TASK(USB_Keyboard_Report);
60
61 TASK(Magstripe_Read);
62
63 /* Macros: */
64 /** HID Class Specific Request to get the current HID report from the device. */
65 #define REQ_GetReport 0x01
66
67 /** HID Class Specific Request to get the current device idle count. */
68 #define REQ_GetIdle 0x02
69
70 /** HID Class Specific Request to set the current HID report to the device. */
71 #define REQ_SetReport 0x09
72
73 /** HID Class Specific Request to set the device's idle count. */
74 #define REQ_SetIdle 0x0A
75
76 /** HID Class Specific Request to get the current HID report protocol mode. */
77 #define REQ_GetProtocol 0x03
78
79 /** HID Class Specific Request to set the current HID report protocol mode. */
80 #define REQ_SetProtocol 0x0B
81
82 /** HID keyboard keycode to indicate that the "1" key is currently pressed. */
83 #define KEY_1 30
84
85 /** HID keyboard keycode to indicate that the "0" key is currently pressed. */
86 #define KEY_0 39
87
88 /** HID keyboard keycode to indicate that the enter key is currently pressed. */
89 #define KEY_ENTER 40
90
91 /* Type Defines: */
92 /** Type define for the keyboard report structure. This structure matches the report layout
93 * given to the host in the HID Report descriptor, as well as matches the boot protocol report
94 * structure. This means that this one report structure can be used in both Report and Boot Protocol
95 * modes. */
96 typedef struct
97 {
98 uint8_t Modifier; /**< Modifier byte, indicating pressed modifier keys such as CTRL or ALT */
99 uint8_t Reserved; /**< Reserved for OEM use, always set to 0 */
100 uint8_t KeyCode[6]; /**< Key code array for pressed keys - up to six can be given simultaneously */
101 } USB_KeyboardReport_Data_t;
102
103 /* Event Handlers: */
104 /** Indicates that this module will catch the USB_Connect event when thrown by the library. */
105 HANDLES_EVENT(USB_Connect);
106
107 /** Indicates that this module will catch the USB_Disconnect event when thrown by the library. */
108 HANDLES_EVENT(USB_Disconnect);
109
110 /** Indicates that this module will catch the USB_ConfigurationChanged event when thrown by the library. */
111 HANDLES_EVENT(USB_ConfigurationChanged);
112
113 /** Indicates that this module will catch the USB_UnhandledControlPacket event when thrown by the library. */
114 HANDLES_EVENT(USB_UnhandledControlPacket);
115
116 /* Function Prototypes: */
117 bool GetNextReport(USB_KeyboardReport_Data_t* ReportData);
118 void SendKey(USB_KeyboardReport_Data_t* KeyboardReportData, uint8_t Key);
119 void Send(USB_KeyboardReport_Data_t* KeyboardReportData, bool SendReport);
120
121 #endif