Description
Source
Call Graph
Start Line: 627
int main(void)
{
unsigned int cnt=0;
unsigned int len;
unsigned char iBuffer[64];
unsigned char oBuffer[64];
unsigned char bmLEDs=0;
unsigned char update;
TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);
printf("-- USB Device HID Transfer Project 1.4 --\n\r");
// If they are present, configure Vbus & Wake-up pins
PIO_InitializeInterrupts(0);
WAKEUP_CONFIGURE();
// Configure PINs for LEDs and Buttons
LED_Configure(0);
LED_Configure(1);
PIO_Configure(pinsButtons, PIO_LISTSIZE(pinsButtons));
#ifdef PINS_JOYSTICK
PIO_Configure(pinsJoystick, PIO_LISTSIZE(pinsJoystick));
#endif
// HID driver initialization
HIDDTransferDriver_Initialize();
// connect if needed
VBUS_CONFIGURE();
while (USBD_GetState() < USBD_STATE_CONFIGURED);
// Infinite loop
while (1) {
update = 0;
len = HIDDTransferDriver_Read(iBuffer, 64);
if (len) {
printf("Data In(%d):", len);
ShowBuffer(iBuffer, len);
bmLEDs = iBuffer[0];
update = 1;
}
len = HIDDTransferDriver_ReadReport(iBuffer, 64);
if (len) {
printf("Report In(%d):", len);
ShowBuffer(iBuffer, len);
bmLEDs = iBuffer[0];
update = 1;
}
// Update the status of LEDs
if (update && (0x80 & bmLEDs)) {
// LED1
if (bmLEDs & 0x01) {
LED_Set(0);
}
else {
LED_Clear(0);
}
// LED2
if (bmLEDs & 0x02) {
LED_Set(1);
}
else {
LED_Clear(1);
}
}
// Update the status of the buttons
oBuffer[0] = 0x80;
if (PIO_Get(&pinsButtons[PUSHBUTTON_BP1]) == 0) {
oBuffer[0] |= 0x01;
}
#ifdef PUSHBUTTON_BP2
if (PIO_Get(&pinsButtons[PUSHBUTTON_BP2]) == 0) {
oBuffer[0] |= 0x02;
}
#endif
#ifdef PINS_JOYSTICK
if (PIO_Get(&pinsJoystick[JOYSTICK_LEFT]) == 0) {
oBuffer[0] |= 0x04;
}
if (PIO_Get(&pinsJoystick[JOYSTICK_UP]) == 0) {
oBuffer[0] |= 0x08;
}
if (PIO_Get(&pinsJoystick[JOYSTICK_DOWN]) == 0) {
oBuffer[0] |= 0x10;
}
if (PIO_Get(&pinsJoystick[JOYSTICK_RIGHT]) == 0) {
oBuffer[0] |= 0x20;
}
#endif
sprintf((char*)&oBuffer[5], ":%04x:%05d!", cnt, cnt);
oBuffer[1] = (unsigned char)(cnt);
oBuffer[2] = (unsigned char)(cnt >> 8);
oBuffer[3] = (unsigned char)(cnt >> 16);
oBuffer[4] = (unsigned char)(cnt >> 24);
if (USBD_STATUS_SUCCESS == HIDDTransferDriver_Write(oBuffer, 64, 0, 0)) {
cnt ++;
}
if( USBState == STATE_SUSPEND ) {
TRACE_DEBUG("suspend !\n\r");
LowPowerMode();
USBState = STATE_IDLE;
}
if( USBState == STATE_RESUME ) {
// Return in normal MODE
TRACE_DEBUG("resume !\n\r");
NormalPowerMode();
USBState = STATE_IDLE;
}
}
}