Commit dfe50ff3 authored by Dean Camera's avatar Dean Camera
Browse files

Added ability to set the serial baud rate via the user's terminal in the XPLAINBridge project.

parent 40631e9f
......@@ -15,6 +15,7 @@
* - Added new SWAPENDIAN_16() and SWAPENDIAN_32() macros to Common.h for statically initialized variables at compile time
* - Added new Drivers/USB/LowLevel/Device.c file to house Device mode specific functions that are more complicated than simple macros
* - Added new AVRStudio 4 project files for all library demos, projects and bootloaders
* - Added ability to set the serial baud rate via the user's terminal in the XPLAINBridge project
*
* <b>Changed:</b>
* - The RingBuff library code has been replaced in the XPLAINBridge, Benito and USBtoSerial projects with an ultra lightweight
......
......@@ -118,7 +118,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.Data = {0x06}
},
.CDC_Functional_Union=
.CDC_Functional_Union =
{
.Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
.SubType = 0x06,
......
......@@ -130,7 +130,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.Data = {0x06}
},
.CDC_Functional_Union=
.CDC_Functional_Union =
{
.Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
.SubType = 0x06,
......
......@@ -63,12 +63,13 @@ void SoftUART_Init(void)
EICRA = (1 << ISC01);
EIMSK = (1 << INT0);
/* Set reception timer compare period and enable compare ISR */
OCR1A = BIT_TIME;
/* Set the transmission and reception timer compare values for the default baud rate */
SoftUART_SetBaud(9600);
/* Setup reception timer compare ISR */
TIMSK1 = (1 << OCIE1A);
/* Set transmission timer compare period, enable compare ISR and start the timer */
OCR3A = BIT_TIME;
/* Setup transmission timer compare ISR and start the timer */
TIMSK3 = (1 << OCIE3A);
TCCR3B = ((1 << CS30) | (1 << WGM32));
}
......
......@@ -42,9 +42,6 @@
#include "LightweightRingBuff.h"
/* Macros: */
#define BAUD 9600
#define BIT_TIME ((F_CPU / BAUD) - 1)
#define SRX PD0
#define SRXPIN PIND
#define SRXPORT PORTD
......@@ -53,6 +50,15 @@
#define STXPORT PORTD
#define STXDDR DDRD
/* Inline Functions: */
static inline void SoftUART_SetBaud(const uint32_t Baud)
{
uint16_t BitTime = ((F_CPU / Baud) - 1);
OCR1A = BitTime;
OCR3A = BitTime;
}
/* Function Prototypes: */
void SoftUART_Init(void);
......
......@@ -130,7 +130,7 @@ USART_USB_Descriptor_Configuration_t PROGMEM USART_ConfigurationDescriptor =
.Data = {0x06}
},
.CDC_Functional_Union=
.CDC_Functional_Union =
{
.Header = {.Size = sizeof(CDC_FUNCTIONAL_DESCRIPTOR(2)), .Type = 0x24},
.SubType = 0x06,
......
......@@ -225,6 +225,16 @@ void EVENT_USB_Device_Disconnect(void)
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
}
/** Event handler for the CDC Class driver Line Encoding Changed event.
*
* \param[in] CDCInterfaceInfo Pointer to the CDC class interface configuration structure being referenced
*/
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
{
/* Change the software UART's baud rate to match the new baud rate */
SoftUART_SetBaud(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);
}
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
* 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
......
......@@ -91,6 +91,8 @@
void EVENT_USB_Device_Connect(void);
void EVENT_USB_Device_Disconnect(void);
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo);
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex, void** const DescriptorAddress);
#endif
......@@ -54,12 +54,17 @@
* will enumerate as a regular COM port on the host, which can then be opened and data exchanged between the XMEGA and Host as if
* the XMEGA was connected directly to the host's serial port. If the pin is pulled low by shorting it to GND (pin 10), the device
* will enumerate as an AVRISP-MKII to the host, so that the XMEGA can be reprogrammed by AVRStudio or other compatible software
* such as avrdude.
* such as avrdude by connecting to the board as if it was an Atmel AVRISP-MKII programmer.
*
* After running this project for the first time on a new computer, you will need to supply the .INF file located in this project
* project's directory as the device's driver when running under Windows. This will enable Windows to use its inbuilt CDC drivers,
* negating the need for custom drivers for the device. Other Operating Systems should automatically use their own inbuilt CDC-ACM
* drivers.
* After running this project in serial bridge mode for the first time on a new computer, you will need to supply the .INF file
* located in this project project's directory as the device's driver when running under Windows. This will enable Windows to use
* its inbuilt CDC virtual serial drivers, negating the need for custom drivers for the device. Other Operating Systems should
* automatically use their own inbuilt CDC-ACM drivers.
*
* In serial bridge mode, the UART baud rate can be altered through the host terminal software to select a new baud rate - the default
* baud is 9600. Note that parity, data bits and stop bits are fixed at none, eight and one respectively can cannot be altered. Changes
* to the connection's parity, data bits or stop bits are ignored by the firmware. As the serial link between the controllers on the
* XPLAIN is software emulated by the USB AVR, not all baud rates will work correctly.
*
* This project relies on files from the LUFA AVRISP-MKII project for compilation.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment