Skip to content

Commit

Permalink
Fix buildage for lilka v1
Browse files Browse the repository at this point in the history
  • Loading branch information
frostmorn committed Mar 24, 2024
1 parent 12e3c1a commit 005785d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 11 additions & 3 deletions firmware/keira/src/apps/nes/osd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <freertos/timers.h>

#include "driver.h"
#define OSD_OK 0
#define OSD_INIT_FAILED -1

extern "C" {
#include <event.h>
Expand Down Expand Up @@ -84,8 +86,7 @@ int logprint(const char* string) {

int osd_init() {
nofrendo_log_chain_logfunc(logprint);
osd_init_sound();
return 0;
return osd_init_sound();
}

void osd_shutdown() {
Expand Down Expand Up @@ -138,9 +139,15 @@ static void (*audio_callback)(void* buffer, int length) = NULL;
int16_t* audio_frame;
QueueHandle_t queue;
int osd_init_sound() {
#if LILKA_VERSION == 1
lilka::serial_err("This part of code should never be called. Audio not supported for this version of lilka");
return OSD_INIT_FAILED;
#elif LILKA_VERSION == 2
audio_frame = static_cast<int16_t*>(malloc(DEFAULT_FRAGSIZE * 4));
if (!audio_frame) {
lilka::serial_err("Failed to allocate audio_frame\n");
//
return OSD_INIT_FAILED;
}

esp_i2s::i2s_config_t cfg = {
Expand All @@ -165,7 +172,8 @@ int osd_init_sound() {
i2s_set_pin(esp_i2s::I2S_NUM_0, &pins);
i2s_zero_dma_buffer(esp_i2s::I2S_NUM_0);
audio_callback = 0;
return 0;
return OSD_OK;
#endif
}

void osd_stopsound() {
Expand Down
10 changes: 9 additions & 1 deletion sdk/lib/lilka/src/lilka/audio.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "audio.h"
#include "config.h"
#include "hi.h"

#include "serial.h"
namespace lilka {

Audio::Audio() {
Expand All @@ -10,14 +10,21 @@ Audio::Audio() {
void hi_task(void* arg);

void Audio::begin() {
#if LILKA_VERSION == 1
serial_err("Audio not supported in this version of lilka. Try to use Buzzer instead");
#elif LILKA_VERSION == 2
I2S.setAllPins(LILKA_I2S_BCLK, LILKA_I2S_LRCK, LILKA_I2S_DOUT, LILKA_I2S_DOUT, -1);

I2S.begin(I2S_PHILIPS_MODE, 22050, 16);

xTaskCreatePinnedToCore(hi_task, "hi_task", 4096, NULL, 1, NULL, 0);
#endif
}

void hi_task(void* arg) {
#if LILKA_VERSION == 1
serial_err("This part of code should never be called. Audio not supported for this version of lilka");
#elif LILKA_VERSION == 2
// Signed 16-bit PCM
const int16_t* hi = reinterpret_cast<const int16_t*>(hi_raw);

Expand All @@ -29,6 +36,7 @@ void hi_task(void* arg) {
I2S.end();

vTaskDelete(NULL);
#endif
}

Audio audio;
Expand Down

0 comments on commit 005785d

Please sign in to comment.