MicroMod Beta Testing

@KurtE
Just gave your 'V' mode a try with the ST7789 and....
1. Sparkfun config - worked very nicely, however when I exited video mode the TMM was basically hung. Could not enter any other commands and had to do a restart.
2. Non-Sparkfun - Video all broken into different pieces, basically out of synch. Has same problem when you exit video mode - not still experimenting on this one.

UPDATE 1: non-sparkfun. Changed frame rate to 15 and video quality 100% better - shows a little tearing but thats about it. 'd' continuous is seems to be perfect.

I saw some hangs leaving Vid mode as well in some combination with ILI9341 - thought it was just an invalid command series but it was there. Some part of the DMA left active doing interrupt spasms?
 
@mjs513 does the "case 0x30:" work as "case 48:" ?

I've got outdoor things to do as well. Spring sun is sprouting trees in deck cracks and a pickup firewood to unload.

I did GIT that ST7735 lib ... Would be nice to have a second setup to avoid display swapping $10 SFun cam on a T_4.1? KurtE does all your DMA work have the needed pins for T_4.1 (T_4.0) - and an SPI display?
Seems we all got this - but that goes to the question of how Teensy useful/critical this camera is?
Nope:
Code:
hm01b0_testv3:503: error: duplicate case value
       case 48:
       ^
hm01b0_testv3:489: error: previously used here
     case '0':
     ^
only wants single characters - maybe redo section for way it was done in CSI
 
Is the the switch 'VAR' a byte type by any chance?

Or something odd confusing the compiler optimization?

switch ( VAR&0xF )
 
Nope:
Code:
hm01b0_testv3:503: error: duplicate case value
       case 48:
       ^
hm01b0_testv3:489: error: previously used here
     case '0':
     ^
only wants single characters - maybe redo section for way it was done in CSI

'0' and 48 and 0x30 are all the same thing - the Ascii code for the zero character.
 
'0' and 48 and 0x30 are all the same thing - the Ascii code for the zero character.

You know never thought about looking up the ascii character - no wonder I was having a problem - thanks :) So obvious after the fact
 
Sorry guys, been sort of distracted with other things today. Like trying to help get Lynxmotion LSS servos to talk to T4.1...

Will be interesting still to figure out what the differences are between Sparkfun settings and non-sparkfun settings. It would be nice to be able to be able to setup LA to see the signals. Paul's board looks like it should work well for that. I also ordered 2 more cameras from Sparkfun which shipped today, plus I have another ATP board, I ordered from Amazon, which I think arrived today. May be few days before I get to town again.

The idea was/is to use that breakout board and hope 3.3v is OK for the feeding the camera. By their doc looks like Max 3v... Wonder if I can breadboard and put in Diode? to drop the voltage some...

But first need to go through and test the ST77xx code some more... But someone hid most of my ST7789 displays... Or maybe I organized them at some point that I knew I remember where I put them :D
 
Pushed up some changes to the ST7735 stuff, which helps so far with starting and stopping async...

Test sketch I modified from my ILI9341 sketch...

Tomorrow will check it out on T3.6 to make sure I did not screw things up...
Code:
#define TFT_ST7789 1
//#define TFT_ILI9341 1
#ifdef TFT_ST7789
//ST7735 Adafruit 320x240 display
#include <ST7789_t3.h>
#include <font_Arial.h>
#include <font_ArialBold.h>
#else
#include <ILI9341_fonts.h>
#include <ILI9341_t3n.h>
#include <font_Arial.h>
#include <font_ArialBold.h>
#endif

elapsedMicros _dt;
#define dtSTART {_dt=0;}
#define dtEND(a) { Serial.printf( "\n%s()_%s : dt %ul us", __func__, a, (uint32_t)_dt);}

#define UPDATE_HALF_FRAME

#define ROTATION 3

#include "SPI.h"


//------------------------------------
#ifdef TFT_ST7789
#define TFT_DC  1   // "TX1" on left side of Sparkfun ML Carrier
#define TFT_CS  4   // "CS" on left side of Sparkfun ML Carrier
#define TFT_RST  0  // "RX1" on left side of Sparkfun ML Carrier
ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_RST);

