Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

add I2S mode

Geo1e91010a61ad
diff --git a/platformio.ini b/platformio.ini
index 87c70d8e..c95cdf3f 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -30,7 +30,7 @@ build_flags =
-DDEVICE_CARDPUTER
; --- Pin in use ---
- -DPROTECTED_PINS="\"8,9,11,19,20,22,23,24,25,27,28,29,30,31,32,33,34,35,36,37,38,41,42\""
+ -DPROTECTED_PINS="\"8,9,11,19,20,22,23,24,25,27,28,29,30,31,32,33,34,35,36,37,38\""
; --- Builtin LED ---
-DLED_PIN=21
@@ -62,6 +62,13 @@ build_flags =
-DIR_TX_PIN=44
-DIR_RX_PIN=1
+ ; --- I2S ---
+ -DI2S_BCLK_PIN=41
+ -DI2S_LRCK_PIN=43
+ -DI2S_DATA_PIN=42
+ -DI2S_SAMPLE_RATE=44100
+ -DI2S_BITS=16
+
[env:m5stick]
platform = espressif32
@@ -111,4 +118,11 @@ build_flags =
; --- Infrared ---
-DIR_TX_PIN=19
- -DIR_RX_PIN=33
\ No newline at end of file
+ -DIR_RX_PIN=33
+
+ ; --- I2S ---
+ -DI2S_BCLK_PIN=0
+ -DI2S_LRCK_PIN=25
+ -DI2S_DATA_PIN=26
+ -DI2S_SAMPLE_RATE=16000
+ -DI2S_BITS=16
diff --git a/src/Controllers/I2sController.cpp b/src/Controllers/I2sController.cpp
new file mode 100644
index 00000000..0122be77
--- /dev/null
+++ b/src/Controllers/I2sController.cpp
@@ -0,0 +1,174 @@
+#include "I2sController.h"
+
+I2sController::I2sController(ITerminalView& terminalView, IInput& terminalInput,
+ I2sService& i2sService, ArgTransformer& argTransformer,
+ UserInputManager& userInputManager)
+ : terminalView(terminalView), terminalInput(terminalInput),
+ i2sService(i2sService), argTransformer(argTransformer),
+ userInputManager(userInputManager) {}
+
+void I2sController::handleCommand(const TerminalCommand& cmd) {
+ if (cmd.getRoot() == "config") {
+ handleConfig();
+ } else if (cmd.getRoot() == "play") {
+ handlePlay(cmd);
+ } else if (cmd.getRoot() == "record") {
+ handleRecord(cmd);
+ } else if (cmd.getRoot() == "reset") {
+ handleReset();
+ } else {
+ handleHelp();
+ }
+}
+
+void I2sController::handleConfig() {
+ terminalView.println("I2S Configuration:");
+
+ const auto& forbidden = state.getProtectedPins();
+
+ uint8_t bclk = userInputManager.readValidatedPinNumber("BCLK pin", state.getI2sBclkPin(), forbidden);
+ state.setI2sBclkPin(bclk);
+
+ uint8_t lrck = userInputManager.readValidatedPinNumber("LRCK/WS pin", state.getI2sLrckPin(), forbidden);
+ state.setI2sLrckPin(lrck);
+
+ uint8_t data = userInputManager.readValidatedPinNumber("DATA pin", state.getI2sDataPin(), forbidden);
+ state.setI2sDataPin(data);
+
+ uint32_t freq = userInputManager.readValidatedUint32("Sample rate (e.g. 44100)", state.getI2sSampleRate());
+ state.setI2sSampleRate(freq);
+
+ uint8_t bits = userInputManager.readValidatedUint8("Bits per sample (e.g. 16)", state.getI2sBitsPerSample());
+ state.setI2sBitsPerSample(bits);
+
+ i2sService.configureOutput(bclk, lrck, data, freq, bits);
+
+ terminalView.println("I2S configured.\n");
+}
+
+void I2sController::handlePlay(const TerminalCommand& cmd) {
+ auto args = argTransformer.splitArgs(cmd.getArgs());
+
+ if (!argTransformer.isValidNumber(cmd.getSubcommand()) ||
+ args.size() != 1 || !argTransformer.isValidNumber(args[0])) {
+ terminalView.println("Usage: play <frequency> <durationMs>");
+ return;
+ }
+
+ uint16_t freq = argTransformer.parseHexOrDec32(cmd.getSubcommand());
+ uint16_t duration = argTransformer.parseHexOrDec32(args[0]);
+
+ terminalView.println("\nI2S Play: Tone @ " + std::to_string(freq) + " Hz for " + std::to_string(duration) + " ms... Press [ENTER] to stop.\n");
+
+ i2sService.playToneInterruptible(freq, duration, [&]() -> bool {
+ char ch = terminalInput.readChar();
+ return ch == '\n' || ch == '\r';
+ });
+
+ terminalView.println("I2S Play: Done.");
+}
+
+void I2sController::handleRecord(const TerminalCommand& cmd) {
+ terminalView.println("I2S Record: In progress... Press [Enter] to stop.\n");
+
+ // Config input
+ i2sService.configureInput(
+ state.getI2sBclkPin(),
+ state.getI2sLrckPin(),
+ state.getI2sDataPin(),
+ state.getI2sSampleRate(),
+ state.getI2sBitsPerSample()
+ );
+
+ constexpr size_t batchSize = 2048;
+ constexpr size_t groupSize = 16;
+ std::vector<int16_t> buffer(batchSize);
+
+ while (true) {
+ // Read samples
+ size_t samplesRead = i2sService.recordSamples(buffer.data(), batchSize);
+
+ // Compress data
+ std::string line;
+ size_t samplesPerGroup = samplesRead / groupSize;
+
+ for (size_t g = 0; g < groupSize; ++g) {
+ int32_t mean = 0;
+ for (size_t i = 0; i < samplesPerGroup; ++i) {
+ size_t idx = g * samplesPerGroup + i;
+ mean += buffer[idx];
+ }
+ mean /= samplesPerGroup;
+
+ int32_t energy = 0;
+ for (size_t i = 0; i < samplesPerGroup; ++i) {
+ size_t idx = g * samplesPerGroup + i;
+ int32_t deviation = buffer[idx] - mean;
+ energy += abs(deviation);
+ }
+ int avg = energy / samplesPerGroup;
+
+ int level = map(avg, 0, 32767, 0, 99);
+ if (level < 0) level = 0;
+ else if (level > 99) level = 99;
+
+ if (level < 10)
+ line += "[0" + std::to_string(level) + "] ";
+ else
+ line += "[" + std::to_string(level) + "] ";
+ }
+
+ terminalView.println(line);
+
+ // Enter press
+ char ch = terminalInput.readChar();
+ if (ch == '\n' || ch == '\r') {
+ break;
+ }
+ }
+
+ // Reconfig ouput
+ i2sService.configureOutput(
+ state.getI2sBclkPin(),
+ state.getI2sLrckPin(),
+ state.getI2sDataPin(),
+ state.getI2sSampleRate(),
+ state.getI2sBitsPerSample()
+ );
+
+ terminalView.println("\nI2S Record: Stopped by user.\n");
+}
+
+void I2sController::handleHelp() {
+ terminalView.println("Available I2S commands:");
+ terminalView.println(" play <freq> [duration]");
+ terminalView.println(" record ");
+ terminalView.println(" reset");
+ terminalView.println(" config");
+}
+
+void I2sController::handleReset() {
+ i2sService.stop();
+
+ // Config output
+ i2sService.configureOutput(state.getI2sBclkPin(),
+ state.getI2sLrckPin(),
+ state.getI2sDataPin(),
+ state.getI2sSampleRate(),
+ state.getI2sBitsPerSample());
+
+ terminalView.println("I2S Reset: TX (output) mode.");
+}
+
+void I2sController::ensureConfigured() {
+ if (!configured) {
+ handleConfig();
+ configured = true;
+ } else {
+ // Reapply
+ i2sService.stop();
+ i2sService.configureOutput(state.getI2sBclkPin(), state.getI2sLrckPin(),
+ state.getI2sDataPin(), state.getI2sSampleRate(),
+ state.getI2sBitsPerSample());
+ }
+}
\ No newline at end of file
diff --git a/src/Controllers/I2sController.h b/src/Controllers/I2sController.h
new file mode 100644
index 00000000..e323d970
--- /dev/null
+++ b/src/Controllers/I2sController.h
@@ -0,0 +1,35 @@
+#pragma once
+
+#include <Arduino.h>
+#include "Interfaces/ITerminalView.h"
+#include "Interfaces/IInput.h"
+#include "Services/I2sService.h"
+#include "Transformers/ArgTransformer.h"
+#include "Managers/UserInputManager.h"
+#include "Models/TerminalCommand.h"
+#include "States/GlobalState.h"
+
+class I2sController {
+public:
+ I2sController(ITerminalView& terminalView, IInput& terminalInput,
+ I2sService& i2sService, ArgTransformer& argTransformer,
+ UserInputManager& userInputManager);
+
+ void handleCommand(const TerminalCommand& cmd);
+ void ensureConfigured();
+
+private:
+ void handleConfig();
+ void handlePlay(const TerminalCommand& cmd);
+ void handleRecord(const TerminalCommand& cmd);
+ void handleReset();
+ void handleHelp();
+
+ ITerminalView& terminalView;
+ IInput& terminalInput;
+ I2sService& i2sService;
+ ArgTransformer& argTransformer;
+ UserInputManager& userInputManager;
+ GlobalState& state = GlobalState::getInstance();
+ bool configured = false;
+};
diff --git a/src/Controllers/UtilityController.cpp b/src/Controllers/UtilityController.cpp
index 688cc550..c6f19f03 100644
--- a/src/Controllers/UtilityController.cpp
+++ b/src/Controllers/UtilityController.cpp
@@ -63,7 +63,7 @@ ModeEnum UtilityController::handleModeSelect() {
terminalView.println("Select mode:");
std::vector<ModeEnum> modes;
- for (int i = 0; i <= static_cast<int>(ModeEnum::JTAG); ++i) {
+ for (int i = 0; i < static_cast<int>(ModeEnum::COUNT); ++i) {
ModeEnum mode = static_cast<ModeEnum>(i);
std::string name = ModeEnumMapper::toString(mode);
if (!name.empty()) {
@@ -375,6 +375,13 @@ void UtilityController::handleHelp() {
terminalView.println(" 15. JTAG:");
terminalView.println(" scan - Scan JTAG/SWD pins");
+ terminalView.println("");
+ terminalView.println(" 16. I2S:");
+ terminalView.println(" play <freq> <ms> - Play sine wave for ms");
+ terminalView.println(" record - Read mic continuously");
+ terminalView.println(" reset - Reset to default");
+ terminalView.println(" config - Configure settings");
+
terminalView.println("");
terminalView.println(" Instructions (available in most modes):");
terminalView.println(" See documentation for instruction syntax.");
diff --git a/src/Dispatchers/ActionDispatcher.cpp b/src/Dispatchers/ActionDispatcher.cpp
index 15dd8063..bf20244c 100644
--- a/src/Dispatchers/ActionDispatcher.cpp
+++ b/src/Dispatchers/ActionDispatcher.cpp
@@ -129,6 +129,10 @@ void ActionDispatcher::dispatchCommand(const TerminalCommand& cmd) {
case ModeEnum::JTAG:
provider.getJtagController().handleCommand(cmd);
break;
+ case ModeEnum::I2S:
+ provider.getI2sController().handleCommand(cmd);
+ break;
+
}
// Config was handled in specific mode, we need to rerender the pinout view
@@ -379,6 +383,15 @@ void ActionDispatcher::setCurrentMode(ModeEnum newMode) {
config.setMappings({ "TCK GPIOX", "TMS GPIOY", "TDO GPIOZ", "TDI GPIOW" }); // TODO
provider.getJtagController().ensureConfigured();
break;
+ case ModeEnum::I2S:
+ provider.getI2sController().ensureConfigured();
+ config.setMappings({
+ "BCLK GPIO " + std::to_string(state.getI2sBclkPin()),
+ "LRCLK GPIO " + std::to_string(state.getI2sLrckPin()),
+ "DATA GPIO " + std::to_string(state.getI2sDataPin()),
+ "RATE " + std::to_string(state.getI2sSampleRate())
+ });
+ break;
}
// Show the new mode pinout
diff --git a/src/Enums/ModeEnum.h b/src/Enums/ModeEnum.h
index b0452a14..dbbac610 100644
--- a/src/Enums/ModeEnum.h
+++ b/src/Enums/ModeEnum.h
@@ -22,6 +22,8 @@ enum class ModeEnum {
Bluetooth,
WiFi,
JTAG,
+ I2S,
+ COUNT
};
class ModeEnumMapper {
@@ -43,7 +45,8 @@ public:
{ModeEnum::USB, "USB"},
{ModeEnum::Bluetooth, "BLUETOOTH"},
{ModeEnum::WiFi, "WIFI"},
- {ModeEnum::JTAG, "JTAG"}
+ {ModeEnum::JTAG, "JTAG"},
+ {ModeEnum::I2S, "I2S"}
};
auto it = map.find(proto);
@@ -74,7 +77,8 @@ public:
{"USB", ModeEnum::USB},
{"BLUETOOTH", ModeEnum::Bluetooth},
{"WIFI", ModeEnum::WiFi},
- {"JTAG", ModeEnum::JTAG}
+ {"JTAG", ModeEnum::JTAG},
+ {"I2S", ModeEnum::I2S}
};
std::string upper;
diff --git a/src/Providers/DependencyProvider.cpp b/src/Providers/DependencyProvider.cpp
index a83020c9..0bc34d34 100644
--- a/src/Providers/DependencyProvider.cpp
+++ b/src/Providers/DependencyProvider.cpp
@@ -20,6 +20,7 @@ DependencyProvider::DependencyProvider(ITerminalView& terminalView, IDeviceView&
pinService(),
bluetoothService(),
wifiService(),
+ i2sService(),
commandTransformer(),
instructionTransformer(),
argTransformer(),
@@ -42,6 +43,7 @@ DependencyProvider::DependencyProvider(ITerminalView& terminalView, IDeviceView&
dioController(terminalView, terminalInput, pinService, argTransformer),
ledController(terminalView, terminalInput, ledService),
bluetoothController(terminalView, terminalInput, bluetoothService, argTransformer),
+ i2sController(terminalView, terminalInput, i2sService, argTransformer, userInputManager),
wifiController(terminalView, terminalInput, wifiService, nvsService, argTransformer)
{}
@@ -66,6 +68,7 @@ HdUartService& DependencyProvider::getHdUartService() { return hdUartService; }
PinService& DependencyProvider::getPinService() { return pinService; }
WifiService& DependencyProvider::getWifiService() { return wifiService; }
BluetoothService& DependencyProvider::getBluetoothService() { return bluetoothService; }
+I2sService& DependencyProvider::getI2sService() { return i2sService; }
// Controllers
UartController& DependencyProvider::getUartController() { return uartController; }
@@ -83,6 +86,7 @@ DioController& DependencyProvider::getDioController() { return dioController; }
LedController& DependencyProvider::getLedController() { return ledController; }
WifiController& DependencyProvider::getWifiController() { return wifiController; }
BluetoothController& DependencyProvider::getBluetoothController() { return bluetoothController; }
+I2sController& DependencyProvider::getI2sController() { return i2sController; }
// Transformers
TerminalCommandTransformer& DependencyProvider::getCommandTransformer() { return commandTransformer; }
@@ -102,6 +106,7 @@ HorizontalSelector& DependencyProvider::getHorizontalSelector() { return horizon
TerminalTypeConfigurator& DependencyProvider::getTerminalTypeConfigurator() { return terminalTypeConfigurator ;}
+
// Disable interfaces
void DependencyProvider::disableAllProtocols() {
getUartService().end();
diff --git a/src/Providers/DependencyProvider.h b/src/Providers/DependencyProvider.h
index 173d4f3c..752d5dfa 100644
--- a/src/Providers/DependencyProvider.h
+++ b/src/Providers/DependencyProvider.h
@@ -24,6 +24,7 @@ and injecting shared instances of core components
#include "Services/PinService.h"
#include "Services/BluetoothService.h"
#include "Services/WifiService.h"
+#include "Services/I2sService.h"
#include "Controllers/UartController.h"
#include "Controllers/I2cController.h"
#include "Controllers/OneWireController.h"
@@ -39,6 +40,7 @@ and injecting shared instances of core components
#include "Controllers/LedController.h"
#include "Controllers/BluetoothController.h"
#include "Controllers/WifiController.h"
+#include "Controllers/I2sController.h"
#include "Transformers/TerminalCommandTransformer.h"
#include "Transformers/InstructionTransformer.h"
#include "Transformers/ArgTransformer.h"
@@ -77,7 +79,8 @@ public:
PinService& getPinService();
BluetoothService& getBluetoothService();
WifiService& getWifiService();
-
+ I2sService& getI2sService();
+
// Controllers
UartController& getUartController();
I2cController& getI2cController();
@@ -94,6 +97,7 @@ public:
LedController& getLedController();
BluetoothController& getBluetoothController();
WifiController& getWifiController();
+ I2sController& getI2sController();
// Transformers
TerminalCommandTransformer& getCommandTransformer();
@@ -137,6 +141,7 @@ private:
PinService pinService;
WifiService wifiService;
BluetoothService bluetoothService;
+ I2sService i2sService;
// Controllers
UartController uartController;
@@ -153,7 +158,8 @@ private:
LedController ledController;
WifiController wifiController;
BluetoothController bluetoothController;
-
+ I2sController i2sController;
+
// Transformers
TerminalCommandTransformer commandTransformer;
InstructionTransformer instructionTransformer;
diff --git a/src/Services/I2sService.cpp b/src/Services/I2sService.cpp
new file mode 100644
index 00000000..e24d6190
--- /dev/null
+++ b/src/Services/I2sService.cpp
@@ -0,0 +1,138 @@
+#include "I2sService.h"
+#include "math.h"
+
+void I2sService::configureOutput(uint8_t bclk, uint8_t lrck, uint8_t dout, uint32_t sampleRate, uint8_t bits) {
+ if (initialized) i2s_driver_uninstall(port);
+
+ i2s_config_t config = {
+ .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
+ .sample_rate = sampleRate,
+ .bits_per_sample = (i2s_bits_per_sample_t)(bits),
+ .channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
+ .communication_format = I2S_COMM_FORMAT_I2S,
+ .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
+ .dma_buf_count = 4,
+ .dma_buf_len = 256,
+ .use_apll = false,
+ .tx_desc_auto_clear = true,
+ .fixed_mclk = 0
+ };
+
+ i2s_pin_config_t pins = {
+ .bck_io_num = bclk,
+ .ws_io_num = lrck,
+ .data_out_num = dout,
+ .data_in_num = I2S_PIN_NO_CHANGE
+ };
+
+ i2s_driver_install(port, &config, 0, nullptr);
+ i2s_set_pin(port, &pins);
+
+ initialized = true;
+}
+
+void I2sService::configureInput(uint8_t bclk, uint8_t lrck, uint8_t din, uint32_t sampleRate, uint8_t bits) {
+ if (initialized) i2s_driver_uninstall(port);
+
+ i2s_config_t config = {
+ .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
+ .sample_rate = sampleRate,
+ .bits_per_sample = (i2s_bits_per_sample_t)(bits),
+ .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
+ .communication_format = I2S_COMM_FORMAT_I2S,
+ .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
+ .dma_buf_count = 4,
+ .dma_buf_len = 256,
+ .use_apll = false,
+ .tx_desc_auto_clear = false,
+ .fixed_mclk = 0
+ };
+
+ i2s_pin_config_t pins = {
+ .bck_io_num = bclk,
+ .ws_io_num = lrck,
+ .data_out_num = I2S_PIN_NO_CHANGE,
+ .data_in_num = din
+ };
+
+ i2s_driver_install(port, &config, 0, nullptr);
+ i2s_set_pin(port, &pins);
+
+ initialized = true;
+}
+
+void I2sService::playTone(uint16_t freq, uint16_t durationMs) {
+ if (!initialized) return;
+
+ const int sampleRate = 44100;
+ int samples = (sampleRate * durationMs) / 1000;
+ int16_t buffer[2];
+
+ for (int i = 0; i < samples; ++i) {
+ float t = (float)i / sampleRate;
+ int16_t sample = sinf(2.0f * PI * freq * t) * 32767;
+ buffer[0] = sample;
+ buffer[1] = sample;
+ size_t written;
+ i2s_write(port, buffer, sizeof(buffer), &written, portMAX_DELAY);
+ }
+}
+
+void I2sService::playToneInterruptible(uint16_t freq, uint32_t durationMs, std::function<bool()> shouldStop) {
+ const int sampleRate = 44100;
+ const int16_t amplitude = 32767;
+ const int chunkDurationMs = 20;
+ const int samplesPerChunk = (sampleRate * chunkDurationMs) / 1000;
+ int16_t buffer[2 * samplesPerChunk];
+
+ uint32_t elapsed = 0;
+ while (elapsed < durationMs) {
+ for (int i = 0; i < samplesPerChunk; ++i) {
+ float t = (float)(i + (elapsed * sampleRate / 1000)) / sampleRate;
+ int16_t sample = sinf(2.0f * PI * freq * t) * amplitude;
+ buffer[2 * i] = sample;
+ buffer[2 * i + 1] = sample;
+ }
+
+ size_t written;
+ i2s_write(port, buffer, sizeof(buffer), &written, portMAX_DELAY);
+ elapsed += chunkDurationMs;
+
+ if (shouldStop()) {
+ break;
+ }
+ }
+}
+
+size_t I2sService::recordSamples(int16_t* outBuffer, size_t sampleCount) {
+ if (!initialized) return 0;
+
+ size_t totalRead = 0;
+ size_t bytesToRead = sampleCount * sizeof(int16_t);
+
+ uint8_t* buffer = reinterpret_cast<uint8_t*>(outBuffer);
+ while (totalRead < bytesToRead) {
+ size_t readBytes = 0;
+ i2s_read(port, buffer + totalRead, bytesToRead - totalRead, &readBytes, portMAX_DELAY);
+ totalRead += readBytes;
+ }
+
+ return totalRead / sizeof(int16_t);
+}
+
+void I2sService::playRaw(const int16_t* samples, size_t count) {
+ if (!initialized) return;
+ size_t written;
+ i2s_write(port, samples, count * sizeof(int16_t), &written, portMAX_DELAY);
+}
+
+void I2sService::stop() {
+ if (initialized) {
+ i2s_driver_uninstall(port);
+ initialized = false;
+ }
+}
+
+bool I2sService::isInitialized() const {
+ return initialized;
+}
diff --git a/src/Services/I2sService.h b/src/Services/I2sService.h
new file mode 100644
index 00000000..b4b82218
--- /dev/null
+++ b/src/Services/I2sService.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include <stdint.h>
+#include <Arduino.h>
+#include <functional>
+#include <stddef.h>
+#include <string>
+#include "driver/i2s.h"
+
+class I2sService {
+public:
+ void configureOutput(uint8_t bclk, uint8_t lrck, uint8_t dout, uint32_t sampleRate = 44100, uint8_t bits = 16);
+ void configureInput(uint8_t bclk, uint8_t lrck, uint8_t din, uint32_t sampleRate = 44100, uint8_t bits = 16);
+
+ void playTone(uint16_t freq, uint16_t durationMs);
+ void playToneInterruptible(uint16_t freq, uint32_t durationMs, std::function<bool()> shouldStop);
+ void playRaw(const int16_t* samples, size_t count);
+ size_t recordSamples(int16_t* outBuffer, size_t sampleCount);
+ void stop();
+ bool isInitialized() const;
+
+private:
+ bool initialized = false;
+ i2s_port_t port = I2S_NUM_0;
+};
diff --git a/src/States/GlobalState.h b/src/States/GlobalState.h
index 081f9139..68a57ae2 100644
--- a/src/States/GlobalState.h
+++ b/src/States/GlobalState.h
@@ -77,6 +77,13 @@ private:
uint8_t infraredRxPin = 1;
InfraredProtocolEnum infraredProtocol = InfraredProtocolEnum::_NEC;
+ // I2S Default Configuration
+ uint8_t i2sBclkPin = 41;
+ uint8_t i2sLrckPin = 43;
+ uint8_t i2sDataPin = 42;
+ uint32_t i2sSampleRate = 44100;
+ uint8_t i2sBitsPerSample = 16;
+
// SD Card File Limits
size_t fileCountLimit = 512;
size_t fileCacheLimit = 64;
@@ -190,6 +197,19 @@ public:
InfraredProtocolEnum getInfraredProtocol() const { return infraredProtocol ; }
void setInfraredProtocol(InfraredProtocolEnum prot) { infraredProtocol = prot; }
+ // I2S
+ uint8_t getI2sBclkPin() const { return i2sBclkPin; }
+ uint8_t getI2sLrckPin() const { return i2sLrckPin; }
+ uint8_t getI2sDataPin() const { return i2sDataPin; }
+ uint32_t getI2sSampleRate() const { return i2sSampleRate; }
+ uint8_t getI2sBitsPerSample() const { return i2sBitsPerSample; }
+
+ void setI2sBclkPin(uint8_t pin) { i2sBclkPin = pin; }
+ void setI2sLrckPin(uint8_t pin) { i2sLrckPin = pin; }
+ void setI2sDataPin(uint8_t pin) { i2sDataPin = pin; }
+ void setI2sSampleRate(uint32_t rate) { i2sSampleRate = rate; }
+ void setI2sBitsPerSample(uint8_t bits) { i2sBitsPerSample = bits; }
+
// SD File Limits
size_t getFileCountLimit() const { return fileCountLimit; }
size_t getFileCacheLimit() const { return fileCacheLimit; }
@@ -266,6 +286,21 @@ public:
#ifdef IR_RX_PIN
infraredRxPin = IR_RX_PIN;
#endif
+ #ifdef I2S_BCLK_PIN
+ i2sBclkPin = I2S_BCLK_PIN;
+ #endif
+ #ifdef I2S_LRCK_PIN
+ i2sLrckPin = I2S_LRCK_PIN;
+ #endif
+ #ifdef I2S_DATA_PIN
+ i2sDataPin = I2S_DATA_PIN;
+ #endif
+ #ifdef I2S_SAMPLE_RATE
+ i2sSampleRate = I2S_SAMPLE_RATE;
+ #endif
+ #ifdef I2S_BITS
+ i2sBitsPerSample = I2S_BITS;
+ #endif
#ifdef PROTECTED_PINS
{
diff --git a/src/main.cpp b/src/main.cpp
index 94f28c64..668ba436 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,6 +36,7 @@ void setup() {
auto cfg = M5.config();
M5Cardputer.begin(cfg, true);
deviceView.setRotation(1);
+ M5Cardputer.Speaker.end();
CardputerInput deviceInput;
#endif