Library to control a Graphics TFT connected to 4-wire SPI - revised for the Raio RA8875 Display Controller.

Dependents:   FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more

Fork of SPI_TFT by Peter Drescher

See Components - RA8875 Based Display

Enhanced touch-screen support - where it previous supported both the Resistive Touch and Capacitive Touch based on the FT5206 Touch Controller, now it also has support for the GSL1680 Touch Controller.

Offline Help Manual (Windows chm)

/media/uploads/WiredHome/ra8875.zip.bin (download, rename to .zip and unzip)

Revision:
175:7be3a1fb7fc2
Parent:
166:53fd4a876dac
Child:
176:4ab96d33a8ec
--- a/RA8875.cpp	Sat Mar 02 12:43:03 2019 +0000
+++ b/RA8875.cpp	Fri Mar 15 01:39:39 2019 +0000
@@ -311,73 +311,73 @@
     Reset();
     // Set PLL based on display size from buy-display.com sample code
     if (width == 800) {
-        WriteCommand(0x88, 0x0C);               // PLLC1 - Phase Lock Loop registers
+        WriteCommand(RA8875_PLLC1, 0x0C);               // PLLC1 - Phase Lock Loop registers
     } else {
-        WriteCommand(0x88, 0x0B);               // PLLC1 - Phase Lock Loop registers
+        WriteCommand(RA8875_PLLC1, 0x0B);               // PLLC1 - Phase Lock Loop registers
     }
     wait_ms(1);
