Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: ILI9341 simulator (worth about as much as you paid for it)

  1. #1

    ILI9341 simulator (worth about as much as you paid for it)

    OK, I know the very worst thing is to develop some code then on the first occasion it "kind of works" immediately post it on the internet saying "here's a perfect example of ..." but here I am anyway!

    I am actually trying to piece together my own Teensy4 + Audio Adapter synthesizer and, with that in mind (because I love UIs!) I decided to put one of those very popular $10 ILI9341 2.8TFT + touch screens on it (in fact, already, I have it so you can adjust ADSR by poking the screen with a pen).

    But what I found is that when trying to layout a user interface, every time you make a tweak, like "move that slider 3 pixels to the right", you have to rebuild and re-flash to see if it "looks right". With Teensy 4 + audio the build time is significant. Also I don't like re-flashing things too often how ever long the manufacturer may say a micros flash erase cycle life is.

    Besides that my day-job is actually writing simulators so I am always a great fan of simulators to speed development.

    So I ended up with this:

    Click image for larger version. 

Name:	simulated.png 
Views:	24 
Size:	61.3 KB 
ID:	22000

    (which proves that black text does not really work on top of pictures of beautiful Bengal cats - that's "Amelia" by the way!). Meanwhile on a Teensy 4 + ILI9341 (almost!) the same code creates:

    Click image for larger version. 

Name:	actual_synth.png 
Views:	23 
Size:	401.2 KB 
ID:	22001

    So it seems to work kind of OK. I'm keeping the code for this in a subdirectory of my Synth project on Github:

    https://github.com/wrightflyer/Synth...master/ILI_sim

    As the readme.md says this basically involved lifting ILI9341_t3.* from the Teensy 4 libs in Teensyduino together with the Print and Wstring and stuff in the "core" that it derives from then hacking it about so it would build in isolation from the Arduino/Teensyduino. Whacking a Win32 "blitter" on the front. Then noticing the fact that in all the SPI activity to the ILI9341 in the graphic lib almost every operation starts by defining an x0,y0 to x1,y1 rectangle on the display then just constantly "pushing bytes" at it. So by replacing those bits with something that just holds the rectangle dimensions for the display array then, as 565 color words are pushed, walking across the X's and down the Ys until the rectangle is complete then (probably too often) doing InavlidateRectangles to force WM_PAINTs and the display magically appears.

    Normally I'd "polish the turd" before release but I was so chuffed to see this work the first time I thought I'd better get out there and brag about it a bit.

    Hopefully others might find this useful? You just put all your drawing stuff in setup()/loop() in Display.cpp and the sim will (in theory) do the rest.

    However note this ONLY simulates the display so if you were doing tft.something();delay(50);tft.something() it's possible the tft.something()s will do what was expected but this knows nothing about delay() or anything else in the rich Arduino library.

    Enjoy.

    (I will continue to "polish" this)

  2. #2
    Wow. Good job. I want to use this. But since I am a bit new to GitHub, could you tell me how to actually download and run your simulator? (Sorry if this is a stupid question ) Thank you very much.

  3. #3
    Well for now you'd need to install git then "git clone https://github.com/wrightflyer/Synth.git" which would create a "Synth" directory that includes the simulator files in the ILi_sim sub-dir. Then you'd need some version of Visual Studio installed and load the .sln file in the ILI_Sim directory and build it.

    The fact is that the idea is that you build your Teensy/ILI code "into" this (replace Display.cpp) so you are going to need to be in a position to get the files and build them with Visual Studio.

    I will "improve" things by adding things to the File menu so you can test various "screens" from the project which might then call drawScreen1(), drawScreen2() or whatever but the whole idea is that you use this as a "test bed" to try out display modifications without needing to keep involving Teensyduino so you are going to need to be able to do build/run/debug cycles and for that you will need Visual Studio and some idea of how to use it.

    BTW it's set to MSVC toolset V120 (which is the compiler in VS2013), If you install a later VS (as 2013 is hard to get hold of) then after loading the project the toolset needs to be set to something else (like "v140" for VS2015 or "v141" for VS2017 etc).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •