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:
77:9206c13aa527
Parent:
76:c981284eb513
Child:
78:faf49c381591
--- a/RA8875.h	Fri Nov 28 22:53:35 2014 +0000
+++ b/RA8875.h	Fri Dec 26 21:34:28 2014 +0000
@@ -2,17 +2,18 @@
 #define RA8875_H
 #include <mbed.h>
 
+#include "RA8875_Regs.h"
 #include "GraphicsDisplay.h"
 
 #define RA8875_DEFAULT_SPI_FREQ 5000000
 
 // Define this to enable code that monitors the performance of various
 // graphics commands.
-//#define PERF_METRICS
+#define PERF_METRICS
 
 // What better place for some test code than in here and the companion
 // .cpp file. See also the bottom of this file.
-//#define TESTENABLE
+#define TESTENABLE
 
 /// DOS colors - slightly color enhanced
 #define Black       (color_t)(RGB(0,0,0))
@@ -362,6 +363,77 @@
     ///
     uint8_t TouchPanelReadRaw(loc_t *x, loc_t *y);
     
+    
+    /// Calibrate the touch panel.
+    ///
+    /// This method accepts two lists - one list is target points in ,
+    /// display coordinates and the other is a lit of raw touch coordinate 
+    /// values. It generates a calibration matrix for later use. This
+    /// matrix is also accessible to the calling API, which may store
+    /// the matrix in persistent memory and then install the calibration
+    /// matrix on the next power cycle. By doing so, it can avoid the
+    /// need to calibrate on every power cycle.
+    ///
+    /// @note The methods "TouchPanelCalibrate", "TouchPanelPoint", and
+    ///     indirectly the "TouchPanelSetMatrix" methods are all derived
+    ///     from a program by Carlos E. Vidales. See the copyright note
+    ///     for further details. See also the article
+    ///     http://www.embedded.com/design/system-integration/4023968/How-To-Calibrate-Touch-Screens
+    ///
+    /// @copyright Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
+    /// This sample program was written and put in the public domain 
+    ///  by Carlos E. Vidales.  The program is provided "as is" 
+    ///  without warranty of any kind, either expressed or implied.
+    /// If you choose to use the program within your own products
+    ///  you do so at your own risk, and assume the responsibility
+    ///  for servicing, repairing or correcting the program should
+    ///  it prove defective in any manner.
+    /// You may copy and distribute the program's source code in any 
+    ///  medium, provided that you also include in each copy an
+    ///  appropriate copyright notice and disclaimer of warranty.
+    /// You may also modify this program and distribute copies of
+    ///  it provided that you include prominent notices stating 
+    ///  that you changed the file(s) and the date of any change,
+    ///  and that you do not charge any royalties or licenses for 
+    ///  its use.
+    ///
+    /// @param[in] display is a pointer to a set of 3 points, which 
+    ///             are in display units of measure. These are the targets
+    ///             the calibration was aiming for.
+    /// @param[in] screen is a pointer to a set of 3 points, which
+    ///             are in touchscreen units of measure. These are the
+    ///             registered touches.
+    /// @param[out] matrix is an optional parameter to hold the calibration matrix 
+    ///             as a result of the calibration. This can be saved in  
+    ///             non-volatile memory to recover the calibration after a power fail.
+    /// @returns success/failure code. @see RetCode_t.
+    ///
+    RetCode_t TouchPanelCalibrate(point_t display[3], point_t screen[3], tpMatrix_t * matrix);
+
+    /// Set the calibration matrix for the touch panel.
+    ///
+    /// This method is used to set the calibration matrix for the touch panel. After
+    /// performing the calibration (@see TouchPanelCalibrate), the matrix can be stored.
+    /// On a subsequence power cycle, the matrix may be restored from non-volatile and
+    /// passed in to this method. It will then be held to perform the corrections when
+    /// reading the touch panel point.
+    ///
+    /// @param[in] matrix is a pointer to the touch panel calibration matrix.
+    /// @returns success/failure code. @see RetCode_t.
+    ///
+    RetCode_t TouchPanelSetMatrix(tpMatrix_t * matrix);
+    
+    /// Get the screen calibrated point of touch.
+    ///
+    /// This method determines if there is a touch and if so it will provide
+    /// the screen-relative touch coordinates.
+    ///
+    /// @param[out] touch is the touch point, if a touch is registered.
+    /// @returns true if a touch was registered, no_touch if not, and bad_parameter if the 
+    ///     calibration matrix is not defined.
+    ///
+    RetCode_t TouchPanelPoint(point_t * touch);
+        
 #if 0
     /// Append interrupt handler for specific RA8875 interrupt source
     ///
@@ -388,6 +460,7 @@
     ///
     void UnAppendISR(uint8_t bISRType);
 #endif
+
     /// Initialize the keypad interface on the RA8875 controller.
     ///
     /// Enables the keypad subsystem. It will scan the 4 x 5 matrix
