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_HID_t Mouse_HID_Interface
=
37 .ReportINEndpointNumber
= MOUSE_EPNUM
,
38 .ReportINEndpointSize
= MOUSE_EPSIZE
,
40 .ReportBufferSize
= sizeof(USB_MouseReport_Data_t
),
47 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
51 USB_HID_USBTask(&Mouse_HID_Interface
);
56 void SetupHardware(void)
58 /* Disable watchdog if enabled by bootloader/fuses */
59 MCUSR
&= ~(1 << WDRF
);
62 /* Disable clock division */
63 clock_prescale_set(clock_div_1
);
65 /* Hardware Initialization */
72 void EVENT_USB_Connect(void)
74 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
77 void EVENT_USB_Disconnect(void)
79 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
82 void EVENT_USB_ConfigurationChanged(void)
84 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
86 if (!(USB_HID_ConfigureEndpoints(&Mouse_HID_Interface
)))
87 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
90 void EVENT_USB_UnhandledControlPacket(void)
92 USB_HID_ProcessControlPacket(&Mouse_HID_Interface
);
95 void EVENT_USB_StartOfFrame(void)
97 USB_HID_RegisterStartOfFrame(&Mouse_HID_Interface
);
100 uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t
* HIDInterfaceInfo
, void* ReportData
)
102 USB_MouseReport_Data_t
* MouseReport
= (USB_MouseReport_Data_t
*)ReportData
;
104 uint8_t JoyStatus_LCL
= Joystick_GetStatus();
105 uint8_t ButtonStatus_LCL
= Buttons_GetStatus();
107 if (JoyStatus_LCL
& JOY_UP
)
109 else if (JoyStatus_LCL
& JOY_DOWN
)
112 if (JoyStatus_LCL
& JOY_RIGHT
)
114 else if (JoyStatus_LCL
& JOY_LEFT
)
117 if (JoyStatus_LCL
& JOY_PRESS
)
118 MouseReport
->Button
= (1 << 0);
120 if (ButtonStatus_LCL
& BUTTONS_BUTTON1
)
121 MouseReport
->Button
|= (1 << 1);
123 return sizeof(USB_MouseReport_Data_t
);
126 void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t
* HIDInterfaceInfo
, void* ReportData
, uint16_t ReportSize
)
128 // Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports