   digitalWrite(CSX, HIGH);
 }
 
+void write_command(uint8_t b)
+{
+  digitalWrite(DCX, LOW);
+  out_8(b);
+}
+
+void write_data(uint8_t b)
+{
+  digitalWrite(DCX, HIGH);
+  out_8(b);
+}
+
 uint8_t rdreg(uint8_t reg)
 {
   uint8_t r;
 
-  digitalWrite(DCX, LOW);
-  out_8(reg);
+  write_command(reg);
 
   digitalWrite(DCX, HIGH);
   digitalWrite(CSX, LOW);

  return r;
}

uint8_t wrreg(uint8_t reg, uint8_t val)
{
  digitalWrite(DCX, LOW);
  out_8(reg);
  digitalWrite(DCX, HIGH);
  out_8(val);
}

void loop()
{
  Serial.println();
  Serial.print("ID1: ");
  Serial.println(rdreg(ILI9488_CMD_READ_ID1), HEX);
  Serial.print("ID2: ");
  Serial.println(rdreg(ILI9488_CMD_READ_ID2), HEX);
  Serial.print("ID3: ");
  Serial.println(rdreg(ILI9488_CMD_READ_ID3), HEX);

  delay(3000);
}

  pinMode(SDO, INPUT);

  digitalWrite(CSX, HIGH);
  delay(100);

  ili9488_report();
  ili9488_rgb_mode();
  ili9488_report();

  Serial.println("GD init");
  GD.begin(0);

  Serial.println("Setting video timing for ILI9488");
  GD.wr16(REG_HCYCLE,   400 );
  GD.wr16(REG_HOFFSET,  40  );
  GD.wr16(REG_HSYNC0,   0   );
  GD.wr16(REG_HSYNC1,   10  );
  GD.wr16(REG_VCYCLE,   500 );
  GD.wr16(REG_VOFFSET,  10  );
  GD.wr16(REG_VSYNC0,   0   );
  GD.wr16(REG_VSYNC1,   5   );
  GD.wr16(REG_SWIZZLE,  2   );
  GD.wr16(REG_PCLK_POL, 1   );
  GD.wr16(REG_HSIZE,    320 );
  GD.wr16(REG_VSIZE,    480 );
  GD.wr16(REG_CSPREAD,  1   );
  GD.wr16(REG_DITHER,   1   );
  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)
{