@@ -413,6 +486,7 @@
         uint8_t longTimeAdjustment = 0,
         bool interruptEnable = false, bool wakeupEnable = false);
 
+
     /// Create Key Code definitions for the key matrix.
     ///
     /// This API provides a table of 22 key-code assignments for the matrix of keys.
@@ -434,6 +508,13 @@
     /// //          +-------------------------+  +-------------------------+
     /// //     Return value  0 = No Key pressed
     /// //     Return value 21 = Error
+    /// const uint8_t CodeList[22] = 
+    ///     {0, '7', '8', '9', ',', '\h', 
+    ///         '4', '5', '6', '/', '-',
+    ///         '1', '2', '3', '*', '+',
+    ///         '0', '.', '(', ')', '\n', 
+    ///         '\x1b'};
+    ///     lcd.SetKeyMap(CodeList);
     /// @endcode
     /// 
     /// @param[in] CodeList is a pointer to an always available byte-array 
@@ -1376,75 +1457,29 @@
     void ReportPerformance(Serial & pc);
 #endif
 
-// Touch Panel public macros
-
-/* Touch Panel Enable/Disable Reg TPCR0[7] */
-#define TP_ENABLE   ((uint8_t)(1<<7))
-#define TP_DISABLE  ((uint8_t)(0<<7))
-
-/* Touch Panel operating mode Reg TPCR1[6] */
-#define TP_MODE_AUTO    ((uint8_t)(0<<6))   
-#define TP_MODE_MANUAL  ((uint8_t)(1<<6))
-
-/* Touch Panel debounce Reg TPCR1[2]    */
-#define TP_DEBOUNCE_OFF ((uint8_t)(0<<2))
-#define TP_DEBOUNCE_ON  ((uint8_t)(1<<2))
-
-/* Touch Panel manual modes Reg TPCR1[1:0]  */
-#define TP_MANUAL_IDLE      0
-#define TP_MANUAL_WAIT      1
-#define TP_MANUAL_LATCH_X   2
-#define TP_MANUAL_LATCH_Y   3
-
-/* Touch Panel ADC Clock modes Reg TPCR0[2:0] */
-#define TP_ADC_CLKDIV_1            0
-#define TP_ADC_CLKDIV_2            1        
-#define TP_ADC_CLKDIV_4            2        
-#define TP_ADC_CLKDIV_8            3      
-#define TP_ADC_CLKDIV_16           4        
-#define TP_ADC_CLKDIV_32           5        
-#define TP_ADC_CLKDIV_64           6        
-#define TP_ADC_CLKDIV_128          7
-        
-
-/* Touch Panel Sample Time Reg TPCR0[6:4] */
-#define TP_ADC_SAMPLE_512_CLKS     ((uint8_t)(0<<4))
-#define TP_ADC_SAMPLE_1024_CLKS    ((uint8_t)(1<<4))
-#define TP_ADC_SAMPLE_2048_CLKS    ((uint8_t)(2<<4))
-#define TP_ADC_SAMPLE_4096_CLKS    ((uint8_t)(3<<4))
-#define TP_ADC_SAMPLE_8192_CLKS    ((uint8_t)(4<<4))
-#define TP_ADC_SAMPLE_16384_CLKS   ((uint8_t)(5<<4))
-#define TP_ADC_SAMPLE_32768_CLKS   ((uint8_t)(6<<4))
-#define TP_ADC_SAMPLE_65536_CLKS   ((uint8_t)(7<<4))
-
-/* RA8875 interrupt enable/flag/clear masks */
-#define RA8875_INT_KEYSCAN          ((uint8_t)(1<<4))    /**< KEYSCAN interrupts  */
-#define RA8875_INT_DMA              ((uint8_t)(1<<3))    /**< DMA interrupts  */
-#define RA8875_INT_TP               ((uint8_t)(1<<2))    /**< Touch panel interrupts  */
-#define RA8875_INT_BTE              ((uint8_t)(1<<1))    /**< BTE process complete interrupts  */
-#define RA8875_INT_BTEMCU_FONTWR    ((uint8_t)(1<<0))    /**< BTE-MCU-R/W or Font-Write interrupts  */
-
 
 private:
     /// Touch Panel register name definitions
-#define TPCR0   0x70
-#define TPCR1   0x71
-#define TPXH    0x72
-#define TPYH    0x73
-#define TPXYL   0x74
-#define INTC1   0xF0
-#define INTC2   0xF1
+    #define TPCR0   0x70
+    #define TPCR1   0x71
+    #define TPXH    0x72
+    #define TPYH    0x73
+    #define TPXYL   0x74
+    #define INTC1   0xF0
+    #define INTC2   0xF1
 
     /// 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_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_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
 
+    /// Touch Panel calibration matrix.
+    tpMatrix_t tpMatrix;
 
     /// Initialize the chip, which is normally done as part of the
     /// constructor, so not typically called by the user.