3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
33 USB_ClassInfo_CDC_t VirtualSerial1_CDC_Interface
=
35 .ControlInterfaceNumber
= 0,
37 .DataINEndpointNumber
= CDC1_TX_EPNUM
,
38 .DataINEndpointSize
= CDC_TXRX_EPSIZE
,
40 .DataOUTEndpointNumber
= CDC1_RX_EPNUM
,
41 .DataOUTEndpointSize
= CDC_TXRX_EPSIZE
,
43 .NotificationEndpointNumber
= CDC1_NOTIFICATION_EPNUM
,
44 .NotificationEndpointSize
= CDC_NOTIFICATION_EPSIZE
,
47 USB_ClassInfo_CDC_t VirtualSerial2_CDC_Interface
=
49 .ControlInterfaceNumber
= 0,
51 .DataINEndpointNumber
= CDC2_TX_EPNUM
,
52 .DataINEndpointSize
= CDC_TXRX_EPSIZE
,
54 .DataOUTEndpointNumber
= CDC2_RX_EPNUM
,
55 .DataOUTEndpointSize
= CDC_TXRX_EPSIZE
,
57 .NotificationEndpointNumber
= CDC2_NOTIFICATION_EPNUM
,
58 .NotificationEndpointSize
= CDC_NOTIFICATION_EPSIZE
,
65 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
69 CheckJoystickMovement();
71 uint16_t BytesToDiscard
= USB_CDC_BytesReceived(&VirtualSerial1_CDC_Interface
);
72 while (BytesToDiscard
--)
73 USB_CDC_ReceiveByte(&VirtualSerial1_CDC_Interface
);
75 uint16_t BytesToEcho
= USB_CDC_BytesReceived(&VirtualSerial2_CDC_Interface
);
77 USB_CDC_SendByte(&VirtualSerial2_CDC_Interface
, USB_CDC_ReceiveByte(&VirtualSerial2_CDC_Interface
));
79 USB_CDC_USBTask(&VirtualSerial1_CDC_Interface
);
80 USB_CDC_USBTask(&VirtualSerial2_CDC_Interface
);
85 void SetupHardware(void)
87 /* Disable watchdog if enabled by bootloader/fuses */
88 MCUSR
&= ~(1 << WDRF
);
91 /* Disable clock division */
92 clock_prescale_set(clock_div_1
);
94 /* Hardware Initialization */
100 void CheckJoystickMovement(void)
102 uint8_t JoyStatus_LCL
= Joystick_GetStatus();
103 char* ReportString
= NULL
;
104 static bool ActionSent
= false;
106 char* JoystickStrings
[] =
111 "Joystick Right\r\n",
112 "Joystick Pressed\r\n",
115 if (JoyStatus_LCL
& JOY_UP
)
116 ReportString
= JoystickStrings
[0];
117 else if (JoyStatus_LCL
& JOY_DOWN
)
118 ReportString
= JoystickStrings
[1];
119 else if (JoyStatus_LCL
& JOY_LEFT
)
120 ReportString
= JoystickStrings
[2];
121 else if (JoyStatus_LCL
& JOY_RIGHT
)
122 ReportString
= JoystickStrings
[3];
123 else if (JoyStatus_LCL
& JOY_PRESS
)
124 ReportString
= JoystickStrings
[4];
128 if ((ReportString
!= NULL
) && (ActionSent
== false))
132 USB_CDC_SendString(&VirtualSerial1_CDC_Interface
, ReportString
, strlen(ReportString
));
136 void EVENT_USB_Connect(void)
138 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
141 void EVENT_USB_Disconnect(void)
143 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
146 void EVENT_USB_ConfigurationChanged(void)
148 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
150 if (!(USB_CDC_ConfigureEndpoints(&VirtualSerial1_CDC_Interface
)))
151 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
153 if (!(USB_CDC_ConfigureEndpoints(&VirtualSerial2_CDC_Interface
)))
154 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
157 void EVENT_USB_UnhandledControlPacket(void)
159 USB_CDC_ProcessControlPacket(&VirtualSerial1_CDC_Interface
);
160 USB_CDC_ProcessControlPacket(&VirtualSerial2_CDC_Interface
);