#define TFT_BLACK ST77XX_BLACK
#define TFT_YELLOW ST77XX_YELLOW
#define TFT_RED   ST77XX_RED
#define TFT_GREEN ST77XX_GREEN
#define TFT_BLUE  ST77XX_BLUE
#define TCENTER ST7735_t3::CENTER
uint16_t our_pallet[] = {
  TFT_BLACK,  TFT_RED, TFT_GREEN,  TFT_BLUE,
  ST77XX_YELLOW, ST77XX_ORANGE, ST77XX_CYAN,ST77XX_PINK
};

#else
#define TFT_BLACK ILI9341_BLACK
#define TFT_YELLOW ILI9341_YELLOW
#define TFT_RED   ILI9341_RED
#define TFT_GREEN ILI9341_GREEN
#define TFT_BLUE  ILI9341_BLUE
#define TCENTER ILI9341_t3n::CENTER
#define USE_SPI2
#ifdef USE_SPI2
#define TFT_DC 44
#define TFT_RST 46
#define TFT_CS 47 // any pin will work not hardware

// T4.1 SCK pins on SDCARD
#define USE_MEMORY_PINS
#ifdef USE_MEMORY_PINS
#define TFT_SCK 49
#define TFT_MISO 54
#define TFT_MOSI 50
#else
#define TFT_SCK 45
#define TFT_MISO 42
#define TFT_MOSI 43
#endif
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);
#else
#define TFT_RST 8
#define TFT_DC  9
#define TFT_CS 10
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
#endif
uint16_t our_pallet[] = {
  ILI9341_BLACK,  ILI9341_RED, ILI9341_GREEN,  ILI9341_BLUE,
  ILI9341_YELLOW, ILI9341_ORANGE, ILI9341_CYAN, ILI9341_PINK
};
#endif

#define COUNT_SHUTDOWN_FRAMES 16
volatile uint8_t shutdown_cont_update_count = 0xff;
uint16_t *tft_frame_buffer = nullptr;
#define FRAME_BUFFER_SIZE (320*240*2)
elapsedMicros my_us;


void setup() {
  while (!Serial && (millis() < 4000)) ;
  Serial.begin(115200);
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  Serial.printf("Begin: CS:%d, DC:%dRST: %d\n", TFT_CS, TFT_DC, TFT_RST);
#ifdef TFT_ST7789
  tft.init(240, 320);           // Init ST7789 320x240
#else
  tft.begin(26000000);
#endif  
  tft.setRotation(ROTATION);
  tft.fillScreen(TFT_RED);
  delay(500);
  tft.fillScreen(TFT_GREEN);
  delay(500);
  tft.fillScreen(TFT_BLUE);
  delay(500);
  tft.fillScreen(TFT_BLACK);
  delay(500);

  tft.useFrameBuffer(true);
  tft.fillScreen(TFT_BLACK);
  tft.setCursor(TCENTER, TCENTER);
  tft.setTextColor(TFT_RED);
  tft.setFont(Arial_20_Bold);
  tft.println("*** Auto start ***");
  tft.updateScreen();
  tft_frame_buffer = tft.getFrameBuffer();
  delay(250);
#ifdef UPDATE_HALF_FRAME
  tft.setFrameCompleteCB(&frame_callback, true);
#else
  tft.setFrameCompleteCB(&frame_callback, false);
#endif
  // We are not running DMA currently so start it up.
  Serial.println("Starting up DMA Updates");
  shutdown_cont_update_count = 0xff;
  tft.updateScreenAsync(true);

  Serial.println("==================================================");

  Serial.println("\n*** Commands ***");
  Serial.println("    t - Toggle display updates on or off");
}

