示例#1
0
int main(void)
{
	
	int autorun;
//		double calcfreq;
//	double CurrentFreq = 144e6;

	
  /* 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_SPI1_Init();
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);

  MX_TIM3_Init();
	MX_TIM14_Init();
  MX_USB_DEVICE_Init();
	
	Morse_Init();
	
//	prepare_pll();
//  UpdateFrequencyRegisters(CurrentFreq, 50000000.0, 5000, 1, 1, &calcfreq); 	
//	PLL_Sync();
	
	autorun = cmd_isautorun() ;

  /* Infinite loop */
  while (1)
  {
	  if (is_line_received())
		{
//     Process received line

			cmd_proc(get_line_buffer());
		}
		HAL_Delay(10); ar_count++;
		if ((ar_count > 1000) & (autorun>0))
		{
			// Start Autorun
			cmd_autorun(autorun);
			cw_autorunning = 1;
			while(cw_autorunning) HAL_Delay(10);
		}
  }
}
示例#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();

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

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_SPI1_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM7_Init();
  MX_TIM10_Init();
  MX_TIM11_Init();
  MX_TIM13_Init();
  MX_TIM14_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */
	
	HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);      //Motor1
	HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4);      //Motor2
	HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);      //Motor3
	HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);      //Motor4

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
示例#3
0
/**
  * @brief  The application entry point.
  *
  * @retval None
  */
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_TIM3_Init();
  //MX_IWDG_Init();
  MX_TIM14_Init();
  MX_TIM16_Init();
  MX_TIM17_Init();
  /* USER CODE BEGIN 2 */

  HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
  HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(TIM3_IRQn);
  HAL_TIM_Base_Start_IT(&htim3);


  // Seconds Counter startup duty
  HAL_TIM_Base_Start_IT(&htim14);
  HAL_TIM_Base_Stop_IT(&htim14);
  HAL_TIM_Base_Start_IT(&htim16);

  HAL_TIM_Base_Start_IT(&htim17);
  
  HAL_GPIO_WritePin(GPIOA, LED_RED_PIN, GPIO_PIN_RESET);
  ssd1306_Init();
  current_cursor = exposition;
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
    //HAL_IWDG_Refresh(&hiwdg);

    if(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSE) HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN, GPIO_PIN_SET);
    else HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN, GPIO_PIN_RESET);

    if (update_screen_flag)
    {
      ssd1306_Fill(Black);
      ssd1306_UpdateScreen();
      update_screen_flag = 0;
    }
    
    if (seconds_counter > STOP_TIME_SEC) //if more than 10 s need to stop
    {
      // Entering STOP Mode Procedure
      seconds_counter = 0;

      GPIO_InitTypeDef GPIO_InitStruct;
      

      ssd1306_WriteCommand(0xAE);       // OLED Off

      GPIO_InitStruct.Pin = ENC_BUTTON_PIN;
      GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING_FALLING;
      GPIO_InitStruct.Pull = GPIO_PULLDOWN;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

      HAL_NVIC_SetPriority(EXTI4_15_IRQn, 0, 0);
      HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);

      HAL_GPIO_WritePin(GPIOA, LED_GREEN_PIN|LED_RED_PIN|GATE_PIN|FOCUS_PIN, GPIO_PIN_RESET);

      HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFE);

      // Exit from STOP Mode procedure
      SystemClock_Config();
      ssd1306_WriteCommand(0xAF);      // OLED On

      GPIO_InitStruct.Pin = ENC_BUTTON_PIN;
      GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
      GPIO_InitStruct.Pull = GPIO_PULLDOWN;
      HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

      current_state = menu_navigation;
    }

    Menu();

    if (current_state == running_timer || current_state == running_interval)
    {
      if(gate_flag)
      {
        // Reset Gate & Focus
        HAL_GPIO_WritePin(GPIOA, FOCUS_PIN, GPIO_PIN_RESET);
        HAL_GPIO_WritePin(GPIOA, GATE_PIN, GPIO_PIN_RESET);
        HAL_TIM_Base_Stop_IT(&htim14);
        HAL_Delay(500);
        __HAL_TIM_SET_COUNTER(&htim14, 0);
        HAL_TIM_Base_Start_IT(&htim14);
        gate_flag = 0;
        // If not last shot, go to Interval state
        if(tmp_num_shots != 0)
        {
          tmp_int_minutes = set_int_minutes;
          tmp_int_sec = set_int_sec;
          tmp_exp_minutes = set_exp_minutes;
          tmp_exp_sec = set_exp_sec;
          current_state = running_interval;
          HAL_GPIO_WritePin(GPIOA, LED_RED_PIN,GPIO_PIN_RESET); // 1s LED Off
        }
        else
        {
          HAL_TIM_Base_Stop_IT(&htim14);
          __HAL_TIM_SET_COUNTER(&htim14, 0);
          HAL_GPIO_WritePin(GPIOA, LED_RED_PIN,GPIO_PIN_RESET); // 1s LED Off
          tmp_exp_minutes = set_exp_minutes;
          tmp_exp_sec = set_exp_sec;
          current_state = menu_navigation;
          update_screen_flag = 1;
        }
      }
    }
      
    if (exiting_run)
    {
      HAL_TIM_Base_Stop_IT(&htim16);
      HAL_Delay(1000);
      exiting_run = 0;
      HAL_TIM_Base_Start_IT(&htim16);
      HAL_GPIO_WritePin(GPIOA, FOCUS_PIN, GPIO_PIN_RESET);
      HAL_GPIO_WritePin(GPIOA, GATE_PIN, GPIO_PIN_RESET);
    }
    
  }
  /* USER CODE END 3 */

}
示例#4
0
int main(void)
{
    /* 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_ADC_Init();
    MX_SPI1_Init();
    MX_USB_DEVICE_Init();
    MX_TIM14_Init();

    HAL_FLASH_Unlock();
    EE_Init();

    EE_ReadVariable(VirtAddVarTab[0], &x_low_th);
    EE_ReadVariable(VirtAddVarTab[1], &x_high_th);
    EE_ReadVariable(VirtAddVarTab[2], &y_low_th);
    EE_ReadVariable(VirtAddVarTab[3], &y_high_th);

    HAL_FLASH_Lock();

    HAL_ADC_Start_DMA(&hadc, (uint32_t*)axis, 5);

    while (1)
    {
        HAL_GPIO_WritePin(SPI1_nCS_GPIO_Port, SPI1_nCS_Pin, GPIO_PIN_SET);

        HAL_TIM_Base_Start_IT(&htim14);
        while (!u100ticks) /* do nothing for 100 us */;
        HAL_TIM_Base_Stop_IT(&htim14);
        u100ticks = 0;

        HAL_StatusTypeDef status =
            HAL_SPI_Receive(&hspi1, rx_buffer, sizeof(rx_buffer), 3000);

        switch(status)
        {
        case HAL_OK:
            report.buttons[0] = 0x00;
            // report.buttons[1] = 0x00;
            report.buttons[2] = 0x00;

            if ((rx_buffer[0] & 0xff) != 0xff)   // if all bits of rx_buffer[0] is 1 assume shifter is disconnected
            {
                if (rx_buffer[0] & 4)   report.buttons[0] |= 1;         else report.buttons[0] &= ~1;
                if (rx_buffer[0] & 1)   report.buttons[0] |= (1 << 1);  else report.buttons[0] &= ~(1 << 1);
                if (rx_buffer[0] & 2)   report.buttons[0] |= (1 << 2);  else report.buttons[0] &= ~(1 << 2);
                if (rx_buffer[0] & 8)   report.buttons[0] |= (1 << 3);  else report.buttons[0] &= ~(1 << 3);

                if (rx_buffer[1] & 1)   report.buttons[2] |= 1;         else report.buttons[2] &= ~1;
                if (rx_buffer[1] & 2)   report.buttons[2] |= (1 << 1);  else report.buttons[2] &= ~(1 << 1);
                if (rx_buffer[1] & 4)   report.buttons[2] |= (1 << 2);  else report.buttons[2] &= ~(1 << 2);
                if (rx_buffer[1] & 8)   report.buttons[2] |= (1 << 3);  else report.buttons[2] &= ~(1 << 3);

                if (rx_buffer[1] & 32)  report.buttons[0] |= (1 << 4);  else report.buttons[0] &= ~(1 << 4);
                if (rx_buffer[1] & 128) report.buttons[0] |= (1 << 5);  else report.buttons[0] &= ~(1 << 5);
                if (rx_buffer[1] & 64)  report.buttons[0] |= (1 << 6);  else report.buttons[0] &= ~(1 << 6);
                if (rx_buffer[1] & 16)  report.buttons[0] |= (1 << 7);  else report.buttons[0] &= ~(1 << 7);
            }
            break;

        case HAL_TIMEOUT:
        case HAL_BUSY:
        case HAL_ERROR:
            Error_Handler();
        default:
            report.buttons[0] = 0xff;
            break;
        }

        HAL_GPIO_WritePin(SPI1_nCS_GPIO_Port, SPI1_nCS_Pin, GPIO_PIN_RESET);
        report.id = 0x01;

        x_axis = ((X_AXIS << 2) + x_axis * 96) / 100;
        y_axis = ((Y_AXIS << 2) + y_axis * 96) / 100;

        if (rx_buffer[0] & 16)
        {
            if (y_axis < y_low_th)   // stick towards player
            {
                report.buttons[1] = 128;
                report.buttons[2] &= ~(1 << 4);
            }
            else if (y_axis > y_high_th)   // stick opposite to player
            {
                report.buttons[1] = 0; // neutral
                report.buttons[2] |= (1 << 4);
            }
            else
            {
                report.buttons[1] = 0; // neutral
                report.buttons[2] &= ~(1 << 4);
            }
        }
        else
        {
            report.buttons[1] &= ~(1 << 7);
            report.buttons[2] &= ~(1 << 4);

            if (y_axis < y_low_th)   // stick towards player
            {
                if (x_axis < x_low_th)
                {
                    if (!report.buttons[1]) report.buttons[1] = 2; // 2nd gear
                }
                else if (!report.buttons[1])
                {
                    report.buttons[1] = (x_axis > x_high_th) ? ((rx_buffer[0] & 64) ? 64 : 32) : 8;
                }
            }
            else
            {
                if (y_axis > y_high_th)   // stick opposite to player
                {
                    if (x_axis < x_low_th)
                    {
                        if (!report.buttons[1]) report.buttons[1] = 1; // 1st gear
                    }
                    else if (!report.buttons[1])
                    {
                        report.buttons[1] = (x_axis > x_high_th) ? 16 : 4;
                    }
                }
                else
                {
                    report.buttons[1] = 0; // neutral
                }
            }
        }

        report.axis[0] = x_axis;
        report.axis[1] = y_axis;

        if (report2send == 2)
        {
            HAL_FLASH_Unlock();

            EE_WriteVariable(VirtAddVarTab[0], x_low_th);
            EE_WriteVariable(VirtAddVarTab[1], x_high_th);
            EE_WriteVariable(VirtAddVarTab[2], y_low_th);
            EE_WriteVariable(VirtAddVarTab[3], y_high_th);

            HAL_FLASH_Lock();
            report2send = 0;
        }

        if (hUsbDeviceFS.pClassData
                && ((USBD_HID_HandleTypeDef *)hUsbDeviceFS.pClassData)->state == HID_IDLE)
        {
            USBD_HID_SendReport(&hUsbDeviceFS, (uint8_t *)&report, sizeof(report));
        }
    }
}
示例#5
0
int main(void)
{
  uint8_t oldRelease = 0;
  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */
  /* Enable I-Cache-------------------------------------------------------------*/
  SCB_EnableICache();
  /* Enable D-Cache-------------------------------------------------------------*/
  SCB_EnableDCache();
  /* 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_ADC1_Init();
  MX_DMA_Init();
  MX_CAN1_Init();
  MX_CAN2_Init();
  MX_DAC_Init();
  MX_DMA2D_Init();
  MX_FMC_Init();
  MX_I2C2_Init();
  MX_SDMMC1_SD_Init();
  MX_SPI2_Init();
  MX_TIM6_Init();
  MX_TIM7_Init();
  MX_USART2_UART_Init();
  MX_USART3_UART_Init();
  MX_USART6_UART_Init();
  MX_FATFS_Init();
  MX_USB_HOST_Init();
  MX_TIM11_Init();
  MX_TIM13_Init();
  MX_TIM14_Init();

  /* USER CODE BEGIN 2 */
  //MPU_Config(); 
  InitPeriph();
  
  /* USER CODE END 2 */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while(1){
  /* USER CODE END WHILE */
    MX_USB_HOST_Process();

  /* USER CODE BEGIN 3 */
   RoutineFast(); // get and run deals from medium queue 

   if(oldRelease && Touch_Data.status == TOUCH_RELEASED){
   ReleaseFunction();
   }
   else
   {oldRelease = 1;}
 if(UpdateScreen|| DISP.ReleaseFlag || TimeIsReady){
  Run_GUI();

  Show_GUI();
  UpdateScreen = 0;
  DISP.ReleaseFlag = 0;
  }
    
  }
  /* USER CODE END 3 */

}