Source file: /~heha/ewa/Motor/Maxmaus8.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 "device.h"
#include "driverlib.h"
#include "usblib/usbdhidmouse.h"

//usb:: { tDHIDMouseDevice -> 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() {
    // Initialize device clock and peripherals
  Device::init();
#if 1
  SysCtl_setAuxClock(SYSCTL_OSCSRC_XTAL	// use 10 MHz crystal as source
		| SYSCTL_PLL_ENABLE
		| SYSCTL_IMULT(12)	// multiply by 12 => 120 MHz
		| SYSCTL_SYSDIV(2));	// divide by 2 => 60 MHz needed for USB
#else
#include <F2837xD_device.h>
  EALLOW;
  ClkCfgRegs.CLKSRCCTL2.all=1;		// Quelle = Externer 10-MHz-Oszillator
  SysCtl_delay(38);			// 200 CPU-Takte warten: 9 Takte + 38×5 Takte
  ClkCfgRegs.AUXPLLMULT.all=12;	// 10 MHz × 12 = 120 MHz
//  ClkCfgRegs.AUXCLKDIVSEL.all|=1;	// steht schon auf /2 nach RESET
  while (!ClkCfgRegs.AUXPLLSTS.bit.LOCKS);
  ClkCfgRegs.AUXPLLCTL1.bit.PLLCLKEN=1;
  EDIS;
#endif
    // 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);
    // Register the interrupt handler, returning an error if an error occurs.
  Interrupt_register(INT_TIMER0, CPUTimerIntHandler);
  CPUTimerInit();
  CPUTimer_setPeriod(CPUTIMER0_BASE, (SysCtl_getClock(Device::F_XTAL) / 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: UTF-80