main.cpp

来自「STM32 USB HID」· C++ 代码 · 共 93 行

CPP
93
字号
#include"main.hpp"
//-----------------------------------------------------------------------------
int main(void)
{
  unsigned int status=0;
	
	while(1)
	{
		switch(status)
		{
			case GOTO_WAIT:
				status=Wait();
			break;
			default:
				status=Reset();
			break;
		}
	}
}
//-----------------------------------------------------------------------------
unsigned int Reset(void)
{
	//sm32f10x hardware initialization
	{
		RCC_Configration();
		SCB_Configuration();
	
		USART1_Configuration();
	/*	PWM_Configuration();
		EXTI_Configuration();

		{
			RCC_APB2ENR_BITS[GPIOC_EN] =1;
			GPIOC_CRL=0x11111111;
		}

		{
			ADC_Configuration();
			DMA_Configuration();
		}*/
	}

	//USB.Open();
	return(GOTO_WAIT);
}
//-----------------------------------------------------------------------------
unsigned int Wait(void)
{
	if(usart1_command)
	{
		USART1_DR=usart1_command;
		usart1_command=0;
	}	
	return(GOTO_WAIT);
	

	if(usb0.Reserived_Data)
	{
		switch(usb0.EP1R.Rx_Buffer[0].BYTE[1])
		{
			case 0x02:
				PWM_Set_Period(usb0.EP1R.Rx_Buffer[1].WORD[0]);
				PWM_ON();
			break;
			case 0x03:
				PWM_OFF();
				DMA_STOP();
				DMA1_CNDTR1=4096;
				DMA_START();
				while(DMA1_CNDTR1);
			break;
			case 0x04:
				PWM_Set_Period(usb0.EP1R.Rx_Buffer[1].WORD[0]);
				PWM_ONE_PULS();
			break;
		}
		usb0.Reserived_Data=0;
	}
	return(GOTO_WAIT);
}
//-----------------------------------------------------------------------------
extern "C" void EXTI2_IRQHandler(void);
//-----------------------------------------------------------------------------
void EXTI2_IRQHandler(void)
{
	{
		usb0.EP1R.Tx_Buffer[0]=3;
		EP1_COUNT_TX=2;
		usb0.EP1R.STAT_RX_TX(VALID,VALID);
	}
	EXTI_PR_BITS[PR2]=EXTI_PR_BITS[PR2];
}

⌨️ 快捷键说明

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