/*---------------------------------------------------------------------------------------------------------*/ 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) { uint32_t au32Config[2]; SYS_Init(); UART0_Init(); printf("NuMicro USB composite device Sample.(HID Transfer and Mass storage)\n"); SYS_UnlockReg(); /* Enable FMC ISP function */ FMC_Open(); /* Check if Data Flash Size is 64K. If not, to re-define Data Flash size and to enable Data Flash function */ if (FMC_ReadConfig(au32Config, 2) < 0) return -1; if (((au32Config[0] & 0x01) == 1) || (au32Config[1] != DATA_FLASH_BASE) ) { FMC_ENABLE_CFG_UPDATE(); au32Config[0] &= ~0x1; au32Config[1] = DATA_FLASH_BASE; if (FMC_WriteConfig(au32Config, 2) < 0) return -1; FMC_ReadConfig(au32Config, 2); if (((au32Config[0] & 0x01) == 1) || (au32Config[1] != DATA_FLASH_BASE)) { printf("Error: Program Config Failed!\n"); /* Disable FMC ISP function */ FMC_Close(); SYS_LockReg(); return -1; } /* Reset Chip to reload new CONFIG value */ SYS->IPRST_CTL1 = SYS_IPRST_CTL1_CHIP_RST_Msk; } SYS_LockReg(); USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Endpoint configuration */ HID_Init(); NVIC_EnableIRQ(USBD_IRQn); USBD_Start(); while(1) { if (g_usbd_UsbConfig) MSC_ProcessCmd(); } }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main (void) { SYS_Init(); UART0_Init(); printf("NuMicro USB HID Transfer via Control Transfer\n"); printf("Windows tool will Read and Write one pair of reports(periodic exchanges of reports).\n"); USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Endpoint configuration */ HID_Init(); NVIC_EnableIRQ(USBD_IRQn); USBD_Start(); while(1) { } }
/*---------------------------------------------------------------------------------------------------------*/ 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 HID\n"); USBD_Open(&gsInfo, HID_ClassRequest, NULL); /* Endpoint configuration */ HID_Init(); NVIC_EnableIRQ(USBD_IRQn); USBD_Start(); while(1) { HID_UpdateMouseData(); } }
/*---------------------------------------------------------------------------------------------------------*/ 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(); } }
void main (void) { // set pll out 48Mhz, set cpu clock 48Mhz SYS_UnlockReg(); CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk); CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk); CLK_SetCoreClock(48000000); CLK_EnableModuleClock(USBD_MODULE); CLK_SetModuleClock(USBD_MODULE, 0, CLK_CLKDIV_USB(1)); DAP_Setup(); USBD_Open(&gsInfo, HID_ClassRequest, NULL); HID_Init(); balabala_hid_init(); USBD_Start(); NVIC_EnableIRQ(USBD_IRQn); while(1) { usbd_hid_process(); } }
int main() { CLEAR_WRITE(); SET_STOPMOTOR(); CLEAR_SCANMEDIA(); CLEAR_MEDIASET(); CLEAR_READY(); //setup led and button gpio GPIO_SetMode(LED_G_PORT, LED_G_PIN, GPIO_PMD_OUTPUT); GPIO_SetMode(LED_R_PORT, LED_R_PIN, GPIO_PMD_OUTPUT); GPIO_SetMode(SWITCH_PORT, SWITCH_PIN, GPIO_PMD_INPUT); GPIO_SetMode(IRDATA_PORT, IRDATA_PIN, GPIO_PMD_INPUT); LED_GREEN(0); LED_RED(1); detect_board_version(); /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); /* Lock protected registers */ SYS_LockReg(); UART0_Init(); SPI_Init(); TIMER_Open(TIMER0, TIMER_CONTINUOUS_MODE, 6000000); TIMER_Open(TIMER1, TIMER_PERIODIC_MODE, TRANSFER_RATE * 2); TIMER_Open(TIMER3, TIMER_PERIODIC_MODE, TRANSFER_RATE * 2); TIMER_EnableInt(TIMER1); TIMER_EnableInt(TIMER3); /* 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); LED_GREEN(1); LED_RED(0); printf("\n\nnuc123-fdsemu v%d.%02d build %d started. Compiled on "__DATE__" at "__TIME__"\n",version / 100,version % 100,BUILDNUM); printf("--CPU @ %0.3f MHz\n", (double)SystemCoreClock / 1000000.0f); printf("--SPI0 @ %0.3f MHz\n", (double)SPI_GetBusClock(SPI0) / 1000000.0f); printf("--SPI1 @ %0.3f MHz\n", (double)SPI_GetBusClock(SPI1) / 1000000.0f); printf("--Detected board version: %d (config = %d %d %d)\n", boardver,PA12,PA13,PA14); NVIC_SetPriority(USBD_IRQn,2); NVIC_SetPriority(TMR1_IRQn,1); NVIC_SetPriority(TMR2_IRQn,0); NVIC_SetPriority(TMR3_IRQn,0); NVIC_SetPriority(GPAB_IRQn,0); NVIC_SetPriority(EINT0_IRQn,0); flash_init(); sram_init(); fds_init(); print_block_info(0); while(1) { if(havepacket) { havepacket = 0; // process_send_feature(epdata,64); } console_tick(); fds_tick(); } }
void Task2(void *Id) { int32_t i32Ret = E_SUCCESS; E_DRVUSB_STATE eUsbState; (void) Id; i32Ret = DrvUSB_Open((void *)DrvUSB_DispatchEvent); // i32Ret = DrvUSB_Open(0); //随便。。 if (i32Ret != E_SUCCESS) return ; while (1) { /* Disable USB-related interrupts. */ _DRVUSB_ENABLE_MISC_INT(0); /* Enable float-detection interrupt. */ _DRVUSB_ENABLE_FLDET_INT(); // Wait for USB connected. while (1) { // Order here is significant. // Give a chance to handle remaining events before exiting this loop. eUsbState = DrvUSB_GetUsbState(); //DrvUSB_DispatchEvent(); if (eUsbState >= eDRVUSB_ATTACHED && eUsbState != eDRVUSB_SUSPENDED) { break; } } /* Start HID and install the callback functions to handle in/out report */ HID_Init((void *)HID_GetInReport, (void *)HID_SetOutReport); // Enable USB-related interrupts. _DRVUSB_ENABLE_MISC_INT(INTEN_WAKEUP | INTEN_WAKEUPEN | INTEN_FLDET | INTEN_USB | INTEN_BUS); // Poll and handle USB events. while (1) { eUsbState = DrvUSB_GetUsbState(); // DrvUSB_DispatchEvent(); if (eUsbState == eDRVUSB_DETACHED) { break; } // // err = OSTaskStkChk(OS_PRIO_SELF, &stk_data); // if (err == OS_NO_ERR) { // stk_size = stk_data.OSFree + stk_data.OSUsed; // printf(" task 2 stk_size is %d,stk_data.OSFree is %d ,stk_data.OSUsed is %d \n\n",stk_size,stk_data.OSFree,stk_data.OSUsed ); // } } // Disable USB-related interrupts. _DRVUSB_ENABLE_MISC_INT(0); // OSTimeDly(100); } }