void frame_callback() {
  //Serial.printf("FCB: %d %d\n", tft.frameCount(), tft.subFrameCount());
  uint32_t frameCount = tft.frameCount();
  // See if end of test signalled.
  if (shutdown_cont_update_count == COUNT_SHUTDOWN_FRAMES) {
    uint8_t color_index = (frameCount >> 4) & 0x7;
    tft.setCursor(TCENTER, TCENTER);
    tft.setTextColor(our_pallet[(color_index + 3) & 7]);
    tft.setFont(Arial_20_Bold);
    tft.println("Stop Signalled");
    shutdown_cont_update_count--;
    arm_dcache_flush(tft_frame_buffer, FRAME_BUFFER_SIZE);
  } else if (shutdown_cont_update_count == 0) {
    tft.setCursor(TCENTER, tft.getCursorY());
    tft.println("endUpdateAsync");
    tft.endUpdateAsync();
    Serial.println("after endUpdateAsync");
    arm_dcache_flush(tft_frame_buffer, FRAME_BUFFER_SIZE);
  } else if (shutdown_cont_update_count < COUNT_SHUTDOWN_FRAMES) {
    shutdown_cont_update_count--;
  } else {
#ifdef UPDATE_HALF_FRAME
    bool draw_frame = false;
    if (((frameCount & 0xf) == 0) && tft.subFrameCount()) {
      draw_frame = true;
      tft.setClipRect(0, 0, tft.width(), tft.height() / 2);
    } else if (((frameCount & 0xf) == 1) && !tft.subFrameCount()) {
      draw_frame = true;
      tft.setClipRect(0, tft.height() / 2, tft.width(), tft.height() / 2);
    }
    if (draw_frame)
#else
    if (tft.subFrameCount()) {
      // lets ignore these right now
      return;
    }
    if ((frameCount & 0xf) == 0)
#endif
    {
      // First pass ignore subframe...
      uint8_t color_index = (frameCount >> 4) & 0x7;
      tft.fillScreen(our_pallet[color_index]);
      tft.drawRect(5, 5, tft.width() - 10, tft.height() - 10, our_pallet[(color_index + 1) & 7]);
      tft.drawRect(25, 25, tft.width() - 50, tft.height() - 50, our_pallet[(color_index + 2) & 7]);

      static uint8_t display_other = 0;
      switch (display_other) {
        case 0:
          tft.fillRect(50, 50, tft.width() - 100, tft.height() - 100, our_pallet[(color_index + 1) & 7]);
          break;
        case 1:
          tft.fillCircle(tft.width() / 2, tft.height() / 2, 100, our_pallet[(color_index + 1) & 7]);
          break;
        case 2:
          tft.fillTriangle(50, 50, tft.width() - 50, 50, tft.width() / 2, tft.height() - 50, our_pallet[(color_index + 1) & 7]);
          break;
      }
      if (!tft.subFrameCount()) {
        display_other++;
        if (display_other > 2) display_other =  0 ;
      }

      arm_dcache_flush(tft_frame_buffer, FRAME_BUFFER_SIZE);
      tft.setClipRect();
    }
  }

}

void loop(void) {
  // See if any text entered
  int ich;
  if ((ich = Serial.read()) != -1) {
    while (Serial.read() != -1) ;
    switch (ich) {
      case 't':
        toggleOnOffDisplay();
        break;
    }
  }
}

void toggleOnOffDisplay() {
  if (!tft.asyncUpdateActive()) {
    // We are not running DMA currently so start it up.
    Serial.println("Starting up DMA Updates");
    shutdown_cont_update_count = 0xff;
    tft.updateScreenAsync(true);
  } else {
    shutdown_cont_update_count = COUNT_SHUTDOWN_FRAMES;
    while (shutdown_cont_update_count) ;
    tft.waitUpdateAsyncComplete();
    tft.setCursor(TCENTER, tft.getCursorY());
    tft.print("Finished Test\n");
    Serial.println("after waitUpdateAsyncComplete");
    Serial.println("Finished test");

    delay(2000);
    Serial.println("Do normal update to see if data is there");
    tft.updateScreen();
  }

}
 
Morning @KurtE
Just got my coffee then downloaded your updated lib and tried on the Micromod - seems to be working as far as I can see - toggled the updates on/off several times and no issues.

