Added handler for the V2 Protocol SPI_MULTI command to the AVRISP Programmer project.
authorDean Camera <dean@fourwalledcubicle.com>
Wed, 19 Aug 2009 06:25:54 +0000 (06:25 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Wed, 19 Aug 2009 06:25:54 +0000 (06:25 +0000)
Added documentation of the makefile CDEFS values to the MagStripe project.

Projects/Magstripe/Lib/CircularBitBuffer.h
Projects/Magstripe/Magstripe.txt
Projects/Unfinished/AVRISP/AVRISP.c
Projects/Unfinished/AVRISP/AVRISP.h
Projects/Unfinished/AVRISP/AVRISP.txt
Projects/Unfinished/AVRISP/Lib/V2Protocol.c
Projects/Unfinished/AVRISP/Lib/V2Protocol.h
Projects/Unfinished/AVRISP/makefile

index ffbdc86..6220e1b 100644 (file)
@@ -53,7 +53,7 @@
                #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
index a38471a..b725b70 100644 (file)
  *    <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
index 1e5f55d..9826dbb 100644 (file)
@@ -43,6 +43,8 @@ int main(void)
 {\r
        SetupHardware();\r
        \r
+       V2Protocol_ConfigureHardware();\r
+\r
        printf("AVRISP-MKII Clone\r\n");\r
        \r
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
@@ -67,6 +69,7 @@ void SetupHardware(void)
 \r
        /* Hardware Initialization */\r
        SerialStream_Init(9600, false);\r
+       SPI_Init(0, true);\r
        LEDs_Init();\r
        USB_Init();\r
 }\r
index 94e19a3..8a082f6 100644 (file)
@@ -47,6 +47,7 @@
                #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
index 9e5a455..0eb26f4 100644 (file)
  *  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
index 2679ce7..27f6fa7 100644 (file)
@@ -59,6 +59,24 @@ ParameterItem_t ParameterTable[] EEMEM =
                { .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)
 {
@@ -73,6 +91,9 @@ 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
@@ -83,6 +104,7 @@ void V2Protocol_ProcessCommand(void)
                        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
@@ -90,9 +112,7 @@ void V2Protocol_ProcessCommand(void)
        \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
@@ -113,6 +133,8 @@ static void V2Protocol_ProcessCmdSignOn(void)
        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
@@ -131,9 +153,10 @@ static void V2Protocol_ProcessCmdGetSetParam(uint8_t V2Command)
        \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
@@ -148,3 +171,51 @@ static void V2Protocol_ProcessCmdGetSetParam(uint8_t V2Command)
 \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
index 5e83359..6c2ff60 100644 (file)
@@ -40,6 +40,7 @@
                #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
index 5f76575..0877c5d 100644 (file)
@@ -193,6 +193,11 @@ CSTANDARD = -std=gnu99
 \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