Skip to content

Commit

Permalink
pico: use a low priority alarm for audio when core1 is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak committed Sep 26, 2023
1 parent f487e36 commit d8b3c10
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions 32blit-pico/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "hardware/structs/rosc.h"
#include "hardware/vreg.h"
#include "hardware/timer.h"
#include "pico/binary_info.h"
#include "pico/multicore.h"
#include "pico/rand.h"
Expand Down Expand Up @@ -104,6 +105,7 @@ void update(uint32_t);

bool core1_started = false;

#ifdef ENABLE_CORE1
void core1_main() {
core1_started = true;
multicore_lockout_victim_init();
Expand All @@ -118,6 +120,15 @@ void core1_main() {
}
}

#else
static void alarm_callback(uint alarm_num) {
update_audio(::now());

timer_hw->intr = 1 << alarm_num;
hardware_alarm_set_target(alarm_num, make_timeout_time_ms(5));
}
#endif

int main() {
#if OVERCLOCK_250
// Apply a modest overvolt, default is 1.10v.
Expand Down Expand Up @@ -193,6 +204,12 @@ int main() {

#if defined(ENABLE_CORE1)
multicore_launch_core1(core1_main);
#else
// fallback audio timer if core1 is unavailable / not enabled
int alarm_num = hardware_alarm_claim_unused(true);
hardware_alarm_set_callback(alarm_num, alarm_callback);
hardware_alarm_set_target(alarm_num, make_timeout_time_ms(5));
irq_set_priority(TIMER_IRQ_0 + alarm_num, PICO_LOWEST_IRQ_PRIORITY);
#endif

blit::set_screen_mode(ScreenMode::lores);
Expand All @@ -208,9 +225,6 @@ int main() {
update_display(now);
update_input();
int ms_to_next_update = tick(::now());
#if !defined(ENABLE_CORE1)
update_audio(now);
#endif
update_led();
update_usb();
update_multiplayer();
Expand Down

0 comments on commit d8b3c10

Please sign in to comment.