Ejemplo n.º 1
0
int main(void)
{
	SysTick_init();
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	
	uart_init(115200);
	
	Struct_Init();
	Pid_Init();
	
	MotoPwm_Init();
	
	OLED_Init();
	Key_Init();
	
	I2cMaster_Init();
  mpu_dmp_init();	
	GPIO_Config();
	
	Filter_Init();
	
//	NRF_Usart_Pin_Init();//无线初始化
//	NRF_Read_Live_Init();//无线在线传输	
//  ReadData_Init();
	
	Scheduler_Init();
	
  while(1)
	{
		Scheduler_Loop();
	}
}
Ejemplo n.º 2
0
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();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_I2C1_Init();
  MX_USART1_UART_Init();
  MX_TIM16_Init();
  MX_TIM17_Init();

  /* USER CODE BEGIN 2 */
  g_config = g_config_default;

#ifdef USE_I2C
	g_i2c = I2cMaster_Init(&hi2c1);
	InitializeDisplay(g_i2c);
	I2cEEPROM_Init(&g_eeprom, g_i2c, EEPROMADDR, 1, 8);
#endif

#ifdef USE_SERIAL
	UsartInit(&huart1);
#endif

#if defined(USE_I2C) && defined(USE_LCD)
	I2cLcd_Clear(&g_lcd);
	I2cLcd_PrintStr(&g_lcd, "Hello");
#endif

#if defined(USE_SERIAL) && defined(USE_EEPROM)

#define TESTSIZE 2048/8

	HAL_StatusTypeDef st;
	uint8_t i2cBuffer[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

/*
	for(uint16_t i = 0; i < TESTSIZE; i += sizeof(i2cBuffer)) {
		if(!(i & (sizeof(i2cBuffer)-1))) {
			st = I2cEEPROM_Write(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer));
		}
	}

	for (uint16_t i = 0; i < TESTSIZE; ++i) {
		if(!(i & (sizeof(i2cBuffer)-1))) 	{
			st = I2cEEPROM_Read(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer));
			UsartSendStr("\r\n", 1);
			UsartPrintUint(i, 4, 1);
			UsartSendStr(" ", 1);
		}
		UsartPrintByte(i2cBuffer[i&(sizeof(i2cBuffer)-1)], 2, 1);
		UsartSendStr(" ", 1);
	}
	UsartSendStr("\r\n", 1);

	for(uint16_t i = 0; i < TESTSIZE; i += sizeof(i2cBuffer)) {
		if(!(i & (sizeof(i2cBuffer)-1))) {
			for(uint16_t j = 0; j<sizeof(i2cBuffer); ++j)
				i2cBuffer[j] = i+j;
			st = I2cEEPROM_Write(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer));
		}
	}

	for (uint16_t i = 0; i < TESTSIZE; ++i) {
		if(!(i & (sizeof(i2cBuffer)-1))) 	{
			st = I2cEEPROM_Read(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer));
			UsartSendStr("\r\n", 1);
			UsartPrintUint(i, 4, 1);
			UsartSendStr(" ", 1);
		}
		UsartPrintByte(i2cBuffer[i&(sizeof(i2cBuffer)-1)], 2, 1);
		UsartSendStr(" ", 1);
	}
	UsartSendStr("\r\n", 1);
*/
	{
		LIVECONFIG config;

		if (I2cEEPROM_Read(&g_eeprom, EESTART, &config, sizeof(config)) == HAL_OK) {
			I2cMaster_WaitCallback(g_i2c);
			if (config.magic == 0xA5)
				g_config = config;
		}
	}

	for (uint16_t i = 0; i < TESTSIZE; ++i) {
		if(!(i & (sizeof(i2cBuffer)-1))) 	{
			st = I2cEEPROM_Read(&g_eeprom, i, i2cBuffer, sizeof(i2cBuffer));
			UsartSendStr("\r\n", 1);
			UsartPrintUint(i, 4, 1);
			UsartSendStr(" ", 1);
		}
		UsartPrintByte(i2cBuffer[i&(sizeof(i2cBuffer)-1)], 2, 1);
		UsartSendStr(" ", 1);
	}
	UsartSendStr("\r\n", 1);

#endif
	HAL_TIM_IC_Start_IT(&htim16, TIM_CHANNEL_1);
	HAL_TIM_IC_Start_IT(&htim17, TIM_CHANNEL_1);

	HAL_UART_Receive_IT(&huart1, g_lineBuffer, sizeof(g_lineBuffer));

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

	while (1) {

		if (g_lineReceived) {
			ProcessInput(&g_config, (char*) g_lineBuffer);
			//DisplayInput(&i2clcd);
			g_lineReceived = 0;
			HAL_UART_Receive_IT(&huart1, g_lineBuffer, sizeof(g_lineBuffer));
		}

		if(g_statuses[0].trigger) {
		  DisplayResults(0);
		  g_statuses[0].trigger = 0;
		}
		if(g_statuses[1].trigger) {
		  DisplayResults(1);
		  g_statuses[1].trigger = 0;
		}

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

	}
  /* USER CODE END 3 */

}