SHARE
TWEET

Untitled

a guest Jun 24th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  10.   * All rights reserved.</center></h2>
  11.   *
  12.   * This software component is licensed by ST under Ultimate Liberty license
  13.   * SLA0044, the "License"; You may not use this file except in compliance with
  14.   * the License. You may obtain a copy of the License at:
  15.   *                             www.st.com/SLA0044
  16.   *
  17.   ******************************************************************************
  18.   */
  19. /* USER CODE END Header */
  20.  
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "main.h"
  23. #include "cmsis_os.h"
  24.  
  25. /* Private includes ----------------------------------------------------------*/
  26. /* USER CODE BEGIN Includes */
  27. #include "atraso.h"
  28. #include "defPrincipais.h"
  29. #include "NOKIA5110_fb.h"
  30. #include "figuras.h"
  31. #include "PRNG_LFSR.h"
  32. //#include "sound.h"
  33. /* USER CODE END Includes */
  34.  
  35. /* Private typedef -----------------------------------------------------------*/
  36. /* USER CODE BEGIN PTD */
  37.  
  38. /* USER CODE END PTD */
  39.  
  40. /* Private define ------------------------------------------------------------*/
  41. /* USER CODE BEGIN PD */
  42.  
  43. /* USER CODE END PD */
  44.  
  45. /* Private macro -------------------------------------------------------------*/
  46. /* USER CODE BEGIN PM */
  47.  
  48. /* USER CODE END PM */
  49.  
  50. /* Private variables ---------------------------------------------------------*/
  51. ADC_HandleTypeDef hadc1;
  52. DMA_HandleTypeDef hdma_adc1;
  53.  
  54. TIM_HandleTypeDef htim2;
  55. TIM_HandleTypeDef htim3;
  56.  
  57. osThreadId defaultTaskHandle;
  58. /* USER CODE BEGIN PV */
  59. /* Private variables ---------------------------------------------------------*/
  60.  
  61. uint32_t score;
  62.  
  63. //flags joy
  64. uint32_t joystick_pos[4];
  65.  
  66. uint32_t ADC_buffer[2];
  67. uint32_t valor_ADC[2];
  68. uint32_t counter;
  69.  
  70. TaskHandle_t GameHandle;
  71. //TaskHandle_t CriaSetaHandle;
  72. //TaskHandle_t SoundSHandle;
  73. //TaskHandle_t DeslocaHandle;
  74. TaskHandle_t JoyHandle;     // Para excluir uma task(que não se auto exclui) é necessário o Handler
  75.  
  76.  
  77. //xQueueHandle xSound;
  78.  
  79.  
  80. /* USER CODE END PV */
  81.  
  82. /* Private function prototypes -----------------------------------------------*/
  83. void SystemClock_Config(void);
  84. static void MX_GPIO_Init(void);
  85. static void MX_DMA_Init(void);
  86. static void MX_ADC1_Init(void);
  87. static void MX_TIM3_Init(void);
  88. static void MX_TIM2_Init(void);
  89. void StartDefaultTask(void const * argument);
  90.  
  91. /* USER CODE BEGIN PFP */
  92. /* Private function prototypes -----------------------------------------------*/
  93.  
  94.  
  95. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc);
  96. void change_note (TIM_HandleTypeDef *htim, int nota);
  97.  
  98. //- Tasks do jogo
  99. void vT_Create_Game (void *pv);
  100. void vT_Game (void * pv);
  101. //void vT_Sound(void *pv);
  102. void vT_Joy(void *pv);
  103. void vT_Restart (void * pv);
  104.  
  105. /* USER CODE END PFP */
  106.  
  107. /* Private user code ---------------------------------------------------------*/
  108. /* USER CODE BEGIN 0 */
  109.  
  110. /* USER CODE END 0 */
  111.  
  112. /**
  113.   * @brief  The application entry point.
  114.   * @retval int
  115.   */
  116. int main(void)
  117. {
  118.   /* USER CODE BEGIN 1 */
  119.  
  120.   /* USER CODE END 1 */
  121.  
  122.  
  123.   /* MCU Configuration--------------------------------------------------------*/
  124.  
  125.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  126.   HAL_Init();
  127.  
  128.   /* USER CODE BEGIN Init */
  129.  
  130.   /* USER CODE END Init */
  131.  
  132.   /* Configure the system clock */
  133.   SystemClock_Config();
  134.  
  135.   /* USER CODE BEGIN SysInit */
  136.  
  137.   /* USER CODE END SysInit */
  138.  
  139.   /* Initialize all configured peripherals */
  140.   MX_GPIO_Init();
  141.   MX_DMA_Init();
  142.   MX_ADC1_Init();
  143.   MX_TIM3_Init();
  144.   MX_TIM2_Init();
  145.   /* USER CODE BEGIN 2 */
  146.  
  147.   //LCD 5110
  148.   inic_LCD();
  149.   limpa_LCD();
  150.  
  151.  /* escreve2fb( (unsigned char *) intro);
  152.   imprime_LCD();
  153.   while(1){
  154.  
  155.   }
  156. */
  157.  
  158.   //ADC Joystick
  159.   HAL_ADC_Start_DMA(&hadc1,(uint32_t*)ADC_buffer,2);
  160.   HAL_ADC_Start_IT(&hadc1);
  161.  
  162.   //PWM Buzzer
  163.   HAL_TIM_Base_Start(&htim3);
  164.   HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_4);
  165.  
  166.  
  167.   /* USER CODE END 2 */
  168.  
  169.   /* USER CODE BEGIN RTOS_MUTEX */
  170.   /* add mutexes, ... */
  171.   /* USER CODE END RTOS_MUTEX */
  172.  
  173.   /* USER CODE BEGIN RTOS_SEMAPHORES */
  174.   //xSound = xQueueCreateCountingSemaphore(10, sizeof(long));
  175.  // xSound = xQueueCreateCountingSemaphore(16,0);
  176.   //xQueueCreateCountingSemaphore()
  177.  
  178.   //xSound = xQueueCreate(16, sizeof(uint32_t));
  179.  
  180.  
  181.  
  182.   /* USER CODE END RTOS_SEMAPHORES */
  183.  
  184.   /* USER CODE BEGIN RTOS_TIMERS */
  185.   /* start timers, add new ones, ... */
  186.   /* USER CODE END RTOS_TIMERS */
  187.  
  188.   /* USER CODE BEGIN RTOS_QUEUES */
  189.   /* add queues, ... */
  190.  
  191.  
  192.  
  193.  
  194.   /* USER CODE END RTOS_QUEUES */
  195.  
  196.   /* Create the thread(s) */
  197.   /* definition and creation of defaultTask */
  198.  // osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  199.  // defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  200.  
  201.   /* USER CODE BEGIN RTOS_THREADS */
  202.   /* add threads, ... */
  203.   uint32_t vT_Create = pdTRUE;
  204.   vT_Create = xTaskCreate(vT_Create_Game, "Create", 64, NULL, 3, NULL);
  205.  
  206.   if (vT_Create == pdFALSE){
  207.         //abort
  208.         string_LCD("Erro ao criar tarefas");
  209.         imprime_LCD();
  210.         while(1);
  211.     }
  212.  
  213.  
  214.  
  215.   /* USER CODE END RTOS_THREADS */
  216.  
  217.   /* Start scheduler */
  218.   osKernelStart();
  219.  
  220.   /* We should never get here as control is now taken by the scheduler */
  221.  
  222.   /* Infinite loop */
  223.   /* USER CODE BEGIN WHILE */
  224.   while (1)
  225.   {
  226.  
  227.     /* USER CODE END WHILE */
  228.  
  229.     /* USER CODE BEGIN 3 */
  230.  
  231.   }
  232.   /* USER CODE END 3 */
  233. }
  234.  
  235. /**
  236.   * @brief System Clock Configuration
  237.   * @retval None
  238.   */
  239. void SystemClock_Config(void)
  240. {
  241.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  242.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  243.   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  244.  
  245.   /** Initializes the CPU, AHB and APB busses clocks
  246.   */
  247.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  248.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  249.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  250.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  251.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  252.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  253.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  254.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  255.   {
  256.     Error_Handler();
  257.   }
  258.   /** Initializes the CPU, AHB and APB busses clocks
  259.   */
  260.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  261.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  262.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  263.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  264.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  265.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  266.  
  267.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  268.   {
  269.     Error_Handler();
  270.   }
  271.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
  272.   PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
  273.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  274.   {
  275.     Error_Handler();
  276.   }
  277. }
  278.  
  279. /**
  280.   * @brief ADC1 Initialization Function
  281.   * @param None
  282.   * @retval None
  283.   */
  284. static void MX_ADC1_Init(void)
  285. {
  286.  
  287.   /* USER CODE BEGIN ADC1_Init 0 */
  288.  
  289.   /* USER CODE END ADC1_Init 0 */
  290.  
  291.   ADC_ChannelConfTypeDef sConfig = {0};
  292.  
  293.   /* USER CODE BEGIN ADC1_Init 1 */
  294.  
  295.   /* USER CODE END ADC1_Init 1 */
  296.   /** Common config
  297.   */
  298.   hadc1.Instance = ADC1;
  299.   hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  300.   hadc1.Init.ContinuousConvMode = ENABLE;
  301.   hadc1.Init.DiscontinuousConvMode = DISABLE;
  302.   hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  303.   hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  304.   hadc1.Init.NbrOfConversion = 2;
  305.   if (HAL_ADC_Init(&hadc1) != HAL_OK)
  306.   {
  307.     Error_Handler();
  308.   }
  309.   /** Configure Regular Channel
  310.   */
  311.   sConfig.Channel = ADC_CHANNEL_1;
  312.   sConfig.Rank = ADC_REGULAR_RANK_1;
  313.   sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
  314.   if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  315.   {
  316.     Error_Handler();
  317.   }
  318.   /** Configure Regular Channel
  319.   */
  320.   sConfig.Channel = ADC_CHANNEL_2;
  321.   sConfig.Rank = ADC_REGULAR_RANK_2;
  322.   if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  323.   {
  324.     Error_Handler();
  325.   }
  326.   /* USER CODE BEGIN ADC1_Init 2 */
  327.  
  328.   /* USER CODE END ADC1_Init 2 */
  329.  
  330. }
  331.  
  332. /**
  333.   * @brief TIM2 Initialization Function
  334.   * @param None
  335.   * @retval None
  336.   */
  337. static void MX_TIM2_Init(void)
  338. {
  339.  
  340.   /* USER CODE BEGIN TIM2_Init 0 */
  341.  
  342.   /* USER CODE END TIM2_Init 0 */
  343.  
  344.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  345.   TIM_OC_InitTypeDef sConfigOC = {0};
  346.  
  347.   /* USER CODE BEGIN TIM2_Init 1 */
  348.  
  349.   /* USER CODE END TIM2_Init 1 */
  350.   htim2.Instance = TIM2;
  351.   htim2.Init.Prescaler = 0;
  352.   htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
  353.   htim2.Init.Period = TIM_COUNT;
  354.   htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  355.   htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
  356.   if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
  357.   {
  358.     Error_Handler();
  359.   }
  360.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  361.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  362.   if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
  363.   {
  364.     Error_Handler();
  365.   }
  366.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  367.   sConfigOC.Pulse = 900;
  368.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  369.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  370.   if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  371.   {
  372.     Error_Handler();
  373.   }
  374.   /* USER CODE BEGIN TIM2_Init 2 */
  375.  
  376.   /* USER CODE END TIM2_Init 2 */
  377.   HAL_TIM_MspPostInit(&htim2);
  378.  
  379. }
  380.  
  381. /**
  382.   * @brief TIM3 Initialization Function
  383.   * @param None
  384.   * @retval None
  385.   */
  386. static void MX_TIM3_Init(void)
  387. {
  388.  
  389.   /* USER CODE BEGIN TIM3_Init 0 */
  390.  
  391.   /* USER CODE END TIM3_Init 0 */
  392.  
  393.   TIM_MasterConfigTypeDef sMasterConfig = {0};
  394.   TIM_OC_InitTypeDef sConfigOC = {0};
  395.  
  396.   /* USER CODE BEGIN TIM3_Init 1 */
  397.  
  398.   /* USER CODE END TIM3_Init 1 */
  399.   htim3.Instance = TIM3;
  400.   htim3.Init.Prescaler = 0;
  401.   htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  402.   htim3.Init.Period = TIM_COUNT;
  403.   htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  404.   htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
  405.   if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
  406.   {
  407.     Error_Handler();
  408.   }
  409.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  410.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  411.   if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
  412.   {
  413.     Error_Handler();
  414.   }
  415.   sConfigOC.OCMode = TIM_OCMODE_PWM1;
  416.   sConfigOC.Pulse = 900;
  417.   sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  418.   sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  419.   if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
  420.   {
  421.     Error_Handler();
  422.   }
  423.   /* USER CODE BEGIN TIM3_Init 2 */
  424.  
  425.   /* USER CODE END TIM3_Init 2 */
  426.   HAL_TIM_MspPostInit(&htim3);
  427.  
  428. }
  429.  
  430. /**
  431.   * Enable DMA controller clock
  432.   */
  433. static void MX_DMA_Init(void)
  434. {
  435.   /* DMA controller clock enable */
  436.   __HAL_RCC_DMA1_CLK_ENABLE();
  437.  
  438.   /* DMA interrupt init */
  439.   /* DMA1_Channel1_IRQn interrupt configuration */
  440.   HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 5, 0);
  441.   HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
  442.  
  443. }
  444.  
  445. /**
  446.   * @brief GPIO Initialization Function
  447.   * @param None
  448.   * @retval None
  449.   */
  450. static void MX_GPIO_Init(void)
  451. {
  452.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  453.  
  454.   /* GPIO Ports Clock Enable */
  455.   __HAL_RCC_GPIOC_CLK_ENABLE();
  456.   __HAL_RCC_GPIOD_CLK_ENABLE();
  457.   __HAL_RCC_GPIOA_CLK_ENABLE();
  458.   __HAL_RCC_GPIOB_CLK_ENABLE();
  459.  
  460.   /*Configure GPIO pin Output Level */
  461.   HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
  462.                           |GPIO_PIN_7, GPIO_PIN_RESET);
  463.  
  464.   /*Configure GPIO pin : Botao_Pin */
  465.   GPIO_InitStruct.Pin = GPIO_PIN_15;
  466.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  467.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  468.   HAL_GPIO_Init(Botao_GPIO_Port, &GPIO_InitStruct);
  469.  
  470.   /*Configure GPIO pins : PA3 PA4 PA5 PA6
  471.                            PA7 */
  472.   GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6
  473.                           |GPIO_PIN_7;
  474.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  475.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  476.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  477.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  478.  
  479. }
  480.  
  481. /* USER CODE BEGIN 4 */
  482.  
  483.  
  484. // Protótipo funções
  485. void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
  486. {
  487.     if(hadc->Instance == ADC1)
  488.     {
  489.         valor_ADC[0]=ADC_buffer[0];
  490.         valor_ADC[1]=ADC_buffer[1];
  491.     }
  492. }
  493. void change_note (TIM_HandleTypeDef *htim, int nota){
  494.     uint32_t prescaler;
  495.     if (nota>0)
  496.         prescaler = SystemCoreClock/(TIM_COUNT*nota);
  497.     else
  498.         prescaler =0;
  499.     __HAL_TIM_SET_PRESCALER(htim, prescaler);
  500. }
  501.  
  502.  
  503. void vT_Create_Game(void * pv){
  504.  
  505.     uint32_t seed = 1;
  506.     uint32_t count = 0;
  507.     score = 0;
  508.  
  509.     //TELA DE INICIO
  510.  
  511.     while(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_15)){ // enquando nao pressionar joystick fica travado
  512.  
  513.             seed++;     // semente para o gerador de números pseudoaleatorios
  514.  
  515.             if(count == 0)
  516.             {
  517.                 escreve2fb((unsigned char *)intro);
  518.             }
  519.  
  520.             if(count == 300)
  521.             {
  522.                 escreve2fb((unsigned char *)intro2);
  523.             }
  524.  
  525.             count++;
  526.  
  527.             if(count == 600)
  528.             {
  529.                 count = 0;
  530.             }
  531.  
  532.             imprime_LCD();
  533.             vTaskDelay(5);
  534.  
  535.     }
  536.  
  537.     init_LFSR(seed);    // inicializacao para geracao de numeros pseudoaleatorios
  538.  
  539.     uint32_t vT_Create = pdTRUE;
  540.  
  541.     vT_Create = xTaskCreate(vT_Game, "Game", 64, NULL,1, &GameHandle);
  542.     vT_Create = xTaskCreate(vT_Joy, "Joy", 64, NULL,1, &JoyHandle);
  543.     //vT_Create = xTaskCreate(vT_Sound, "Som", 128, NULL,1, &SoundSHandle);
  544.  
  545.     if (vT_Create != pdPASS){
  546.         //abort
  547.         string_LCD("Erro ao criar tarefas");
  548.         imprime_LCD();
  549.         while(1);
  550.     }
  551.  
  552.     //delete task - somente executar uma vez
  553.     vTaskDelete(NULL);
  554.     while(1){
  555.     }
  556.  
  557. }
  558.  
  559.     uint8_t vect_rand[256];
  560.     uint32_t but_count = 0;
  561.     uint32_t i;
  562.  
  563. void vT_Game(void *pv) {
  564.  
  565.         while(but_count < 256) {
  566.  
  567.             vect_rand[but_count] = rand()%4;    // preenche o vetor com os valores das direções (0 à 3)
  568.             but_count++;
  569.  
  570.             for( i = 0; i < but_count; i++) {
  571.  
  572.                 if(vect_rand[i] == 0) {
  573.                     escreve2fb((unsigned char *)pisca_up);
  574.                 }
  575.  
  576.                 if(vect_rand[i] == 1) {
  577.                     escreve2fb((unsigned char *)pisca_right);
  578.                 }
  579.  
  580.                 if(vect_rand[i] == 2) {
  581.                     escreve2fb((unsigned char *)pisca_down);
  582.                 }
  583.  
  584.                 if(vect_rand[i] == 3) {
  585.                     escreve2fb((unsigned char *)pisca_left);
  586.                 }
  587.  
  588.                 imprime_LCD();
  589.                 vTaskDelay(1500);
  590.                 escreve2fb((unsigned char *)jogo);
  591.                 imprime_LCD();
  592.                 vTaskDelay(500);
  593.             }
  594.  
  595.             for( i = 0; i < but_count; i++) {
  596.  
  597.                 while(!(joystick_pos[UP] || joystick_pos[RIGHT] || joystick_pos[DOWN] || joystick_pos[LEFT])) // enquanto nenhuma direção estiver em 1
  598.  
  599.                 if(joystick_pos[UP]){
  600.                     if(vect_rand[i] == UP){
  601.                     escreve2fb((unsigned char *)pisca_up);
  602.                     imprime_LCD();
  603.                     vTaskDelay(1500);
  604.                     escreve2fb((unsigned char *)jogo);
  605.                     imprime_LCD();
  606.                     vTaskDelay(500);
  607.                     score++;
  608.                     }
  609.  
  610.                 else
  611.                     but_count = End_Game;   // perdeu o jogo -> sai do while
  612.                 }
  613.  
  614.                 if(joystick_pos[RIGHT]){
  615.                     if(vect_rand[i] == RIGHT){
  616.                     escreve2fb((unsigned char *)pisca_right);
  617.                     imprime_LCD();
  618.                     vTaskDelay(1500);
  619.                     escreve2fb((unsigned char *)jogo);
  620.                     imprime_LCD();
  621.                     vTaskDelay(500);
  622.                     score++;
  623.                     }
  624.  
  625.                 else
  626.                     but_count = End_Game;   // perdeu o jogo -> sai do while
  627.                 }
  628.  
  629.                 if(joystick_pos[DOWN]){
  630.                     if(vect_rand[i] == DOWN){
  631.                     escreve2fb((unsigned char *)pisca_down);
  632.                     imprime_LCD();
  633.                     vTaskDelay(1500);
  634.                     escreve2fb((unsigned char *)jogo);
  635.                     imprime_LCD();
  636.                     vTaskDelay(500);
  637.                     score++;
  638.                     }
  639.  
  640.                 else
  641.                     but_count = End_Game;   // perdeu o jogo -> sai do while
  642.                 }
  643.  
  644.                 if(joystick_pos[LEFT]){
  645.                     if(vect_rand[i] == LEFT){
  646.                     escreve2fb((unsigned char *)pisca_left);
  647.                     imprime_LCD();
  648.                     vTaskDelay(1500);
  649.                     escreve2fb((unsigned char *)jogo);
  650.                     imprime_LCD();
  651.                     vTaskDelay(500);
  652.                     score++;
  653.                     }
  654.  
  655.                 else
  656.                     but_count = End_Game;   // perdeu o jogo -> sai do while
  657.                 }
  658.  
  659.             }
  660.         }
  661.  
  662.         escreve2fb((unsigned char *)placar);
  663.         escreve_Nr_Peq(34, 20, score, 0);
  664.         imprime_LCD();
  665.         vTaskDelay(3500);
  666.  
  667.         xTaskCreate(vT_Restart, "Restart", 64, NULL,3, NULL);
  668.  
  669. }
  670.  
  671. /*void vT_Sound(void *pv){
  672.  
  673.     int pos;
  674.  
  675.     while(1)
  676.     {
  677.         xQueueReceive(xSound,&pos,osWaitForever);
  678.  
  679.  
  680.         //vTaskDelay(MS(60*(48/passo)));
  681.  
  682.         change_note(&htim3, song[pos]);
  683.  
  684.         vTaskDelay(MS(song[pos+1]));
  685.  
  686.         change_note(&htim3, 0);
  687.  
  688.         vTaskDelay(MS(3));  //
  689.  
  690.     }
  691.  
  692. }
  693. */
  694.  
  695. void vT_Joy(void *pv){
  696.  
  697.     while(1){
  698.  
  699.         if (valor_ADC[0]<MIN_JOY){
  700.             joystick_pos[DOWN]= 1;
  701.         } else{
  702.             joystick_pos[DOWN]= 0;
  703.         }
  704.         if (valor_ADC[0]>MAX_JOY){
  705.             joystick_pos[UP]= 1;
  706.         } else{
  707.             joystick_pos[UP]= 0;
  708.         }
  709.         if (valor_ADC[1]<MIN_JOY){
  710.             joystick_pos[RIGHT]= 1;
  711.         } else{
  712.             joystick_pos[RIGHT]= 0;
  713.         }
  714.         if (valor_ADC[1]>MAX_JOY){
  715.             joystick_pos[LEFT]= 1;
  716.         } else{
  717.             joystick_pos[LEFT]= 0;
  718.         }
  719.  
  720.         vTaskDelay(MS(100));
  721.     }
  722.  
  723. }
  724.  
  725. void vT_Restart (void * pv){
  726.  
  727.     limpa_LCD();
  728.     //desenha tela de jogar novamente
  729.     escreve2fb((unsigned char *)restart);
  730.     imprime_LCD();
  731.  
  732.     vTaskDelete(GameHandle);
  733.     //vTaskDelete(SoundSHandle);
  734.     vTaskDelete(JoyHandle);
  735.  
  736.     while(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_15)){ // enquanto não pressionar joystick fica travado
  737.  
  738.  
  739.     }
  740.  
  741.     HAL_Delay(1000);
  742.     xTaskCreate(vT_Create_Game,"Create",64, NULL, 4, NULL);
  743.  
  744.     //delete task - somente executar uma vez
  745.     vTaskDelete(NULL);
  746.     while(1){
  747.     }
  748. }
  749.  
  750. /* USER CODE END 4 */
  751.  
  752. /* USER CODE BEGIN Header_StartDefaultTask */
  753. /**
  754.   * @brief  Function implementing the defaultTask thread.
  755.   * @param  argument: Not used
  756.   * @retval None
  757.   */
  758. /* USER CODE END Header_StartDefaultTask */
  759. void StartDefaultTask(void const * argument)
  760. {
  761.  
  762.   /* USER CODE BEGIN 5 */
  763.   /* Infinite loop */
  764.   for(;;)
  765.   {
  766.     osDelay(1);
  767.   }
  768.   /* USER CODE END 5 */
  769. }
  770.  
  771. /**
  772.   * @brief  Period elapsed callback in non blocking mode
  773.   * @note   This function is called  when TIM1 interrupt took place, inside
  774.   * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
  775.   * a global variable "uwTick" used as application time base.
  776.   * @param  htim : TIM handle
  777.   * @retval None
  778.   */
  779. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  780. {
  781.   /* USER CODE BEGIN Callback 0 */
  782.  
  783.   /* USER CODE END Callback 0 */
  784.   if (htim->Instance == TIM1) {
  785.     HAL_IncTick();
  786.   }
  787.   /* USER CODE BEGIN Callback 1 */
  788.  
  789.   /* USER CODE END Callback 1 */
  790. }
  791.  
  792. /**
  793.   * @brief  This function is executed in case of error occurrence.
  794.   * @retval None
  795.   */
  796. void Error_Handler(void)
  797. {
  798.   /* USER CODE BEGIN Error_Handler_Debug */
  799.   /* User can add his own implementation to report the HAL error return state */
  800.   while(1)
  801.   {
  802.   }
  803.   /* USER CODE END Error_Handler_Debug */
  804. }
  805.  
  806. #ifdef  USE_FULL_ASSERT
  807. /**
  808.   * @brief  Reports the name of the source file and the source line number
  809.   *         where the assert_param error has occurred.
  810.   * @param  file: pointer to the source file name
  811.   * @param  line: assert_param error line source number
  812.   * @retval None
  813.   */
  814. void assert_failed(uint8_t *file, uint32_t line)
  815. {
  816.   /* USER CODE BEGIN 6 */
  817.   /* User can add his own implementation to report the file name and line number,
  818.      tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  819.   /* USER CODE END 6 */
  820. }
  821. #endif /* USE_FULL_ASSERT */
  822.  
  823. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top