Endpoint_Read_Stream_LE(&Write_Memory_Params, sizeof(Write_Memory_Params));\r
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);\r
\r
- for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
+ if (Write_Memory_Params.ProgrammingMode & PROG_MODE_PAGED_WRITES_MASK)\r
{\r
- // TODO - Read in programming data, write to device\r
+ for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
+ {\r
+ if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))\r
+ Write_Memory_Params.ProgrammingCommands[0] ^= READ_WRITE_ODD_BYTE_MASK;\r
+ \r
+ SPI_SendByte(Write_Memory_Params.ProgrammingCommands[0]);\r
+ SPI_SendByte(CurrentAddress >> 8);\r
+ SPI_SendByte(CurrentAddress & 0xFF);\r
+ SPI_SendByte(Endpoint_Read_Byte());\r
+ \r
+ // TODO - Correct Polling\r
+\r
+ if (((V2Command == CMD_PROGRAM_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
+ CurrentAddress++;\r
+ }\r
+ \r
+ /* If the current page must be committed, send the PROGRAM PAGE command to the target */\r
+ if (Write_Memory_Params.ProgrammingMode & PROG_MODE_COMMIT_PAGE_MASK)\r
+ {\r
+ SPI_SendByte(Write_Memory_Params.ProgrammingCommands[1]);\r
+ SPI_SendByte(CurrentAddress >> 8);\r
+ SPI_SendByte(CurrentAddress & 0xFF);\r
+ SPI_SendByte(0x00);\r
+ }\r
+ }\r
+ else\r
+ { \r
+ // TODO - Read in programming data, write to device \r
}\r
\r
Endpoint_ClearOUT();\r
\r
Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
-\r
+ \r
for (uint16_t CurrentByte = 0; CurrentByte < Read_Memory_Params.BytesToRead; CurrentByte++)\r
{\r
if ((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01))\r
Endpoint_WaitUntilReady();\r
}\r
\r
- CurrentAddress++;\r
+ if (((V2Command == CMD_READ_FLASH_ISP) && (CurrentByte & 0x01)) || (V2Command == CMD_READ_EEPROM_ISP))\r
+ CurrentAddress++;\r
}\r
\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
- \r
- bool EndpointBankFull = Endpoint_IsReadWriteAllowed();\r
Endpoint_ClearIN();\r
- \r
- /* Ensure data transfer is terminated by a short packet if the last sent bank was completely full */\r
- if (EndpointBankFull)\r
- {\r
- Endpoint_WaitUntilReady();\r
- Endpoint_ClearIN();\r
- }\r
}\r
\r
static void V2Protocol_Command_ChipErase(void)\r
\r
Endpoint_Write_Byte(V2Command);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
- Endpoint_Write_Byte(ResponseBytes[Read_FuseLockSigOSCCAL_Params.RetByte]);\r
+ Endpoint_Write_Byte(ResponseBytes[Read_FuseLockSigOSCCAL_Params.RetByte - 1]);\r
Endpoint_Write_Byte(STATUS_CMD_OK);\r
Endpoint_ClearIN();\r
}\r