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).
// Arduino Due - LCD HX8347A clock sample 1
// Brief LCD controller HX8347A TFT example for Arduino Due
// ported from Atmel ASF SAM3X-EK Display COntroller Example.
// Draw current date and time on the HX8347A LCD controller.
// By Wilfredo Molina 2014 (RTC code by Markus_L811)
// Required libraries
#include "hx8347a.h"
#include "smc.h"
#include <rtc_clock.h>
#define CONF_BOARD_HX8347A_LCD_CS 2
struct opt_t display_opt;
HX8347A HX8347A;
RTC_clock rtc_clock(XTAL);
int hour, minute, second, day, month, year;
char hour1[12];
char minute1[12];
char second1[12];
char day1[12];
char month1[12];
char year1[12];
char* daynames[]={"Monday", "Tueday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
/* Convert 24-bits color to 16-bits color */
static color_t rgb24_to_rgb16(uint32_t ul_color)
{
color_t result_color;
result_color = (((ul_color >> 8) & 0xF800) |
((ul_color >> 5) & 0x7E0) | ((ul_color >> 3) & 0x1F));
return result_color;
}
void setup() {
Serial.begin(115200);
rtc_clock.init();
rtc_clock.set_time(10, 28, 30);
rtc_clock.set_date(14, 4, 2014);
}
void loop()
{
month = rtc_clock.get_months();
day = rtc_clock.get_days();
year = rtc_clock.get_years();
hour = rtc_clock.get_hours();
minute = rtc_clock.get_minutes();
second = rtc_clock.get_seconds();
/* Enable peripheral clock */
pmc_enable_periph_clk(ID_SMC);
/* Configure SMC interface for Lcd */
smc_set_setup_timing(SMC, CONF_BOARD_HX8347A_LCD_CS, SMC_SETUP_NWE_SETUP(1)
| SMC_SETUP_NCS_WR_SETUP(1)
| SMC_SETUP_NRD_SETUP(9)
| SMC_SETUP_NCS_RD_SETUP(9));
smc_set_pulse_timing(SMC, CONF_BOARD_HX8347A_LCD_CS, SMC_PULSE_NWE_PULSE(4)
| SMC_PULSE_NCS_WR_PULSE(4)
| SMC_PULSE_NRD_PULSE(36)
| SMC_PULSE_NCS_RD_PULSE(36));
smc_set_cycle_timing(SMC, CONF_BOARD_HX8347A_LCD_CS, SMC_CYCLE_NWE_CYCLE(10)
| SMC_CYCLE_NRD_CYCLE(45));
smc_set_mode(SMC, CONF_BOARD_HX8347A_LCD_CS, SMC_MODE_READ_MODE
| SMC_MODE_WRITE_MODE | SMC_MODE_DBW_BIT_16);
/* Initialize display parameter */
display_opt.ul_width = HX8347A_LCD_WIDTH;
display_opt.ul_height = HX8347A_LCD_HEIGHT;
display_opt.foreground_color = rgb24_to_rgb16(COLOR_BLACK);
display_opt.background_color = rgb24_to_rgb16(COLOR_WHITE);
/* Switch off backlight */
aat31xx_disable_backlight();
/* Initialize LCD */
if(HX8347A.init(&display_opt)){
puts("Read HX8347A chip ID error, please check the configuration.\r");
}
/* Set backlight level */
aat31xx_set_backlight(AAT31XX_AVG_BACKLIGHT_LEVEL);
HX8347A.set_foreground_color(rgb24_to_rgb16(COLOR_WHITE));
HX8347A.draw_filled_rectangle(0, 0, HX8347A_LCD_WIDTH - 1, HX8347A_LCD_HEIGHT - 1);
/* Turn on LCD */
HX8347A.display_on();
/* Draw real Date and Time on the LCD */
HX8347A.set_foreground_color(rgb24_to_rgb16(COLOR_BLACK));
HX8347A.draw_string(20, 20, (uint8_t *)"Arduino DUE clock");
HX8347A.draw_string(10, 100, (uint8_t *)daynames[rtc_clock.get_day_of_week()-1]);
HX8347A.draw_string(105, 100, (uint8_t *)ltoa(month, month1, 10));
HX8347A.draw_string(110, 100, (uint8_t *)" / ");
HX8347A.draw_string(135, 100, (uint8_t *)ltoa(day, day1, 10));
HX8347A.draw_string(150, 100, (uint8_t *)" / ");
HX8347A.draw_string(174, 100, (uint8_t *)ltoa(year, year1, 10));
HX8347A.draw_string(110, 120, (uint8_t *)ltoa(hour, hour1, 10));
HX8347A.draw_string(125, 120, (uint8_t *)" : ");
HX8347A.draw_string(150, 120, (uint8_t *)ltoa(minute, minute1, 10));
HX8347A.draw_string(163, 120, (uint8_t *)" : ");
HX8347A.draw_string(188, 120, (uint8_t *)ltoa(second, second1, 10));
}
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.
p