I ordered an extra 320x240 display from Amazon just in case - should arrive today.
 
Morning @KurtE
Just got my coffee then downloaded your updated lib and tried on the Micromod - seems to be working as far as I can see - toggled the updates on/off several times and no issues.

I ordered an extra 320x240 display from Amazon just in case - should arrive today.
One like: https://smile.amazon.com/gp/product/B081Q79X2F ? Mine arrived yesterday, might pick up today.

Right now editing the T3.6/T3.5 code. For Callbacks.
 
Yesterday and this morning was working on sending an image to Arducam Imaging App. The app takes images - bmp or video and displays it rathe quickly. But looks like I have to resize from down to 320x240 from 324x244. Got the rows right now but have to still do the columns:
Capture.PNG
 
Looks like you are having fun.

I just finished this round of ST7735_t3/89 updates on T3.5 and T3.6... To allow them also to get callbacks on full frames and half frames.

Note I rebase -i the changes and combined all of them into 1...

Tested on T3.5 and 3.6 on ST7789 for 320 and 240 size... May play a little more with it before doing PR...

Also only tested on SPI, maybe should try on SPi1 or 2 on 3.5 as the SPI objects are sort of screwy on 3.5.

Also maybe should pull out ST7735 of some size... But note not too worried as this code should simply add functionality

Also tested with both the Adafruit 320 as well as the one that I picked up from PMB this morning.
 
Exact same one - will arrive this afternoon probably :)

That ST7789 display is the one I just got and hooked up - so far just to a T_4.1 and indications are it works well and easily with DC.

Has a hand plug to 8" Female wires. Put long males headers in the PJRC mem board and it came right up.

I saw the latest from github - but didn't build anything or swap it to T.MM yet.

Was beat after chores yesterday and about to run another couple hours ... until lunch.

Cool there is an alternative to the PDE sketch for viewing - good luck with that
 
That ST7789 display is the one I just got and hooked up - so far just to a T_4.1 and indications are it works well and easily with DC.

Has a hand plug to 8" Female wires. Put long males headers in the PJRC mem board and it came right up.

I saw the latest from github - but didn't build anything or swap it to T.MM yet.

Was beat after chores yesterday and about to run another couple hours ... until lunch.

Cool there is an alternative to the PDE sketch for viewing - good luck with that

@KurtE - glad all is working. The testing I did was on the 320 display and just waiting for the mail to hook it up to the T4.1 display adapter I have. Will let you know when I get it. Rainy cool day here today and not doing much of anything except sleeping :) Wife took the second shot so we'll see how that goes.
 
@KurtE - glad all is working. The testing I did was on the 320 display and just waiting for the mail to hook it up to the T4.1 display adapter I have. Will let you know when I get it. Rainy cool day here today and not doing much of anything except sleeping :) Wife took the second shot so we'll see how that goes.

Looks like I may have a bit more work to do on ST7735 on T4.x...
60788756a8c6d975720300.jpg
 
Ok - thats strange would have thought it would have worked.

Not having much luck with my project. Think going to ditch it. Something is off have I can't figure it out.
 
Got a side question on regulators for the T4.1 breakout board.

