trying to make it work

master
Dmitry Maylarov 7 years ago
parent 172aac8dff
commit 6f27bb7d81

@ -73,7 +73,7 @@
#define configUSE_TICKLESS_IDLE 1 #define configUSE_TICKLESS_IDLE 1
#define configUSE_IDLE_HOOK 0 #define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0 #define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ CLOCK #define configCPU_CLOCK_HZ 24000000
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES 5 #define configMAX_PRIORITIES 5
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 128 )

@ -32,6 +32,13 @@ extern "C" {
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include <stdlib.h>
#include "lcd.h"
#include "game.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@ -56,7 +63,22 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
void Error_Handler(void); void Error_Handler(void);
/* USER CODE BEGIN EFP */ /* USER CODE BEGIN EFP */
void vTaskLed(void *parameter);
void vTaskButton(void *parameter);
void vTaskDisplay(void *parameter);
void vTaskBeep(void *parameter);
void vTaskOvertime(void *parameter);
void vTaskStateMachine(void *parameter);
void vTaskPlayerSetup(void *parameter);
void vTaskConfig(void *parameter);
void vTaskTimerSetup(void *parameter);
void vTaskTurn(void *parameter);
void vTaskTurnEnd(void *parameter);
void vTimerCallback(TimerHandle_t xTimer);
/* USER CODE END EFP */ /* USER CODE END EFP */
/* Private defines -----------------------------------------------------------*/ /* Private defines -----------------------------------------------------------*/

@ -1,3 +1,5 @@
#ifndef __GAME_H
#define __GAME_H
#include "game.h" #include "game.h"
void InitGameEngine() { void InitGameEngine() {
@ -59,3 +61,4 @@ void NextPlayer() {
game.currentPlayer = (game.currentPlayer + 1) % game.activePlayers; game.currentPlayer = (game.currentPlayer + 1) % game.activePlayers;
ResetTurnTimer(); ResetTurnTimer();
} }
#endif

@ -1,3 +1,5 @@
#ifndef __LCD_H
#define __LCD_H
#include "lcd.h" #include "lcd.h"
#define LCD_COLS 20 #define LCD_COLS 20
@ -117,3 +119,5 @@ void LCD_SendString(LCD_HandleTypeDef *lcd, char *str) {
str++; str++;
} }
} }
#endif

