/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * *

© Copyright (c) 2021 STMicroelectronics. * All rights reserved.

* * This software component is licensed by ST under Ultimate Liberty license * SLA0044, the "License"; You may not use this file except in compliance with * the License. You may obtain a copy of the License at: * www.st.com/SLA0044 * * * Bonjour ! J'aime beaucoup l'informatique industrielle * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "cmsis_os.h" #include "lwip.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "stm32746g_discovery_lcd.h" #include "stm32746g_discovery_ts.h" #include "stdio.h" #include "semphr.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ ADC_HandleTypeDef hadc1; ADC_HandleTypeDef hadc3; CRC_HandleTypeDef hcrc; DAC_HandleTypeDef hdac; DMA2D_HandleTypeDef hdma2d; LTDC_HandleTypeDef hltdc; RNG_HandleTypeDef hrng; SPI_HandleTypeDef hspi2; TIM_HandleTypeDef htim1; TIM_HandleTypeDef htim2; TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim5; TIM_HandleTypeDef htim8; SDRAM_HandleTypeDef hsdram1; osThreadId GameMasterHandle; osThreadId Joueur_1Handle; osThreadId Block_EnemieHandle; osThreadId ProjectileHandle; osThreadId IRQ_BPHandle; osThreadId tir_joueurHandle; osMessageQId Queue_JHandle; osMessageQId Queue_NHandle; osMessageQId Queue_FHandle; osMessageQId Queue_EHandle; /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_ADC3_Init(void); static void MX_LTDC_Init(void); static void MX_SPI2_Init(void); static void MX_TIM1_Init(void); static void MX_TIM2_Init(void); static void MX_TIM3_Init(void); static void MX_TIM5_Init(void); static void MX_TIM8_Init(void); static void MX_ADC1_Init(void); static void MX_DAC_Init(void); static void MX_FMC_Init(void); static void MX_DMA2D_Init(void); static void MX_CRC_Init(void); static void MX_RNG_Init(void); void f_GameMaster(void const * argument); void f_Joueur_1(void const * argument); void f_block_enemie(void const * argument); void f_projectile(void const * argument); void f_IRQ_BP(void const * argument); void f_tir_joueur(void const * argument); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* The semaphore used to synchronise the button push task with the interrupt. */ static xSemaphoreHandle xButtonSemaphore; #define butDEBOUNCE_DELAY 2000 struct Missile { uint16_t x; uint16_t y; uint8_t dx; uint8_t dy; uint8_t equipe; uint32_t color; uint8_t damage; uint8_t valide; }; struct Joueur { // uint32_t et pas 16 car fonction d'affichage bitmap (j'en sais pas plus) uint32_t x; uint32_t y; uint8_t dx; uint8_t dy; uint8_t health; struct Missile missile; }; struct Monster { uint32_t x; uint32_t y; uint8_t pbmp; struct Missile missile; uint8_t type; uint8_t health; }; // Définition des paramètres du joueurs struct Joueur joueur = {10, 10, 1, 1, 3}; uint8_t LED = 1; uint32_t LCD_COLOR_BACKGROUND = LCD_COLOR_BLACK; // Number of waves of enemies before the game is won. uint8_t waves_left = 10; // La limite au dela de laquelle les ennemis ne peuvent pas être (utilisé pour uint32_t Limit_ennemis_x = 50; /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ char text[50] = {}; static TS_StateTypeDef TS_State; ADC_ChannelConfTypeDef sConfig = {0}; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; /* 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_ADC3_Init(); MX_LTDC_Init(); MX_SPI2_Init(); MX_TIM1_Init(); MX_TIM2_Init(); MX_TIM3_Init(); MX_TIM5_Init(); MX_TIM8_Init(); MX_ADC1_Init(); MX_DAC_Init(); MX_FMC_Init(); MX_DMA2D_Init(); MX_CRC_Init(); MX_RNG_Init(); /* USER CODE BEGIN 2 */ BSP_LCD_Init(); BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS); BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS + BSP_LCD_GetXSize() * BSP_LCD_GetYSize() * 4); BSP_LCD_DisplayOn(); BSP_LCD_SelectLayer(1); BSP_LCD_Clear(LCD_COLOR_BLACK); BSP_LCD_SetFont(&Font12); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_SetBackColor(LCD_COLOR_BLACK); BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); /* USER CODE END 2 */ /* USER CODE BEGIN RTOS_MUTEX */ /* add mutexes, ... */ /* USER CODE END RTOS_MUTEX */ /* USER CODE BEGIN RTOS_SEMAPHORES */ /* add semaphores, ... */ /* USER CODE END RTOS_SEMAPHORES */ /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ /* USER CODE END RTOS_TIMERS */ /* Create the queue(s) */ /* definition and creation of Queue_J */ osMessageQDef(Queue_J, 16, uint16_t); Queue_JHandle = osMessageCreate(osMessageQ(Queue_J), NULL); /* definition and creation of Queue_N */ osMessageQDef(Queue_N, 16, uint16_t); Queue_NHandle = osMessageCreate(osMessageQ(Queue_N), NULL); /* definition and creation of Queue_F */ osMessageQDef(Queue_F, 16, uint16_t); Queue_FHandle = osMessageCreate(osMessageQ(Queue_F), NULL); /* definition and creation of Queue_E */ osMessageQDef(Queue_E, 16, uint16_t); Queue_EHandle = osMessageCreate(osMessageQ(Queue_E), NULL); /* USER CODE BEGIN RTOS_QUEUES */ /* add queues, ... */ /* USER CODE END RTOS_QUEUES */ /* Create the thread(s) */ /* definition and creation of GameMaster */ osThreadDef(GameMaster, f_GameMaster, osPriorityNormal, 0, 128); GameMasterHandle = osThreadCreate(osThread(GameMaster), NULL); /* definition and creation of Joueur_1 */ osThreadDef(Joueur_1, f_Joueur_1, osPriorityNormal, 0, 128); Joueur_1Handle = osThreadCreate(osThread(Joueur_1), NULL); /* definition and creation of Block_Enemie */ osThreadDef(Block_Enemie, f_block_enemie, osPriorityIdle, 0, 128); Block_EnemieHandle = osThreadCreate(osThread(Block_Enemie), NULL); /* definition and creation of Projectile */ osThreadDef(Projectile, f_projectile, osPriorityNormal, 0, 128); ProjectileHandle = osThreadCreate(osThread(Projectile), NULL); /* definition and creation of IRQ_BP */ osThreadDef(IRQ_BP, f_IRQ_BP, osPriorityHigh, 0, 128); IRQ_BPHandle = osThreadCreate(osThread(IRQ_BP), NULL); /* definition and creation of tir_joueur */ osThreadDef(tir_joueur, f_tir_joueur, osPriorityNormal, 0, 128); tir_joueurHandle = osThreadCreate(osThread(tir_joueur), NULL); /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ /* USER CODE END RTOS_THREADS */ /* Start scheduler */ osKernelStart(); /* We should never get here as control is now taken by the scheduler */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* Code de base */ HAL_GPIO_WritePin(LED13_GPIO_Port, LED13_Pin, HAL_GPIO_ReadPin(BP1_GPIO_Port, BP1_Pin)); HAL_GPIO_WritePin(LED14_GPIO_Port, LED14_Pin, HAL_GPIO_ReadPin(BP2_GPIO_Port, BP2_Pin)); sprintf(text, "BP1 : %d", HAL_GPIO_ReadPin(BP1_GPIO_Port, BP1_Pin)); BSP_LCD_DisplayStringAtLine(5, (uint8_t *)text); ; sConfig.Channel = ADC_CHANNEL_7; HAL_ADC_ConfigChannel(&hadc3, &sConfig); HAL_ADC_Start(&hadc3); sConfig.Channel = ADC_CHANNEL_6; HAL_ADC_ConfigChannel(&hadc3, &sConfig); HAL_ADC_Start(&hadc3); sConfig.Channel = ADC_CHANNEL_8; HAL_ADC_ConfigChannel(&hadc3, &sConfig); HAL_ADC_Start(&hadc3); HAL_ADC_Start(&hadc1); BSP_TS_GetState(&TS_State); if (TS_State.touchDetected) { BSP_LCD_FillCircle(TS_State.touchX[0], TS_State.touchY[0], 4); } /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; /** Configure LSE Drive Capability */ HAL_PWR_EnableBkUpAccess(); /** Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 400; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 9; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Activate the Over-Drive mode */ if (HAL_PWREx_EnableOverDrive() != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6) != HAL_OK) { Error_Handler(); } PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC|RCC_PERIPHCLK_CLK48; PeriphClkInitStruct.PLLSAI.PLLSAIN = 384; PeriphClkInitStruct.PLLSAI.PLLSAIR = 5; PeriphClkInitStruct.PLLSAI.PLLSAIQ = 2; PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV8; PeriphClkInitStruct.PLLSAIDivQ = 1; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8; PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLLSAIP; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) { Error_Handler(); } } /** * @brief ADC1 Initialization Function * @param None * @retval None */ static void MX_ADC1_Init(void) { /* USER CODE BEGIN ADC1_Init 0 */ /* USER CODE END ADC1_Init 0 */ ADC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN ADC1_Init 1 */ /* USER CODE END ADC1_Init 1 */ /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; hadc1.Init.Resolution = ADC_RESOLUTION_12B; hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; hadc1.Init.ContinuousConvMode = DISABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 1; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; if (HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); } /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_0; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN ADC1_Init 2 */ /* USER CODE END ADC1_Init 2 */ } /** * @brief ADC3 Initialization Function * @param None * @retval None */ static void MX_ADC3_Init(void) { /* USER CODE BEGIN ADC3_Init 0 */ /* USER CODE END ADC3_Init 0 */ ADC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN ADC3_Init 1 */ /* USER CODE END ADC3_Init 1 */ /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc3.Instance = ADC3; hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; hadc3.Init.Resolution = ADC_RESOLUTION_12B; hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE; hadc3.Init.ContinuousConvMode = DISABLE; hadc3.Init.DiscontinuousConvMode = DISABLE; hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc3.Init.NbrOfConversion = 1; hadc3.Init.DMAContinuousRequests = DISABLE; hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV; if (HAL_ADC_Init(&hadc3) != HAL_OK) { Error_Handler(); } /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_8; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN ADC3_Init 2 */ /* USER CODE END ADC3_Init 2 */ } /** * @brief CRC Initialization Function * @param None * @retval None */ static void MX_CRC_Init(void) { /* USER CODE BEGIN CRC_Init 0 */ /* USER CODE END CRC_Init 0 */ /* USER CODE BEGIN CRC_Init 1 */ /* USER CODE END CRC_Init 1 */ hcrc.Instance = CRC; hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; if (HAL_CRC_Init(&hcrc) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN CRC_Init 2 */ /* USER CODE END CRC_Init 2 */ } /** * @brief DAC Initialization Function * @param None * @retval None */ static void MX_DAC_Init(void) { /* USER CODE BEGIN DAC_Init 0 */ /* USER CODE END DAC_Init 0 */ DAC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN DAC_Init 1 */ /* USER CODE END DAC_Init 1 */ /** DAC Initialization */ hdac.Instance = DAC; if (HAL_DAC_Init(&hdac) != HAL_OK) { Error_Handler(); } /** DAC channel OUT1 config */ sConfig.DAC_Trigger = DAC_TRIGGER_NONE; sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE; if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN DAC_Init 2 */ /* USER CODE END DAC_Init 2 */ } /** * @brief DMA2D Initialization Function * @param None * @retval None */ static void MX_DMA2D_Init(void) { /* USER CODE BEGIN DMA2D_Init 0 */ /* USER CODE END DMA2D_Init 0 */ /* USER CODE BEGIN DMA2D_Init 1 */ /* USER CODE END DMA2D_Init 1 */ hdma2d.Instance = DMA2D; hdma2d.Init.Mode = DMA2D_M2M; hdma2d.Init.ColorMode = DMA2D_OUTPUT_ARGB8888; hdma2d.Init.OutputOffset = 0; hdma2d.LayerCfg[1].InputOffset = 0; hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_ARGB8888; hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; hdma2d.LayerCfg[1].InputAlpha = 0; if (HAL_DMA2D_Init(&hdma2d) != HAL_OK) { Error_Handler(); } if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN DMA2D_Init 2 */ /* USER CODE END DMA2D_Init 2 */ } /** * @brief LTDC Initialization Function * @param None * @retval None */ static void MX_LTDC_Init(void) { /* USER CODE BEGIN LTDC_Init 0 */ /* USER CODE END LTDC_Init 0 */ LTDC_LayerCfgTypeDef pLayerCfg = {0}; /* USER CODE BEGIN LTDC_Init 1 */ /* USER CODE END LTDC_Init 1 */ hltdc.Instance = LTDC; hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL; hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL; hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL; hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC; hltdc.Init.HorizontalSync = 40; hltdc.Init.VerticalSync = 9; hltdc.Init.AccumulatedHBP = 53; hltdc.Init.AccumulatedVBP = 11; hltdc.Init.AccumulatedActiveW = 533; hltdc.Init.AccumulatedActiveH = 283; hltdc.Init.TotalWidth = 565; hltdc.Init.TotalHeigh = 285; hltdc.Init.Backcolor.Blue = 0; hltdc.Init.Backcolor.Green = 0; hltdc.Init.Backcolor.Red = 0; if (HAL_LTDC_Init(&hltdc) != HAL_OK) { Error_Handler(); } pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = 480; pLayerCfg.WindowY0 = 0; pLayerCfg.WindowY1 = 272; pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; pLayerCfg.Alpha = 255; pLayerCfg.Alpha0 = 0; pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; pLayerCfg.FBStartAdress = 0xC0000000; pLayerCfg.ImageWidth = 480; pLayerCfg.ImageHeight = 272; pLayerCfg.Backcolor.Blue = 0; pLayerCfg.Backcolor.Green = 0; pLayerCfg.Backcolor.Red = 0; if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN LTDC_Init 2 */ /* USER CODE END LTDC_Init 2 */ } /** * @brief RNG Initialization Function * @param None * @retval None */ static void MX_RNG_Init(void) { /* USER CODE BEGIN RNG_Init 0 */ /* USER CODE END RNG_Init 0 */ /* USER CODE BEGIN RNG_Init 1 */ /* USER CODE END RNG_Init 1 */ hrng.Instance = RNG; if (HAL_RNG_Init(&hrng) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN RNG_Init 2 */ /* USER CODE END RNG_Init 2 */ } /** * @brief SPI2 Initialization Function * @param None * @retval None */ static void MX_SPI2_Init(void) { /* USER CODE BEGIN SPI2_Init 0 */ /* USER CODE END SPI2_Init 0 */ /* USER CODE BEGIN SPI2_Init 1 */ /* USER CODE END SPI2_Init 1 */ /* SPI2 parameter configuration*/ hspi2.Instance = SPI2; hspi2.Init.Mode = SPI_MODE_MASTER; hspi2.Init.Direction = SPI_DIRECTION_2LINES; hspi2.Init.DataSize = SPI_DATASIZE_4BIT; hspi2.Init.CLKPolarity = SPI_POLARITY_LOW; hspi2.Init.CLKPhase = SPI_PHASE_1EDGE; hspi2.Init.NSS = SPI_NSS_HARD_OUTPUT; hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi2.Init.TIMode = SPI_TIMODE_DISABLE; hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi2.Init.CRCPolynomial = 7; hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE; if (HAL_SPI_Init(&hspi2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN SPI2_Init 2 */ /* USER CODE END SPI2_Init 2 */ } /** * @brief TIM1 Initialization Function * @param None * @retval None */ static void MX_TIM1_Init(void) { /* USER CODE BEGIN TIM1_Init 0 */ /* USER CODE END TIM1_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; /* USER CODE BEGIN TIM1_Init 1 */ /* USER CODE END TIM1_Init 1 */ htim1.Instance = TIM1; htim1.Init.Prescaler = 0; htim1.Init.CounterMode = TIM_COUNTERMODE_UP; htim1.Init.Period = 65535; htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim1.Init.RepetitionCounter = 0; htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim1) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM1_Init 2 */ /* USER CODE END TIM1_Init 2 */ } /** * @brief TIM2 Initialization Function * @param None * @retval None */ static void MX_TIM2_Init(void) { /* USER CODE BEGIN TIM2_Init 0 */ /* USER CODE END TIM2_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; /* USER CODE BEGIN TIM2_Init 1 */ /* USER CODE END TIM2_Init 1 */ htim2.Instance = TIM2; htim2.Init.Prescaler = 0; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 4294967295; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM2_Init 2 */ /* USER CODE END TIM2_Init 2 */ } /** * @brief TIM3 Initialization Function * @param None * @retval None */ static void MX_TIM3_Init(void) { /* USER CODE BEGIN TIM3_Init 0 */ /* USER CODE END TIM3_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_SlaveConfigTypeDef sSlaveConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; /* USER CODE BEGIN TIM3_Init 1 */ /* USER CODE END TIM3_Init 1 */ htim3.Instance = TIM3; htim3.Init.Prescaler = 0; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 65535; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim3) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_Init(&htim3) != HAL_OK) { Error_Handler(); } sSlaveConfig.SlaveMode = TIM_SLAVEMODE_DISABLE; sSlaveConfig.InputTrigger = TIM_TS_ITR0; if (HAL_TIM_SlaveConfigSynchro(&htim3, &sSlaveConfig) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) { Error_Handler(); } sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM3_Init 2 */ /* USER CODE END TIM3_Init 2 */ HAL_TIM_MspPostInit(&htim3); } /** * @brief TIM5 Initialization Function * @param None * @retval None */ static void MX_TIM5_Init(void) { /* USER CODE BEGIN TIM5_Init 0 */ /* USER CODE END TIM5_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; /* USER CODE BEGIN TIM5_Init 1 */ /* USER CODE END TIM5_Init 1 */ htim5.Instance = TIM5; htim5.Init.Prescaler = 0; htim5.Init.CounterMode = TIM_COUNTERMODE_UP; htim5.Init.Period = 4294967295; htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim5) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM5_Init 2 */ /* USER CODE END TIM5_Init 2 */ } /** * @brief TIM8 Initialization Function * @param None * @retval None */ static void MX_TIM8_Init(void) { /* USER CODE BEGIN TIM8_Init 0 */ /* USER CODE END TIM8_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; TIM_OC_InitTypeDef sConfigOC = {0}; TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; /* USER CODE BEGIN TIM8_Init 1 */ /* USER CODE END TIM8_Init 1 */ htim8.Instance = TIM8; htim8.Init.Prescaler = 0; htim8.Init.CounterMode = TIM_COUNTERMODE_UP; htim8.Init.Period = 65535; htim8.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim8.Init.RepetitionCounter = 0; htim8.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim8) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim8, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } if (HAL_TIM_PWM_Init(&htim8) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim8, &sMasterConfig) != HAL_OK) { Error_Handler(); } sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 0; sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; if (HAL_TIM_PWM_ConfigChannel(&htim8, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) { Error_Handler(); } sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; sBreakDeadTimeConfig.DeadTime = 0; sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; sBreakDeadTimeConfig.BreakFilter = 0; sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE; sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH; sBreakDeadTimeConfig.Break2Filter = 0; sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; if (HAL_TIMEx_ConfigBreakDeadTime(&htim8, &sBreakDeadTimeConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM8_Init 2 */ /* USER CODE END TIM8_Init 2 */ HAL_TIM_MspPostInit(&htim8); } /* FMC initialization function */ static void MX_FMC_Init(void) { /* USER CODE BEGIN FMC_Init 0 */ /* USER CODE END FMC_Init 0 */ FMC_SDRAM_TimingTypeDef SdramTiming = {0}; /* USER CODE BEGIN FMC_Init 1 */ /* USER CODE END FMC_Init 1 */ /** Perform the SDRAM1 memory initialization sequence */ hsdram1.Instance = FMC_SDRAM_DEVICE; /* hsdram1.Init */ hsdram1.Init.SDBank = FMC_SDRAM_BANK1; hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8; hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12; hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_16; hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4; hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_1; hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE; hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_DISABLE; hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_DISABLE; hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0; /* SdramTiming */ SdramTiming.LoadToActiveDelay = 16; SdramTiming.ExitSelfRefreshDelay = 16; SdramTiming.SelfRefreshTime = 16; SdramTiming.RowCycleDelay = 16; SdramTiming.WriteRecoveryTime = 16; SdramTiming.RPDelay = 16; SdramTiming.RCDDelay = 16; if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK) { Error_Handler( ); } /* USER CODE BEGIN FMC_Init 2 */ /* USER CODE END FMC_Init 2 */ } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOJ_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOI_CLK_ENABLE(); __HAL_RCC_GPIOK_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOE, LED14_Pin|LED15_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(OTG_FS_PowerSwitchOn_GPIO_Port, OTG_FS_PowerSwitchOn_Pin, GPIO_PIN_SET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LED16_GPIO_Port, LED16_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_Port, LCD_BL_CTRL_Pin, GPIO_PIN_SET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LCD_DISP_GPIO_Port, LCD_DISP_Pin, GPIO_PIN_SET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOH, LED13_Pin|LED17_Pin|LED11_Pin|LED12_Pin |LED2_Pin|LED18_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(EXT_RST_GPIO_Port, EXT_RST_Pin, GPIO_PIN_RESET); /*Configure GPIO pin : PE3 */ GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); /*Configure GPIO pins : ARDUINO_SCL_D15_Pin ARDUINO_SDA_D14_Pin */ GPIO_InitStruct.Pin = ARDUINO_SCL_D15_Pin|ARDUINO_SDA_D14_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*Configure GPIO pins : ULPI_D7_Pin ULPI_D6_Pin ULPI_D5_Pin ULPI_D2_Pin ULPI_D1_Pin ULPI_D4_Pin */ GPIO_InitStruct.Pin = ULPI_D7_Pin|ULPI_D6_Pin|ULPI_D5_Pin|ULPI_D2_Pin |ULPI_D1_Pin|ULPI_D4_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*Configure GPIO pins : BP2_Pin BP1_Pin */ GPIO_InitStruct.Pin = BP2_Pin|BP1_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /*Configure GPIO pins : LED14_Pin LED15_Pin */ GPIO_InitStruct.Pin = LED14_Pin|LED15_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); /*Configure GPIO pin : VCP_RX_Pin */ GPIO_InitStruct.Pin = VCP_RX_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF7_USART1; HAL_GPIO_Init(VCP_RX_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : OTG_FS_VBUS_Pin */ GPIO_InitStruct.Pin = OTG_FS_VBUS_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(OTG_FS_VBUS_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : Audio_INT_Pin */ GPIO_InitStruct.Pin = Audio_INT_Pin; GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(Audio_INT_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : OTG_FS_PowerSwitchOn_Pin LED16_Pin */ GPIO_InitStruct.Pin = OTG_FS_PowerSwitchOn_Pin|LED16_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /*Configure GPIO pins : LED3_Pin LCD_DISP_Pin */ GPIO_InitStruct.Pin = LED3_Pin|LCD_DISP_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); /*Configure GPIO pin : uSD_Detect_Pin */ GPIO_InitStruct.Pin = uSD_Detect_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(uSD_Detect_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : LCD_BL_CTRL_Pin */ GPIO_InitStruct.Pin = LCD_BL_CTRL_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(LCD_BL_CTRL_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : OTG_FS_OverCurrent_Pin */ GPIO_InitStruct.Pin = OTG_FS_OverCurrent_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(OTG_FS_OverCurrent_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : TP3_Pin NC2_Pin */ GPIO_InitStruct.Pin = TP3_Pin|NC2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); /*Configure GPIO pins : LED13_Pin LED17_Pin LED11_Pin LED12_Pin LED2_Pin LED18_Pin */ GPIO_InitStruct.Pin = LED13_Pin|LED17_Pin|LED11_Pin|LED12_Pin |LED2_Pin|LED18_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); /*Configure GPIO pin : VCP_TX_Pin */ GPIO_InitStruct.Pin = VCP_TX_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF7_USART1; HAL_GPIO_Init(VCP_TX_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : LCD_INT_Pin */ GPIO_InitStruct.Pin = LCD_INT_Pin; GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(LCD_INT_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : PC7 PC6 */ GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF8_USART6; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /*Configure GPIO pin : ULPI_NXT_Pin */ GPIO_InitStruct.Pin = ULPI_NXT_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(ULPI_NXT_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : BP_JOYSTICK_Pin RMII_RXER_Pin */ GPIO_InitStruct.Pin = BP_JOYSTICK_Pin|RMII_RXER_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); /*Configure GPIO pin : PF7 */ GPIO_InitStruct.Pin = GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF8_UART7; HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); /*Configure GPIO pins : ULPI_STP_Pin ULPI_DIR_Pin */ GPIO_InitStruct.Pin = ULPI_STP_Pin|ULPI_DIR_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /*Configure GPIO pin : EXT_RST_Pin */ GPIO_InitStruct.Pin = EXT_RST_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(EXT_RST_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : LCD_SCL_Pin LCD_SDA_Pin */ GPIO_InitStruct.Pin = LCD_SCL_Pin|LCD_SDA_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF4_I2C3; HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); /*Configure GPIO pins : ULPI_CLK_Pin ULPI_D0_Pin */ GPIO_InitStruct.Pin = ULPI_CLK_Pin|ULPI_D0_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /* USER CODE BEGIN Header_f_GameMaster */ /** * @brief Function implementing the GameMaster thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_f_GameMaster */ void f_GameMaster(void const * argument) { /* init code for LWIP */ MX_LWIP_Init(); /* USER CODE BEGIN 5 */ TickType_t xLastWakeTime; const TickType_t xPeriodeTache = 10; // Si la variable end est à 1, le jeu s'arrete. uint8_t end = 0; /* Infinite loop */ for (;;) { xQueueReceive(Queue_FHandle, &end, 0); if (end == 1){ vTaskDelete(Block_EnemieHandle); vTaskDelete(ProjectileHandle); vTaskDelete(Joueur_1Handle); //TODO L'affichage de l'écran de fin et des scores } if (end == 0){ if (waves_left == 0){ vTaskDelete(Block_EnemieHandle); vTaskDelete(ProjectileHandle); vTaskDelete(Joueur_1Handle); //TODO L'affichage de l'écran de fin et des scores } } vTaskDelayUntil(&xLastWakeTime, xPeriodeTache); } /* USER CODE END 5 */ } /* USER CODE BEGIN Header_f_Joueur_1 */ /** * @brief Function implementing the Joueur_1 thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_f_Joueur_1 */ void f_Joueur_1(void const * argument) { /* USER CODE BEGIN f_Joueur_1 */ TickType_t xLastWakeTime; const TickType_t xPeriodeTache = 10; uint16_t Width = 20; uint16_t Height = 20; uint32_t joystick_h, joystick_v; uint8_t stop = 1; struct Missile missile; ADC_ChannelConfTypeDef sConfig3 = {0}; sConfig3.Rank = ADC_REGULAR_RANK_1; sConfig3.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig3.Channel = ADC_CHANNEL_8; HAL_ADC_ConfigChannel(&hadc3, &sConfig3); HAL_ADC_Start(&hadc3); ADC_ChannelConfTypeDef sConfig1 = {0}; sConfig1.Rank = ADC_REGULAR_RANK_1; sConfig1.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig1.Channel = ADC_CHANNEL_0; HAL_ADC_ConfigChannel(&hadc1, &sConfig1); HAL_ADC_Start(&hadc1); // Paramètre de l'écran pour la reprouductibilité uint32_t LCD_HEIGHT = BSP_LCD_GetXSize(); uint32_t LCD_WIDTH = BSP_LCD_GetYSize(); /* Infinite loop */ for (;;) { BSP_LCD_SetTextColor(LCD_COLOR_BACKGROUND); BSP_LCD_FillRect(joueur.x, joueur.y, Width, Height); // BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp) HAL_ADC_ConfigChannel(&hadc3, &sConfig3); HAL_ADC_Start(&hadc3); while (HAL_ADC_PollForConversion(&hadc3, 100) != HAL_OK); joystick_h = HAL_ADC_GetValue(&hadc3); HAL_ADC_ConfigChannel(&hadc1, &sConfig1); HAL_ADC_Start(&hadc1); while (HAL_ADC_PollForConversion(&hadc1, 100) != HAL_OK); joystick_v = HAL_ADC_GetValue(&hadc1); if ((joueur.y < LCD_WIDTH- Width - joueur.dy)&&(joystick_h < 1900)) joueur.y += joueur.dy; if ((joueur.y > joueur.dy)&&(joystick_h > 2100)) joueur.y -= joueur.dy; if ((joueur.x < LCD_HEIGHT - Height - joueur.dx)&&(joystick_v < 1900)) joueur.x += joueur.dx; if ((joueur.x > joueur.dx)&&(joystick_v > 2100)) joueur.x -= joueur.dx; BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(joueur.x, joueur.y, Width, Height); if (xQueueReceive(Queue_JHandle, &missile, 0) == pdPASS) joueur.health = joueur.health - missile.damage; // On envoie 1 si le joueur est mort et on envoie 0 si les enemis sont tous morts if (joueur.health == 0)xQueueSend(Queue_FHandle,&stop,0); // TODO La condition sur une entrée analogique pour envoyer un missile // struct Missile missile = {joueur.x, joueur.y,joueur.missile.dx, joueur.missile.dy, 1, joueur.missile.color, joueur.missile.damage}; // xQueueSend(Queue_NHandle,&missile,0); vTaskDelayUntil(&xLastWakeTime, xPeriodeTache); } /* USER CODE END f_Joueur_1 */ } /* USER CODE BEGIN Header_f_block_enemie */ /** * @brief Function implementing the Block_Enemie thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_f_block_enemie */ void f_block_enemie(void const * argument) { /* USER CODE BEGIN f_block_enemie */ TickType_t xLastWakeTime; const TickType_t xPeriodeTache = 10; uint8_t number_monsters = 30; struct Monster list_monsters[30]; uint8_t end = 0; uint8_t deplacement = 1; struct Missile missile; /* Infinite loop */ for (;;) { xQueueReceive(Queue_EHandle, &missile, 0); if (number_monsters == 0){ xQueueSend(Queue_FHandle, &end, 0); } for (int i=0;i< number_monsters;i++){ if (list_monsters[i].health > 0 ){ if ((missile.x == list_monsters[i].x)&&(missile.y == list_monsters[i].y)) { list_monsters[i].health = list_monsters[i].health -1; // Est ce que cette ligne va marcher sachant que je transmets l'adresse dans la queue ? missile.valide = 0; if (list_monsters[i].health == 0){ //TODO explosion du plaisir ? number_monsters = number_monsters -1; } } BSP_LCD_DrawBitmap(list_monsters[i].x, list_monsters[i].y, &list_monsters[i].pbmp); // On alterne le deplacement des méchants comme dans le vrai jeux //TODO est ce que ca va posé un décalage entre l'affichage et la hitboxe ? list_monsters[i].x = list_monsters[i].x + deplacement*2; } } deplacement = -1; vTaskDelayUntil(&xLastWakeTime, xPeriodeTache); } /* USER CODE END f_block_enemie */ } /* USER CODE BEGIN Header_f_projectile */ /** * @brief Function implementing the Projectile thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_f_projectile */ void f_projectile(void const * argument) { /* USER CODE BEGIN f_projectile */ TickType_t xLastWakeTime; const TickType_t xPeriodeTache = 5000; /* Infinite loop */ struct Missile liste_missile[20]; struct Missile missile = {70, 70, 1, 0, 0, LCD_COLOR_WHITE, 1,1}; uint8_t indice = 1; liste_missile[0] = missile; // Paramètre de l'écran pour la reprouductibilité uint32_t LCD_HEIGHT = BSP_LCD_GetXSize(); uint32_t LCD_WIDTH = BSP_LCD_GetYSize(); for (;;) { //xQueueReceive(Queue_NHandle, &missile, 0); //liste_missile[indice++] = missile; for (int i=0;i< indice;i++) { // Si le missile n'est pas sur un bord if (liste_missile[i].valide == 1) { // Si le missile appartient au joueur : if (liste_missile[i].equipe == 0) { if (liste_missile[i].x >= Limit_ennemis_x) { xQueueSend(Queue_EHandle, &liste_missile+indice,0); // TODO Une petite animation d'explosion ? } if ((liste_missile[i].x > 1)&&(liste_missile[i].x < LCD_HEIGHT-1)&&(liste_missile[i].y < LCD_WIDTH-1)&&(liste_missile[i].y > 1)) { BSP_LCD_DrawPixel(liste_missile[i].x, liste_missile[i].y, LCD_COLOR_BACKGROUND); liste_missile[i].x = liste_missile[i].x + liste_missile[i].dx ; liste_missile[i].y = liste_missile[i].y + liste_missile[i].dy; BSP_LCD_DrawPixel(liste_missile[i].x, liste_missile[i].y, liste_missile[i].color); } //TODO test sur tous les ennemis else { liste_missile[i].valide = 0; BSP_LCD_DrawPixel(liste_missile[i].x, liste_missile[i].y, LCD_COLOR_BACKGROUND); } } // Si le missile appartient aux ennemis else if (liste_missile[i].equipe == 1) { if ((liste_missile[i].x == joueur.x)&&(liste_missile[i].y == joueur.y)) { xQueueSend(Queue_JHandle, &liste_missile+indice,0); liste_missile[i].valide = 0; // TODO Une petite animation d'explosion ? } if ((liste_missile[i].x > 1)&&(liste_missile[i].x < LCD_HEIGHT-1)&&(liste_missile[i].y < LCD_WIDTH-1)&&(liste_missile[i].y > 1)) { BSP_LCD_DrawPixel(liste_missile[i].x, liste_missile[i].y, LCD_COLOR_BACKGROUND); liste_missile[i].x = liste_missile[i].x + liste_missile[i].dx ; liste_missile[i].y = liste_missile[i].y + liste_missile[i].dy; BSP_LCD_DrawPixel(liste_missile[i].x, liste_missile[i].y, liste_missile[i].color); } else { liste_missile[i].valide = 0; BSP_LCD_DrawPixel(liste_missile[i].x, liste_missile[i].y, LCD_COLOR_BACKGROUND); } } } } vTaskDelayUntil(&xLastWakeTime, xPeriodeTache); } /* USER CODE END f_projectile */ } /* USER CODE BEGIN Header_f_IRQ_BP */ /** * @brief Function implementing the IRQ_BP thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_f_IRQ_BP */ void f_IRQ_BP(void const * argument) { /* USER CODE BEGIN f_IRQ_BP */ // Jsp pk long mais ca ne renvoie pas d'erreur. C'était initialement short sur google long sHigherPriorityTaskWoken = pdFALSE; /* 'Give' the semaphore to unblock the button task. */ xSemaphoreGiveFromISR( xButtonSemaphore, &sHigherPriorityTaskWoken ); /* If giving the semaphore unblocked a task, and the unblocked task has a priority that is higher than the currently running task, then sHigherPriorityTaskWoken will have been set to pdTRUE. Passing a pdTRUE value to portYIELD_FROM_ISR() will cause this interrupt to return directly to the higher priority unblocked task. */ portYIELD_FROM_ISR( sHigherPriorityTaskWoken ); /* USER CODE END f_IRQ_BP */ } /* USER CODE BEGIN Header_f_tir_joueur */ /** * @brief Function implementing the tir_joueur thread. * @param argument: Not used * @retval None */ /* USER CODE END Header_f_tir_joueur */ void f_tir_joueur(void const * argument) { /* USER CODE BEGIN f_tir_joueur */ /* Ensure the semaphore is created before it gets used. */ vSemaphoreCreateBinary( xButtonSemaphore ); /* Infinite loop */ for(;;) { /* Block on the semaphore to wait for an interrupt event. The semaphore is 'given' from f_IRQ_BP() below. Using portMAX_DELAY as the block time will cause the task to block indefinitely provided INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. */ xSemaphoreTake( xButtonSemaphore, portMAX_DELAY ); /* The button must have been pushed for this line to be executed. Simply toggle the LED. */ HAL_GPIO_WritePin(LED14_GPIO_Port, LED14_Pin,!LED); /* Wait a short time then clear any pending button pushes as a crude method of debouncing the switch. xSemaphoreTake() uses a block time of zero this time so it returns immediately rather than waiting for the interrupt to occur. */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(50, 50, 40, 40); vTaskDelay( butDEBOUNCE_DELAY ); xSemaphoreTake( xButtonSemaphore, 0 ); } /* USER CODE END f_tir_joueur */ } /** * @brief Period elapsed callback in non blocking mode * @note This function is called when TIM6 interrupt took place, inside * HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment * a global variable "uwTick" used as application time base. * @param htim : TIM handle * @retval None */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { /* USER CODE BEGIN Callback 0 */ /* USER CODE END Callback 0 */ if (htim->Instance == TIM6) { HAL_IncTick(); } /* USER CODE BEGIN Callback 1 */ /* USER CODE END Callback 1 */ } /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* 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) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/