trying to debug; need to disable USB

master
Dmitry Maylarov 7 years ago
parent b8da0dabe5
commit be4309595d

@ -61,12 +61,11 @@ void Error_Handler(void);
void vTaskLed(void *parameter); void vTaskLed(void *parameter);
void vTaskButton(void *parameter); void vTaskButton(void *parameter);
void vTaskDisplay(void *parameter); void vTaskDisplay(void *parameter);
void vTaskButtonPoll(void *parameter);
void vTaskBeep(void *parameter); void vTaskBeep(void *parameter);
void vTaskOvertime(void *parameter); void vTaskOvertime(void *parameter);
void vTaskStateMachine(void *parameter);
void vTaskPlayerSetup(void *parameter); void vTaskPlayerSetup(void *parameter);
void vTaskConfig(void *parameter); void vTaskConfig(void *parameter);
void vTaskTimerSetup(void *parameter); void vTaskTimerSetup(void *parameter);

@ -1,6 +1,8 @@
#ifndef __LCD_H #ifndef __LCD_H
#define __LCD_H #define __LCD_H
#include "lcd.h" #include "lcd.h"
#include "FreeRTOS.h"
#include "task.h"
#define LCD_COLS 20 #define LCD_COLS 20
@ -79,7 +81,7 @@ HAL_StatusTypeDef LCD_SendInternal(LCD_HandleTypeDef *lcd, uint8_t data, uint8_t
res = HAL_I2C_Master_Transmit(lcd->I2C_Handle, lcd->address, data_arr, res = HAL_I2C_Master_Transmit(lcd->I2C_Handle, lcd->address, data_arr,
sizeof(data_arr), HAL_MAX_DELAY); sizeof(data_arr), HAL_MAX_DELAY);
HAL_Delay(LCD_DELAY_MS); vTaskDelay(LCD_DELAY_MS);
return res; return res;
} }

