Commit 60fd0ff4 authored by Dean Camera's avatar Dean Camera
Browse files

Changed XPLAINBridge project to be both a USB to USART bridge and a PDI...

Changed XPLAINBridge project to be both a USB to USART bridge and a PDI programmer, based on the state of a mode select pin.
parent 27461546
...@@ -181,8 +181,8 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = ...@@ -181,8 +181,8 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{ {
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = 0x01, .InterfaceNumber = 1,
.AlternateSetting = 0x00, .AlternateSetting = 0,
.TotalEndpoints = 1, .TotalEndpoints = 1,
......
This diff is collapsed.
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
www.fourwalledcubicle.com www.fourwalledcubicle.com
*/ */
#include "TWI.h" #include "../TWI.h"
bool TWI_StartTransmission(uint8_t SlaveAddress) bool TWI_StartTransmission(uint8_t SlaveAddress)
{ {
......
...@@ -42,8 +42,6 @@ ...@@ -42,8 +42,6 @@
int main(void) int main(void)
{ {
SetupHardware(); SetupHardware();
V2Params_LoadNonVolatileParamValues();
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
...@@ -70,18 +68,7 @@ void SetupHardware(void) ...@@ -70,18 +68,7 @@ void SetupHardware(void)
/* Hardware Initialization */ /* Hardware Initialization */
LEDs_Init(); LEDs_Init();
USB_Init(); USB_Init();
V2Protocol_Init();
#if defined(ADC)
/* Initialize the ADC converter for VTARGET level detection on supported AVR models */
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);
ADC_SetupChannel(VTARGET_ADC_CHANNEL);
ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);
#endif
/* Millisecond timer initialization for managing the command timeout counter */
OCR0A = ((F_CPU / 64) / 1000);
TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00));
} }
/** Event handler for the library USB Connection event. */ /** Event handler for the library USB Connection event. */
......
...@@ -54,7 +54,7 @@ void ISPProtocol_EnterISPMode(void) ...@@ -54,7 +54,7 @@ void ISPProtocol_EnterISPMode(void)
uint8_t EnterProgBytes[4]; uint8_t EnterProgBytes[4];
} Enter_ISP_Params; } Enter_ISP_Params;
Endpoint_Read_Stream_LE(&Enter_ISP_Params, sizeof(Enter_ISP_Params)); Endpoint_Read_Stream_LE(&Enter_ISP_Params, sizeof(Enter_ISP_Params), NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
...@@ -107,7 +107,7 @@ void ISPProtocol_LeaveISPMode(void) ...@@ -107,7 +107,7 @@ void ISPProtocol_LeaveISPMode(void)
uint8_t PostDelayMS; uint8_t PostDelayMS;
} Leave_ISP_Params; } Leave_ISP_Params;
Endpoint_Read_Stream_LE(&Leave_ISP_Params, sizeof(Leave_ISP_Params)); Endpoint_Read_Stream_LE(&Leave_ISP_Params, sizeof(Leave_ISP_Params), NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
...@@ -142,7 +142,7 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command) ...@@ -142,7 +142,7 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command)
} Write_Memory_Params; // whole page and ACK the packet as fast as possible to prevent it from aborting } Write_Memory_Params; // whole page and ACK the packet as fast as possible to prevent it from aborting
Endpoint_Read_Stream_LE(&Write_Memory_Params, (sizeof(Write_Memory_Params) - Endpoint_Read_Stream_LE(&Write_Memory_Params, (sizeof(Write_Memory_Params) -
sizeof(Write_Memory_Params.ProgData))); sizeof(Write_Memory_Params.ProgData)), NO_STREAM_CALLBACK);
Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite); Write_Memory_Params.BytesToWrite = SwapEndian_16(Write_Memory_Params.BytesToWrite);
...@@ -158,7 +158,7 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command) ...@@ -158,7 +158,7 @@ void ISPProtocol_ProgramMemory(uint8_t V2Command)
return; return;
} }
Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite); Endpoint_Read_Stream_LE(&Write_Memory_Params.ProgData, Write_Memory_Params.BytesToWrite, NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
...@@ -287,7 +287,7 @@ void ISPProtocol_ReadMemory(uint8_t V2Command) ...@@ -287,7 +287,7 @@ void ISPProtocol_ReadMemory(uint8_t V2Command)
uint8_t ReadMemoryCommand; uint8_t ReadMemoryCommand;
} Read_Memory_Params; } Read_Memory_Params;
Endpoint_Read_Stream_LE(&Read_Memory_Params, sizeof(Read_Memory_Params)); Endpoint_Read_Stream_LE(&Read_Memory_Params, sizeof(Read_Memory_Params), NO_STREAM_CALLBACK);
Read_Memory_Params.BytesToRead = SwapEndian_16(Read_Memory_Params.BytesToRead); Read_Memory_Params.BytesToRead = SwapEndian_16(Read_Memory_Params.BytesToRead);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
...@@ -358,7 +358,7 @@ void ISPProtocol_ChipErase(void) ...@@ -358,7 +358,7 @@ void ISPProtocol_ChipErase(void)
uint8_t EraseCommandBytes[4]; uint8_t EraseCommandBytes[4];
} Erase_Chip_Params; } Erase_Chip_Params;
Endpoint_Read_Stream_LE(&Erase_Chip_Params, sizeof(Erase_Chip_Params)); Endpoint_Read_Stream_LE(&Erase_Chip_Params, sizeof(Erase_Chip_Params), NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
...@@ -393,7 +393,7 @@ void ISPProtocol_ReadFuseLockSigOSCCAL(uint8_t V2Command) ...@@ -393,7 +393,7 @@ void ISPProtocol_ReadFuseLockSigOSCCAL(uint8_t V2Command)
uint8_t ReadCommandBytes[4]; uint8_t ReadCommandBytes[4];
} Read_FuseLockSigOSCCAL_Params; } Read_FuseLockSigOSCCAL_Params;
Endpoint_Read_Stream_LE(&Read_FuseLockSigOSCCAL_Params, sizeof(Read_FuseLockSigOSCCAL_Params)); Endpoint_Read_Stream_LE(&Read_FuseLockSigOSCCAL_Params, sizeof(Read_FuseLockSigOSCCAL_Params), NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
...@@ -423,7 +423,7 @@ void ISPProtocol_WriteFuseLock(uint8_t V2Command) ...@@ -423,7 +423,7 @@ void ISPProtocol_WriteFuseLock(uint8_t V2Command)
uint8_t WriteCommandBytes[4]; uint8_t WriteCommandBytes[4];
} Write_FuseLockSig_Params; } Write_FuseLockSig_Params;
Endpoint_Read_Stream_LE(&Write_FuseLockSig_Params, sizeof(Write_FuseLockSig_Params)); Endpoint_Read_Stream_LE(&Write_FuseLockSig_Params, sizeof(Write_FuseLockSig_Params), NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
...@@ -449,8 +449,8 @@ void ISPProtocol_SPIMulti(void) ...@@ -449,8 +449,8 @@ void ISPProtocol_SPIMulti(void)
uint8_t TxData[255]; uint8_t TxData[255];
} SPI_Multi_Params; } SPI_Multi_Params;
Endpoint_Read_Stream_LE(&SPI_Multi_Params, sizeof(SPI_Multi_Params) - sizeof(SPI_Multi_Params.TxData)); Endpoint_Read_Stream_LE(&SPI_Multi_Params, (sizeof(SPI_Multi_Params) - sizeof(SPI_Multi_Params.TxData)), NO_STREAM_CALLBACK);
Endpoint_Read_Stream_LE(&SPI_Multi_Params.TxData, SPI_Multi_Params.TxBytes); Endpoint_Read_Stream_LE(&SPI_Multi_Params.TxData, SPI_Multi_Params.TxBytes, NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
......
...@@ -50,6 +50,24 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK) ...@@ -50,6 +50,24 @@ ISR(TIMER0_COMPA_vect, ISR_BLOCK)
TimeoutMSRemaining--; TimeoutMSRemaining--;
} }
/** Initializes the hardware and software associated with the V2 protocol command handling. */
void V2Protocol_Init(void)
{
#if defined(ADC)
/* Initialize the ADC converter for VTARGET level detection on supported AVR models */
ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128);
ADC_SetupChannel(VTARGET_ADC_CHANNEL);
ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC);
#endif
/* Millisecond timer initialization for managing the command timeout counter */
OCR0A = ((F_CPU / 64) / 1000);
TCCR0A = (1 << WGM01);
TCCR0B = ((1 << CS01) | (1 << CS00));
V2Params_LoadNonVolatileParamValues();
}
/** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host. /** Master V2 Protocol packet handler, for received V2 Protocol packets from a connected host.
* This routine decodes the issued command and passes off the handling of the command to the * This routine decodes the issued command and passes off the handling of the command to the
* appropriate function. * appropriate function.
...@@ -160,7 +178,7 @@ static void V2Protocol_SignOn(void) ...@@ -160,7 +178,7 @@ static void V2Protocol_SignOn(void)
Endpoint_Write_Byte(CMD_SIGN_ON); Endpoint_Write_Byte(CMD_SIGN_ON);
Endpoint_Write_Byte(STATUS_CMD_OK); Endpoint_Write_Byte(STATUS_CMD_OK);
Endpoint_Write_Byte(sizeof(PROGRAMMER_ID) - 1); Endpoint_Write_Byte(sizeof(PROGRAMMER_ID) - 1);
Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1)); Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1), NO_STREAM_CALLBACK);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
...@@ -222,7 +240,7 @@ static void V2Protocol_GetSetParam(const uint8_t V2Command) ...@@ -222,7 +240,7 @@ static void V2Protocol_GetSetParam(const uint8_t V2Command)
*/ */
static void V2Protocol_LoadAddress(void) static void V2Protocol_LoadAddress(void)
{ {
Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress)); Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress), NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
......
...@@ -70,6 +70,7 @@ ...@@ -70,6 +70,7 @@
extern bool MustSetAddress; extern bool MustSetAddress;
/* Function Prototypes: */ /* Function Prototypes: */
void V2Protocol_Init(void);
void V2Protocol_ProcessCommand(void); void V2Protocol_ProcessCommand(void);
#if defined(INCLUDE_FROM_V2PROTOCOL_C) #if defined(INCLUDE_FROM_V2PROTOCOL_C)
......
...@@ -62,7 +62,7 @@ void XPROGProtocol_SetMode(void) ...@@ -62,7 +62,7 @@ void XPROGProtocol_SetMode(void)
uint8_t Protocol; uint8_t Protocol;
} SetMode_XPROG_Params; } SetMode_XPROG_Params;
Endpoint_Read_Stream_LE(&SetMode_XPROG_Params, sizeof(SetMode_XPROG_Params)); Endpoint_Read_Stream_LE(&SetMode_XPROG_Params, sizeof(SetMode_XPROG_Params), NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
...@@ -202,7 +202,7 @@ static void XPROGProtocol_Erase(void) ...@@ -202,7 +202,7 @@ static void XPROGProtocol_Erase(void)
uint32_t Address; uint32_t Address;
} Erase_XPROG_Params; } Erase_XPROG_Params;
Endpoint_Read_Stream_LE(&Erase_XPROG_Params, sizeof(Erase_XPROG_Params)); Endpoint_Read_Stream_LE(&Erase_XPROG_Params, sizeof(Erase_XPROG_Params), NO_STREAM_CALLBACK);
Erase_XPROG_Params.Address = SwapEndian_32(Erase_XPROG_Params.Address); Erase_XPROG_Params.Address = SwapEndian_32(Erase_XPROG_Params.Address);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
...@@ -262,10 +262,10 @@ static void XPROGProtocol_WriteMemory(void) ...@@ -262,10 +262,10 @@ static void XPROGProtocol_WriteMemory(void)
} WriteMemory_XPROG_Params; } WriteMemory_XPROG_Params;
Endpoint_Read_Stream_LE(&WriteMemory_XPROG_Params, (sizeof(WriteMemory_XPROG_Params) - Endpoint_Read_Stream_LE(&WriteMemory_XPROG_Params, (sizeof(WriteMemory_XPROG_Params) -
sizeof(WriteMemory_XPROG_Params).ProgData)); sizeof(WriteMemory_XPROG_Params).ProgData), NO_STREAM_CALLBACK);
WriteMemory_XPROG_Params.Address = SwapEndian_32(WriteMemory_XPROG_Params.Address); WriteMemory_XPROG_Params.Address = SwapEndian_32(WriteMemory_XPROG_Params.Address);
WriteMemory_XPROG_Params.Length = SwapEndian_16(WriteMemory_XPROG_Params.Length); WriteMemory_XPROG_Params.Length = SwapEndian_16(WriteMemory_XPROG_Params.Length);
Endpoint_Read_Stream_LE(&WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length); Endpoint_Read_Stream_LE(&WriteMemory_XPROG_Params.ProgData, WriteMemory_XPROG_Params.Length, NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
...@@ -351,7 +351,7 @@ static void XPROGProtocol_ReadMemory(void) ...@@ -351,7 +351,7 @@ static void XPROGProtocol_ReadMemory(void)
uint16_t Length; uint16_t Length;
} ReadMemory_XPROG_Params; } ReadMemory_XPROG_Params;
Endpoint_Read_Stream_LE(&ReadMemory_XPROG_Params, sizeof(ReadMemory_XPROG_Params)); Endpoint_Read_Stream_LE(&ReadMemory_XPROG_Params, sizeof(ReadMemory_XPROG_Params), NO_STREAM_CALLBACK);
ReadMemory_XPROG_Params.Address = SwapEndian_32(ReadMemory_XPROG_Params.Address); ReadMemory_XPROG_Params.Address = SwapEndian_32(ReadMemory_XPROG_Params.Address);
ReadMemory_XPROG_Params.Length = SwapEndian_16(ReadMemory_XPROG_Params.Length); ReadMemory_XPROG_Params.Length = SwapEndian_16(ReadMemory_XPROG_Params.Length);
...@@ -380,7 +380,7 @@ static void XPROGProtocol_ReadMemory(void) ...@@ -380,7 +380,7 @@ static void XPROGProtocol_ReadMemory(void)
Endpoint_Write_Byte(ReturnStatus); Endpoint_Write_Byte(ReturnStatus);
if (ReturnStatus == XPRG_ERR_OK) if (ReturnStatus == XPRG_ERR_OK)
Endpoint_Write_Stream_LE(ReadBuffer, ReadMemory_XPROG_Params.Length); Endpoint_Write_Stream_LE(ReadBuffer, ReadMemory_XPROG_Params.Length, NO_STREAM_CALLBACK);
Endpoint_ClearIN(); Endpoint_ClearIN();
} }
...@@ -397,7 +397,7 @@ static void XPROGProtocol_ReadCRC(void) ...@@ -397,7 +397,7 @@ static void XPROGProtocol_ReadCRC(void)
uint8_t CRCType; uint8_t CRCType;
} ReadCRC_XPROG_Params; } ReadCRC_XPROG_Params;
Endpoint_Read_Stream_LE(&ReadCRC_XPROG_Params, sizeof(ReadCRC_XPROG_Params)); Endpoint_Read_Stream_LE(&ReadCRC_XPROG_Params, sizeof(ReadCRC_XPROG_Params), NO_STREAM_CALLBACK);
Endpoint_ClearOUT(); Endpoint_ClearOUT();
Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN); Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);
......
...@@ -119,7 +119,6 @@ LUFA_PATH = ../../ ...@@ -119,7 +119,6 @@ LUFA_PATH = ../../
LUFA_OPTS = -D USB_DEVICE_ONLY LUFA_OPTS = -D USB_DEVICE_ONLY
LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=16 LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=16
LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1 LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
LUFA_OPTS += -D NO_STREAM_CALLBACKS
LUFA_OPTS += -D USE_FLASH_DESCRIPTORS LUFA_OPTS += -D USE_FLASH_DESCRIPTORS
LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)" LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
* the device's capabilities and functions. * the device's capabilities and functions.
*/ */
#include "Descriptors.h" #include "USARTDescriptors.h"
/* On some devices, there is a factory set internal serial number which can be automatically sent to the host as /* On some devices, there is a factory set internal serial number which can be automatically sent to the host as
* the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL. * the device's serial number when the Device Descriptor's .SerialNumStrIndex entry is set to USE_INTERNAL_SERIAL.
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
* number of device configurations. The descriptor is read out by the USB host when the enumeration * number of device configurations. The descriptor is read out by the USB host when the enumeration
* process begins. * process begins.
*/ */
USB_Descriptor_Device_t PROGMEM DeviceDescriptor = USB_Descriptor_Device_t PROGMEM USART_DeviceDescriptor =
{ {
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device}, .Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
...@@ -81,13 +81,13 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor = ...@@ -81,13 +81,13 @@ USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
* a configuration so that the host may correctly communicate with the USB device. * a configuration so that the host may correctly communicate with the USB device.
*/ */
USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = USART_USB_Descriptor_Configuration_t PROGMEM USART_ConfigurationDescriptor =
{ {
.Config = .Config =
{ {
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), .TotalConfigurationSize = sizeof(USART_USB_Descriptor_Configuration_t),
.TotalInterfaces = 2, .TotalInterfaces = 2,
.ConfigurationNumber = 1, .ConfigurationNumber = 1,
...@@ -197,7 +197,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = ...@@ -197,7 +197,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
* the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
* via the language ID table available at USB.org what languages the device supports for its string descriptors. * via the language ID table available at USB.org what languages the device supports for its string descriptors.
*/ */
USB_Descriptor_String_t PROGMEM LanguageString = USB_Descriptor_String_t PROGMEM USART_LanguageString =
{ {
.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String}, .Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
...@@ -208,7 +208,7 @@ USB_Descriptor_String_t PROGMEM LanguageString = ...@@ -208,7 +208,7 @@ USB_Descriptor_String_t PROGMEM LanguageString =
* form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor. * Descriptor.
*/ */
USB_Descriptor_String_t PROGMEM ManufacturerString = USB_Descriptor_String_t PROGMEM USART_ManufacturerString =
{ {
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String}, .Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
...@@ -219,20 +219,14 @@ USB_Descriptor_String_t PROGMEM ManufacturerString = ...@@ -219,20 +219,14 @@ USB_Descriptor_String_t PROGMEM ManufacturerString =
* and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor. * Descriptor.
*/ */
USB_Descriptor_String_t PROGMEM ProductString = USB_Descriptor_String_t PROGMEM USART_ProductString =
{ {
.Header = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String}, .Header = {.Size = USB_STRING_LEN(18), .Type = DTYPE_String},
.UnicodeString = L"LUFA XPLAIN Bridge" .UnicodeString = L"LUFA XPLAIN Bridge"
}; };
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" uint16_t USART_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)
* documentation) by the application code so that the address and size of a requested descriptor can be given
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
* USB host.
*/
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress)
{ {
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
...@@ -243,27 +237,27 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, ...@@ -243,27 +237,27 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex,
switch (DescriptorType) switch (DescriptorType)
{ {
case DTYPE_Device: case DTYPE_Device:
Address = (void*)&DeviceDescriptor; Address = (void*)&USART_DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t); Size = sizeof(USB_Descriptor_Device_t);
break; break;
case DTYPE_Configuration: case DTYPE_Configuration:
Address = (void*)&ConfigurationDescriptor; Address = (void*)&USART_ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t); Size = sizeof(USART_USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
switch (DescriptorNumber) switch (DescriptorNumber)
{ {
case 0x00: case 0x00:
Address = (void*)&LanguageString; Address = (void*)&USART_LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size); Size = pgm_read_byte(&USART_LanguageString.Header.Size);
break; break;
case 0x01: case 0x01:
Address = (void*)&ManufacturerString; Address = (void*)&USART_ManufacturerString;
Size = pgm_read_byte(&ManufacturerString.Header.Size); Size = pgm_read_byte(&USART_ManufacturerString.Header.Size);
break; break;
case 0x02: case 0x02:
Address = (void*)&ProductString; Address = (void*)&USART_ProductString;
Size = pgm_read_byte(&ProductString.Header.Size); Size = pgm_read_byte(&USART_ProductString.Header.Size);
break; break;
} }
......
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
/** \file /** \file
* *
* Header file for Descriptors.c. * Header file for USARTDescriptors.c.
*/ */
#ifndef _DESCRIPTORS_H_ #ifndef _USART_DESCRIPTORS_H_
#define _DESCRIPTORS_H_ #define _USART_DESCRIPTORS_H_
/* Includes: */ /* Includes: */
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
...@@ -56,8 +56,8 @@ ...@@ -56,8 +56,8 @@
#define CDC_NOTIFICATION_EPSIZE 8 #define CDC_NOTIFICATION_EPSIZE 8
/** Size in bytes of the CDC data IN and OUT endpoints. */ /** Size in bytes of the CDC data IN and OUT endpoints. */
#define CDC_TXRX_EPSIZE 16 #define CDC_TXRX_EPSIZE 16
/* Type Defines: */ /* Type Defines: */
/** Type define for the device configuration descriptor structure. This must be defined in the /** Type define for the device configuration descriptor structure. This must be defined in the
* application code, as the configuration descriptor contains several sub-descriptors which * application code, as the configuration descriptor contains several sub-descriptors which
...@@ -75,10 +75,9 @@ ...@@ -75,10 +75,9 @@
USB_Descriptor_Interface_t DCI_Interface; USB_Descriptor_Interface_t DCI_Interface;
USB_Descriptor_Endpoint_t DataOutEndpoint; USB_Descriptor_Endpoint_t DataOutEndpoint;
USB_Descriptor_Endpoint_t DataInEndpoint; USB_Descriptor_Endpoint_t DataInEndpoint;
} USB_Descriptor_Configuration_t; } USART_USB_Descriptor_Configuration_t;
/* Function Prototypes: */ /* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress) uint16_t USART_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress);
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif #endif
...@@ -36,11 +36,8 @@ ...@@ -36,11 +36,8 @@
#include "XPLAINBridge.h" #include "XPLAINBridge.h"
/** Circular buffer to hold data from the host before it is sent to the device via the serial port. */ /* Current firmware mode, making the device behave as either a programmer or a USART bridge */
RingBuff_t USBtoUART_Buffer; bool CurrentFirmwareMode = MODE_PDI_PROGRAMMER;
/** Circular buffer to hold data from the serial port before it is sent to the host. */
RingBuff_t UARTtoUSB_Buffer;
/** LUFA CDC Class driver interface configuration and state information. This structure is /** LUFA CDC Class driver interface configuration and state information. This structure is
* passed to all CDC Class driver functions, so that multiple instances of the same class * passed to all CDC Class driver functions, so that multiple instances of the same class
...@@ -65,6 +62,13 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = ...@@ -65,6 +62,13 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
.NotificationEndpointDoubleBank = false, .NotificationEndpointDoubleBank = false,
}, },
}; };
/** Circular buffer to hold data from the host before it is sent to the device via the serial port. */
RingBuff_t USBtoUART_Buffer;
/** Circular buffer to hold data from the serial port before it is sent to the host. */
RingBuff_t UARTtoUSB_Buffer;
/** Main program entry point. This routine contains the overall program flow, including initial /** Main program entry point. This routine contains the overall program flow, including initial
* setup of all components and the main program loop.