ili931_touch.c
This commit is contained in:
parent
862fc8da97
commit
de2abc2cc7
199
Core/Src/main.c
199
Core/Src/main.c
@ -26,7 +26,8 @@
|
|||||||
//#include "ili9341_touch.h"
|
//#include "ili9341_touch.h"
|
||||||
#include "ILI9341_STM32_Driver.h"
|
#include "ILI9341_STM32_Driver.h"
|
||||||
#include "ILI9341_GFX.h"
|
#include "ILI9341_GFX.h"
|
||||||
//#include "ili9341_touch.h"
|
#include "ili9341_touch.h"
|
||||||
|
//#include "xpt2046.h"
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
@ -61,26 +62,42 @@ UART_HandleTypeDef huart6;
|
|||||||
|
|
||||||
/* Definitions for touchhistory */
|
/* Definitions for touchhistory */
|
||||||
osThreadId_t touchhistoryHandle;
|
osThreadId_t touchhistoryHandle;
|
||||||
const osThreadAttr_t touchhistory_attributes = { .name = "touchhistory",
|
const osThreadAttr_t touchhistory_attributes = {
|
||||||
.stack_size = 128 * 4, .priority = (osPriority_t) osPriorityNormal, };
|
.name = "touchhistory",
|
||||||
|
.stack_size = 128 * 4,
|
||||||
|
.priority = (osPriority_t) osPriorityNormal,
|
||||||
|
};
|
||||||
/* Definitions for draw */
|
/* Definitions for draw */
|
||||||
osThreadId_t drawHandle;
|
osThreadId_t drawHandle;
|
||||||
const osThreadAttr_t draw_attributes = { .name = "draw", .stack_size = 1024 * 4,
|
const osThreadAttr_t draw_attributes = {
|
||||||
.priority = (osPriority_t) osPriorityLow, };
|
.name = "draw",
|
||||||
|
.stack_size = 512 * 4,
|
||||||
|
.priority = (osPriority_t) osPriorityLow,
|
||||||
|
};
|
||||||
/* Definitions for reactiongame */
|
/* Definitions for reactiongame */
|
||||||
osThreadId_t reactiongameHandle;
|
osThreadId_t reactiongameHandle;
|
||||||
const osThreadAttr_t reactiongame_attributes = { .name = "reactiongame",
|
const osThreadAttr_t reactiongame_attributes = {
|
||||||
.stack_size = 128 * 4, .priority = (osPriority_t) osPriorityLow, };
|
.name = "reactiongame",
|
||||||
|
.stack_size = 128 * 4,
|
||||||
|
.priority = (osPriority_t) osPriorityLow,
|
||||||
|
};
|
||||||
/* Definitions for gamepicker */
|
/* Definitions for gamepicker */
|
||||||
osThreadId_t gamepickerHandle;
|
osThreadId_t gamepickerHandle;
|
||||||
const osThreadAttr_t gamepicker_attributes = { .name = "gamepicker",
|
const osThreadAttr_t gamepicker_attributes = {
|
||||||
.stack_size = 128 * 4, .priority = (osPriority_t) osPriorityLow, };
|
.name = "gamepicker",
|
||||||
|
.stack_size = 128 * 4,
|
||||||
|
.priority = (osPriority_t) osPriorityLow,
|
||||||
|
};
|
||||||
/* Definitions for presses */
|
/* Definitions for presses */
|
||||||
osMessageQueueId_t pressesHandle;
|
osMessageQueueId_t pressesHandle;
|
||||||
const osMessageQueueAttr_t presses_attributes = { .name = "presses" };
|
const osMessageQueueAttr_t presses_attributes = {
|
||||||
|
.name = "presses"
|
||||||
|
};
|
||||||
/* Definitions for display */
|
/* Definitions for display */
|
||||||
osMutexId_t displayHandle;
|
osMutexId_t displayHandle;
|
||||||
const osMutexAttr_t display_attributes = { .name = "display" };
|
const osMutexAttr_t display_attributes = {
|
||||||
|
.name = "display"
|
||||||
|
};
|
||||||
/* USER CODE BEGIN PV */
|
/* USER CODE BEGIN PV */
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
@ -313,13 +330,26 @@ void UserInput() {
|
|||||||
// snake.Dir = LEFT;
|
// snake.Dir = LEFT;
|
||||||
uint16_t x, y;
|
uint16_t x, y;
|
||||||
|
|
||||||
//if (ILI9341_TouchGetCoordinates(&x, &y)) { // Only act if touch detected
|
x = getX();
|
||||||
|
y = getY();
|
||||||
|
if (x != 0 || y != 0) {
|
||||||
|
int a = x;
|
||||||
|
}
|
||||||
|
int ia = HAL_GPIO_ReadPin(ILI9341_TOUCH_IRQ_GPIO_Port,
|
||||||
|
ILI9341_TOUCH_IRQ_Pin) == GPIO_PIN_RESET;
|
||||||
|
|
||||||
|
if (ILI9341_TouchGetCoordinates(&x, &y)) { // Only act if touch detected
|
||||||
|
if ((x == 123 || x == 124 || x == 125 || x == 126) && y == 0) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
for (int i = 0; i < touchbuffersize - 1; i++) {
|
for (int i = 0; i < touchbuffersize - 1; i++) {
|
||||||
touchcoord.x[i] = touchcoord.x[i + 1];
|
touchcoord.x[i] = touchcoord.x[i + 1];
|
||||||
touchcoord.y[i] = touchcoord.y[i + 1];
|
touchcoord.y[i] = touchcoord.y[i + 1];
|
||||||
//}
|
//}
|
||||||
touchcoord.x[touchbuffersize - 1] = x;
|
touchcoord.x[touchbuffersize - 1] = x;
|
||||||
touchcoord.y[touchbuffersize - 1] = y;
|
touchcoord.y[touchbuffersize - 1] = y;
|
||||||
|
}
|
||||||
char dir;
|
char dir;
|
||||||
if (x < 107) {
|
if (x < 107) {
|
||||||
dir = 'L'; // Left
|
dir = 'L'; // Left
|
||||||
@ -335,11 +365,13 @@ void UserInput() {
|
|||||||
|
|
||||||
// Send the direction to the queue
|
// Send the direction to the queue
|
||||||
//if (!prevpressed && ILI9341_TouchPressed()) {
|
//if (!prevpressed && ILI9341_TouchPressed()) {
|
||||||
|
|
||||||
osStatus_t status = osMessageQueuePut(pressesHandle, &dir, 0, 0);
|
osStatus_t status = osMessageQueuePut(pressesHandle, &dir, 0, 0);
|
||||||
if (status != osOK) {
|
if (status != osOK) {
|
||||||
// Optional: Handle error
|
// Optional: Handle error
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
prevpressed = 1;
|
prevpressed = 1;
|
||||||
//} else {
|
//} else {
|
||||||
prevpressed = 0;
|
prevpressed = 0;
|
||||||
@ -354,7 +386,6 @@ void UserInput() {
|
|||||||
touchcoord.y[touchbuffersize - 1] = ILI9341_SCREEN_WIDTH;
|
touchcoord.y[touchbuffersize - 1] = ILI9341_SCREEN_WIDTH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Function for creating the game board & rendering
|
// Function for creating the game board & rendering
|
||||||
void GameRender() {
|
void GameRender() {
|
||||||
@ -480,7 +511,8 @@ void GameRender() {
|
|||||||
* @brief The application entry point.
|
* @brief The application entry point.
|
||||||
* @retval int
|
* @retval int
|
||||||
*/
|
*/
|
||||||
int main(void) {
|
int main(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|
||||||
@ -516,6 +548,7 @@ int main(void) {
|
|||||||
ILI9341_Init();
|
ILI9341_Init();
|
||||||
ILI9341_SetRotation(SCREEN_HORIZONTAL_1);
|
ILI9341_SetRotation(SCREEN_HORIZONTAL_1);
|
||||||
ILI9341_FillScreen(MAGENTA);
|
ILI9341_FillScreen(MAGENTA);
|
||||||
|
//void XPT2046_Init();
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
@ -539,21 +572,25 @@ int main(void) {
|
|||||||
|
|
||||||
/* Create the queue(s) */
|
/* Create the queue(s) */
|
||||||
/* creation of presses */
|
/* creation of presses */
|
||||||
//pressesHandle = osMessageQueueNew (16, sizeof(char), &presses_attributes);
|
pressesHandle = osMessageQueueNew (16, sizeof(char), &presses_attributes);
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
/* add queues, ... */
|
/* add queues, ... */
|
||||||
/* USER CODE END RTOS_QUEUES */
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
/* Create the thread(s) */
|
/* Create the thread(s) */
|
||||||
/* creation of touchhistory */
|
/* creation of touchhistory */
|
||||||
//touchhistoryHandle = osThreadNew(StartTouchHist, NULL, &touchhistory_attributes);
|
touchhistoryHandle = osThreadNew(StartTouchHist, NULL, &touchhistory_attributes);
|
||||||
|
|
||||||
/* creation of draw */
|
/* creation of draw */
|
||||||
drawHandle = osThreadNew(snakegame, NULL, &draw_attributes);
|
drawHandle = osThreadNew(snakegame, NULL, &draw_attributes);
|
||||||
|
|
||||||
/* creation of reactiongame */
|
/* creation of reactiongame */
|
||||||
//reactiongameHandle = osThreadNew(startreactiongame, NULL, &reactiongame_attributes);
|
//reactiongameHandle = osThreadNew(startreactiongame, NULL, &reactiongame_attributes);
|
||||||
|
|
||||||
/* creation of gamepicker */
|
/* creation of gamepicker */
|
||||||
//gamepickerHandle = osThreadNew(gamepicker_entry, NULL, &gamepicker_attributes);
|
//gamepickerHandle = osThreadNew(gamepicker_entry, NULL, &gamepicker_attributes);
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
/* add threads, ... */
|
/* add threads, ... */
|
||||||
|
|
||||||
@ -626,7 +663,8 @@ int main(void) {
|
|||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SystemClock_Config(void) {
|
void SystemClock_Config(void)
|
||||||
|
{
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
|
|
||||||
@ -642,7 +680,8 @@ void SystemClock_Config(void) {
|
|||||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,7 +694,8 @@ void SystemClock_Config(void) {
|
|||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) {
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -665,7 +705,8 @@ void SystemClock_Config(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_I2C1_Init(void) {
|
static void MX_I2C1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN I2C1_Init 0 */
|
/* USER CODE BEGIN I2C1_Init 0 */
|
||||||
|
|
||||||
@ -683,7 +724,8 @@ static void MX_I2C1_Init(void) {
|
|||||||
hi2c1.Init.OwnAddress2 = 0;
|
hi2c1.Init.OwnAddress2 = 0;
|
||||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK) {
|
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN I2C1_Init 2 */
|
/* USER CODE BEGIN I2C1_Init 2 */
|
||||||
@ -697,7 +739,8 @@ static void MX_I2C1_Init(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_SPI1_Init(void) {
|
static void MX_SPI1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI1_Init 0 */
|
/* USER CODE BEGIN SPI1_Init 0 */
|
||||||
|
|
||||||
@ -719,7 +762,8 @@ static void MX_SPI1_Init(void) {
|
|||||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||||
hspi1.Init.CRCPolynomial = 10;
|
hspi1.Init.CRCPolynomial = 10;
|
||||||
if (HAL_SPI_Init(&hspi1) != HAL_OK) {
|
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN SPI1_Init 2 */
|
/* USER CODE BEGIN SPI1_Init 2 */
|
||||||
@ -733,7 +777,8 @@ static void MX_SPI1_Init(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_SPI2_Init(void) {
|
static void MX_SPI2_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI2_Init 0 */
|
/* USER CODE BEGIN SPI2_Init 0 */
|
||||||
|
|
||||||
@ -750,12 +795,13 @@ static void MX_SPI2_Init(void) {
|
|||||||
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
|
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||||
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||||
hspi2.Init.NSS = SPI_NSS_SOFT;
|
hspi2.Init.NSS = SPI_NSS_SOFT;
|
||||||
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
|
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
|
||||||
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||||
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
|
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||||
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||||
hspi2.Init.CRCPolynomial = 10;
|
hspi2.Init.CRCPolynomial = 10;
|
||||||
if (HAL_SPI_Init(&hspi2) != HAL_OK) {
|
if (HAL_SPI_Init(&hspi2) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN SPI2_Init 2 */
|
/* USER CODE BEGIN SPI2_Init 2 */
|
||||||
@ -769,7 +815,8 @@ static void MX_SPI2_Init(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_TIM1_Init(void) {
|
static void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM1_Init 0 */
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
@ -797,13 +844,14 @@ static void MX_TIM1_Init(void) {
|
|||||||
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
|
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
|
||||||
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
|
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
|
||||||
sConfig.IC2Filter = 0;
|
sConfig.IC2Filter = 0;
|
||||||
if (HAL_TIM_Encoder_Init(&htim1, &sConfig) != HAL_OK) {
|
if (HAL_TIM_Encoder_Init(&htim1, &sConfig) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig)
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
!= HAL_OK) {
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN TIM1_Init 2 */
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
@ -817,7 +865,8 @@ static void MX_TIM1_Init(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_TIM4_Init(void) {
|
static void MX_TIM4_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM4_Init 0 */
|
/* USER CODE BEGIN TIM4_Init 0 */
|
||||||
|
|
||||||
@ -844,13 +893,14 @@ static void MX_TIM4_Init(void) {
|
|||||||
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
|
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
|
||||||
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
|
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
|
||||||
sConfig.IC2Filter = 0;
|
sConfig.IC2Filter = 0;
|
||||||
if (HAL_TIM_Encoder_Init(&htim4, &sConfig) != HAL_OK) {
|
if (HAL_TIM_Encoder_Init(&htim4, &sConfig) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig)
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
|
||||||
!= HAL_OK) {
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN TIM4_Init 2 */
|
/* USER CODE BEGIN TIM4_Init 2 */
|
||||||
@ -864,7 +914,8 @@ static void MX_TIM4_Init(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_TIM5_Init(void) {
|
static void MX_TIM5_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN TIM5_Init 0 */
|
/* USER CODE BEGIN TIM5_Init 0 */
|
||||||
|
|
||||||
@ -883,40 +934,43 @@ static void MX_TIM5_Init(void) {
|
|||||||
htim5.Init.Period = 4294967295;
|
htim5.Init.Period = 4294967295;
|
||||||
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
if (HAL_TIM_Base_Init(&htim5) != HAL_OK) {
|
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK) {
|
if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
if (HAL_TIM_PWM_Init(&htim5) != HAL_OK) {
|
if (HAL_TIM_PWM_Init(&htim5) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig)
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
|
||||||
!= HAL_OK) {
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||||
sConfigOC.Pulse = 0;
|
sConfigOC.Pulse = 0;
|
||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_1)
|
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||||
!= HAL_OK) {
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_2)
|
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
||||||
!= HAL_OK) {
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_3)
|
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
|
||||||
!= HAL_OK) {
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_4)
|
if (HAL_TIM_PWM_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
||||||
!= HAL_OK) {
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN TIM5_Init 2 */
|
/* USER CODE BEGIN TIM5_Init 2 */
|
||||||
@ -931,7 +985,8 @@ static void MX_TIM5_Init(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_USART6_UART_Init(void) {
|
static void MX_USART6_UART_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* USER CODE BEGIN USART6_Init 0 */
|
/* USER CODE BEGIN USART6_Init 0 */
|
||||||
|
|
||||||
@ -948,7 +1003,8 @@ static void MX_USART6_UART_Init(void) {
|
|||||||
huart6.Init.Mode = UART_MODE_TX_RX;
|
huart6.Init.Mode = UART_MODE_TX_RX;
|
||||||
huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
huart6.Init.OverSampling = UART_OVERSAMPLING_16;
|
huart6.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
if (HAL_UART_Init(&huart6) != HAL_OK) {
|
if (HAL_UART_Init(&huart6) != HAL_OK)
|
||||||
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN USART6_Init 2 */
|
/* USER CODE BEGIN USART6_Init 2 */
|
||||||
@ -960,7 +1016,8 @@ static void MX_USART6_UART_Init(void) {
|
|||||||
/**
|
/**
|
||||||
* Enable DMA controller clock
|
* Enable DMA controller clock
|
||||||
*/
|
*/
|
||||||
static void MX_DMA_Init(void) {
|
static void MX_DMA_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
/* DMA controller clock enable */
|
/* DMA controller clock enable */
|
||||||
__HAL_RCC_DMA2_CLK_ENABLE();
|
__HAL_RCC_DMA2_CLK_ENABLE();
|
||||||
@ -980,7 +1037,8 @@ static void MX_DMA_Init(void) {
|
|||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
static void MX_GPIO_Init(void) {
|
static void MX_GPIO_Init(void)
|
||||||
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||||
|
|
||||||
@ -1043,20 +1101,26 @@ static void MX_GPIO_Init(void) {
|
|||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_StartTouchHist */
|
/* USER CODE END Header_StartTouchHist */
|
||||||
void StartTouchHist(void *argument) {
|
void StartTouchHist(void *argument)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN 5 */
|
/* USER CODE BEGIN 5 */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
UserInput();
|
UserInput();
|
||||||
|
|
||||||
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
||||||
// Mutex successfully locked
|
// Mutex successfully locked
|
||||||
|
ILI9341_DrawPixel(touchcoord.x[touchbuffersize - 1],
|
||||||
|
touchcoord.y[touchbuffersize - 1], MAGENTA);
|
||||||
|
ILI9341_DrawPixel(touchcoord.x[0], touchcoord.y[0], MAGENTA);
|
||||||
//ILI9341_DrawPixel(touchcoord.x[touchbuffersize - 1],
|
//ILI9341_DrawPixel(touchcoord.x[touchbuffersize - 1],
|
||||||
// touchcoord.y[touchbuffersize - 1], ILI9341_MAGENTA);
|
// touchcoord.y[touchbuffersize - 1], ILI9341_MAGENTA);
|
||||||
// ILI9341_DrawPixel(touchcoord.x[0], touchcoord.y[0], ILI9341_WHITE);
|
// ILI9341_DrawPixel(touchcoord.x[0], touchcoord.y[0], ILI9341_WHITE);
|
||||||
osMutexRelease(displayHandle);
|
osMutexRelease(displayHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
osDelay(1);
|
osDelay(100);
|
||||||
}
|
}
|
||||||
/* USER CODE END 5 */
|
/* USER CODE END 5 */
|
||||||
}
|
}
|
||||||
@ -1068,14 +1132,15 @@ void StartTouchHist(void *argument) {
|
|||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_snakegame */
|
/* USER CODE END Header_snakegame */
|
||||||
void snakegame(void *argument) {
|
void snakegame(void *argument)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN snakegame */
|
/* USER CODE BEGIN snakegame */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
ILI9341_FillScreen(BLACK);
|
ILI9341_FillScreen(BLACK);
|
||||||
GameInit();
|
GameInit();
|
||||||
GameRender();
|
GameRender();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
//uint16_t x,y;
|
//uint16_t x,y;
|
||||||
//ILI9341_TouchGetCoordinates(&x, &y);
|
//ILI9341_TouchGetCoordinates(&x, &y);
|
||||||
GameRender();
|
GameRender();
|
||||||
@ -1086,11 +1151,6 @@ void snakegame(void *argument) {
|
|||||||
|
|
||||||
//ILI9341_FillScreen(timer%0xFFFF);
|
//ILI9341_FillScreen(timer%0xFFFF);
|
||||||
UpdateGame();
|
UpdateGame();
|
||||||
if(i==6){
|
|
||||||
int a=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,7 +1164,8 @@ void snakegame(void *argument) {
|
|||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_startreactiongame */
|
/* USER CODE END Header_startreactiongame */
|
||||||
void startreactiongame(void *argument) {
|
void startreactiongame(void *argument)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN startreactiongame */
|
/* USER CODE BEGIN startreactiongame */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
uint32_t lasttimestamp = osKernelGetTickCount();
|
uint32_t lasttimestamp = osKernelGetTickCount();
|
||||||
@ -1175,7 +1236,8 @@ void startreactiongame(void *argument) {
|
|||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header_gamepicker_entry */
|
/* USER CODE END Header_gamepicker_entry */
|
||||||
void gamepicker_entry(void *argument) {
|
void gamepicker_entry(void *argument)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN gamepicker_entry */
|
/* USER CODE BEGIN gamepicker_entry */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -1211,11 +1273,13 @@ void gamepicker_entry(void *argument) {
|
|||||||
* @param htim : TIM handle
|
* @param htim : TIM handle
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN Callback 0 */
|
/* USER CODE BEGIN Callback 0 */
|
||||||
|
|
||||||
/* USER CODE END Callback 0 */
|
/* USER CODE END Callback 0 */
|
||||||
if (htim->Instance == TIM2) {
|
if (htim->Instance == TIM2)
|
||||||
|
{
|
||||||
HAL_IncTick();
|
HAL_IncTick();
|
||||||
}
|
}
|
||||||
/* USER CODE BEGIN Callback 1 */
|
/* USER CODE BEGIN Callback 1 */
|
||||||
@ -1227,7 +1291,8 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
|||||||
* @brief This function is executed in case of error occurrence.
|
* @brief This function is executed in case of error occurrence.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void Error_Handler(void) {
|
void Error_Handler(void)
|
||||||
|
{
|
||||||
/* USER CODE BEGIN Error_Handler_Debug */
|
/* USER CODE BEGIN Error_Handler_Debug */
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user