diff --git a/examples/aduio_pcm5102a/Aduio_pcm5102a.ino b/examples/aduio_pcm5102a/Aduio_pcm5102a.ino new file mode 100644 index 0000000..91755c9 --- /dev/null +++ b/examples/aduio_pcm5102a/Aduio_pcm5102a.ino @@ -0,0 +1,202 @@ +#include "Arduino.h" +#include "Audio.h" +#include "SD.h" +#include "SPI.h" +#include "FS.h" +#include "Ticker.h" +#include +#include "utilities.h" + +// Digital I/O used +#define SD_CS 48 +#define SPI_MOSI 33 +#define SPI_MISO 47 +#define SPI_SCK 36 +#define I2S_BCLK 7 +#define I2S_DOUT 8 +#define I2S_LRC 9 + +#define ASSERT_FLAG(x) \ + if (x == false) \ + Serial.printf("[%d] Execution error\n", __LINE__); + +Audio audio; +Ticker ticker; +struct tm timeinfo; +time_t now; + +uint8_t hour = 6; +uint8_t minute = 59; +uint8_t sec = 45; + +bool f_time = false; +int8_t timefile = -1; +char chbuf[100]; +bool audio_paly_flag = false; + +void tckr1s() +{ + sec++; + if (sec > 59) + { + sec = 0; + minute++; + } + if (minute > 59) + { + minute = 0; + hour++; + } + if (hour > 23) + { + hour = 0; + } + if (minute == 59 && sec == 50) + f_time = true; // flag will be set 10s before full hour + Serial.printf("%02d:%02d:%02d\n", hour, minute, sec); +} + +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) +{ + Serial.printf("Listing directory: %s\n", dirname); + + File root = fs.open(dirname); + if (!root) + { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) + { + Serial.println("Not a directory"); + return; + } + + File file = root.openNextFile(); + while (file) + { + if (file.isDirectory()) + { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) + { + listDir(fs, file.path(), levels - 1); + } + } + else + { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.println(file.size()); + } + file = root.openNextFile(); + } +} + +void sd_card_init(void) +{ + if (!SD.begin(SD_CS)) + { + Serial.println("Card Mount Failed"); + return; + } + uint8_t cardType = SD.cardType(); + + if (cardType == CARD_NONE) + { + Serial.println("No SD card attached"); + return; + } + + Serial.print("SD Card Type: "); + if (cardType == CARD_MMC) + { + Serial.println("MMC"); + } + else if (cardType == CARD_SD) + { + Serial.println("SDSC"); + } + else if (cardType == CARD_SDHC) + { + Serial.println("SDHC"); + } + else + { + Serial.println("UNKNOWN"); + } + + uint64_t cardSize = SD.cardSize() / (1024 * 1024); + Serial.printf("SD Card Size: %lluMB\n", cardSize); + + listDir(SD, "/voice_time", 0); +} + +void setup() +{ + Serial.begin(115200); + SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI); + + sd_card_init(); + + audio_paly_flag = audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT); + ASSERT_FLAG(audio_paly_flag); + + audio.setVolume(21); // 0...21 + ticker.attach(1, tckr1s); + + pinMode(BOARD_6609_EN, OUTPUT); + digitalWrite(BOARD_6609_EN, HIGH); +} + +void loop() +{ + audio.loop(); + if (f_time == true) + { + f_time = false; + timefile = 3; + uint8_t next_hour = hour + 1; + if (next_hour == 25) + next_hour = 1; + Serial.printf("Paly Audio\n"); + audio_paly_flag = audio.connecttoFS(SD, "/voice_time/BBIBBI.mp3"); + ASSERT_FLAG(audio_paly_flag); + } +} + +void audio_eof_mp3(const char *info) +{ // end of file + // Serial.printf("file :%s\n", info); + if (timefile > 0) + { + Serial.printf("timefile: %d\n", timefile); + if (timefile == 1) + { + audio_paly_flag = audio.connecttoFS(SD, "/voice_time/2-on.mp3"); + ASSERT_FLAG(audio_paly_flag); + timefile--; + } // stroke + if (timefile == 2) + { + audio_paly_flag = audio.connecttoFS(SD, "/voice_time/2-on.mp3"); + ASSERT_FLAG(audio_paly_flag); + timefile--; + } // precisely + if (timefile == 3) + { + audio_paly_flag = audio.connecttoFS(SD, "/voice_time/2-on.mp3"); + ASSERT_FLAG(audio_paly_flag); + timefile--; + } + } +} + +// optional +void audio_info(const char *info) +{ + Serial.print("info "); + Serial.println(info); +} diff --git a/examples/aduio_pcm5102a/sd_flies/1-off.mp3 b/examples/aduio_pcm5102a/sd_flies/1-off.mp3 new file mode 100644 index 0000000..ae985ef Binary files /dev/null and b/examples/aduio_pcm5102a/sd_flies/1-off.mp3 differ diff --git a/examples/aduio_pcm5102a/sd_flies/2-on.mp3 b/examples/aduio_pcm5102a/sd_flies/2-on.mp3 new file mode 100644 index 0000000..a448d99 Binary files /dev/null and b/examples/aduio_pcm5102a/sd_flies/2-on.mp3 differ diff --git a/examples/aduio_pcm5102a/sd_flies/3-start.mp3 b/examples/aduio_pcm5102a/sd_flies/3-start.mp3 new file mode 100644 index 0000000..fa4f475 Binary files /dev/null and b/examples/aduio_pcm5102a/sd_flies/3-start.mp3 differ diff --git a/examples/aduio_pcm5102a/sd_flies/4-ulink.mp3 b/examples/aduio_pcm5102a/sd_flies/4-ulink.mp3 new file mode 100644 index 0000000..46321fa Binary files /dev/null and b/examples/aduio_pcm5102a/sd_flies/4-ulink.mp3 differ diff --git a/examples/aduio_pcm5102a/sd_flies/5-link.mp3 b/examples/aduio_pcm5102a/sd_flies/5-link.mp3 new file mode 100644 index 0000000..4f4d3ce Binary files /dev/null and b/examples/aduio_pcm5102a/sd_flies/5-link.mp3 differ diff --git a/examples/aduio_pcm5102a/sd_flies/BBIBBI.mp3 b/examples/aduio_pcm5102a/sd_flies/BBIBBI.mp3 new file mode 100644 index 0000000..2c820bc Binary files /dev/null and b/examples/aduio_pcm5102a/sd_flies/BBIBBI.mp3 differ diff --git a/examples/aduio_pcm5102a/utilities.h b/examples/aduio_pcm5102a/utilities.h new file mode 100644 index 0000000..d072ed2 --- /dev/null +++ b/examples/aduio_pcm5102a/utilities.h @@ -0,0 +1,107 @@ +/** + * @file utilities.h + * @author ShallowGreen123 + * @license MIT + * @copyright Copyright (c) 2023 Shenzhen Xin Yuan Electronic Technology Co., Ltd + * @date 2023-04-11 + * + */ +#pragma once + +#define BOARD_I2C_ADDR_TOUCH 0x1A // Touch --- CST328 +#define BOARD_I2C_ADDR_LTR_553ALS 0x23 // Light sensor --- LTR_553ALS +#define BOARD_I2C_ADDR_GYROSCOPDE 0x28 // Gyroscope --- BHI260AP +#define BOARD_I2C_ADDR_KEYBOARD 0x34 // Keyboard --- TCA8418 +#define BOARD_I2C_ADDR_PMU_SY6970 0x6A // PMU --- SY6970 + +// IIC +#define BOARD_I2C_SDA 13 +#define BOARD_I2C_SCL 14 + +// Keyboard +#define BOARD_KEYBOARD_SCL BOARD_I2C_SCL +#define BOARD_KEYBOARD_SDA BOARD_I2C_SDA +#define BOARD_KEYBOARD_INT 15 +#define BOARD_KEYBOARD_LED 42 + +// Touch +#define BOARD_TOUCH_SCL BOARD_I2C_SCL +#define BOARD_TOUCH_SDA BOARD_I2C_SDA +#define BOARD_TOUCH_INT 12 +#define BOARD_TOUCH_RST 45 + +// LTR-553ALS-WA beam sensor +#define BOARD_ALS_SCL BOARD_I2C_SCL +#define BOARD_ALS_SDA BOARD_I2C_SDA +#define BOARD_ALS_INT 16 + +// Gyroscope +#define BOARD_GYROSCOPDE_SCL BOARD_I2C_SCL +#define BOARD_GYROSCOPDE_SDA BOARD_I2C_SDA +#define BOARD_GYROSCOPDE_INT 21 +#define BOARD_GYROSCOPDE_RST -1 + +// PMU +#define BOARD_PMU_SY6970_SCL BOARD_I2C_SCL +#define BOARD_PMU_SY6970_SDA BOARD_I2C_SDA +#define BOARD_PMU_SY6970_INT 16 + +// SPI +#define BOARD_SPI_SCK 36 +#define BOARD_SPI_MOSI 33 +#define BOARD_SPI_MISO 47 + +// Display +#define BOARD_EPD_SCK BOARD_SPI_SCK +#define BOARD_EPD_MOSI BOARD_SPI_MOSI +#define BOARD_EPD_DC 35 +#define BOARD_EPD_CS 34 +#define BOARD_EPD_BUSY 37 +#define BOARD_EPD_RST -1 + +// SD card +#define BOARD_SD_CS 48 +#define BOARD_SD_SCK BOARD_SPI_SCK +#define BOARD_SD_MOSI BOARD_SPI_MOSI +#define BOARD_SD_MISO BOARD_SPI_MISO + +// Lora +#define BOARD_LORA_SCK BOARD_SPI_SCK +#define BOARD_LORA_MOSI BOARD_SPI_MOSI +#define BOARD_LORA_MISO BOARD_SPI_MISO +#define BOARD_LORA_CS 3 +#define BOARD_LORA_BUSY 6 +#define BOARD_LORA_RST 4 +#define BOARD_LORA_INT 5 + +// GPS +#define BOARD_GPS_RXD 44 +#define BOARD_GPS_TXD 43 +#define BOARD_GPS_PPS 1 + +// A7682E Modem +#define BOARD_A7682E_RI 7 +#define BOARD_A7682E_ITR 8 +#define BOARD_A7682E_RST 9 +#define BOARD_A7682E_RXD 10 +#define BOARD_A7682E_TXD 11 +#define BOARD_A7682E_PWRKEY 2 + +// Boot pin +#define BOARD_BOOT_PIN 0 + +// Motor pin +#define BOARD_MOTOR_PIN 40 + +// EN +#define BOARD_GPS_EN 39 // enable GPS module +#define BOARD_1V8_EN 38 // enable gyroscope module +#define BOARD_6609_EN 41 // enable 7682 module +#define BOARD_LORA_EN 46 // enable LORA module + +// Mic +#define BOARD_MIC_DATA 17 +#define BOARD_MIC_CLOCK 18 +// ------------------------------------------------- + + diff --git a/hardware/PCM5102A/T-HeadJack V1.0.pdf b/hardware/PCM5102A/T-HeadJack V1.0.pdf new file mode 100644 index 0000000..3edfcb4 Binary files /dev/null and b/hardware/PCM5102A/T-HeadJack V1.0.pdf differ diff --git a/hardware/PCM5102A/pcm5102a.pdf b/hardware/PCM5102A/pcm5102a.pdf new file mode 100644 index 0000000..0508577 Binary files /dev/null and b/hardware/PCM5102A/pcm5102a.pdf differ diff --git a/platformio.ini b/platformio.ini index bdd0cc5..b572d3e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,6 +13,7 @@ src_dir = examples/factory ; src_dir = examples/A7682E/test_AT ; src_dir = examples/test_factory ; src_dir = examples/test_sd +; src_dir = examples/aduio_pcm5102a ;------------------ ;- Display @@ -72,6 +73,7 @@ build_flags = -DCORE_DEBUG_LEVEL=0 lib_deps = + esphome/ESP32-audioI2S@^2.0.7 zinggjm/GxEPD2@1.5.5 jgromes/RadioLib@6.4.2 lewisxhe/SensorLib@^0.2.0