Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lighter ram memory allocation/possible long beep fix #1344

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more work
  • Loading branch information
kisslorand committed Dec 4, 2020
commit 51068ac65575515ebcd163b5fb2352b04cec1762
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ tags
*.x86_64
*.hex

# Binary files
*.bin

# Debug files
*.dSYM/
*.su
Expand Down
Binary file modified Copy to SD Card root directory to update/MKSTFT28.bin
Binary file not shown.
39 changes: 23 additions & 16 deletions TFT/src/User/Hal/buzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,31 @@ static BUZZER buzzer;
volatile uint32_t buzzerEndTime = 0;

void tone(const uint32_t frequency, const uint32_t duration);
void loopBuzzer(void) {
const uint32_t now = OS_GetTimeMs();

if (!buzzerEndTime) {
void loopBuzzer(void)
{
if (!buzzerEndTime)
{
buzzerEndTime = OS_GetTimeMs() + buzzer.duration[buzzer.rIndex];
if (buzzer.count == 0) return;

buzzerEndTime = now + buzzer.duration[buzzer.rIndex];

if (buzzer.frequency[buzzer.rIndex] > 0) {
if (buzzer.frequency[buzzer.rIndex] > 0)
{
tone(buzzer.frequency[buzzer.rIndex], buzzer.duration[buzzer.rIndex]);
}

buzzer.rIndex = (buzzer.rIndex + 1) % BUZZER_CACHE_SIZE;
buzzer.count--;
}
else if (now > buzzerEndTime) {
else if (OS_GetTimeMs() > buzzerEndTime)
{
buzzerEndTime = 0;
GPIO_SetLevel(BUZZER_PIN, BUZZER_STOP_LEVEL);
}
}

void Buzzer_TurnOn(const uint32_t frequency, const uint32_t duration)
{
while (buzzer.count == BUZZER_CACHE_SIZE) {
while (buzzer.count == BUZZER_CACHE_SIZE)
{
loopBuzzer();
}
buzzer.duration[buzzer.wIndex] = duration;
Expand Down Expand Up @@ -132,7 +133,8 @@ void Buzzer_play(SOUND sound)
}

volatile uint32_t toggles = 0;
void tone(const uint32_t frequency, const uint32_t duration) {
void tone(const uint32_t frequency, const uint32_t duration)
{
if (frequency == 0 || duration == 0) return;

NVIC_DisableIRQ(TIM3_IRQn);
Expand All @@ -147,13 +149,18 @@ void tone(const uint32_t frequency, const uint32_t duration) {
}


void TIM3_IRQHandler(void) {
if ((TIM3->SR & 0x01) != 0) { // update interrupt flag
void TIM3_IRQHandler(void)
{
if ((TIM3->SR & 0x01) != 0) // update interrupt flag
{
TIM3->SR = (uint16_t)~(1<<0); // clear interrupt flag
if (toggles != 0) {
if (toggles != 0)
{
if(toggles > 0) toggles--;
GPIO_ToggleLevel(BUZZER_PIN);
} else {
GPIO_ToggleLevel(BUZZER_PIN);
}
else
{
TIM3->CR1 &= ~(0x01); // stop timer
}
}
Expand Down