Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:examples:usb:crazy_mouse [2010/02/16 11:44] – created mikk.leinien:examples:usb:crazy_mouse [2010/03/14 14:17] (current) – removed mikk.leini
Line 1: Line 1:
-====== Crazy USB mouse ====== 
  
-<code c> 
-//***************************************************************************** 
-// 
-// Crazy USB mouse. 
-// 
-// Copyright (c) 2009 TUT Department of Mechatronics 
-// 
-//***************************************************************************** 
- 
-#include <inc/hw_ints.h> 
-#include <inc/hw_types.h> 
-#include <driverlib/sysctl.h> 
-#include <driverlib/interrupt.h> 
-#include <driverlib/usb.h> 
-#include <usblib/usblib.h> 
-#include <usblib/usbhid.h> 
-#include <usblib/usb-ids.h> 
-#include <usblib/device/usbdevice.h> 
-#include <usblib/device/usbdhid.h> 
-#include <usblib/device/usbdhidmouse.h> 
-#include <drivers/general.h> 
-#include <utils/sine.h> 
-#include "usb_mouse_structs.h" 
- 
-//***************************************************************************** 
-// 
-// Global variables. 
-// 
-//***************************************************************************** 
-volatile tBoolean g_bConnected; 
-volatile tBoolean g_bCanSend; 
- 
-//***************************************************************************** 
-// 
-// Mouse handler. 
-// 
-//***************************************************************************** 
-unsigned long MouseHandler(void *pvCBData, unsigned long ulEvent, 
-                           unsigned long ulMsgData, void *pvMsgData) 
-{ 
-    switch (ulEvent) 
-    { 
-        // 
-        // The USB host has connected to and configured the device. 
-        // 
-        case USB_EVENT_CONNECTED: 
-        {             
-            g_bConnected = true; 
- g_bCanSend = true; 
-            break; 
-        } 
- 
-        // 
-        // The USB host has disconnected from the device. 
-        // 
-        case USB_EVENT_DISCONNECTED: 
-        {          
-            g_bConnected = false;          
- g_bCanSend = false; 
-            break; 
-        } 
- 
-        // 
-        // A report was sent to the host. 
-        // 
-        case USB_EVENT_TX_COMPLETE: 
-        {             
- g_bCanSend = true; 
-            break; 
-        } 
- 
-    } 
-    return(0); 
-} 
- 
-//***************************************************************************** 
-// 
-// Main function. 
-// 
-//***************************************************************************** 
-int main(void) 
-{  
- unsigned long ulAngle = 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 | 
-                   SYSCTL_XTAL_8MHZ); 
-      
- // 
- // Drivers configuring. 
- // 
- DeviceConfigure(); 
- 
- // 
-    // Pass the USB library our device information, initialize the USB 
-    // controller and connect the device to the bus. 
-    // 
-    USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); 
- 
- // 
-    // Enable processor interrupts. 
-    // 
-    IntMasterEnable();  
-  
-    // 
-    // Loop forever. 
-    // 
-    while (true) 
-  {  
- // 
- // Device connected and ready ? 
- // 
- if (g_bConnected && g_bCanSend) 
- {  
- // 
- // Rotate by 1 / 256 of full circle. 
- // 
- ulAngle += 0x1000000; 
- 
- // 
- // Calculate X and Y movement. 
- // Use sine function with fixed point numbers. 
- // 
- cDeltaX = sine(ulAngle) >> 14; 
- cDeltaY = sine(ulAngle - 0x40000000) >> 14; 
- 
- // 
- // Keep a small break. 
- // 
- DelayMS(5); 
- 
- // 
- // Update mouse state. 
- //  
- USBDHIDMouseStateChange((void *)&g_sMouseDevice, 
-                         cDeltaX, cDeltaY, 
-                         (ButtonIsPressed() ? MOUSE_REPORT_BUTTON_1 : 0));  
- } 
-    } 
-} 
-</code> 
en/examples/usb/crazy_mouse.1266320648.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0