3 Copyright (C) Dean Camera, 2011.
\r
5 dean [at] fourwalledcubicle [dot] com
\r
10 Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
\r
12 Permission to use, copy, modify, distribute, and sell this
\r
13 software and its documentation for any purpose is hereby granted
\r
14 without fee, provided that the above copyright notice appear in
\r
15 all copies and that both that the copyright notice and this
\r
16 permission notice and warranty disclaimer appear in supporting
\r
17 documentation, and that the name of the author not be used in
\r
18 advertising or publicity pertaining to distribution of the
\r
19 software without specific, written prior permission.
\r
21 The author disclaim all warranties with regard to this
\r
22 software, including all implied warranties of merchantability
\r
23 and fitness. In no event shall the author be liable for any
\r
24 special, indirect or consequential damages or any damages
\r
25 whatsoever resulting from loss of use, data or profits, whether
\r
26 in an action of contract, negligence or other tortious action,
\r
27 arising out of or in connection with the use or performance of
\r
33 * Main source file for the DualVirtualSerial demo. This file contains the main tasks of
\r
34 * the demo and is responsible for the initial application hardware configuration.
\r
37 #include "DualVirtualSerial.h"
\r
40 #include <aversive.h>
\r
41 #include <aversive/error.h>
\r
42 #include <aversive/queue.h>
\r
44 #include <scheduler.h>
\r
45 #include <clock_time.h>
\r
50 #include "xbee_neighbor.h"
\r
51 #include "xbee_atcmd.h"
\r
52 #include "xbee_stats.h"
\r
53 #include "xbee_buf.h"
\r
54 #include "xbee_proto.h"
\r
57 #include "callout.h"
\r
59 #include "cmdline.h"
\r
61 /** LUFA CDC Class driver interface configuration and state information. This structure is
\r
62 * passed to all CDC Class driver functions, so that multiple instances of the same class
\r
63 * within a device can be differentiated from one another. This is for the first CDC interface,
\r
64 * which sends strings to the host for each joystick movement.
\r
66 USB_ClassInfo_CDC_Device_t VirtualSerial1_CDC_Interface =
\r
70 .ControlInterfaceNumber = 0,
\r
72 .DataINEndpointNumber = CDC1_TX_EPNUM,
\r
73 .DataINEndpointSize = CDC_TXRX_EPSIZE,
\r
74 .DataINEndpointDoubleBank = false,
\r
76 .DataOUTEndpointNumber = CDC1_RX_EPNUM,
\r
77 .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
\r
78 .DataOUTEndpointDoubleBank = false,
\r
80 .NotificationEndpointNumber = CDC1_NOTIFICATION_EPNUM,
\r
81 .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
\r
82 .NotificationEndpointDoubleBank = false,
\r
86 /** LUFA CDC Class driver interface configuration and state information. This structure is
\r
87 * passed to all CDC Class driver functions, so that multiple instances of the same class
\r
88 * within a device can be differentiated from one another. This is for the second CDC interface,
\r
89 * which echos back all received data from the host.
\r
91 USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface =
\r
95 .ControlInterfaceNumber = 2,
\r
97 .DataINEndpointNumber = CDC2_TX_EPNUM,
\r
98 .DataINEndpointSize = CDC_TXRX_EPSIZE,
\r
99 .DataINEndpointDoubleBank = false,
\r
101 .DataOUTEndpointNumber = CDC2_RX_EPNUM,
\r
102 .DataOUTEndpointSize = CDC_TXRX_EPSIZE,
\r
103 .DataOUTEndpointDoubleBank = false,
\r
105 .NotificationEndpointNumber = CDC2_NOTIFICATION_EPNUM,
\r
106 .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE,
\r
107 .NotificationEndpointDoubleBank = false,
\r
112 /** Configures the board hardware and chip peripherals for the demo's functionality. */
\r
113 void SetupHardware(void)
\r
115 /* Disable watchdog if enabled by bootloader/fuses */
\r
116 MCUSR &= ~(1 << WDRF);
\r
119 /* Disable clock division */
\r
120 clock_prescale_set(clock_div_1);
\r
122 /* Hardware Initialization */
\r
128 /** Checks for changes in the position of the board joystick, sending strings to the host upon each change
\r
129 * through the first of the CDC interfaces.
\r
131 void CheckJoystickMovement(void)
\r
133 uint8_t JoyStatus_LCL = Joystick_GetStatus();
\r
134 char* ReportString = NULL;
\r
135 static bool ActionSent = false;
\r
137 if (JoyStatus_LCL & JOY_UP)
\r
138 ReportString = "Joystick Up\r\n";
\r
139 else if (JoyStatus_LCL & JOY_DOWN)
\r
140 ReportString = "Joystick Down\r\n";
\r
141 else if (JoyStatus_LCL & JOY_LEFT)
\r
142 ReportString = "Joystick Left\r\n";
\r
143 else if (JoyStatus_LCL & JOY_RIGHT)
\r
144 ReportString = "Joystick Right\r\n";
\r
145 else if (JoyStatus_LCL & JOY_PRESS)
\r
146 ReportString = "Joystick Pressed\r\n";
\r
148 ActionSent = false;
\r
150 if ((ReportString != NULL) && (ActionSent == false))
\r
154 CDC_Device_SendString(&VirtualSerial1_CDC_Interface, ReportString);
\r
158 /** Event handler for the library USB Connection event. */
\r
159 void EVENT_USB_Device_Connect(void)
\r
161 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
\r
164 /** Event handler for the library USB Disconnection event. */
\r
165 void EVENT_USB_Device_Disconnect(void)
\r
167 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
\r
170 /** Event handler for the library USB Configuration Changed event. */
\r
171 void EVENT_USB_Device_ConfigurationChanged(void)
\r
173 bool ConfigSuccess = true;
\r
175 ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial1_CDC_Interface);
\r
176 ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial2_CDC_Interface);
\r
178 LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
\r
180 rdline_newline(&xbeeboard.rdl, xbeeboard.prompt);
\r
183 /** Event handler for the library USB Control Request reception event. */
\r
184 void EVENT_USB_Device_ControlRequest(void)
\r
186 CDC_Device_ProcessControlRequest(&VirtualSerial1_CDC_Interface);
\r
187 CDC_Device_ProcessControlRequest(&VirtualSerial2_CDC_Interface);
\r