+/*\r
+ LUFA Library\r
+ Copyright (C) Dean Camera, 2009.\r
+ \r
+ dean [at] fourwalledcubicle [dot] com\r
+ www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+ Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+ Permission to use, copy, modify, and distribute this software\r
+ and its documentation for any purpose and without fee is hereby\r
+ granted, provided that the above copyright notice appear in all\r
+ copies and that both that the copyright notice and this\r
+ permission notice and warranty disclaimer appear in supporting\r
+ documentation, and that the name of the author not be used in\r
+ advertising or publicity pertaining to distribution of the\r
+ software without specific, written prior permission.\r
+\r
+ The author disclaim all warranties with regard to this\r
+ software, including all implied warranties of merchantability\r
+ and fitness. In no event shall the author be liable for any\r
+ special, indirect or consequential damages or any damages\r
+ whatsoever resulting from loss of use, data or profits, whether\r
+ in an action of contract, negligence or other tortious action,\r
+ arising out of or in connection with the use or performance of\r
+ this software.\r
+*/\r
+\r
+#if defined(ENABLE_XPROG_PROTOCOL)\r
+\r
+/** \file\r
+ *\r
+ * Target-related functions for the PDI Protocol decoder.\r
+ */\r
+\r
+#define INCLUDE_FROM_PDITARGET_C\r
+#include "PDITarget.h"\r
+\r
+void PDITarget_SendByte(uint8_t Byte)\r
+{\r
+ PDIDATA_LINE_PORT &= ~PDIDATA_LINE_MASK;\r
+\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK; \r
+\r
+ for (uint8_t i = 0; i < 8; i++)\r
+ {\r
+ if (Byte & 0x01)\r
+ PDIDATA_LINE_PORT |= PDIDATA_LINE_MASK;\r
+ else\r
+ PDIDATA_LINE_PORT &= ~PDIDATA_LINE_MASK;\r
+ \r
+ Byte >>= 1;\r
+\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK; \r
+ }\r
+\r
+ PDIDATA_LINE_PORT |= PDIDATA_LINE_MASK;\r
+\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+}\r
+\r
+uint8_t PDITarget_ReceiveByte(void)\r
+{\r
+ uint8_t ReceivedByte = 0;\r
+\r
+ PDIDATA_LINE_DDR &= ~PDIDATA_LINE_MASK;\r
+\r
+ bool FoundStartBit;\r
+\r
+ do\r
+ {\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ FoundStartBit = !(PDIDATA_LINE_PIN & PDIDATA_LINE_MASK);\r
+ } while (!FoundStartBit);\r
+ \r
+ for (uint8_t i = 0; i < 8; i++)\r
+ {\r
+ if (PDIDATA_LINE_PIN & PDIDATA_LINE_MASK)\r
+ ReceivedByte |= 0x01;\r
+\r
+ ReceivedByte <<= 1;\r
+\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK; \r
+ }\r
+\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ PDICLOCK_LINE_PORT ^= PDICLOCK_LINE_MASK;\r
+ \r
+ PDIDATA_LINE_DDR |= PDIDATA_LINE_MASK;\r
+ \r
+ return ReceivedByte;\r
+}\r
+\r
+#endif\r