-    WriteCommand(0x89, 0x02);
+    WriteCommand(RA8875_PLLC2, 0x02);
     wait_ms(1);
 
     // System Config Register (SYSR)
     screenbpp = color_bpp;
     if (color_bpp == 16) {
-        WriteCommand(0x10, 0x0C);               // 16-bpp (65K colors) color depth, 8-bit interface
+        WriteCommand(RA8875_SYSR, 0x0C);               // 16-bpp (65K colors) color depth, 8-bit interface
     } else { // color_bpp == 8
-        WriteCommand(0x10, 0x00);               // 8-bpp (256 colors)
+        WriteCommand(RA8875_SYSR, 0x00);               // 8-bpp (256 colors)
     }
 
     // Set Pixel Clock Setting Register (PCSR) based on display size from buy-display.com sample code
     if (width == 800) {
-        WriteCommand(0x04, 0x81);               // PDAT on PCLK falling edge, PCLK = 4 x System Clock
+        WriteCommand(RA8875_PCSR, 0x81);               // PDAT on PCLK falling edge, PCLK = 4 x System Clock
         wait_ms(1);
 
         // Horizontal Settings
         screenwidth = width;
-        WriteCommand(0x14, width/8 - 1);            //HDWR//Horizontal Display Width Setting Bit[6:0]
-        WriteCommand(0x15, 0x00);                   //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
-        WriteCommand(0x16, 0x03);                   //HNDR//Horizontal Non-Display Period Bit[4:0]
-        WriteCommand(0x17, 0x03);                   //HSTR//HSYNC Start Position[4:0]
-        WriteCommand(0x18, 0x0B);                   //HPWR//HSYNC Polarity ,The period width of HSYNC.
+        WriteCommand(RA8875_HDWR, width/8 - 1);            //HDWR//Horizontal Display Width Setting Bit[6:0]
+        WriteCommand(RA8875_HNDFTR, 0x00);                   //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
+        WriteCommand(RA8875_HNDR, 0x03);                   //HNDR//Horizontal Non-Display Period Bit[4:0]
+        WriteCommand(RA8875_HSTR, 0x03);                   //HSTR//HSYNC Start Position[4:0]
+        WriteCommand(RA8875_HPWR, 0x0B);                   //HPWR//HSYNC Polarity ,The period width of HSYNC.
 
         // Vertical Settings
         screenheight = height;
-        WriteCommand(0x19, (height-1)&0xFF);        //VDHR0 //Vertical Display Height Bit [7:0]
-        WriteCommand(0x1a, (height-1)>>8);          //VDHR1 //Vertical Display Height Bit [8]
-        WriteCommand(0x1b, 0x20);                   //VNDR0 //Vertical Non-Display Period Bit [7:0]
-        WriteCommand(0x1c, 0x00);                   //VNDR1 //Vertical Non-Display Period Bit [8]
-        WriteCommand(0x1d, 0x16);                   //VSTR0 //VSYNC Start Position[7:0]
-        WriteCommand(0x1e, 0x00);                   //VSTR1 //VSYNC Start Position[8]
-        WriteCommand(0x1f, 0x01);                   //VPWR  //VSYNC Polarity ,VSYNC Pulse Width[6:0]
+        WriteCommand(RA8875_VDHR0, (height-1)&0xFF);        //VDHR0 //Vertical Display Height Bit [7:0]
+        WriteCommand(RA8875_VDHR1, (height-1)>>8);          //VDHR1 //Vertical Display Height Bit [8]
+        WriteCommand(RA8875_VNDR0, 0x20);                   //VNDR0 //Vertical Non-Display Period Bit [7:0]
+        WriteCommand(RA8875_VNDR1, 0x00);                   //VNDR1 //Vertical Non-Display Period Bit [8]
+        WriteCommand(RA8875_VSTR0, 0x16);                   //VSTR0 //VSYNC Start Position[7:0]
+        WriteCommand(RA8875_VSTR1, 0x00);                   //VSTR1 //VSYNC Start Position[8]
+        WriteCommand(RA8875_VPWR, 0x01);                   //VPWR  //VSYNC Polarity ,VSYNC Pulse Width[6:0]
     } else {
-        WriteCommand(0x04, 0x82);               // PDAT on PCLK falling edge, PCLK = 4 x System Clock
+        WriteCommand(RA8875_PCSR, 0x82);               // PDAT on PCLK falling edge, PCLK = 4 x System Clock
         wait_ms(1);
 
         // Horizontal Settings
         screenwidth = width;
-        WriteCommand(0x14, width/8 - 1);            //HDWR//Horizontal Display Width Setting Bit[6:0]
-        WriteCommand(0x15, 0x02);                   //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
-        WriteCommand(0x16, 0x03);                   //HNDR//Horizontal Non-Display Period Bit[4:0]
-        WriteCommand(0x17, 0x01);                   //HSTR//HSYNC Start Position[4:0]
-        WriteCommand(0x18, 0x03);                   //HPWR//HSYNC Polarity ,The period width of HSYNC.
+        WriteCommand(RA8875_HDWR, width/8 - 1);            //HDWR//Horizontal Display Width Setting Bit[6:0]
+        WriteCommand(RA8875_HNDFTR, 0x02);                   //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
+        WriteCommand(RA8875_HNDR, 0x03);                   //HNDR//Horizontal Non-Display Period Bit[4:0]
+        WriteCommand(RA8875_HSTR, 0x01);                   //HSTR//HSYNC Start Position[4:0]
+        WriteCommand(RA8875_HPWR, 0x03);                   //HPWR//HSYNC Polarity ,The period width of HSYNC.
 
         // Vertical Settings
         screenheight = height;
-        WriteCommand(0x19, (height-1)&0xFF);        //VDHR0 //Vertical Display Height Bit [7:0]
-        WriteCommand(0x1a, (height-1)>>8);          //VDHR1 //Vertical Display Height Bit [8]
-        WriteCommand(0x1b, 0x0F);                   //VNDR0 //Vertical Non-Display Period Bit [7:0]
-        WriteCommand(0x1c, 0x00);                   //VNDR1 //Vertical Non-Display Period Bit [8]
-        WriteCommand(0x1d, 0x0e);                   //VSTR0 //VSYNC Start Position[7:0]
-        WriteCommand(0x1e, 0x06);                   //VSTR1 //VSYNC Start Position[8]
-        WriteCommand(0x1f, 0x01);                   //VPWR  //VSYNC Polarity ,VSYNC Pulse Width[6:0]
+        WriteCommand(RA8875_VDHR0, (height-1)&0xFF);        //VDHR0 //Vertical Display Height Bit [7:0]
+        WriteCommand(RA8875_VDHR1, (height-1)>>8);          //VDHR1 //Vertical Display Height Bit [8]
+        WriteCommand(RA8875_VNDR0, 0x0F);                   //VNDR0 //Vertical Non-Display Period Bit [7:0]
+        WriteCommand(RA8875_VNDR1, 0x00);                   //VNDR1 //Vertical Non-Display Period Bit [8]
+        WriteCommand(RA8875_VSTR0, 0x0e);                   //VSTR0 //VSYNC Start Position[7:0]
+        WriteCommand(RA8875_VSTR1, 0x06);                   //VSTR1 //VSYNC Start Position[8]
+        WriteCommand(RA8875_VPWR, 0x01);                   //VPWR  //VSYNC Polarity ,VSYNC Pulse Width[6:0]
     }
 
     portraitmode = false;
 
     if (width >= 800 && height >= 480 && color_bpp > 8) {
-        WriteCommand(0x20, 0x00);               // DPCR - 1-layer mode when the resolution is too high
+        WriteCommand(RA8875_DPCR, 0x00);               // DPCR - 1-layer mode when the resolution is too high
     } else {
-        WriteCommand(0x20, 0x80);               // DPCR - 2-layer mode
+        WriteCommand(RA8875_DPCR, 0x80);               // DPCR - 2-layer mode
     }
 
     // Set display image to Blue on Black as default
