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 .ReportINBufferSize
= 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 */
71 /* Millisecond timer initialization, with output compare interrupt enabled for the idle timing */
72 OCR0A
= ((F_CPU
/ 64) / 1000);
73 TCCR0A
= (1 << WGM01
);
74 TCCR0B
= ((1 << CS01
) | (1 << CS00
));
75 TIMSK0
= (1 << OCIE0A
);
78 void EVENT_USB_Connect(void)
80 LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING
);
83 void EVENT_USB_Disconnect(void)
85 LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY
);
88 void EVENT_USB_ConfigurationChanged(void)
90 LEDs_SetAllLEDs(LEDMASK_USB_READY
);
92 if (!(USB_HID_ConfigureEndpoints(&Mouse_HID_Interface
)))
93 LEDs_SetAllLEDs(LEDMASK_USB_ERROR
);
96 void EVENT_USB_UnhandledControlPacket(void)
98 USB_HID_ProcessControlPacket(&Mouse_HID_Interface
);
101 ISR(TIMER0_COMPA_vect
, ISR_BLOCK
)
103 if (Mouse_HID_Interface
.IdleMSRemaining
)
104 Mouse_HID_Interface
.IdleMSRemaining
--;
107 uint16_t CALLBACK_USB_HID_CreateNextHIDReport(USB_ClassInfo_HID_t
* HIDInterfaceInfo
, void* ReportData
)
109 USB_MouseReport_Data_t
* MouseReport
= (USB_MouseReport_Data_t
*)ReportData
;
111 uint8_t JoyStatus_LCL
= Joystick_GetStatus();
112 uint8_t ButtonStatus_LCL
= Buttons_GetStatus();
114 if (JoyStatus_LCL
& JOY_UP
)
116 else if (JoyStatus_LCL
& JOY_DOWN
)
119 if (JoyStatus_LCL
& JOY_RIGHT
)
121 else if (JoyStatus_LCL
& JOY_LEFT
)
124 if (JoyStatus_LCL
& JOY_PRESS
)
125 MouseReport
->Button
= (1 << 0);
127 if (ButtonStatus_LCL
& BUTTONS_BUTTON1
)
128 MouseReport
->Button
|= (1 << 1);
130 return sizeof(USB_MouseReport_Data_t
);
133 void CALLBACK_USB_HID_ProcessReceivedHIDReport(USB_ClassInfo_HID_t
* HIDInterfaceInfo
, void* ReportData
, uint16_t ReportSize
)
135 // Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports