Skip to content

Commit

Permalink
sdk: add I2S config
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Mar 22, 2024
1 parent 4945f31 commit 6e1afd5
Show file tree
Hide file tree
Showing 6 changed files with 2,294 additions and 3 deletions.
5 changes: 4 additions & 1 deletion sdk/boards/lilka_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"-DARDUINO_USB_CDC_ON_BOOT=1",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1",
"-DBOARD_HAS_PSRAM"
"-DBOARD_HAS_PSRAM",
"-DPIN_I2S_SD=2",
"-DPIN_I2S_FS=1",
"-DPIN_I2S_SCK=42"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
Expand Down
1 change: 1 addition & 0 deletions sdk/lib/lilka/src/lilka.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void begin() {
multiboot.begin();
spi_begin();
buzzer.begin(); // Play notification sound
audio.begin();
display.begin(); // Must be initialized BEFORE SD card
sdcard.begin();
controller.begin(); // Must be initialized AFTER SD card (since SD card somehow messes with GPIO)
Expand Down
3 changes: 1 addition & 2 deletions sdk/lib/lilka/src/lilka.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#include "lilka/sys.h"
#include "lilka/resources.h"
#include "lilka/fmath.h"
// #include "lua/luarunner.h"
// #include "mjs/mjsrunner.h"
#include "lilka/audio.h"

namespace lilka {
/// Ініціалізація Лілки
Expand Down
39 changes: 39 additions & 0 deletions sdk/lib/lilka/src/lilka/audio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "audio.h"
#include "hi.h"

namespace lilka {

Audio::Audio() {
}

void hi_task(void* arg);

void Audio::begin() {
I2S.begin(I2S_PHILIPS_MODE, 22050, 16);

// Signed 8-bit PCM
// for (int i = 0; i < hi_raw_size; i++) {
// I2S.write(hi_raw[i]);
// I2S.write(hi_raw[i]);
// }

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

void hi_task(void* arg) {
// Signed 16-bit PCM
const int16_t* hi = reinterpret_cast<const int16_t*>(hi_raw);

for (int i = 0; i < hi_raw_size / 2; i++) {
I2S.write(hi[i]);
I2S.write(hi[i]);
}

vTaskDelete(NULL);
}

Audio audio;

// I2SClass i2s(0, 0, LILKA_I2S_DOUT, LILKA_I2S_BCLK, LILKA_I2S_LRCK);

} // namespace lilka
18 changes: 18 additions & 0 deletions sdk/lib/lilka/src/lilka/audio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <I2S.h>
#include "lilka/config.h"

namespace lilka {

class Audio {
public:
Audio();
void begin();
};

extern Audio audio;

// extern I2SClass i2s;

} // namespace lilka
Loading

0 comments on commit 6e1afd5

Please sign in to comment.