From cf22a744ec0da3b68c4ffdb14c6fa43f2e07542f Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 7 Dec 2009 04:35:59 +0000 Subject: Additional file renames and modifications to change CDC demos to VirtualSerial. --- .../ClassDriver/DualVirtualSerial/Doxygen.conf | 2 +- .../Device/ClassDriver/DualVirtualSerial/DualCDC.c | 191 ------------ .../Device/ClassDriver/DualVirtualSerial/DualCDC.h | 75 ----- .../ClassDriver/DualVirtualSerial/DualCDC.txt | 84 ------ .../DualVirtualSerial/DualVirtualSerial.c | 191 ++++++++++++ .../DualVirtualSerial/DualVirtualSerial.h | 75 +++++ .../DualVirtualSerial/DualVirtualSerial.txt | 84 ++++++ .../ClassDriver/DualVirtualSerial/LUFA DualCDC.inf | 106 ------- .../DualVirtualSerial/LUFA DualVirtualSerial.inf | 106 +++++++ .../Device/ClassDriver/DualVirtualSerial/makefile | 2 +- Demos/Device/ClassDriver/VirtualSerial/CDC.c | 166 ----------- Demos/Device/ClassDriver/VirtualSerial/CDC.h | 76 ----- Demos/Device/ClassDriver/VirtualSerial/CDC.txt | 72 ----- .../Device/ClassDriver/VirtualSerial/Doxygen.conf | 2 +- .../Device/ClassDriver/VirtualSerial/LUFA CDC.inf | 106 ------- .../VirtualSerial/LUFA VirtualSerial.inf | 106 +++++++ .../ClassDriver/VirtualSerial/VirtualSerial.c | 166 +++++++++++ .../ClassDriver/VirtualSerial/VirtualSerial.h | 76 +++++ .../ClassDriver/VirtualSerial/VirtualSerial.txt | 72 +++++ Demos/Device/ClassDriver/VirtualSerial/makefile | 2 +- .../ClassDriver/VirtualSerialMouse/CDCMouse.c | 240 --------------- .../ClassDriver/VirtualSerialMouse/CDCMouse.h | 82 ------ .../ClassDriver/VirtualSerialMouse/CDCMouse.txt | 75 ----- .../ClassDriver/VirtualSerialMouse/Doxygen.conf | 2 +- .../VirtualSerialMouse/LUFA CDCMouse.inf | 106 ------- .../VirtualSerialMouse/LUFA VirtualSerialMouse.inf | 106 +++++++ .../VirtualSerialMouse/VirtualSerialMouse.c | 240 +++++++++++++++ .../VirtualSerialMouse/VirtualSerialMouse.h | 82 ++++++ .../VirtualSerialMouse/VirtualSerialMouse.txt | 75 +++++ .../Device/ClassDriver/VirtualSerialMouse/makefile | 2 +- Demos/Device/ClassDriver/makefile | 22 +- .../Device/LowLevel/DualVirtualSerial/Doxygen.conf | 2 +- Demos/Device/LowLevel/DualVirtualSerial/DualCDC.c | 323 -------------------- Demos/Device/LowLevel/DualVirtualSerial/DualCDC.h | 119 -------- .../Device/LowLevel/DualVirtualSerial/DualCDC.txt | 84 ------ .../LowLevel/DualVirtualSerial/DualVirtualSerial.c | 323 ++++++++++++++++++++ .../LowLevel/DualVirtualSerial/DualVirtualSerial.h | 119 ++++++++ .../DualVirtualSerial/DualVirtualSerial.txt | 84 ++++++ .../LowLevel/DualVirtualSerial/LUFA DualCDC.inf | 106 ------- .../DualVirtualSerial/LUFA DualVirtualSerial.inf | 106 +++++++ Demos/Device/LowLevel/DualVirtualSerial/makefile | 2 +- Demos/Device/LowLevel/VirtualSerial/CDC.c | 327 --------------------- Demos/Device/LowLevel/VirtualSerial/CDC.h | 183 ------------ Demos/Device/LowLevel/VirtualSerial/CDC.txt | 72 ----- Demos/Device/LowLevel/VirtualSerial/Doxygen.conf | 2 +- Demos/Device/LowLevel/VirtualSerial/LUFA CDC.inf | 106 ------- .../LowLevel/VirtualSerial/LUFA VirtualSerial.inf | 106 +++++++ .../Device/LowLevel/VirtualSerial/VirtualSerial.c | 327 +++++++++++++++++++++ .../Device/LowLevel/VirtualSerial/VirtualSerial.h | 183 ++++++++++++ .../LowLevel/VirtualSerial/VirtualSerial.txt | 72 +++++ Demos/Device/LowLevel/VirtualSerial/makefile | 2 +- Demos/Device/LowLevel/makefile | 14 +- 52 files changed, 2727 insertions(+), 2727 deletions(-) delete mode 100644 Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.c delete mode 100644 Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.h delete mode 100644 Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.txt create mode 100644 Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c create mode 100644 Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.h create mode 100644 Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt delete mode 100644 Demos/Device/ClassDriver/DualVirtualSerial/LUFA DualCDC.inf create mode 100644 Demos/Device/ClassDriver/DualVirtualSerial/LUFA DualVirtualSerial.inf delete mode 100644 Demos/Device/ClassDriver/VirtualSerial/CDC.c delete mode 100644 Demos/Device/ClassDriver/VirtualSerial/CDC.h delete mode 100644 Demos/Device/ClassDriver/VirtualSerial/CDC.txt delete mode 100644 Demos/Device/ClassDriver/VirtualSerial/LUFA CDC.inf create mode 100644 Demos/Device/ClassDriver/VirtualSerial/LUFA VirtualSerial.inf create mode 100644 Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c create mode 100644 Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.h create mode 100644 Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt delete mode 100644 Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.c delete mode 100644 Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.h delete mode 100644 Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.txt delete mode 100644 Demos/Device/ClassDriver/VirtualSerialMouse/LUFA CDCMouse.inf create mode 100644 Demos/Device/ClassDriver/VirtualSerialMouse/LUFA VirtualSerialMouse.inf create mode 100644 Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c create mode 100644 Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.h create mode 100644 Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt delete mode 100644 Demos/Device/LowLevel/DualVirtualSerial/DualCDC.c delete mode 100644 Demos/Device/LowLevel/DualVirtualSerial/DualCDC.h delete mode 100644 Demos/Device/LowLevel/DualVirtualSerial/DualCDC.txt create mode 100644 Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c create mode 100644 Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.h create mode 100644 Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt delete mode 100644 Demos/Device/LowLevel/DualVirtualSerial/LUFA DualCDC.inf create mode 100644 Demos/Device/LowLevel/DualVirtualSerial/LUFA DualVirtualSerial.inf delete mode 100644 Demos/Device/LowLevel/VirtualSerial/CDC.c delete mode 100644 Demos/Device/LowLevel/VirtualSerial/CDC.h delete mode 100644 Demos/Device/LowLevel/VirtualSerial/CDC.txt delete mode 100644 Demos/Device/LowLevel/VirtualSerial/LUFA CDC.inf create mode 100644 Demos/Device/LowLevel/VirtualSerial/LUFA VirtualSerial.inf create mode 100644 Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c create mode 100644 Demos/Device/LowLevel/VirtualSerial/VirtualSerial.h create mode 100644 Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt (limited to 'Demos/Device') diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/Doxygen.conf b/Demos/Device/ClassDriver/DualVirtualSerial/Doxygen.conf index 04af23b64..b505cf51a 100644 --- a/Demos/Device/ClassDriver/DualVirtualSerial/Doxygen.conf +++ b/Demos/Device/ClassDriver/DualVirtualSerial/Doxygen.conf @@ -25,7 +25,7 @@ DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = "LUFA Library - Dual CDC Device Demo" +PROJECT_NAME = "LUFA Library - Dual Virtual Serial Device Demo" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.c b/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.c deleted file mode 100644 index 000d18b9a..000000000 --- a/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Main source file for the DualCDC demo. This file contains the main tasks of - * the demo and is responsible for the initial application hardware configuration. - */ - -#include "DualCDC.h" - -/** 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 - * within a device can be differentiated from one another. This is for the first CDC interface, - * which sends strings to the host for each joystick movement. - */ -USB_ClassInfo_CDC_Device_t VirtualSerial1_CDC_Interface = - { - .Config = - { - .ControlInterfaceNumber = 0, - - .DataINEndpointNumber = CDC1_TX_EPNUM, - .DataINEndpointSize = CDC_TXRX_EPSIZE, - .DataINEndpointDoubleBank = false, - - .DataOUTEndpointNumber = CDC1_RX_EPNUM, - .DataOUTEndpointSize = CDC_TXRX_EPSIZE, - .DataOUTEndpointDoubleBank = false, - - .NotificationEndpointNumber = CDC1_NOTIFICATION_EPNUM, - .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, - .NotificationEndpointDoubleBank = false, - }, - }; - -/** 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 - * within a device can be differentiated from one another. This is for the second CDC interface, - * which echos back all received data from the host. - */ -USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface = - { - .Config = - { - .ControlInterfaceNumber = 2, - - .DataINEndpointNumber = CDC2_TX_EPNUM, - .DataINEndpointSize = CDC_TXRX_EPSIZE, - .DataINEndpointDoubleBank = false, - - .DataOUTEndpointNumber = CDC2_RX_EPNUM, - .DataOUTEndpointSize = CDC_TXRX_EPSIZE, - .DataOUTEndpointDoubleBank = false, - - .NotificationEndpointNumber = CDC2_NOTIFICATION_EPNUM, - .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, - .NotificationEndpointDoubleBank = false, - }, - }; - -/** Main program entry point. This routine contains the overall program flow, including initial - * setup of all components and the main program loop. - */ -int main(void) -{ - SetupHardware(); - - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - - for (;;) - { - CheckJoystickMovement(); - - /* Discard all received data on the first CDC interface */ - while (CDC_Device_BytesReceived(&VirtualSerial1_CDC_Interface)) - CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface); - - /* Echo all received data on the second CDC interface */ - while (CDC_Device_BytesReceived(&VirtualSerial2_CDC_Interface)) - CDC_Device_SendByte(&VirtualSerial2_CDC_Interface, CDC_Device_ReceiveByte(&VirtualSerial2_CDC_Interface)); - - CDC_Device_USBTask(&VirtualSerial1_CDC_Interface); - CDC_Device_USBTask(&VirtualSerial2_CDC_Interface); - USB_USBTask(); - } -} - -/** Configures the board hardware and chip peripherals for the demo's functionality. */ -void SetupHardware(void) -{ - /* Disable watchdog if enabled by bootloader/fuses */ - MCUSR &= ~(1 << WDRF); - wdt_disable(); - - /* Disable clock division */ - clock_prescale_set(clock_div_1); - - /* Hardware Initialization */ - Joystick_Init(); - LEDs_Init(); - USB_Init(); -} - -/** Checks for changes in the position of the board joystick, sending strings to the host upon each change - * through the first of the CDC interfaces. - */ -void CheckJoystickMovement(void) -{ - uint8_t JoyStatus_LCL = Joystick_GetStatus(); - char* ReportString = NULL; - static bool ActionSent = false; - - if (JoyStatus_LCL & JOY_UP) - ReportString = "Joystick Up\r\n"; - else if (JoyStatus_LCL & JOY_DOWN) - ReportString = "Joystick Down\r\n"; - else if (JoyStatus_LCL & JOY_LEFT) - ReportString = "Joystick Left\r\n"; - else if (JoyStatus_LCL & JOY_RIGHT) - ReportString = "Joystick Right\r\n"; - else if (JoyStatus_LCL & JOY_PRESS) - ReportString = "Joystick Pressed\r\n"; - else - ActionSent = false; - - if ((ReportString != NULL) && (ActionSent == false)) - { - ActionSent = true; - - CDC_Device_SendString(&VirtualSerial1_CDC_Interface, ReportString, strlen(ReportString)); - } -} - -/** Event handler for the library USB Connection event. */ -void EVENT_USB_Device_Connect(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); -} - -/** Event handler for the library USB Disconnection event. */ -void EVENT_USB_Device_Disconnect(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); -} - -/** Event handler for the library USB Configuration Changed event. */ -void EVENT_USB_Device_ConfigurationChanged(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_READY); - - if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial1_CDC_Interface))) - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - - if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial2_CDC_Interface))) - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); -} - -/** Event handler for the library USB Unhandled Control Request event. */ -void EVENT_USB_Device_UnhandledControlRequest(void) -{ - CDC_Device_ProcessControlRequest(&VirtualSerial1_CDC_Interface); - CDC_Device_ProcessControlRequest(&VirtualSerial2_CDC_Interface); -} diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.h b/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.h deleted file mode 100644 index 2f12aca88..000000000 --- a/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for DualCDC.c. - */ - -#ifndef _DUAL_CDC_H_ -#define _DUAL_CDC_H_ - - /* Includes: */ - #include - #include - #include - #include - - #include "Descriptors.h" - - #include - #include - #include - #include - #include - - /* Macros: */ - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /* Function Prototypes: */ - void SetupHardware(void); - void CheckJoystickMovement(void); - - void EVENT_USB_Device_Connect(void); - void EVENT_USB_Device_Disconnect(void); - void EVENT_USB_Device_ConfigurationChanged(void); - void EVENT_USB_Device_UnhandledControlRequest(void); - -#endif diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.txt b/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.txt deleted file mode 100644 index 761769e3c..000000000 --- a/Demos/Device/ClassDriver/DualVirtualSerial/DualCDC.txt +++ /dev/null @@ -1,84 +0,0 @@ -/** \file - * - * This file contains special DoxyGen information for the generation of the main page and other special - * documentation pages. It is not a project source file. - */ - -/** \mainpage Dual Communications Device Class (Dual Virtual Serial Port) Device - * - * \section SSec_Compat Demo Compatibility: - * - * The following list indicates what microcontrollers are compatible with this demo. - * - * - Series 7 USB AVRs - * - Series 6 USB AVRs - * - Series 4 USB AVRs - * - Series 2 USB AVRs - * - * \section SSec_Info USB Information: - * - * The following table gives a rundown of the USB utilization of this demo. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
USB Mode:Device
USB Class:Miscellaneous Device Class( Sub-Interface: Communications Device Class (CDC) )
USB Subclass:Common Class( Sub-Interface: Abstract Control Model (ACM) )
Relevant Standards:USBIF Interface Association Descriptor ECNUSBIF CDC Class Standard
Usable Speeds:Full Speed Mode
- * - * \section SSec_Description Project Description: - * - * Dual Communications Device Class demonstration application. - * This gives a simple reference application for implementing - * a compound device with dual CDC functions acting as a pair - * of virtual serial ports. This demo uses Interface Association - * Descriptors to link together the pair of related CDC - * descriptors for each virtual serial port, which may not be - * supported in all OSes - Windows Vista is supported, as is - * XP (although the latter may need a hotfix to function). - * - * Joystick actions are transmitted to the host as strings - * through the first serial port. The device does not respond to - * serial data sent from the host in the first serial port. - * - * The second serial port echoes back data sent from the host. - * - * After running this demo for the first time on a new computer, - * you will need to supply the .INF file located in this demo - * 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. - * - * \section SSec_Options Project Options - * - * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. - * - * - * - * - * - *
- * None - *
- */ \ No newline at end of file diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c new file mode 100644 index 000000000..000d18b9a --- /dev/null +++ b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.c @@ -0,0 +1,191 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Main source file for the DualCDC demo. This file contains the main tasks of + * the demo and is responsible for the initial application hardware configuration. + */ + +#include "DualCDC.h" + +/** 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 + * within a device can be differentiated from one another. This is for the first CDC interface, + * which sends strings to the host for each joystick movement. + */ +USB_ClassInfo_CDC_Device_t VirtualSerial1_CDC_Interface = + { + .Config = + { + .ControlInterfaceNumber = 0, + + .DataINEndpointNumber = CDC1_TX_EPNUM, + .DataINEndpointSize = CDC_TXRX_EPSIZE, + .DataINEndpointDoubleBank = false, + + .DataOUTEndpointNumber = CDC1_RX_EPNUM, + .DataOUTEndpointSize = CDC_TXRX_EPSIZE, + .DataOUTEndpointDoubleBank = false, + + .NotificationEndpointNumber = CDC1_NOTIFICATION_EPNUM, + .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, + .NotificationEndpointDoubleBank = false, + }, + }; + +/** 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 + * within a device can be differentiated from one another. This is for the second CDC interface, + * which echos back all received data from the host. + */ +USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface = + { + .Config = + { + .ControlInterfaceNumber = 2, + + .DataINEndpointNumber = CDC2_TX_EPNUM, + .DataINEndpointSize = CDC_TXRX_EPSIZE, + .DataINEndpointDoubleBank = false, + + .DataOUTEndpointNumber = CDC2_RX_EPNUM, + .DataOUTEndpointSize = CDC_TXRX_EPSIZE, + .DataOUTEndpointDoubleBank = false, + + .NotificationEndpointNumber = CDC2_NOTIFICATION_EPNUM, + .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, + .NotificationEndpointDoubleBank = false, + }, + }; + +/** Main program entry point. This routine contains the overall program flow, including initial + * setup of all components and the main program loop. + */ +int main(void) +{ + SetupHardware(); + + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); + + for (;;) + { + CheckJoystickMovement(); + + /* Discard all received data on the first CDC interface */ + while (CDC_Device_BytesReceived(&VirtualSerial1_CDC_Interface)) + CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface); + + /* Echo all received data on the second CDC interface */ + while (CDC_Device_BytesReceived(&VirtualSerial2_CDC_Interface)) + CDC_Device_SendByte(&VirtualSerial2_CDC_Interface, CDC_Device_ReceiveByte(&VirtualSerial2_CDC_Interface)); + + CDC_Device_USBTask(&VirtualSerial1_CDC_Interface); + CDC_Device_USBTask(&VirtualSerial2_CDC_Interface); + USB_USBTask(); + } +} + +/** Configures the board hardware and chip peripherals for the demo's functionality. */ +void SetupHardware(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + /* Hardware Initialization */ + Joystick_Init(); + LEDs_Init(); + USB_Init(); +} + +/** Checks for changes in the position of the board joystick, sending strings to the host upon each change + * through the first of the CDC interfaces. + */ +void CheckJoystickMovement(void) +{ + uint8_t JoyStatus_LCL = Joystick_GetStatus(); + char* ReportString = NULL; + static bool ActionSent = false; + + if (JoyStatus_LCL & JOY_UP) + ReportString = "Joystick Up\r\n"; + else if (JoyStatus_LCL & JOY_DOWN) + ReportString = "Joystick Down\r\n"; + else if (JoyStatus_LCL & JOY_LEFT) + ReportString = "Joystick Left\r\n"; + else if (JoyStatus_LCL & JOY_RIGHT) + ReportString = "Joystick Right\r\n"; + else if (JoyStatus_LCL & JOY_PRESS) + ReportString = "Joystick Pressed\r\n"; + else + ActionSent = false; + + if ((ReportString != NULL) && (ActionSent == false)) + { + ActionSent = true; + + CDC_Device_SendString(&VirtualSerial1_CDC_Interface, ReportString, strlen(ReportString)); + } +} + +/** Event handler for the library USB Connection event. */ +void EVENT_USB_Device_Connect(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); +} + +/** Event handler for the library USB Disconnection event. */ +void EVENT_USB_Device_Disconnect(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); +} + +/** Event handler for the library USB Configuration Changed event. */ +void EVENT_USB_Device_ConfigurationChanged(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_READY); + + if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial1_CDC_Interface))) + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial2_CDC_Interface))) + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); +} + +/** Event handler for the library USB Unhandled Control Request event. */ +void EVENT_USB_Device_UnhandledControlRequest(void) +{ + CDC_Device_ProcessControlRequest(&VirtualSerial1_CDC_Interface); + CDC_Device_ProcessControlRequest(&VirtualSerial2_CDC_Interface); +} diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.h b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.h new file mode 100644 index 000000000..2f12aca88 --- /dev/null +++ b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.h @@ -0,0 +1,75 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for DualCDC.c. + */ + +#ifndef _DUAL_CDC_H_ +#define _DUAL_CDC_H_ + + /* Includes: */ + #include + #include + #include + #include + + #include "Descriptors.h" + + #include + #include + #include + #include + #include + + /* Macros: */ + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /* Function Prototypes: */ + void SetupHardware(void); + void CheckJoystickMovement(void); + + void EVENT_USB_Device_Connect(void); + void EVENT_USB_Device_Disconnect(void); + void EVENT_USB_Device_ConfigurationChanged(void); + void EVENT_USB_Device_UnhandledControlRequest(void); + +#endif diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt new file mode 100644 index 000000000..761769e3c --- /dev/null +++ b/Demos/Device/ClassDriver/DualVirtualSerial/DualVirtualSerial.txt @@ -0,0 +1,84 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \mainpage Dual Communications Device Class (Dual Virtual Serial Port) Device + * + * \section SSec_Compat Demo Compatibility: + * + * The following list indicates what microcontrollers are compatible with this demo. + * + * - Series 7 USB AVRs + * - Series 6 USB AVRs + * - Series 4 USB AVRs + * - Series 2 USB AVRs + * + * \section SSec_Info USB Information: + * + * The following table gives a rundown of the USB utilization of this demo. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
USB Mode:Device
USB Class:Miscellaneous Device Class( Sub-Interface: Communications Device Class (CDC) )
USB Subclass:Common Class( Sub-Interface: Abstract Control Model (ACM) )
Relevant Standards:USBIF Interface Association Descriptor ECNUSBIF CDC Class Standard
Usable Speeds:Full Speed Mode
+ * + * \section SSec_Description Project Description: + * + * Dual Communications Device Class demonstration application. + * This gives a simple reference application for implementing + * a compound device with dual CDC functions acting as a pair + * of virtual serial ports. This demo uses Interface Association + * Descriptors to link together the pair of related CDC + * descriptors for each virtual serial port, which may not be + * supported in all OSes - Windows Vista is supported, as is + * XP (although the latter may need a hotfix to function). + * + * Joystick actions are transmitted to the host as strings + * through the first serial port. The device does not respond to + * serial data sent from the host in the first serial port. + * + * The second serial port echoes back data sent from the host. + * + * After running this demo for the first time on a new computer, + * you will need to supply the .INF file located in this demo + * 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. + * + * \section SSec_Options Project Options + * + * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. + * + * + * + * + * + *
+ * None + *
+ */ \ No newline at end of file diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/LUFA DualCDC.inf b/Demos/Device/ClassDriver/DualVirtualSerial/LUFA DualCDC.inf deleted file mode 100644 index 741bf28eb..000000000 --- a/Demos/Device/ClassDriver/DualVirtualSerial/LUFA DualCDC.inf +++ /dev/null @@ -1,106 +0,0 @@ -;************************************************************ -; Windows USB CDC ACM Setup File -; Copyright (c) 2000 Microsoft Corporation - - -[Version] -Signature="$Windows NT$" -Class=Ports -ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} -Provider=%MFGNAME% -LayoutFile=layout.inf -CatalogFile=%MFGFILENAME%.cat -DriverVer=11/15/2007,5.1.2600.0 - -[Manufacturer] -%MFGNAME%=DeviceList, NTamd64 - -[DestinationDirs] -DefaultDestDir=12 - - -;------------------------------------------------------------------------------ -; Windows 2000/XP/Vista-32bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.nt] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.nt -AddReg=DriverInstall.nt.AddReg - -[DriverCopyFiles.nt] -usbser.sys,,,0x20 - -[DriverInstall.nt.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.nt.Services] -AddService=usbser, 0x00000002, DriverService.nt - -[DriverService.nt] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - -;------------------------------------------------------------------------------ -; Vista-64bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.NTamd64] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.NTamd64 -AddReg=DriverInstall.NTamd64.AddReg - -[DriverCopyFiles.NTamd64] -%DRIVERFILENAME%.sys,,,0x20 - -[DriverInstall.NTamd64.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.NTamd64.Services] -AddService=usbser, 0x00000002, DriverService.NTamd64 - -[DriverService.NTamd64] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - - -;------------------------------------------------------------------------------ -; Vendor and Product ID Definitions -;------------------------------------------------------------------------------ -; When developing your USB device, the VID and PID used in the PC side -; application program and the firmware on the microcontroller must match. -; Modify the below line to use your VID and PID. Use the format as shown below. -; Note: One INF file can be used for multiple devices with different VID and PIDs. -; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. -;------------------------------------------------------------------------------ -[SourceDisksFiles] -[SourceDisksNames] -[DeviceList] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02 - -[DeviceList.NTamd64] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02 - - -;------------------------------------------------------------------------------ -; String Definitions -;------------------------------------------------------------------------------ -;Modify these strings to customize your device -;------------------------------------------------------------------------------ -[Strings] -MFGFILENAME="CDC_vista" -DRIVERFILENAME ="usbser" -MFGNAME="CCS, Inc." -INSTDISK="LUFA Dual CDC Driver Installer" -DESCRIPTION="Communications Port" -SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/LUFA DualVirtualSerial.inf b/Demos/Device/ClassDriver/DualVirtualSerial/LUFA DualVirtualSerial.inf new file mode 100644 index 000000000..741bf28eb --- /dev/null +++ b/Demos/Device/ClassDriver/DualVirtualSerial/LUFA DualVirtualSerial.inf @@ -0,0 +1,106 @@ +;************************************************************ +; Windows USB CDC ACM Setup File +; Copyright (c) 2000 Microsoft Corporation + + +[Version] +Signature="$Windows NT$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%MFGNAME% +LayoutFile=layout.inf +CatalogFile=%MFGFILENAME%.cat +DriverVer=11/15/2007,5.1.2600.0 + +[Manufacturer] +%MFGNAME%=DeviceList, NTamd64 + +[DestinationDirs] +DefaultDestDir=12 + + +;------------------------------------------------------------------------------ +; Windows 2000/XP/Vista-32bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.nt] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.nt +AddReg=DriverInstall.nt.AddReg + +[DriverCopyFiles.nt] +usbser.sys,,,0x20 + +[DriverInstall.nt.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.nt.Services] +AddService=usbser, 0x00000002, DriverService.nt + +[DriverService.nt] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + +;------------------------------------------------------------------------------ +; Vista-64bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.NTamd64] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.NTamd64 +AddReg=DriverInstall.NTamd64.AddReg + +[DriverCopyFiles.NTamd64] +%DRIVERFILENAME%.sys,,,0x20 + +[DriverInstall.NTamd64.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.NTamd64.Services] +AddService=usbser, 0x00000002, DriverService.NTamd64 + +[DriverService.NTamd64] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + + +;------------------------------------------------------------------------------ +; Vendor and Product ID Definitions +;------------------------------------------------------------------------------ +; When developing your USB device, the VID and PID used in the PC side +; application program and the firmware on the microcontroller must match. +; Modify the below line to use your VID and PID. Use the format as shown below. +; Note: One INF file can be used for multiple devices with different VID and PIDs. +; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. +;------------------------------------------------------------------------------ +[SourceDisksFiles] +[SourceDisksNames] +[DeviceList] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02 + +[DeviceList.NTamd64] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02 + + +;------------------------------------------------------------------------------ +; String Definitions +;------------------------------------------------------------------------------ +;Modify these strings to customize your device +;------------------------------------------------------------------------------ +[Strings] +MFGFILENAME="CDC_vista" +DRIVERFILENAME ="usbser" +MFGNAME="CCS, Inc." +INSTDISK="LUFA Dual CDC Driver Installer" +DESCRIPTION="Communications Port" +SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/ClassDriver/DualVirtualSerial/makefile b/Demos/Device/ClassDriver/DualVirtualSerial/makefile index 466865a6d..d8cf086b8 100644 --- a/Demos/Device/ClassDriver/DualVirtualSerial/makefile +++ b/Demos/Device/ClassDriver/DualVirtualSerial/makefile @@ -102,7 +102,7 @@ FORMAT = ihex # Target file name (without extension). -TARGET = DualCDC +TARGET = DualVirtualSerial # Object files directory diff --git a/Demos/Device/ClassDriver/VirtualSerial/CDC.c b/Demos/Device/ClassDriver/VirtualSerial/CDC.c deleted file mode 100644 index 8940ae042..000000000 --- a/Demos/Device/ClassDriver/VirtualSerial/CDC.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Main source file for the CDC demo. This file contains the main tasks of - * the demo and is responsible for the initial application hardware configuration. - */ - -#include "CDC.h" - -/** 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 - * within a device can be differentiated from one another. - */ -USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = - { - .Config = - { - .ControlInterfaceNumber = 0, - - .DataINEndpointNumber = CDC_TX_EPNUM, - .DataINEndpointSize = CDC_TXRX_EPSIZE, - .DataINEndpointDoubleBank = false, - - .DataOUTEndpointNumber = CDC_RX_EPNUM, - .DataOUTEndpointSize = CDC_TXRX_EPSIZE, - .DataOUTEndpointDoubleBank = false, - - .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, - .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, - .NotificationEndpointDoubleBank = false, - }, - }; - -/** Standard file stream for the CDC interface when set up, so that the virtual CDC COM port can be - * used like any regular character stream in the C APIs - */ -static FILE USBSerialStream; - -/** Main program entry point. This routine contains the overall program flow, including initial - * setup of all components and the main program loop. - */ -int main(void) -{ - SetupHardware(); - - /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */ - CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream); - - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - - for (;;) - { - CheckJoystickMovement(); - - /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */ - while (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) - CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); - - CDC_Device_USBTask(&VirtualSerial_CDC_Interface); - USB_USBTask(); - } -} - -/** Configures the board hardware and chip peripherals for the demo's functionality. */ -void SetupHardware(void) -{ - /* Disable watchdog if enabled by bootloader/fuses */ - MCUSR &= ~(1 << WDRF); - wdt_disable(); - - /* Disable clock division */ - clock_prescale_set(clock_div_1); - - /* Hardware Initialization */ - Joystick_Init(); - LEDs_Init(); - USB_Init(); -} - -/** Checks for changes in the position of the board joystick, sending strings to the host upon each change. */ -void CheckJoystickMovement(void) -{ - uint8_t JoyStatus_LCL = Joystick_GetStatus(); - char* ReportString = NULL; - static bool ActionSent = false; - - if (JoyStatus_LCL & JOY_UP) - ReportString = "Joystick Up\r\n"; - else if (JoyStatus_LCL & JOY_DOWN) - ReportString = "Joystick Down\r\n"; - else if (JoyStatus_LCL & JOY_LEFT) - ReportString = "Joystick Left\r\n"; - else if (JoyStatus_LCL & JOY_RIGHT) - ReportString = "Joystick Right\r\n"; - else if (JoyStatus_LCL & JOY_PRESS) - ReportString = "Joystick Pressed\r\n"; - else - ActionSent = false; - - if ((ReportString != NULL) && (ActionSent == false)) - { - ActionSent = true; - - /* Write the string to the virtual COM port via the created character stream */ - fputs(ReportString, &USBSerialStream); - - /* Alternatively, without the stream: */ - // CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString, strlen(ReportString)); - } -} - -/** Event handler for the library USB Connection event. */ -void EVENT_USB_Device_Connect(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); -} - -/** Event handler for the library USB Disconnection event. */ -void EVENT_USB_Device_Disconnect(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); -} - -/** Event handler for the library USB Configuration Changed event. */ -void EVENT_USB_Device_ConfigurationChanged(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_READY); - - if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface))) - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); -} - -/** Event handler for the library USB Unhandled Control Request event. */ -void EVENT_USB_Device_UnhandledControlRequest(void) -{ - CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface); -} diff --git a/Demos/Device/ClassDriver/VirtualSerial/CDC.h b/Demos/Device/ClassDriver/VirtualSerial/CDC.h deleted file mode 100644 index 9cc72487c..000000000 --- a/Demos/Device/ClassDriver/VirtualSerial/CDC.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for CDC.c. - */ - -#ifndef _CDC_H_ -#define _CDC_H_ - - /* Includes: */ - #include - #include - #include - #include - #include - - #include "Descriptors.h" - - #include - #include - #include - #include - #include - - /* Macros: */ - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /* Function Prototypes: */ - void SetupHardware(void); - void CheckJoystickMovement(void); - - void EVENT_USB_Device_Connect(void); - void EVENT_USB_Device_Disconnect(void); - void EVENT_USB_Device_ConfigurationChanged(void); - void EVENT_USB_Device_UnhandledControlRequest(void); - -#endif diff --git a/Demos/Device/ClassDriver/VirtualSerial/CDC.txt b/Demos/Device/ClassDriver/VirtualSerial/CDC.txt deleted file mode 100644 index 49837354c..000000000 --- a/Demos/Device/ClassDriver/VirtualSerial/CDC.txt +++ /dev/null @@ -1,72 +0,0 @@ -/** \file - * - * This file contains special DoxyGen information for the generation of the main page and other special - * documentation pages. It is not a project source file. - */ - -/** \mainpage Communications Device Class (Virtual Serial Port) Demo - * - * \section SSec_Compat Demo Compatibility: - * - * The following list indicates what microcontrollers are compatible with this demo. - * - * - Series 7 USB AVRs - * - Series 6 USB AVRs - * - Series 4 USB AVRs - * - Series 2 USB AVRs - * - * \section SSec_Info USB Information: - * - * The following table gives a rundown of the USB utilization of this demo. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
USB Mode:Device
USB Class:Communications Device Class (CDC)
USB Subclass:Abstract Control Model (ACM)
Relevant Standards:USBIF CDC Class Standard
Usable Speeds:Full Speed Mode
- * - * \section SSec_Description Project Description: - * - * Communications Device Class demonstration application. - * This gives a simple reference application for implementing - * a CDC device acting as a virtual serial port. Joystick - * actions are transmitted to the host as strings. The device - * does not respond to serial data sent from the host. - * - * After running this demo for the first time on a new computer, - * you will need to supply the .INF file located in this demo - * 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. - * - * \section SSec_Options Project Options - * - * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. - * - * - * - * - * - *
- * None - *
- */ \ No newline at end of file diff --git a/Demos/Device/ClassDriver/VirtualSerial/Doxygen.conf b/Demos/Device/ClassDriver/VirtualSerial/Doxygen.conf index fa91d2207..57d102359 100644 --- a/Demos/Device/ClassDriver/VirtualSerial/Doxygen.conf +++ b/Demos/Device/ClassDriver/VirtualSerial/Doxygen.conf @@ -25,7 +25,7 @@ DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = "LUFA Library - CDC Device Demo" +PROJECT_NAME = "LUFA Library - Virtual Serial Device Demo" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/Demos/Device/ClassDriver/VirtualSerial/LUFA CDC.inf b/Demos/Device/ClassDriver/VirtualSerial/LUFA CDC.inf deleted file mode 100644 index 4cdf59435..000000000 --- a/Demos/Device/ClassDriver/VirtualSerial/LUFA CDC.inf +++ /dev/null @@ -1,106 +0,0 @@ -;************************************************************ -; Windows USB CDC ACM Setup File -; Copyright (c) 2000 Microsoft Corporation - - -[Version] -Signature="$Windows NT$" -Class=Ports -ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} -Provider=%MFGNAME% -LayoutFile=layout.inf -CatalogFile=%MFGFILENAME%.cat -DriverVer=11/15/2007,5.1.2600.0 - -[Manufacturer] -%MFGNAME%=DeviceList, NTamd64 - -[DestinationDirs] -DefaultDestDir=12 - - -;------------------------------------------------------------------------------ -; Windows 2000/XP/Vista-32bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.nt] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.nt -AddReg=DriverInstall.nt.AddReg - -[DriverCopyFiles.nt] -usbser.sys,,,0x20 - -[DriverInstall.nt.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.nt.Services] -AddService=usbser, 0x00000002, DriverService.nt - -[DriverService.nt] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - -;------------------------------------------------------------------------------ -; Vista-64bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.NTamd64] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.NTamd64 -AddReg=DriverInstall.NTamd64.AddReg - -[DriverCopyFiles.NTamd64] -%DRIVERFILENAME%.sys,,,0x20 - -[DriverInstall.NTamd64.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.NTamd64.Services] -AddService=usbser, 0x00000002, DriverService.NTamd64 - -[DriverService.NTamd64] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - - -;------------------------------------------------------------------------------ -; Vendor and Product ID Definitions -;------------------------------------------------------------------------------ -; When developing your USB device, the VID and PID used in the PC side -; application program and the firmware on the microcontroller must match. -; Modify the below line to use your VID and PID. Use the format as shown below. -; Note: One INF file can be used for multiple devices with different VID and PIDs. -; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. -;------------------------------------------------------------------------------ -[SourceDisksFiles] -[SourceDisksNames] -[DeviceList] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2044 - -[DeviceList.NTamd64] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2044 - - -;------------------------------------------------------------------------------ -; String Definitions -;------------------------------------------------------------------------------ -;Modify these strings to customize your device -;------------------------------------------------------------------------------ -[Strings] -MFGFILENAME="CDC_vista" -DRIVERFILENAME ="usbser" -MFGNAME="CCS, Inc." -INSTDISK="LUFA CDC Driver Installer" -DESCRIPTION="Communications Port" -SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/ClassDriver/VirtualSerial/LUFA VirtualSerial.inf b/Demos/Device/ClassDriver/VirtualSerial/LUFA VirtualSerial.inf new file mode 100644 index 000000000..4cdf59435 --- /dev/null +++ b/Demos/Device/ClassDriver/VirtualSerial/LUFA VirtualSerial.inf @@ -0,0 +1,106 @@ +;************************************************************ +; Windows USB CDC ACM Setup File +; Copyright (c) 2000 Microsoft Corporation + + +[Version] +Signature="$Windows NT$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%MFGNAME% +LayoutFile=layout.inf +CatalogFile=%MFGFILENAME%.cat +DriverVer=11/15/2007,5.1.2600.0 + +[Manufacturer] +%MFGNAME%=DeviceList, NTamd64 + +[DestinationDirs] +DefaultDestDir=12 + + +;------------------------------------------------------------------------------ +; Windows 2000/XP/Vista-32bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.nt] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.nt +AddReg=DriverInstall.nt.AddReg + +[DriverCopyFiles.nt] +usbser.sys,,,0x20 + +[DriverInstall.nt.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.nt.Services] +AddService=usbser, 0x00000002, DriverService.nt + +[DriverService.nt] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + +;------------------------------------------------------------------------------ +; Vista-64bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.NTamd64] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.NTamd64 +AddReg=DriverInstall.NTamd64.AddReg + +[DriverCopyFiles.NTamd64] +%DRIVERFILENAME%.sys,,,0x20 + +[DriverInstall.NTamd64.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.NTamd64.Services] +AddService=usbser, 0x00000002, DriverService.NTamd64 + +[DriverService.NTamd64] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + + +;------------------------------------------------------------------------------ +; Vendor and Product ID Definitions +;------------------------------------------------------------------------------ +; When developing your USB device, the VID and PID used in the PC side +; application program and the firmware on the microcontroller must match. +; Modify the below line to use your VID and PID. Use the format as shown below. +; Note: One INF file can be used for multiple devices with different VID and PIDs. +; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. +;------------------------------------------------------------------------------ +[SourceDisksFiles] +[SourceDisksNames] +[DeviceList] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2044 + +[DeviceList.NTamd64] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2044 + + +;------------------------------------------------------------------------------ +; String Definitions +;------------------------------------------------------------------------------ +;Modify these strings to customize your device +;------------------------------------------------------------------------------ +[Strings] +MFGFILENAME="CDC_vista" +DRIVERFILENAME ="usbser" +MFGNAME="CCS, Inc." +INSTDISK="LUFA CDC Driver Installer" +DESCRIPTION="Communications Port" +SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c new file mode 100644 index 000000000..8940ae042 --- /dev/null +++ b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.c @@ -0,0 +1,166 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Main source file for the CDC demo. This file contains the main tasks of + * the demo and is responsible for the initial application hardware configuration. + */ + +#include "CDC.h" + +/** 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 + * within a device can be differentiated from one another. + */ +USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = + { + .Config = + { + .ControlInterfaceNumber = 0, + + .DataINEndpointNumber = CDC_TX_EPNUM, + .DataINEndpointSize = CDC_TXRX_EPSIZE, + .DataINEndpointDoubleBank = false, + + .DataOUTEndpointNumber = CDC_RX_EPNUM, + .DataOUTEndpointSize = CDC_TXRX_EPSIZE, + .DataOUTEndpointDoubleBank = false, + + .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, + .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, + .NotificationEndpointDoubleBank = false, + }, + }; + +/** Standard file stream for the CDC interface when set up, so that the virtual CDC COM port can be + * used like any regular character stream in the C APIs + */ +static FILE USBSerialStream; + +/** Main program entry point. This routine contains the overall program flow, including initial + * setup of all components and the main program loop. + */ +int main(void) +{ + SetupHardware(); + + /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */ + CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream); + + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); + + for (;;) + { + CheckJoystickMovement(); + + /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */ + while (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) + CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); + + CDC_Device_USBTask(&VirtualSerial_CDC_Interface); + USB_USBTask(); + } +} + +/** Configures the board hardware and chip peripherals for the demo's functionality. */ +void SetupHardware(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + /* Hardware Initialization */ + Joystick_Init(); + LEDs_Init(); + USB_Init(); +} + +/** Checks for changes in the position of the board joystick, sending strings to the host upon each change. */ +void CheckJoystickMovement(void) +{ + uint8_t JoyStatus_LCL = Joystick_GetStatus(); + char* ReportString = NULL; + static bool ActionSent = false; + + if (JoyStatus_LCL & JOY_UP) + ReportString = "Joystick Up\r\n"; + else if (JoyStatus_LCL & JOY_DOWN) + ReportString = "Joystick Down\r\n"; + else if (JoyStatus_LCL & JOY_LEFT) + ReportString = "Joystick Left\r\n"; + else if (JoyStatus_LCL & JOY_RIGHT) + ReportString = "Joystick Right\r\n"; + else if (JoyStatus_LCL & JOY_PRESS) + ReportString = "Joystick Pressed\r\n"; + else + ActionSent = false; + + if ((ReportString != NULL) && (ActionSent == false)) + { + ActionSent = true; + + /* Write the string to the virtual COM port via the created character stream */ + fputs(ReportString, &USBSerialStream); + + /* Alternatively, without the stream: */ + // CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString, strlen(ReportString)); + } +} + +/** Event handler for the library USB Connection event. */ +void EVENT_USB_Device_Connect(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); +} + +/** Event handler for the library USB Disconnection event. */ +void EVENT_USB_Device_Disconnect(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); +} + +/** Event handler for the library USB Configuration Changed event. */ +void EVENT_USB_Device_ConfigurationChanged(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_READY); + + if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface))) + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); +} + +/** Event handler for the library USB Unhandled Control Request event. */ +void EVENT_USB_Device_UnhandledControlRequest(void) +{ + CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface); +} diff --git a/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.h b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.h new file mode 100644 index 000000000..9cc72487c --- /dev/null +++ b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.h @@ -0,0 +1,76 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for CDC.c. + */ + +#ifndef _CDC_H_ +#define _CDC_H_ + + /* Includes: */ + #include + #include + #include + #include + #include + + #include "Descriptors.h" + + #include + #include + #include + #include + #include + + /* Macros: */ + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /* Function Prototypes: */ + void SetupHardware(void); + void CheckJoystickMovement(void); + + void EVENT_USB_Device_Connect(void); + void EVENT_USB_Device_Disconnect(void); + void EVENT_USB_Device_ConfigurationChanged(void); + void EVENT_USB_Device_UnhandledControlRequest(void); + +#endif diff --git a/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt new file mode 100644 index 000000000..49837354c --- /dev/null +++ b/Demos/Device/ClassDriver/VirtualSerial/VirtualSerial.txt @@ -0,0 +1,72 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \mainpage Communications Device Class (Virtual Serial Port) Demo + * + * \section SSec_Compat Demo Compatibility: + * + * The following list indicates what microcontrollers are compatible with this demo. + * + * - Series 7 USB AVRs + * - Series 6 USB AVRs + * - Series 4 USB AVRs + * - Series 2 USB AVRs + * + * \section SSec_Info USB Information: + * + * The following table gives a rundown of the USB utilization of this demo. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
USB Mode:Device
USB Class:Communications Device Class (CDC)
USB Subclass:Abstract Control Model (ACM)
Relevant Standards:USBIF CDC Class Standard
Usable Speeds:Full Speed Mode
+ * + * \section SSec_Description Project Description: + * + * Communications Device Class demonstration application. + * This gives a simple reference application for implementing + * a CDC device acting as a virtual serial port. Joystick + * actions are transmitted to the host as strings. The device + * does not respond to serial data sent from the host. + * + * After running this demo for the first time on a new computer, + * you will need to supply the .INF file located in this demo + * 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. + * + * \section SSec_Options Project Options + * + * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. + * + * + * + * + * + *
+ * None + *
+ */ \ No newline at end of file diff --git a/Demos/Device/ClassDriver/VirtualSerial/makefile b/Demos/Device/ClassDriver/VirtualSerial/makefile index 8b67fd3ba..024bf9289 100644 --- a/Demos/Device/ClassDriver/VirtualSerial/makefile +++ b/Demos/Device/ClassDriver/VirtualSerial/makefile @@ -102,7 +102,7 @@ FORMAT = ihex # Target file name (without extension). -TARGET = CDC +TARGET = VirtualSerial # Object files directory diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.c b/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.c deleted file mode 100644 index d979e665c..000000000 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Main source file for the CDCMouse demo. This file contains the main tasks of - * the demo and is responsible for the initial application hardware configuration. - */ - -#include "CDCMouse.h" - -/** 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 - * within a device can be differentiated from one another. - */ -USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = - { - .Config = - { - .ControlInterfaceNumber = 0, - - .DataINEndpointNumber = CDC_TX_EPNUM, - .DataINEndpointSize = CDC_TXRX_EPSIZE, - .DataINEndpointDoubleBank = false, - - .DataOUTEndpointNumber = CDC_RX_EPNUM, - .DataOUTEndpointSize = CDC_TXRX_EPSIZE, - .DataOUTEndpointDoubleBank = false, - - .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, - .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, - .NotificationEndpointDoubleBank = false, - }, - }; - -/** Buffer to hold the previously generated Mouse HID report, for comparison purposes inside the HID class driver. */ -uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)]; - -/** LUFA HID Class driver interface configuration and state information. This structure is - * passed to all HID Class driver functions, so that multiple instances of the same class - * within a device can be differentiated from one another. - */ -USB_ClassInfo_HID_Device_t Mouse_HID_Interface = - { - .Config = - { - .InterfaceNumber = 0, - - .ReportINEndpointNumber = MOUSE_EPNUM, - .ReportINEndpointSize = MOUSE_EPSIZE, - .ReportINEndpointDoubleBank = false, - - .PrevReportINBuffer = PrevMouseHIDReportBuffer, - .PrevReportINBufferSize = sizeof(PrevMouseHIDReportBuffer), - }, - }; - -/** Main program entry point. This routine contains the overall program flow, including initial - * setup of all components and the main program loop. - */ -int main(void) -{ - SetupHardware(); - - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - - for (;;) - { - CheckJoystickMovement(); - - /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */ - while (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) - CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); - - CDC_Device_USBTask(&VirtualSerial_CDC_Interface); - HID_Device_USBTask(&Mouse_HID_Interface); - USB_USBTask(); - } -} - -/** Configures the board hardware and chip peripherals for the demo's functionality. */ -void SetupHardware(void) -{ - /* Disable watchdog if enabled by bootloader/fuses */ - MCUSR &= ~(1 << WDRF); - wdt_disable(); - - /* Disable clock division */ - clock_prescale_set(clock_div_1); - - /* Hardware Initialization */ - Joystick_Init(); - LEDs_Init(); - USB_Init(); -} - -/** Checks for changes in the position of the board joystick, sending strings to the host upon each change. */ -void CheckJoystickMovement(void) -{ - uint8_t JoyStatus_LCL = Joystick_GetStatus(); - char* ReportString = NULL; - static bool ActionSent = false; - - if (JoyStatus_LCL & JOY_UP) - ReportString = "Joystick Up\r\n"; - else if (JoyStatus_LCL & JOY_DOWN) - ReportString = "Joystick Down\r\n"; - else if (JoyStatus_LCL & JOY_LEFT) - ReportString = "Joystick Left\r\n"; - else if (JoyStatus_LCL & JOY_RIGHT) - ReportString = "Joystick Right\r\n"; - else if (JoyStatus_LCL & JOY_PRESS) - ReportString = "Joystick Pressed\r\n"; - else - ActionSent = false; - - if ((ReportString != NULL) && (ActionSent == false)) - { - ActionSent = true; - - CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString, strlen(ReportString)); - } -} - -/** Event handler for the library USB Connection event. */ -void EVENT_USB_Device_Connect(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); -} - -/** Event handler for the library USB Disconnection event. */ -void EVENT_USB_Device_Disconnect(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); -} - -/** Event handler for the library USB Configuration Changed event. */ -void EVENT_USB_Device_ConfigurationChanged(void) -{ - LEDs_SetAllLEDs(LEDMASK_USB_READY); - - if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface))) - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - - if (!(HID_Device_ConfigureEndpoints(&Mouse_HID_Interface))) - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - - USB_Device_EnableSOFEvents(); -} - -/** Event handler for the library USB Unhandled Control Request event. */ -void EVENT_USB_Device_UnhandledControlRequest(void) -{ - CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface); - HID_Device_ProcessControlRequest(&Mouse_HID_Interface); -} - -/** Event handler for the USB device Start Of Frame event. */ -void EVENT_USB_Device_StartOfFrame(void) -{ - HID_Device_MillisecondElapsed(&Mouse_HID_Interface); -} - -/** HID class driver callback function for the creation of HID reports to the host. - * - * \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced - * \param[in,out] ReportID Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID - * \param[in] ReportType Type of the report to create, either REPORT_ITEM_TYPE_In or REPORT_ITEM_TYPE_Feature - * \param[out] ReportData Pointer to a buffer where the created report should be stored - * \param[out] ReportSize Number of bytes written in the report (or zero if no report is to be sent - * - * \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent - */ -bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, - const uint8_t ReportType, void* ReportData, uint16_t* ReportSize) -{ - USB_MouseReport_Data_t* MouseReport = (USB_MouseReport_Data_t*)ReportData; - - uint8_t JoyStatus_LCL = Joystick_GetStatus(); - uint8_t ButtonStatus_LCL = Buttons_GetStatus(); - - if (JoyStatus_LCL & JOY_UP) - MouseReport->Y = -1; - else if (JoyStatus_LCL & JOY_DOWN) - MouseReport->Y = 1; - - if (JoyStatus_LCL & JOY_LEFT) - MouseReport->X = -1; - else if (JoyStatus_LCL & JOY_RIGHT) - MouseReport->X = 1; - - if (JoyStatus_LCL & JOY_PRESS) - MouseReport->Button = (1 << 0); - - if (ButtonStatus_LCL & BUTTONS_BUTTON1) - MouseReport->Button |= (1 << 1); - - *ReportSize = sizeof(USB_MouseReport_Data_t); - return true; -} - -/** HID class driver callback function for the processing of HID reports from the host. - * - * \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced - * \param[in] ReportID Report ID of the received report from the host - * \param[in] ReportData Pointer to a buffer where the created report has been stored - * \param[in] ReportSize Size in bytes of the received HID report - */ -void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, - const void* ReportData, const uint16_t ReportSize) -{ - // Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports -} diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.h b/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.h deleted file mode 100644 index bee1b0435..000000000 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for CDCMouse.c. - */ - -#ifndef _CDC_MOUSE_H_ -#define _CDC_MOUSE_H_ - - /* Includes: */ - #include - #include - #include - #include - - #include "Descriptors.h" - - #include - #include - #include - #include - #include - #include - #include - - /* Macros: */ - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /* Function Prototypes: */ - void SetupHardware(void); - void CheckJoystickMovement(void); - - void EVENT_USB_Device_Connect(void); - void EVENT_USB_Device_Disconnect(void); - void EVENT_USB_Device_ConfigurationChanged(void); - void EVENT_USB_Device_UnhandledControlRequest(void); - void EVENT_USB_Device_StartOfFrame(void); - - bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, - const uint8_t ReportType, void* ReportData, uint16_t* ReportSize); - void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, - const void* ReportData, const uint16_t ReportSize); -#endif diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.txt b/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.txt deleted file mode 100644 index ff0d8a361..000000000 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/CDCMouse.txt +++ /dev/null @@ -1,75 +0,0 @@ -/** \file - * - * This file contains special DoxyGen information for the generation of the main page and other special - * documentation pages. It is not a project source file. - */ - -/** \mainpage Combined Communications Device Class (Virtual Serial Port) and Mouse Demo - * - * \section SSec_Compat Demo Compatibility: - * - * The following list indicates what microcontrollers are compatible with this demo. - * - * - Series 7 USB AVRs - * - Series 6 USB AVRs - * - Series 4 USB AVRs - * - Series 2 USB AVRs - * - * \section SSec_Info USB Information: - * - * The following table gives a rundown of the USB utilization of this demo. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
USB Mode:Device
USB Class:Communications Device Class (CDC)Human Interface Device Class (HID)
USB Subclass:Abstract Control Model (ACM)Mouse Subclass
Relevant Standards:USBIF CDC Class StandardUSBIF HID Specification, USBIF HID Usage Tables
Usable Speeds:Full Speed Mode
- * - * \section SSec_Description Project Description: - * - * Combined Communications Device Class/Mouse demonstration application. - * This gives a simple reference application for implementing a combined - * CDC and HID device acting as a both a virtual serial port and a mouse. - * Joystick actions are transmitted to the host as strings and as mouse - * movements. The device does not respond to serial data sent from the host. - * - * After running this demo for the first time on a new computer, - * you will need to supply the .INF file located in this demo - * 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. - * - * \section SSec_Options Project Options - * - * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. - * - * - * - * - * - *
- * None - *
- */ \ No newline at end of file diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/Doxygen.conf b/Demos/Device/ClassDriver/VirtualSerialMouse/Doxygen.conf index 38e30f5f7..30849907a 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/Doxygen.conf +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/Doxygen.conf @@ -25,7 +25,7 @@ DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = "LUFA Library - Combined CDC and Mouse Device Demo" +PROJECT_NAME = "LUFA Library - Combined Virtual Serial and Mouse Device Demo" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/LUFA CDCMouse.inf b/Demos/Device/ClassDriver/VirtualSerialMouse/LUFA CDCMouse.inf deleted file mode 100644 index f15c93c2f..000000000 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/LUFA CDCMouse.inf +++ /dev/null @@ -1,106 +0,0 @@ -;************************************************************ -; Windows USB CDC ACM Setup File -; Copyright (c) 2000 Microsoft Corporation - - -[Version] -Signature="$Windows NT$" -Class=Ports -ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} -Provider=%MFGNAME% -LayoutFile=layout.inf -CatalogFile=%MFGFILENAME%.cat -DriverVer=11/15/2007,5.1.2600.0 - -[Manufacturer] -%MFGNAME%=DeviceList, NTamd64 - -[DestinationDirs] -DefaultDestDir=12 - - -;------------------------------------------------------------------------------ -; Windows 2000/XP/Vista-32bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.nt] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.nt -AddReg=DriverInstall.nt.AddReg - -[DriverCopyFiles.nt] -usbser.sys,,,0x20 - -[DriverInstall.nt.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.nt.Services] -AddService=usbser, 0x00000002, DriverService.nt - -[DriverService.nt] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - -;------------------------------------------------------------------------------ -; Vista-64bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.NTamd64] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.NTamd64 -AddReg=DriverInstall.NTamd64.AddReg - -[DriverCopyFiles.NTamd64] -%DRIVERFILENAME%.sys,,,0x20 - -[DriverInstall.NTamd64.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.NTamd64.Services] -AddService=usbser, 0x00000002, DriverService.NTamd64 - -[DriverService.NTamd64] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - - -;------------------------------------------------------------------------------ -; Vendor and Product ID Definitions -;------------------------------------------------------------------------------ -; When developing your USB device, the VID and PID used in the PC side -; application program and the firmware on the microcontroller must match. -; Modify the below line to use your VID and PID. Use the format as shown below. -; Note: One INF file can be used for multiple devices with different VID and PIDs. -; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. -;------------------------------------------------------------------------------ -[SourceDisksFiles] -[SourceDisksNames] -[DeviceList] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2062&MI_00 - -[DeviceList.NTamd64] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2062&MI_00 - - -;------------------------------------------------------------------------------ -; String Definitions -;------------------------------------------------------------------------------ -;Modify these strings to customize your device -;------------------------------------------------------------------------------ -[Strings] -MFGFILENAME="CDC_vista" -DRIVERFILENAME ="usbser" -MFGNAME="CCS, Inc." -INSTDISK="LUFA CDC/Mouse Driver Installer" -DESCRIPTION="Communications Port" -SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/LUFA VirtualSerialMouse.inf b/Demos/Device/ClassDriver/VirtualSerialMouse/LUFA VirtualSerialMouse.inf new file mode 100644 index 000000000..f15c93c2f --- /dev/null +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/LUFA VirtualSerialMouse.inf @@ -0,0 +1,106 @@ +;************************************************************ +; Windows USB CDC ACM Setup File +; Copyright (c) 2000 Microsoft Corporation + + +[Version] +Signature="$Windows NT$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%MFGNAME% +LayoutFile=layout.inf +CatalogFile=%MFGFILENAME%.cat +DriverVer=11/15/2007,5.1.2600.0 + +[Manufacturer] +%MFGNAME%=DeviceList, NTamd64 + +[DestinationDirs] +DefaultDestDir=12 + + +;------------------------------------------------------------------------------ +; Windows 2000/XP/Vista-32bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.nt] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.nt +AddReg=DriverInstall.nt.AddReg + +[DriverCopyFiles.nt] +usbser.sys,,,0x20 + +[DriverInstall.nt.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.nt.Services] +AddService=usbser, 0x00000002, DriverService.nt + +[DriverService.nt] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + +;------------------------------------------------------------------------------ +; Vista-64bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.NTamd64] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.NTamd64 +AddReg=DriverInstall.NTamd64.AddReg + +[DriverCopyFiles.NTamd64] +%DRIVERFILENAME%.sys,,,0x20 + +[DriverInstall.NTamd64.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.NTamd64.Services] +AddService=usbser, 0x00000002, DriverService.NTamd64 + +[DriverService.NTamd64] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + + +;------------------------------------------------------------------------------ +; Vendor and Product ID Definitions +;------------------------------------------------------------------------------ +; When developing your USB device, the VID and PID used in the PC side +; application program and the firmware on the microcontroller must match. +; Modify the below line to use your VID and PID. Use the format as shown below. +; Note: One INF file can be used for multiple devices with different VID and PIDs. +; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. +;------------------------------------------------------------------------------ +[SourceDisksFiles] +[SourceDisksNames] +[DeviceList] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2062&MI_00 + +[DeviceList.NTamd64] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2062&MI_00 + + +;------------------------------------------------------------------------------ +; String Definitions +;------------------------------------------------------------------------------ +;Modify these strings to customize your device +;------------------------------------------------------------------------------ +[Strings] +MFGFILENAME="CDC_vista" +DRIVERFILENAME ="usbser" +MFGNAME="CCS, Inc." +INSTDISK="LUFA CDC/Mouse Driver Installer" +DESCRIPTION="Communications Port" +SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c new file mode 100644 index 000000000..d979e665c --- /dev/null +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.c @@ -0,0 +1,240 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Main source file for the CDCMouse demo. This file contains the main tasks of + * the demo and is responsible for the initial application hardware configuration. + */ + +#include "CDCMouse.h" + +/** 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 + * within a device can be differentiated from one another. + */ +USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = + { + .Config = + { + .ControlInterfaceNumber = 0, + + .DataINEndpointNumber = CDC_TX_EPNUM, + .DataINEndpointSize = CDC_TXRX_EPSIZE, + .DataINEndpointDoubleBank = false, + + .DataOUTEndpointNumber = CDC_RX_EPNUM, + .DataOUTEndpointSize = CDC_TXRX_EPSIZE, + .DataOUTEndpointDoubleBank = false, + + .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, + .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, + .NotificationEndpointDoubleBank = false, + }, + }; + +/** Buffer to hold the previously generated Mouse HID report, for comparison purposes inside the HID class driver. */ +uint8_t PrevMouseHIDReportBuffer[sizeof(USB_MouseReport_Data_t)]; + +/** LUFA HID Class driver interface configuration and state information. This structure is + * passed to all HID Class driver functions, so that multiple instances of the same class + * within a device can be differentiated from one another. + */ +USB_ClassInfo_HID_Device_t Mouse_HID_Interface = + { + .Config = + { + .InterfaceNumber = 0, + + .ReportINEndpointNumber = MOUSE_EPNUM, + .ReportINEndpointSize = MOUSE_EPSIZE, + .ReportINEndpointDoubleBank = false, + + .PrevReportINBuffer = PrevMouseHIDReportBuffer, + .PrevReportINBufferSize = sizeof(PrevMouseHIDReportBuffer), + }, + }; + +/** Main program entry point. This routine contains the overall program flow, including initial + * setup of all components and the main program loop. + */ +int main(void) +{ + SetupHardware(); + + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); + + for (;;) + { + CheckJoystickMovement(); + + /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */ + while (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) + CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); + + CDC_Device_USBTask(&VirtualSerial_CDC_Interface); + HID_Device_USBTask(&Mouse_HID_Interface); + USB_USBTask(); + } +} + +/** Configures the board hardware and chip peripherals for the demo's functionality. */ +void SetupHardware(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + /* Hardware Initialization */ + Joystick_Init(); + LEDs_Init(); + USB_Init(); +} + +/** Checks for changes in the position of the board joystick, sending strings to the host upon each change. */ +void CheckJoystickMovement(void) +{ + uint8_t JoyStatus_LCL = Joystick_GetStatus(); + char* ReportString = NULL; + static bool ActionSent = false; + + if (JoyStatus_LCL & JOY_UP) + ReportString = "Joystick Up\r\n"; + else if (JoyStatus_LCL & JOY_DOWN) + ReportString = "Joystick Down\r\n"; + else if (JoyStatus_LCL & JOY_LEFT) + ReportString = "Joystick Left\r\n"; + else if (JoyStatus_LCL & JOY_RIGHT) + ReportString = "Joystick Right\r\n"; + else if (JoyStatus_LCL & JOY_PRESS) + ReportString = "Joystick Pressed\r\n"; + else + ActionSent = false; + + if ((ReportString != NULL) && (ActionSent == false)) + { + ActionSent = true; + + CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString, strlen(ReportString)); + } +} + +/** Event handler for the library USB Connection event. */ +void EVENT_USB_Device_Connect(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); +} + +/** Event handler for the library USB Disconnection event. */ +void EVENT_USB_Device_Disconnect(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); +} + +/** Event handler for the library USB Configuration Changed event. */ +void EVENT_USB_Device_ConfigurationChanged(void) +{ + LEDs_SetAllLEDs(LEDMASK_USB_READY); + + if (!(CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface))) + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + if (!(HID_Device_ConfigureEndpoints(&Mouse_HID_Interface))) + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + USB_Device_EnableSOFEvents(); +} + +/** Event handler for the library USB Unhandled Control Request event. */ +void EVENT_USB_Device_UnhandledControlRequest(void) +{ + CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface); + HID_Device_ProcessControlRequest(&Mouse_HID_Interface); +} + +/** Event handler for the USB device Start Of Frame event. */ +void EVENT_USB_Device_StartOfFrame(void) +{ + HID_Device_MillisecondElapsed(&Mouse_HID_Interface); +} + +/** HID class driver callback function for the creation of HID reports to the host. + * + * \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced + * \param[in,out] ReportID Report ID requested by the host if non-zero, otherwise callback should set to the generated report ID + * \param[in] ReportType Type of the report to create, either REPORT_ITEM_TYPE_In or REPORT_ITEM_TYPE_Feature + * \param[out] ReportData Pointer to a buffer where the created report should be stored + * \param[out] ReportSize Number of bytes written in the report (or zero if no report is to be sent + * + * \return Boolean true to force the sending of the report, false to let the library determine if it needs to be sent + */ +bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, + const uint8_t ReportType, void* ReportData, uint16_t* ReportSize) +{ + USB_MouseReport_Data_t* MouseReport = (USB_MouseReport_Data_t*)ReportData; + + uint8_t JoyStatus_LCL = Joystick_GetStatus(); + uint8_t ButtonStatus_LCL = Buttons_GetStatus(); + + if (JoyStatus_LCL & JOY_UP) + MouseReport->Y = -1; + else if (JoyStatus_LCL & JOY_DOWN) + MouseReport->Y = 1; + + if (JoyStatus_LCL & JOY_LEFT) + MouseReport->X = -1; + else if (JoyStatus_LCL & JOY_RIGHT) + MouseReport->X = 1; + + if (JoyStatus_LCL & JOY_PRESS) + MouseReport->Button = (1 << 0); + + if (ButtonStatus_LCL & BUTTONS_BUTTON1) + MouseReport->Button |= (1 << 1); + + *ReportSize = sizeof(USB_MouseReport_Data_t); + return true; +} + +/** HID class driver callback function for the processing of HID reports from the host. + * + * \param[in] HIDInterfaceInfo Pointer to the HID class interface configuration structure being referenced + * \param[in] ReportID Report ID of the received report from the host + * \param[in] ReportData Pointer to a buffer where the created report has been stored + * \param[in] ReportSize Size in bytes of the received HID report + */ +void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, + const void* ReportData, const uint16_t ReportSize) +{ + // Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports +} diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.h b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.h new file mode 100644 index 000000000..bee1b0435 --- /dev/null +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.h @@ -0,0 +1,82 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for CDCMouse.c. + */ + +#ifndef _CDC_MOUSE_H_ +#define _CDC_MOUSE_H_ + + /* Includes: */ + #include + #include + #include + #include + + #include "Descriptors.h" + + #include + #include + #include + #include + #include + #include + #include + + /* Macros: */ + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /* Function Prototypes: */ + void SetupHardware(void); + void CheckJoystickMovement(void); + + void EVENT_USB_Device_Connect(void); + void EVENT_USB_Device_Disconnect(void); + void EVENT_USB_Device_ConfigurationChanged(void); + void EVENT_USB_Device_UnhandledControlRequest(void); + void EVENT_USB_Device_StartOfFrame(void); + + bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, uint8_t* const ReportID, + const uint8_t ReportType, void* ReportData, uint16_t* ReportSize); + void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDInterfaceInfo, const uint8_t ReportID, + const void* ReportData, const uint16_t ReportSize); +#endif diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt new file mode 100644 index 000000000..ff0d8a361 --- /dev/null +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/VirtualSerialMouse.txt @@ -0,0 +1,75 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \mainpage Combined Communications Device Class (Virtual Serial Port) and Mouse Demo + * + * \section SSec_Compat Demo Compatibility: + * + * The following list indicates what microcontrollers are compatible with this demo. + * + * - Series 7 USB AVRs + * - Series 6 USB AVRs + * - Series 4 USB AVRs + * - Series 2 USB AVRs + * + * \section SSec_Info USB Information: + * + * The following table gives a rundown of the USB utilization of this demo. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
USB Mode:Device
USB Class:Communications Device Class (CDC)Human Interface Device Class (HID)
USB Subclass:Abstract Control Model (ACM)Mouse Subclass
Relevant Standards:USBIF CDC Class StandardUSBIF HID Specification, USBIF HID Usage Tables
Usable Speeds:Full Speed Mode
+ * + * \section SSec_Description Project Description: + * + * Combined Communications Device Class/Mouse demonstration application. + * This gives a simple reference application for implementing a combined + * CDC and HID device acting as a both a virtual serial port and a mouse. + * Joystick actions are transmitted to the host as strings and as mouse + * movements. The device does not respond to serial data sent from the host. + * + * After running this demo for the first time on a new computer, + * you will need to supply the .INF file located in this demo + * 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. + * + * \section SSec_Options Project Options + * + * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. + * + * + * + * + * + *
+ * None + *
+ */ \ No newline at end of file diff --git a/Demos/Device/ClassDriver/VirtualSerialMouse/makefile b/Demos/Device/ClassDriver/VirtualSerialMouse/makefile index 85e3e97a3..990760e85 100644 --- a/Demos/Device/ClassDriver/VirtualSerialMouse/makefile +++ b/Demos/Device/ClassDriver/VirtualSerialMouse/makefile @@ -102,7 +102,7 @@ FORMAT = ihex # Target file name (without extension). -TARGET = CDCMouse +TARGET = VirtualSerialMouse # Object files directory diff --git a/Demos/Device/ClassDriver/makefile b/Demos/Device/ClassDriver/makefile index 288e01fe4..13a317635 100644 --- a/Demos/Device/ClassDriver/makefile +++ b/Demos/Device/ClassDriver/makefile @@ -20,14 +20,8 @@ all: make -C AudioOutput clean make -C AudioOutput all - make -C CDC clean - make -C CDC all - - make -C CDCMouse clean - make -C CDCMouse all - - make -C DualCDC clean - make -C DualCDC all + make -C DualVirtualSerial clean + make -C DualVirtualSerial all make -C GenericHID clean make -C GenericHID all @@ -56,12 +50,16 @@ all: make -C RNDISEthernet clean make -C RNDISEthernet all + make -C VirtualSerial clean + make -C VirtualSerial all + + make -C VirtualSerialMouse clean + make -C VirtualSerialMouse all + %: make -C AudioInput $@ make -C AudioOutput $@ - make -C CDC $@ - make -C CDCMouse $@ - make -C DualCDC $@ + make -C DualVirtualSerial $@ make -C GenericHID $@ make -C Joystick $@ make -C Keyboard $@ @@ -71,3 +69,5 @@ all: make -C MIDI $@ make -C Mouse $@ make -C RNDISEthernet $@ + make -C VirtualSerial $@ + make -C VirtualSerialMouse $@ diff --git a/Demos/Device/LowLevel/DualVirtualSerial/Doxygen.conf b/Demos/Device/LowLevel/DualVirtualSerial/Doxygen.conf index 04af23b64..b505cf51a 100644 --- a/Demos/Device/LowLevel/DualVirtualSerial/Doxygen.conf +++ b/Demos/Device/LowLevel/DualVirtualSerial/Doxygen.conf @@ -25,7 +25,7 @@ DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = "LUFA Library - Dual CDC Device Demo" +PROJECT_NAME = "LUFA Library - Dual Virtual Serial Device Demo" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.c b/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.c deleted file mode 100644 index 8b1da0348..000000000 --- a/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Main source file for the DualCDC demo. This file contains the main tasks of the demo and - * is responsible for the initial application hardware configuration. - */ - -#include "DualCDC.h" - -/** Contains the current baud rate and other settings of the first virtual serial port. While this demo does not use - * the physical USART and thus does not use these settings, they must still be retained and returned to the host - * upon request or the host will assume the device is non-functional. - * - * These values are set by the host via a class-specific request, however they are not required to be used accurately. - * It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical - * serial link characteristics and instead sends and receives data in endpoint streams. - */ -CDC_Line_Coding_t LineEncoding1 = { .BaudRateBPS = 0, - .CharFormat = OneStopBit, - .ParityType = Parity_None, - .DataBits = 8 }; - -/** Contains the current baud rate and other settings of the second virtual serial port. While this demo does not use - * the physical USART and thus does not use these settings, they must still be retained and returned to the host - * upon request or the host will assume the device is non-functional. - * - * These values are set by the host via a class-specific request, however they are not required to be used accurately. - * It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical - * serial link characteristics and instead sends and receives data in endpoint streams. - */ -CDC_Line_Coding_t LineEncoding2 = { .BaudRateBPS = 0, - .CharFormat = OneStopBit, - .ParityType = Parity_None, - .DataBits = 8 }; - - -/** Main program entry point. This routine configures the hardware required by the application, then - * enters a loop to run the application tasks in sequence. - */ -int main(void) -{ - SetupHardware(); - - for (;;) - { - CDC1_Task(); - CDC2_Task(); - USB_USBTask(); - } -} - -/** Configures the board hardware and chip peripherals for the demo's functionality. */ -void SetupHardware(void) -{ - /* Disable watchdog if enabled by bootloader/fuses */ - MCUSR &= ~(1 << WDRF); - wdt_disable(); - - /* Disable clock division */ - clock_prescale_set(clock_div_1); - - /* Hardware Initialization */ - Joystick_Init(); - LEDs_Init(); - USB_Init(); -} - -/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and - * starts the library USB task to begin the enumeration and USB management process. - */ -void EVENT_USB_Device_Connect(void) -{ - /* Indicate USB enumerating */ - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); -} - -/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via - * the status LEDs and stops the USB management and CDC management tasks. - */ -void EVENT_USB_Device_Disconnect(void) -{ - /* Indicate USB not ready */ - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); -} - -/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration - * of the USB device after enumeration - the device endpoints are configured and the CDC management tasks are started. - */ -void EVENT_USB_Device_ConfigurationChanged(void) -{ - /* Indicate USB connected and ready */ - LEDs_SetAllLEDs(LEDMASK_USB_READY); - - /* Setup CDC Notification, Rx and Tx Endpoints for the first CDC */ - if (!(Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, - ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - if (!(Endpoint_ConfigureEndpoint(CDC1_TX_EPNUM, EP_TYPE_BULK, - ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - if (!(Endpoint_ConfigureEndpoint(CDC1_RX_EPNUM, EP_TYPE_BULK, - ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - /* Setup CDC Notification, Rx and Tx Endpoints for the second CDC */ - if (!(Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, - ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - if (!(Endpoint_ConfigureEndpoint(CDC2_TX_EPNUM, EP_TYPE_BULK, - ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - if (!(Endpoint_ConfigureEndpoint(CDC2_RX_EPNUM, EP_TYPE_BULK, - ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - /* Reset line encoding baud rates so that the host knows to send new values */ - LineEncoding1.BaudRateBPS = 0; - LineEncoding2.BaudRateBPS = 0; -} - -/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific - * control requests that are not handled internally by the USB library (including the CDC control commands, - * which are all issued via the control endpoint), so that they can be handled appropriately for the application. - */ -void EVENT_USB_Device_UnhandledControlRequest(void) -{ - /* Determine which interface's Line Coding data is being set from the wIndex parameter */ - uint8_t* LineEncodingData = (USB_ControlRequest.wIndex == 0) ? (uint8_t*)&LineEncoding1 : (uint8_t*)&LineEncoding2; - - /* Process CDC specific control requests */ - switch (USB_ControlRequest.bRequest) - { - case REQ_GetLineEncoding: - if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) - { - /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearSETUP(); - - /* Write the line coding data to the control endpoint */ - Endpoint_Write_Control_Stream_LE(LineEncodingData, sizeof(CDC_Line_Coding_t)); - - /* Finalize the stream transfer to send the last packet or clear the host abort */ - Endpoint_ClearOUT(); - } - - break; - case REQ_SetLineEncoding: - if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) - { - /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearSETUP(); - - /* Read the line coding data in from the host into the global struct */ - Endpoint_Read_Control_Stream_LE(LineEncodingData, sizeof(CDC_Line_Coding_t)); - - /* Finalize the stream transfer to clear the last packet from the host */ - Endpoint_ClearIN(); - } - - break; - case REQ_SetControlLineState: - if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) - { - /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearSETUP(); - - Endpoint_ClearStatusStage(); - } - - break; - } -} - -/** Function to manage CDC data transmission and reception to and from the host for the first CDC interface, which sends joystick - * movements to the host as ASCII strings. - */ -void CDC1_Task(void) -{ - char* ReportString = NULL; - uint8_t JoyStatus_LCL = Joystick_GetStatus(); - static bool ActionSent = false; - - /* Device must be connected and configured for the task to run */ - if (USB_DeviceState != DEVICE_STATE_Configured) - return; - - /* Determine if a joystick action has occurred */ - if (JoyStatus_LCL & JOY_UP) - ReportString = "Joystick Up\r\n"; - else if (JoyStatus_LCL & JOY_DOWN) - ReportString = "Joystick Down\r\n"; - else if (JoyStatus_LCL & JOY_LEFT) - ReportString = "Joystick Left\r\n"; - else if (JoyStatus_LCL & JOY_RIGHT) - ReportString = "Joystick Right\r\n"; - else if (JoyStatus_LCL & JOY_PRESS) - ReportString = "Joystick Pressed\r\n"; - else - ActionSent = false; - - /* Flag management - Only allow one string to be sent per action */ - if ((ReportString != NULL) && (ActionSent == false) && LineEncoding1.BaudRateBPS) - { - ActionSent = true; - - /* Select the Serial Tx Endpoint */ - Endpoint_SelectEndpoint(CDC1_TX_EPNUM); - - /* Write the String to the Endpoint */ - Endpoint_Write_Stream_LE(ReportString, strlen(ReportString)); - - /* Finalize the stream transfer to send the last packet */ - Endpoint_ClearIN(); - - /* Wait until the endpoint is ready for another packet */ - Endpoint_WaitUntilReady(); - - /* Send an empty packet to ensure that the host does not buffer data sent to it */ - Endpoint_ClearIN(); - } - - /* Select the Serial Rx Endpoint */ - Endpoint_SelectEndpoint(CDC1_RX_EPNUM); - - /* Throw away any received data from the host */ - if (Endpoint_IsOUTReceived()) - Endpoint_ClearOUT(); -} - -/** Function to manage CDC data transmission and reception to and from the host for the second CDC interface, which echoes back - * all data sent to it from the host. - */ -void CDC2_Task(void) -{ - /* Device must be connected and configured for the task to run */ - if (USB_DeviceState != DEVICE_STATE_Configured) - return; - - /* Select the Serial Rx Endpoint */ - Endpoint_SelectEndpoint(CDC2_RX_EPNUM); - - /* Check to see if any data has been received */ - if (Endpoint_IsOUTReceived()) - { - /* Create a temp buffer big enough to hold the incoming endpoint packet */ - uint8_t Buffer[Endpoint_BytesInEndpoint()]; - - /* Remember how large the incoming packet is */ - uint16_t DataLength = Endpoint_BytesInEndpoint(); - - /* Read in the incoming packet into the buffer */ - Endpoint_Read_Stream_LE(&Buffer, DataLength); - - /* Finalize the stream transfer to send the last packet */ - Endpoint_ClearOUT(); - - /* Select the Serial Tx Endpoint */ - Endpoint_SelectEndpoint(CDC2_TX_EPNUM); - - /* Write the received data to the endpoint */ - Endpoint_Write_Stream_LE(&Buffer, DataLength); - - /* Finalize the stream transfer to send the last packet */ - Endpoint_ClearIN(); - - /* Wait until the endpoint is ready for the next packet */ - Endpoint_WaitUntilReady(); - - /* Send an empty packet to prevent host buffering */ - Endpoint_ClearIN(); - } -} diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.h b/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.h deleted file mode 100644 index b2085c452..000000000 --- a/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for DualCDC.c. - */ - -#ifndef _DUAL_CDC_H_ -#define _DUAL_CDC_H_ - - /* Includes: */ - #include - #include - #include - #include - - #include "Descriptors.h" - - #include - #include - #include - #include - - /* Macros: */ - /** CDC Class specific request to get the current virtual serial port configuration settings. */ - #define REQ_GetLineEncoding 0x21 - - /** CDC Class specific request to set the current virtual serial port configuration settings. */ - #define REQ_SetLineEncoding 0x20 - - /** CDC Class specific request to set the current virtual serial port handshake line states. */ - #define REQ_SetControlLineState 0x22 - - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /* Type Defines: */ - /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration - * as set by the host via a class specific request. - */ - typedef struct - { - uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */ - uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the - * CDCDevice_CDC_LineCodingFormats_t enum - */ - uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the - * CDCDevice_LineCodingParity_t enum - */ - uint8_t DataBits; /**< Bits of data per character of the virtual serial port */ - } CDC_Line_Coding_t; - - /* Enums: */ - /** Enum for the possible line encoding formats of a virtual serial port. */ - enum CDCDevice_CDC_LineCodingFormats_t - { - OneStopBit = 0, /**< Each frame contains one stop bit */ - OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits */ - TwoStopBits = 2, /**< Each frame contains two stop bits */ - }; - - /** Enum for the possible line encoding parity settings of a virtual serial port. */ - enum CDCDevice_LineCodingParity_t - { - Parity_None = 0, /**< No parity bit mode on each frame */ - Parity_Odd = 1, /**< Odd parity bit mode on each frame */ - Parity_Even = 2, /**< Even parity bit mode on each frame */ - Parity_Mark = 3, /**< Mark parity bit mode on each frame */ - Parity_Space = 4, /**< Space parity bit mode on each frame */ - }; - - /* Function Prototypes: */ - void CDC1_Task(void); - void CDC2_Task(void); - void SetupHardware(void); - - void EVENT_USB_Device_Connect(void); - void EVENT_USB_Device_Disconnect(void); - void EVENT_USB_Device_ConfigurationChanged(void); - void EVENT_USB_Device_UnhandledControlRequest(void); - -#endif diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.txt b/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.txt deleted file mode 100644 index 761769e3c..000000000 --- a/Demos/Device/LowLevel/DualVirtualSerial/DualCDC.txt +++ /dev/null @@ -1,84 +0,0 @@ -/** \file - * - * This file contains special DoxyGen information for the generation of the main page and other special - * documentation pages. It is not a project source file. - */ - -/** \mainpage Dual Communications Device Class (Dual Virtual Serial Port) Device - * - * \section SSec_Compat Demo Compatibility: - * - * The following list indicates what microcontrollers are compatible with this demo. - * - * - Series 7 USB AVRs - * - Series 6 USB AVRs - * - Series 4 USB AVRs - * - Series 2 USB AVRs - * - * \section SSec_Info USB Information: - * - * The following table gives a rundown of the USB utilization of this demo. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
USB Mode:Device
USB Class:Miscellaneous Device Class( Sub-Interface: Communications Device Class (CDC) )
USB Subclass:Common Class( Sub-Interface: Abstract Control Model (ACM) )
Relevant Standards:USBIF Interface Association Descriptor ECNUSBIF CDC Class Standard
Usable Speeds:Full Speed Mode
- * - * \section SSec_Description Project Description: - * - * Dual Communications Device Class demonstration application. - * This gives a simple reference application for implementing - * a compound device with dual CDC functions acting as a pair - * of virtual serial ports. This demo uses Interface Association - * Descriptors to link together the pair of related CDC - * descriptors for each virtual serial port, which may not be - * supported in all OSes - Windows Vista is supported, as is - * XP (although the latter may need a hotfix to function). - * - * Joystick actions are transmitted to the host as strings - * through the first serial port. The device does not respond to - * serial data sent from the host in the first serial port. - * - * The second serial port echoes back data sent from the host. - * - * After running this demo for the first time on a new computer, - * you will need to supply the .INF file located in this demo - * 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. - * - * \section SSec_Options Project Options - * - * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. - * - * - * - * - * - *
- * None - *
- */ \ No newline at end of file diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c new file mode 100644 index 000000000..8b1da0348 --- /dev/null +++ b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c @@ -0,0 +1,323 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Main source file for the DualCDC demo. This file contains the main tasks of the demo and + * is responsible for the initial application hardware configuration. + */ + +#include "DualCDC.h" + +/** Contains the current baud rate and other settings of the first virtual serial port. While this demo does not use + * the physical USART and thus does not use these settings, they must still be retained and returned to the host + * upon request or the host will assume the device is non-functional. + * + * These values are set by the host via a class-specific request, however they are not required to be used accurately. + * It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical + * serial link characteristics and instead sends and receives data in endpoint streams. + */ +CDC_Line_Coding_t LineEncoding1 = { .BaudRateBPS = 0, + .CharFormat = OneStopBit, + .ParityType = Parity_None, + .DataBits = 8 }; + +/** Contains the current baud rate and other settings of the second virtual serial port. While this demo does not use + * the physical USART and thus does not use these settings, they must still be retained and returned to the host + * upon request or the host will assume the device is non-functional. + * + * These values are set by the host via a class-specific request, however they are not required to be used accurately. + * It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical + * serial link characteristics and instead sends and receives data in endpoint streams. + */ +CDC_Line_Coding_t LineEncoding2 = { .BaudRateBPS = 0, + .CharFormat = OneStopBit, + .ParityType = Parity_None, + .DataBits = 8 }; + + +/** Main program entry point. This routine configures the hardware required by the application, then + * enters a loop to run the application tasks in sequence. + */ +int main(void) +{ + SetupHardware(); + + for (;;) + { + CDC1_Task(); + CDC2_Task(); + USB_USBTask(); + } +} + +/** Configures the board hardware and chip peripherals for the demo's functionality. */ +void SetupHardware(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + /* Hardware Initialization */ + Joystick_Init(); + LEDs_Init(); + USB_Init(); +} + +/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and + * starts the library USB task to begin the enumeration and USB management process. + */ +void EVENT_USB_Device_Connect(void) +{ + /* Indicate USB enumerating */ + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); +} + +/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via + * the status LEDs and stops the USB management and CDC management tasks. + */ +void EVENT_USB_Device_Disconnect(void) +{ + /* Indicate USB not ready */ + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); +} + +/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration + * of the USB device after enumeration - the device endpoints are configured and the CDC management tasks are started. + */ +void EVENT_USB_Device_ConfigurationChanged(void) +{ + /* Indicate USB connected and ready */ + LEDs_SetAllLEDs(LEDMASK_USB_READY); + + /* Setup CDC Notification, Rx and Tx Endpoints for the first CDC */ + if (!(Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, + ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + if (!(Endpoint_ConfigureEndpoint(CDC1_TX_EPNUM, EP_TYPE_BULK, + ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + if (!(Endpoint_ConfigureEndpoint(CDC1_RX_EPNUM, EP_TYPE_BULK, + ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + /* Setup CDC Notification, Rx and Tx Endpoints for the second CDC */ + if (!(Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, + ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + if (!(Endpoint_ConfigureEndpoint(CDC2_TX_EPNUM, EP_TYPE_BULK, + ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + if (!(Endpoint_ConfigureEndpoint(CDC2_RX_EPNUM, EP_TYPE_BULK, + ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + /* Reset line encoding baud rates so that the host knows to send new values */ + LineEncoding1.BaudRateBPS = 0; + LineEncoding2.BaudRateBPS = 0; +} + +/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific + * control requests that are not handled internally by the USB library (including the CDC control commands, + * which are all issued via the control endpoint), so that they can be handled appropriately for the application. + */ +void EVENT_USB_Device_UnhandledControlRequest(void) +{ + /* Determine which interface's Line Coding data is being set from the wIndex parameter */ + uint8_t* LineEncodingData = (USB_ControlRequest.wIndex == 0) ? (uint8_t*)&LineEncoding1 : (uint8_t*)&LineEncoding2; + + /* Process CDC specific control requests */ + switch (USB_ControlRequest.bRequest) + { + case REQ_GetLineEncoding: + if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) + { + /* Acknowledge the SETUP packet, ready for data transfer */ + Endpoint_ClearSETUP(); + + /* Write the line coding data to the control endpoint */ + Endpoint_Write_Control_Stream_LE(LineEncodingData, sizeof(CDC_Line_Coding_t)); + + /* Finalize the stream transfer to send the last packet or clear the host abort */ + Endpoint_ClearOUT(); + } + + break; + case REQ_SetLineEncoding: + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + /* Acknowledge the SETUP packet, ready for data transfer */ + Endpoint_ClearSETUP(); + + /* Read the line coding data in from the host into the global struct */ + Endpoint_Read_Control_Stream_LE(LineEncodingData, sizeof(CDC_Line_Coding_t)); + + /* Finalize the stream transfer to clear the last packet from the host */ + Endpoint_ClearIN(); + } + + break; + case REQ_SetControlLineState: + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + /* Acknowledge the SETUP packet, ready for data transfer */ + Endpoint_ClearSETUP(); + + Endpoint_ClearStatusStage(); + } + + break; + } +} + +/** Function to manage CDC data transmission and reception to and from the host for the first CDC interface, which sends joystick + * movements to the host as ASCII strings. + */ +void CDC1_Task(void) +{ + char* ReportString = NULL; + uint8_t JoyStatus_LCL = Joystick_GetStatus(); + static bool ActionSent = false; + + /* Device must be connected and configured for the task to run */ + if (USB_DeviceState != DEVICE_STATE_Configured) + return; + + /* Determine if a joystick action has occurred */ + if (JoyStatus_LCL & JOY_UP) + ReportString = "Joystick Up\r\n"; + else if (JoyStatus_LCL & JOY_DOWN) + ReportString = "Joystick Down\r\n"; + else if (JoyStatus_LCL & JOY_LEFT) + ReportString = "Joystick Left\r\n"; + else if (JoyStatus_LCL & JOY_RIGHT) + ReportString = "Joystick Right\r\n"; + else if (JoyStatus_LCL & JOY_PRESS) + ReportString = "Joystick Pressed\r\n"; + else + ActionSent = false; + + /* Flag management - Only allow one string to be sent per action */ + if ((ReportString != NULL) && (ActionSent == false) && LineEncoding1.BaudRateBPS) + { + ActionSent = true; + + /* Select the Serial Tx Endpoint */ + Endpoint_SelectEndpoint(CDC1_TX_EPNUM); + + /* Write the String to the Endpoint */ + Endpoint_Write_Stream_LE(ReportString, strlen(ReportString)); + + /* Finalize the stream transfer to send the last packet */ + Endpoint_ClearIN(); + + /* Wait until the endpoint is ready for another packet */ + Endpoint_WaitUntilReady(); + + /* Send an empty packet to ensure that the host does not buffer data sent to it */ + Endpoint_ClearIN(); + } + + /* Select the Serial Rx Endpoint */ + Endpoint_SelectEndpoint(CDC1_RX_EPNUM); + + /* Throw away any received data from the host */ + if (Endpoint_IsOUTReceived()) + Endpoint_ClearOUT(); +} + +/** Function to manage CDC data transmission and reception to and from the host for the second CDC interface, which echoes back + * all data sent to it from the host. + */ +void CDC2_Task(void) +{ + /* Device must be connected and configured for the task to run */ + if (USB_DeviceState != DEVICE_STATE_Configured) + return; + + /* Select the Serial Rx Endpoint */ + Endpoint_SelectEndpoint(CDC2_RX_EPNUM); + + /* Check to see if any data has been received */ + if (Endpoint_IsOUTReceived()) + { + /* Create a temp buffer big enough to hold the incoming endpoint packet */ + uint8_t Buffer[Endpoint_BytesInEndpoint()]; + + /* Remember how large the incoming packet is */ + uint16_t DataLength = Endpoint_BytesInEndpoint(); + + /* Read in the incoming packet into the buffer */ + Endpoint_Read_Stream_LE(&Buffer, DataLength); + + /* Finalize the stream transfer to send the last packet */ + Endpoint_ClearOUT(); + + /* Select the Serial Tx Endpoint */ + Endpoint_SelectEndpoint(CDC2_TX_EPNUM); + + /* Write the received data to the endpoint */ + Endpoint_Write_Stream_LE(&Buffer, DataLength); + + /* Finalize the stream transfer to send the last packet */ + Endpoint_ClearIN(); + + /* Wait until the endpoint is ready for the next packet */ + Endpoint_WaitUntilReady(); + + /* Send an empty packet to prevent host buffering */ + Endpoint_ClearIN(); + } +} diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.h b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.h new file mode 100644 index 000000000..b2085c452 --- /dev/null +++ b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.h @@ -0,0 +1,119 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for DualCDC.c. + */ + +#ifndef _DUAL_CDC_H_ +#define _DUAL_CDC_H_ + + /* Includes: */ + #include + #include + #include + #include + + #include "Descriptors.h" + + #include + #include + #include + #include + + /* Macros: */ + /** CDC Class specific request to get the current virtual serial port configuration settings. */ + #define REQ_GetLineEncoding 0x21 + + /** CDC Class specific request to set the current virtual serial port configuration settings. */ + #define REQ_SetLineEncoding 0x20 + + /** CDC Class specific request to set the current virtual serial port handshake line states. */ + #define REQ_SetControlLineState 0x22 + + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /* Type Defines: */ + /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration + * as set by the host via a class specific request. + */ + typedef struct + { + uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */ + uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the + * CDCDevice_CDC_LineCodingFormats_t enum + */ + uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the + * CDCDevice_LineCodingParity_t enum + */ + uint8_t DataBits; /**< Bits of data per character of the virtual serial port */ + } CDC_Line_Coding_t; + + /* Enums: */ + /** Enum for the possible line encoding formats of a virtual serial port. */ + enum CDCDevice_CDC_LineCodingFormats_t + { + OneStopBit = 0, /**< Each frame contains one stop bit */ + OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits */ + TwoStopBits = 2, /**< Each frame contains two stop bits */ + }; + + /** Enum for the possible line encoding parity settings of a virtual serial port. */ + enum CDCDevice_LineCodingParity_t + { + Parity_None = 0, /**< No parity bit mode on each frame */ + Parity_Odd = 1, /**< Odd parity bit mode on each frame */ + Parity_Even = 2, /**< Even parity bit mode on each frame */ + Parity_Mark = 3, /**< Mark parity bit mode on each frame */ + Parity_Space = 4, /**< Space parity bit mode on each frame */ + }; + + /* Function Prototypes: */ + void CDC1_Task(void); + void CDC2_Task(void); + void SetupHardware(void); + + void EVENT_USB_Device_Connect(void); + void EVENT_USB_Device_Disconnect(void); + void EVENT_USB_Device_ConfigurationChanged(void); + void EVENT_USB_Device_UnhandledControlRequest(void); + +#endif diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt new file mode 100644 index 000000000..761769e3c --- /dev/null +++ b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.txt @@ -0,0 +1,84 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \mainpage Dual Communications Device Class (Dual Virtual Serial Port) Device + * + * \section SSec_Compat Demo Compatibility: + * + * The following list indicates what microcontrollers are compatible with this demo. + * + * - Series 7 USB AVRs + * - Series 6 USB AVRs + * - Series 4 USB AVRs + * - Series 2 USB AVRs + * + * \section SSec_Info USB Information: + * + * The following table gives a rundown of the USB utilization of this demo. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
USB Mode:Device
USB Class:Miscellaneous Device Class( Sub-Interface: Communications Device Class (CDC) )
USB Subclass:Common Class( Sub-Interface: Abstract Control Model (ACM) )
Relevant Standards:USBIF Interface Association Descriptor ECNUSBIF CDC Class Standard
Usable Speeds:Full Speed Mode
+ * + * \section SSec_Description Project Description: + * + * Dual Communications Device Class demonstration application. + * This gives a simple reference application for implementing + * a compound device with dual CDC functions acting as a pair + * of virtual serial ports. This demo uses Interface Association + * Descriptors to link together the pair of related CDC + * descriptors for each virtual serial port, which may not be + * supported in all OSes - Windows Vista is supported, as is + * XP (although the latter may need a hotfix to function). + * + * Joystick actions are transmitted to the host as strings + * through the first serial port. The device does not respond to + * serial data sent from the host in the first serial port. + * + * The second serial port echoes back data sent from the host. + * + * After running this demo for the first time on a new computer, + * you will need to supply the .INF file located in this demo + * 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. + * + * \section SSec_Options Project Options + * + * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. + * + * + * + * + * + *
+ * None + *
+ */ \ No newline at end of file diff --git a/Demos/Device/LowLevel/DualVirtualSerial/LUFA DualCDC.inf b/Demos/Device/LowLevel/DualVirtualSerial/LUFA DualCDC.inf deleted file mode 100644 index 741bf28eb..000000000 --- a/Demos/Device/LowLevel/DualVirtualSerial/LUFA DualCDC.inf +++ /dev/null @@ -1,106 +0,0 @@ -;************************************************************ -; Windows USB CDC ACM Setup File -; Copyright (c) 2000 Microsoft Corporation - - -[Version] -Signature="$Windows NT$" -Class=Ports -ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} -Provider=%MFGNAME% -LayoutFile=layout.inf -CatalogFile=%MFGFILENAME%.cat -DriverVer=11/15/2007,5.1.2600.0 - -[Manufacturer] -%MFGNAME%=DeviceList, NTamd64 - -[DestinationDirs] -DefaultDestDir=12 - - -;------------------------------------------------------------------------------ -; Windows 2000/XP/Vista-32bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.nt] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.nt -AddReg=DriverInstall.nt.AddReg - -[DriverCopyFiles.nt] -usbser.sys,,,0x20 - -[DriverInstall.nt.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.nt.Services] -AddService=usbser, 0x00000002, DriverService.nt - -[DriverService.nt] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - -;------------------------------------------------------------------------------ -; Vista-64bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.NTamd64] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.NTamd64 -AddReg=DriverInstall.NTamd64.AddReg - -[DriverCopyFiles.NTamd64] -%DRIVERFILENAME%.sys,,,0x20 - -[DriverInstall.NTamd64.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.NTamd64.Services] -AddService=usbser, 0x00000002, DriverService.NTamd64 - -[DriverService.NTamd64] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - - -;------------------------------------------------------------------------------ -; Vendor and Product ID Definitions -;------------------------------------------------------------------------------ -; When developing your USB device, the VID and PID used in the PC side -; application program and the firmware on the microcontroller must match. -; Modify the below line to use your VID and PID. Use the format as shown below. -; Note: One INF file can be used for multiple devices with different VID and PIDs. -; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. -;------------------------------------------------------------------------------ -[SourceDisksFiles] -[SourceDisksNames] -[DeviceList] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02 - -[DeviceList.NTamd64] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02 - - -;------------------------------------------------------------------------------ -; String Definitions -;------------------------------------------------------------------------------ -;Modify these strings to customize your device -;------------------------------------------------------------------------------ -[Strings] -MFGFILENAME="CDC_vista" -DRIVERFILENAME ="usbser" -MFGNAME="CCS, Inc." -INSTDISK="LUFA Dual CDC Driver Installer" -DESCRIPTION="Communications Port" -SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/LowLevel/DualVirtualSerial/LUFA DualVirtualSerial.inf b/Demos/Device/LowLevel/DualVirtualSerial/LUFA DualVirtualSerial.inf new file mode 100644 index 000000000..741bf28eb --- /dev/null +++ b/Demos/Device/LowLevel/DualVirtualSerial/LUFA DualVirtualSerial.inf @@ -0,0 +1,106 @@ +;************************************************************ +; Windows USB CDC ACM Setup File +; Copyright (c) 2000 Microsoft Corporation + + +[Version] +Signature="$Windows NT$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%MFGNAME% +LayoutFile=layout.inf +CatalogFile=%MFGFILENAME%.cat +DriverVer=11/15/2007,5.1.2600.0 + +[Manufacturer] +%MFGNAME%=DeviceList, NTamd64 + +[DestinationDirs] +DefaultDestDir=12 + + +;------------------------------------------------------------------------------ +; Windows 2000/XP/Vista-32bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.nt] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.nt +AddReg=DriverInstall.nt.AddReg + +[DriverCopyFiles.nt] +usbser.sys,,,0x20 + +[DriverInstall.nt.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.nt.Services] +AddService=usbser, 0x00000002, DriverService.nt + +[DriverService.nt] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + +;------------------------------------------------------------------------------ +; Vista-64bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.NTamd64] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.NTamd64 +AddReg=DriverInstall.NTamd64.AddReg + +[DriverCopyFiles.NTamd64] +%DRIVERFILENAME%.sys,,,0x20 + +[DriverInstall.NTamd64.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.NTamd64.Services] +AddService=usbser, 0x00000002, DriverService.NTamd64 + +[DriverService.NTamd64] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + + +;------------------------------------------------------------------------------ +; Vendor and Product ID Definitions +;------------------------------------------------------------------------------ +; When developing your USB device, the VID and PID used in the PC side +; application program and the firmware on the microcontroller must match. +; Modify the below line to use your VID and PID. Use the format as shown below. +; Note: One INF file can be used for multiple devices with different VID and PIDs. +; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. +;------------------------------------------------------------------------------ +[SourceDisksFiles] +[SourceDisksNames] +[DeviceList] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02 + +[DeviceList.NTamd64] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_204E&MI_00, USB\VID_03EB&PID_204E&MI_02 + + +;------------------------------------------------------------------------------ +; String Definitions +;------------------------------------------------------------------------------ +;Modify these strings to customize your device +;------------------------------------------------------------------------------ +[Strings] +MFGFILENAME="CDC_vista" +DRIVERFILENAME ="usbser" +MFGNAME="CCS, Inc." +INSTDISK="LUFA Dual CDC Driver Installer" +DESCRIPTION="Communications Port" +SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/LowLevel/DualVirtualSerial/makefile b/Demos/Device/LowLevel/DualVirtualSerial/makefile index 802a4dd5c..ef10bb38d 100644 --- a/Demos/Device/LowLevel/DualVirtualSerial/makefile +++ b/Demos/Device/LowLevel/DualVirtualSerial/makefile @@ -102,7 +102,7 @@ FORMAT = ihex # Target file name (without extension). -TARGET = DualCDC +TARGET = DualVirtualSerial # Object files directory diff --git a/Demos/Device/LowLevel/VirtualSerial/CDC.c b/Demos/Device/LowLevel/VirtualSerial/CDC.c deleted file mode 100644 index 444dc019d..000000000 --- a/Demos/Device/LowLevel/VirtualSerial/CDC.c +++ /dev/null @@ -1,327 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Main source file for the CDC demo. This file contains the main tasks of the demo and - * is responsible for the initial application hardware configuration. - */ - -#include "CDC.h" - -/** Contains the current baud rate and other settings of the virtual serial port. While this demo does not use - * the physical USART and thus does not use these settings, they must still be retained and returned to the host - * upon request or the host will assume the device is non-functional. - * - * These values are set by the host via a class-specific request, however they are not required to be used accurately. - * It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical - * serial link characteristics and instead sends and receives data in endpoint streams. - */ -CDC_Line_Coding_t LineEncoding = { .BaudRateBPS = 0, - .CharFormat = OneStopBit, - .ParityType = Parity_None, - .DataBits = 8 }; - - -#if 0 -/* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in - * can be used on the virtual serial port (e.g. fprintf(&USBSerial, "Test"); to print a string). - */ - -static int CDC_putchar(char c, FILE *stream) -{ - Endpoint_SelectEndpoint(CDC_TX_EPNUM); - - if (!(LineEncoding.BaudRateBPS)) - return -1; - - if (Endpoint_WaitUntilReady()) - return -1; - - Endpoint_Write_Byte(c); - Endpoint_ClearIN(); - - return 0; -} - -static int CDC_getchar(FILE *stream) -{ - int c; - - if (!(LineEncoding.BaudRateBPS)) - return -1; - - Endpoint_SelectEndpoint(CDC_RX_EPNUM); - - for (;;) - { - if (Endpoint_WaitUntilReady()) - return -1; - - if (!(Endpoint_BytesInEndpoint())) - { - Endpoint_ClearOUT(); - } - else - { - c = Endpoint_Read_Byte(); - break; - } - } - - return c; -} - -static FILE USBSerial = FDEV_SETUP_STREAM(CDC_putchar, CDC_getchar, _FDEV_SETUP_RW); -#endif - -/** Main program entry point. This routine contains the overall program flow, including initial - * setup of all components and the main program loop. - */ -int main(void) -{ - SetupHardware(); - - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - - for (;;) - { - CDC_Task(); - USB_USBTask(); - } -} - -/** Configures the board hardware and chip peripherals for the demo's functionality. */ -void SetupHardware(void) -{ - /* Disable watchdog if enabled by bootloader/fuses */ - MCUSR &= ~(1 << WDRF); - wdt_disable(); - - /* Disable clock division */ - clock_prescale_set(clock_div_1); - - /* Hardware Initialization */ - Joystick_Init(); - LEDs_Init(); - USB_Init(); -} - -/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and - * starts the library USB task to begin the enumeration and USB management process. - */ -void EVENT_USB_Device_Connect(void) -{ - /* Indicate USB enumerating */ - LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); -} - -/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via - * the status LEDs and stops the USB management and CDC management tasks. - */ -void EVENT_USB_Device_Disconnect(void) -{ - /* Indicate USB not ready */ - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); -} - -/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration - * of the USB device after enumeration - the device endpoints are configured and the CDC management task started. - */ -void EVENT_USB_Device_ConfigurationChanged(void) -{ - /* Indicate USB connected and ready */ - LEDs_SetAllLEDs(LEDMASK_USB_READY); - - /* Setup CDC Notification, Rx and Tx Endpoints */ - if (!(Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, - ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - if (!(Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK, - ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - if (!(Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK, - ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE, - ENDPOINT_BANK_SINGLE))) - { - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - } - - /* Reset line encoding baud rate so that the host knows to send new values */ - LineEncoding.BaudRateBPS = 0; -} - -/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific - * control requests that are not handled internally by the USB library (including the CDC control commands, - * which are all issued via the control endpoint), so that they can be handled appropriately for the application. - */ -void EVENT_USB_Device_UnhandledControlRequest(void) -{ - /* Process CDC specific control requests */ - switch (USB_ControlRequest.bRequest) - { - case REQ_GetLineEncoding: - if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) - { - /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearSETUP(); - - /* Write the line coding data to the control endpoint */ - Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); - - /* Finalize the stream transfer to send the last packet or clear the host abort */ - Endpoint_ClearOUT(); - } - - break; - case REQ_SetLineEncoding: - if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) - { - /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearSETUP(); - - /* Read the line coding data in from the host into the global struct */ - Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); - - /* Finalize the stream transfer to clear the last packet from the host */ - Endpoint_ClearIN(); - } - - break; - case REQ_SetControlLineState: - if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) - { - /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearSETUP(); - - /* NOTE: Here you can read in the line state mask from the host, to get the current state of the output handshake - lines. The mask is read in from the wValue parameter in USB_ControlRequest, and can be masked against the - CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code: - */ - - Endpoint_ClearStatusStage(); - } - - break; - } -} - -/** Function to manage CDC data transmission and reception to and from the host. */ -void CDC_Task(void) -{ - char* ReportString = NULL; - uint8_t JoyStatus_LCL = Joystick_GetStatus(); - static bool ActionSent = false; - - /* Device must be connected and configured for the task to run */ - if (USB_DeviceState != DEVICE_STATE_Configured) - return; - -#if 0 - /* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232 - * handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code: - */ - USB_Notification_Header_t Notification = (USB_Notification_Header_t) - { - .NotificationType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), - .Notification = NOTIF_SerialState, - .wValue = 0, - .wIndex = 0, - .wLength = sizeof(uint16_t), - }; - - uint16_t LineStateMask; - - // Set LineStateMask here to a mask of CONTROL_LINE_IN_* masks to set the input handshake line states to send to the host - - Endpoint_SelectEndpoint(CDC_NOTIFICATION_EPNUM); - Endpoint_Write_Stream_LE(&Notification, sizeof(Notification)); - Endpoint_Write_Stream_LE(&LineStateMask, sizeof(LineStateMask)); - Endpoint_ClearIN(); -#endif - - /* Determine if a joystick action has occurred */ - if (JoyStatus_LCL & JOY_UP) - ReportString = "Joystick Up\r\n"; - else if (JoyStatus_LCL & JOY_DOWN) - ReportString = "Joystick Down\r\n"; - else if (JoyStatus_LCL & JOY_LEFT) - ReportString = "Joystick Left\r\n"; - else if (JoyStatus_LCL & JOY_RIGHT) - ReportString = "Joystick Right\r\n"; - else if (JoyStatus_LCL & JOY_PRESS) - ReportString = "Joystick Pressed\r\n"; - else - ActionSent = false; - - /* Flag management - Only allow one string to be sent per action */ - if ((ReportString != NULL) && (ActionSent == false) && LineEncoding.BaudRateBPS) - { - ActionSent = true; - - /* Select the Serial Tx Endpoint */ - Endpoint_SelectEndpoint(CDC_TX_EPNUM); - - /* Write the String to the Endpoint */ - Endpoint_Write_Stream_LE(ReportString, strlen(ReportString)); - - /* Remember if the packet to send completely fills the endpoint */ - bool IsFull = (Endpoint_BytesInEndpoint() == CDC_TXRX_EPSIZE); - - /* Finalize the stream transfer to send the last packet */ - Endpoint_ClearIN(); - - /* If the last packet filled the endpoint, send an empty packet to release the buffer on - * the receiver (otherwise all data will be cached until a non-full packet is received) */ - if (IsFull) - { - /* Wait until the endpoint is ready for another packet */ - Endpoint_WaitUntilReady(); - - /* Send an empty packet to ensure that the host does not buffer data sent to it */ - Endpoint_ClearIN(); - } - } - - /* Select the Serial Rx Endpoint */ - Endpoint_SelectEndpoint(CDC_RX_EPNUM); - - /* Throw away any received data from the host */ - if (Endpoint_IsOUTReceived()) - Endpoint_ClearOUT(); -} diff --git a/Demos/Device/LowLevel/VirtualSerial/CDC.h b/Demos/Device/LowLevel/VirtualSerial/CDC.h deleted file mode 100644 index 4a7b6b158..000000000 --- a/Demos/Device/LowLevel/VirtualSerial/CDC.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - LUFA Library - Copyright (C) Dean Camera, 2009. - - dean [at] fourwalledcubicle [dot] com - www.fourwalledcubicle.com -*/ - -/* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the - software without specific, written prior permission. - - The author disclaim all warranties with regard to this - software, including all implied warranties of merchantability - and fitness. In no event shall the author be liable for any - special, indirect or consequential damages or any damages - whatsoever resulting from loss of use, data or profits, whether - in an action of contract, negligence or other tortious action, - arising out of or in connection with the use or performance of - this software. -*/ - -/** \file - * - * Header file for CDC.c. - */ - -#ifndef _CDC_H_ -#define _CDC_H_ - - /* Includes: */ - #include - #include - #include - #include - - #include "Descriptors.h" - - #include - #include - #include - #include - - /* Macros: */ - /** CDC Class specific request to get the current virtual serial port configuration settings. */ - #define REQ_GetLineEncoding 0x21 - - /** CDC Class specific request to set the current virtual serial port configuration settings. */ - #define REQ_SetLineEncoding 0x20 - - /** CDC Class specific request to set the current virtual serial port handshake line states. */ - #define REQ_SetControlLineState 0x22 - - /** Notification type constant for a change in the virtual serial port handshake line states, for - * use with a USB_Notification_Header_t notification structure when sent to the host via the CDC - * notification endpoint. - */ - #define NOTIF_SerialState 0x20 - - /** Mask for the DTR handshake line for use with the REQ_SetControlLineState class specific request - * from the host, to indicate that the DTR line state should be high. - */ - #define CONTROL_LINE_OUT_DTR (1 << 0) - - /** Mask for the RTS handshake line for use with the REQ_SetControlLineState class specific request - * from the host, to indicate that theRTS line state should be high. - */ - #define CONTROL_LINE_OUT_RTS (1 << 1) - - /** Mask for the DCD handshake line for use with the a NOTIF_SerialState class specific notification - * from the device to the host, to indicate that the DCD line state is currently high. - */ - #define CONTROL_LINE_IN_DCD (1 << 0) - - /** Mask for the DSR handshake line for use with the a NOTIF_SerialState class specific notification - * from the device to the host, to indicate that the DSR line state is currently high. - */ - #define CONTROL_LINE_IN_DSR (1 << 1) - - /** Mask for the BREAK handshake line for use with the a NOTIF_SerialState class specific notification - * from the device to the host, to indicate that the BREAK line state is currently high. - */ - #define CONTROL_LINE_IN_BREAK (1 << 2) - - /** Mask for the RING handshake line for use with the a NOTIF_SerialState class specific notification - * from the device to the host, to indicate that the RING line state is currently high. - */ - #define CONTROL_LINE_IN_RING (1 << 3) - - /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host, - * to indicate that a framing error has occurred on the virtual serial port. - */ - #define CONTROL_LINE_IN_FRAMEERROR (1 << 4) - - /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host, - * to indicate that a parity error has occurred on the virtual serial port. - */ - #define CONTROL_LINE_IN_PARITYERROR (1 << 5) - - /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host, - * to indicate that a data overrun error has occurred on the virtual serial port. - */ - #define CONTROL_LINE_IN_OVERRUNERROR (1 << 6) - - /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ - #define LEDMASK_USB_NOTREADY LEDS_LED1 - - /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ - #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) - - /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ - #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) - - /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ - #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) - - /* Type Defines: */ - /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration - * as set by the host via a class specific request. - */ - typedef struct - { - uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */ - uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the - * CDCDevice_CDC_LineCodingFormats_t enum - */ - uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the - * CDCDevice_LineCodingParity_t enum - */ - uint8_t DataBits; /**< Bits of data per character of the virtual serial port */ - } CDC_Line_Coding_t; - - /** Type define for a CDC notification, sent to the host via the CDC notification endpoint to indicate a - * change in the device state asynchronously. - */ - typedef struct - { - uint8_t NotificationType; /**< Notification type, a mask of REQDIR_*, REQTYPE_* and REQREC_* constants - * from the library StdRequestType.h header - */ - uint8_t Notification; /**< Notification value, a NOTIF_* constant */ - uint16_t wValue; /**< Notification wValue, notification-specific */ - uint16_t wIndex; /**< Notification wIndex, notification-specific */ - uint16_t wLength; /**< Notification wLength, notification-specific */ - } USB_Notification_Header_t; - - /* Enums: */ - /** Enum for the possible line encoding formats of a virtual serial port. */ - enum CDCDevice_CDC_LineCodingFormats_t - { - OneStopBit = 0, /**< Each frame contains one stop bit */ - OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits */ - TwoStopBits = 2, /**< Each frame contains two stop bits */ - }; - - /** Enum for the possible line encoding parity settings of a virtual serial port. */ - enum CDCDevice_LineCodingParity_t - { - Parity_None = 0, /**< No parity bit mode on each frame */ - Parity_Odd = 1, /**< Odd parity bit mode on each frame */ - Parity_Even = 2, /**< Even parity bit mode on each frame */ - Parity_Mark = 3, /**< Mark parity bit mode on each frame */ - Parity_Space = 4, /**< Space parity bit mode on each frame */ - }; - - /* Function Prototypes: */ - void SetupHardware(void); - void CDC_Task(void); - - void EVENT_USB_Device_Connect(void); - void EVENT_USB_Device_Disconnect(void); - void EVENT_USB_Device_ConfigurationChanged(void); - void EVENT_USB_Device_UnhandledControlRequest(void); - -#endif diff --git a/Demos/Device/LowLevel/VirtualSerial/CDC.txt b/Demos/Device/LowLevel/VirtualSerial/CDC.txt deleted file mode 100644 index 49837354c..000000000 --- a/Demos/Device/LowLevel/VirtualSerial/CDC.txt +++ /dev/null @@ -1,72 +0,0 @@ -/** \file - * - * This file contains special DoxyGen information for the generation of the main page and other special - * documentation pages. It is not a project source file. - */ - -/** \mainpage Communications Device Class (Virtual Serial Port) Demo - * - * \section SSec_Compat Demo Compatibility: - * - * The following list indicates what microcontrollers are compatible with this demo. - * - * - Series 7 USB AVRs - * - Series 6 USB AVRs - * - Series 4 USB AVRs - * - Series 2 USB AVRs - * - * \section SSec_Info USB Information: - * - * The following table gives a rundown of the USB utilization of this demo. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
USB Mode:Device
USB Class:Communications Device Class (CDC)
USB Subclass:Abstract Control Model (ACM)
Relevant Standards:USBIF CDC Class Standard
Usable Speeds:Full Speed Mode
- * - * \section SSec_Description Project Description: - * - * Communications Device Class demonstration application. - * This gives a simple reference application for implementing - * a CDC device acting as a virtual serial port. Joystick - * actions are transmitted to the host as strings. The device - * does not respond to serial data sent from the host. - * - * After running this demo for the first time on a new computer, - * you will need to supply the .INF file located in this demo - * 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. - * - * \section SSec_Options Project Options - * - * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. - * - * - * - * - * - *
- * None - *
- */ \ No newline at end of file diff --git a/Demos/Device/LowLevel/VirtualSerial/Doxygen.conf b/Demos/Device/LowLevel/VirtualSerial/Doxygen.conf index fa91d2207..57d102359 100644 --- a/Demos/Device/LowLevel/VirtualSerial/Doxygen.conf +++ b/Demos/Device/LowLevel/VirtualSerial/Doxygen.conf @@ -25,7 +25,7 @@ DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. -PROJECT_NAME = "LUFA Library - CDC Device Demo" +PROJECT_NAME = "LUFA Library - Virtual Serial Device Demo" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or diff --git a/Demos/Device/LowLevel/VirtualSerial/LUFA CDC.inf b/Demos/Device/LowLevel/VirtualSerial/LUFA CDC.inf deleted file mode 100644 index 4cdf59435..000000000 --- a/Demos/Device/LowLevel/VirtualSerial/LUFA CDC.inf +++ /dev/null @@ -1,106 +0,0 @@ -;************************************************************ -; Windows USB CDC ACM Setup File -; Copyright (c) 2000 Microsoft Corporation - - -[Version] -Signature="$Windows NT$" -Class=Ports -ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} -Provider=%MFGNAME% -LayoutFile=layout.inf -CatalogFile=%MFGFILENAME%.cat -DriverVer=11/15/2007,5.1.2600.0 - -[Manufacturer] -%MFGNAME%=DeviceList, NTamd64 - -[DestinationDirs] -DefaultDestDir=12 - - -;------------------------------------------------------------------------------ -; Windows 2000/XP/Vista-32bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.nt] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.nt -AddReg=DriverInstall.nt.AddReg - -[DriverCopyFiles.nt] -usbser.sys,,,0x20 - -[DriverInstall.nt.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.nt.Services] -AddService=usbser, 0x00000002, DriverService.nt - -[DriverService.nt] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - -;------------------------------------------------------------------------------ -; Vista-64bit Sections -;------------------------------------------------------------------------------ - -[DriverInstall.NTamd64] -include=mdmcpq.inf -CopyFiles=DriverCopyFiles.NTamd64 -AddReg=DriverInstall.NTamd64.AddReg - -[DriverCopyFiles.NTamd64] -%DRIVERFILENAME%.sys,,,0x20 - -[DriverInstall.NTamd64.AddReg] -HKR,,DevLoader,,*ntkern -HKR,,NTMPDriver,,%DRIVERFILENAME%.sys -HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" - -[DriverInstall.NTamd64.Services] -AddService=usbser, 0x00000002, DriverService.NTamd64 - -[DriverService.NTamd64] -DisplayName=%SERVICE% -ServiceType=1 -StartType=3 -ErrorControl=1 -ServiceBinary=%12%\%DRIVERFILENAME%.sys - - -;------------------------------------------------------------------------------ -; Vendor and Product ID Definitions -;------------------------------------------------------------------------------ -; When developing your USB device, the VID and PID used in the PC side -; application program and the firmware on the microcontroller must match. -; Modify the below line to use your VID and PID. Use the format as shown below. -; Note: One INF file can be used for multiple devices with different VID and PIDs. -; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. -;------------------------------------------------------------------------------ -[SourceDisksFiles] -[SourceDisksNames] -[DeviceList] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2044 - -[DeviceList.NTamd64] -%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2044 - - -;------------------------------------------------------------------------------ -; String Definitions -;------------------------------------------------------------------------------ -;Modify these strings to customize your device -;------------------------------------------------------------------------------ -[Strings] -MFGFILENAME="CDC_vista" -DRIVERFILENAME ="usbser" -MFGNAME="CCS, Inc." -INSTDISK="LUFA CDC Driver Installer" -DESCRIPTION="Communications Port" -SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/LowLevel/VirtualSerial/LUFA VirtualSerial.inf b/Demos/Device/LowLevel/VirtualSerial/LUFA VirtualSerial.inf new file mode 100644 index 000000000..4cdf59435 --- /dev/null +++ b/Demos/Device/LowLevel/VirtualSerial/LUFA VirtualSerial.inf @@ -0,0 +1,106 @@ +;************************************************************ +; Windows USB CDC ACM Setup File +; Copyright (c) 2000 Microsoft Corporation + + +[Version] +Signature="$Windows NT$" +Class=Ports +ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} +Provider=%MFGNAME% +LayoutFile=layout.inf +CatalogFile=%MFGFILENAME%.cat +DriverVer=11/15/2007,5.1.2600.0 + +[Manufacturer] +%MFGNAME%=DeviceList, NTamd64 + +[DestinationDirs] +DefaultDestDir=12 + + +;------------------------------------------------------------------------------ +; Windows 2000/XP/Vista-32bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.nt] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.nt +AddReg=DriverInstall.nt.AddReg + +[DriverCopyFiles.nt] +usbser.sys,,,0x20 + +[DriverInstall.nt.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.nt.Services] +AddService=usbser, 0x00000002, DriverService.nt + +[DriverService.nt] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + +;------------------------------------------------------------------------------ +; Vista-64bit Sections +;------------------------------------------------------------------------------ + +[DriverInstall.NTamd64] +include=mdmcpq.inf +CopyFiles=DriverCopyFiles.NTamd64 +AddReg=DriverInstall.NTamd64.AddReg + +[DriverCopyFiles.NTamd64] +%DRIVERFILENAME%.sys,,,0x20 + +[DriverInstall.NTamd64.AddReg] +HKR,,DevLoader,,*ntkern +HKR,,NTMPDriver,,%DRIVERFILENAME%.sys +HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" + +[DriverInstall.NTamd64.Services] +AddService=usbser, 0x00000002, DriverService.NTamd64 + +[DriverService.NTamd64] +DisplayName=%SERVICE% +ServiceType=1 +StartType=3 +ErrorControl=1 +ServiceBinary=%12%\%DRIVERFILENAME%.sys + + +;------------------------------------------------------------------------------ +; Vendor and Product ID Definitions +;------------------------------------------------------------------------------ +; When developing your USB device, the VID and PID used in the PC side +; application program and the firmware on the microcontroller must match. +; Modify the below line to use your VID and PID. Use the format as shown below. +; Note: One INF file can be used for multiple devices with different VID and PIDs. +; For each supported device, append ",USB\VID_xxxx&PID_yyyy" to the end of the line. +;------------------------------------------------------------------------------ +[SourceDisksFiles] +[SourceDisksNames] +[DeviceList] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2044 + +[DeviceList.NTamd64] +%DESCRIPTION%=DriverInstall, USB\VID_03EB&PID_2044 + + +;------------------------------------------------------------------------------ +; String Definitions +;------------------------------------------------------------------------------ +;Modify these strings to customize your device +;------------------------------------------------------------------------------ +[Strings] +MFGFILENAME="CDC_vista" +DRIVERFILENAME ="usbser" +MFGNAME="CCS, Inc." +INSTDISK="LUFA CDC Driver Installer" +DESCRIPTION="Communications Port" +SERVICE="USB RS-232 Emulation Driver" \ No newline at end of file diff --git a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c new file mode 100644 index 000000000..444dc019d --- /dev/null +++ b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c @@ -0,0 +1,327 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Main source file for the CDC demo. This file contains the main tasks of the demo and + * is responsible for the initial application hardware configuration. + */ + +#include "CDC.h" + +/** Contains the current baud rate and other settings of the virtual serial port. While this demo does not use + * the physical USART and thus does not use these settings, they must still be retained and returned to the host + * upon request or the host will assume the device is non-functional. + * + * These values are set by the host via a class-specific request, however they are not required to be used accurately. + * It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical + * serial link characteristics and instead sends and receives data in endpoint streams. + */ +CDC_Line_Coding_t LineEncoding = { .BaudRateBPS = 0, + .CharFormat = OneStopBit, + .ParityType = Parity_None, + .DataBits = 8 }; + + +#if 0 +/* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in + * can be used on the virtual serial port (e.g. fprintf(&USBSerial, "Test"); to print a string). + */ + +static int CDC_putchar(char c, FILE *stream) +{ + Endpoint_SelectEndpoint(CDC_TX_EPNUM); + + if (!(LineEncoding.BaudRateBPS)) + return -1; + + if (Endpoint_WaitUntilReady()) + return -1; + + Endpoint_Write_Byte(c); + Endpoint_ClearIN(); + + return 0; +} + +static int CDC_getchar(FILE *stream) +{ + int c; + + if (!(LineEncoding.BaudRateBPS)) + return -1; + + Endpoint_SelectEndpoint(CDC_RX_EPNUM); + + for (;;) + { + if (Endpoint_WaitUntilReady()) + return -1; + + if (!(Endpoint_BytesInEndpoint())) + { + Endpoint_ClearOUT(); + } + else + { + c = Endpoint_Read_Byte(); + break; + } + } + + return c; +} + +static FILE USBSerial = FDEV_SETUP_STREAM(CDC_putchar, CDC_getchar, _FDEV_SETUP_RW); +#endif + +/** Main program entry point. This routine contains the overall program flow, including initial + * setup of all components and the main program loop. + */ +int main(void) +{ + SetupHardware(); + + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); + + for (;;) + { + CDC_Task(); + USB_USBTask(); + } +} + +/** Configures the board hardware and chip peripherals for the demo's functionality. */ +void SetupHardware(void) +{ + /* Disable watchdog if enabled by bootloader/fuses */ + MCUSR &= ~(1 << WDRF); + wdt_disable(); + + /* Disable clock division */ + clock_prescale_set(clock_div_1); + + /* Hardware Initialization */ + Joystick_Init(); + LEDs_Init(); + USB_Init(); +} + +/** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and + * starts the library USB task to begin the enumeration and USB management process. + */ +void EVENT_USB_Device_Connect(void) +{ + /* Indicate USB enumerating */ + LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING); +} + +/** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via + * the status LEDs and stops the USB management and CDC management tasks. + */ +void EVENT_USB_Device_Disconnect(void) +{ + /* Indicate USB not ready */ + LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); +} + +/** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration + * of the USB device after enumeration - the device endpoints are configured and the CDC management task started. + */ +void EVENT_USB_Device_ConfigurationChanged(void) +{ + /* Indicate USB connected and ready */ + LEDs_SetAllLEDs(LEDMASK_USB_READY); + + /* Setup CDC Notification, Rx and Tx Endpoints */ + if (!(Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, + ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + if (!(Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK, + ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + if (!(Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK, + ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE, + ENDPOINT_BANK_SINGLE))) + { + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + } + + /* Reset line encoding baud rate so that the host knows to send new values */ + LineEncoding.BaudRateBPS = 0; +} + +/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific + * control requests that are not handled internally by the USB library (including the CDC control commands, + * which are all issued via the control endpoint), so that they can be handled appropriately for the application. + */ +void EVENT_USB_Device_UnhandledControlRequest(void) +{ + /* Process CDC specific control requests */ + switch (USB_ControlRequest.bRequest) + { + case REQ_GetLineEncoding: + if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) + { + /* Acknowledge the SETUP packet, ready for data transfer */ + Endpoint_ClearSETUP(); + + /* Write the line coding data to the control endpoint */ + Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); + + /* Finalize the stream transfer to send the last packet or clear the host abort */ + Endpoint_ClearOUT(); + } + + break; + case REQ_SetLineEncoding: + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + /* Acknowledge the SETUP packet, ready for data transfer */ + Endpoint_ClearSETUP(); + + /* Read the line coding data in from the host into the global struct */ + Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t)); + + /* Finalize the stream transfer to clear the last packet from the host */ + Endpoint_ClearIN(); + } + + break; + case REQ_SetControlLineState: + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + /* Acknowledge the SETUP packet, ready for data transfer */ + Endpoint_ClearSETUP(); + + /* NOTE: Here you can read in the line state mask from the host, to get the current state of the output handshake + lines. The mask is read in from the wValue parameter in USB_ControlRequest, and can be masked against the + CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code: + */ + + Endpoint_ClearStatusStage(); + } + + break; + } +} + +/** Function to manage CDC data transmission and reception to and from the host. */ +void CDC_Task(void) +{ + char* ReportString = NULL; + uint8_t JoyStatus_LCL = Joystick_GetStatus(); + static bool ActionSent = false; + + /* Device must be connected and configured for the task to run */ + if (USB_DeviceState != DEVICE_STATE_Configured) + return; + +#if 0 + /* NOTE: Here you can use the notification endpoint to send back line state changes to the host, for the special RS-232 + * handshake signal lines (and some error states), via the CONTROL_LINE_IN_* masks and the following code: + */ + USB_Notification_Header_t Notification = (USB_Notification_Header_t) + { + .NotificationType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), + .Notification = NOTIF_SerialState, + .wValue = 0, + .wIndex = 0, + .wLength = sizeof(uint16_t), + }; + + uint16_t LineStateMask; + + // Set LineStateMask here to a mask of CONTROL_LINE_IN_* masks to set the input handshake line states to send to the host + + Endpoint_SelectEndpoint(CDC_NOTIFICATION_EPNUM); + Endpoint_Write_Stream_LE(&Notification, sizeof(Notification)); + Endpoint_Write_Stream_LE(&LineStateMask, sizeof(LineStateMask)); + Endpoint_ClearIN(); +#endif + + /* Determine if a joystick action has occurred */ + if (JoyStatus_LCL & JOY_UP) + ReportString = "Joystick Up\r\n"; + else if (JoyStatus_LCL & JOY_DOWN) + ReportString = "Joystick Down\r\n"; + else if (JoyStatus_LCL & JOY_LEFT) + ReportString = "Joystick Left\r\n"; + else if (JoyStatus_LCL & JOY_RIGHT) + ReportString = "Joystick Right\r\n"; + else if (JoyStatus_LCL & JOY_PRESS) + ReportString = "Joystick Pressed\r\n"; + else + ActionSent = false; + + /* Flag management - Only allow one string to be sent per action */ + if ((ReportString != NULL) && (ActionSent == false) && LineEncoding.BaudRateBPS) + { + ActionSent = true; + + /* Select the Serial Tx Endpoint */ + Endpoint_SelectEndpoint(CDC_TX_EPNUM); + + /* Write the String to the Endpoint */ + Endpoint_Write_Stream_LE(ReportString, strlen(ReportString)); + + /* Remember if the packet to send completely fills the endpoint */ + bool IsFull = (Endpoint_BytesInEndpoint() == CDC_TXRX_EPSIZE); + + /* Finalize the stream transfer to send the last packet */ + Endpoint_ClearIN(); + + /* If the last packet filled the endpoint, send an empty packet to release the buffer on + * the receiver (otherwise all data will be cached until a non-full packet is received) */ + if (IsFull) + { + /* Wait until the endpoint is ready for another packet */ + Endpoint_WaitUntilReady(); + + /* Send an empty packet to ensure that the host does not buffer data sent to it */ + Endpoint_ClearIN(); + } + } + + /* Select the Serial Rx Endpoint */ + Endpoint_SelectEndpoint(CDC_RX_EPNUM); + + /* Throw away any received data from the host */ + if (Endpoint_IsOUTReceived()) + Endpoint_ClearOUT(); +} diff --git a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.h b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.h new file mode 100644 index 000000000..4a7b6b158 --- /dev/null +++ b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.h @@ -0,0 +1,183 @@ +/* + LUFA Library + Copyright (C) Dean Camera, 2009. + + dean [at] fourwalledcubicle [dot] com + www.fourwalledcubicle.com +*/ + +/* + Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the + software without specific, written prior permission. + + The author disclaim all warranties with regard to this + software, including all implied warranties of merchantability + and fitness. In no event shall the author be liable for any + special, indirect or consequential damages or any damages + whatsoever resulting from loss of use, data or profits, whether + in an action of contract, negligence or other tortious action, + arising out of or in connection with the use or performance of + this software. +*/ + +/** \file + * + * Header file for CDC.c. + */ + +#ifndef _CDC_H_ +#define _CDC_H_ + + /* Includes: */ + #include + #include + #include + #include + + #include "Descriptors.h" + + #include + #include + #include + #include + + /* Macros: */ + /** CDC Class specific request to get the current virtual serial port configuration settings. */ + #define REQ_GetLineEncoding 0x21 + + /** CDC Class specific request to set the current virtual serial port configuration settings. */ + #define REQ_SetLineEncoding 0x20 + + /** CDC Class specific request to set the current virtual serial port handshake line states. */ + #define REQ_SetControlLineState 0x22 + + /** Notification type constant for a change in the virtual serial port handshake line states, for + * use with a USB_Notification_Header_t notification structure when sent to the host via the CDC + * notification endpoint. + */ + #define NOTIF_SerialState 0x20 + + /** Mask for the DTR handshake line for use with the REQ_SetControlLineState class specific request + * from the host, to indicate that the DTR line state should be high. + */ + #define CONTROL_LINE_OUT_DTR (1 << 0) + + /** Mask for the RTS handshake line for use with the REQ_SetControlLineState class specific request + * from the host, to indicate that theRTS line state should be high. + */ + #define CONTROL_LINE_OUT_RTS (1 << 1) + + /** Mask for the DCD handshake line for use with the a NOTIF_SerialState class specific notification + * from the device to the host, to indicate that the DCD line state is currently high. + */ + #define CONTROL_LINE_IN_DCD (1 << 0) + + /** Mask for the DSR handshake line for use with the a NOTIF_SerialState class specific notification + * from the device to the host, to indicate that the DSR line state is currently high. + */ + #define CONTROL_LINE_IN_DSR (1 << 1) + + /** Mask for the BREAK handshake line for use with the a NOTIF_SerialState class specific notification + * from the device to the host, to indicate that the BREAK line state is currently high. + */ + #define CONTROL_LINE_IN_BREAK (1 << 2) + + /** Mask for the RING handshake line for use with the a NOTIF_SerialState class specific notification + * from the device to the host, to indicate that the RING line state is currently high. + */ + #define CONTROL_LINE_IN_RING (1 << 3) + + /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host, + * to indicate that a framing error has occurred on the virtual serial port. + */ + #define CONTROL_LINE_IN_FRAMEERROR (1 << 4) + + /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host, + * to indicate that a parity error has occurred on the virtual serial port. + */ + #define CONTROL_LINE_IN_PARITYERROR (1 << 5) + + /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host, + * to indicate that a data overrun error has occurred on the virtual serial port. + */ + #define CONTROL_LINE_IN_OVERRUNERROR (1 << 6) + + /** LED mask for the library LED driver, to indicate that the USB interface is not ready. */ + #define LEDMASK_USB_NOTREADY LEDS_LED1 + + /** LED mask for the library LED driver, to indicate that the USB interface is enumerating. */ + #define LEDMASK_USB_ENUMERATING (LEDS_LED2 | LEDS_LED3) + + /** LED mask for the library LED driver, to indicate that the USB interface is ready. */ + #define LEDMASK_USB_READY (LEDS_LED2 | LEDS_LED4) + + /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */ + #define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3) + + /* Type Defines: */ + /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration + * as set by the host via a class specific request. + */ + typedef struct + { + uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */ + uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the + * CDCDevice_CDC_LineCodingFormats_t enum + */ + uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the + * CDCDevice_LineCodingParity_t enum + */ + uint8_t DataBits; /**< Bits of data per character of the virtual serial port */ + } CDC_Line_Coding_t; + + /** Type define for a CDC notification, sent to the host via the CDC notification endpoint to indicate a + * change in the device state asynchronously. + */ + typedef struct + { + uint8_t NotificationType; /**< Notification type, a mask of REQDIR_*, REQTYPE_* and REQREC_* constants + * from the library StdRequestType.h header + */ + uint8_t Notification; /**< Notification value, a NOTIF_* constant */ + uint16_t wValue; /**< Notification wValue, notification-specific */ + uint16_t wIndex; /**< Notification wIndex, notification-specific */ + uint16_t wLength; /**< Notification wLength, notification-specific */ + } USB_Notification_Header_t; + + /* Enums: */ + /** Enum for the possible line encoding formats of a virtual serial port. */ + enum CDCDevice_CDC_LineCodingFormats_t + { + OneStopBit = 0, /**< Each frame contains one stop bit */ + OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits */ + TwoStopBits = 2, /**< Each frame contains two stop bits */ + }; + + /** Enum for the possible line encoding parity settings of a virtual serial port. */ + enum CDCDevice_LineCodingParity_t + { + Parity_None = 0, /**< No parity bit mode on each frame */ + Parity_Odd = 1, /**< Odd parity bit mode on each frame */ + Parity_Even = 2, /**< Even parity bit mode on each frame */ + Parity_Mark = 3, /**< Mark parity bit mode on each frame */ + Parity_Space = 4, /**< Space parity bit mode on each frame */ + }; + + /* Function Prototypes: */ + void SetupHardware(void); + void CDC_Task(void); + + void EVENT_USB_Device_Connect(void); + void EVENT_USB_Device_Disconnect(void); + void EVENT_USB_Device_ConfigurationChanged(void); + void EVENT_USB_Device_UnhandledControlRequest(void); + +#endif diff --git a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt new file mode 100644 index 000000000..49837354c --- /dev/null +++ b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.txt @@ -0,0 +1,72 @@ +/** \file + * + * This file contains special DoxyGen information for the generation of the main page and other special + * documentation pages. It is not a project source file. + */ + +/** \mainpage Communications Device Class (Virtual Serial Port) Demo + * + * \section SSec_Compat Demo Compatibility: + * + * The following list indicates what microcontrollers are compatible with this demo. + * + * - Series 7 USB AVRs + * - Series 6 USB AVRs + * - Series 4 USB AVRs + * - Series 2 USB AVRs + * + * \section SSec_Info USB Information: + * + * The following table gives a rundown of the USB utilization of this demo. + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
USB Mode:Device
USB Class:Communications Device Class (CDC)
USB Subclass:Abstract Control Model (ACM)
Relevant Standards:USBIF CDC Class Standard
Usable Speeds:Full Speed Mode
+ * + * \section SSec_Description Project Description: + * + * Communications Device Class demonstration application. + * This gives a simple reference application for implementing + * a CDC device acting as a virtual serial port. Joystick + * actions are transmitted to the host as strings. The device + * does not respond to serial data sent from the host. + * + * After running this demo for the first time on a new computer, + * you will need to supply the .INF file located in this demo + * 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. + * + * \section SSec_Options Project Options + * + * The following defines can be found in this demo, which can control the demo behaviour when defined, or changed in value. + * + * + * + * + * + *
+ * None + *
+ */ \ No newline at end of file diff --git a/Demos/Device/LowLevel/VirtualSerial/makefile b/Demos/Device/LowLevel/VirtualSerial/makefile index 934b3d014..652865134 100644 --- a/Demos/Device/LowLevel/VirtualSerial/makefile +++ b/Demos/Device/LowLevel/VirtualSerial/makefile @@ -102,7 +102,7 @@ FORMAT = ihex # Target file name (without extension). -TARGET = CDC +TARGET = VirtualSerial # Object files directory diff --git a/Demos/Device/LowLevel/makefile b/Demos/Device/LowLevel/makefile index 68bcac61a..991b37e49 100644 --- a/Demos/Device/LowLevel/makefile +++ b/Demos/Device/LowLevel/makefile @@ -20,11 +20,8 @@ all: make -C AudioOutput clean make -C AudioOutput all - make -C CDC clean - make -C CDC all - - make -C DualCDC clean - make -C DualCDC all + make -C DualVirtualSerial clean + make -C DualVirtualSerial all make -C GenericHID clean make -C GenericHID all @@ -50,11 +47,13 @@ all: make -C RNDISEthernet clean make -C RNDISEthernet all + make -C VirtualSerial clean + make -C VirtualSerial all + %: make -C AudioInput $@ make -C AudioOutput $@ - make -C CDC $@ - make -C DualCDC $@ + make -C DualVirtualSerial $@ make -C GenericHID $@ make -C Joystick $@ make -C Keyboard $@ @@ -63,3 +62,4 @@ all: make -C MIDI $@ make -C Mouse $@ make -C RNDISEthernet $@ + make -C VirtualSerial $@ -- cgit v1.2.3