looks like music is here; compiled but not tested

master
Dmitry Maylarov 7 years ago
parent ddbdad4bb9
commit b8da0dabe5

@ -39,6 +39,14 @@
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"problemMatcher": []
},
{

@ -3,5 +3,12 @@
{
"path": "D:\\Folders\\Documents\\STM32\\Uberdevice"
}
]
],
"settings": {
"files.associations": {
"task.h": "c",
"music.h": "c",
"usb_device.h": "c"
}
}
}

@ -16,8 +16,6 @@ typedef struct {
uint32_t scores[MAX_PLAYERS];
} GameEngine;
extern GameEngine game;
void InitGameEngine();
void IncrementTurnTime();
void DecrementTurnTime();

@ -32,13 +32,7 @@ extern "C" {
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stm32f1xx_hal_gpio.h"
#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 */

@ -2,8 +2,23 @@
#define __MUSIC_H
#include <stdint.h>
#include <stdbool.h>
void MusicPlay(void);
#define MAX_TONEGENS 6
#define MAX_CHANNELS 2
typedef enum returnCodes {
OK,
STOPPED,
WRONG_HEADER,
OUT_OF_LOOP,
WRONG_BYTE
} RET_CODE;
typedef struct {
uint8_t *begin;
uint32_t size;
} Track;
RET_CODE MusicPlay(Track *track);
void MusicStop(void);
#endif

@ -1,5 +1,7 @@
#include "game.h"
extern GameEngine game;
void InitGameEngine() {
game.timerValue = game.turnTime;
game.countScores = false;

@ -25,6 +25,14 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdlib.h>
#include "stm32f1xx_hal_gpio.h"
#include "lcd.h"
#include "game.h"
#include "task.h"
#include "queue.h"
#include "music.h"
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@ -42,7 +50,6 @@
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
@ -68,8 +75,25 @@ bool plusButton = false;
bool minusButton = false;
bool bigButton = false;
static TimerHandle_t secondsTimerHandle = NULL;
static TaskHandle_t xMusicHandle = NULL;
TimerHandle_t secondsTimerHandle = NULL;
TaskHandle_t xMusicHandle = NULL;
asm(
"tetris:\n\t"
".incbin \"../../Resources/tetris.bin\"\n\t" // используем директиву .incbin
"tetris_len:\n\t"
".long .-tetris\n\t" // вставляем значение .long с вычисленной длиной файла
);
extern uint8_t *tetris;
extern uint32_t tetris_len;
asm(
"super_mario:\n\t"
".incbin \"../../Resources/super_mario.bin\"\n\t" // используем директиву .incbin
"super_mario_len:\n\t"
".long .-super_mario\n\t" // вставляем значение .long с вычисленной длиной файла
);
extern uint8_t *super_mario;
extern uint32_t super_mario_len;
/* USER CODE END PV */
@ -479,7 +503,7 @@ void vTaskTimerSetup(void *parameter) {
vTimerCallback // function to call after timer expires
);
xTaskCreate(vTaskPlayerSetup, "Setup", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
xTaskCreate(vTaskConfig, "Config", configMINIMAL_STACK_SIZE, NULL, 1, NULL);
vTaskDelete(NULL);
}
@ -565,10 +589,14 @@ void vTaskTurnEnd(void *parameter) {
}
void vTaskOvertime(void *parameter) {
Track music[2] = {
{ .begin = tetris, .size = tetris_len},
{ .begin = super_mario, .size = super_mario_len}
};
while (1)
{
HAL_GPIO_WritePin(LED2_GPIO_Port, LED1_Pin, GPIO_PIN_SET);
MusicPlay();
MusicPlay(&music[0]);
HAL_GPIO_WritePin(LED2_GPIO_Port, LED1_Pin, GPIO_PIN_RESET);
vTaskDelay(1000);
}

@ -1,9 +1,223 @@
#include "music.h"
#include "FreeRTOS.h"
#include "task.h"
#include <stdbool.h>
void MusicPlay(void) {
#define NOTE_C0 16
#define NOTE_CS0 17
#define NOTE_D0 18
#define NOTE_DS0 19
#define NOTE_E0 21
#define NOTE_F0 22
#define NOTE_FS0 23
#define NOTE_G0 24
#define NOTE_GS0 26
#define NOTE_A0 28
#define NOTE_AS0 29
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
}
bool playing;
uint16_t pitches[110];
uint8_t tonegens[MAX_TONEGENS] = { 0, 0, 0, 0, 0, 0 };
uint8_t channelOut[MAX_TONEGENS] = { 0, 0, 0, 0, 0, 0 };
void MusicStop(void) {
playing = false;
for (int i = 0; i < MAX_TONEGENS; i++) {
// disable PWM
tonegens[i] = 0;
channelOut[i] = 0;
}
}
RET_CODE MusicPlay(Track *track) {
MusicStop();
uint8_t *melody = track->begin;
uint32_t melodySize = track->size;
playing = true;
TickType_t xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
if (melody[0] != 'P' || melody[1] != 't')
{
MusicStop();
return WRONG_HEADER;
}
for (int i = melody[2]; i < melodySize; i++) {
if (playing == true)
{
//melody[2] stores the length of header
/* If the high-order bit of the byte is 0, it is a command to delay for a while until
the next note change. The other 7 bits and the 8 bits of the following byte are
interpreted as a 15-bit big-endian integer that is the number of milliseconds to
wait before processing the next command. For example, 07 D0
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.*/
uint8_t byte = melody[i];
if ((melody[i] >> 7) == 0) {
uint32_t delay = (melody[i] << 8) + melody[i + 1];
vTaskDelayUntil(&xLastWakeTime, delay);
i++;
}
else {
switch (melody[i] >> 4) {
case 0xF || 0xE : {
MusicStop();
return OK;
}
case 0x8 : {
// 8t Stop playing the note on tone generator t
uint8_t generator = melody[i] & 0x0F;
tonegens[generator] = 0;
break;
}
/* 9t nn [vv]
Start playing note nn on tone generator t, replacing any previous note.
Generators are numbered starting with 0. The note numbers are the MIDI
numbers for the chromatic scale, with decimal 69 being Middle A (440 Hz).
If the -v option was given, the third byte specifies the note volume.*/
case 0x9 : {
uint8_t generator = melody[i] & 0x0F;
tonegens[generator] = pitches[melody[i + 1]];
i++;
break;
}
/* Ct ii Change tone generator t to play instrument ii from now on. This will only
be generated if the -i option was given.*/
case 0xC : {
//not impemented
i++;
break;
}
default: {
MusicStop();
return WRONG_BYTE;
}
}
}
//placeholder (тут так и было, хз)
for (uint8_t i = 0; i < MAX_TONEGENS; i++) {
channelOut[i] = 0;
}
uint8_t activeChannels = 0;
uint8_t currentChannel = 0;
for (uint8_t i = 0; i < MAX_TONEGENS; i++) {
if (tonegens[i] && (activeChannels < MAX_CHANNELS)) {
activeChannels++;
channelOut[currentChannel++] = tonegens[i];
}
}
for (uint8_t i = 0; i < MAX_CHANNELS; i++) {
channelOut[i] = 0;
}
/*
for (auto i = 0; i < channels.size(); i++) {
channels[i].PWM_SetFrequency(channelOut[i] ? channelOut[i] : Periph::Timer::PWM_MAX);
}
*/
} else {
MusicStop();
return STOPPED;
}
}
return OUT_OF_LOOP;
}
/*
MusicPlayer() {
for (auto &channel : channels)
channel.PWM_Init();
channels[1].PWM_SetParam(1000, 250);
}*/

@ -46,6 +46,7 @@ Middlewares/FreeRTOS/Src/croutine.c \
Middlewares/FreeRTOS/Src/queue.c \
Middlewares/FreeRTOS/Src/timers.c \
Core/Src/main.c \
Core/Src/music.c \
Core/Src/lcd.c \
Core/Src/game.c \
Core/Src/stm32f1xx_it.c \
@ -133,6 +134,7 @@ AS_INCLUDES =
# C includes
C_INCLUDES = \
-IMiddlewares/FreeRTOS/Inc \
-IUSB_DEVICE/App \
-IUSB_DEVICE/Target \
-ICore/Inc \
@ -141,7 +143,6 @@ C_INCLUDES = \
-IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc \
-IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IMiddlewares/FreeRTOS/Inc \
-IDrivers/CMSIS/Include

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save