Source file: /~heha/ewa/Motor/Maxmaus6.zip/main.cpp

//! This example application turns the evaluation board into a USB mouse
//! supporting the Human Interface Device class.  After loading and running the
//! example simply connect the PC to the controlCARDs microUSB port using a USB
//! cable, and the mouse pointer will move in a square pattern for the duration
//! of the time it is plugged in.

//#include "driverlib.h"
#include "device.h"
#include "usb_hal.h"
#include "usblib/usbdhidmouse.h"
// The languages supported by this device.
const uint8_t g_pLangDescriptor[] ={4,3, USB2(0x0409)};

// The manufacturer string.
const uint8_t g_pManufacturerString[] ={
    (17 + 1) * 2,3,
    'T', 0, 'e', 0, 'x', 0, 'a', 0, 's', 0, ' ', 0, 'I', 0, 'n', 0, 's', 0,
    't', 0, 'r', 0, 'u', 0, 'm', 0, 'e', 0, 'n', 0, 't', 0, 's', 0};

// The product string.
const uint8_t g_pProductString[] ={
    (13 + 1) * 2,3,
    'M', 0, 'o', 0, 'u', 0, 's', 0, 'e', 0, ' ', 0, 'E', 0, 'x', 0, 'a', 0,
    'm', 0, 'p', 0, 'l', 0, 'e', 0};

// The descriptor string table.
const uint8_t * const g_pStringDescriptors[] ={
  g_pLangDescriptor,
  g_pManufacturerString,
  g_pProductString,
};

//******************************************************************************
// The HID mouse device initialization and customization structures.
//******************************************************************************
/* Objekthierarchie:
usb:: { tDHIDMouseDevice -> tHIDDevice -> tDevice }
 */

usb::tHIDMouseDevice gMyDevice;

static volatile bool timer0overflow;
static volatile uint32_t g_ui32TickCount;       // Global system tick counter holds
	// elapsed time since the application started expressed in 100ths of a second.

//******************************************************************************
// This function provides simulated movements of the mouse.
//******************************************************************************
void MoveHandler() {
  char dx=0, dy=0;
    // Determine the direction to move the mouse.
  switch (g_ui32TickCount/100&3) {
    case 0: dx = 1; break;
    case 1: dy = 1; break;
    case 2: dx =-1; break;
    default:dy =-1; break;
  }
    // Tell the HID driver to send this new report.
  gMyDevice.StateChange(0, dx, dy);
}

//******************************************************************************
// CPUTimerIntHandler - This is the interrupt handler for the CPU Timer
// interrupt. It is called periodically and updates a global tick counter then
// sets a flag to tell the main loop to move the mouse.
//******************************************************************************
__interrupt void CPUTimerIntHandler() {
  g_ui32TickCount++;
  timer0overflow = true;
  Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
}

//******************************************************************************
//
// This is the main application entry function.
//
//******************************************************************************
int main() {
  gMyDevice.ppui8StringDescriptors=g_pStringDescriptors;
    // Initialize device clock and peripherals
  Device::init();
    // Initialize GPIO and configure GPIO pins for USB.
  Device::initGPIO();
    // Set the clocking to run from the PLL at 60MHz
  SysCtl_setAuxClock(DEVICE_AUXSETCLOCK_CFG_USB);
    // Initialize PIE and clear PIE registers. Disables CPU interrupts.
  Interrupt_initModule();
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
  Interrupt_initVectorTable();
  EINT;	// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
  ERTM;
  usb::GPIOEnable();
  Interrupt_register(INT_USBA, usb::DeviceIntHandler);
    // Initialize the USB stack for device mode.
//  GPIO_setDirectionMode(0, GPIO_DIR_MODE_OUT);
    // Register the interrupt handler, returning an error if an error occurs.
  Interrupt_register(INT_TIMER0, &CPUTimerIntHandler);
  CPUTimerInit();
  CPUTimer_setPeriod(CPUTIMER0_BASE,
                      (SysCtl_getClock(DEVICE_OSCSRC_FREQ) / 100));
    // Enable the CPU Timer interrupt.
  CPUTimer_enableInterrupt(CPUTIMER0_BASE);
  Interrupt_enable(INT_TIMER0);
  CPUTimer_startTimer(CPUTIMER0_BASE);
    // Pass the USB library our device information, initialize the USB
    // controller and connect the device to the bus.
  gMyDevice.Init();
  Interrupt_enableMaster();

  for(;;) {
    if (timer0overflow) {
            // If it is time to move the mouse then do so.
      timer0overflow=false;
      MoveHandler();
    }
  }
}
Detected encoding: ASCII (7 bit)2