Someone gave me a link for 5v VIN reg (https://www.ezsbc.com/product/psu5-2/ or I was looking at https://www.ezsbc.com/product/psu5-nonoise/), obviously this would get attached to a the jack for external power not USB power.

I have not used those before, some of the others I have used that looks similar:
https://www.digikey.com/en/products/detail/murata-power-solutions-inc/OKI-78SR-5-1-5-W36-C/2259781
Or a similar one with the pins at 90 degrees.
In fact board that Lynxmotion is assembling for a for a few of us from my quick and dirty design uses one:

I have also used some from Pololu: like if 1amp is enough: https://www.pololu.com/product/2831
 
Ok - thats strange would have thought it would have worked.

Not having much luck with my project. Think going to ditch it. Something is off have I can't figure it out.

Yep - often times it is the simple things: Code came from ILI9341: 320x240:

So on those I need to split up the DMA into 3 chunks: So number of Words to write per DMA: 320*240/3 = 25600
So worked fine on large one: Also 240x240/3 = 19200 again works.
But now try: 128*128/3 = 5461.33333 (not so good).

So will now Mod, to work like the T3.6 code, and try for 2, if won't fit in 2 then go to 3...
 
Just pushed up I think fix for T4.x into the ST7735_t3 branch I mentioned... Not sure if anyone else wants to try it before I do the PR?
 
Arghh - github wanted to merge from your tree when nothing changed here - had to remove and start over ...

Installed 'git' but that's foreign - dumping and restarting repositories is a regular thing it seems ...

Anyhow on T_4.1 the AMZN ST7789 running one eye of : uncannyEyes_async_st7789_240x240.ino

<edit> p#483 sketch doesn't compile? Not sure why the conflicts and inclusion of 9341?
Code:
Compiling sketch...
"T:\\arduino-1.8.13_t54\\hardware\\teensy/../tools/precompile_helper" "T:\\arduino-1.8.13_t54\\hardware\\teensy\\avr/cores/teensy4" "t:\\temp\\arduino_build_ST7789_DMA.ino" "T:\\arduino-1.8.13_t54\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -x c++-header -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=154 -DARDUINO=10600 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IT:\\arduino-1.8.13_t54\\hardware\\teensy\\avr/cores/teensy4" "t:\\temp\\arduino_build_ST7789_DMA.ino/pch/Arduino.h" -o "t:\\temp\\arduino_build_ST7789_DMA.ino/pch/Arduino.h.gch"
Using previously compiled file: t:\temp\arduino_build_ST7789_DMA.ino\pch\Arduino.h.gch
"T:\\arduino-1.8.13_t54\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -D__IMXRT1062__ -DTEENSYDUINO=154 -DARDUINO=10600 -DARDUINO_TEENSY41 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-It:\\temp\\arduino_build_ST7789_DMA.ino/pch" "-IT:\\arduino-1.8.13_t54\\hardware\\teensy\\avr\\cores\\teensy4" "-IT:\\tCode\\libraries\\ST7735_t3" "-IT:\\arduino-1.8.13_t54\\hardware\\teensy\\avr\\libraries\\SPI" "-IT:\\arduino-1.8.13_t54\\hardware\\teensy\\avr\\libraries\\ILI9341_t3" "t:\\temp\\arduino_build_ST7789_DMA.ino\\sketch\\ST7789_DMA.ino.cpp" -o "t:\\temp\\arduino_build_ST7789_DMA.ino\\sketch\\ST7789_DMA.ino.cpp.o"
In file included from T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\ILI9341_t3/font_Arial.h:4:0,
                 from T:\tCode\T_4.1\ST7789_DMA\ST7789_DMA.ino:6:
T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\ILI9341_t3/ILI9341_t3.h:170:3: error: conflicting declaration 'typedef struct ILI9341_t3_font_t ILI9341_t3_font_t'
 } ILI9341_t3_font_t;
   ^
In file included from T:\tCode\libraries\ST7735_t3/ST7735_t3.h:28:0,
                 from T:\tCode\libraries\ST7735_t3/ST7789_t3.h:21,
                 from T:\tCode\T_4.1\ST7789_DMA\ST7789_DMA.ino:5:
T:\tCode\libraries\ST7735_t3/ILI9341_fonts.h:22:3: note: previous declaration as 'typedef struct ILI9341_t3_font_t ILI9341_t3_font_t'
 } ILI9341_t3_font_t;
   ^
In file included from T:\tCode\libraries\ST7735_t3/ST7789_t3.h:21:0,
                 from T:\tCode\T_4.1\ST7789_DMA\ST7789_DMA.ino:5:
T:\tCode\libraries\ST7735_t3/ST7735_t3.h:852:29: error: redefinition of 'class ST7735_Button'
 #define Adafruit_GFX_Button ST7735_Button
                             ^
