Browse Source

Merge pull request #246 from FrankBoesing/patch-1

Add F-RAM CY15B104
dds
Paul Stoffregen 7 years ago
parent
commit
9485e7bd4f
2 changed files with 53 additions and 26 deletions
  1. +49
    -23
      effect_delay_ext.cpp
  2. +4
    -3
      effect_delay_ext.h

+ 49
- 23
effect_delay_ext.cpp View File



//#define INTERNAL_TEST //#define INTERNAL_TEST


// While 20 MHz (Teensy actually uses 16 MHz in most cases) and even 24 MHz
// have worked well in testing at room temperature with 3.3V power, to fully
// meet all the worst case timing specs, the SPI clock low time would need
// to be 40ns (12.5 MHz clock) for the single chip case and 51ns (9.8 MHz
// clock) for the 6-chip memoryboard with 74LCX126 buffers.
//
// Timing analysis and info is here:
// https://forum.pjrc.com/threads/29276-Limits-of-delay-effect-in-audio-library?p=97506&viewfull=1#post97506
#define SPISETTING SPISettings(20000000, MSBFIRST, SPI_MODE0)

// Use these with the audio adaptor board (should be adjustable by the user...) // Use these with the audio adaptor board (should be adjustable by the user...)
#define SPIRAM_MOSI_PIN 7 #define SPIRAM_MOSI_PIN 7
#define SPIRAM_MISO_PIN 12 #define SPIRAM_MISO_PIN 12
activemask = 0; activemask = 0;
head_offset = 0; head_offset = 0;
memory_type = type; memory_type = type;

SPI.setMOSI(SPIRAM_MOSI_PIN);
SPI.setMISO(SPIRAM_MISO_PIN);
SPI.setSCK(SPIRAM_SCK_PIN);

SPI.begin();
if (type == AUDIO_MEMORY_23LC1024) { if (type == AUDIO_MEMORY_23LC1024) {
#ifdef INTERNAL_TEST #ifdef INTERNAL_TEST
memsize = 8000; memsize = 8000;
pinMode(MEMBOARD_CS2_PIN, OUTPUT); pinMode(MEMBOARD_CS2_PIN, OUTPUT);
digitalWriteFast(MEMBOARD_CS0_PIN, LOW); digitalWriteFast(MEMBOARD_CS0_PIN, LOW);
digitalWriteFast(MEMBOARD_CS1_PIN, LOW); digitalWriteFast(MEMBOARD_CS1_PIN, LOW);
digitalWriteFast(MEMBOARD_CS2_PIN, LOW);
digitalWriteFast(MEMBOARD_CS2_PIN, LOW);
} else if (type == AUDIO_MEMORY_CY15B104) {
#ifdef INTERNAL_TEST
memsize = 8000;
#else
memsize = 262144;
#endif
pinMode(SPIRAM_CS_PIN, OUTPUT);
digitalWriteFast(SPIRAM_CS_PIN, HIGH);
} else { } else {
return; return;
} }
allocated[type] += samples; allocated[type] += samples;
memory_length = samples; memory_length = samples;


SPI.setMOSI(SPIRAM_MOSI_PIN);
SPI.setMISO(SPIRAM_MISO_PIN);
SPI.setSCK(SPIRAM_SCK_PIN);

SPI.begin();
zero(0, memory_length); zero(0, memory_length);
} }


static int16_t testmem[8000]; // testing only static int16_t testmem[8000]; // testing only
#endif #endif



#define SPISETTING SPISettings(20000000, MSBFIRST, SPI_MODE0)

// While 20 MHz (Teensy actually uses 16 MHz in most cases) and even 24 MHz
// have worked well in testing at room temperature with 3.3V power, to fully
// meet all the worst case timing specs, the SPI clock low time would need
// to be 40ns (12.5 MHz clock) for the single chip case and 51ns (9.8 MHz
// clock) for the 6-chip memoryboard with 74LCX126 buffers.
//
// Timing analysis and info is here:
// https://forum.pjrc.com/threads/29276-Limits-of-delay-effect-in-audio-library?p=97506&viewfull=1#post97506

void AudioEffectDelayExternal::read(uint32_t offset, uint32_t count, int16_t *data) void AudioEffectDelayExternal::read(uint32_t offset, uint32_t count, int16_t *data)
{ {
uint32_t addr = memory_begin + offset; uint32_t addr = memory_begin + offset;
#ifdef INTERNAL_TEST #ifdef INTERNAL_TEST
while (count) { *data++ = testmem[addr++]; count--; } // testing only while (count) { *data++ = testmem[addr++]; count--; } // testing only
#else #else
if (memory_type == AUDIO_MEMORY_23LC1024) {
if (memory_type == AUDIO_MEMORY_23LC1024 ||
memory_type == AUDIO_MEMORY_CY15B104) {
addr *= 2; addr *= 2;
SPI.beginTransaction(SPISETTING); SPI.beginTransaction(SPISETTING);
digitalWriteFast(SPIRAM_CS_PIN, LOW); digitalWriteFast(SPIRAM_CS_PIN, LOW);
} }
digitalWriteFast(SPIRAM_CS_PIN, HIGH); digitalWriteFast(SPIRAM_CS_PIN, HIGH);
SPI.endTransaction(); SPI.endTransaction();
} else if (memory_type == AUDIO_MEMORY_MEMORYBOARD) {
} else if (memory_type == AUDIO_MEMORY_CY15B104) {
addr *= 2;

SPI.beginTransaction(SPISETTING);
digitalWriteFast(SPIRAM_CS_PIN, LOW);
SPI.transfer(0x06); //write-enable before every write
digitalWriteFast(SPIRAM_CS_PIN, HIGH);
asm volatile ("NOP\n NOP\n NOP\n NOP\n NOP\n NOP\n");
digitalWriteFast(SPIRAM_CS_PIN, LOW);
SPI.transfer16((0x02 << 8) | (addr >> 16));
SPI.transfer16(addr & 0xFFFF);
while (count) {
int16_t w = 0;
if (data) w = *data++;
SPI.transfer16(w);
count--;
}
digitalWriteFast(SPIRAM_CS_PIN, HIGH);
SPI.endTransaction();
} else if (memory_type == AUDIO_MEMORY_MEMORYBOARD) {
SPI.beginTransaction(SPISETTING); SPI.beginTransaction(SPISETTING);
while (count) { while (count) {
uint32_t chip = (addr >> 16) + 1; uint32_t chip = (addr >> 16) + 1;
} }
#endif #endif
} }




+ 4
- 3
effect_delay_ext.h View File

#include "spi_interrupt.h" #include "spi_interrupt.h"


enum AudioEffectDelayMemoryType_t { enum AudioEffectDelayMemoryType_t {
AUDIO_MEMORY_23LC1024 = 0,
AUDIO_MEMORY_MEMORYBOARD = 1,
AUDIO_MEMORY_UNDEFINED = 2
AUDIO_MEMORY_23LC1024 = 0, // 128k x 8 S-RAM
AUDIO_MEMORY_MEMORYBOARD = 1,
AUDIO_MEMORY_CY15B104 = 2, // 512k x 8 F-RAM
AUDIO_MEMORY_UNDEFINED = 3
}; };


class AudioEffectDelayExternal : public AudioStream class AudioEffectDelayExternal : public AudioStream

Loading…
Cancel
Save