{ .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