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:
207:82f336e5c021
Parent:
203:704df2dbd3e6
Child:
209:08fc22dea762
--- a/RA8875.h	Mon May 25 16:08:50 2020 +0000
+++ b/RA8875.h	Sun Apr 04 16:50:15 2021 +0000
@@ -14,12 +14,12 @@
 ///
 /// Aside from 800 x 480 pixel displays, another common implementation is
 /// 480 x 272 x 16 with two layers. The two layers can be exchanged, or blended
-/// in various ways (transparency, OR, AND, and more). 
+/// in various ways (transparency, OR, AND, and more).
 ///
 /// It is not a display for video-speed animations, and maybe could hold its own
-/// as a slow picture frame, at least when using the SPI interface. How the 
-/// performance differs using I2C, 8-bit parallel or 16-bit parallel has not 
-/// been evaluated. Certainly the parallel interface option would be expected to be 
+/// as a slow picture frame, at least when using the SPI interface. How the
+/// performance differs using I2C, 8-bit parallel or 16-bit parallel has not
+/// been evaluated. Certainly the parallel interface option would be expected to be
 /// a lot faster.
 ///
 /// What it is good at is performing as a basic display for appliances or simple
@@ -39,7 +39,7 @@
 /// It has some built-in fonts, which can be enhanced with optional font-chips, and
 /// with the software font engine that is part of this library. Instructions are provided
 /// to convert most any True Type Font into the data structures suitable for this display.
-/// The user of this library is expected to respect the copyright of those fonts (there 
+/// The user of this library is expected to respect the copyright of those fonts (there
 /// are open-source fonts that can be found on the web).
 ///
 /// To round out the features, this library offers the ability to render Bitmap (BMP),
@@ -49,7 +49,7 @@
 /// memory.
 ///
 /// When you are satisfied with what appears on screen, there is a PrintScreen method
-/// to pull that image back out of the display RAM and write it to a file system as a 
+/// to pull that image back out of the display RAM and write it to a file system as a
 /// BitMap image.
 ///
 ///
@@ -63,9 +63,9 @@
 /// Recent Changes:
 /// * @ref RA8875::SelectDrawingLayer() returns the previously selected layer, making restore quicker.
 /// * @ref RA8875::SetGraphicsOrientation() has been improved to support 0 deg (typical landscape),
-///             90 deg, 180 deg, and 270 deg, and this includes bitmap and soft-font presentation, 
+///             90 deg, 180 deg, and 270 deg, and this includes bitmap and soft-font presentation,
 ///             as well as touch support and to return the previous angle.
-/// * @ref RA8875::SetBackgroundTransparencyColor() returns the previous color value, making 
+/// * @ref RA8875::SetBackgroundTransparencyColor() returns the previous color value, making
 ///             restore quicker.
 /// * @ref RA8875::SetWindow() accepts a rect_t, or an (x1,y1, x2,y2) point-pair, rather than a
 ///             point-pair and a width,height. This makes it much more consisten with all other APIs.
@@ -96,7 +96,7 @@
 /// @todo Add Hardware reset signal - testing to date indicates it is not needed.
 /// @todo Add APIs for the 2nd RA8875 PWM channel. If the frequency can be independently
 ///     controlled, it could be used as a simple sound channel (beeper).
-/// @todo Find out if 4-wire SPI can leverage 16-bit mode, and if so, how does the 
+/// @todo Find out if 4-wire SPI can leverage 16-bit mode, and if so, how does the
 ///     performance change?
 ///
 /// @note As the author of this library, let me state that I am not affiliated with
@@ -563,8 +563,7 @@
     } halign_t;
 
     /// cursor type argument for @ref SetTextCursorControl()
