+ {\r
+ /* Word/byte mode memory programming */\r
+ for (uint16_t CurrentByte = 0; CurrentByte < Write_Memory_Params.BytesToWrite; CurrentByte++)\r
+ {\r
+ bool IsOddByte = (CurrentByte & 0x01);\r
+ uint8_t ByteToWrite = Endpoint_Read_Byte();\r
+ \r
+ if ((V2Command == CMD_READ_FLASH_ISP) && IsOddByte)\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(ByteToWrite);\r
+ \r
+ if ((ByteToWrite != Write_Memory_Params.PollValue1) && (V2Command == CMD_PROGRAM_FLASH_ISP))\r
+ PollAddress = (((CurrentAddress & 0xFFFF) << 1) | IsOddByte);\r
+ else if ((ByteToWrite != Write_Memory_Params.PollValue2) && (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
+ PollAddress = (CurrentAddress & 0xFFFF);\r
+\r
+ ProgrammingStatus = V2Protocol_WaitForProgrammingComplete(PollAddress, Write_Memory_Params.ProgrammingMode);\r
+\r
+ if (IsOddByte || (V2Command == CMD_PROGRAM_EEPROM_ISP))\r
+ CurrentAddress++;\r
+ \r
+ if (ProgrammingStatus != STATUS_CMD_OK)\r
+ break;\r
+ }\r