Source file: /~heha/ewa/Motor/Maxmaus1.zip/main.c

//! 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.h>
#include <usbhid.h>
#include <device/usbdevice.h>
#include <device/usbdhid.h>
#include <device/usbdhidmouse.h>
#include <stdint.h>
#include <stdbool.h>
#include <inc/hw_types.h>
#include <usb_ids.h>

//******************************************************************************
//
// The languages supported by this device.
//
//******************************************************************************
const uint8_t g_pLangDescriptor[] =
{
    4,
    USB_DTYPE_STRING,
    USBShort(USB_LANG_EN_US)
};

//******************************************************************************
//
// The manufacturer string.
//
//******************************************************************************
const uint8_t g_pManufacturerString[] =
{
    (17 + 1) * 2,
    USB_DTYPE_STRING,
    '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,
    USB_DTYPE_STRING,
    '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 serial number string.
//
//******************************************************************************
const uint8_t g_pSerialNumberString[] =
{
    (8 + 1) * 2,
    USB_DTYPE_STRING,
    '1', 0, '2', 0, '3', 0, '4', 0, '5', 0, '6', 0, '7', 0, '8', 0
};

//******************************************************************************
//
// The interface description string.
//
//******************************************************************************
const uint8_t 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 uint8_t 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 uint8_t * const g_pStringDescriptors[] =
{
    g_pLangDescriptor,
    g_pManufacturerString,
    g_pProductString,
    g_pSerialNumberString,
    g_pHIDInterfaceString,
    g_pConfigString
};

#define NUM_STRING_DESCRIPTORS (sizeof(g_pStringDescriptors)                  /\
                                sizeof(uint8_t *))

//******************************************************************************
//
// The HID mouse device initialization and customization structures.
//
//******************************************************************************
tHIDMouseInstance g_sMouseInstance;

static uint32_t MouseHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgData, void *pvMsgData);

tUSBDHIDMouseDevice g_sMouseDevice = {
  USB_VID_TI_1CBE,
  USB_PID_MOUSE,
  500,
  USB_CONF_ATTR_SELF_PWR,
  MouseHandler,
  &g_sMouseDevice,
  g_pStringDescriptors,
  NUM_STRING_DESCRIPTORS,
};

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.

//******************************************************************************
// MouseHandler - This function handles notification messages from the
//                mouse device driver.
//******************************************************************************
static uint32_t MouseHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgData, void *pvMsgData) {
  switch(ui32Event) {
        // 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;
        // A report was sent to the host.  We are not free to send another.
    case USB_EVENT_TX_COMPLETE: break;
        // Ignore the other events.
    default: break;
  }
  return 0;
}

//******************************************************************************
// MoveHandler - 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.
  USBDHIDMouseStateChange(&g_sMouseDevice, 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) {
    // 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.
  USBDHIDMouseInit(0,&g_sMouseDevice);
  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