 
 void setup()
 {
-  Serial.begin(1000000); // JCB
+  Serial.begin(1000000);
 
   pinMode(CSX, OUTPUT);
+  digitalWrite(CSX, HIGH);
+
+  Serial.println("GD init");
+  gd_ili9488_init();
+
+  if (1) {
+    GD.__end();
+    SPI.end();
+
+    pinMode(DCX, OUTPUT);
+    pinMode(SCL, OUTPUT);
+    pinMode(SDA, OUTPUT);
+    pinMode(SDO, INPUT);
+
+    delay(100);
+
+    ili9488_report();
+    ili9488_rgb_mode();
+    ili9488_report();
+    SPI.begin();
+    GD.resume();
+  }
+
+}
+
+unsigned long t;
+
+void loop()
+{
+  GD.ClearColorRGB(0x103000);
+  GD.Clear();
+  GD.cmd_text(GD.w / 2, GD.h / 2, 31, OPT_CENTER, "Hello world");
+  GD.cmd_number(GD.w / 2, 3 * GD.h / 4, 31, OPT_CENTER, t++);
+  GD.swap();
+
+  /*
+  uint32_t f0 = GD.rd32(REG_FRAMES);
+  delay(1000);
+  uint32_t f1 = GD.rd32(REG_FRAMES);
+  Serial.println(f1 - f0);
+  GD.finish();
+  GD.__end();
+  SPI.end();
   pinMode(DCX, OUTPUT);
   pinMode(SCL, OUTPUT);
   pinMode(SDA, OUTPUT);
   pinMode(SDO, INPUT);
-
-  digitalWrite(CSX, HIGH);
-  delay(100);
-
   ili9488_report();
-  ili9488_rgb_mode();
-  ili9488_report();
-
-  Serial.println("GD init");
-  GD.begin(0);
-
+  SPI.begin();
+  GD.resume();
+  */
+}
+
+// Initialize GD for the ILI9488 
+void gd_ili9488_init()
+{
+  GD.begin(~GD_STORAGE);
   Serial.println("Setting video timing for ILI9488");
   GD.wr16(REG_HCYCLE,   400 );
   GD.wr16(REG_HOFFSET,  40  );

  GD.wr16(REG_PCLK,     5   );
  GD.w = 320;
  GD.h = 480;
}

void loop()
{
  GD.ClearColorRGB(0x103000);
  GD.Clear();
  GD.cmd_text(GD.w / 2, GD.h / 2, 31, OPT_CENTER, "Hello world");
  GD.swap();
}

void out_8(uint8_t b)

#include <EEPROM.h>
#include <SPI.h>
#include <GD2.h>

#define CSX 6   // chip select, active low
#define DCX 5   // data/command select
#define SCL 13  // clock, rising edge
#define SDA 11  // data in to ILI9488
#define SDO 12  // data out from ILI9488

#define ILI9488_CMD_READ_ID1                    0xDA
#define ILI9488_CMD_READ_ID2                    0xDB
