//----------------------------------------------------------------------------- /// Post-processes a command given the case identified during the /// pre-processing step. /// Depending on the case, one of the following actions can be done: /// - Bulk IN endpoint is stalled /// - Bulk OUT endpoint is stalled /// - CSW status set to phase error /// \param pMsdDriver Pointer to a MSDDriver instance /// \return If the device is halted //----------------------------------------------------------------------------- static unsigned char MSDD_PostProcessCommand(MSDDriver *pMsdDriver) { MSDCommandState *commandState = &(pMsdDriver->commandState); MSCsw *csw = &(commandState->csw); unsigned char haltStatus = 0; // STALL Bulk IN endpoint ? if ((commandState->postprocess & MSDD_CASE_STALL_IN) != 0) { TRACE_INFO_WP("StallIn "); MSDD_Halt(MSDD_CASE_STALL_IN); haltStatus = 1; } // STALL Bulk OUT endpoint ? if ((commandState->postprocess & MSDD_CASE_STALL_OUT) != 0) { TRACE_INFO_WP("StallOut "); MSDD_Halt(MSDD_CASE_STALL_OUT); haltStatus = 1; } // Set CSW status code to phase error ? if ((commandState->postprocess & MSDD_CASE_PHASE_ERROR) != 0) { TRACE_INFO_WP("PhaseErr "); csw->bCSWStatus = MSD_CSW_PHASE_ERROR; } return haltStatus; }
static uint8_t _VerifyData( uint32_t AddrBegin, uint32_t AddrEnd, uint32_t *TestBuff , uint8_t secure) { static uint8_t TestPassed = 0; uint32_t i, j, Fault = 0; uint8_t *pBuffRx, *pBuffTx; pBuffTx = (uint8_t *)TestBuff; TRACE_INFO_WP("Verifying data from 0x%x to 0x%x \n\r", (unsigned int)AddrBegin, (unsigned int)AddrEnd); if (secure) { TRACE_INFO(" Reading data with scramble ON \n\r"); } else { TRACE_INFO(" Reading data with scramble OFF \n\r"); } for (i = AddrBegin; i < AddrEnd; ) { if (PeripheralInit == 2) { S25FL1D_Read(Buffer, BUFFER_SIZE, i); pBuffRx = (uint8_t *)Buffer; pBuffRx = &pBuffRx[6]; } else if (PeripheralInit == 1) { S25FL1D_ReadQuadIO(Buffer, BUFFER_SIZE, i, 0, secure); pBuffRx = (uint8_t *)Buffer; } for (j = 0; j < BUFFER_SIZE; j++) { if (pBuffRx[j] != pBuffTx[j]) { TestPassed = 1; if (Fault == 0) printf("\n\rData does not match @ 0x%x ", (unsigned int)i); Fault++; } else { if (Fault > 1) printf("upto 0x%x \r\n", (unsigned int)i); Fault = 0; } } i += BUFFER_SIZE; } if (Fault > 1) { TRACE_INFO_WP("upto 0x%x \r\n", (unsigned int)i); Fault = 0; } if (TestPassed) TRACE_ERROR("Data Does not match \n\r"); return TestPassed; }
//------------------------------------------------------------------------------ /// Sets the current value of a particular Feature control of a channel. /// \param entity Entity number. /// \param channel Channel number. /// \param control Control selector value (see TODO). /// \param length Length of the data containing the new value. //------------------------------------------------------------------------------ static void AUDDSpeakerDriver_SetFeatureCurrentValue(unsigned char entity, unsigned char channel, unsigned char control, unsigned short length) { TRACE_INFO_WP("sFeature "); TRACE_DEBUG("\b(E%d, CS%d, CN%d, L%d) ", entity, control, channel, length); // Check the the requested control is supported // Control/channel combination not supported if ((control == AUDFeatureUnitRequest_MUTE) && (channel < (AUDDSpeakerDriver_NUMCHANNELS+1)) && (length == 1)) { unsigned int argument = channel; // Avoids compiler warning USBD_Read(0, // Endpoint #0 &muted, sizeof(muted), (TransferCallback) AUDDSpeakerDriver_MuteReceived, (void *) argument); } // Control/channel combination not supported else { USBD_Stall(0); } }
//------------------------------------------------------------------------------ /// Handles CDC-specific SETUP requests. Should be called from a /// re-implementation of USBDCallbacks_RequestReceived() method. /// \param Pointer to a USBGenericRequest instance. //------------------------------------------------------------------------------ void CDCDSerialDriver_RequestHandler(const USBGenericRequest *request) { TRACE_INFO_WP("NewReq "); // Handle the request switch (USBGenericRequest_GetRequest(request)) { case CDCGenericRequest_SETLINECODING: CDCDSerialDriver_SetLineCoding(); break; case CDCGenericRequest_GETLINECODING: CDCDSerialDriver_GetLineCoding(); break; case CDCGenericRequest_SETCONTROLLINESTATE: CDCDSerialDriver_SetControlLineState( CDCSetControlLineStateRequest_ActivateCarrier(request), CDCSetControlLineStateRequest_IsDtePresent(request)); break; default: USBDDriver_RequestHandler(&(cdcdSerialDriver.usbdDriver), request); break; } }
/** * Sets the active setting of the given interface if the configuration supports * it; otherwise, the control pipe is STALLed. If the setting of an interface * changes. * \parma pDriver Pointer to a USBDDriver instance. * \parma infnum Interface number. * \parma setting New active setting for the interface. */ static void SetInterface( USBDDriver *pDriver, uint8_t infnum, uint8_t setting) { /* Make sure alternate settings are supported */ TRACE_INFO_WP( "Setting %d ", setting); if (!pDriver->pInterfaces) { USBD_Stall(0); } else { /* Change the current setting of the interface and trigger the callback */ /* if necessary */ if (pDriver->pInterfaces[infnum] != setting) { pDriver->pInterfaces[infnum] = setting; if (NULL != USBDDriverCallbacks_InterfaceSettingChanged) USBDDriverCallbacks_InterfaceSettingChanged(infnum, setting); } /* Acknowledge the request */ USBD_Write(0, 0, 0, 0, 0); } }
/** * \brief Dump all register * \param pTwid TWI interface */ void ov_DumpRegisters16(Twid *pTwid) { uint32_t i; uint8_t value; TRACE_INFO_WP("Dump all camera register\n\r"); for(i = 3000; i <= 0x305C; i++) { value = 0; ov_read_reg16(pTwid, i, &value); TRACE_INFO_WP("[0x%02x]=0x%02x ", i, value); if( ((i+1)%5) == 0 ) { TRACE_INFO_WP("\n\r"); } } TRACE_INFO_WP("\n\r"); }
/** * Handles audio-specific USB requests sent by the host, and forwards * standard ones to the USB device driver. * \param request Pointer to a USBGenericRequest instance. */ void AUDDSpeakerDriver_RequestHandler(const USBGenericRequest *request) { AUDDSpeakerDriver *pAudd = &auddSpeakerDriver; AUDDSpeakerPhone *pAudf = &pAudd->fun; USBDDriver *pUsbd = pAudf->pUsbd; TRACE_INFO_WP("NewReq "); /* Handle Audio Class requests */ if (AUDDSpeakerPhone_RequestHandler(pAudf, request) == USBRC_SUCCESS) { return; } /* Handle STD requests */ if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) { USBDDriver_RequestHandler(pUsbd, request); } /* Unsupported request */ else { TRACE_WARNING( "AUDDSpeakerDriver_RequestHandler: Unsupported request (%d,%x)\n\r", USBGenericRequest_GetType(request), USBGenericRequest_GetRequest(request)); USBD_Stall(0); } }
/** * Handles CDC-specific SETUP requests. Should be called from a * re-implementation of USBDCallbacks_RequestReceived() method. * \param request Pointer to a USBGenericRequest instance. */ uint32_t CDCDSerial_RequestHandler(const USBGenericRequest *request) { CDCDSerialPort * pCdcd = &cdcdSerial; TRACE_INFO_WP("Cdcf "); return CDCDSerialPort_RequestHandler(pCdcd, request); }
/** * Handles composite-specific USB requests sent by the host, and forwards * standard ones to the USB device driver. * \param request Pointer to a USBGenericRequest instance. */ void DUALCDCDDriver_RequestHandler(const USBGenericRequest *request) { CDCDSerialPort *pCdcd = 0; USBDDriver *pUsbd = 0; uint32_t rc, i; TRACE_INFO_WP("NewReq "); for (i = 0; i < NUM_PORTS; i ++) { pCdcd = &dualcdcdDriver.cdcdSerialPort[i]; rc = CDCDSerialPort_RequestHandler(pCdcd, request); if (rc == USBRC_SUCCESS) break; } /* Not handled by CDC Serial */ if (rc != USBRC_SUCCESS) { if (USBGenericRequest_GetType(request) == USBGenericRequest_STANDARD) { pUsbd = pCdcd->pUsbd; USBDDriver_RequestHandler(pUsbd, request); } else { TRACE_WARNING( "DUALCDCDDriver_RequestHandler: Unsupported request (%d,%d)\n\r", USBGenericRequest_GetType(request), USBGenericRequest_GetRequest(request)); USBD_Stall(0); } } }
void ui_uhi_hid_mouse_move(int8_t x, int8_t y, int8_t scroll) { ui_x = x; ui_y = y; TRACE_INFO_WP("\r Mouse at X:%d, Y:%d ", ui_x, ui_y); ui_scroll = scroll; }
/** * Sets the device address to the given value. * \param address New device address. */ void USBD_SetAddress(uint8_t address) { TRACE_INFO_WP("SetAddr(%d) ", address); USBD_HAL_SetAddress(address); if (address == 0) deviceState = USBD_STATE_DEFAULT; else deviceState = USBD_STATE_ADDRESS; }
//----------------------------------------------------------------------------- /// Resets the state of the MSD driver //----------------------------------------------------------------------------- static void MSDDriver_Reset(void) { TRACE_INFO_WP("MSDReset "); msdDriver.state = MSDD_STATE_READ_CBW; msdDriver.waitResetRecovery = 0; msdDriver.commandState.state = 0; }
/** * Handler for incoming SETUP requests on default Control endpoint 0. * * Standard requests are forwarded to the USBDDriver_RequestHandler * method. * \param pMsdDriver Pointer to MSDDriver instance. * \param request Pointer to a USBGenericRequest instance */ void MSDDriver_RequestHandler( const USBGenericRequest *request) { USBDDriver *pUsbd = USBD_GetDriver(); TRACE_INFO_WP("NewReq "); if (MSDFunction_RequestHandler(request)) USBDDriver_RequestHandler(pUsbd, request); }
/** * Sends the current line coding information to the host through Control * endpoint 0. * \param pCdcd Pointer to CDCDSerialPort instance. */ static void _GetLineCoding(CDCDSerialPort * pCdcd) { TRACE_INFO_WP("gLineCoding "); USBD_Write(0, (void *) &(pCdcd->lineCoding), sizeof(CDCLineCoding), 0, 0); }
//------------------------------------------------------------------------------ /// Sends the current line coding information to the host through Control /// endpoint 0. //------------------------------------------------------------------------------ static void CDCDSerialDriver_GetLineCoding(void) { TRACE_INFO_WP("gLineCoding "); USBD_Write(0, (void *) &(cdcdSerialDriver.lineCoding), sizeof(CDCLineCoding), 0, 0); }
//------------------------------------------------------------------------------ /// Receives new line coding information from the USB host. //------------------------------------------------------------------------------ static void CDCDSerialDriver_SetLineCoding(void) { TRACE_INFO_WP("sLineCoding "); USBD_Read(0, (void *) &(cdcdSerialDriver.lineCoding), sizeof(CDCLineCoding), (TransferCallback) CDCDSerialDriver_SetLineCodingCallback, 0); }
/** * Resets the state of the MSD driver */ static void MSDFunction_Reset(void) { MSDDriver *pMsdd = &msdFunction; TRACE_INFO_WP("MSDReset "); pMsdd->state = MSDD_STATE_READ_CBW; pMsdd->waitResetRecovery = 0; pMsdd->commandState.state = 0; }
/** * Handles HID-specific SETUP request sent by the host. * \param request Pointer to a USBGenericRequest instance. * \return USBRC_SUCCESS if request is handled. */ uint32_t HIDDKeyboard_RequestHandler(const USBGenericRequest *request) { HIDDKeyboard *pKbd = &hiddKeyboard; HIDDFunction *pHidd = &pKbd->hidDrv; TRACE_INFO_WP("Kbd "); /* Process HID requests */ return HIDDFunction_RequestHandler(pHidd, request); }
/** * Receives new line coding information from the USB host. * \param pCdcd Pointer to CDCDSerialPort instance. */ static void _SetLineCoding(CDCDSerialPort * pCdcd) { TRACE_INFO_WP("sLineCoding "); USBD_Read(0, (void *) & (lineCoding), sizeof(CDCLineCoding), (TransferCallback)_SetLineCodingCallback, (void*)pCdcd); }
//------------------------------------------------------------------------------ /// Changes the state of the serial driver according to the information /// sent by the host via a SetControlLineState request, and acknowledges /// the request with a zero-length packet. //------------------------------------------------------------------------------ static void CDCDSerialDriver_SetControlLineState(unsigned char activateCarrier, unsigned char isDTEPresent) { TRACE_INFO_WP( "sControlLineState(%d, %d) ", activateCarrier, isDTEPresent); cdcdSerialDriver.isCarrierActivated = activateCarrier; USBD_Write(0, 0, 0, 0, 0); }
//----------------------------------------------------------------------------- /// Sends the current line coding information to the host through Control /// endpoint 0. /// \param request Pointer to a USBGenericRequest instance. //----------------------------------------------------------------------------- static void CDCD_GetLineCoding(const USBGenericRequest *request) { unsigned char serial; serial = CDCD_GetSerialPort(request); TRACE_INFO_WP("gLineCoding_%d ", serial); USBD_Write(0, (void *) &(cdcFunDriver.pCdcPorts[serial].lineCoding), sizeof(CDCLineCoding), 0, 0); }
//----------------------------------------------------------------------------- /// Receives new line coding information from the USB host. /// \param request Pointer to a USBGenericRequest instance. //----------------------------------------------------------------------------- static void CDCD_SetLineCoding(const USBGenericRequest *request) { unsigned char serial; serial = CDCD_GetSerialPort(request); TRACE_INFO_WP("sLineCoding_%d ", serial); USBD_Read(0, (void *) &(cdcFunDriver.pCdcPorts[serial].lineCoding), sizeof(CDCLineCoding), (TransferCallback) CDCD_SetLineCodingCallback, 0); }
/** * Initializes the USB driver. */ void USBD_Init(void) { TRACE_INFO_WP("USBD_Init\n\r"); /* HW Layer Initialize */ USBD_HAL_Init(); /* Device is in the Attached state */ deviceState = USBD_STATE_SUSPENDED; previousDeviceState = USBD_STATE_POWERED; /* Upper Layer Initialize */ USBDCallbacks_Initialized(); }
/** * Handles CDCMSD-specific USB requests sent by the host, and forwards * standard ones to the USB device driver. * \param request Pointer to a USBGenericRequest instance. */ void CDCMSDDriver_RequestHandler(const USBGenericRequest *request) { USBDDriver *pUsbd = USBD_GetDriver(); TRACE_INFO_WP("NewReq "); if (CDCDSerial_RequestHandler(request) == USBRC_SUCCESS) return; if (MSDFunction_RequestHandler(request) == USBRC_SUCCESS) return; USBDDriver_RequestHandler(pUsbd, request); }
/** * Handles composite-specific USB requests sent by the host, and forwards * standard ones to the USB device driver. * \param request Pointer to a USBGenericRequest instance. */ void HIDAUDDDriver_RequestHandler(const USBGenericRequest *request) { USBDDriver *pUsbd = USBD_GetDriver(); TRACE_INFO_WP("NewReq "); if (HIDDKeyboard_RequestHandler(request) == USBRC_SUCCESS) return; if (AUDDFunction_RequestHandler(request) == USBRC_SUCCESS) return; USBDDriver_RequestHandler(pUsbd, request); }
//------------------------------------------------------------------------------ //! \brief Performs a TEST UNIT READY COMMAND command. //! \param lun Pointer to the LUN affected by the command //! \return Operation result code (SUCCESS, ERROR, INCOMPLETE or PARAMETER) //! \see MSDLun //------------------------------------------------------------------------------ static unsigned char SBC_TestUnitReady(MSDLun *lun) { unsigned char result = MSDD_STATUS_ERROR; // Check current media state switch(lun->media->state) { //------------------- case MED_STATE_READY: //------------------- // Nothing to do TRACE_INFO_WP("Rdy "); result = MSDD_STATUS_SUCCESS; break; //------------------ case MED_STATE_BUSY: //------------------ TRACE_INFO_WP("Bsy "); SBC_UpdateSenseData(&(lun->requestSenseData), SBC_SENSE_KEY_NOT_READY, 0, 0); break; //------ default: //------ TRACE_INFO_WP("? "); SBC_UpdateSenseData(&(lun->requestSenseData), SBC_SENSE_KEY_NOT_READY, SBC_ASC_MEDIUM_NOT_PRESENT, 0); break; } return result; }
/** * Sets the current device configuration. * \param cfgnum - Configuration number to set. */ void USBD_SetConfiguration(uint8_t cfgnum) { TRACE_INFO_WP("SetCfg(%d) ", cfgnum); USBD_HAL_SetConfiguration(cfgnum); if (cfgnum != 0) { deviceState = USBD_STATE_CONFIGURED; } else { deviceState = USBD_STATE_ADDRESS; /* Reset all endpoints */ USBD_HAL_ResetEPs(0xFFFFFFFF, USBD_STATUS_RESET, 0); } }
//------------------------------------------------------------------------------ //! \brief Reads data from a LUN, starting at the specified block address. //! \param pLUN Pointer to a MSDLun instance //! \param blockAddress First block address to read //! \param data Pointer to a data buffer in which to store the data //! \param length Number of blocks to read //! \param callback Optional callback to invoke when the read finishes //! \return Operation result code //------------------------------------------------------------------------------ unsigned char LUN_Read(MSDLun *lun, unsigned int blockAddress, void *data, unsigned int length, TransferCallback callback, void *argument) { unsigned int address; unsigned char status; // Check that the data is not too big if ((length * lun->blockSize) > (lun->size - lun->blockSize * blockAddress)) { TRACE_WARNING("LUN_Read: Data too big\n\r"); status = USBD_STATUS_ABORTED; } else { TRACE_INFO_WP("LUNRead(%u) ", blockAddress); // Compute read start address address = lun->media->baseAddress + lun->baseAddress + blockAddress * lun->blockSize; // Start write operation status = MED_Read(lun->media, address, data, length * lun->blockSize, (MediaCallback) callback, argument); // Check result code if (status == MED_STATUS_SUCCESS) { status = USBD_STATUS_SUCCESS; } else { TRACE_WARNING("LUN_Read: Cannot read media\n\r"); status = USBD_STATUS_ABORTED; } } return status; }
//----------------------------------------------------------------------------- /// Changes the state of the serial driver according to the information /// sent by the host via a SetControlLineState request, and acknowledges /// the request with a zero-length packet. /// \param request Pointer to a USBGenericRequest instance. /// \param activateCarrier The active carrier state to set. /// \param isDTEPresent The DTE status. //----------------------------------------------------------------------------- static void CDCD_SetControlLineState(const USBGenericRequest *request, unsigned char activateCarrier, unsigned char isDTEPresent) { unsigned char serial; serial = CDCD_GetSerialPort(request); TRACE_INFO_WP( "sControlLineState_%d(%d, %d) ", serial, activateCarrier, isDTEPresent); cdcFunDriver.pCdcPorts[serial].isCarrierActivated = activateCarrier; USBD_Write(0, 0, 0, 0, 0); }
/** * Handle the SET_CUR request. * \param pAudf Pointer to AUDDSpeakerPhone instance. * \param pReq Pointer to USBGenericRequest instance. */ static void AUDD_SetCUR( AUDDSpeakerPhone *pAudf, const USBGenericRequest* pReq) { uint8_t bIf = AUDGenericRequest_GetInterface(pReq); uint8_t bEntity = AUDGenericRequest_GetEntity(pReq); uint8_t bLength = USBGenericRequest_GetLength(pReq); uint8_t bCh = AUDFeatureUnitRequest_GetChannel(pReq); uint8_t bCtrl = AUDFeatureUnitRequest_GetControl(pReq); uint8_t bSet = 1; AUDDStream *pAuds = AUDD_GetCtlStream(pAudf, bIf, bEntity, bCh); TransferCallback fCallback; TRACE_INFO_WP("sCUR "); TRACE_DEBUG("\b(E%d, CtlS%d, Ch%d, L%d) ", bEntity, bCtrl, bCh, bLength); /* Set Mute to AC, 1 byte */ if (bCtrl == AUDFeatureUnitRequest_MUTE && bLength == 1 && pAuds) { fCallback = (TransferCallback) AUDD_MuteReceived; } else if (bCtrl == AUDFeatureUnitRequest_VOLUME && bLength == 2 && pAuds && pAuds->pwVolumes) { fCallback = (TransferCallback) AUDD_VolumeReceived; } else bSet = 0; if (bSet) { auddXfrData.pStream = pAuds; auddXfrData.bEntity = bEntity; auddXfrData.bCh = bCh; USBD_Read(0, &auddXfrData.usbBuffer, bLength, fCallback, (void *) &auddXfrData); } else { USBD_Stall(0); } }