⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 STM32 USB HID键盘
💻 C
字号:
/******************** (C) COPYRIGHT 2009 STMicroelectronics ********************
* File Name          : main.c
* Author             : MCD Application Team
* Version            : V3.0.1
* Date               : 04/27/2009
* Description        : Joystick Mouse demo main file
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "STM32Lib\\stm32f10x.h"
#include "STM32Lib\\USBLib\\usb_lib.h"
#include "hw_config.h"
#include "usb_pwr.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define OB00 	GPIO_ResetBits(GPIOB, GPIO_Pin_0);
#define OB01		GPIO_SetBits(GPIOB, GPIO_Pin_0);  

//输入宏定义
#define IB4	GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_4)
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
void Delay(__IO uint32_t nCount);
void EP1_OUT_Callback(void)
{
	u8 DataLen; //保存接收数据的长度
	u8 DataBuffer[64]; //保存接收数据的缓冲区

	DataLen = GetEPRxCount(ENDP1); //获取收到的长度
	PMAToUserBufferCopy(DataBuffer, ENDP1_RXADDR, DataLen); //复制数据
	SetEPRxValid(ENDP1); //设置端点有效,以接收下一次数据

	if(DataLen==1) //收到一字节的输出报告
	{
  		//D0位表示数字键盘灯,D1位表示大写字母锁定灯
  		if(DataBuffer[0]&0x01)  //数字键盘灯亮
  		{
   			GPIOC->BSRR=(1<<6); //亮LED3
  		}
  		else
  		{
   			GPIOC->BRR=(1<<6); //灭LED3
  		}
  		if(DataBuffer[0]&0x02) //大写字母锁定键
  		{
   			GPIOC->BSRR=(1<<7); //亮LED2
  		}
  		else
  		{
   			GPIOC->BRR=(1<<7); //灭LED2
  		}
	}
}
/*****************   延时x毫秒函数 ***********/
void DelayXms(unsigned int x)               
{
 unsigned int i,j;
 for(i=0;i<x;i++)
 for(j=0;j<5150;j++);
}
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name  : main.
* Description    : main routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
int main(void)
{
  	Set_System();
  	USB_Interrupts_Config();
  	USB_Init();
  	while (1)
  	{
    		if ( bDeviceState == CONFIGURED)
    		{
    			if(!IB4)
    			{
      				Joystick_Send(1);
				DelayXms(2);
				Joystick_Send(0);
				DelayXms(1);
    			}
    		}
		Delay(10000);
  	}
}
/*******************************************************************************
* Function Name  : Delay
* Description    : Inserts a delay time.
* Input          : nCount: specifies the delay time length.
* Output         : None
* Return         : None
*******************************************************************************/
void Delay(__IO uint32_t nCount)
{
  for (; nCount != 0;nCount--);
}

#ifdef  USE_FULL_ASSERT
/*******************************************************************************
* Function Name  : assert_failed																															   
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {}
}
#endif

/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -