stm32_ota/HARDWARE/USB/usb.c

71 lines
2.8 KiB
C
Raw Permalink Normal View History

2023-12-15 06:28:06 +00:00
#include "usb.h"
#include <string.h>
#include <stdbool.h>
#include "sysport.h"
#include "usart.h"
#include "io.h"
/********************************************************************************
* @file usb.c
* @author <EFBFBD>̳ϿƼ<EFBFBD> Mr.Wang
* @version V1.0.0
* @date 11-Dec-2018
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>תUSB<EFBFBD>ӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
******************************************************************************
* @ʹ<EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD>Camera_Init()<EFBFBD><EFBFBD>USB_COM<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD>ͨ<EFBFBD><EFBFBD>USBSendData()<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡsUsbQueue֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*******************************************************************************/
/*****************************************
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ʹ<EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
****************************************/
/*****************************************
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD>ⲿʹ<EFBFBD>õij<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
****************************************/
FrameQueue_s sUsbQueue ; //USB <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>ݻ<EFBFBD><DDBB>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>ֻ<EFBFBD><D6BB>Ҫ<EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>USB<53>󣬴<EFBFBD><F3A3ACB4><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD>
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void UsbInit(uint32_t baudrate)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>Usb<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sUsbQueue
* 5<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>Usb<EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***************************************************************************************************/
void UsbInit(uint32_t baudrate)
{
InitQueueMem(&sUsbQueue) ; //<2F><>ʼ<EFBFBD><CABC>RS485<38><35><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sUsbQueue
UARTx_Init(COM5, baudrate, USART_Mode_Rx | USART_Mode_Tx, INT_RANK_1) ;//<2F><>ʼ<EFBFBD><CABC>RS485ӳ<35><D3B3><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>USB_COM<4F><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>շ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>ΪINT_RANK_1
Uart_RegHookCallback(COM5, UsbRecFrameCallback) ; //ע<><D7A2>RS485<38><35><EFBFBD><EFBFBD>֡<EFBFBD>жϻص<CFBB><D8B5><EFBFBD><EFBFBD><EFBFBD>
}
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> void Rs232RecFrameCallback(char *recvBuf, uint16_t recvLen)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>USB<EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡ʱ<EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>sUsbQueue<EFBFBD><EFBFBD>
* Ӧ<EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>ν<EFBFBD><EFBFBD>գ<EFBFBD>ֻ<EFBFBD><EFBFBD>Ҫ<EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><EFBFBD>Usb<EFBFBD>󣬴<EFBFBD><EFBFBD><EFBFBD>sUsbQueue֡<EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD><EFBFBD>ɡ<EFBFBD>
**************************************************************************************************/
void UsbRecFrameCallback(char *recvBuf, uint16_t recvLen)
{
if( RW_OK != InsertQueueMemData(&sUsbQueue, recvBuf, recvLen) )
{
ErrorLogPrintf("sUsbQueue<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>") ;
}
}
/****************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD>void UsbSendData(char* sendData, uint16_t dataLen)
* <EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD>ͨ<EFBFBD><EFBFBD>USB_COM<EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dataLen<EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sendData
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param *sendData <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
* @param dataLen <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD>
****************************************************************************/
void UsbSendData(char* sendData, uint16_t dataLen)
{
UARTx_SendData(USB_COM, sendData, dataLen) ;
}