MagstripeHW.h 4.1 KB

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