T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\ILI9341_t3/ILI9341_t3.h:560:7: note: in expansion of macro 'Adafruit_GFX_Button'
 class Adafruit_GFX_Button {
       ^
T:\tCode\libraries\ST7735_t3/ST7735_t3.h:853:7: error: previous definition of 'class ST7735_Button'
 class ST7735_Button {
       ^
Multiple libraries were found for "ST7789_t3.h"
 Used: T:\tCode\libraries\ST7735_t3
 Not used: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\ST7735_t3
Using library ST7735_t3 at version 1.0.0 in folder: T:\tCode\libraries\ST7735_t3 
Using library SPI at version 1.0 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\SPI 
Using library ILI9341_t3 at version 1.0 in folder: T:\arduino-1.8.13_t54\hardware\teensy\avr\libraries\ILI9341_t3 
exit status 1
[Finished in 2.3s with exit code 1]
[shell_cmd: .\Compile.cmd 1]
[dir: T:\tCode\T_4.1\ST7789_DMA]
[path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft SQL
 
Last edited:
Afternoon @KurtE
Thanks for the references on the regulators - now have no idea which to put on the breakout board :) Any suggestions. Leaning to the 1.5 amp one just in case :)

I'll give the ST7735 a test as soon as I can find them. Did get my other 320x240 display a little while ago though. Now I think get some coffee and start playing again.
 
@mjs513 which one? Hard to say. Maybe depends on what the power source is. If ac might just use wallwart if battery depends, when I was playing with nimh or lifo for 6v servos I used different... but for 3s lipo I went to the ones mentioned.
 
@defragster - not sure why not building? Obviously only define one of the two displays... Actually in my current version one of 3...
Note, I should probably hack it up some more for which ST7789... There are lines commented in or out for which one...

Also I tested last time without turning on the half frame code... So running tests again. So far with 320... working

There are other defines

Code:
//#define TFT_ST7735 1
#define TFT_ST7789 1
//#define TFT_ILI9341 1
#if defined(TFT_ST7789) || defined(TFT_ST7735)
//ST7735 Adafruit 320x240 display
#include <ST7735_t3.h>
#include <ST7789_t3.h>
#include <font_Arial.h>
#include <font_ArialBold.h>
#else
#include <ILI9341_fonts.h>
#include <ILI9341_t3n.h>
#include <font_Arial.h>
#include <font_ArialBold.h>
#endif

elapsedMicros _dt;
#define dtSTART {_dt=0;}
#define dtEND(a) { Serial.printf( "\n%s()_%s : dt %ul us", __func__, a, (uint32_t)_dt);}

#define UPDATE_HALF_FRAME

#define ROTATION 3

#include "SPI.h"


//------------------------------------
#if defined(TFT_ST7789) || defined(TFT_ST7735)
#ifdef ARDUINO_TEENSY_MICROMOD
#define TFT_DC  1   // "TX1" on left side of Sparkfun ML Carrier
#define TFT_CS  4   // "CS" on left side of Sparkfun ML Carrier
#define TFT_RST  0  // "RX1" on left side of Sparkfun ML Carrier
#else
#define TFT_DC  9   // "TX1" on left side of Sparkfun ML Carrier
#define TFT_CS  10   // "CS" on left side of Sparkfun ML Carrier
#define TFT_RST  8  // "RX1" on left side of Sparkfun ML Carrier
#endif
#ifdef TFT_ST7789
ST7789_t3 tft = ST7789_t3(TFT_CS, TFT_DC, TFT_RST);
#else
ST7735_t3 tft = ST7735_t3(TFT_CS, TFT_DC, TFT_RST);
#endif

#define TFT_BLACK ST77XX_BLACK
#define TFT_YELLOW ST77XX_YELLOW
#define TFT_RED   ST77XX_RED
#define TFT_GREEN ST77XX_GREEN
#define TFT_BLUE  ST77XX_BLUE
#define TCENTER ST7735_t3::CENTER
uint16_t our_pallet[] = {
  TFT_BLACK,  TFT_RED, TFT_GREEN,  TFT_BLUE,
  ST77XX_YELLOW, ST77XX_ORANGE, ST77XX_CYAN,ST77XX_PINK
};

#else
#define TFT_BLACK ILI9341_BLACK
#define TFT_YELLOW ILI9341_YELLOW
#define TFT_RED   ILI9341_RED
#define TFT_GREEN ILI9341_GREEN
#define TFT_BLUE  ILI9341_BLUE
#define TCENTER ILI9341_t3n::CENTER
#define USE_SPI2
#ifdef USE_SPI2
#define TFT_DC 44
#define TFT_RST 46
#define TFT_CS 47 // any pin will work not hardware

// T4.1 SCK pins on SDCARD
#define USE_MEMORY_PINS
#ifdef USE_MEMORY_PINS
#define TFT_SCK 49
#define TFT_MISO 54
#define TFT_MOSI 50
#else
#define TFT_SCK 45
#define TFT_MISO 42
#define TFT_MOSI 43
#endif
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);
#else
#define TFT_RST 8
#define TFT_DC  9
#define TFT_CS 10
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
#endif
uint16_t our_pallet[] = {
  ILI9341_BLACK,  ILI9341_RED, ILI9341_GREEN,  ILI9341_BLUE,
  ILI9341_YELLOW, ILI9341_ORANGE, ILI9341_CYAN, ILI9341_PINK
};
#endif

