TI中文支持网
TI专业的中文技术问题搜集分享网站

TM4C123GXL launchpad做鼠标、游戏手柄的相关问题

现在手上有一块TM4C123GXL  launchpad,想做一个模拟USB鼠标,参考了TivaWare中提供的 “usb_dev_gamepad” 例程还是没有头绪,想问下各位大神几个问题:

1.用开发板做一个模拟USB鼠标需要了解什么知识?

2.下面usblib.h代码分别是什么模式?在什么时候使用?

typedef enum
{////! Operate in USB device mode with active monitoring of VBUS and the//! ID pin must be pulled to a logic high value.//eUSBModeDevice = 0,////! Operate in USB host mode with active monitoring of VBUS and the ID pin//! must be pulled to a logic low value.//eUSBModeHost,////! Operate as an On-The-Go device which requires both VBUS and ID to be//! connected directly to the USB controller from the USB connector.//eUSBModeOTG,////! A marker indicating that no USB mode has yet been set by the//! application.//eUSBModeNone,////! Force host mode so that the VBUS and ID pins are not used or monitored//! by the USB controller.//eUSBModeForceHost,////! Forcing device mode so that the VBUS and ID pins are not used or//! monitored by the USB controller.//eUSBModeForceDevice,
}
tUSBMode;

3.在usblib.h文件中有:

extern void USBStackModeSet(uint32_t ui32Index, tUSBMode iUSBMode, tUSBModeCallback pfnCallback);

想问下这个函数的三个参数分别代表什么?如何使用?

4.自己按例程改的代码如下,在main中运行到USBStackModeSet(0, eUSBModeForceDevice, 0);时会跳入错误函数,想了解这块怎么写?(main.c 82行)

以下为代码,其他用的都是官方代码就不贴了

main.c

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "driverlib/adc.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "usblib/usblib.h"
#include "usblib/usbhid.h"
#include "usblib/device/usbdevice.h"
#include "usblib/device/usbdhid.h"
#include "usblib/device/usbdhidmouse.h"
#include "usb_mouse_structs.h"
//#include "drivers/buttons.h"
#include "utils/uartstdio.h"
#include "drivers/rocker.h"

//extern void USBStackModeSet(uint32_t ui32Index, tUSBMode iUSBMode, tUSBModeCallback pfnCallback);
//void *USBDHIDMouseInit(uint32_t ui32Index, tUSBDHIDMouseDevice *psMouseDevice);
//uint32_t USBDHIDMouseStateChange(void *pvMouseDevice, int8_t i8DeltaX, int8_t i8DeltaY, uint8_t ui8Buttons);

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

volatile enum
{//// Not yet configured.//eStateNotConfigured,//// Connected and not waiting on data to be sent.//eStateIdle,//// Suspended.//eStateSuspend,//// Connected and waiting on data to be sent out.//eStateSending
}
g_iGamepadState;

int main(void)
{
	ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

	//LED_RED
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

	ConfigureUART();
	
	// Not configured initially.
	g_iGamepadState = eStateNotConfigured;

	//
	// Enable the GPIO peripheral used for USB, and configure the USB
	// pins.
	//
	ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
	SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);
	ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_AHB_BASE, GPIO_PIN_4 | GPIO_PIN_5);

//	ButtonsInit();
//	ADCInit();

	UARTprintf("Configuring USB\n");

	USBStackModeSet(0, eUSBModeForceDevice, 0);

	USBDHIDMouseInit(0, &g_sMouseDevice);

	while(1)
		USBDHIDMouseStateChange(&g_sMouseDevice, 1, 1, 1);

	return 0;
}

void
ConfigureUART(void)
{//// Enable the GPIO Peripheral used by the UART.//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);//// Enable UART0//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);//// Configure GPIO Pins for UART mode.//ROM_GPIOPinConfigure(GPIO_PA0_U0RX);ROM_GPIOPinConfigure(GPIO_PA1_U0TX);ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);//// Use the internal 16MHz oscillator as the UART clock source.//UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);//// Initialize the UART for console I/O.//UARTStdioConfig(0, 115200, 16000000);
}

uint32_t MouseHandler(void *pvCBData, uint32_t ui32Event,uint32_t ui32MsgData, void *pvMsgData)
{

}

usb_mouse_structs.c

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "usblib/usblib.h"
#include "usblib/usbhid.h"
#include "usblib/usb-ids.h"
#include "usblib/device/usbdevice.h"
#include "usblib/device/usbdcomp.h"
#include "usblib/device/usbdhid.h"
#include "usblib/device/usbdhidmouse.h"

#include "usb_mouse_structs.h"

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

//****************************************************************************
//
// The manufacturer string.
//
//****************************************************************************
const uint8_t g_pui8ManufacturerString[] =
{(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_pui8ProductString[] =
{(17 + 1) * 2,USB_DTYPE_STRING,'E', 0, 'x', 0, 'a', 0, 'm', 0, 'p', 0, 'l', 0, 'e', 0, ' ', 0,'G', 0, 'a', 0, 'm', 0, 'e', 0, ' ', 0, 'P', 0, 'a', 0, 'd', 0, ' ', 0,
};

//****************************************************************************
//
// The serial number string.
//
//****************************************************************************
const uint8_t g_pui8SerialNumberString[] =
{(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_pui8HIDInterfaceString[] =
{(21 + 1) * 2,USB_DTYPE_STRING,'H', 0, 'I', 0, 'D', 0, ' ', 0, 'G', 0, 'a', 0, 'm', 0, 'e', 0,'p', 0, 'a', 0, 'd', 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_pui8ConfigString[] =
{(25 + 1) * 2,USB_DTYPE_STRING,'H', 0, 'I', 0, 'D', 0, ' ', 0, 'G', 0, 'a', 0, 'm', 0, 'e', 0,'p', 0, 'a', 0, 'd', 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_ppui8StringDescriptors[] =
{g_pui8LangDescriptor,g_pui8ManufacturerString,g_pui8ProductString,g_pui8SerialNumberString,g_pui8HIDInterfaceString,g_pui8ConfigString
};

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

//*****************************************************************************
//
// The HID game pad device initialization and customization structures.
//
//*****************************************************************************
tUSBDHIDMouseDevice  g_sMouseDevice =
{USB_VID_TI_1CBE,
	USB_PID_MOUSE,500,USB_CONF_ATTR_SELF_PWR | USB_CONF_ATTR_RWAKE,
	USB_PID_MOUSE,(void *)&g_sMouseDevice,g_ppui8StringDescriptors,NUM_STRING_DESCRIPTORS
};

感谢各位工程师、大佬们赐教。

编译环境:win7,CCS6.2

Seven Han:

您好,

5.2月2-4号论坛处于维护状态,可能会存在无法访问的情况,请谅解!

赞(0)
未经允许不得转载:TI中文支持网 » TM4C123GXL launchpad做鼠标、游戏手柄的相关问题
分享到: 更多 (0)