@@ -415,10 +415,10 @@
         res = 1;                            // de-assert reset
     }
     #endif
-    ret = WriteCommand(0x01, 0x01);         // Apply Display Off, Reset
+    ret = WriteCommand(RA8875_PWRR, 0x01);         // Apply Display Off, Reset
     wait_ms(2);                             // no idea if I need to wait, or how long
     if (ret == noerror) {
-        ret = WriteCommand(0x01, 0x00);     // Display off, Remove reset
+        ret = WriteCommand(RA8875_PWRR, 0x00);     // Display off, Remove reset
         wait_ms(2);                         // no idea if I need to wait, or how long
     }
     return ret;
@@ -452,7 +452,7 @@
     } else if (layer > 1) {
         layer = 0;
     }
-    return WriteCommand(0x41, mwcr1 | layer);
+    return WriteCommand(RA8875_MWCR1, mwcr1 | layer);
 }
 
 
@@ -467,7 +467,7 @@
     unsigned char ltpr0 = ReadCommand(0x52) & ~0x7; // retain all but the display layer mode
     
     if (mode <= (LayerMode_T)6) {
-        WriteCommand(0x52, ltpr0 | (mode & 0x7));
+        WriteCommand(RA8875_LTPR0, ltpr0 | (mode & 0x7));
         return noerror;
     } else {
         return bad_parameter;
@@ -481,7 +481,7 @@
         layer1 = 8;
     if (layer2 > 8)
         layer2 = 8;
-    WriteCommand(0x53, ((layer2 & 0xF) << 4) | (layer1 & 0xF));
+    WriteCommand(RA8875_LTPR1, ((layer2 & 0xF) << 4) | (layer1 & 0xF));
     return noerror;
 }
 
@@ -514,17 +514,17 @@
     value |= (longDetect) ? 0x40 : 0x00;
     value |= (sampleTime & 0x03) << 4;
     value |= (scanFrequency & 0x07);
-    WriteCommand(0xC0, value);   // KSCR1 - Enable Key Scan (and ignore possibility of an error)
+    WriteCommand(RA8875_KSCR1, value);   // KSCR1 - Enable Key Scan (and ignore possibility of an error)
 
     value = 0;
     value |= (wakeupEnable) ? 0x80 : 0x00;
     value |= (longTimeAdjustment & 0x03) << 2;
-    WriteCommand(0xC1, value);  // KSCR2 - (and ignore possibility of an error)
+    WriteCommand(RA8875_KSCR2, value);  // KSCR2 - (and ignore possibility of an error)
 
     value = ReadCommand(0xF0);          // (and ignore possibility of an error)
     value &= ~0x10;
     value |= (interruptEnable) ? 0x10 : 0x00;
-    return WriteCommand(0xF0, value);   // INT
+    return WriteCommand(RA8875_INTC1, value);   // INT
 }
 
 
@@ -615,7 +615,7 @@
     printf(" count: %02X\r\n", count);
     printf("   key: %02X\r\n", key);
 #endif
-    WriteCommand(0xF1, 0x10);       // Clear KS status
+    WriteCommand(RA8875_INTC2, 0x10);       // Clear KS status
     return key;
 }
 
@@ -1006,8 +1006,8 @@
     INFO("SetTextCursor(%d, %d)", x, y);
     cursor_x = x;     // set these values for non-internal fonts
     cursor_y = y;
-    WriteCommandW(0x2A, x);
-    WriteCommandW(0x2C, y);
+    WriteCommandW(RA8875_FCURXL, x);
+    WriteCommandW(RA8875_FCURYL, y);
     return noerror;
 }
 
