This is an old revision of the document!
ARM-CAN demo project.
//***************************************************************************** // // 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)); } } }