@ -38,6 +38,14 @@
/* Private typedef -----------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */ /* USER CODE BEGIN PTD */
typedef struct {
bool temp;
bool pressed;
GPIO_TypeDef *port;
uint16_t pin;
} Button;
/* USER CODE END PTD */ /* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/
@ -46,6 +54,8 @@
#define LCD_COLS 20 #define LCD_COLS 20
#define LCD_ROWS 4 #define LCD_ROWS 4
#define BUTTON_COUNT 3
/* USER CODE END PD */ /* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/
@ -71,9 +81,25 @@ LCD_HandleTypeDef hlcd = {
LCD_ROWS, LCD_ROWS,
LCD_COLS LCD_COLS
}; };
bool plusButton = false; Button buttons[BUTTON_COUNT] = { {
bool minusButton = false; .temp = false,
bool bigButton = false; .pressed = false,
.port = BigButton_GPIO_Port,
.pin = BigButton_Pin
}, {
.temp = false,
.pressed = false,
.port = PlusButton_GPIO_Port,
.pin = PlusButton_Pin
}, {
.temp = false,
.pressed = false,
.port = MinusButton_GPIO_Port,
.pin = MinusButton_Pin
} };
Button *plusButton = &buttons[1];
Button *minusButton = &buttons[2];
Button *bigButton = &buttons[0];
TimerHandle_t secondsTimerHandle = NULL; TimerHandle_t secondsTimerHandle = NULL;
TaskHandle_t xMusicHandle = NULL; TaskHandle_t xMusicHandle = NULL;
@ -154,6 +180,7 @@ int main(void)
InitGameEngine(); InitGameEngine();
xTaskCreate(vTaskPlayerSetup, "Player", configMINIMAL_STACK_SIZE, NULL, 1, NULL); xTaskCreate(vTaskPlayerSetup, "Player", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(vTaskButtonPoll, "Buttons", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
vTaskStartScheduler(); vTaskStartScheduler();
/* USER CODE END 2 */ /* USER CODE END 2 */
@ -459,13 +486,13 @@ static void MX_GPIO_Init(void)
void vTaskPlayerSetup(void *parameter) void vTaskPlayerSetup(void *parameter)
{ {
while (1) while (1)
{ {
if (plusButton) if (plusButton->pressed)
{ {
AddPlayer(); AddPlayer();
} }
if (minusButton) if (minusButton->pressed)
{ {
RemovePlayer(); RemovePlayer();
} }
@ -480,17 +507,17 @@ void vTaskPlayerSetup(void *parameter)
void vTaskTimerSetup(void *parameter) { void vTaskTimerSetup(void *parameter) {
while (1) while (1)
{ {
if (plusButton) if (plusButton->pressed)
{ {
IncrementTurnTime(); IncrementTurnTime();
} }
else if (minusButton) else if (minusButton->pressed)
{ {
DecrementTurnTime(); DecrementTurnTime();
} }
else vTaskDelay(10); else vTaskDelay(10);
if (bigButton) { if (bigButton->pressed) {
break; break;
} }
vTaskDelay(10); vTaskDelay(10);
@ -510,12 +537,12 @@ void vTaskTimerSetup(void *parameter) {
void vTaskConfig(void *parameter) { void vTaskConfig(void *parameter) {
while (1) while (1)
{ {
if (plusButton) if (plusButton->pressed)
game.countScores = !game.countScores; game.countScores = !game.countScores;
if (minusButton) if (minusButton->pressed)
// 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) { if (bigButton->pressed) {
break; break;
} }
vTaskDelay(10); vTaskDelay(10);
@ -532,15 +559,15 @@ void vTaskTurn(void *parameter) {
while (1) while (1)
{ {
if (plusButton) { if (plusButton->pressed) {
xTaskCreate(vTaskTimerSetup, "TaskTimerSetup", configMINIMAL_STACK_SIZE, NULL, 1, NULL); xTaskCreate(vTaskTimerSetup, "TaskTimerSetup", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
break; break;
} }
else if (minusButton) { else if (minusButton->pressed) {
xTaskCreate(vTaskConfig, "Config", configMINIMAL_STACK_SIZE, NULL, 1, NULL); xTaskCreate(vTaskConfig, "Config", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
break; break;
} }
else if (bigButton) { else if (bigButton->pressed) {
xTaskCreate(vTaskTurnEnd, "TaskTurnEnd", configMINIMAL_STACK_SIZE, NULL, 1, NULL); xTaskCreate(vTaskTurnEnd, "TaskTurnEnd", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
break; break;
} }
@ -568,15 +595,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) { if (bigButton->pressed) {
ChangeScore(delta); ChangeScore(delta);
break; break;
} }
else if (plusButton) else if (plusButton->pressed)
{ {
delta++; delta++;
} }
else if (minusButton) else if (minusButton->pressed)
{ {
delta--; delta--;
} }
@ -607,6 +634,23 @@ void vTimerCallback(TimerHandle_t xTimer) {
game.timerValue--; game.timerValue--;
} }
void vTaskButtonPoll(void *parameter) {
while (1) {
for(int i = 0; i<BUTTON_COUNT; i++)
{
bool state = HAL_GPIO_ReadPin(buttons[i].port, buttons[i].pin);
if (state && !buttons[i].temp)
buttons[i].temp = true;
else if (state && buttons[i].temp)
buttons[i].pressed = true;
else if (!state && buttons[i].pressed)
buttons[i].temp = false;
else if (!state && !buttons[i].temp)
buttons[i].pressed = false;
}
vTaskDelay(50);
}
}
/* USER CODE END 4 */ /* USER CODE END 4 */
/** /**

@ -142,7 +142,6 @@ RET_CODE MusicPlay(Track *track) {
wait before processing the next command. For example, 07 D0 wait before processing the next command. For example, 07 D0
would cause a delay of 0x07d0 = 2000 decimal millisconds, or 2 seconds. Any tones would cause a delay of 0x07d0 = 2000 decimal millisconds, or 2 seconds. Any tones
that were playing before the delay command will continue to play.*/ that were playing before the delay command will continue to play.*/
uint8_t byte = melody[i];
if ((melody[i] >> 7) == 0) { if ((melody[i] >> 7) == 0) {
uint32_t delay = (melody[i] << 8) + melody[i + 1]; uint32_t delay = (melody[i] << 8) + melody[i + 1];
vTaskDelayUntil(&xLastWakeTime, delay); vTaskDelayUntil(&xLastWakeTime, delay);

Loading…
Cancel
Save