@@ -1058,9 +1058,9 @@
         mwcr0 |= 0x40;              // visible
     if (blink)
         mwcr0 |= 0x20;              // blink
-    WriteCommand(0x40, mwcr0);      // configure the cursor
-    WriteCommand(0x41, mwcr1);      // close the graphics cursor
-    WriteCommand(0x44, 0x1f);       // The cursor flashing cycle
+    WriteCommand(RA8875_MWCR0, mwcr0);      // configure the cursor
+    WriteCommand(RA8875_MWCR1, mwcr1);      // close the graphics cursor
+    WriteCommand(RA8875_BTCR, 0x1f);       // The cursor flashing cycle
     switch (cursor) {
         case IBEAM:
             horz = 0x01;
@@ -1078,8 +1078,8 @@
         default:
             break;
     }
-    WriteCommand(0x4e, horz);       // The cursor size horz
-    WriteCommand(0x4f, vert);       // The cursor size vert
+    WriteCommand(RA8875_CURHS, horz);       // The cursor size horz
+    WriteCommand(RA8875_CURVS, vert);       // The cursor size vert
     return noerror;
 }
 
@@ -1087,7 +1087,7 @@
 RetCode_t RA8875::SetTextFont(RA8875::font_t font)
 {
     if (/*font >= RA8875::ISO8859_1 && */ font <= RA8875::ISO8859_4) {
-        WriteCommand(0x21, (unsigned int)(font));
+        WriteCommand(RA8875_FNCR0, (unsigned int)(font));
         return noerror;
     } else {
         return bad_parameter;
@@ -1127,8 +1127,8 @@
             return bad_parameter;
     }
     INFO("Orientation: %d, %d", angle, portraitmode);
-    WriteCommand(0x22, fncr1Val);
-    return WriteCommand(0x20, dpcrVal);
+    WriteCommand(RA8875_FNCR1, fncr1Val);
+    return WriteCommand(RA8875_DPCR, dpcrVal);
 }
 
 
@@ -1148,7 +1148,7 @@
             fncr1Val |= 0x40;
         fncr1Val |= ((hScale - 1) << 2);
         fncr1Val |= ((vScale - 1) << 0);
-        return WriteCommand(0x22, fncr1Val);
+        return WriteCommand(RA8875_FNCR1, fncr1Val);
     } else {
         return bad_parameter;
     }
@@ -1167,7 +1167,7 @@
         reg &= 0xF0;    // keep the high nibble as is.
         reg |= ((hScale - 1) << 2);
         reg |= ((vScale - 1) << 0);
