Differences

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

Link to this comparison view

Next revision
Previous revision
en:projects:crazy_mouse [2010/03/14 14:18] – created mikk.leinien: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.+//Requirements: [HW] [[en:hardware:avr-can:controller]]// 
 + 
 +[{{  :images:projects:crazy_mouse:crazy_mouse_windows_cursor.png|Mouse cursor moving round}}] 
 + 
 +ARM-CAN USB mouse demo project. Software is based on TI StellarisWare USB library. When attaching the ARM-CAN controller board to the PC, it acts as a standard USB HID mouse. Fixed-point sine calculation functions are used to move cursor around. Push-button on the controller board acts as a left button. 
 + 
 +~~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 + // 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); + SYSCTL_XTAL_8MHZ); 
-     +
  //  //
  // Drivers configuring.  // Drivers configuring.
  //  //
  DeviceConfigure();  DeviceConfigure();
 +
  //  //
-    // Pass the USB library our device information, initialize the USB + // Pass the USB library our device information, initialize the USB 
-    // controller and connect the device to the bus. + // controller and connect the device to the bus.
-    // +
-    USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); +
  //  //
-    // Enable processor interrupts. + USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice);
-    // +
-    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 *)&g_sMouseDevice,  USBDHIDMouseStateChange((void *)&g_sMouseDevice,
-                         cDeltaX, cDeltaY, + cDeltaX, cDeltaY, 
-                         (ButtonIsPressed() ? MOUSE_REPORT_BUTTON_1 : 0)); + (ButtonIsPressed() ? MOUSE_REPORT_BUTTON_1 : 0));
  }  }
-    }+ }
 } }
 </code> </code>
 +
 +===== 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
 +</code>
 +
 +===== usb_mouse_struct.c =====
 +
 +<code c>
 +//*****************************************************************************
 +//
 +// usb_mouse_structs.c - Data structures defining the USB mouse device.
 +//
 +//*****************************************************************************
 +
 +#include "inc/hw_types.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 "usb_mouse_structs.h"
 +
 +//*****************************************************************************
 +//
 +// 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,
 +    'T', 0, 'U', 0, 'T', 0, ' ', 0, 'D', 0, 'e', 0, 'p', 0, 'a', 0,
 + 'r', 0, 't', 0, 'm', 0, 'e', 0, 'n', 0, 't', 0, ' ', 0, 'o', 0,
 + 'f', 0, ' ', 0, 'm', 0, 'e', 0, 'c', 0, 'h', 0, 'a', 0, 't', 0,
 + 'r', 0, 'o', 0, 'n', 0, 'i', 0, 'c', 0, 's', 0
 +};
 +
 +//*****************************************************************************
 +//
 +// The product string.
 +//
 +//*****************************************************************************
 +const unsigned char g_pProductString[] =
 +{
 +    (11 + 1) * 2,
 +    USB_DTYPE_STRING,
 +    'C', 0, 'r', 0, 'a', 0, 'z', 0, 'y', 0, ' ', 0, 'M', 0, 'o', 0, 'u', 0,
 +    's', 0, 'e', 0
 +};
 +
 +//*****************************************************************************
 +//
 +// The serial number string.
 +//
 +//*****************************************************************************
 +const unsigned char g_pSerialNumberString[] =
 +{
 +    (8 + 1) * 2,
 +    USB_DTYPE_STRING,
 +    'F', 0, 'F', 0, 'F', 0, 'F', 0, 'F', 0, 'F', 0, 'F', 0, 'F', 0
 +};
 +
 +//*****************************************************************************
 +//
 +// The interface description string.
 +//
 +//*****************************************************************************
 +const unsigned char g_pHIDInterfaceString[] =
 +{
 +    (19 + 1) * 2,
 +    USB_DTYPE_STRING,
 +    'H', 0, 'I', 0, 'D', 0, ' ', 0, 'M', 0, 'o', 0, 'u', 0, 's', 0,
 +    'e', 0, ' ', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0, 'r', 0, 'f', 0,
 +    'a', 0, 'c', 0, 'e', 0
 +};
 +
 +//*****************************************************************************
 +//
 +// The configuration description string.
 +//
 +//*****************************************************************************
 +const unsigned char g_pConfigString[] =
 +{
 +    (23 + 1) * 2,
 +    USB_DTYPE_STRING,
 +    'H', 0, 'I', 0, 'D', 0, ' ', 0, 'M', 0, 'o', 0, 'u', 0, 's', 0,
 +    'e', 0, ' ', 0, 'C', 0, 'o', 0, 'n', 0, 'f', 0, 'i', 0, 'g', 0,
 +    'u', 0, 'r', 0, 'a', 0, 't', 0, 'i', 0, 'o', 0, 'n', 0
 +};
 +
 +//*****************************************************************************
 +//
 +// 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_sMouseDevice,
 +    g_pStringDescriptors,
 +    NUM_STRING_DESCRIPTORS,
 +    &g_sMouseInstance
 +};
 +</code>
 +
en/projects/crazy_mouse.1268576305.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