Added ability to set the serial baud rate via the user's terminal in the XPLAINBridge...
authorDean Camera <dean@fourwalledcubicle.com>
Thu, 15 Jul 2010 11:01:31 +0000 (11:01 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Thu, 15 Jul 2010 11:01:31 +0000 (11:01 +0000)
LUFA/ManPages/ChangeLog.txt
Projects/Benito/Descriptors.c
Projects/USBtoSerial/Descriptors.c
Projects/XPLAINBridge/Lib/SoftUART.c
Projects/XPLAINBridge/Lib/SoftUART.h
Projects/XPLAINBridge/USARTDescriptors.c
Projects/XPLAINBridge/XPLAINBridge.c
Projects/XPLAINBridge/XPLAINBridge.h
Projects/XPLAINBridge/XPLAINBridge.txt

index a6f3a95..ffd1fcf 100644 (file)
@@ -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
index ef02625..3ca9dd9 100644 (file)
@@ -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,
index bb2ee10..c60da31 100644 (file)
@@ -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,
index 4ec8dcd..8710722 100644 (file)
@@ -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));
 }
index a107d48..d0b03c0 100644 (file)
@@ -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
                #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);
 
index 8acbacd..159f386 100644 (file)
@@ -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,
index 3bbc0bc..2e8e6a8 100644 (file)
@@ -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
index 3d257e5..fcb1776 100644 (file)
@@ -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
index f22feca..3f4647e 100644 (file)
  *  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.
  *