-        WriteCommand(0x22, reg);
+        WriteCommand(RA8875_FNCR1, reg);
         return noerror;
     } else {
         return bad_parameter;
@@ -1243,21 +1243,21 @@
 
         mwcr0 = ReadCommand(0x40);
         if ((mwcr0 & 0x80) == 0x00) {
-            WriteCommand(0x40, 0x80 | mwcr0);    // Put in Text mode if not already
+            WriteCommand(RA8875_MWCR0, 0x80 | mwcr0);    // Put in Text mode if not already
         }
         if (c == '\r') {
             loc_t x;
             x = ReadCommand(0x30) | (ReadCommand(0x31) << 8);   // Left edge of active window
-            WriteCommandW(0x2A, x);
+            WriteCommandW(RA8875_FCURXL, x);
         } else if (c == '\n') {
             loc_t y;
             y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8);   // current y location
             y += fontheight();
             if (y >= height())               // @TODO after bottom of active window, then scroll window?
                 y = 0;
-            WriteCommandW(0x2C, y);
+            WriteCommandW(RA8875_FCURYL, y);
         } else {
-            WriteCommand(0x02);                 // RA8875 Internal Fonts
+            WriteCommand(RA8875_MRWC);                 // RA8875 Internal Fonts
             _select(true);
             WriteData(c);
             _WaitWhileBusy(0x80);
@@ -1270,8 +1270,8 @@
 
 RetCode_t RA8875::_StartGraphicsStream(void)
 {
-    WriteCommand(0x40,0x00);    // Graphics write mode
-    WriteCommand(0x02);         // Prepare for streaming data
+    WriteCommand(RA8875_MWCR0,0x00);    // Graphics write mode
+    WriteCommand(RA8875_MRWC);         // Prepare for streaming data
     return noerror;
 }
 
@@ -1299,7 +1299,7 @@
 void RA8875::puts(const char * string)
 {
     if (font == NULL) {
-        WriteCommand(0x40,0x80);    // Put in Text mode if internal font
+        WriteCommand(RA8875_MWCR0,0x80);    // Put in Text mode if internal font
     }
     if (*string != '\0') {
         while (*string) {           // @TODO calling individual _putc is slower... optimizations?
@@ -1311,8 +1311,8 @@
 
 RetCode_t RA8875::SetGraphicsCursor(loc_t x, loc_t y)
 {
-    WriteCommandW(0x46, x);
-    WriteCommandW(0x48, y);
+    WriteCommandW(RA8875_CURH0, x);
+    WriteCommandW(RA8875_CURV0, y);
     return noerror;
 }
 
@@ -1332,8 +1332,8 @@
 
 RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y)
 {
-    WriteCommandW(0x4A, x);
-    WriteCommandW(0x4C, y);
+    WriteCommandW(RA8875_RCURH0, x);
+    WriteCommandW(RA8875_RCURV0, y);
     return noerror;
 }
 
@@ -1354,10 +1354,10 @@
     windowrect.p2.x = x + width - 1;
     windowrect.p2.y = y + height - 1;
     GraphicsDisplay::window(x,y, width,height);
-    WriteCommandW(0x30, x);
-    WriteCommandW(0x32, y);
-    WriteCommandW(0x34, (x+width-1));
-    WriteCommandW(0x36, (y+height-1));
+    WriteCommandW(RA8875_HSAW0, x);
+    WriteCommandW(RA8875_VSAW0, y);
+    WriteCommandW(RA8875_HEAW0, (x+width-1));
+    WriteCommandW(RA8875_VEAW0, (y+height-1));
     //SetTextCursor(x,y);
     //SetGraphicsCursor(x,y);
     return noerror;
@@ -1395,7 +1395,7 @@
 RetCode_t RA8875::clsw(RA8875::Region_t region)
 {
     PERFORMANCE_RESET;
-    WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
+    WriteCommand(RA8875_MCLR, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
     if (!_WaitWhileReg(0x8E, 0x80)) {
         REGISTERPERFORMANCE(PRF_CLS);
         return external_abort;
@@ -1515,9 +1515,9 @@
     color_t pixel;
 
     PERFORMANCE_RESET;
-    WriteCommand(0x40,0x00);    // Graphics write mode
+    WriteCommand(RA8875_MWCR0,0x00);    // Graphics write mode
     SetGraphicsCursorRead(x, y);
-    WriteCommand(0x02);
+    WriteCommand(RA8875_MRWC);
     _select(true);
     _spiwrite(0x40);         // Cmd: read data
     _spiwrite(0x00);         // dummy read
@@ -1539,9 +1539,9 @@
     RetCode_t ret = noerror;
 
     PERFORMANCE_RESET;
-    ret = WriteCommand(0x40,0x00);    // Graphics write mode
+    ret = WriteCommand(RA8875_MWCR0,0x00);    // Graphics write mode
     ret = SetGraphicsCursorRead(x, y);
-    ret = WriteCommand(0x02);
+    ret = WriteCommand(RA8875_MRWC);
     _select(true);
     _spiwrite(0x40);         // Cmd: read data
     _spiwrite(0x00);         // dummy read
@@ -1587,13 +1587,13 @@
     if (x1 == x2 && y1 == y2) {
         pixel(x1, y1);
     } else {
-        WriteCommandW(0x91, x1);
-        WriteCommandW(0x93, y1);
-        WriteCommandW(0x95, x2);
-        WriteCommandW(0x97, y2);
+        WriteCommandW(RA8875_DLHSR0, x1);
+        WriteCommandW(RA8875_DLVSR0, y1);
+        WriteCommandW(RA8875_DLHER0, x2);
+        WriteCommandW(RA8875_DLVER0, y2);
         unsigned char drawCmd = 0x00;       // Line
-        WriteCommand(0x90, drawCmd);
-        WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
+        WriteCommand(RA8875_DCR, drawCmd);
+        WriteCommand(RA8875_DCR, 0x80 + drawCmd); // Start drawing.
         if (!_WaitWhileReg(0x90, 0x80)) {
             REGISTERPERFORMANCE(PRF_DRAWLINE);
             return external_abort;
@@ -1672,15 +1672,15 @@
         } else if (y1 == y2) {
             line(x1, y1, x2, y2);
         } else {
-            WriteCommandW(0x91, x1);
-            WriteCommandW(0x93, y1);
-            WriteCommandW(0x95, x2);
-            WriteCommandW(0x97, y2);
+            WriteCommandW(RA8875_DLHSR0, x1);
+            WriteCommandW(RA8875_DLVSR0, y1);
+            WriteCommandW(RA8875_DLHER0, x2);
+            WriteCommandW(RA8875_DLVER0, y2);
             unsigned char drawCmd = 0x10;   // Rectangle
             if (fillit == FILL)
                 drawCmd |= 0x20;
-            WriteCommand(0x90, drawCmd);
-            ret = WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
+            WriteCommand(RA8875_DCR, drawCmd);
+            ret = WriteCommand(RA8875_DCR, 0x80 + drawCmd); // Start drawing.
             if (!_WaitWhileReg(0x90, 0x80)) {
                 REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
                 return external_abort;
@@ -1739,20 +1739,20 @@
     } else if (y1 == y2) {
         line(x1, y1, x2, y2);
     } else {
-        WriteCommandW(0x91, x1);
-        WriteCommandW(0x93, y1);
-        WriteCommandW(0x95, x2);
-        WriteCommandW(0x97, y2);
-        WriteCommandW(0xA1, radius1);
-        WriteCommandW(0xA3, radius2);
+        WriteCommandW(RA8875_DLHSR0, x1);
+        WriteCommandW(RA8875_DLVSR0, y1);
+        WriteCommandW(RA8875_DLHER0, x2);
+        WriteCommandW(RA8875_DLVER0, y2);
+        WriteCommandW(RA8875_ELLA0, radius1);
+        WriteCommandW(RA8875_ELLB0, radius2);
         // Should not need this...
-        WriteCommandW(0xA5, 0);
-        WriteCommandW(0xA7, 0);
+        WriteCommandW(RA8875_DEHR0, 0);
+        WriteCommandW(RA8875_DEVR0, 0);
         unsigned char drawCmd = 0x20;       // Rounded Rectangle
         if (fillit == FILL)
             drawCmd |= 0x40;
-        WriteCommand(0xA0, drawCmd);
-        WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
+        WriteCommand(RA8875_ELLIPSE, drawCmd);
+        WriteCommand(RA8875_ELLIPSE, 0x80 + drawCmd); // Start drawing.
         if (!_WaitWhileReg(0xA0, 0x80)) {
             REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
             return external_abort;
@@ -1801,17 +1801,17 @@
     if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) {
         pixel(x1, y1);
     } else {
-        WriteCommandW(0x91, x1);
-        WriteCommandW(0x93, y1);
-        WriteCommandW(0x95, x2);
-        WriteCommandW(0x97, y2);
-        WriteCommandW(0xA9, x3);
-        WriteCommandW(0xAB, y3);
+        WriteCommandW(RA8875_DLHSR0, x1);
+        WriteCommandW(RA8875_DLVSR0, y1);
+        WriteCommandW(RA8875_DLHER0, x2);
+        WriteCommandW(RA8875_DLVER0, y2);
+        WriteCommandW(RA8875_DTPH0, x3);
+        WriteCommandW(RA8875_DTPV0, y3);
         unsigned char drawCmd = 0x01;       // Triangle
         if (fillit == FILL)
             drawCmd |= 0x20;
-        WriteCommand(0x90, drawCmd);
-        WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
+        WriteCommand(RA8875_DCR, drawCmd);
+        WriteCommand(RA8875_DCR, 0x80 + drawCmd); // Start drawing.
         if (!_WaitWhileReg(0x90, 0x80)) {
             REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
             return external_abort;
@@ -1871,14 +1871,14 @@
     } else if (radius == 1) {
         pixel(x,y);
     } else {
-        WriteCommandW(0x99, x);
-        WriteCommandW(0x9B, y);
-        WriteCommand(0x9d, radius & 0xFF);
+        WriteCommandW(RA8875_DCHR0, x);
+        WriteCommandW(RA8875_DCVR0, y);
+        WriteCommand(RA8875_DCRR, radius & 0xFF);
         unsigned char drawCmd = 0x00;       // Circle
         if (fillit == FILL)
             drawCmd |= 0x20;
-        WriteCommand(0x90, drawCmd);
-        WriteCommand(0x90, 0x40 + drawCmd); // Start drawing.
+        WriteCommand(RA8875_DCR, drawCmd);
+        WriteCommand(RA8875_DCR, 0x40 + drawCmd); // Start drawing.
         if (!_WaitWhileReg(0x90, 0x40)) {
             REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
             return external_abort;
@@ -1914,15 +1914,15 @@
     } else if (radius1 == 1 && radius2 == 1) {
         pixel(x, y);
     } else {
-        WriteCommandW(0xA5, x);
-        WriteCommandW(0xA7, y);
-        WriteCommandW(0xA1, radius1);
-        WriteCommandW(0xA3, radius2);
+        WriteCommandW(RA8875_DEHR0, x);
+        WriteCommandW(RA8875_DEVR0, y);
+        WriteCommandW(RA8875_ELLA0, radius1);
+        WriteCommandW(RA8875_ELLB0, radius2);
         unsigned char drawCmd = 0x00;   // Ellipse
         if (fillit == FILL)
             drawCmd |= 0x40;
-        WriteCommand(0xA0, drawCmd);
-        WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
+        WriteCommand(RA8875_ELLIPSE, drawCmd);
+        WriteCommand(RA8875_ELLIPSE, 0x80 + drawCmd); // Start drawing.
         if (!_WaitWhileReg(0xA0, 0x80)) {
             REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
             return external_abort;
@@ -1975,15 +1975,15 @@
     srcPoint.y &= 0x1FF;
     dstPoint.x &= 0x3FF;
     dstPoint.y &= 0x1FF;
-    WriteCommandW(0x54, srcPoint.x);
-    WriteCommandW(0x56, ((dim_t)(srcLayer & 1) << 15) | srcPoint.y);
-    WriteCommandW(0x58, dstPoint.x);
-    WriteCommandW(0x5A, ((dim_t)(dstLayer & 1) << 15) | dstPoint.y);
-    WriteCommandW(0x5C, bte_width);
-    WriteCommandW(0x5E, bte_height);
-    WriteCommand(0x51,  ((bte_rop_code & 0x0F) << 4) | (bte_op_code & 0x0F));
+    WriteCommandW(RA8875_HSBE0, srcPoint.x);
+    WriteCommandW(RA8875_VSBE0, ((dim_t)(srcLayer & 1) << 15) | srcPoint.y);
+    WriteCommandW(RA8875_HDBE0, dstPoint.x);
+    WriteCommandW(RA8875_VDBE0, ((dim_t)(dstLayer & 1) << 15) | dstPoint.y);
+    WriteCommandW(RA8875_BEWR0, bte_width);
+    WriteCommandW(RA8875_BEHR0, bte_height);
+    WriteCommand(RA8875_BECR1,  ((bte_rop_code & 0x0F) << 4) | (bte_op_code & 0x0F));
     cmd = ((srcDataSelect & 1) << 6) | ((dstDataSelect & 1) << 5);
-    WriteCommand(0x50, 0x80 | cmd);     // enable the BTE
+    WriteCommand(RA8875_BECR0, 0x80 | cmd);     // enable the BTE
     if (!_WaitWhileBusy(0x40)) {
         REGISTERPERFORMANCE(PRF_BLOCKMOVE);
         return external_abort;
@@ -1995,7 +1995,7 @@
 
 RetCode_t RA8875::Power(bool on)
 {
-    WriteCommand(0x01, (on) ? 0x80 : 0x00);
+    WriteCommand(RA8875_PWRR, (on) ? 0x80 : 0x00);
     return noerror;
 }
 
@@ -2005,17 +2005,17 @@
     static bool is_enabled = false;
     
     if (brightness == 0) {
-        WriteCommand(0x8a); // Disable the PWM
+        WriteCommand(RA8875_P1CR); // Disable the PWM
         WriteData(0x00);
         is_enabled = false;
     } else if (!is_enabled) {
-        WriteCommand(0x8a); // Enable the PWM
+        WriteCommand(RA8875_P1CR); // Enable the PWM
         WriteData(0x80);
-        WriteCommand(0x8a); // Not sure why this is needed, but following the pattern
+        WriteCommand(RA8875_P1CR); // Not sure why this is needed, but following the pattern
         WriteData(0x81);    // open PWM (SYS_CLK / 2 as best I can tell)
         is_enabled = true;
     }
-    WriteCommand(0x8b, brightness);  // Brightness parameter 0xff-0x00
+    WriteCommand(RA8875_P1DCR, brightness);  // Brightness parameter 0xff-0x00
     return noerror;
 }