-    typedef enum
-    {
+    typedef enum {
         NOCURSOR,   ///< cursor is hidden
         IBEAM,      ///< I Beam '|' cursor
         UNDER,      ///< Underscore '_' cursor
@@ -572,8 +571,7 @@
     } cursor_t;
 
     /// font type selection argument for @ref SetTextFont()
-    typedef enum
-    {
+    typedef enum {
         ISO8859_1,      ///< ISO8859-1 font
         ISO8859_2,      ///< ISO8859-2 font
         ISO8859_3,      ///< ISO8859-3 font
@@ -581,8 +579,7 @@
     } font_t;
 
     /// alignment control argument for @ref SetTextFontControl()
-    typedef enum
-    {
+    typedef enum {
         align_none,     ///< align - none
         align_full      ///< align - full
     } alignment_t;
@@ -594,15 +591,13 @@
     typedef int VerticalScale;
 
     /// Clear screen region option for @ref clsw()
-    typedef enum
-    {
+    typedef enum {
         FULLWINDOW,     ///< Full screen
         ACTIVEWINDOW    ///< active window/region
     } Region_t;
 
     /// Layer Display Mode argument for @ref SetLayerMode, @ref GetLayerMode
-    typedef enum
-    {
+    typedef enum {
         ShowLayer0,         ///< Only layer 0 is visible, layer 1 is hidden (default)
         ShowLayer1,         ///< Only layer 1 is visible, layer 0 is hidden
         LightenOverlay,     ///< Lighten-overlay mode
@@ -613,15 +608,13 @@
     } LayerMode_T;
 
     /// Touch Panel modes
-    typedef enum
-    {
+    typedef enum {
         TP_Auto,               ///< Auto touch detection mode
         TP_Manual,             ///< Manual touch detection mode
     } tpmode_t;
 
     /// PrintScreen callback commands for the user code @ref PrintCallback_T()
-    typedef enum
-    {
+    typedef enum {
         OPEN,       ///< command to open the file. cast uint32_t * to the buffer to get the total size to be written.
         WRITE,      ///< command to write some data, buffer points to the data and the size is in bytes.
         CLOSE,      ///< command to close the file
@@ -746,7 +739,7 @@
     ///         capturing stdout to puts() and printf() directly to it.
     ///
     RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset,
-        const char * name = "lcd");
+           const char * name = "lcd");
 
 
     /// Constructor for a display based on the RAiO RA8875 display controller
@@ -782,7 +775,7 @@
     ///         capturing stdout to puts() and printf() directly to it.
     ///
     RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset,
-        PinName sda, PinName scl, PinName irq, const char * name = "lcd");
+           PinName sda, PinName scl, PinName irq, const char * name = "lcd");
 
 
     /// Constructor for a display based on the RAiO RA8875 display controller
@@ -819,7 +812,7 @@
     ///         capturing stdout to puts() and printf() directly to it.
     ///
     RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset,
-        PinName sda, PinName scl, PinName wake, PinName irq, const char * name = "lcd");
+           PinName sda, PinName scl, PinName wake, PinName irq, const char * name = "lcd");
 
 
     // Destructor doesn't have much to do as this would typically be created
@@ -835,9 +828,9 @@
     ///
     /// Typical of the displays that are readily purchased, you will find 480x272 and 800x480 resolutions.
     ///
-    /// @param[in] width in pixels in landscape orientation to configure the display for. 
+    /// @param[in] width in pixels in landscape orientation to configure the display for.
     ///             This parameter is optional and the default is 480.
-    /// @param[in] height in pixels in landscape orientation to configure the display for. 
+    /// @param[in] height in pixels in landscape orientation to configure the display for.
     ///             This parameter is optional and the default is 272.
     /// @param[in] color_bpp can be either 8 or 16, but must be consistent
     ///             with the width and height parameters. This parameter is optional
@@ -858,7 +851,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t init(int width = 480, int height = 272, int color_bpp = 16,
-        uint8_t poweron = 40, bool keypadon = true, bool touchscreeenon = true);
+                   uint8_t poweron = 40, bool keypadon = true, bool touchscreeenon = true);
 
 
     /// Get a pointer to the text string representing the RetCode_t
@@ -1059,7 +1052,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t TouchPanelInit(uint8_t bTpEnable, uint8_t bTpAutoManual, uint8_t bTpDebounce,
-        uint8_t bTpManualMode, uint8_t bTpAdcClkDiv, uint8_t bTpAdcSampleTime);
+                             uint8_t bTpManualMode, uint8_t bTpAdcClkDiv, uint8_t bTpAdcSampleTime);
 
 
     /// Get the screen calibrated point of touch.
@@ -1114,14 +1107,20 @@
     ///
     /// @returns gesture information.
     ///
-    uint8_t TouchGesture(void) { return gesture; }
+    uint8_t TouchGesture(void)
+    {
+        return gesture;
+    }
 
 
     /// Get the count of registered touches.
     ///
     /// @returns count of touch points to communicate; 0 to 5.
     ///
-    int TouchCount(void) { return numberOfTouchPoints; }
+    int TouchCount(void)
+    {
+        return numberOfTouchPoints;
+    }
 
 
     /// Get the count of possible touch channels.
