mirror of https://github.com/radex/radmatrix.git
Compare commits
No commits in common. "2cc5f3d6fccb2f86383bb8a5bd96583b65be60f9" and "634406bb2e5993a58808166f2b39caf7eae232fa" have entirely different histories.
2cc5f3d6fc
...
634406bb2e
|
@ -14,5 +14,6 @@ board = pico
|
|||
framework = arduino
|
||||
board_build.core = earlephilhower
|
||||
board_build.filesystem_size = 0.5m
|
||||
; lib_deps =
|
||||
lib_deps =
|
||||
; khoih-prog/RP2040_SD@^1.0.1
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#define AUDIO_PIN 2
|
||||
|
||||
#define AUDIO_RATE 22000.0f
|
||||
#define BUFFER_LEN 512*4
|
||||
#define BUFFER_LEN 512*2
|
||||
#define BUFFER_LEN_MS (BUFFER_LEN / AUDIO_RATE) * 1000.0f
|
||||
|
||||
extern uint8_t wav_buffer_0[BUFFER_LEN];
|
||||
|
|
|
@ -56,52 +56,3 @@ int32_t gfx_decoder_handleLoop() {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void gfx_decoder_setTestFrame() {
|
||||
uint8_t buffer[ROW_COUNT * COL_COUNT] = {0};
|
||||
|
||||
// le boxes
|
||||
for (int i = 0; i < 8; i++) {
|
||||
uint8_t color = 1 << i;
|
||||
int startX = (i % 4) * 10;
|
||||
int startY = (i / 4) * 10;
|
||||
|
||||
// box with only 1<<n color
|
||||
for (int x = startX; x < startX + 10; x++) {
|
||||
for (int y = startY + 5; y < startY + 10; y++) {
|
||||
buffer[y * ROW_COUNT + x] = color;
|
||||
}
|
||||
}
|
||||
|
||||
// box with 1<<n - 1 color for comparison
|
||||
for (int x = startX; x < startX + 10; x++) {
|
||||
for (int y = startY; y < startY + 5; y++) {
|
||||
buffer[y * ROW_COUNT + x] = color - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// full color
|
||||
for (int x = 30; x < ROW_COUNT; x++) {
|
||||
for (int y = 20; y < 25; y++) {
|
||||
buffer[y * ROW_COUNT + x] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
// smooth gradient - lower range
|
||||
for (int x = 0; x < ROW_COUNT; x++) {
|
||||
for (int y = 30; y < 35; y++) {
|
||||
buffer[y * ROW_COUNT + x] = x;
|
||||
}
|
||||
}
|
||||
|
||||
// smooth gradient
|
||||
float delta = 256 / (COL_COUNT);
|
||||
for (int x = 0; x < ROW_COUNT; x++) {
|
||||
for (int y = 35; y < 40; y++) {
|
||||
buffer[y * ROW_COUNT + x] = (x + 1) * delta;
|
||||
}
|
||||
}
|
||||
|
||||
leds_set_framebuffer(buffer);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,5 @@ extern uint8_t gfxFrameBuffer[6400];
|
|||
|
||||
int32_t gfx_decoder_loadNextFrame();
|
||||
int32_t gfx_decoder_handleLoop();
|
||||
void gfx_decoder_setTestFrame();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,8 +11,6 @@ uint pusher_sm = 255; // invalid
|
|||
uint delay_sm = 255; // invalid
|
||||
uint row_sm = 255; // invalid
|
||||
|
||||
#define LEDS_PIO_CLKDIV 1
|
||||
|
||||
// NOTE: RCLK, SRCLK capture on *rising* edge
|
||||
inline void pulsePin(uint8_t pin) {
|
||||
gpio_put(pin, HIGH);
|
||||
|
@ -36,36 +34,16 @@ inline void outputEnable(uint8_t pin, bool enable) {
|
|||
uint8_t brightnessPhase = 0;
|
||||
|
||||
// delays in nanoseconds
|
||||
#define NS_TO_DELAY(ns) (ns / NS_PER_CYCLE / LEDS_PIO_CLKDIV)
|
||||
#define NS_TO_DELAY(ns) ns / NS_PER_CYCLE
|
||||
uint32_t brightnessPhaseDelays[COLOR_BITS] = {
|
||||
// NOTE: 100ns seems to be the minimum that's (barely) visible
|
||||
/* 1 */ NS_TO_DELAY(170),
|
||||
/* 2 */ NS_TO_DELAY(180),
|
||||
/* 4 */ NS_TO_DELAY(210),
|
||||
/* 8 */ NS_TO_DELAY(540),
|
||||
/* 16 */ NS_TO_DELAY(2300), // x2
|
||||
/* 32 */ NS_TO_DELAY(3000), // x4
|
||||
/* 64 */ NS_TO_DELAY(2500), // x10
|
||||
/* 128 */ NS_TO_DELAY(3300), // x20
|
||||
};
|
||||
|
||||
#define DITHERING_PHASES 20;
|
||||
uint8_t ditheringPhase = 0;
|
||||
uint8_t brightnessPhaseDithering[COLOR_BITS] = {
|
||||
// Out of DITHERING_PHASES, how many of these should a given
|
||||
// brightness phase be displayed?
|
||||
// NOTE: This is done brecause for small delays, pixel pushing dominates the time, making
|
||||
// the display's duty cycle (and hence brightness) low. But since these less significant bits
|
||||
// contribute little to the overall brightness, and overall displaying time is short (a fraction of
|
||||
// a framerate), we can skip displaying these small brightness levels most of the time.
|
||||
/* 1 */ 1,
|
||||
/* 2 */ 1,
|
||||
/* 4 */ 1,
|
||||
/* 8 */ 1,
|
||||
/* 16 */ 2,
|
||||
/* 32 */ 4,
|
||||
/* 64 */ 10,
|
||||
/* 128 */ 20,
|
||||
NS_TO_DELAY(50),
|
||||
NS_TO_DELAY(100),
|
||||
NS_TO_DELAY(200),
|
||||
NS_TO_DELAY(500),
|
||||
NS_TO_DELAY(1500),
|
||||
NS_TO_DELAY(6000),
|
||||
NS_TO_DELAY(20000),
|
||||
NS_TO_DELAY(60000),
|
||||
};
|
||||
|
||||
// NOTE: Alignment required to allow 4-byte reads
|
||||
|
@ -124,18 +102,18 @@ void leds_set_framebuffer(uint8_t *buffer) {
|
|||
}
|
||||
|
||||
// set row shifting data
|
||||
bool firstRow = y == 0;
|
||||
uint32_t extraPulses = 0;
|
||||
bool firstRow = y == (ROW_COUNT - 1);
|
||||
uint32_t rowPulses = 1;
|
||||
|
||||
if (moduleY == 0) {
|
||||
extraPulses++;
|
||||
rowPulses++;
|
||||
}
|
||||
|
||||
if (moduleY == 7 || moduleY == 14 || (moduleY == 0 && yModule != 0)) {
|
||||
extraPulses++;
|
||||
rowPulses++;
|
||||
}
|
||||
|
||||
uint32_t rowData = firstRow | (extraPulses << 1);
|
||||
uint32_t rowData = firstRow | (rowPulses << 1);
|
||||
ledBuffer[bi][outputYOffset + COL_MODULES] = rowData;
|
||||
}
|
||||
}
|
||||
|
@ -205,16 +183,11 @@ void leds_initRenderer() {
|
|||
multicore_launch_core1(main2);
|
||||
}
|
||||
|
||||
void leds_nextPhase();
|
||||
|
||||
void leds_render() {
|
||||
if (!ledBufferReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
// next brightness phase
|
||||
leds_nextPhase();
|
||||
|
||||
auto buffer = ledBuffer[brightnessPhase];
|
||||
auto delayData = brightnessPhaseDelays[brightnessPhase];
|
||||
|
||||
|
@ -236,19 +209,9 @@ void leds_render() {
|
|||
// set delay data
|
||||
pio_sm_put_blocking(leds_pio, delay_sm, delayData);
|
||||
}
|
||||
}
|
||||
|
||||
void leds_nextPhase() {
|
||||
brightnessPhase++;
|
||||
|
||||
if (brightnessPhase == COLOR_BITS) {
|
||||
brightnessPhase = 0;
|
||||
ditheringPhase = (ditheringPhase + 1) % DITHERING_PHASES;
|
||||
}
|
||||
|
||||
while (ditheringPhase >= brightnessPhaseDithering[brightnessPhase]) {
|
||||
brightnessPhase++;
|
||||
}
|
||||
// next brightness phase
|
||||
brightnessPhase = (brightnessPhase + 1) % COLOR_BITS;
|
||||
}
|
||||
|
||||
void leds_initPusher() {
|
||||
|
@ -259,7 +222,7 @@ void leds_initPusher() {
|
|||
uint offset = pio_add_program(pio, &leds_px_pusher_program);
|
||||
|
||||
pio_sm_config config = leds_px_pusher_program_get_default_config(offset);
|
||||
sm_config_set_clkdiv_int_frac(&config, LEDS_PIO_CLKDIV, 0);
|
||||
sm_config_set_clkdiv_int_frac(&config, 1, 0);
|
||||
|
||||
// Shift OSR to the right, autopull
|
||||
sm_config_set_out_shift(&config, true, true, 32);
|
||||
|
@ -299,7 +262,7 @@ void leds_initRowSelector() {
|
|||
uint offset = pio_add_program(pio, &leds_row_selector_program);
|
||||
|
||||
pio_sm_config config = leds_row_selector_program_get_default_config(offset);
|
||||
sm_config_set_clkdiv_int_frac(&config, LEDS_PIO_CLKDIV, 0);
|
||||
sm_config_set_clkdiv_int_frac(&config, 1, 0);
|
||||
|
||||
// Shift OSR to the right, autopull
|
||||
sm_config_set_out_shift(&config, true, true, 32);
|
||||
|
@ -328,7 +291,7 @@ void leds_initDelay() {
|
|||
uint offset = pio_add_program(pio, &leds_delay_program);
|
||||
|
||||
pio_sm_config config = leds_delay_program_get_default_config(offset);
|
||||
sm_config_set_clkdiv_int_frac(&config, LEDS_PIO_CLKDIV, 0);
|
||||
sm_config_set_clkdiv_int_frac(&config, 1, 0);
|
||||
|
||||
// Shift OSR to the right, autopull
|
||||
sm_config_set_out_shift(&config, true, true, 32);
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
|
||||
#define COLOR_BITS 8
|
||||
#define FPS 30
|
||||
#define MS_PER_FRAME (1000 / FPS)
|
||||
#define MS_PER_FRAME 1000 / FPS
|
||||
|
||||
#define CPU_MHZ 125
|
||||
#define NS_PER_CYCLE (1000 / CPU_MHZ)
|
||||
#define NS_PER_CYCLE 1000 / CPU_MHZ
|
||||
|
||||
void leds_init();
|
||||
void leds_initRenderer();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.define public irq_did_latch 0
|
||||
.define public irq_delaying 1
|
||||
.define public irq_row_selected 1
|
||||
.define public irq_delaying 2
|
||||
|
||||
; TODO: check if delays can be lowered with a PCB
|
||||
.define public srclk_0_delay 1
|
||||
|
@ -48,7 +48,7 @@ entry_point:
|
|||
.wrap_target
|
||||
; LSB=1 indicates first (bottom) row, ergo, high SER for the first pulse
|
||||
out pins, 1 side 0 [srclk_0_delay]
|
||||
; The rest of the word indicates number of extra SRCLK pulses
|
||||
; The rest of the word indicates number of SRCLK pulses
|
||||
out x, 31
|
||||
loop:
|
||||
; pulse SRCLK x times
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
#endif
|
||||
|
||||
#define irq_did_latch 0
|
||||
#define irq_delaying 1
|
||||
#define irq_row_selected 1
|
||||
#define irq_delaying 2
|
||||
#define srclk_0_delay 1
|
||||
#define srclk_1_delay 2
|
||||
#define rclk_1_delay 3
|
||||
|
@ -29,7 +29,7 @@ static const uint16_t leds_px_pusher_program_instructions[] = {
|
|||
0x1a41, // 2: jmp x--, 1 side 1 [2]
|
||||
0x7028, // 3: out x, 8 side 0
|
||||
0x0020, // 4: jmp !x, 0
|
||||
0x2042, // 5: wait 0 irq, 2
|
||||
0x2041, // 5: wait 0 irq, 1
|
||||
0x20c1, // 6: wait 1 irq, 1
|
||||
0xc000, // 7: irq nowait 0
|
||||
0xe301, // 8: set pins, 1 [3]
|
||||
|
@ -98,10 +98,10 @@ static inline pio_sm_config leds_row_selector_program_get_default_config(uint of
|
|||
static const uint16_t leds_delay_program_instructions[] = {
|
||||
// .wrap_target
|
||||
0x20c0, // 0: wait 1 irq, 0
|
||||
0xc002, // 1: irq nowait 2
|
||||
0xc001, // 1: irq nowait 1
|
||||
0x6020, // 2: out x, 32
|
||||
0x1043, // 3: jmp x--, 3 side 0
|
||||
0xd842, // 4: irq clear 2 side 1
|
||||
0xd841, // 4: irq clear 1 side 1
|
||||
// .wrap
|
||||
};
|
||||
|
||||
|
|
|
@ -30,8 +30,6 @@ void setup() {
|
|||
sd_loadPlaylist();
|
||||
|
||||
loadVideo(0);
|
||||
|
||||
// gfx_decoder_setTestFrame();
|
||||
}
|
||||
|
||||
size_t currentVideoIndex = 0;
|
||||
|
@ -63,9 +61,7 @@ void nextSong() {
|
|||
|
||||
void loop() {
|
||||
if (digitalRead(4) == LOW) {
|
||||
delay(100);
|
||||
nextSong();
|
||||
delay(50);
|
||||
}
|
||||
|
||||
// if (Serial.available() > 0) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
// #include <RP2040_SD.h>
|
||||
#include "sd.h"
|
||||
#include "audio.h"
|
||||
#include "gfx_decoder.h"
|
||||
|
@ -10,22 +11,17 @@
|
|||
|
||||
#define SD_DET_PIN 28
|
||||
|
||||
#define SD_PIN_SS 17
|
||||
#define SD_PIN_SCK 18
|
||||
#define SD_PIN_MOSI 19
|
||||
#define SD_PIN_MISO 16
|
||||
|
||||
static spi_t spi = {
|
||||
.hw_inst = spi0,
|
||||
.miso_gpio = SD_PIN_MISO,
|
||||
.mosi_gpio = SD_PIN_MOSI,
|
||||
.sck_gpio = SD_PIN_SCK,
|
||||
.miso_gpio = 4,
|
||||
.mosi_gpio = 3,
|
||||
.sck_gpio = 2,
|
||||
.baud_rate = 10 * 1000 * 1000,
|
||||
};
|
||||
|
||||
static sd_spi_if_t spi_if = {
|
||||
.spi = &spi,
|
||||
.ss_gpio = SD_PIN_SS,
|
||||
.ss_gpio = 7,
|
||||
};
|
||||
|
||||
static sd_card_t sd_card = {
|
||||
|
@ -33,85 +29,212 @@ static sd_card_t sd_card = {
|
|||
.spi_if_p = &spi_if,
|
||||
};
|
||||
|
||||
size_t sd_get_num() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
sd_card_t *sd_get_by_num(size_t num) {
|
||||
if (num == 0) {
|
||||
return &sd_card;
|
||||
void sd_test() {
|
||||
FATFS fs;
|
||||
FRESULT fr = f_mount(&fs, "", 1);
|
||||
if (FR_OK != fr) panic("f_mount error: %s (%d)\n", FRESULT_str(fr), fr);
|
||||
FIL fil;
|
||||
const char* const filename = "filename.txt";
|
||||
fr = f_open(&fil, filename, FA_OPEN_APPEND | FA_WRITE);
|
||||
if (FR_OK != fr && FR_EXIST != fr)
|
||||
panic("f_open(%s) error: %s (%d)\n", filename, FRESULT_str(fr), fr);
|
||||
if (f_printf(&fil, "Hello, world!\n") < 0) {
|
||||
printf("f_printf failed\n");
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
fr = f_close(&fil);
|
||||
if (FR_OK != fr) {
|
||||
printf("f_close error: %s (%d)\n", FRESULT_str(fr), fr);
|
||||
}
|
||||
f_unmount("");
|
||||
}
|
||||
|
||||
/*
|
||||
#if PIN_SPI_SS != 17
|
||||
#error "PIN_SPI_SS must be 17"
|
||||
#endif
|
||||
#if PIN_SPI_SCK != 18
|
||||
#error "PIN_SPI_SCK must be 18"
|
||||
#endif
|
||||
#if PIN_SPI_MOSI != 19
|
||||
#error "PIN_SPI_MOSI must be 19"
|
||||
#endif
|
||||
#if PIN_SPI_MISO != 16
|
||||
#error "PIN_SPI_MISO must be 16"
|
||||
#endif
|
||||
*/
|
||||
|
||||
void setupSDPins() {
|
||||
// TODO: Is that even needed if we use built-in SPI?
|
||||
/*
|
||||
pinMode(PIN_SPI_MISO, INPUT);
|
||||
pinMode(PIN_SPI_SS, OUTPUT);
|
||||
digitalWrite(PIN_SPI_SS, HIGH);
|
||||
pinMode(PIN_SPI_SCK, OUTPUT);
|
||||
pinMode(PIN_SPI_MOSI, OUTPUT);
|
||||
pinMode(SD_DET_PIN, INPUT_PULLUP);
|
||||
*/
|
||||
}
|
||||
|
||||
bool isSDCardInserted() {
|
||||
return digitalRead(SD_DET_PIN) == LOW;
|
||||
}
|
||||
|
||||
#define CHECK_RESULT(result, caller) \
|
||||
if (result != FR_OK) { \
|
||||
Serial.print(caller); \
|
||||
Serial.print(" error: "); \
|
||||
Serial.print(FRESULT_str(result)); \
|
||||
Serial.print(" ("); \
|
||||
Serial.print(result); \
|
||||
Serial.println(")"); \
|
||||
}
|
||||
|
||||
FATFS *fs;
|
||||
/*
|
||||
void printSDConfig();
|
||||
void testSDCard();
|
||||
void printSDStats();
|
||||
void printDirectory(File dir, int numTabs);
|
||||
*/
|
||||
|
||||
void setupSD() {
|
||||
Serial.println("Initializing SD card...");
|
||||
/*
|
||||
SPI.begin();
|
||||
|
||||
sd_init_driver();
|
||||
// printSDConfig();
|
||||
|
||||
fs = (FATFS*) malloc(sizeof(FATFS));
|
||||
FRESULT result = f_mount(fs, "", 1);
|
||||
CHECK_RESULT(result, "f_mount");
|
||||
if (!SD.begin(20000000, PIN_SPI_SS)) {
|
||||
Serial.println("SD Initialization failed!");
|
||||
// Serial.print("Error code: ");
|
||||
// Serial.println(SD.card.errorCode(), HEX);
|
||||
while (true) {}
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("SD Initialization done");
|
||||
|
||||
// testSDCard();
|
||||
// printSDStats(SD.volume);
|
||||
|
||||
// File root = SD.open("/");
|
||||
// printDirectory(root, 0);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
void printSDConfig() {
|
||||
Serial.println(BOARD_NAME);
|
||||
Serial.println(RP2040_SD_VERSION);
|
||||
|
||||
Serial.print("Initializing SD card with SS = ");
|
||||
Serial.println(PIN_SPI_SS);
|
||||
Serial.print("SCK = ");
|
||||
Serial.println(PIN_SPI_SCK);
|
||||
Serial.print("MOSI = ");
|
||||
Serial.println(PIN_SPI_MOSI);
|
||||
Serial.print("MISO = ");
|
||||
Serial.println(PIN_SPI_MISO);
|
||||
}
|
||||
|
||||
void testSDCard() {
|
||||
File myFile = SD.open("test.txt", FILE_WRITE);
|
||||
|
||||
// if the file opened okay, write to it:
|
||||
if (myFile) {
|
||||
Serial.print("Writing to test.txt...");
|
||||
myFile.println("testing 1, 2, 3.");
|
||||
myFile.close();
|
||||
Serial.println("done.");
|
||||
} else {
|
||||
Serial.println("error opening test.txt");
|
||||
}
|
||||
|
||||
// re-open the file for reading:
|
||||
myFile = SD.open("test.txt");
|
||||
if (myFile) {
|
||||
Serial.println("test.txt:");
|
||||
|
||||
while (myFile.available()) {
|
||||
Serial.write(myFile.read());
|
||||
}
|
||||
myFile.close();
|
||||
} else {
|
||||
Serial.println("error opening test.txt");
|
||||
}
|
||||
}
|
||||
|
||||
void printDirectory(File dir, int numTabs) {
|
||||
while (true) {
|
||||
File entry = dir.openNextFile();
|
||||
|
||||
if (!entry) {
|
||||
// no more files
|
||||
break;
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < numTabs; i++) {
|
||||
Serial.print('\t');
|
||||
}
|
||||
|
||||
Serial.print(entry.name());
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
Serial.println("/");
|
||||
printDirectory(entry, numTabs + 1);
|
||||
} else {
|
||||
// files have sizes, directories do not
|
||||
Serial.print("\t\t");
|
||||
Serial.println(entry.size(), DEC);
|
||||
}
|
||||
entry.close();
|
||||
}
|
||||
}
|
||||
|
||||
void printSDStats(RP2040_SdVolume volume) {
|
||||
Serial.print("Clusters: ");
|
||||
Serial.println(volume.clusterCount());
|
||||
Serial.print("Blocks x Cluster: ");
|
||||
Serial.println(volume.blocksPerCluster());
|
||||
|
||||
Serial.print("Total Blocks: ");
|
||||
Serial.println(volume.blocksPerCluster() * volume.clusterCount());
|
||||
Serial.println();
|
||||
|
||||
// print the type and size of the first FAT-type volume
|
||||
uint32_t volumesize;
|
||||
Serial.print("Volume type is: FAT");
|
||||
Serial.println(volume.fatType(), DEC);
|
||||
|
||||
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
|
||||
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
|
||||
volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1 KB)
|
||||
Serial.print("Volume size (KB): ");
|
||||
Serial.println(volumesize);
|
||||
Serial.print("Volume size (MB): ");
|
||||
volumesize /= 1024;
|
||||
Serial.println(volumesize);
|
||||
Serial.print("Volume size (GB): ");
|
||||
Serial.println((float)volumesize / 1024.0);
|
||||
}
|
||||
*/
|
||||
String playlist[128] = {};
|
||||
size_t playlistSize = 0;
|
||||
|
||||
void sd_loadPlaylist() {
|
||||
/*
|
||||
auto path = "video/playlist.txt";
|
||||
|
||||
FIL playlistFile;
|
||||
FRESULT result = f_open(&playlistFile, path, FA_READ);
|
||||
CHECK_RESULT(result, "playlist file open");
|
||||
if (!SD.exists(path)) {
|
||||
Serial.println("Could not find playlist for videos :(");
|
||||
return;
|
||||
}
|
||||
|
||||
auto playlistFile = SD.open(path, FILE_READ);
|
||||
Serial.println("Playlist file opened");
|
||||
|
||||
char playlist_buffer[512];
|
||||
auto fileSize = f_size(&playlistFile);
|
||||
|
||||
auto fileSize = playlistFile.size();
|
||||
if (fileSize > sizeof(playlist_buffer)) {
|
||||
Serial.print("Playlist file too large, max: ");
|
||||
Serial.println(sizeof(playlist_buffer));
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int bytesRead;
|
||||
result = f_read(&playlistFile, &playlist_buffer, fileSize, &bytesRead);
|
||||
CHECK_RESULT(result, "playlist file read");
|
||||
|
||||
if (bytesRead != fileSize) {
|
||||
Serial.print("playlist file read error: read ");
|
||||
Serial.print(bytesRead);
|
||||
Serial.print(" bytes, expected ");
|
||||
Serial.println(fileSize);
|
||||
if (playlistFile.read(&playlist_buffer, sizeof(playlist_buffer)) != fileSize) {
|
||||
Serial.println("Could not read playlist file");
|
||||
return;
|
||||
}
|
||||
|
||||
result = f_close(&playlistFile);
|
||||
CHECK_RESULT(result, "playlist file close");
|
||||
playlistFile.close();
|
||||
|
||||
Serial.println("Parsing playlist...");
|
||||
|
||||
|
@ -148,11 +271,13 @@ void sd_loadPlaylist() {
|
|||
Serial.print(": ");
|
||||
Serial.println(playlist[i]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
FIL *audioFile;
|
||||
// File audioFile;
|
||||
|
||||
void sd_loadAudio(size_t index) {
|
||||
/*
|
||||
if (index >= playlistSize) {
|
||||
Serial.println("Index out of range");
|
||||
return;
|
||||
|
@ -160,42 +285,37 @@ void sd_loadAudio(size_t index) {
|
|||
|
||||
auto path = "video/" + playlist[index] + "/audio.bin";
|
||||
|
||||
FRESULT result;
|
||||
|
||||
if (audioFile) {
|
||||
result = f_close(audioFile);
|
||||
CHECK_RESULT(result, "audio file close");
|
||||
free(audioFile);
|
||||
if (!SD.exists(path)) {
|
||||
Serial.println("Audio not found :(");
|
||||
return;
|
||||
}
|
||||
|
||||
audioFile = (FIL*) malloc(sizeof(FIL));
|
||||
result = f_open(audioFile, path.c_str(), FA_READ);
|
||||
CHECK_RESULT(result, "audio file open");
|
||||
if (audioFile) {
|
||||
audioFile.close();
|
||||
}
|
||||
|
||||
audioFile = SD.open(path, FILE_READ);
|
||||
Serial.println("Audio file opened");
|
||||
|
||||
audio_stop();
|
||||
|
||||
// load two buffers' worth of audio
|
||||
unsigned int bytesRead;
|
||||
result = f_read(audioFile, &wav_buffer_0, BUFFER_LEN, &bytesRead);
|
||||
CHECK_RESULT(result, "first audio sample");
|
||||
if (bytesRead < BUFFER_LEN) {
|
||||
if (audioFile.read(&wav_buffer_0, BUFFER_LEN) < BUFFER_LEN) {
|
||||
Serial.println("Could not read first sample");
|
||||
return;
|
||||
}
|
||||
|
||||
result = f_read(audioFile, &wav_buffer_1, BUFFER_LEN, &bytesRead);
|
||||
CHECK_RESULT(result, "second audio sample");
|
||||
if (bytesRead < BUFFER_LEN) {
|
||||
if (audioFile.read(&wav_buffer_1, BUFFER_LEN) < BUFFER_LEN) {
|
||||
Serial.println("Could not read second sample");
|
||||
return;
|
||||
}
|
||||
|
||||
audio_start();
|
||||
*/
|
||||
}
|
||||
|
||||
void sd_loadNextAudio() {
|
||||
/*
|
||||
if (!next_buffer_requested) {
|
||||
return;
|
||||
}
|
||||
|
@ -203,14 +323,11 @@ void sd_loadNextAudio() {
|
|||
|
||||
auto b4 = millis();
|
||||
auto next_buffer = wav_buffer1_active ? &wav_buffer_0 : &wav_buffer_1;
|
||||
|
||||
FRESULT result;
|
||||
unsigned int bytesRead;
|
||||
|
||||
result = f_read(audioFile, next_buffer, BUFFER_LEN, &bytesRead);
|
||||
CHECK_RESULT(result, "audio sample");
|
||||
auto bytesRead = audioFile.read(next_buffer, BUFFER_LEN);
|
||||
|
||||
if (bytesRead < BUFFER_LEN) {
|
||||
// Serial.println("End of audio file, rewinding...");
|
||||
// audioFile.seek(0);
|
||||
Serial.println("End of audio.");
|
||||
audio_stop();
|
||||
} else {
|
||||
|
@ -220,11 +337,14 @@ void sd_loadNextAudio() {
|
|||
Serial.print(" bytes from audio file in ");
|
||||
Serial.print(millis() - b4);
|
||||
Serial.println("ms");
|
||||
*/
|
||||
* /
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
bool sd_loadGfxFrameLengths(size_t index) {
|
||||
return false;
|
||||
/*
|
||||
if (index >= playlistSize) {
|
||||
Serial.println("Index out of range");
|
||||
return false;
|
||||
|
@ -232,42 +352,39 @@ bool sd_loadGfxFrameLengths(size_t index) {
|
|||
|
||||
auto path = "video/" + playlist[index] + "/gfx_len.bin";
|
||||
|
||||
FIL lengthsFile;
|
||||
FRESULT result = f_open(&lengthsFile, path.c_str(), FA_READ);
|
||||
CHECK_RESULT(result, "frame lengths file open");
|
||||
if (!SD.exists(path)) {
|
||||
Serial.println("Frame lengths file not found :(");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto fileSize = f_size(&lengthsFile);
|
||||
auto lengthsFile = SD.open(path, FILE_READ);
|
||||
auto fileSize = lengthsFile.size();
|
||||
|
||||
if (fileSize > sizeof(gfxFrameLengthsBuffer)) {
|
||||
Serial.println("Frame lengths file too large");
|
||||
return false;
|
||||
}
|
||||
Serial.println(fileSize);
|
||||
|
||||
frameCount = fileSize / sizeof(uint16_t);
|
||||
|
||||
unsigned int bytesRead;
|
||||
result = f_read(&lengthsFile, &gfxFrameLengthsBuffer, fileSize, &bytesRead);
|
||||
CHECK_RESULT(result, "playlist file read");
|
||||
|
||||
if (bytesRead != fileSize) {
|
||||
Serial.print("frame lengths file read error: read ");
|
||||
Serial.print(bytesRead);
|
||||
Serial.print(" bytes, expected ");
|
||||
Serial.println(fileSize);
|
||||
return false;
|
||||
while (lengthsFile.available()) {
|
||||
lengthsFile.read(&gfxFrameLengthsBuffer, sizeof(gfxFrameLengthsBuffer));
|
||||
}
|
||||
|
||||
result = f_close(&lengthsFile);
|
||||
CHECK_RESULT(result, "frame lengths file close");
|
||||
lengthsFile.close();
|
||||
Serial.println("Done reading frame lengths");
|
||||
|
||||
return true;
|
||||
*/
|
||||
}
|
||||
|
||||
FIL *gfxFile;
|
||||
// File gfxFile;
|
||||
|
||||
uint16_t frameIdx = 0;
|
||||
|
||||
bool sd_loadGfxBlob(size_t index) {
|
||||
return false;
|
||||
/*
|
||||
if (index >= playlistSize) {
|
||||
Serial.println("Index out of range");
|
||||
return false;
|
||||
|
@ -275,32 +392,28 @@ bool sd_loadGfxBlob(size_t index) {
|
|||
|
||||
auto path = "video/" + playlist[index] + "/gfx.bin";
|
||||
|
||||
FRESULT result;
|
||||
|
||||
if (gfxFile) {
|
||||
result = f_close(gfxFile);
|
||||
CHECK_RESULT(result, "gfx file close");
|
||||
free(gfxFile);
|
||||
if (!SD.exists(path)) {
|
||||
Serial.println("Gfx blob file not found :(");
|
||||
return false;
|
||||
}
|
||||
|
||||
gfxFile = (FIL*) malloc(sizeof(FIL));
|
||||
result = f_open(gfxFile, path.c_str(), FA_READ);
|
||||
CHECK_RESULT(result, "gfx blob file open");
|
||||
|
||||
gfxFile = SD.open(path, FILE_READ);
|
||||
Serial.println("Opened video frames");
|
||||
|
||||
frameIdx = 0;
|
||||
|
||||
return true;
|
||||
*/
|
||||
}
|
||||
|
||||
// Returns size of frame read or -1 if error
|
||||
int32_t sd_loadNextFrame() {
|
||||
return -1;
|
||||
/*
|
||||
if (frameIdx > 0) {
|
||||
// return -1;
|
||||
}
|
||||
|
||||
if (!gfxFile) {
|
||||
if (!gfxFile || !gfxFile.available()) {
|
||||
Serial.println("Gfx file not available");
|
||||
return -1;
|
||||
}
|
||||
|
@ -312,19 +425,14 @@ int32_t sd_loadNextFrame() {
|
|||
|
||||
// get size of frame png
|
||||
auto frameSize = gfxFrameLengthsBuffer[frameIdx];
|
||||
|
||||
if (frameSize > sizeof(gfxFrameBuffer)) {
|
||||
Serial.print("Frame too large: ");
|
||||
Serial.println(frameSize);
|
||||
while (true) {}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// read data
|
||||
unsigned int bytesRead;
|
||||
FRESULT result = f_read(gfxFile, &gfxFrameBuffer, frameSize, &bytesRead);
|
||||
CHECK_RESULT(result, "playlist file read");
|
||||
|
||||
auto bytesRead = gfxFile.read(&gfxFrameBuffer, frameSize);
|
||||
if (bytesRead < frameSize) {
|
||||
Serial.println("Could not read the entire frame");
|
||||
return -1;
|
||||
|
@ -332,6 +440,9 @@ int32_t sd_loadNextFrame() {
|
|||
|
||||
// increment
|
||||
if (frameIdx == frameCount - 1) {
|
||||
// Serial.println("Last frame, rewinding...");
|
||||
// gfxFile.seek(0);
|
||||
// frameIdx = 0;
|
||||
Serial.println("Last frame, next video!");
|
||||
return -2;
|
||||
} else {
|
||||
|
@ -339,4 +450,5 @@ int32_t sd_loadNextFrame() {
|
|||
}
|
||||
|
||||
return frameSize;
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue