This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
en:projects:crazy_mouse [2010/03/14 14:18] – created mikk.leini | en:projects:crazy_mouse [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Crazy USB mouse ====== | ====== Crazy USB mouse ====== | ||
- | ARM-CAN demo project. | + | // |
+ | |||
+ | [{{ : | ||
+ | |||
+ | ARM-CAN | ||
+ | |||
+ | ~~CL~~ | ||
+ | |||
+ | ===== crazy_mouse.c ===== | ||
<code c> | <code c> | ||
Line 87: | Line 95: | ||
unsigned long ulAngle = 0; | unsigned long ulAngle = 0; | ||
char cDeltaX = 0, cDeltaY = 0; | char cDeltaX = 0, cDeltaY = 0; | ||
+ | |||
// | // | ||
- | | + | // Set the clocking to run from the PLL at 50MHz |
- | // | + | // |
- | SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | | + | SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | |
- | | + | SYSCTL_XTAL_8MHZ); |
- | + | ||
// | // | ||
// Drivers configuring. | // Drivers configuring. | ||
// | // | ||
DeviceConfigure(); | DeviceConfigure(); | ||
+ | |||
// | // | ||
- | | + | // Pass the USB library our device information, |
- | // controller and connect the device to the bus. | + | // controller and connect the device to the bus. |
- | // | + | |
- | USBDHIDMouseInit(0, | + | |
// | // | ||
- | // Enable processor interrupts. | + | USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)& |
- | // | + | |
- | IntMasterEnable(); | + | |
- | | + | // |
- | // Loop forever. | + | // Enable processor interrupts. |
- | // | + | // |
- | while (true) | + | IntMasterEnable(); |
- | { | + | |
+ | // | ||
+ | // Loop forever. | ||
+ | // | ||
+ | while (true) | ||
+ | { | ||
// | // | ||
// Device connected and ready ? | // Device connected and ready ? | ||
Line 124: | Line 132: | ||
// | // | ||
ulAngle += 0x1000000; | ulAngle += 0x1000000; | ||
+ | |||
// | // | ||
// Calculate X and Y movement. | // Calculate X and Y movement. | ||
Line 131: | Line 139: | ||
cDeltaX = sine(ulAngle) >> 14; | cDeltaX = sine(ulAngle) >> 14; | ||
cDeltaY = sine(ulAngle - 0x40000000) >> 14; | cDeltaY = sine(ulAngle - 0x40000000) >> 14; | ||
+ | |||
// | // | ||
// Keep a small break. | // Keep a small break. | ||
// | // | ||
DelayMS(5); | DelayMS(5); | ||
+ | |||
// | // | ||
// Update mouse state. | // Update mouse state. | ||
// | // | ||
USBDHIDMouseStateChange((void *)& | USBDHIDMouseStateChange((void *)& | ||
- | | + | cDeltaX, cDeltaY, |
- | | + | (ButtonIsPressed() ? MOUSE_REPORT_BUTTON_1 : 0)); |
} | } | ||
- | | + | } |
} | } | ||
</ | </ | ||
+ | |||
+ | ===== usb_mouse_struct.h ===== | ||
+ | |||
+ | <code c> | ||
+ | // | ||
+ | // | ||
+ | // usb_mouse_structs.h - Data structures defining the mouse USB device. | ||
+ | // | ||
+ | // | ||
+ | |||
+ | #ifndef _USB_MOUSE_STRUCTS_H_ | ||
+ | #define _USB_MOUSE_STRUCTS_H_ | ||
+ | // | ||
+ | // | ||
+ | // Application event handlers. | ||
+ | // | ||
+ | // | ||
+ | extern unsigned long MouseHandler(void *pvCBData, | ||
+ | unsigned long ulEvent, | ||
+ | unsigned long ulMsgData, | ||
+ | void *pvMsgData); | ||
+ | |||
+ | extern const tUSBDHIDMouseDevice g_sMouseDevice; | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | |||
+ | ===== usb_mouse_struct.c ===== | ||
+ | |||
+ | <code c> | ||
+ | // | ||
+ | // | ||
+ | // usb_mouse_structs.c - Data structures defining the USB mouse device. | ||
+ | // | ||
+ | // | ||
+ | |||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | // | ||
+ | // | ||
+ | // The languages supported by this device. | ||
+ | // | ||
+ | // | ||
+ | const unsigned char g_pLangDescriptor[] = | ||
+ | { | ||
+ | 4, | ||
+ | USB_DTYPE_STRING, | ||
+ | USBShort(USB_LANG_EN_US) | ||
+ | }; | ||
+ | |||
+ | // | ||
+ | // | ||
+ | // The manufacturer string. | ||
+ | // | ||
+ | // | ||
+ | const unsigned char g_pManufacturerString[] = | ||
+ | { | ||
+ | (30 + 1) * 2, | ||
+ | USB_DTYPE_STRING, | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | }; | ||
+ | |||
+ | // | ||
+ | // | ||
+ | // The product string. | ||
+ | // | ||
+ | // | ||
+ | const unsigned char g_pProductString[] = | ||
+ | { | ||
+ | (11 + 1) * 2, | ||
+ | USB_DTYPE_STRING, | ||
+ | ' | ||
+ | ' | ||
+ | }; | ||
+ | |||
+ | // | ||
+ | // | ||
+ | // The serial number string. | ||
+ | // | ||
+ | // | ||
+ | const unsigned char g_pSerialNumberString[] = | ||
+ | { | ||
+ | (8 + 1) * 2, | ||
+ | USB_DTYPE_STRING, | ||
+ | ' | ||
+ | }; | ||
+ | |||
+ | // | ||
+ | // | ||
+ | // The interface description string. | ||
+ | // | ||
+ | // | ||
+ | const unsigned char g_pHIDInterfaceString[] = | ||
+ | { | ||
+ | (19 + 1) * 2, | ||
+ | USB_DTYPE_STRING, | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | }; | ||
+ | |||
+ | // | ||
+ | // | ||
+ | // The configuration description string. | ||
+ | // | ||
+ | // | ||
+ | const unsigned char g_pConfigString[] = | ||
+ | { | ||
+ | (23 + 1) * 2, | ||
+ | USB_DTYPE_STRING, | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | }; | ||
+ | |||
+ | // | ||
+ | // | ||
+ | // The descriptor string table. | ||
+ | // | ||
+ | // | ||
+ | const unsigned char * const g_pStringDescriptors[] = | ||
+ | { | ||
+ | g_pLangDescriptor, | ||
+ | g_pManufacturerString, | ||
+ | g_pProductString, | ||
+ | g_pSerialNumberString, | ||
+ | g_pHIDInterfaceString, | ||
+ | g_pConfigString | ||
+ | }; | ||
+ | |||
+ | #define NUM_STRING_DESCRIPTORS (sizeof(g_pStringDescriptors) / \ | ||
+ | sizeof(unsigned char *)) | ||
+ | |||
+ | // | ||
+ | // | ||
+ | // The HID mouse device initialization and customization structures. | ||
+ | // | ||
+ | // | ||
+ | tHIDMouseInstance g_sMouseInstance; | ||
+ | |||
+ | const tUSBDHIDMouseDevice g_sMouseDevice = | ||
+ | { | ||
+ | USB_VID_LUMINARY, | ||
+ | USB_PID_MOUSE, | ||
+ | 500, | ||
+ | USB_CONF_ATTR_SELF_PWR, | ||
+ | MouseHandler, | ||
+ | (void *)& | ||
+ | g_pStringDescriptors, | ||
+ | NUM_STRING_DESCRIPTORS, | ||
+ | & | ||
+ | }; | ||
+ | </ | ||
+ |