h4yn0nnym0u5e
Well-known member
Right, OK, so I now have a demo. And have fixed a bug. And the DMAChannel fixes needed updating. It's just amazing (and a bit embarrassing...) how the software has rotted since last summer.
- new DMAChannel code attached;
- the source repo is here, and should be regarded as definitive - the zip file is just today's snapshot
- copy the DMAChannel.* and imxrt.h files to your Teensy 4 cores
- the dev/big-screen-T4 branch has had a bug fix
C++:
/*
* Example of correct setup of ST7796 DMA to avoid audio conflicts
* during asynchronous partial updates
*/
#include <ST7796_t3.h>
#include <Audio.h>
//=========================================================
// GUItool: begin automatically generated code
AudioSynthWaveform wav1; //xy=672,229
AudioSynthWaveform wav2; //xy=698,269
AudioOutputI2S i2sOut; //xy=950,241
AudioConnection patchCord1(wav1, 0, i2sOut, 0);
AudioConnection patchCord2(wav2, 0, i2sOut, 1);
AudioControlSGTL5000 audioShield; //xy=943,324
// GUItool: end automatically generated code
//---------------------------------------------------------
void randomWav(AudioSynthWaveform& wav)
{
wav.begin(0.5f,110.0f*random(1,7),WAVEFORM_SINE);
}
//=========================================================
// Change pin numbers to suit your hardware!
// CS DC RST
ST7796_t3 tft = ST7796_t3{29,10,33};
#define TFT_BL 34 // backlight pin
//---------------------------------------------------------
void randomRect(void)
{
if (!tft.asyncUpdateActive())
{
// choose new rectangle dimensions
int16_t x=999,y=999,w,h;
w = random(tft.width() / 2);
h = random(tft.height() / 2);
while (x+w >= tft.width())
x = random(tft.width());
while (y+h >= tft.height())
y = random(tft.height());
// write to frame buffer
tft.clearChangedArea();
tft.fillRect(x,y,w,h,random(65536));
tft.changeAsyncClipArea();
// update changed area only to screen
tft.updateScreenAsync(false,true);
}
}
//=========================================================
void setup()
{
AudioMemory(20);
audioShield.enable();
audioShield.volume(0.05f); // low volume
// standard TFT display setup
tft.begin();
pinMode(TFT_BL,OUTPUT);
digitalWriteFast(TFT_BL,HIGH);
tft.fillScreen(0);
tft.setRotation(1);
tft.print("Hello world");
// now prepare to use async area updates
tft.setAsyncInterruptPriority(224);
tft.useIntermediateBuffer(tft.width() * 2 * 2);
tft.useFrameBuffer(true);
tft.updateChangedAreasOnly(true);
}
//=========================================================
elapsedMillis audioTimer;
void loop()
{
if (audioTimer >= 250)
{
audioTimer = 0;
if (random(2))
randomWav(wav2);
else
randomWav(wav1);
}
randomRect();
}