Skip to content

Commit

Permalink
sdk: configure I2S during runtime
Browse files Browse the repository at this point in the history
doc: add audio page
  • Loading branch information
and3rson committed Mar 22, 2024
1 parent 6e1afd5 commit 2be850a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
5 changes: 5 additions & 0 deletions docs/library/audio.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``Audio``: Звук (I2S)
=====================

.. doxygenclass:: lilka::Audio
:members:
1 change: 1 addition & 0 deletions docs/library/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
.. toctree::
:maxdepth: 1

audio
battery
buzzer
controller
Expand Down
5 changes: 1 addition & 4 deletions sdk/boards/lilka_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
"-DARDUINO_USB_CDC_ON_BOOT=1",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1",
"-DBOARD_HAS_PSRAM",
"-DPIN_I2S_SD=2",
"-DPIN_I2S_FS=1",
"-DPIN_I2S_SCK=42"
"-DBOARD_HAS_PSRAM"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
Expand Down
13 changes: 5 additions & 8 deletions sdk/lib/lilka/src/lilka/audio.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "audio.h"
#include "config.h"
#include "hi.h"

namespace lilka {
Expand All @@ -9,13 +10,9 @@ Audio::Audio() {
void hi_task(void* arg);

void Audio::begin() {
I2S.begin(I2S_PHILIPS_MODE, 22050, 16);
I2S.setAllPins(LILKA_I2S_BCLK, LILKA_I2S_LRCK, LILKA_I2S_DOUT, LILKA_I2S_DOUT, -1);

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

xTaskCreatePinnedToCore(hi_task, "hi_task", 4096, NULL, 1, NULL, 0);
}
Expand All @@ -29,11 +26,11 @@ void hi_task(void* arg) {
I2S.write(hi[i]);
}

I2S.end();

vTaskDelete(NULL);
}

Audio audio;

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

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

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

namespace lilka {

/// Клас для ініціалізації аудіо.
///
/// Цей клас лише встановлює піни для I2S і відтворює тестовий звук.
///
/// Для роботи з аудіо використовуйте клас I2S напряму: https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/api/i2s.html#sample-code
class Audio {
public:
Audio();
/// Налаштоувує піни для I2S і відтворює тестовий звук.
/// \warning Цей метод викликається автоматично при виклику `lilka::begin()`.
void begin();
};

extern Audio audio;

// extern I2SClass i2s;

} // namespace lilka
6 changes: 4 additions & 2 deletions sdk/lib/lilka/src/lilka/hi.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* Generated by bin2c, do not edit manually */
// clang-format off

#include <stdint.h>

/* Contents of file hi.raw */
const long int hi_raw_size = 35576;
const unsigned char hi_raw[35576] = {
const uint32_t hi_raw_size = 35576;
const uint8_t hi_raw[35576] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0xFD, 0xFF,
0xFF, 0xFF, 0x04, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x01, 0x00,
Expand Down

0 comments on commit 2be850a

Please sign in to comment.