/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { uint32_t u32TrimInit; /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART0_Init(); printf("\n"); printf("+--------------------------------------------------------------+\n"); printf("| NuMicro USB Virtual COM and HID Keyboard Sample Code |\n"); printf("+--------------------------------------------------------------+\n"); printf("If PB.15 = 0, just report it is key 'a'.\n"); /* Set PB.15 as Quasi-bidirectional mode */ PB->PMD = (PB->PMD & ~GPIO_PMD_PMD15_Msk) | (GPIO_PMD_QUASI << GPIO_PMD_PMD15_Pos); USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Endpoint configuration */ HID_Init(); USBD_Start(); #if CRYSTAL_LESS /* Backup init trim */ u32TrimInit = M32(TRIM_INIT); /* Enable USB crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); #endif NVIC_EnableIRQ(USBD_IRQn); NVIC_EnableIRQ(UART02_IRQn); while(1) { #if CRYSTAL_LESS /* Re-start crystal-less when any error found */ if (SYS->HIRCTSTS & (SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk)) { SYS->HIRCTSTS = SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk; if((u32TrimInit < 0x1E6) || (u32TrimInit > 0x253)) /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (1 << SYS_HIRCTCTL_BOUNDARY_Pos); else /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); //printf("USB trim fail. Just retry. SYS->HIRCTSTS = 0x%x, SYS->HIRCTCTL = 0x%x\n", SYS->HIRCTSTS, SYS->HIRCTCTL); } #endif VCOM_TransferData(); HID_UpdateKbData(); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { uint32_t u32TrimInit; /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART0_Init(); printf("\n"); printf("+--------------------------------------------------------+\n"); printf("| NuMicro USB HID Keyboard Sample Code |\n"); printf("+--------------------------------------------------------+\n"); printf("If PB.15 = 0, just report it is key 'a'.\n"); USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Endpoint configuration */ HID_Init(); USBD_Start(); #if CRYSTAL_LESS /* Backup init trim */ u32TrimInit = M32(TRIM_INIT); /* Enable USB crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); #endif NVIC_EnableIRQ(USBD_IRQn); /* start to IN data */ g_u8EP2Ready = 1; while(1) { #if CRYSTAL_LESS /* Re-start crystal-less when any error found */ if (SYS->HIRCTSTS & (SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk)) { SYS->HIRCTSTS = SYS_HIRCTSTS_CLKERIF_Msk | SYS_HIRCTSTS_TFAILIF_Msk; if((u32TrimInit < 0x1E6) || (u32TrimInit > 0x253)) /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (1 << SYS_HIRCTCTL_BOUNDARY_Pos); else /* Re-enable crystal-less */ SYS->HIRCTCTL = 0x201 | (31 << SYS_HIRCTCTL_BOUNDARY_Pos); //printf("USB trim fail. Just retry. SYS->HIRCTSTS = 0x%x, SYS->HIRCTCTL = 0x%x\n", SYS->HIRCTSTS, SYS->HIRCTCTL); } #endif HID_UpdateKbData(); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main(void) { /* This sample code demonstrate how to use HID interface to transfer data between PC and USB device. A demo window tool is also included in "WindowsTool" directory with this sample code. User can use it to test data transfer with this sample code. */ /* Unlock write-protected registers */ SYS_UnlockReg(); /* Init system and multi-function I/O */ SYS_Init(); /* Init UART for debug message */ UART0_Init(); printf("\n"); printf("+--------------------------------------------------------+\n"); printf("| NuMicro USB Composite Device Sample Code |\n"); printf("| (USB HID Transfer + Keyboard) |\n"); printf("+--------------------------------------------------------+\n"); printf("If PB.5 = 0, just report key 'a'.\n"); /* Set PB.5 as Quasi-bidirectional mode */ PB->MODE = (PB->MODE & ~GPIO_MODE_MODE5_Msk) | (GPIO_MODE_QUASI << GPIO_MODE_MODE5_Pos); /* Open USB controller */ USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Init Endpoint configuration for HID */ HID_Init(); /* Start USB device */ USBD_Start(); /* Enable USB device interrupt */ NVIC_EnableIRQ(USBD_IRQn); while(1) { HID_UpdateKbData(); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main (void) { SYS_Init(); UART0_Init(); printf("NuMicro USB composite device Sample.(VCOM and HID Keyboard)\n"); printf("If PB.15 = 0, just report it is key 'a'.\n"); USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Endpoint configuration */ HID_Init(); NVIC_EnableIRQ(UART0_IRQn); NVIC_EnableIRQ(USBD_IRQn); USBD_Start(); while(1) { VCOM_TransferData(); HID_UpdateKbData(); } }