This is another of my pet projects. To build an LCD library based on the HX8347A TFT display controller.
I know that there are several LCD libraries out there but I still believe that there is a spot for this one. Why?
Because this LCD board matches perfectly the 18x2F-H8.5 pin connector of the DUE. See pictures below.
I will be porting the Atmel ASF HX8347A library and example to Arduino DUE. I will use one Arduino DUE and one EM-LCD28TP board borrowed from my Atmel EB-SAM3U.
I hope to start next week and keep this thread updated with my progress. Any comment or contribution is welcome.
P
The purpose of this post is to present the building of a library that allows to connect an LCD TFT module to the Arduino Due.
There are so many LCD TFT chips out there and each one has unique configuration requirements, that it is not practical to build here a library that could be use with different LCDs but only the one presented here and compatibles.
This application uses the External Bus Interface (EBI) called Static Memory Controller (SMC) inside the SAM3X8E to handle the LCD module.
I will port the LCD library and one example of the SAM3X/SAM3U evaluation boards from the ASF Atmel to Arduino DUE.
I will use a 240RGB x 320 dot LCD integrated with the HX8347A chip controller. The same one used in the mentioned Atmel boards. The library will consist of the HX8347A files (.h, .cpp) and a configuration file (.h). The library invokes the smc library. The example will draw pictures and strings on the LCD. This porting also covers the XY touch screen capabilities of the LCD. It will be is required an ADS7843E controller.
The beautiful of the HX8347A LCD is that the 2x18 connector 'almost' fit the Due one. I say almost because if everything goes accordingly, the board will be shifted one column to the right. A couple of small power jumpers and one 100K resistor will be also needed. The building of a shield will be necessary to avoid obstruction with the DUE connectors.
That said, let’s start the porting.
PART I. Raw Porting from the Original
Hardware needed:
Arduino Due
LCD EM-LCD28TP.
I have decided to start this porting using the original pin/register definitions. The idea here is to stick as close as possible with the original application (hardware and software). Remember that the SAM3X/3U-EK board's cores are close siblings of the Due's core and the LCD is the same. This implies few changes to be made at the beginning. For example, I had to re-defined 3 pins (data and CS) used in the original code given that those pins are not connected in the Arduino Due.
Before make a stop, here a picture of the pinout inter-connection and the Arduino DUE with the LCD. So far, the initial raw LCD library works OK despite the rat's nest. I will create and upload in Github the LCD library files and example sketch very soon.
Thanks Rob! Indeed, your Due pinout diagram has been of great assistance to me.
Hardware (Con't)
Let's take a look at what I have called the LCD integrated system. It comprehends mainly three parts: 1. The LCD 2. The Touch Screen 3. The Back Light
1. The LCD:
The LCD module comprehends a 2.8 inches panel with a native resolution of 240RGB x 320 pixels with integrated TFT driver IC HX8347. So far it will be enough for us to know that the HX8347 interface with the panel (black box) and connects to the outer world (DUE) via its CS, RS, WR, RD, Reset, D0-D17, Vdd and GND pins as shown in my last reply. Notice that I left open (free running mode) the CS pin keeping the chip always selected.
2. The Touch Screen is a 4-wire panel controlled by an ADS7843 as a slave device on the DUE SPI bus.
3. The Back Light is made of 4 white chip LEDs in parallel, driven by an AAT3194 charge pump. The AAT3194 is controlled by the DUE through a single line Simple Serial Control (S2Cwire) interface, which permits to enable, disable, and set the LED drive current (LED brightness control) from a 32-level logarithmic scale. The AAT3194 chip is embedded in the LCD board.
In the first stage of this porting, I have focused the hardware only to draw text and shapes on the LCD. Later I will deal with the touch screen and back light.
Let's look now the DUE-LCD Interface.
The Arduino DUE communicates with the LCD through the EBI SMC embedded inside the SAM3X8E via PIOC where a 16-bit parallel "8080-like" protocol data bus has been implemented by software. Due configures the HX8347A for access the LCD controller, then initialize the LCD and finally draw some text, image and basic shapes like lines, rectangles and circles on the LCD.
SOFTWARE.
With the advent of the Arduino DUE, even when Atmel has written some ASF examples for it, the LCD example remained confined only for the SAM3U and SAM3X based evaluation boards. Thus, my plan was to start porting the original LCD library and examples to Arduino Due under the Atmel Studio environment, and then complete the porting to the Arduino IDE. Why? Again, to stay close to the original application and to corroborate that it worked on the Due from the Atmel side.
Before enter with the porting, I think this is an opportune moment to explain one or two things about EBI/SMC controller. SAM3X8E's core: ARM-Cortex M3 is fitted with a 6 layer AHB bus (84MHz) as a bridge between the processor M3 and the peripherals. The EBI/SMC controller is in between and can connect I/O lines from the 4 PIO controllers via AHB to the core. In other words, the SMC guarantees high speed data processing, which is what we need for our LCD applications with DUE (videos/photos). It is even faster that using the SPI protocol.
Porting from SAM3X-EK (SAM3X8H) to Due (SAM3X8E) inside Atmel Studio 6.1 (AS61).
Caveat: You don't need (even if you can) to do the following steps. I will provide for you the .bin file at the end of this reply in case you want to test in advance the application by yourself.
I am using the SAM3X-EK ASF LCD example and HX8347A library contained in AS61.
Step 1: to compile the LCD example in the SAM3X-EK using SAM-ICE and AS61. Check
Step 2: to create a blank project for Arduino Due in AS61. Check
Step 3: to copy and fill (paste) the LCD example in the main.c file of the Arduino Due project. Check
Step 4: to compile the LCD example and fix all the configuration issues (errors) like missing files (mostly classes), headers, etc.. Check
Step 5: to modify the arduino_due_x.h (equivalent to the variant.h in Arduino 1.5.X IDE) and the init.c (equivalent to the variant.cpp in Arduino 1.5.X IDE) according to Due I/O capabilities. Check
Step 6: to compile the LCD example for Arduno Due in AS61. Check
Step 7: to load the .bin file via SAM-ICE (jtag) or bossac via (usb) to Arduino Due.
Step 8: to wire the LCD with Due as shown in my reply #1. Check
Now we should have the LCD TFT module connected to Arduino Due and showing the same screen as reply#1.
What's next? All the LCD ASF AS61 project (around 214 files/116 folders, 17.6 MB) should be reduced to the following files:
I have good news! I finished the 'raw porting' of the LCD TFT library/example from Atmel ASF for SAM3X-EK to the IDE 1.5.6 for Arduino Due. The sketch is running flawlessly.
The library is small. Only 3 files:
-hx8347a.c
-hx8347a.h
-conf_hx8347a.h
I also needed to add some EBI SMC pin definitions to the variant files.
By 'raw porting' I mean to say that the sketch looks almost identical to the example in AS61.
My next step is to create the class for the Arduino IDE with few LCD functions and modify the sketch (Arduino style).
I finished the class HX8347A with 24 functions for the Arduino IDE 1.5.X. I started to play a bit with it and made a clock sketch based on Markus_L811's RTC library (Thank you Markus!). Here the sketch and a picture to give an idea about how it looks (still raw but much better).
I will be revising a bit more the HX8347A library before being published in github.
For those interested to connect/test Arduino Due with the LCD and this 'in progress' library/examples.
Bad news: The LCD that I am using is only sold as a part of the Atmel eval boards (SAM3X-EK/SAM3U-EK).
Good news: There is a couple of vendors of an LCD made by mikroElectronika. This board should work with the library.
I ordered one and I hope to receive it today to test it, but again, I believe that any LCD with HX8347A display driver with parallel (16-bit) operating mode should work.
Another test of the LCD HX8347A library with DUE. This time using stimmer's VGA approach (Thank you stimmer!). Even though the LCD can handle 24-bit RGB(888), I decided to keep stimmer 8-bit colour (RRRGGGBB). http://forum.arduino.cc/index.php?topic=130742.0
Refreshing time: 50 secs.
As I mentioned in my last post, the LCD TFT HX8347A library for Due is almost done but before publish it on github, I decided to create a drawing bitmap function (nonexistent in the Atmel ASF example). So far it is running OK. I used part of the Adafruit/Arduino TFT LCD code that converts RGB888 to RGB565. It was necessary to resolve a couple of issues including the redefinition of two EBI data bus pins D8(PC9) and D9(PC10) correspondent to the Due pins 117 and 93 that never where broken out. Another pending task of this first phase is to redefine the rest of the necessary pins between DUE and the LCD to make possible them to interconnect via the 2x18 connector. I still believe that this library is worthy given that the data is transferred via the AHB bus which is almost twice faster than SPI that use the DMA at around 40MHz, and also the matching of the LCD with DUE without any shield in between.
The second phase will be the touch screen feature but I must finish first with the HX8347A.
I already received a commercially available LCD (mikroElectronika) with same controller. I hope to test it next week.
Here a picture of the famous tiger bitmap from Adafruit (Image by Shane Gorski).
Regarding the frame rate, I want to clarify that I am pulling the bitmap data from an SD card via SPI given the size of the bitmap file, thus, we must not expect high-speed data transfer rates with 16-bit pictures even using the SAM3X8E HSMCI interface via PMC that operates at the masterclock/2 = 42MHz. So far, I haven't focused on the optimization of the bitmap refreshing time but functionality (Indeed, I have added few brief delays and fill functions in the code). I believe, the speed could be reduced a little bit. Of course, if the interest involves the use of shapes and text (static or dynamic), the speed data transfer will be very high (pure RAM).
-Built and tested library for aat31xx LCD backlight controller (.h,.c) that uses one-line Simple Serial Control (S2Cwire) to interface the controller with Due. aat3194 disables/enables backlight (32 brightness levels-logarithmic scale of 4 white chip LEDs in parallel embedded in the LCD board). The control line can be any digital pin (I am using pin D2). For details see replay#3 of this thread.
-Regarding the connection between the Due and the LCD via the 2x18 connector, it is not possible to use other PIO pins on the SMC bus. The only progress I made was to mirror the two missing data pins through a mask, thus, the only option left to me is to build a small pin adapter.