int main(int ac, char **av) { int i, l, l1, l2; USB_Open(); // We send bytes one by one - not very efficient from the USB point of view, but keeps // things simple // For commands, it's ok to send 2 bytes at once because the first one (0x00) is not sent // to the LCD module but is just there to indicate that the second byte is a command to the LCD // Remember, the PC is little-endian, so that's 0x00 followed by 0x38 !! USB_WriteWord(0x3800); // 8 bits USB_WriteWord(0x0F00); // cursor ON USB_WriteWord(0x0100); // clear screen Sleep(2); l = strlen(av[1]); l1 = (l > 20 ? 20 : l); // Send text for (i = 0 ; i < l1 ; i++) USB_WriteChar(av[1][i]); if (l > 20) { // next line USB_WriteWord(0xC000); for ( ; i < l ; i++) USB_WriteChar(av[1][i]); } USB_Close(); }
int32_t HID_MainProcess(void) { STR_USBD_T sParam; USBD_Init(); sParam.UsbDeviceClass = USB_CLASS_HID; sParam.u32CtrlMaxPacketSize = HID_MAX_PACKET_SIZE_CTRL; sParam.u32EndpointCount = 1; sParam.EP[0].u32EpNum = INT_IN_EP_NUM; sParam.EP[0].u32MaxPacketSize = HID_MAX_PACKET_SIZE_INT_IN; sParam.EP[0].IsDirIN = TRUE; sParam.EP[0].IsIsoTransfer = FALSE; USB_Open(&sParam); while(1) { } }
int main() { unsigned char c = 0x55; USB_Open(); //USB_WriteWord(0x0100); //USB_WriteChar('D'); //USB_WriteChar(c); //printf("W: 0x%02x\r\n", c); while(1) { if(kbhit()) break; c = USB_Read(); printf("R: 0x%02x\r\n", c); Sleep(200); } USB_Close(); }
ProjectorLC4500::ProjectorLC4500(unsigned int): nPatterns(0), isRunning(false){ std::cout << "ProjectorLC4500: preparing LightCrafter 4500 for duty... " << std::endl; // Initialize usb connection if(USB_Init()){ showError("Could not init USB!"); } if(USB_Open()){ showError("Could not connect!"); } if(!USB_IsConnected()){ showError("Could not connect."); } // unsigned char HWStatus, SysStatus, MainStatus; // while(LCR_GetStatus(&HWStatus, &SysStatus, &MainStatus) != 0){ // std::cout << "."; // continue; // } // Make sure LC is not in standby const bool standby = false; if(!LCR_SetPowerMode(standby)){ showError("Error Setting Power Mode"); } // Set LED selection const bool SeqCtrl = true; // manual (false) or automatic (true) const bool LEDRed = true; const bool LEDGreen = false; const bool LEDBlue = false; LCR_SetLedEnables(SeqCtrl, LEDRed, LEDGreen, LEDBlue); // Set LED currents const unsigned char RedCurrent = 90; const unsigned char GreenCurrent = 0; const unsigned char BlueCurrent = 0; LCR_SetLedCurrents(255-RedCurrent, 255-GreenCurrent, 255-BlueCurrent); unsigned char Red; unsigned char Green; unsigned char Blue; LCR_GetLedCurrents(&Red, &Green, &Blue); // Set to pattern sequence mode const bool patternSequenceMode = true; if(!LCR_SetMode(patternSequenceMode)){ showError("Error Setting Mode"); } // Clear pattern LUT LCR_ClearPatLut(); const int bitDepth = 8; const int ledSelect = 1; bool invertPattern = false; //int LCR_AddToPatLut(int TrigType, int PatNum,int BitDepth,int LEDSelect,bool InvertPat, bool InsertBlack,bool BufSwap, bool trigOutPrev) // 2 x 8.333 exposures of the 2x3 psp pattern LCR_AddToPatLut(0, 1, bitDepth, ledSelect, invertPattern, false, true, false); LCR_AddToPatLut(3, 1, bitDepth, ledSelect, invertPattern, true, false, true); LCR_AddToPatLut(0, 0, bitDepth, ledSelect, invertPattern, false, false, false); LCR_AddToPatLut(3, 0, bitDepth, ledSelect, invertPattern, true, false, true); LCR_AddToPatLut(0, 2, bitDepth, ledSelect, invertPattern, false, false, false); LCR_AddToPatLut(3, 2, bitDepth, ledSelect, invertPattern, true, false, true); LCR_AddToPatLut(0, 1, bitDepth, ledSelect, invertPattern, false, true, false); LCR_AddToPatLut(3, 1, bitDepth, ledSelect, invertPattern, true, false, true); LCR_AddToPatLut(0, 0, bitDepth, ledSelect, invertPattern, false, false, false); LCR_AddToPatLut(3, 0, bitDepth, ledSelect, invertPattern, true, false, true); LCR_AddToPatLut(0, 2, bitDepth, ledSelect, invertPattern, false, false, false); LCR_AddToPatLut(3, 2, bitDepth, ledSelect, invertPattern, true, false, true); // Set to internal flash source const bool patternDisplayMode = false; LCR_SetPatternDisplayMode(patternDisplayMode); LCR_SetPatternConfig(12, true, 12, 2); LCR_SetExpsosure_FramePeriod(16666, 16666); // Internal trigger const bool patternTriggerMode = true; LCR_SetPatternTriggerMode(patternTriggerMode); if(LCR_SendPatLut() < 0) showError("Error Sending Pattern LUT"); unsigned char splashLutEntries[] = {3, 4}; unsigned int numEntries = 2; LCR_SendSplashLut(splashLutEntries, numEntries); unsigned int status; if(LCR_ValidatePatLutData(&status) < 0) showError("Error validating LUT data"); // Set trigger signal configuration LCR_SetTrigOutConfig(1, true, 0, 0); }
/** * Initialize the interface to the card reader ctn attached * to the port number specified in pn * * @param ctn Card terminal number * @param pn Port number * @return Status code \ref OK, \ref ERR_INVALID, \ref ERR_CT, \ref ERR_TRANS, \ref ERR_MEMORY, \ref ERR_HOST, \ref ERR_HTSI */ signed char CT_init(unsigned short ctn, unsigned short pn) { int rc, indx; scr_t *ctx; InterlockedIncrement(&mutex_refcnt); /* prevents mutex_destroy */ if (!mutex_initialized) { if (safe_mutex_initialize() != 0) { InterlockedDecrement(&mutex_refcnt); return ERR_MUTEX; } } if (mutex_lock(&mutex) != 0) { if (InterlockedDecrement(&mutex_refcnt) == 0) { safe_mutex_destroy(); } return ERR_MUTEX; } rc = LookupReader(ctn); if (rc < 0) { /* * Determine next free position in reader list */ for (indx = 0; indx < MAX_READER && readerTable[indx]; indx++) { ; } if (indx == MAX_READER) { mutex_unlock(&mutex); if (InterlockedDecrement(&mutex_refcnt) == 0) { safe_mutex_destroy(); } return ERR_MEMORY; } ctx = (scr_t *)calloc(1, sizeof(scr_t)); if (!ctx) { mutex_unlock(&mutex); if (InterlockedDecrement(&mutex_refcnt) == 0) { safe_mutex_destroy(); } return ERR_MEMORY; } /* * No active reader yet - try to find one */ rc = USB_Open(pn, &ctx->device); if (rc != USB_OK) { free(ctx); if (rc == ERR_NO_READER) { rc = ERR_CT; } else { rc = ERR_HOST; /* USB transmission error */ } mutex_unlock(&mutex); if (InterlockedDecrement(&mutex_refcnt) == 0) { safe_mutex_destroy(); } return rc; } ctx->ctn = ctn; ctx->pn = pn; if (mutex_init(&ctx->mutex) != 0) { free(ctx); return ERR_MUTEX; } readerTable[indx] = ctx; } mutex_unlock(&mutex); return OK; }
/** * Initialize the interface to the card reader ctn attached * to the port number specified in pn * * @param ctn Card terminal number * @param pn Port number * @return Status code \ref OK, \ref ERR_INVALID, \ref ERR_CT, \ref ERR_TRANS, \ref ERR_MEMORY, \ref ERR_HOST, \ref ERR_HTSI */ signed char CT_init(unsigned short ctn, unsigned short pn) { int rc, indx; scr_t *ctx; if (!mutexInitialized) { if (mutex_init(&globalmutex) != 0) { return ERR_CT; }; } mutexInitialized++; if (mutex_lock(&globalmutex) != 0) { return ERR_CT; } rc = LookupReader(ctn); if (rc < 0) { /* * Determine next free position in reader list */ for (indx = 0; (indx < MAX_READER) && readerTable[indx]; indx++) { ; } if (indx == MAX_READER) { mutexInitialized--; mutex_unlock(&globalmutex); if (!mutexInitialized) { mutex_destroy(&globalmutex); } return ERR_MEMORY; } ctx = (scr_t *)calloc(1, sizeof(scr_t)); if (!ctx) { mutexInitialized--; mutex_unlock(&globalmutex); if (!mutexInitialized) { mutex_destroy(&globalmutex); } return ERR_MEMORY; } /* * No active reader yet - try to find one */ rc = USB_Open(pn, &(ctx->device)); if (rc != USB_OK) { free(ctx); if (rc == ERR_NO_READER) { mutexInitialized--; mutex_unlock(&globalmutex); if (!mutexInitialized) { mutex_destroy(&globalmutex); } return ERR_CT; } else { mutexInitialized--; mutex_unlock(&globalmutex); if (!mutexInitialized) { mutex_destroy(&globalmutex); } return ERR_HOST; /* USB transmission error */ } } ctx->ctn = ctn; ctx->pn = pn; if (mutex_init(&ctx->mutex) != 0) { free(ctx); return ERR_CT; } readerTable[indx] = ctx; } if (mutex_unlock(&globalmutex) != 0) { return ERR_CT; } return OK; }
/** * @brief VCOM_MainProcess, VCOM main process. * @param None. * @retval None. */ void VCOM_MainProcess(void) { int32_t i, i32Len; STR_USBD_T sParam; /* Enable UART Interrupt */ UART_EnableInt(UART0, DRVUART_RDAINT); /* Initial USB */ USBD_Init(); sParam.UsbDeviceClass = USB_CLASS_CDC; sParam.u32CtrlMaxPacketSize = MAX_PACKET_SIZE_CTRL; sParam.u32EndpointCount = 3; sParam.EP[0].u32EpNum = BULK_IN_EP_NUM; sParam.EP[0].u32MaxPacketSize = MAX_PACKET_SIZE_BULK; sParam.EP[0].IsDirIN = TRUE; sParam.EP[0].IsIsoTransfer = FALSE; sParam.EP[1].u32EpNum = BULK_OUT_EP_NUM; sParam.EP[1].u32MaxPacketSize = MAX_PACKET_SIZE_BULK; sParam.EP[1].IsDirIN = FALSE; sParam.EP[1].IsIsoTransfer = FALSE; sParam.EP[2].u32EpNum = INT_IN_EP_NUM; sParam.EP[2].u32MaxPacketSize = MAX_PACKET_SIZE_INT; sParam.EP[2].IsDirIN = TRUE; sParam.EP[2].IsIsoTransfer = FALSE; USB_Open(&sParam); memset((void *)&gVcomInfo, 0, sizeof(STR_USBD_VCOM_T)); while(1) { /* Check if any data to send to USB & USB is ready to send them out */ if(comRbytes && (gVcomInfo.TxSize == 0)) { i32Len = comRbytes; if(i32Len > MAX_PACKET_SIZE_BULK) i32Len = MAX_PACKET_SIZE_BULK; for(i=0;i<i32Len;i++) { gRxBuf[i] = comRbuf[comRhead++]; if(comRhead >= RXBUFSIZE) comRhead = 0; } NVIC_DisableIRQ(UART0_IRQn); comRbytes -= i32Len; NVIC_EnableIRQ(UART0_IRQn); gVcomInfo.TxSize = i32Len; my_memcpy((uint8_t *)((uint32_t)USBD_SRAM_BASE + (uint32_t)USBD->BUFSEG2), (void *)gRxBuf, i32Len); USBD->MXPLD2 = i32Len; } /* Process the Bulk out data when bulk out data is ready. */ if(gVcomInfo.BulkOutReady && (gVcomInfo.RxSize <= TXBUFSIZE - comTbytes)) { for(i=0;i<gVcomInfo.RxSize;i++) { comTbuf[comTtail++] = *(gVcomInfo.RxBuf+i); if(comTtail >= TXBUFSIZE) comTtail = 0; } NVIC_DisableIRQ(UART0_IRQn); comTbytes += gVcomInfo.RxSize; NVIC_EnableIRQ(UART0_IRQn); gVcomInfo.RxSize = 0; gVcomInfo.BulkOutReady = 0; /* Clear bulk out ready flag */ /* Ready to get next BULK out */ USBD->MXPLD3 = MAX_PACKET_SIZE_BULK; } /* Process the software Tx FIFO */ if(comTbytes) { /* Check if Tx is working */ if (!(UART0->IER & UART_IER_THRE_IE)) { /* Send one bytes out */ UART0->THR = comTbuf[comThead++]; if(comThead >= TXBUFSIZE) comThead = 0; NVIC_DisableIRQ(UART0_IRQn); comTbytes--; NVIC_EnableIRQ(UART0_IRQn); /* Enable Tx Empty Interrupt. (Trigger first one) */ UART0->IER |= UART_IER_THRE_IE; } } } }