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 VirtualSerial_CDC_Interface
=
35 .ControlInterfaceNumber
= 0,
37 .DataINEndpointNumber
= CDC_TX_EPNUM
,
38 .DataINEndpointSize
= CDC_TXRX_EPSIZE
,
40 .DataOUTEndpointNumber
= CDC_RX_EPNUM
,
41 .DataOUTEndpointSize
= CDC_TXRX_EPSIZE
,
43 .NotificationEndpointNumber
= CDC_NOTIFICATION_EPNUM
,
44 .NotificationEndpointSize
= CDC_NOTIFICATION_EPSIZE
,
51 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
55 CheckJoystickMovement();
57 uint16_t BytesToDiscard
= USB_CDC_BytesReceived(&VirtualSerial_CDC_Interface
);
58 while (BytesToDiscard
--)
59 USB_CDC_ReceiveByte(&VirtualSerial_CDC_Interface
);
61 USB_CDC_USBTask(&VirtualSerial_CDC_Interface
);
66 void SetupHardware(void)
68 /* Disable watchdog if enabled by bootloader/fuses */
69 MCUSR
&= ~(1 << WDRF
);
72 /* Disable clock division */
73 clock_prescale_set(clock_div_1
);
75 /* Hardware Initialization */
81 void CheckJoystickMovement(void)
83 uint8_t JoyStatus_LCL
= Joystick_GetStatus();
84 char* ReportString
= NULL
;
85 static bool ActionSent
= false;
87 char* JoystickStrings
[] =
93 "Joystick Pressed\r\n",
96 if (JoyStatus_LCL
& JOY_UP
)
97 ReportString
= JoystickStrings
[0];
98 else if (JoyStatus_LCL
& JOY_DOWN
)
99 ReportString
= JoystickStrings
[1];
100 else if (JoyStatus_LCL
& JOY_LEFT
)
101 ReportString
= JoystickStrings
[2];
102 else if (JoyStatus_LCL
& JOY_RIGHT
)
103 ReportString
= JoystickStrings
[3];
104 else if (JoyStatus_LCL
& JOY_PRESS
)
105 ReportString
= JoystickStrings
[4];
109 if ((ReportString
!= NULL
) && (ActionSent
== false))
113 USB_CDC_SendString(&VirtualSerial_CDC_Interface
, ReportString
, strlen(ReportString
));
117 void EVENT_USB_Connect(void)
119 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
122 void EVENT_USB_Disconnect(void)
124 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
127 void EVENT_USB_ConfigurationChanged(void)
129 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
131 if (!(USB_CDC_ConfigureEndpoints(&VirtualSerial_CDC_Interface
)))
132 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
135 void EVENT_USB_UnhandledControlPacket(void)
137 USB_CDC_ProcessControlPacket(&VirtualSerial_CDC_Interface
);