@@ -1458,9 +1457,9 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t  KeypadInit(bool scanEnable = true, bool longDetect = false,
-        uint8_t sampleTime = 0, uint8_t scanFrequency = 0,
-        uint8_t longTimeAdjustment = 0,
-        bool interruptEnable = false, bool wakeupEnable = false);
+                          uint8_t sampleTime = 0, uint8_t scanFrequency = 0,
+                          uint8_t longTimeAdjustment = 0,
+                          bool interruptEnable = false, bool wakeupEnable = false);
 
 
     /// Create Key Code definitions for the key matrix.
@@ -1971,9 +1970,9 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t SetTextFontControl(fill_t fillit = FILL,
-        HorizontalScale hScale = 1,
-        VerticalScale vScale = 1,
-        alignment_t alignment = align_none);
+                                 HorizontalScale hScale = 1,
+                                 VerticalScale vScale = 1,
+                                 alignment_t alignment = align_none);
 
 
     /// Control the font - to background fill or "ink-only"
@@ -2519,7 +2518,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        color_t color, fill_t fillit = NOFILL);
+                   color_t color, fill_t fillit = NOFILL);
 
 
     /// Draw a filled rectangle in the specified color
@@ -2536,7 +2535,7 @@
     /// @returns @ref RetCode_t value.
     ///
     virtual RetCode_t fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        color_t color, fill_t fillit = FILL);
+                               color_t color, fill_t fillit = FILL);
 
 
     /// Draw a rectangle
@@ -2551,7 +2550,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        fill_t fillit = NOFILL);
+                   fill_t fillit = NOFILL);
 
 
     /// Draw a filled rectangle with rounded corners using the specified color.
@@ -2579,7 +2578,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL);
+                            dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL);
 
 
     /// Draw a filled rectangle with rounded corners using the specified color.
@@ -2604,7 +2603,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t fillroundrect(rect_t r,
-        dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL);
+                            dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL);
 
 
     /// Draw a rectangle with rounded corners using the specified color.
@@ -2629,7 +2628,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t roundrect(rect_t r,
-        dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL);
+                        dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL);
 
 
     /// Draw a rectangle with rounded corners using the specified color.
@@ -2657,7 +2656,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL);
+                        dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL);
 
 
     /// Draw a rectangle with rounded corners.
@@ -2681,7 +2680,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        dim_t radius1, dim_t radius2, fill_t fillit = NOFILL);
+                        dim_t radius1, dim_t radius2, fill_t fillit = NOFILL);
 
 
     /// Draw a triangle in the specified color.
@@ -2728,7 +2727,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        loc_t x3, loc_t y3, color_t color, fill_t fillit = NOFILL);
+                       loc_t x3, loc_t y3, color_t color, fill_t fillit = NOFILL);
 
 
     /// Draw a filled triangle in the specified color.
@@ -2747,7 +2746,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        loc_t x3, loc_t y3, color_t color, fill_t fillit = FILL);
+                           loc_t x3, loc_t y3, color_t color, fill_t fillit = FILL);
 
 
     /// Draw a triangle
@@ -2764,7 +2763,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2,
-        loc_t x3, loc_t y3, fill_t fillit = NOFILL);
+                       loc_t x3, loc_t y3, fill_t fillit = NOFILL);
 
 
     /// Draw a circle using the specified color.
@@ -2863,7 +2862,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2,
-        color_t color, fill_t fillit = NOFILL);
+                      color_t color, fill_t fillit = NOFILL);
 
 
     /// Draw a filled Ellipse using the specified color
@@ -2880,7 +2879,7 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t fillellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2,
-        color_t color, fill_t fillit = FILL);
+                          color_t color, fill_t fillit = FILL);
 
 
     /// Draw an Ellipse
@@ -3007,9 +3006,9 @@
     /// @returns @ref RetCode_t value.
     ///
     RetCode_t BlockMove(uint8_t dstLayer, uint8_t dstDataSelect, point_t dstPoint,
-        uint8_t srcLayer, uint8_t srcDataSelect, point_t srcPoint,
-        dim_t bte_width, dim_t bte_height,
-        uint8_t bte_op_code, uint8_t bte_rop_code);
+                        uint8_t srcLayer, uint8_t srcDataSelect, point_t srcPoint,
+                        dim_t bte_width, dim_t bte_height,
+                        uint8_t bte_op_code, uint8_t bte_rop_code);
 
 
     /// Control display power
@@ -3078,7 +3077,10 @@
     ///
     /// @returns a pointer to the font, or null, if no user font is selected.
     ///
