Added documentation of the makefile CDEFS values to the MagStripe project.
#endif\r
\r
/* Type Defines: */\r
- /* Type define for a pointer to a bit in a bit buffer. */\r
+ /** Type define for a pointer to a bit in a bit buffer. */\r
typedef struct\r
{\r
uint8_t* CurrentByte; /**< Pointer to the current byte in the buffer */\r
* <td>CircularBitBuffer.h</td>\r
* <td>Gives the maximum number of bits per track which can be buffered by the device for later transmission to a host.</td>\r
* </tr>\r
+ * <tr>\r
+ * <td>MAG_T1_CLOCK</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>Mask for the magnetic card reader's CLOCK line for the reader's track 1 output.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_T1_DATA</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>Mask for the magnetic card reader's DATA line for the reader's track 1 output.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_T2_CLOCK</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>Mask for the magnetic card reader's CLOCK line for the reader's track 2 output.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_T2_DATA</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>Mask for the magnetic card reader's DATA line for the reader's track 2 output.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_T3_CLOCK</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>Mask for the magnetic card reader's CLOCK line for the reader's track 3 output.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_T3_DATA</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>Mask for the magnetic card reader's DATA line for the reader's track 3 output.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_CARDPRESENT</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>Mask for the magnetic card reader's card detection output.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_PIN</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>PIN register that the magnetic card reader device is attached to.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_PORT</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>PORT register that the magnetic card reader device is attached to.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>MAG_DDR</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>DDR register that the magnetic card reader device is attached to.</td>\r
+ * </tr>\r
* </table>\r
*/\r
{\r
SetupHardware();\r
\r
+ V2Protocol_ConfigureHardware();\r
+\r
printf("AVRISP-MKII Clone\r\n");\r
\r
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
\r
/* Hardware Initialization */\r
SerialStream_Init(9600, false);\r
+ SPI_Init(0, true);\r
LEDs_Init();\r
USB_Init();\r
}\r
#include <LUFA/Version.h>\r
#include <LUFA/Drivers/Board/LEDs.h>\r
#include <LUFA/Drivers/Peripheral/SerialStream.h>\r
+ #include <LUFA/Drivers/Peripheral/SPI.h>\r
#include <LUFA/Drivers/USB/USB.h>
#include "Lib/V2Protocol.h"\r
* This device spoofs Atmel's official AVRISP-MKII device PID so that it remains compatible with Atmel's AVRISP-MKII\r
* drivers. When promted, direct your OS to install Atmel's AVRISP-MKII drivers provided with AVRStudio.\r
*\r
+ * This demo contains both FLASH and EEPROM data, as compiled .HEX and .EEP files respectively. <b>Both</b> files must\r
+ * be loaded into the device for it to perform correctly.\r
+ *\r
* \section SSec_Options Project Options\r
*\r
* The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value.\r
*\r
* <table>\r
* <tr>\r
- * <td>\r
- * None\r
- * </td>\r
+ * <td><b>Define Name:</b></td>\r
+ * <td><b>Location:</b></td>\r
+ * <td><b>Description:</b></td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>RESET_LINE_PORT</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>PORT register for the programmer's target RESET line.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>RESET_LINE_PIN</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>PIN register for the programmer's target RESET line.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>RESET_LINE_DDR</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>DDR register for the programmer's target RESET line.</td>\r
+ * </tr>\r
+ * <tr>\r
+ * <td>RESET_LINE_MASK</td>\r
+ * <td>Makefile CDEFS</td>\r
+ * <td>Mask for the programmer's target RESET line on the chosen port.</td>\r
* </tr>\r
* </table>\r
*/\r
{ .ParameterID = PARAM_DISCHARGEDELAY,\r
.ParameterValue = 0x00 },\r
};\r
+ \r
+void V2Protocol_ConfigureHardware(void)\r
+{\r
+#if F_CPU == 8000000\r
+ uint8_t SPIMaskFromSCKDuration[] = {SPI_SPEED_FCPU_DIV_128, SPI_SPEED_FCPU_DIV_128, SPI_SPEED_FCPU_DIV_128,\r
+ SPI_SPEED_FCPU_DIV_128, SPI_SPEED_FCPU_DIV_128, SPI_SPEED_FCPU_DIV_128};\r
+#else\r
+ uint8_t SPIMaskFromSCKDuration[] = {SPI_SPEED_FCPU_DIV_128, SPI_SPEED_FCPU_DIV_128, SPI_SPEED_FCPU_DIV_128,\r
+ SPI_SPEED_FCPU_DIV_128, SPI_SPEED_FCPU_DIV_128, SPI_SPEED_FCPU_DIV_128};\r
+#endif\r
+\r
+ uint8_t SCKDuration = eeprom_read_byte(&V2Protocol_GetParameterItem(PARAM_SCK_DURATION)->ParameterValue);\r
+\r
+ if (SCKDuration > sizeof(SPIMaskFromSCKDuration))\r
+ SCKDuration = SPIMaskFromSCKDuration;\r
+ \r
+ SPI_Init(SPIMaskFromSCKDuration[SCKDuration], true); \r
+}\r
void V2Protocol_ProcessCommand(void)
{
case CMD_GET_PARAMETER:\r
V2Protocol_ProcessCmdGetSetParam(V2Command);\r
break;\r
+ case CMD_SPI_MULTI:\r
+ V2Protocol_ProcessCmdSPIMulti();\r
+ break; \r
default:\r
while (Endpoint_BytesInEndpoint() == AVRISP_DATA_EPSIZE)\r
{\r
Endpoint_ClearOUT();\r
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
\r
+ Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(STATUS_CMD_UNKNOWN);\r
Endpoint_ClearIN();\r
break;\r
\r
printf("COMMAND 0x%02x\r\n", V2Command);\r
\r
- Endpoint_WaitUntilReady();\r
- \r
- /* Reset Endpoint direction to OUT ready for next command */\r
+ Endpoint_WaitUntilReady(); \r
Endpoint_SetEndpointDirection(ENDPOINT_DIR_OUT);
}\r
\r
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
Endpoint_WaitUntilReady();\r
\r
+ V2Protocol_ConfigureHardware();\r
+\r
Endpoint_Write_Byte(CMD_SIGN_ON);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
Endpoint_Write_Byte(PROGRAMMER_ID_LEN);\r
\r
ParameterItem_t* ParameterItem = V2Protocol_GetParameterItem(ParamID);\r
\r
+ Endpoint_Write_Byte(V2Command);\r
+\r
if (ParameterItem != NULL)\r
{\r
- Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
\r
if (V2Command == CMD_SET_PARAMETER)\r
\r
Endpoint_ClearIN();\r
}\r
+\r
+static void V2Protocol_ProcessCmdSPIMulti(void)\r
+{\r
+ uint8_t TxBytes = Endpoint_Read_Byte();\r
+ uint8_t RxBytes = Endpoint_Read_Byte();\r
+ uint8_t RxStartAddr = Endpoint_Read_Byte();\r
+ uint8_t TxData[255];\r
+ \r
+ Endpoint_Read_Stream_LE(TxData, TxBytes);\r
+ \r
+ Endpoint_ClearOUT();\r
+ Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);\r
+ Endpoint_WaitUntilReady();\r
+ \r
+ Endpoint_Write_Byte(CMD_SPI_MULTI);\r
+ Endpoint_Write_Byte(STATUS_CMD_OK);\r
+\r
+ uint8_t CurrTxPos = 0;\r
+ uint8_t CurrRxPos = 0;\r
+\r
+ while (CurrTxPos < RxStartAddr)\r
+ {\r
+ if (CurrTxPos < TxBytes)\r
+ SPI_SendByte(TxData[CurrTxPos]);\r
+ else\r
+ SPI_SendByte(0);\r
+ \r
+ CurrTxPos++;\r
+ }\r
+\r
+ while (CurrRxPos < RxBytes)\r
+ {\r
+ if (CurrTxPos < TxBytes)\r
+ {\r
+ Endpoint_Write_Byte(SPI_TransferByte(TxData[CurrTxPos]));\r
+ CurrTxPos++;\r
+ }\r
+ else\r
+ {\r
+ Endpoint_Write_Byte(SPI_ReceiveByte());\r
+ }\r
+ \r
+ CurrRxPos++;\r
+ } \r
+ \r
+ Endpoint_Write_Byte(STATUS_CMD_OK);\r
+ Endpoint_ClearIN(); \r
+}\r
#include <avr/io.h>
#include <LUFA/Drivers/USB/USB.h>
+ #include <LUFA/Drivers/Peripheral/SPI.h>\r
\r
#include "../Descriptors.h"
#include "V2ProtocolConstants.h"
uint8_t ParameterValue;\r
} ParameterItem_t;
- /* Function Prototypes: */
+ /* Function Prototypes: */ \r
+ void V2Protocol_ConfigureHardware(void);
void V2Protocol_ProcessCommand(void);\r
\r
#if defined(INCLUDE_FROM_V2PROTOCOL_C)\r
static ParameterItem_t* V2Protocol_GetParameterItem(uint8_t ParamID);\r
static void V2Protocol_ProcessCmdSignOn(void);\r
static void V2Protocol_ProcessCmdGetSetParam(uint8_t V2Command);\r
+ static void V2Protocol_ProcessCmdSPIMulti(void);\r
#endif
#endif
\r
# Place -D or -U options here for C sources\r
CDEFS = -DF_CPU=$(F_CPU)UL -DF_CLOCK=$(F_CLOCK)UL -DBOARD=BOARD_$(BOARD) $(LUFA_OPTS)\r
+CDEFS += -DRESET_LINE_PORT=PORTA\r
+CDEFS += -DRESET_LINE_PIN=PINA\r
+CDEFS += -DRESET_LINE_DDR=DDRA\r
+CDEFS += -DRESET_LINE_MASK="(1 << 0)"\r
+\r
\r
# Place -D or -U options here for ASM sources\r
ADEFS = -DF_CPU=$(F_CPU)\r