@ -24,13 +24,6 @@
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include <stdlib.h>
#include "lcd.h"
#include "game.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "timers.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@ -71,6 +64,11 @@ LCD_HandleTypeDef hlcd = {
LCD_ROWS, LCD_ROWS,
LCD_COLS LCD_COLS
}; };
bool plusButton = false;
bool minusButton = false;
bool bigButton = false;
static TimerHandle_t secondsTimerHandle = NULL;
/* USER CODE END PV */ /* USER CODE END PV */
@ -129,6 +127,9 @@ int main(void)
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
LCD_Init(&hlcd); LCD_Init(&hlcd);
InitGameEngine(); InitGameEngine();
xTaskCreate(vTaskPlayerSetup, "Player", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
vTaskStartScheduler();
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
@ -430,41 +431,21 @@ static void MX_GPIO_Init(void)
} }
/* USER CODE BEGIN 4 */ /* USER CODE BEGIN 4 */
void logic()
{
led1.SetHigh();
usart.Send();
xTaskCreate(vTaskLed, "LED", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
// xTaskCreate(vTaskStateMachine, "FSM", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(vTaskPlayerSetup, "Player", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
vTaskStartScheduler();
while(1) {
};
}
void vTaskPlayerSetup(void *parameter) void vTaskPlayerSetup(void *parameter)
{ {
while (1) while (1)
{ {
if (plusButton.PressedDebounced()) if (plusButton)
{ {
game.AddPlayer(); AddPlayer();
} }
if (minusButton.PressedDebounced()) if (minusButton)
{ {
game.RemovePlayer(); RemovePlayer();
} }
#ifdef DEBUG if (game.activePlayers > 1 && bigButton)
for (auto i = 0; i < game.maxPlayers; i++)
buffer[i] = game.playerScore[i];
usart.Send();
#endif // DEBUG
if (game.activePlayers > 1 && bigButton.PressedDebounced())
break; break;
vTaskDelay(5); vTaskDelay(5);
@ -476,17 +457,17 @@ void vTaskPlayerSetup(void *parameter)
void vTaskTimerSetup(void *parameter) { void vTaskTimerSetup(void *parameter) {
while (1) while (1)
{ {
if (plusButton.PressedDebounced()) if (plusButton)
{ {
game.IncrementTurnTime(); IncrementTurnTime();
} }
else if (minusButton.PressedDebounced()) else if (minusButton)
{ {
game.DecrementTurnTime(); DecrementTurnTime();
} }
else vTaskDelay(10); else vTaskDelay(10);
if (bigButton.PressedDebounced()) { if (bigButton) {
break; break;
} }
vTaskDelay(10); vTaskDelay(10);
@ -514,12 +495,12 @@ void vTaskTimerSetup(void *parameter) {
void vTaskConfig(void *parameter) { void vTaskConfig(void *parameter) {
while (1) while (1)
{ {
if (plusButton.PressedDebounced()) if (plusButton)
game.countScores = !game.countScores; game.countScores = !game.countScores;
if (minusButton.PressedDebounced()) if (minusButton)
// show round number or change the way it counts // show round number or change the way it counts
game.countScores = !game.countScores; game.countScores = !game.countScores;
if (bigButton.PressedDebounced()) { if (bigButton) {
break; break;
} }
vTaskDelay(10); vTaskDelay(10);
@ -537,15 +518,15 @@ void vTaskTurn(void *parameter) {
while (1) while (1)
{ {
if (plusButton.PressedDebounced()) { if (plusButton) {
xTaskCreate(vTaskTimerSetup, "TaskTimerSetup", configMINIMAL_STACK_SIZE, NULL, 1, NULL); xTaskCreate(vTaskTimerSetup, "TaskTimerSetup", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
break; break;
} }
else if (minusButton.PressedDebounced()) { else if (minusButton) {
xTaskCreate(vTaskConfig, "Config", configMINIMAL_STACK_SIZE, NULL, 1, NULL); xTaskCreate(vTaskConfig, "Config", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
break; break;
} }
else if (bigButton.PressedDebounced()) { else if (bigButton) {
xTaskCreate(vTaskTurnEnd, "TaskTurnEnd", configMINIMAL_STACK_SIZE, NULL, 1, NULL); xTaskCreate(vTaskTurnEnd, "TaskTurnEnd", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
break; break;
} }
@ -583,15 +564,15 @@ void vTaskTurnEnd(void *parameter) {
if (game.countScores) { if (game.countScores) {
int32_t delta = 0; int32_t delta = 0;
while (1) { while (1) {
if (bigButton.PressedDebounced()) { if (bigButton) {
game.ChangeScore(delta); game.ChangeScore(delta);
break; break;
} }
else if (plusButton.PressedDebounced()) else if (plusButton)
{ {
delta++; delta++;
} }
else if (minusButton.PressedDebounced()) else if (minusButton)
{ {
delta--; delta--;
} }

@ -37,6 +37,11 @@ BUILD_DIR = build
# C sources # C sources
C_SOURCES = \ C_SOURCES = \
Middlewares/FreeRTOS/Src/tasks.c \ Middlewares/FreeRTOS/Src/tasks.c \
Middlewares/FreeRTOS/Src/list.c \
Middlewares/FreeRTOS/Src/port.c \
Middlewares/FreeRTOS/Src/event_groups.c \
Middlewares/FreeRTOS/Src/stream_buffer.c \
Middlewares/FreeRTOS/Src/heap_4.c \
Middlewares/FreeRTOS/Src/croutine.c \ Middlewares/FreeRTOS/Src/croutine.c \
Middlewares/FreeRTOS/Src/queue.c \ Middlewares/FreeRTOS/Src/queue.c \
Middlewares/FreeRTOS/Src/timers.c \ Middlewares/FreeRTOS/Src/timers.c \
@ -134,11 +139,11 @@ C_INCLUDES = \
-ICore/Inc \ -ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \ -IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \ -IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IMiddlewares/FreeRTOS/Inc \
-IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc \ -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc \
-IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc \ -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \ -IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include \ -IDrivers/CMSIS/Include \
-IMiddlewares/FreeRTOS/Inc \
-IDrivers/CMSIS/Include -IDrivers/CMSIS/Include

Loading…
Cancel
Save