#define COUNT_SHUTDOWN_FRAMES 16
volatile uint8_t shutdown_cont_update_count = 0xff;
uint16_t *tft_frame_buffer = nullptr;
#define FRAME_BUFFER_SIZE (320*240*2)
elapsedMicros my_us;


void setup() {
  while (!Serial && (millis() < 4000)) ;
  Serial.begin(115200);
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  Serial.printf("Begin: CS:%d, DC:%dRST: %d\n", TFT_CS, TFT_DC, TFT_RST);
#ifdef TFT_ST7789
  //tft.init(240, 240);           // Init ST7789 320x240
  tft.init(240, 320);           // Init ST7789 320x240
#elif defined(TFT_ST7735)
  // Use this initializer if you're using a 1.8" TFT 128x160 displays
  //tft.initR(INITR_BLACKTAB);

  // Or use this initializer (uncomment) if you're using a 1.44" TFT (128x128)
  tft.initR(INITR_144GREENTAB);

  // Or use this initializer (uncomment) if you're using a .96" TFT(160x80)
  //tft.initR(INITR_MINI160x80);
#else
  tft.begin(26000000);
#endif  
  tft.setRotation(ROTATION);
  tft.fillScreen(TFT_RED);
  delay(500);
  tft.fillScreen(TFT_GREEN); 
  delay(500);
  tft.fillScreen(TFT_BLUE);
  delay(500);
  tft.fillScreen(TFT_BLACK);
  delay(500);

  tft.useFrameBuffer(true);
  tft.fillScreen(TFT_BLACK);
  tft.setCursor(TCENTER, TCENTER);
  tft.setTextColor(TFT_RED);
  tft.setFont(Arial_20_Bold);
  tft.println("*** Auto start ***");
  tft.updateScreen();
  tft_frame_buffer = tft.getFrameBuffer();
  delay(250);
#ifdef UPDATE_HALF_FRAME
  tft.setFrameCompleteCB(&frame_callback, true);
#else
  tft.setFrameCompleteCB(&frame_callback, false);
#endif
  // We are not running DMA currently so start it up.
  Serial.println("Starting up DMA Updates");
  shutdown_cont_update_count = 0xff;
  tft.updateScreenAsync(true);

  Serial.println("==================================================");

  Serial.println("\n*** Commands ***");
  Serial.println("    t - Toggle display updates on or off");
}

