]> git.donarmstrong.com Git - qmk_firmware.git/blob - lib/lufa/Projects/Magstripe/Lib/MagstripeHW.h
[Keyboard] Aeboards Ext65 - New keyboard & Aegis Update (#6127)
[qmk_firmware.git] / lib / lufa / Projects / Magstripe / Lib / MagstripeHW.h
1 /*
2   Copyright 2010  Denver Gingerich (denver [at] ossguy [dot] com)
3   Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)
4
5   Permission to use, copy, modify, distribute, and sell this
6   software and its documentation for any purpose is hereby granted
7   without fee, provided that the above copyright notice appear in
8   all copies and that both that the copyright notice and this
9   permission notice and warranty disclaimer appear in supporting
10   documentation, and that the name of the author not be used in
11   advertising or publicity pertaining to distribution of the
12   software without specific, written prior permission.
13
14   The author disclaims all warranties with regard to this
15   software, including all implied warranties of merchantability
16   and fitness.  In no event shall the author be liable for any
17   special, indirect or consequential damages or any damages
18   whatsoever resulting from loss of use, data or profits, whether
19   in an action of contract, negligence or other tortious action,
20   arising out of or in connection with the use or performance of
21   this software.
22 */
23
24 /*
25         NOTE: The user of this include file MUST define the following macros
26         prior to including the file:
27
28         MAG_T1_CLOCK_PIN   Pin connected to Track 1 clock wire (i.e.. PORTC1)
29         MAG_T1_DATA_PIN    Pin connected to Track 1 data wire (i.e.. PORTC2)
30         MAG_T2_CLOCK_PIN   Pin connected to Track 2 clock wire (i.e.. PORTC3)
31         MAG_T2_DATA_PIN    Pin connected to Track 2 data wire (i.e.. PORTC0)
32         MAG_T3_CLOCK_PIN   Pin connected to Track 3 clock wire (i.e.. PORTC5)
33         MAG_T3_DATA_PIN    Pin connected to Track 3 data wire (i.e.. PORTC6)
34         MAG_CLS_PIN        Pin connected to card loaded wire (i.e.. PORTC4)
35         MAG_PIN            PIN macro for the reader's port (i.e.. PINC)
36         MAG_DDR            DDR macro for the reader's port (i.e.. DDRC)
37         MAG_PORT           PORT macro for the reader's port (i.e.. PORTC)
38
39         The example macros listed above assume that the Track 2 data wire is
40         connected to pin 0 on port C, the Track 2 clock wire is connected to
41         pin 3 on port C (similarly for Tracks 1 and 3), and the card loaded
42         wire is connected to pin 4 on port C.
43
44         If the mag-stripe reader you are using only reads one or two tracks,
45         then set the clock and data pins for the tracks it doesn't read to a
46         pin that is unused.  For example, on the AT90USBKey, any of the pins on
47         port C that do not have wires attached will be unused since they are
48         not connected to any onboard devices (such as the joystick or
49         temperature sensor).
50
51         Connecting wires to pins on different ports (i.e.. a data wire to pin 0
52         on port C and a clock wire to pin 0 on port D) is currently
53         unsupported.  All pins specified above must be on the same port.
54 */
55
56 /** \file
57  *
58  *  Driver header for a TTL Magnetic Card reader device (such as the Omron V3B-4K).
59  */
60
61 #ifndef _MAGSTRIPEHW_H_
62 #define _MAGSTRIPEHW_H_
63
64         /* Includes: */
65                 #include <avr/io.h>
66
67                 #include <LUFA/Common/Common.h>
68                 #include "Config/AppConfig.h"
69
70         /* Private Interface - For use in library only: */
71                 /* Macros: */
72                         /** Mask of the track data, clock and card detection pins. */
73                         #define MAG_MASK    (MAG_T1_DATA | MAG_T1_CLOCK | \
74                                              MAG_T2_DATA | MAG_T2_CLOCK | \
75                                              MAG_T3_DATA | MAG_T3_CLOCK | \
76                                              MAG_CARDPRESENT)
77
78         /* Public Interface - May be used in end-application: */
79                 /* Inline Functions: */
80                         /** Initializes the magnetic stripe card reader ports and pins so that the card reader
81                          *  device can be controlled and read by the card reader driver. This must be called before
82                          *  trying to read any of the card reader's status lines.
83                          */
84                         static inline void Magstripe_Init(void)
85                         {
86                                 MAG_DDR  &= ~MAG_MASK;
87                                 MAG_PORT |=  MAG_MASK;
88                         };
89
90                         /** Returns the status of all the magnetic card reader's outputs.
91                          *
92                          *  \return A mask indicating which card lines are high or low
93                          */
94                         static inline uint8_t Magstripe_GetStatus(void) ATTR_WARN_UNUSED_RESULT;
95                         static inline uint8_t Magstripe_GetStatus(void)
96                         {
97                                 /* Mag-stripe IOs are active low and must be inverted when read */
98                                 return ((uint8_t)~MAG_PIN & MAG_MASK);
99                         }
100
101 #endif
102