-    virtual const uint8_t * GetUserFont(void) { return font; }
+    virtual const uint8_t * GetUserFont(void)
+    {
+        return font;
+    }
 
     /// Get the @ref color_t value from a DOS color index.
     ///
@@ -3250,7 +3252,10 @@
     /// @param callback is the optional callback function. Without a callback function
     ///     it will unregister the handler.
     ///
-    void AttachPrintHandler(PrintCallback_T callback = NULL) { c_callback = callback; }
+    void AttachPrintHandler(PrintCallback_T callback = NULL)
+    {
+        c_callback = callback;
+    }
 
 
     /// PrintScreen callback registration.
@@ -3263,9 +3268,10 @@
     /// @param method is the callback method in the object to activate.
     ///
     template <class T>
-    void AttachPrintHandler(T *object, RetCode_t (T::*method)(void)) {
+    void AttachPrintHandler(T *object, RetCode_t (T::*method)(void))
+    {
         obj_callback    = (FPointerDummy *)object;
-        method_callback = (uint32_t (FPointerDummy::*)(uint32_t, uint8_t *, uint16_t))method;
+        method_callback = (RetCode_t (FPointerDummy::*)(filecmd_t, uint8_t *, uint16_t))method;
     }
 
 
@@ -3322,7 +3328,10 @@
     /// @param callback is the idle callback function. Without a callback function
     ///     it will unregister the handler.
     ///
-    void AttachIdleHandler(IdleCallback_T callback = NULL) { idle_callback = callback; }
+    void AttachIdleHandler(IdleCallback_T callback = NULL)
+    {
+        idle_callback = callback;
+    }
 
 
 #ifdef PERF_METRICS
@@ -3389,10 +3398,10 @@
 
     touchInfo_T * touchInfo;   /// Storage allocated by the constructor to contains the touch information
 
-    #if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0)
+#if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0)
     Thread eventThread;
     EventQueue queue;
-    #endif
+#endif
     InterruptIn * m_irq;
     I2C * m_i2c;
     int m_addr;                 /// I2C Address of the Cap Touch Controller
@@ -3402,14 +3411,14 @@
     ////////////////// Start of Resistive Touch Panel parameters
 
     /// Specify the default settings for the Touch Panel, where different from the chip defaults
-    #define TP_MODE_DEFAULT             TP_MODE_AUTO
-    #define TP_DEBOUNCE_DEFAULT         TP_DEBOUNCE_ON
-    #define TP_ADC_CLKDIV_DEFAULT       TP_ADC_CLKDIV_8
-
-    #define TP_ADC_SAMPLE_DEFAULT_CLKS  TP_ADC_SAMPLE_8192_CLKS
+#define TP_MODE_DEFAULT             TP_MODE_AUTO
+#define TP_DEBOUNCE_DEFAULT         TP_DEBOUNCE_ON
+#define TP_ADC_CLKDIV_DEFAULT       TP_ADC_CLKDIV_8
+
+#define TP_ADC_SAMPLE_DEFAULT_CLKS  TP_ADC_SAMPLE_8192_CLKS
 
     /// Other Touch Panel params
-    #define TPBUFSIZE   16       // Depth of the averaging buffers for x and y data
+#define TPBUFSIZE   16       // Depth of the averaging buffers for x and y data
 
     // Needs both a ticker and a timer. (could have created a timer from the ticker, but this is easier).
     // on a touch, the timer is reset.
@@ -3588,9 +3597,8 @@
     bool roundCap;                  ///< draw round end cap on thick lines when set.
     loc_t cursor_x, cursor_y;       ///< used for external fonts only
 
-    #ifdef PERF_METRICS
-    typedef enum
-    {
+#ifdef PERF_METRICS
+    typedef enum {
         PRF_CLS,
         PRF_DRAWPIXEL,
         PRF_PIXELSTREAM,
@@ -3610,17 +3618,17 @@
     unsigned long idletime_usec;
     void RegisterPerformance(method_e method);
     Timer performance;
-    #endif
+#endif
 
     RetCode_t _printCallback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size);
 
     FILE * _printFH;             ///< PrintScreen file handle
 
-    RetCode_t privateCallback(filecmd_t cmd, uint8_t * buffer, uint16_t size) {
+    RetCode_t privateCallback(filecmd_t cmd, uint8_t * buffer, uint16_t size)
+    {
         if (c_callback != NULL) {
             return (*c_callback)(cmd, buffer, size);
-        }
-        else {
+        } else {
             if (obj_callback != NULL && method_callback != NULL) {
                 return (obj_callback->*method_callback)(cmd, buffer, size);
             }