Beispiel #1
0
/** Determines if a card has been inserted, and if so reads in each track's contents into the bit buffers
 *  until they are read out to the host as a series of keyboard presses.
 */
void ReadMagstripeData(void)
{
	/* Arrays to hold the buffer pointers, clock and data bit masks for the separate card tracks */
	const struct
	{
		uint8_t ClockMask;
		uint8_t DataMask;
	} TrackInfo[] = {{MAG_T1_CLOCK, MAG_T1_DATA},
	                 {MAG_T2_CLOCK, MAG_T2_DATA},
	                 {MAG_T3_CLOCK, MAG_T3_DATA}};

	uint8_t Magstripe_Prev = 0;
	uint8_t Magstripe_LCL  = Magstripe_GetStatus();

	while (Magstripe_LCL & MAG_CARDPRESENT)
	{
		for (uint8_t Track = 0; Track < TOTAL_TRACKS; Track++)
		{
			bool DataPinLevel      = ((Magstripe_LCL & TrackInfo[Track].DataMask) != 0);
			bool ClockPinLevel     = ((Magstripe_LCL & TrackInfo[Track].ClockMask) != 0);
			bool ClockLevelChanged = (((Magstripe_LCL ^ Magstripe_Prev) & TrackInfo[Track].ClockMask) != 0);

			/* Sample data on rising clock edges from the card reader */
			if (ClockPinLevel && ClockLevelChanged)
			  BitBuffer_StoreNextBit(&TrackDataBuffers[Track], DataPinLevel);
		}

		Magstripe_Prev = Magstripe_LCL;
		Magstripe_LCL  = Magstripe_GetStatus();
	}

	CurrentTrackBuffer = &TrackDataBuffers[0];
}
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
	SetupHardware();
	
	for (uint8_t Buffer = 0; Buffer < TOTAL_TRACKS; Buffer++)
	  BitBuffer_Init(&TrackDataBuffers[Buffer]);

	for (;;)
	{
		if (Magstripe_GetStatus() & MAG_CARDPRESENT)
		  ReadMagstripeData();

		HID_Device_USBTask(&Keyboard_HID_Interface);
		USB_USBTask();
	}
}