Source file: /~heha/ewa/Motor/Maxmaus5.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:
tMyDevice -> tUSBDHIDMouseDevice -> tUSBDHIDDevice -> tDeviceInfo -> tCustomHandlers
 */

struct tMyDevice:public tUSBDHIDMouseDevice{
  virtual uint32_t RxCallback(uint32_t ui32Event, uint32_t ui32MsgData, void *pvMsgData) override;
}gMyDevice;

static volatile bool timer0overflow;
static volatile bool g_bConnected;              // A flag used to indicate whether or
                                         // not we are currently connected to
                                         // the USB host.
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 handles notification messages from the mouse device driver.
//******************************************************************************
uint32_t tMyDevice::RxCallback(uint32_t event, uint32_t data, void *ptr) {
  switch(event) {
        // The USB host has connected to and configured the device.
    case USB_EVENT_CONNECTED: g_bConnected = true; break;
        // The USB host has disconnected from the device.
    case USB_EVENT_DISCONNECTED: g_bConnected = false; break;
  }
  return tUSBDHIDMouseDevice::RxCallback(event,data,ptr);
}

//******************************************************************************
// This function provides simulated movements of the mouse.
//******************************************************************************
void MoveHandler(void) {
  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(dx, dy, 0);
}

//******************************************************************************
// 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(void) {
    g_ui32TickCount++;
    timer0overflow = true;
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
}

//******************************************************************************
//
// This is the main application entry function.
//
//******************************************************************************
int main(void) {
  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;
  USBGPIOEnable();
  Interrupt_register(INT_USBA, f28x_USB0DeviceIntHandler);
    // 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 (g_bConnected && timer0overflow) {
            // If it is time to move the mouse then do so.
      timer0overflow=false;
      MoveHandler();
    }
  }
}
Detected encoding: ASCII (7 bit)2