Next, we need to analyze these files separately:
hw_config.c:
This file mainly configures some onboard and system related codes, such as USB system clock configuration, pull-up resistor pin and LED light configuration, and USB interrupt light. The main functions are as follows:
void Set_System(void); /*Set system clock, USB and LED pin configuration*/
void Set_USBClock(void); /*Set the USB clock frequency*/
void GPIO_AINConfig(void); /*Set GPIO analog input (empty function here)*/
void Enter_LowPowerMode(void); /*Enter low power mode (empty function here)*/
void Leave_LowPowerMode(void); /*Leave low power mode (empty function here)*/
void USB_Interrupts_Config(void); /*Set USB interrupt configuration*/
void USB_Cable_Config (FunctionalState NewState);/*USB connection disconnection selection, actually controls the pull-up resistor pin*/
/*void Joystick_Send(uint8_t Keys);*/ /*Joystick sends (not used)*/
/*uint8_t JoyState(void); */ /*Joystick status (not used)*/
void Get_SerialNum(void); /*Create the serial number of the string descriptor*/
usb_des.c:
This file mainly defines some USB descriptors: device descriptor, configuration descriptor set (including interface descriptor, HID descriptor, endpoint descriptor), HID report descriptor, language ID descriptor, manufacturer string descriptor, product string descriptor, product serial number string descriptor.
CustomHID_DeviceDescriptor[CUSTOMHID_SIZ_DEVICE_DESC];
CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC];
CustomHID_ReportDescriptor[CUSTOMHID_SIZ_REPORT_DESC];
CustomHID_StringLangID[CUSTOMHID_SIZ_STRING_LANGID];
CustomHID_StringVendor[CUSTOMHID_SIZ_STRING_VENDOR];
CustomHID_StringProduct[CUSTOMHID_SIZ_STRING_PRODUCT];
CustomHID_StringSerial[CUSTOMHID_SIZ_STRING_SERIAL];
usb_endp.c:
This file mainly defines several endpoint input and output callback functions. Here, endpoint 1 input and output callback and endpoint 2 input callback functions are specified, as follows:
void EP1_IN_Callback(void); /*Endpoint 1 input callback function*/
void EP1_OUT_Callback(void); /*Endpoint 1 output callback function*/
void EP2_IN_Callback(void); /*Endpoint 2 input callback function*/
usb_Istr.c:
This file mainly registers the callback function corresponding to each endpoint; the processing of the USB interrupt service program determines what kind of interrupt is by reading the STM32 ISTR interrupt status register and making corresponding arbitrary processing.
void (*pEpInt_IN[7])(void) = /*Endpoint input callback function registration*/
{
EP1_IN_Callback,
EP2_IN_Callback,
EP3_IN_Callback,
EP4_IN_Callback,
EP5_IN_Callback,
EP6_IN_Callback,
EP7_IN_Callback,
};
void (*pEpInt_OUT[7])(void) = /*Registration of endpoint output callback function*/
{
EP1_OUT_Callback,
EP2_OUT_Callback,
EP3_OUT_Callback,
EP4_OUT_Callback,
EP5_OUT_Callback,
EP6_OUT_Callback,
EP7_OUT_Callback,
};
void USB_Istr(void);/*ISTR event interrupt service routine*/
usb_propc:
This file mainly registers some previously defined column descriptors into the USB library, and registers some commonly used USB processing functions such as obtaining device descriptors and some standard request functions, as follows:
DEVICE_PROP Device_Property = /*Register some CustomHID functions*/
{
CustomHID_init, /*CustomHID initialization function*/
CustomHID_Reset, /*CustomHID reset function*/
CustomHID_Status_In, /*CustomHID status input function*/
CustomHID_Status_Out, /*CustomHID status output function*/
CustomHID_Data_Setup, /*CustomHID special class request function for processing data*/
CustomHID_NoData_Setup, /*CustomHID processing without data special class request function*/
CustomHID_Get_Interface_Setting, /*CustomHID gets the interface and backup interface settings to see if they are available */
CustomHID_GetDeviceDescriptor, /*CustomHID gets the device descriptor*/
CustomHID_GetConfigDescriptor, /*CustomHID gets the configuration descriptor*/
CustomHID_GetStringDescriptor, /*CustomHID gets string descriptor*/
0, /*Current library is not used*/
0x40 /*MAX PACKET SIZE*/ /*The maximum packet length is 64 bytes*/
};
/*Register USB standard request implementation function*/
USER_STANDARD_REQUESTS User_Standard_Requests =
{
CustomHID_GetConfiguration, /*Get configuration request*/
CustomHID_SetConfiguration, /*Set configuration request*/
CustomHID_GetInterface, /*Get interface request*/
CustomHID_SetInterface, /*Set interface request*/
CustomHID_GetStatus, /*Get status request*/
CustomHID_ClearFeature, /*Clear feature request*/
CustomHID_SetEndPointFeature, /*Set endpoint feature request*/
CustomHID_SetDeviceFeature, /*Set device feature request*/
CustomHID_SetDeviceAddress /*Set device address request*/
};
/*Register device descriptor information*/
ONE_DESCRIPTOR Device_Descriptor;
/*Register report descriptor information*/
ONE_DESCRIPTOR CustomHID_Report_Descriptor;
/*Register HID descriptor information*/
ONE_DESCRIPTOR CustomHID_Descriptor;
/*Register string descriptors, including language ID, manufacturer, product, and serial number descriptors*/
ONE_DESCRIPTOR String_Descriptor[4];
usb_pwr.c:
This file mainly contains some USB and power consumption functions, such as power on, power off, suspend, etc.
void Suspend(void); /*Suspend*/
void Resume_Init(void); /*Resume initialization*/
void Resume(RESUME_STATE eResumeSetVal);/*Resume to a certain state*/
RESULT PowerOn(void); /*Power on*/
RESULT PowerOff(void); /*power off*/
Previous article:STM32 study notes USB virtual serial port descriptor introduction
Next article:LPC54608 generates PDF files
Recommended ReadingLatest update time:2024-11-16 13:40
- Popular Resources
- Popular amplifiers
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
- usb_host_device_code
- Transplantation of real-time operating system RT-ThreadSmart on STM32MP1
- Design of switching power supply with adjustable output voltage based on STM32
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- You can use FIND to check which library a certain component is in in the PROTEL schematic. You can also check which library a certain package is in. Why is it not there?
- Can RS485 communicate stably using parallel wires (non-twisted pair)? 5m wire length, 9600bps
- TI Wired and Wireless Communications in Electric Vehicle Battery Management
- Do you know the audio and video expansion port and asynchronous serial port expansion of DSPs?
- [CH563L Review] Part 1 Based on the official uCos introductory Hello World
- Why is there a "red dot" on my forum icon?
- Is the signal mentioned in Nyquist sampling theorem limited to sine (cosine) signal form?
- Thank you for being there, thank you for being polite!
- How to locate the code and data of C program
- Color screen printing limit for color segment screen