idk
This commit is contained in:
parent
fd295ba480
commit
b82393d4a2
@ -51,6 +51,10 @@
|
|||||||
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
|
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
extern uint32_t SystemCoreClock;
|
extern uint32_t SystemCoreClock;
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
|
extern void configureTimerForRunTimeStats(void);
|
||||||
|
extern unsigned long getRunTimeCounterValue(void);
|
||||||
|
/* USER CODE END 0 */
|
||||||
#endif
|
#endif
|
||||||
#ifndef CMSIS_device_header
|
#ifndef CMSIS_device_header
|
||||||
#define CMSIS_device_header "stm32f4xx.h"
|
#define CMSIS_device_header "stm32f4xx.h"
|
||||||
@ -70,7 +74,9 @@
|
|||||||
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
|
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
|
||||||
#define configTOTAL_HEAP_SIZE ((size_t)15360)
|
#define configTOTAL_HEAP_SIZE ((size_t)15360)
|
||||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||||
|
#define configGENERATE_RUN_TIME_STATS 1
|
||||||
#define configUSE_TRACE_FACILITY 1
|
#define configUSE_TRACE_FACILITY 1
|
||||||
|
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
||||||
#define configUSE_16_BIT_TICKS 0
|
#define configUSE_16_BIT_TICKS 0
|
||||||
#define configUSE_MUTEXES 1
|
#define configUSE_MUTEXES 1
|
||||||
#define configQUEUE_REGISTRY_SIZE 8
|
#define configQUEUE_REGISTRY_SIZE 8
|
||||||
@ -166,6 +172,12 @@ standard names. */
|
|||||||
|
|
||||||
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0
|
#define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 0
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
|
/* Definitions needed when configGENERATE_RUN_TIME_STATS is on */
|
||||||
|
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS configureTimerForRunTimeStats
|
||||||
|
#define portGET_RUN_TIME_COUNTER_VALUE getRunTimeCounterValue
|
||||||
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* USER CODE BEGIN Defines */
|
/* USER CODE BEGIN Defines */
|
||||||
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
|
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */
|
||||||
/* USER CODE END Defines */
|
/* USER CODE END Defines */
|
||||||
|
|||||||
@ -59,8 +59,8 @@ void Error_Handler(void);
|
|||||||
/* USER CODE END EFP */
|
/* USER CODE END EFP */
|
||||||
|
|
||||||
/* Private defines -----------------------------------------------------------*/
|
/* Private defines -----------------------------------------------------------*/
|
||||||
#define LED_Pin GPIO_PIN_13
|
#define LED_BLUE_Pin GPIO_PIN_13
|
||||||
#define LED_GPIO_Port GPIOC
|
#define LED_BLUE_GPIO_Port GPIOC
|
||||||
#define DISPLAY_CS_Pin GPIO_PIN_4
|
#define DISPLAY_CS_Pin GPIO_PIN_4
|
||||||
#define DISPLAY_CS_GPIO_Port GPIOA
|
#define DISPLAY_CS_GPIO_Port GPIOA
|
||||||
#define TOUCH_CS_Pin GPIO_PIN_1
|
#define TOUCH_CS_Pin GPIO_PIN_1
|
||||||
|
|||||||
@ -52,6 +52,27 @@
|
|||||||
|
|
||||||
/* USER CODE END FunctionPrototypes */
|
/* USER CODE END FunctionPrototypes */
|
||||||
|
|
||||||
|
/* Hook prototypes */
|
||||||
|
void configureTimerForRunTimeStats(void);
|
||||||
|
unsigned long getRunTimeCounterValue(void);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN 1 */
|
||||||
|
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
|
||||||
|
__weak void configureTimerForRunTimeStats(void) {
|
||||||
|
// Configure TIM2 as a free-running timer at 1 MHz
|
||||||
|
// __HAL_RCC_TIM2_CLK_ENABLE();
|
||||||
|
// TIM2->PSC = (SystemCoreClock / 1000000) - 1; // 1 MHz
|
||||||
|
// TIM2->ARR = 0xFFFFFFFF;
|
||||||
|
// TIM2->CNT = 0;
|
||||||
|
// TIM2->CR1 = TIM_CR1_CEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
__weak unsigned long getRunTimeCounterValue(void) {
|
||||||
|
return TIM2->CNT;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* USER CODE END 1 */
|
||||||
|
|
||||||
/* Private application code --------------------------------------------------*/
|
/* Private application code --------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Application */
|
/* USER CODE BEGIN Application */
|
||||||
|
|
||||||
|
|||||||
247
Core/Src/main.c
247
Core/Src/main.c
@ -24,9 +24,9 @@
|
|||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
//#include "ili9341.h"
|
//#include "ili9341.h"
|
||||||
//#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"
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ const osThreadAttr_t touchhistory_attributes = {
|
|||||||
osThreadId_t drawHandle;
|
osThreadId_t drawHandle;
|
||||||
const osThreadAttr_t draw_attributes = {
|
const osThreadAttr_t draw_attributes = {
|
||||||
.name = "draw",
|
.name = "draw",
|
||||||
.stack_size = 128 * 4,
|
.stack_size = 1024 * 4,
|
||||||
.priority = (osPriority_t) osPriorityLow,
|
.priority = (osPriority_t) osPriorityLow,
|
||||||
};
|
};
|
||||||
/* Definitions for reactiongame */
|
/* Definitions for reactiongame */
|
||||||
@ -136,8 +136,6 @@ void titlescreen() {
|
|||||||
sprintf(str, "snake");
|
sprintf(str, "snake");
|
||||||
ILI9341_DrawText(str, FONT3, 320 / 2 - 100, 240 / 2, BLACK, WHITE);
|
ILI9341_DrawText(str, FONT3, 320 / 2 - 100, 240 / 2, BLACK, WHITE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
sprintf(str, "1v1");
|
sprintf(str, "1v1");
|
||||||
ILI9341_DrawText(str, FONT3, 10, 30, BLACK, WHITE);
|
ILI9341_DrawText(str, FONT3, 10, 30, BLACK, WHITE);
|
||||||
//ILI9341_WriteString(320 / 2 + 100, 240 / 2, str, Font_11x18,
|
//ILI9341_WriteString(320 / 2 + 100, 240 / 2, str, Font_11x18,
|
||||||
@ -195,46 +193,34 @@ struct Snake {
|
|||||||
int TailPendingDeletionX;
|
int TailPendingDeletionX;
|
||||||
int TailPendingDeletionY;
|
int TailPendingDeletionY;
|
||||||
|
|
||||||
|
int TailGrowPending; // Delay tail growth by one frame
|
||||||
// Game over flag
|
// Game over flag
|
||||||
int isGameOver;
|
int isGameOver;
|
||||||
} snake;
|
} snake;
|
||||||
// Function to initialize game variables
|
// Function to initialize game variables
|
||||||
void GameInit() {
|
void GameInit() {
|
||||||
|
|
||||||
snake.gamesizeheight = 6;
|
snake.gamesizeheight = 6;
|
||||||
snake.gamesizewidth = 8;
|
snake.gamesizewidth = 8;
|
||||||
snake.isGameOver = 0;
|
snake.isGameOver = 0;
|
||||||
snake.Dir = STOP;
|
snake.Dir = RIGHT;
|
||||||
snake.x = snake.gamesizewidth / 2;
|
snake.x = 1; //snake.gamesizewidth / 2;
|
||||||
snake.y = snake.gamesizeheight / 2;
|
snake.y = 1; //snake.gamesizeheight / 2;
|
||||||
snake.fruitCordX = rand() % snake.gamesizewidth;
|
snake.fruitCordX = 2; //rand() % snake.gamesizewidth;
|
||||||
snake.fruitCordY = rand() % snake.gamesizeheight;
|
snake.fruitCordY = 1; //rand() % snake.gamesizeheight;
|
||||||
snake.playerScore = 0;
|
snake.playerScore = 0;
|
||||||
snake.TailLen = 0;
|
snake.TailLen = 0;
|
||||||
|
snake.TailGrowPending = 0;
|
||||||
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
||||||
//ILI9341_FillScreen(ILI9341_WHITE);
|
ILI9341_FillScreen(WHITE);
|
||||||
osMutexRelease(displayHandle);
|
osMutexRelease(displayHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Function for updating the game state
|
// Function for updating the game state
|
||||||
void UpdateGame() {
|
void UpdateGame() {
|
||||||
int prevX = snake.TailX[0];
|
|
||||||
int prevY = snake.TailY[0];
|
|
||||||
int prev2X, prev2Y;
|
|
||||||
snake.TailX[0] = snake.x;
|
|
||||||
snake.TailY[0] = snake.y;
|
|
||||||
snake.TailPendingDeletionX = snake.TailX[snake.TailLen];
|
|
||||||
snake.TailPendingDeletionY = snake.TailY[snake.TailLen];
|
|
||||||
for (int i = 1; i < snake.TailLen; i++) {
|
|
||||||
prev2X = snake.TailX[i];
|
|
||||||
prev2Y = snake.TailY[i];
|
|
||||||
snake.TailX[i] = prevX;
|
|
||||||
snake.TailY[i] = prevY;
|
|
||||||
prevX = prev2X;
|
|
||||||
prevY = prev2Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
char dir;
|
char dir;
|
||||||
// check the queue non blocking
|
// check the queue non blocking
|
||||||
osStatus_t status = osMessageQueueGet(pressesHandle, &dir, NULL, 0); // 0 = no wait
|
osStatus_t status = osMessageQueueGet(pressesHandle, &dir, NULL, 0); // 0 = no wait
|
||||||
|
|
||||||
if (status == osOK) {
|
if (status == osOK) {
|
||||||
@ -253,6 +239,26 @@ void UpdateGame() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!snake.TailGrowPending) {
|
||||||
|
if (snake.TailLen > 0) {
|
||||||
|
snake.TailPendingDeletionX = snake.TailX[snake.TailLen - 1];
|
||||||
|
snake.TailPendingDeletionY = snake.TailY[snake.TailLen - 1];
|
||||||
|
} else {
|
||||||
|
snake.TailPendingDeletionX = snake.x;
|
||||||
|
snake.TailPendingDeletionY = snake.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snake.TailGrowPending = 0;
|
||||||
|
// tail movement
|
||||||
|
if (snake.TailLen > 0) {
|
||||||
|
for (int i = snake.TailLen - 1; i > 0; i--) {
|
||||||
|
snake.TailX[i] = snake.TailX[i - 1];
|
||||||
|
snake.TailY[i] = snake.TailY[i - 1];
|
||||||
|
}
|
||||||
|
snake.TailX[0] = snake.x;
|
||||||
|
snake.TailY[0] = snake.y;
|
||||||
|
}
|
||||||
|
|
||||||
switch (snake.Dir) {
|
switch (snake.Dir) {
|
||||||
case LEFT:
|
case LEFT:
|
||||||
snake.x--;
|
snake.x--;
|
||||||
@ -268,23 +274,27 @@ void UpdateGame() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks for snake's collision with the wall
|
// Checks for snake's collision with the wall
|
||||||
if (snake.x >= snake.gamesizewidth || snake.x < 0
|
if (snake.x >= snake.gamesizewidth || snake.x < 0
|
||||||
|| snake.y >= snake.gamesizeheight || snake.y < 0)
|
|| snake.y >= snake.gamesizeheight || snake.y < 0)
|
||||||
snake.isGameOver = 1;
|
snake.isGameOver = 1;
|
||||||
|
|
||||||
// Checks for collision with the tail (o)
|
// Checks for collision with the tail (o)
|
||||||
for (int i = 0; i < snake.TailLen; i++) {
|
for (int i = 0; i < snake.TailLen; i++) {
|
||||||
if (snake.TailX[i] == snake.x && snake.TailY[i] == snake.y)
|
if (snake.TailX[i] == snake.x && snake.TailY[i] == snake.y)
|
||||||
snake.isGameOver = 1;
|
snake.isGameOver = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks for snake's collision with the food (#)
|
// Checks for snake's collision with the food (#)
|
||||||
if (snake.x == snake.fruitCordX && snake.y == snake.fruitCordY) {
|
if (snake.x == snake.fruitCordX && snake.y == snake.fruitCordY) {
|
||||||
snake.playerScore += 10;
|
snake.playerScore += 10;
|
||||||
snake.fruitCordX = rand() % snake.gamesizewidth;
|
snake.fruitCordX = 0; //rand() % snake.gamesizewidth;
|
||||||
snake.fruitCordY = rand() % snake.gamesizeheight;
|
snake.fruitCordY = 0; //rand() % snake.gamesizeheight;
|
||||||
snake.TailLen++;
|
snake.TailLen++;
|
||||||
|
snake.TailX[snake.TailLen - 1] = snake.x;
|
||||||
|
snake.TailY[snake.TailLen - 1] = snake.y;
|
||||||
|
snake.TailGrowPending = 1;
|
||||||
|
//snake.TailPendingDeletionX = -1;
|
||||||
}
|
}
|
||||||
if (snake.isGameOver) {
|
if (snake.isGameOver) {
|
||||||
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
||||||
@ -292,6 +302,8 @@ void UpdateGame() {
|
|||||||
if (Flash_Read_HighScore() > snake.playerScore) {
|
if (Flash_Read_HighScore() > snake.playerScore) {
|
||||||
char str[50];
|
char str[50];
|
||||||
sprintf(str, "Highscore Remains: %lu", Flash_Read_HighScore());
|
sprintf(str, "Highscore Remains: %lu", Flash_Read_HighScore());
|
||||||
|
ILI9341_DrawText(str, FONT3, 320 / 2 - 70, 240 / 2, BLACK,
|
||||||
|
WHITE);
|
||||||
// ILI9341_WriteString(320 / 2 - 70, 240 / 2, str, Font_11x18,
|
// ILI9341_WriteString(320 / 2 - 70, 240 / 2, str, Font_11x18,
|
||||||
//ILI9341_MAGENTA, ILI9341_WHITE);
|
//ILI9341_MAGENTA, ILI9341_WHITE);
|
||||||
} else {
|
} else {
|
||||||
@ -299,6 +311,8 @@ void UpdateGame() {
|
|||||||
sprintf(str, "New Highscore: %lu", snake.playerScore);
|
sprintf(str, "New Highscore: %lu", snake.playerScore);
|
||||||
//ILI9341_WriteString(320 / 2 - 70, 240 / 2, str, Font_11x18,
|
//ILI9341_WriteString(320 / 2 - 70, 240 / 2, str, Font_11x18,
|
||||||
//ILI9341_MAGENTA, ILI9341_WHITE);
|
//ILI9341_MAGENTA, ILI9341_WHITE);
|
||||||
|
ILI9341_DrawText(str, FONT3, 320 / 2 - 70, 240 / 2, BLACK,
|
||||||
|
WHITE);
|
||||||
Flash_Write_HighScore(snake.playerScore);
|
Flash_Write_HighScore(snake.playerScore);
|
||||||
}
|
}
|
||||||
osMutexRelease(displayHandle);
|
osMutexRelease(displayHandle);
|
||||||
@ -309,17 +323,17 @@ void UpdateGame() {
|
|||||||
// Function to handle user UserInput
|
// Function to handle user UserInput
|
||||||
int prevpressed;
|
int prevpressed;
|
||||||
void UserInput() {
|
void UserInput() {
|
||||||
// Checks if a key is pressed or not
|
// Checks if a key is pressed or not
|
||||||
|
|
||||||
//case 'a':
|
//case 'a':
|
||||||
// snake.Dir = LEFT;
|
// snake.Dir = LEFT;
|
||||||
uint16_t x, y;
|
uint16_t x, y;
|
||||||
|
|
||||||
//if (ILI9341_TouchGetCoordinates(&x, &y)) { // Only act if touch detected
|
//if (ILI9341_TouchGetCoordinates(&x, &y)) { // Only act if touch detected
|
||||||
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;
|
||||||
@ -333,42 +347,53 @@ void UserInput() {
|
|||||||
dir = 'D'; // Down
|
dir = 'D'; // Down
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the direction to the queue
|
dir = 'R';
|
||||||
//if (!prevpressed && ILI9341_TouchPressed()) {
|
|
||||||
|
// Send the direction to the queue
|
||||||
|
//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;
|
||||||
//give illegal coords
|
//give illegal coords
|
||||||
//if it is already we can skip it
|
//if it is already we can skip it
|
||||||
//if (touchcoord.x[0] != ILI9341_WIDTH) { //is the last buffer coord illegal?
|
if (touchcoord.x[0] != ILI9341_SCREEN_WIDTH) { //is the last buffer coord illegal?
|
||||||
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] = ILI9341_WIDTH;
|
touchcoord.x[touchbuffersize - 1] = ILI9341_SCREEN_WIDTH;
|
||||||
// touchcoord.y[touchbuffersize - 1] = ILI9341_HEIGHT;
|
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() {
|
||||||
|
|
||||||
// Creating top walls
|
// Creating top walls
|
||||||
// Creating side walls
|
// Creating side walls
|
||||||
//ILI9341_FillRectangle(j, i, ILI9341_WIDTH/snake.gamesizewidth, ILI9341_HEIGHT/snake.gamesizeheight, ILI9341_YELLOW);
|
//ILI9341_FillRectangle(j, i, ILI9341_WIDTH/snake.gamesizewidth, ILI9341_HEIGHT/snake.gamesizeheight, ILI9341_YELLOW);
|
||||||
ILI9341_FillScreen(WHITE);
|
//ILI9341_FillScreen(MAGENTA);
|
||||||
for (int x = 0; x < snake.gamesizewidth; x++) {
|
for (int x = 0; x < snake.gamesizewidth; x++) {
|
||||||
for (int y = 0; y <= snake.gamesizeheight; y++) {
|
for (int y = 0; y <= snake.gamesizeheight; y++) {
|
||||||
|
|
||||||
if (x == snake.x && y == snake.y) {
|
if (x == snake.x && y == snake.y) {
|
||||||
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
||||||
|
ILI9341_DrawFilledRectangleCoord(
|
||||||
|
(x * ILI9341_SCREEN_WIDTH) / snake.gamesizewidth,
|
||||||
|
(y * ILI9341_SCREEN_HEIGHT) / snake.gamesizeheight,
|
||||||
|
(x * ILI9341_SCREEN_WIDTH) / snake.gamesizewidth
|
||||||
|
+ ILI9341_SCREEN_WIDTH
|
||||||
|
/ snake.gamesizewidth,
|
||||||
|
(y * ILI9341_SCREEN_HEIGHT) / snake.gamesizeheight
|
||||||
|
+ ILI9341_SCREEN_HEIGHT
|
||||||
|
/ snake.gamesizeheight,
|
||||||
|
BLACK);
|
||||||
// ILI9341_FillRectangle(
|
// ILI9341_FillRectangle(
|
||||||
// (x * ILI9341_WIDTH) / snake.gamesizewidth,
|
// (x * ILI9341_WIDTH) / snake.gamesizewidth,
|
||||||
// (y * ILI9341_HEIGHT) / snake.gamesizeheight,
|
// (y * ILI9341_HEIGHT) / snake.gamesizeheight,
|
||||||
@ -383,6 +408,16 @@ void GameRender() {
|
|||||||
// Creating the sanke's food with '#'
|
// Creating the sanke's food with '#'
|
||||||
else if (x == snake.fruitCordX && y == snake.fruitCordY) {
|
else if (x == snake.fruitCordX && y == snake.fruitCordY) {
|
||||||
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
||||||
|
ILI9341_DrawFilledRectangleCoord(
|
||||||
|
(x * ILI9341_SCREEN_WIDTH) / snake.gamesizewidth,
|
||||||
|
(y * ILI9341_SCREEN_HEIGHT) / snake.gamesizeheight,
|
||||||
|
(x * ILI9341_SCREEN_WIDTH) / snake.gamesizewidth
|
||||||
|
+ ILI9341_SCREEN_WIDTH
|
||||||
|
/ snake.gamesizewidth,
|
||||||
|
(y * ILI9341_SCREEN_HEIGHT) / snake.gamesizeheight
|
||||||
|
+ ILI9341_SCREEN_HEIGHT
|
||||||
|
/ snake.gamesizeheight,
|
||||||
|
RED);
|
||||||
// ILI9341_FillRectangle(
|
// ILI9341_FillRectangle(
|
||||||
// (x * ILI9341_WIDTH) / snake.gamesizewidth,
|
// (x * ILI9341_WIDTH) / snake.gamesizewidth,
|
||||||
// (y * ILI9341_HEIGHT) / snake.gamesizeheight,
|
// (y * ILI9341_HEIGHT) / snake.gamesizeheight,
|
||||||
@ -393,9 +428,27 @@ void GameRender() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//cout << "#";
|
//cout << "#";
|
||||||
// Creating snake's head with 'O'
|
|
||||||
else if (snake.TailX[0] == x && snake.TailY[0] == y) {
|
else if (snake.TailLen >= 0) {
|
||||||
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
for (int i = 0; i < snake.TailLen; i++) {
|
||||||
|
|
||||||
|
if (snake.TailX[0] == x && snake.TailY[0] == y) {
|
||||||
|
if (osMutexAcquire(displayHandle, osWaitForever)
|
||||||
|
== osOK) {
|
||||||
|
ILI9341_DrawFilledRectangleCoord(
|
||||||
|
(x * ILI9341_SCREEN_WIDTH)
|
||||||
|
/ snake.gamesizewidth,
|
||||||
|
(y * ILI9341_SCREEN_HEIGHT)
|
||||||
|
/ snake.gamesizeheight,
|
||||||
|
(x * ILI9341_SCREEN_WIDTH)
|
||||||
|
/ snake.gamesizewidth
|
||||||
|
+ ILI9341_SCREEN_WIDTH
|
||||||
|
/ snake.gamesizewidth,
|
||||||
|
(y * ILI9341_SCREEN_HEIGHT)
|
||||||
|
/ snake.gamesizeheight
|
||||||
|
+ ILI9341_SCREEN_HEIGHT
|
||||||
|
/ snake.gamesizeheight,
|
||||||
|
GREEN);
|
||||||
// ILI9341_FillRectangle(
|
// ILI9341_FillRectangle(
|
||||||
// (x * ILI9341_WIDTH) / snake.gamesizewidth,
|
// (x * ILI9341_WIDTH) / snake.gamesizewidth,
|
||||||
// (y * ILI9341_HEIGHT) / snake.gamesizeheight,
|
// (y * ILI9341_HEIGHT) / snake.gamesizeheight,
|
||||||
@ -404,10 +457,24 @@ void GameRender() {
|
|||||||
// ILI9341_GREEN);
|
// ILI9341_GREEN);
|
||||||
osMutexRelease(displayHandle);
|
osMutexRelease(displayHandle);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (snake.TailPendingDeletionX == x
|
}
|
||||||
|
if (snake.TailPendingDeletionX == x
|
||||||
&& snake.TailPendingDeletionY == y) {
|
&& snake.TailPendingDeletionY == y) {
|
||||||
|
|
||||||
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
if (osMutexAcquire(displayHandle, osWaitForever) == osOK) {
|
||||||
|
ILI9341_DrawFilledRectangleCoord(
|
||||||
|
(x * ILI9341_SCREEN_WIDTH) / snake.gamesizewidth,
|
||||||
|
(y * ILI9341_SCREEN_HEIGHT) / snake.gamesizeheight,
|
||||||
|
(x * ILI9341_SCREEN_WIDTH) / snake.gamesizewidth
|
||||||
|
+ ILI9341_SCREEN_WIDTH
|
||||||
|
/ snake.gamesizewidth,
|
||||||
|
(y * ILI9341_SCREEN_HEIGHT) / snake.gamesizeheight
|
||||||
|
+ ILI9341_SCREEN_HEIGHT
|
||||||
|
/ snake.gamesizeheight,
|
||||||
|
WHITE);
|
||||||
// ILI9341_FillRectangle(
|
// ILI9341_FillRectangle(
|
||||||
// (x * ILI9341_WIDTH) / snake.gamesizewidth,
|
// (x * ILI9341_WIDTH) / snake.gamesizewidth,
|
||||||
// (y * ILI9341_HEIGHT) / snake.gamesizeheight,
|
// (y * ILI9341_HEIGHT) / snake.gamesizeheight,
|
||||||
@ -443,7 +510,6 @@ int main(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
|
|
||||||
/* USER CODE END Init */
|
/* USER CODE END Init */
|
||||||
|
|
||||||
/* Configure the system clock */
|
/* Configure the system clock */
|
||||||
@ -464,15 +530,17 @@ int main(void)
|
|||||||
MX_USART6_UART_Init();
|
MX_USART6_UART_Init();
|
||||||
MX_I2C1_Init();
|
MX_I2C1_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
ILI9341_Init();
|
||||||
|
ILI9341_SetRotation(SCREEN_HORIZONTAL_1);
|
||||||
|
ILI9341_FillScreen(MAGENTA);
|
||||||
|
|
||||||
//ILI9341_FillRectangle(100, 100, 100, 100, ILI9341_GREEN);
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Init scheduler */
|
/* Init scheduler */
|
||||||
//osKernelInitialize();
|
osKernelInitialize();
|
||||||
/* Create the mutex(es) */
|
/* Create the mutex(es) */
|
||||||
/* creation of display */
|
/* creation of display */
|
||||||
//displayHandle = osMutexNew(&display_attributes);
|
displayHandle = osMutexNew(&display_attributes);
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_MUTEX */
|
/* USER CODE BEGIN RTOS_MUTEX */
|
||||||
/* add mutexes, ... */
|
/* add mutexes, ... */
|
||||||
@ -499,7 +567,7 @@ int main(void)
|
|||||||
//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);
|
||||||
@ -511,14 +579,14 @@ int main(void)
|
|||||||
/* add threads, ... */
|
/* add threads, ... */
|
||||||
|
|
||||||
char dir;
|
char dir;
|
||||||
// check the queue blocking
|
// check the queue blocking
|
||||||
//osStatus_t status = osMessageQueueGet(pressesHandle, &dir, NULL,
|
//osStatus_t status = osMessageQueueGet(pressesHandle, &dir, NULL,
|
||||||
//osWaitForever); // blocking
|
//osWaitForever); // blocking
|
||||||
//if (dir == 'L')
|
//if (dir == 'L')
|
||||||
// drawHandle = osThreadNew(snakegame, NULL, &draw_attributes);
|
// drawHandle = osThreadNew(snakegame, NULL, &draw_attributes);
|
||||||
//if (dir == 'R')
|
//if (dir == 'R')
|
||||||
//reactiongameHandle = osThreadNew(startreactiongame, NULL,
|
//reactiongameHandle = osThreadNew(startreactiongame, NULL,
|
||||||
// &reactiongame_attributes);
|
// &reactiongame_attributes);
|
||||||
/* USER CODE END RTOS_THREADS */
|
/* USER CODE END RTOS_THREADS */
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_EVENTS */
|
/* USER CODE BEGIN RTOS_EVENTS */
|
||||||
@ -526,21 +594,21 @@ int main(void)
|
|||||||
/* USER CODE END RTOS_EVENTS */
|
/* USER CODE END RTOS_EVENTS */
|
||||||
|
|
||||||
/* Start scheduler */
|
/* Start scheduler */
|
||||||
//osKernelStart();
|
osKernelStart();
|
||||||
|
|
||||||
/* We should never get here as control is now taken by the scheduler */
|
/* We should never get here as control is now taken by the scheduler */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
//int a[4] = { ILI9341_GREEN, ILI9341_WHITE, ILI9341_BLACK, ILI9341_BLUE };
|
|
||||||
|
//int a[4] = { ILI9341_GREEN, ILI9341_WHITE, ILI9341_BLACK, ILI9341_BLUE };
|
||||||
int cnt;
|
int cnt;
|
||||||
|
|
||||||
while (hspi1.State != HAL_SPI_STATE_READY);
|
while (hspi1.State != HAL_SPI_STATE_READY)
|
||||||
|
;
|
||||||
|
|
||||||
while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
|
while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY)
|
||||||
|
;
|
||||||
ILI9341_Init();
|
|
||||||
ILI9341_SetRotation(SCREEN_HORIZONTAL_1);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
@ -553,14 +621,15 @@ int main(void)
|
|||||||
//ILI9341_FillScreen(MAGENTA);
|
//ILI9341_FillScreen(MAGENTA);
|
||||||
//ILI9341_DrawFilledRectangleCoord(10, 10, 20, 20, RED);
|
//ILI9341_DrawFilledRectangleCoord(10, 10, 20, 20, RED);
|
||||||
|
|
||||||
|
|
||||||
//ILI9341_FillScreen(WHITE);
|
//ILI9341_FillScreen(WHITE);
|
||||||
|
HAL_Delay(1);
|
||||||
char str[20];
|
char str[20];
|
||||||
sprintf(str, "%lu", cnt % 1000);
|
sprintf(str, "%lu", cnt % 1000);
|
||||||
int atim = HAL_GetTick();
|
int atim = HAL_GetTick();
|
||||||
//ILI9341_DrawFilledRectangleCoord(10, 10, 20, 20, GREEN);
|
//ILI9341_DrawFilledRectangleCoord(10, 10, 20, 20, GREEN);
|
||||||
ILI9341_FillScreen(atim%0xFFFF);
|
//ILI9341_FillScreen(MAGENTA);
|
||||||
|
|
||||||
|
//ILI9341_FillScreen(atim%0xFFFF);
|
||||||
//ILI9341_DrawText(str, FONT4, 50, 50, WHITE, BLACK);
|
//ILI9341_DrawText(str, FONT4, 50, 50, WHITE, BLACK);
|
||||||
//ILI9341_DrawChar('C', FONT4, 40, 40, WHITE, BLACK);
|
//ILI9341_DrawChar('C', FONT4, 40, 40, WHITE, BLACK);
|
||||||
int c = HAL_GetTick() - atim;
|
int c = HAL_GetTick() - atim;
|
||||||
@ -965,7 +1034,7 @@ static void MX_GPIO_Init(void)
|
|||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(LED_BLUE_GPIO_Port, LED_BLUE_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(GPIOA, DISPLAY_CS_Pin|DISPLAY_RES_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOA, DISPLAY_CS_Pin|DISPLAY_RES_Pin, GPIO_PIN_RESET);
|
||||||
@ -973,12 +1042,12 @@ static void MX_GPIO_Init(void)
|
|||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(GPIOB, TOUCH_CS_Pin|DISPLAY_DC_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOB, TOUCH_CS_Pin|DISPLAY_DC_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin : LED_Pin */
|
/*Configure GPIO pin : LED_BLUE_Pin */
|
||||||
GPIO_InitStruct.Pin = LED_Pin;
|
GPIO_InitStruct.Pin = LED_BLUE_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(LED_BLUE_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
/*Configure GPIO pins : DISPLAY_CS_Pin DISPLAY_RES_Pin */
|
/*Configure GPIO pins : DISPLAY_CS_Pin DISPLAY_RES_Pin */
|
||||||
GPIO_InitStruct.Pin = DISPLAY_CS_Pin|DISPLAY_RES_Pin;
|
GPIO_InitStruct.Pin = DISPLAY_CS_Pin|DISPLAY_RES_Pin;
|
||||||
@ -1046,11 +1115,21 @@ void snakegame(void *argument)
|
|||||||
{
|
{
|
||||||
/* USER CODE BEGIN snakegame */
|
/* USER CODE BEGIN snakegame */
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
|
ILI9341_FillScreen(BLACK);
|
||||||
GameInit();
|
GameInit();
|
||||||
for (;;) {
|
|
||||||
osDelay(200);
|
|
||||||
UpdateGame();
|
|
||||||
GameRender();
|
GameRender();
|
||||||
|
for (;;) {
|
||||||
|
|
||||||
|
//uint16_t x,y;
|
||||||
|
//ILI9341_TouchGetCoordinates(&x, &y);
|
||||||
|
GameRender();
|
||||||
|
static char statsBuffer[512];
|
||||||
|
vTaskGetRunTimeStats(statsBuffer);
|
||||||
|
|
||||||
|
vTaskDelay(1000);
|
||||||
|
uint16_t timer=HAL_GetTick();
|
||||||
|
//ILI9341_FillScreen(timer%0xFFFF);
|
||||||
|
UpdateGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE END snakegame */
|
/* USER CODE END snakegame */
|
||||||
|
|||||||
@ -26,11 +26,13 @@ Dma.SPI1_TX.1.PeriphInc=DMA_PINC_DISABLE
|
|||||||
Dma.SPI1_TX.1.Priority=DMA_PRIORITY_LOW
|
Dma.SPI1_TX.1.Priority=DMA_PRIORITY_LOW
|
||||||
Dma.SPI1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode
|
Dma.SPI1_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode
|
||||||
FREERTOS.FootprintOK=true
|
FREERTOS.FootprintOK=true
|
||||||
FREERTOS.IPParameters=Tasks01,FootprintOK,configUSE_NEWLIB_REENTRANT,Queues01,Mutexes01
|
FREERTOS.IPParameters=Tasks01,FootprintOK,configUSE_NEWLIB_REENTRANT,Queues01,Mutexes01,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS
|
||||||
FREERTOS.Mutexes01=display,Dynamic,NULL,Available
|
FREERTOS.Mutexes01=display,Dynamic,NULL,Available
|
||||||
FREERTOS.Queues01=presses,16,char,0,Dynamic,NULL,NULL
|
FREERTOS.Queues01=presses,16,char,0,Dynamic,NULL,NULL
|
||||||
FREERTOS.Tasks01=touchhistory,24,128,StartTouchHist,Default,NULL,Dynamic,NULL,NULL;draw,8,128,snakegame,Default,NULL,Dynamic,NULL,NULL;reactiongame,8,128,startreactiongame,Default,NULL,Dynamic,NULL,NULL;gamepicker,8,128,gamepicker_entry,Default,NULL,Dynamic,NULL,NULL
|
FREERTOS.Tasks01=touchhistory,24,128,StartTouchHist,Default,NULL,Dynamic,NULL,NULL;draw,8,128,snakegame,Default,NULL,Dynamic,NULL,NULL;reactiongame,8,128,startreactiongame,Default,NULL,Dynamic,NULL,NULL;gamepicker,8,128,gamepicker_entry,Default,NULL,Dynamic,NULL,NULL
|
||||||
|
FREERTOS.configGENERATE_RUN_TIME_STATS=1
|
||||||
FREERTOS.configUSE_NEWLIB_REENTRANT=1
|
FREERTOS.configUSE_NEWLIB_REENTRANT=1
|
||||||
|
FREERTOS.configUSE_STATS_FORMATTING_FUNCTIONS=1
|
||||||
File.Version=6
|
File.Version=6
|
||||||
GPIO.groupedBy=Group By Peripherals
|
GPIO.groupedBy=Group By Peripherals
|
||||||
KeepUserPlacement=false
|
KeepUserPlacement=false
|
||||||
@ -173,7 +175,7 @@ PB8.Signal=I2C1_SCL
|
|||||||
PB9.Mode=I2C
|
PB9.Mode=I2C
|
||||||
PB9.Signal=I2C1_SDA
|
PB9.Signal=I2C1_SDA
|
||||||
PC13-ANTI_TAMP.GPIOParameters=GPIO_Label
|
PC13-ANTI_TAMP.GPIOParameters=GPIO_Label
|
||||||
PC13-ANTI_TAMP.GPIO_Label=LED
|
PC13-ANTI_TAMP.GPIO_Label=LED_BLUE
|
||||||
PC13-ANTI_TAMP.Locked=true
|
PC13-ANTI_TAMP.Locked=true
|
||||||
PC13-ANTI_TAMP.Signal=GPIO_Output
|
PC13-ANTI_TAMP.Signal=GPIO_Output
|
||||||
PinOutPanel.RotationAngle=0
|
PinOutPanel.RotationAngle=0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user