From faf0f77f66145507f4dfc2c78ca79246bc34a380 Mon Sep 17 00:00:00 2001 From: TomonobuHayakawa Date: Wed, 28 Aug 2024 15:50:10 +0900 Subject: [PATCH] Support eMMC. --- src/ParserFactory.cpp | 4 ++++ src/ParserFactory.h | 1 + src/SDSink.cpp | 35 ++++++++++++++++++++++++----- src/SDSink.h | 2 +- src/SFZSink.cpp | 42 ++++++++++++++++++++++++++--------- src/SFZSink.h | 2 +- src/YuruInstrumentConfig.h | 2 ++ src/YuruInstrumentConsole.cpp | 12 ++++++---- 8 files changed, 79 insertions(+), 21 deletions(-) diff --git a/src/ParserFactory.cpp b/src/ParserFactory.cpp index 0cc2e98..3fc062e 100644 --- a/src/ParserFactory.cpp +++ b/src/ParserFactory.cpp @@ -128,7 +128,11 @@ bool ParserFactory::createPlaylist(const String& path) { String file_name = file.name(); ScoreFileType type = getFileType(file_name); if (type == kScoreFileTypeMidi || type == kScoreFileTypeTxt) { +#ifdef EMMC_USE + String kSDFullPath = "/mnt/emmc/"; +#else String kSDFullPath = "/mnt/sd0/"; +#endif // Convert file name to full path - > current path String sd_current_path; if (file_name.startsWith(kSDFullPath)) { diff --git a/src/ParserFactory.h b/src/ParserFactory.h index 5bde9cd..89da840 100644 --- a/src/ParserFactory.h +++ b/src/ParserFactory.h @@ -15,6 +15,7 @@ #include #include "ScoreParser.h" +#include "YuruInstrumentConfig.h" /** * @brief @~japanese ScoreParser オブジェクトの Factory クラスです。 diff --git a/src/SDSink.cpp b/src/SDSink.cpp index 9b08bc6..587397e 100644 --- a/src/SDSink.cpp +++ b/src/SDSink.cpp @@ -8,7 +8,13 @@ #include "SDSink.h" +#ifdef EMMC_USE +#include +#define EMMC_POWER_PIN 26 +#define EMMC_EN 31 // High=eMMC / Low=SD +#else #include +#endif #include "WavReader.h" @@ -93,6 +99,26 @@ SDSink::~SDSink() { bool SDSink::begin() { NullFilter::begin(); + +#ifdef EMMC_USE + pinMode(EMMC_EN, OUTPUT); + digitalWrite(EMMC_EN, HIGH); //eMMC Select + + pinMode(EMMC_POWER_PIN, OUTPUT); + digitalWrite(EMMC_POWER_PIN, HIGH); + delay(50); + if (!eMMC.begin()) + { + Serial.println("eMMC can't begin"); + exit(1); + } +#else + SDClass sdcard; + if (!sdcard.begin()) { + error_printf("[%s::%s] error: cannot access sdcard\n", kClassName, __func__); + exit(1); + } +#endif for (size_t i = 0; i < sizeof(units_) / sizeof(units_[0]); i++) { if (units_[i].path.length() == 0) { continue; @@ -101,12 +127,11 @@ bool SDSink::begin() { if (units_[i].path[0] == '/') { file = File(units_[i].path.c_str()); } else { - SDClass sdcard; - if (!sdcard.begin()) { - error_printf("[%s::%s] error: cannot access sdcard\n", kClassName, __func__); - break; - } +#ifdef EMMC_USE + file = eMMC.open(units_[i].path.c_str()); +#else file = sdcard.open(units_[i].path.c_str()); +#endif } if (!file) { error_printf("[%s::%s] error: cannot open \"%s\"\n", kClassName, __func__, units_[i].path.c_str()); diff --git a/src/SDSink.h b/src/SDSink.h index bc4b22b..d1a4e13 100644 --- a/src/SDSink.h +++ b/src/SDSink.h @@ -19,7 +19,7 @@ #include #include "PcmRenderer.h" -#include "YuruInstrumentFilter.h" +#include "YuruInstrumentConfig.h" /** * @brief @~japanese ユーザーが定義した音源テーブルにしたがって、音源を再生する楽器部品です。 diff --git a/src/SFZSink.cpp b/src/SFZSink.cpp index 8be1ef9..c3e3fc0 100644 --- a/src/SFZSink.cpp +++ b/src/SFZSink.cpp @@ -15,8 +15,14 @@ #include #include - +#ifdef EMMC_USE +#include +#define EMMC_POWER_PIN 26 +#define EMMC_EN 31 // High=eMMC / Low=SD +#else #include +#endif + #include #include "path_util.h" @@ -335,19 +341,35 @@ bool SFZSink::begin() { NullFilter::begin(); debug_printf("[%s::%s] loading sfz\n", kClassName, __func__); - +#ifdef EMMC_USE + pinMode(EMMC_EN, OUTPUT); + digitalWrite(EMMC_EN, HIGH); //eMMC Select + + pinMode(EMMC_POWER_PIN, OUTPUT); + digitalWrite(EMMC_POWER_PIN, HIGH); + delay(50); + if (!eMMC.begin()) + { + Serial.println("eMMC can't begin"); + exit(1); + } +#else + SDClass sdcard; + if (!sdcard.begin()) { + error_printf("[%s::%s] error: cannot access sdcard\n", kClassName, __func__); + exit(1); + } +#endif File file; if (sfz_path_.startsWith("/")) { file = File(sfz_path_.c_str()); } else { - SDClass sdcard; - if (!sdcard.begin()) { - error_printf("[%s::%s] error: cannot access sdcard\n", kClassName, __func__); - ret = false; - } else { - file = sdcard.open(sfz_path_); - sfz_path_ = file.name(); - } +#ifdef EMMC_USE + file = eMMC.open(sfz_path_); +#else + file = sdcard.open(sfz_path_); +#endif + sfz_path_ = file.name(); } if (!file) { error_printf("[%s::%s] error: cannot open \"%s\"\n", kClassName, __func__, sfz_path_.c_str()); diff --git a/src/SFZSink.h b/src/SFZSink.h index d52e6c2..104c095 100644 --- a/src/SFZSink.h +++ b/src/SFZSink.h @@ -18,7 +18,7 @@ #include "SFZParser.h" #include "PcmRenderer.h" -#include "YuruInstrumentFilter.h" +#include "YuruInstrumentConfig.h" /** * @brief @~japanese 音源定義ファイル(SFZファイル)にしたがって、音源を再生する楽器部品です。 diff --git a/src/YuruInstrumentConfig.h b/src/YuruInstrumentConfig.h index 62b783f..b153ce9 100644 --- a/src/YuruInstrumentConfig.h +++ b/src/YuruInstrumentConfig.h @@ -16,6 +16,8 @@ #include "YuruInstrumentFilter.h" +#define EMMC_USE + /** * @brief @~japanese Filter のパラメータ設定を行うコンフィグファイルを実現するクラスです。 */ diff --git a/src/YuruInstrumentConsole.cpp b/src/YuruInstrumentConsole.cpp index 7a673b3..657d7f5 100644 --- a/src/YuruInstrumentConsole.cpp +++ b/src/YuruInstrumentConsole.cpp @@ -42,13 +42,17 @@ struct CommandSpec { }; static void PrintLsItem(File &file) { - const char sdroot[] = "/mnt/sd0/"; - const size_t sdroot_length = strlen(sdroot); +#ifdef EMMC_USE + const char root[] = "/mnt/emmc/"; +#else + const char root[] = "/mnt/sd0/"; +#endif + const size_t root_length = strlen(root); if (file) { // drop prefix if starts with "/mnt/sd0/" const char *path = file.name(); - if (strncmp(path, sdroot, sdroot_length) == 0) { - path = path + sdroot_length; + if (strncmp(path, root, root_length) == 0) { + path = path + root_length; } if (file.isDirectory()) { printf("%s/\n", path);