给C语言函数添加注释并将英文注释翻译成中文 Private function prototypes -----------------------------------------------void SystemClock_Configvoid;static void MX_GPIO_Initvoid;static void MX_DMA_Initvoid;static void MX_ADC
/* Private function prototypes -----------------------------------------------*/ // 私有函数原型声明
void SystemClock_Config(void); // 系统时钟配置函数
static void MX_GPIO_Init(void); // GPIO初始化函数
static void MX_DMA_Init(void); // DMA初始化函数
static void MX_ADC1_Init(void); // ADC1初始化函数
/* USER CODE BEGIN PFP / / Private function prototypes -----------------------------------------------*/ // 用户定义的函数原型声明
/* USER CODE END PFP */
uint8_t USB_RX_Buffer[8] = {0,0,0,0,0,0,0,0}; uint8_t USB_TX_Buffer[8] = {0,0,0,0,0,0,0,0};
extern uint8_t USBD_CUSTOM_HID_SendReport (USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len);
/* USER CODE END 0 */
int sendtag = 1;
int main(void) {
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init();
/* Configure the system clock */ SystemClock_Config();
/* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_USB_DEVICE_Init();
/* USER CODE BEGIN 2 */
HAL_DMA_Init(&hdma_adc1);
HAL_ADC_Start_DMA( &hadc1, ADC_buffer, 6 );
HAL_ADC_Start_IT( &hadc1 );
// Declare port and pins
declareButtonPins(); // 声明按键端口和引脚
declareAnalogPins(); // 声明模拟端口和引脚
declareEncoderPins(); // 声明编码器端口和引脚
/* USER CODE END 2 */
/* Infinite loop / / USER CODE BEGIN WHILE */ while (1) {
// Read and update buttons, dpad and adc handbrake
readButtusons(); // 读取和更新按键、方向键和ADC手刹
// Potentiometers is used to triggers and sticks
// Read ADC values
readAdcValues(); // 读取ADC值
// Update values of sticks
updateSticks(); // 更新摇杆值
// Update values of triggres
// updateTriggers(); // 更新扳机值
sendtag = HAL_GPIO_ReadPin( GPIOA, GPIO_PIN_9 );
// Send commands to PC
//USBD_LL_Transmit( hUsbDevice_0, XINPUT_TX_ENDPOINT, TXData ,XINPUT_TX_SIZE);
if (sendtag == 1){
USBD_CUSTOM_HID_SendReport( hUsbDevice_0, TXData, XINPUT_TX_SIZE ); // 发送命令到PC
}
//HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); // Led to calculate speed transmission
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
} /* USER CODE END 3 */
原文地址: http://www.cveoy.top/t/topic/fe2E 著作权归作者所有。请勿转载和采集!