aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/XPLAINBridge
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-07-15 11:01:31 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-07-15 11:01:31 +0000
commitdfe50ff34970eda173cafbb3d636a5f7bedc87bd (patch)
treefa40f50761a29781d5d3b6e3b94a784a18a19bc2 /Projects/XPLAINBridge
parent40631e9fe5f0782c1fbc3019904d1298ac365cd1 (diff)
downloadlufa-dfe50ff34970eda173cafbb3d636a5f7bedc87bd.tar.gz
lufa-dfe50ff34970eda173cafbb3d636a5f7bedc87bd.tar.bz2
lufa-dfe50ff34970eda173cafbb3d636a5f7bedc87bd.zip
Added ability to set the serial baud rate via the user's terminal in the XPLAINBridge project.
Diffstat (limited to 'Projects/XPLAINBridge')
-rw-r--r--Projects/XPLAINBridge/Lib/SoftUART.c9
-rw-r--r--Projects/XPLAINBridge/Lib/SoftUART.h12
-rw-r--r--Projects/XPLAINBridge/USARTDescriptors.c2
-rw-r--r--Projects/XPLAINBridge/XPLAINBridge.c10
-rw-r--r--Projects/XPLAINBridge/XPLAINBridge.h2
-rw-r--r--Projects/XPLAINBridge/XPLAINBridge.txt15
6 files changed, 37 insertions, 13 deletions
diff --git a/Projects/XPLAINBridge/Lib/SoftUART.c b/Projects/XPLAINBridge/Lib/SoftUART.c
index 4ec8dcdc8..8710722e4 100644
--- a/Projects/XPLAINBridge/Lib/SoftUART.c
+++ b/Projects/XPLAINBridge/Lib/SoftUART.c
@@ -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));
}
diff --git a/Projects/XPLAINBridge/Lib/SoftUART.h b/Projects/XPLAINBridge/Lib/SoftUART.h
index a107d48a8..d0b03c04b 100644
--- a/Projects/XPLAINBridge/Lib/SoftUART.h
+++ b/Projects/XPLAINBridge/Lib/SoftUART.h
@@ -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);
diff --git a/Projects/XPLAINBridge/USARTDescriptors.c b/Projects/XPLAINBridge/USARTDescriptors.c
index 8acbacd2a..159f38609 100644
--- a/Projects/XPLAINBridge/USARTDescriptors.c
+++ b/Projects/XPLAINBridge/USARTDescriptors.c
@@ -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,
diff --git a/Projects/XPLAINBridge/XPLAINBridge.c b/Projects/XPLAINBridge/XPLAINBridge.c
index 3bbc0bc65..2e8e6a89e 100644
--- a/Projects/XPLAINBridge/XPLAINBridge.c
+++ b/Projects/XPLAINBridge/XPLAINBridge.c
@@ -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
diff --git a/Projects/XPLAINBridge/XPLAINBridge.h b/Projects/XPLAINBridge/XPLAINBridge.h
index 3d257e5ae..fcb177633 100644
--- a/Projects/XPLAINBridge/XPLAINBridge.h
+++ b/Projects/XPLAINBridge/XPLAINBridge.h
@@ -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
diff --git a/Projects/XPLAINBridge/XPLAINBridge.txt b/Projects/XPLAINBridge/XPLAINBridge.txt
index f22feca8e..3f4647e61 100644
--- a/Projects/XPLAINBridge/XPLAINBridge.txt
+++ b/Projects/XPLAINBridge/XPLAINBridge.txt
@@ -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.
*