void frame_callback() {
  //Serial.printf("FCB: %d %d\n", tft.frameCount(), tft.subFrameCount());
  uint32_t frameCount = tft.frameCount();
  // See if end of test signalled.
  if (shutdown_cont_update_count == COUNT_SHUTDOWN_FRAMES) {
    uint8_t color_index = (frameCount >> 4) & 0x7;
    tft.setCursor(TCENTER, TCENTER);
    tft.setTextColor(our_pallet[(color_index + 3) & 7]);
    tft.setFont(Arial_20_Bold);
    tft.println("Stop Signalled");
    shutdown_cont_update_count--;
    arm_dcache_flush(tft_frame_buffer, FRAME_BUFFER_SIZE);
  } else if (shutdown_cont_update_count == 0) {
    tft.setCursor(TCENTER, tft.getCursorY());
    tft.println("endUpdateAsync");
    tft.endUpdateAsync();
    Serial.println("after endUpdateAsync");
    arm_dcache_flush(tft_frame_buffer, FRAME_BUFFER_SIZE);
  } else if (shutdown_cont_update_count < COUNT_SHUTDOWN_FRAMES) {
    shutdown_cont_update_count--;
  } else {
#ifdef UPDATE_HALF_FRAME
    bool draw_frame = false;
    if (((frameCount & 0xf) == 0) && tft.subFrameCount()) {
      draw_frame = true;
      tft.setClipRect(0, 0, tft.width(), tft.height() / 2);
    } else if (((frameCount & 0xf) == 1) && !tft.subFrameCount()) {
      draw_frame = true;
      tft.setClipRect(0, tft.height() / 2, tft.width(), tft.height() / 2);
    }
    if (draw_frame)
#else
    if (tft.subFrameCount()) {
      // lets ignore these right now
      return;
    }
    if ((frameCount & 0xf) == 0)
#endif
    {
      // First pass ignore subframe...
      uint8_t color_index = (frameCount >> 4) & 0x7;
      tft.fillScreen(our_pallet[color_index]);
      tft.drawRect(5, 5, tft.width() - 10, tft.height() - 10, our_pallet[(color_index + 1) & 7]);
      tft.drawRect(25, 25, tft.width() - 50, tft.height() - 50, our_pallet[(color_index + 2) & 7]);

      static uint8_t display_other = 0;
      switch (display_other) {
        case 0:
          tft.fillRect(50, 50, tft.width() - 100, tft.height() - 100, our_pallet[(color_index + 1) & 7]);
          break;
        case 1:
          tft.fillCircle(tft.width() / 2, tft.height() / 2, 100, our_pallet[(color_index + 1) & 7]);
          break;
        case 2:
          tft.fillTriangle(50, 50, tft.width() - 50, 50, tft.width() / 2, tft.height() - 50, our_pallet[(color_index + 1) & 7]);
          break;
      }
      if (!tft.subFrameCount()) {
        display_other++;
        if (display_other > 2) display_other =  0 ;
      }

      arm_dcache_flush(tft_frame_buffer, FRAME_BUFFER_SIZE);
      tft.setClipRect();
    }
  }

}

void loop(void) {
  // See if any text entered
  int ich;
  if ((ich = Serial.read()) != -1) {
    while (Serial.read() != -1) ;
    switch (ich) {
      case 't':
        toggleOnOffDisplay();
        break;
    }
  }
}

void toggleOnOffDisplay() {
  if (!tft.asyncUpdateActive()) {
    // We are not running DMA currently so start it up.
    Serial.println("Starting up DMA Updates");
    shutdown_cont_update_count = 0xff;
    tft.updateScreenAsync(true);
  } else {
    shutdown_cont_update_count = COUNT_SHUTDOWN_FRAMES;
    while (shutdown_cont_update_count) ;
    tft.waitUpdateAsyncComplete();
    tft.setCursor(TCENTER, tft.getCursorY());
    tft.print("Finished Test\n");
    Serial.println("after waitUpdateAsyncComplete");
    Serial.println("Finished test");

    delay(2000);
    Serial.println("Do normal update to see if data is there");
    tft.updateScreen();
  }

}

Note: this is not part of any project just in my set of sketches that I hacked up over time...

Edit: which is good running test again 240x240 half not working :(
 
Back
Top