Increased SPI frequency from 5Mhz to 10MHz

Fork of RA8875 by David Smart

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RA8875.h Source File

RA8875.h

00001 ///
00002 /// @mainpage RA8875 Display Controller Driver library
00003 ///
00004 /// The RA8875 Display controller is a powerful interface for low cost displays. It
00005 /// can support displays up to 800 x 600 pixels x 16-bit color. Another common 
00006 /// implementation is 480 x 272 x 16 with two layers. The two layers can be 
00007 /// exchanged, or blended in various ways (transparency, OR, AND, and more).
00008 /// It includes graphics acceleration capabilities for drawing primitives, 
00009 /// such as line, rectangle, circles, and more.
00010 ///
00011 /// It is not a display for super-fast animations, video, picture frames and so forth,
00012 /// at least when using the SPI ports. Performance has not been evaluated with one
00013 /// of the parallel port options.
00014 ///
00015 /// The controller additionally supports backlight control (via PWM), keypad scanning
00016 /// (for a 4 x 5 matrix) and resistive touch-panel support. Recently support for a 
00017 /// capacitive touch screen was integrated, in a manner that makes the resistive and
00018 /// capactive interfaces nearly identical.
00019 ///
00020 /// @section Display_Config Display Configuration
00021 ///
00022 /// This section details basics for bringing the display online. At a minimum,
00023 /// the display is instantiated. After that any of the available commands
00024 /// may be issued.
00025 ///
00026 /// During the instantiation, the display is powered on, cleared, and the backlight
00027 /// is energized. Additionally, the keypad and touchscreen features are activated.
00028 /// It is important to keep in mind that the keypad had the default mapping, and
00029 /// the touchscreen does not have the calibration matrix configured, so additional
00030 /// steps may be necessary.
00031 /// 
00032 /// @code 
00033 /// RA8875 lcd(p5, p6, p7, p12, NC, "tft");
00034 /// lcd.init();
00035 /// lcd.foreground(Blue);
00036 /// lcd.line(0,0, 479,271);
00037 /// ...
00038 /// @endcode
00039 ///
00040 /// @section Touch_Panel Touch Panel
00041 ///
00042 /// The supported touch panel interface is for a resistive panel, and is natively 
00043 /// supported by the RA8875 controller. There are a few steps to enable this interface.
00044 ///
00045 /// @subsection Touch_Panel_Enable Touch Panel Enable
00046 ///
00047 /// See @ref TouchPanelInit has two forms - fully automatic, and controlled. See the APIs for
00048 /// details.
00049 ///
00050 /// @subsection Touch_Panel_Calibration
00051 /// 
00052 /// The touch panel is not initially calibrated on startup. The application should 
00053 /// provide a means to activate the calibration process, and that should not require
00054 /// the touchscreen as it may not yet be usable. Alternately, a calibration matrix
00055 /// can be loaded from non-volatile and installed.
00056 ///
00057 /// @section Keypad Keypad
00058 ///
00059 /// The keypad has a default keypad mapping, but there is an API that permits
00060 /// installing a custom keymap.
00061 ///
00062 /// @todo Add APIs for the 2nd PWM channel, which might be quite useful as a simple
00063 ///     beeper.
00064 /// @todo Figure out how to "init()" in the constructor. I ran into some issues if
00065 ///     the display was instantiated before main(), and the code would not run,
00066 ///     thus the exposure and activation of the init() function. If the constructor
00067 ///     was within main(), then it seemed to work as expected.
00068 ///
00069 #ifndef RA8875_H
00070 #define RA8875_H
00071 #include <mbed.h>
00072 
00073 #include "RA8875_Regs.h"
00074 #include "GraphicsDisplay.h"
00075 
00076 #define RA8875_DEFAULT_SPI_FREQ 5000000
00077 
00078 // Define this to enable code that monitors the performance of various
00079 // graphics commands.
00080 //#define PERF_METRICS
00081 
00082 // What better place for some test code than in here and the companion
00083 // .cpp file. See also the bottom of this file.
00084 //#define TESTENABLE
00085 
00086 /// DOS colors - slightly color enhanced
00087 #define Black       (color_t)(RGB(0,0,0))
00088 #define Blue        (color_t)(RGB(0,0,187))
00089 #define Green       (color_t)(RGB(0,187,0))
00090 #define Cyan        (color_t)(RGB(0,187,187))
00091 #define Red         (color_t)(RGB(187,0,0))
00092 #define Magenta     (color_t)(RGB(187,0,187))
00093 #define Brown       (color_t)(RGB(63,63,0))
00094 #define Gray        (color_t)(RGB(187,187,187))
00095 #define Charcoal    (color_t)(RGB(85,85,85))
00096 #define BrightBlue  (color_t)(RGB(0,0,255))
00097 #define BrightGreen (color_t)(RGB(0,255,0))
00098 #define BrightCyan  (color_t)(RGB(0,255,255))
00099 #define BrightRed   (color_t)(RGB(255,0,0))
00100 #define Orange      (color_t)(RGB(255,85,85))
00101 #define Pink        (color_t)(RGB(255,85,255))
00102 #define Yellow      (color_t)(RGB(187,187,0))
00103 #define White       (color_t)(RGB(255,255,255))
00104 
00105 #define DarkBlue    (color_t)(RGB(0,0,63))
00106 #define DarkGreen   (color_t)(RGB(0,63,0))
00107 #define DarkCyan    (color_t)(RGB(0,63,63))
00108 #define DarkRed     (color_t)(RGB(63,0,0))
00109 #define DarkMagenta (color_t)(RGB(63,0,63))
00110 #define DarkBrown   (color_t)(RGB(63,63,0))
00111 #define DarkGray    (color_t)(RGB(63,63,63))
00112 
00113 #define min(a,b) ((a<b)?a:b)
00114 #define max(a,b) ((a>b)?a:b)
00115 
00116 
00117 /// FT5206 definitions follow
00118 #define FT5206_I2C_FREQUENCY                400000
00119 
00120 #define FT5206_I2C_ADDRESS                  0x38
00121 #define FT5206_NUMBER_OF_REGISTERS          31   // there are more registers, but this
00122                                                  // is enough to get all 5 touch coordinates.
00123 
00124 #define FT5206_NUMBER_OF_TOTAL_REGISTERS    0xFE
00125 
00126 #define FT5206_DEVICE_MODE                  0x00 // Normal, test, etc.
00127 #define FT5206_GEST_ID                      0x01 // Gesture detected
00128 #define FT5206_TD_STATUS                    0x02 // How many points detected (3:0). 1-5 is valid.
00129 
00130 #define FT5206_TOUCH1_XH                    0x03 // Event Flag, Touch X Position
00131 #define FT5206_TOUCH1_XL                    0x04
00132 #define FT5206_TOUCH1_YH                    0x05 // Touch ID, Touch Y Position
00133 #define FT5206_TOUCH1_YL                    0x06
00134 
00135 #define FT5206_TOUCH2_XH                    0x09 // Event Flag, Touch X Position
00136 #define FT5206_TOUCH2_XL                    0x0a
00137 #define FT5206_TOUCH2_YH                    0x0b // Touch ID, Touch Y Position
00138 #define FT5206_TOUCH2_YL                    0x0c
00139 
00140 #define FT5206_TOUCH3_XH                    0x0f // Event Flag, Touch X Position
00141 #define FT5206_TOUCH3_XL                    0x10
00142 #define FT5206_TOUCH3_YH                    0x11 // Touch ID, Touch Y Position
00143 #define FT5206_TOUCH3_YL                    0x12
00144 
00145 #define FT5206_TOUCH4_XH                    0x15 // Event Flag, Touch X Position
00146 #define FT5206_TOUCH4_XL                    0x16
00147 #define FT5206_TOUCH4_YH                    0x17 // Touch ID, Touch Y Position
00148 #define FT5206_TOUCH4_YL                    0x18
00149 
00150 #define FT5206_TOUCH5_XH                    0x1b // Event Flag, Touch X Position
00151 #define FT5206_TOUCH5_XL                    0x1c
00152 #define FT5206_TOUCH5_YH                    0x1d // Touch ID, Touch Y Position
00153 #define FT5206_TOUCH5_YL                    0x1e
00154 
00155 // For typical usage, the registers listed below are not used.
00156 #define FT5206_ID_G_THGROUP                 0x80 // Valid touching detect threshold
00157 #define FT5206_ID_G_THPEAK                  0x81 // Valid touching peak detect threshold
00158 #define FT5206_ID_G_THCAL                   0x82 // The threshold when calculating the focus of touching
00159 #define FT5206_ID_G_THWATER                 0x83 // The threshold when there is surface water
00160 #define FT5206_ID_G_THTEMP                  0x84 // The threshold of temperature compensation
00161 #define FT5206_ID_G_CTRL                    0x86 // Power control mode
00162 #define FT5206_ID_G_TIME_ENTER_MONITOR      0x87 // The timer of entering monitor status
00163 #define FT5206_ID_G_PERIODACTIVE            0x88 // Period Active
00164 #define FT5206_ID_G_PERIODMONITOR           0x89 // The timer of entering idle while in monitor status
00165 #define FT5206_ID_G_AUTO_CLB_MODE           0xA0 // Auto calibration mode
00166 
00167 #define FT5206_TOUCH_LIB_VERSION_H          0xA1 // Firmware Library Version H byte
00168 #define FT5206_TOUCH_LIB_VERSION_L          0xA2 // Firmware Library Version L byte
00169 #define FT5206_ID_G_CIPHER                  0xA3 // Chip vendor ID
00170 #define FT5206_G_MODE                       0xA4 // The interrupt status to host
00171 #define FT5206_ID_G_PMODE                   0xA5 // Power Consume Mode
00172 #define FT5206_FIRMID                       0xA6 // Firmware ID
00173 #define FT5206_ID_G_STATE                   0xA7 // Running State
00174 #define FT5206_ID_G_FT5201ID                0xA8 // CTPM Vendor ID
00175 #define FT5206_ID_G_ERR                     0xA9 // Error Code
00176 #define FT5206_ID_G_CLB                     0xAA // Configure TP module during calibration in Test Mode
00177 #define FT5206_ID_G_B_AREA_TH               0xAE // The threshold of big area
00178 #define FT5206_LOG_MSG_CNT                  0xFE // The log MSG count
00179 #define FT5206_LOG_CUR_CHA                  0xFF // Current character of log message, will point to the next
00180                                                  // character when one character is read.
00181 #define FT5206_GEST_ID_MOVE_UP              0x10
00182 #define FT5206_GEST_ID_MOVE_LEFT            0x14
00183 #define FT5206_GEST_ID_MOVE_DOWN            0x18
00184 #define FT5206_GEST_ID_MOVE_RIGHT           0x1c
00185 #define FT5206_GEST_ID_ZOOM_IN              0x48
00186 #define FT5206_GEST_ID_ZOOM_OUT             0x49
00187 #define FT5206_GEST_ID_NO_GESTURE           0x00
00188 
00189 #define FT5206_EVENT_FLAG_PUT_DOWN          0x00
00190 #define FT5206_EVENT_FLAG_PUT_UP            0x01
00191 #define FT5206_EVENT_FLAG_CONTACT           0x02
00192 #define FT5206_EVENT_FLAG_RESERVED          0x03
00193 
00194 #define FT5206_ID_G_POLLING_MODE            0x00
00195 #define FT5206_ID_G_TRIGGER_MODE            0x01
00196 
00197 #define FT5206_ID_G_PMODE_ACTIVE            0x00
00198 #define FT5206_ID_G_PMODE_MONITOR           0x01
00199 #define FT5206_ID_G_PMODE_HIBERNATE         0x03
00200 
00201 #define FT5206_ID_G_STATE_CONFIGURE         0x00
00202 #define FT5206_ID_G_STATE_WORK              0x01
00203 #define FT5206_ID_G_STATE_CALIBRATION       0x02
00204 #define FT5206_ID_G_STATE_FACTORY           0x03
00205 #define FT5206_ID_G_STATE_AUTO_CALIBRATION  0x04
00206 /// end of FT5206 definitions
00207 
00208 
00209 //namespace SW_graphics
00210 //{
00211 
00212 class FPointerDummy;    // used by the callback methods.
00213 
00214 /// This is a graphics library for the Raio RA8875 Display Controller chip
00215 /// attached to a 4-wire SPI interface.
00216 ///
00217 /// It offers both primitive and high level APIs.
00218 ///
00219 /// Central to this API is a coordinate system, where the origin (0,0) is in
00220 /// the top-left corner of the display, and the width (x) extends positive to the
00221 /// right and the height (y) extends positive toward the bottom.
00222 ///
00223 /// @note As there are both graphics and text commands, one must take care to use
00224 /// the proper coordinate system for each. Some of the text APIs are in units
00225 /// of column and row, which is measured in character positions (and dependent
00226 /// on the font size), where other text APIs permit pixel level positioning.
00227 ///
00228 /// @code
00229 /// #include "RA8875.h"
00230 /// RA8875 lcd(p5, p6, p7, p12, NC, "tft");
00231 ///
00232 /// int main()
00233 /// {
00234 ///     lcd.init();
00235 ///     lcd.printf("printing 3 x 2 = %d", 3*2);
00236 ///     lcd.circle(       400,25,  25,               BrightRed);
00237 ///     lcd.fillcircle(   400,25,  15,               RGB(128,255,128));
00238 ///     lcd.ellipse(      440,75,  35,20,            BrightBlue);
00239 ///     lcd.fillellipse(  440,75,  25,10,            Blue);
00240 ///     lcd.triangle(     440,100, 475,110, 450,125, Magenta);
00241 ///     lcd.filltriangle( 445,105, 467,111, 452,120, Cyan);
00242 ///     lcd.rect(         400,130, 475,155,          Brown);
00243 ///     lcd.fillrect(     405,135, 470,150,          Pink);
00244 ///     lcd.roundrect(    410,160, 475,190, 10,8,    Yellow);
00245 ///     lcd.fillroundrect(415,165, 470,185,  5,3,    Orange);
00246 ///     lcd.line(         430,200, 460,230,          RGB(0,255,0));
00247 ///     for (int i=0; i<=30; i+=5) 
00248 ///         lcd.pixel(435+i,200+i, White);
00249 /// }
00250 /// @endcode
00251 ///
00252 /// @todo Add Scroll support for text.
00253 /// @todo Add Hardware reset signal - but testing to date indicates it is not needed.
00254 /// @todo Add high level objects - x-y graph, meter, others... but these will
00255 ///     probably be best served in another class, since they may not
00256 ///     be needed for many uses.
00257 /// 
00258 class RA8875 : public GraphicsDisplay
00259 {
00260 public:   
00261     /// cursor type to be shown as the text cursor.
00262     typedef enum
00263     {
00264         NOCURSOR,   ///< cursor is hidden
00265         IBEAM,      ///< | cursor
00266         UNDER,      ///< _ cursor
00267         BLOCK       ///< Block cursor
00268     } cursor_t;
00269 
00270     /// font type selection.
00271     typedef enum
00272     {
00273         ISO8859_1,      ///< ISO8859-1 font
00274         ISO8859_2,      ///< ISO8859-2 font
00275         ISO8859_3,      ///< ISO8859-3 font
00276         ISO8859_4       ///< ISO8859-4 font
00277     } font_t;
00278     
00279     /// display orientation
00280     typedef enum
00281     {
00282         normal,         ///< normal (landscape) orientation
00283         rotate_0 = normal,  ///< alternate to 'normal'
00284         rotate_90,      ///< rotated clockwise 90 degree
00285         rotate_180,     ///< rotated (clockwise) 180 degree
00286         rotate_270,     ///< rotated clockwise 270 degree
00287     } orientation_t;
00288     
00289     /// alignment  
00290     typedef enum
00291     {
00292         align_none,     ///< align - none
00293         align_full      ///< align - full
00294     } alignment_t;    
00295     
00296     /// Font Horizontal Scale factor - 1, 2, 3 4
00297     typedef int HorizontalScale;
00298     
00299     /// Font Vertical Scale factor - 1, 2, 3, 4
00300     typedef int VerticalScale;
00301 
00302     /// Clear screen region
00303     typedef enum
00304     {
00305         FULLWINDOW,     ///< Full screen
00306         ACTIVEWINDOW    ///< active window/region
00307     } Region_t;
00308     
00309     /// Set the Layer Display Mode. @ref SetLayerMode
00310     typedef enum
00311     {
00312         ShowLayer0,         ///< Only layer 0 is visible, layer 1 is hidden (default)
00313         ShowLayer1,         ///< Only layer 1 is visible, layer 0 is hidden
00314         LightenOverlay,     ///< Lighten-overlay mode
00315         TransparentMode,    ///< Transparent mode
00316         BooleanOR,          ///< Boolean OR mode
00317         BooleanAND,         ///< Boolean AND mode
00318         FloatingWindow      ///< Floating Window mode
00319     } LayerMode_T;
00320     
00321     /// Touch Panel modes
00322     typedef enum
00323     {
00324         TP_Auto,               ///< Auto touch detection mode
00325         TP_Manual,             ///< Manual touch detection mode
00326     } tpmode_t;
00327 
00328     /// printscreen callback commands
00329     typedef enum
00330     {
00331         OPEN,       ///< command to open the file. cast uint32_t * to the buffer to get the total size to be written.
00332         WRITE,      ///< command to write some data, buffer points to the data and the size is in bytes.
00333         CLOSE,      ///< command to close the file
00334     } filecmd_t;
00335 
00336     /// print screen callback
00337     ///
00338     /// The special form of the print screen will pass one blob at a time 
00339     /// to the callback. There are basic command declaring that the stream
00340     /// can be opened, a block written, and the stream closed. There is
00341     /// also a command to communicate the total size being delivered.
00342     ///
00343     /// @code
00344     /// lcd.PrintScreen(x,y,w,h,callback);
00345     /// ... 
00346     /// void callback(filecmd_t cmd, uint8_t * buffer, uint16_t size) {
00347     ///     switch(cmd) {
00348     ///         case OPEN:
00349     ///             pc.printf("About to write %u bytes\r\n", *(uint32_t *)buffer);
00350     ///             fh = fopen("file.bmp", "w+b");
00351     ///             break;
00352     ///         case WRITE:
00353     ///             fwrite(buffer, size, fh);
00354     ///             break;
00355     ///         case CLOSE:
00356     ///             fclose(fh);
00357     ///             break;
00358     ///         default:
00359     ///             pc.printf("Unexpected callback %d\r\n", cmd);
00360     ///             break;
00361     ///     }
00362     /// }
00363     /// @endcode
00364     ///
00365     /// @param cmd is the command to execute. See @ref filecmd_t.
00366     /// @param buffer is a pointer to the buffer being passed.
00367     /// @param size is the number of bytes in the buffer.
00368     /// @returns the noerror signal.
00369     ///
00370     typedef RetCode_t (* PrintCallback_T)(filecmd_t cmd, uint8_t * buffer, uint16_t size);
00371     
00372     /// Idle reason provided in the Idle Callback
00373     typedef enum {
00374         unknown,            ///< reason has not been assigned (this should not happen)
00375         status_wait,        ///< driver is polling the status register while busy
00376         command_wait,       ///< driver is polling the command register while busy
00377         getc_wait,          ///< user has called the getc function
00378         touch_wait,         ///< user has called the touch function
00379         touchcal_wait       ///< driver is performing a touch calibration
00380     } IdleReason_T;
00381     
00382     /// Idle Callback 
00383     ///
00384     /// This defines the interface for an idle callback. That is, when the 
00385     /// driver is held up, pending some event, it can call a previously registered
00386     /// idle function. This could be most useful for servicing a watchdog.
00387     ///
00388     /// The user code, which is notified via this API, can force the idle
00389     /// to abort, by returning the external_abort value back to the driver.
00390     /// It is important to note that the abort could leave the driver in
00391     /// an undesireable state, so this should be used with care.
00392     ///
00393     /// @note Should it be called the BusyCallback? It is true, that it will
00394     ///     call this function when the RA8875 is busy, but this is also
00395     ///     when the CPU is largely idle.
00396     ///
00397     /// @code
00398     /// RetCode_t myIdle_handler(RA8875::IdleReason_T reason)
00399     /// {
00400     ///     idleFlasher = !idleFlasher;
00401     ///     if (it_has_been_too_long())
00402     ///         return external_abort;
00403     ///     else
00404     ///         return noerror;
00405     /// }
00406     /// @endcode
00407     ///
00408     /// @param reason informs the callback why it is idle.
00409     /// @returns noerror to allow the driver continue waiting.
00410     /// @returns external_abort if the pending action should be aborted.
00411     ///
00412     typedef RetCode_t (* IdleCallback_T)(IdleReason_T reason);
00413 
00414     /// Basic constructor for a display based on the RAiO RA8875 
00415     /// display controller, which can be used with no touchscreen,
00416     /// or the RA8875 managed resistive touchscreen.
00417     ///
00418     /// This constructor differs from the alternate by supportting
00419     /// either No Touch Screen, or the RA8875 built-in resistive
00420     /// touch screen. If the application requires the use of the
00421     /// capacitive touchscreen, the alternate constructor should 
00422     /// be used.
00423     ///
00424     /// This configures the registers and calls the @ref init method.
00425     ///
00426     /// @code
00427     /// #include "RA8875.h"
00428     /// RA8875 lcd(p5, p6, p7, p12, NC, "tft");
00429     ///
00430     /// int main()
00431     /// {
00432     ///     lcd.init();
00433     ///     lcd.printf("printing 3 x 2 = %d", 3*2);
00434     ///     lcd.circle(400,25, 25, BrightRed);
00435     /// }
00436     /// @endcode
00437     ///
00438     /// @param[in] mosi is the SPI master out slave in pin on the mbed.
00439     /// @param[in] miso is the SPI master in slave out pin on the mbed.
00440     /// @param[in] sclk is the SPI shift clock pin on the mbed.
00441     /// @param[in] csel is the DigitalOut pin on the mbed to use as the
00442     ///         active low chip select for the display controller.
00443     /// @param[in] reset is the DigitalOut pin on the mbed to use as the 
00444     ///         active low reset input on the display controller - 
00445     ///         but this is not currently used.
00446     /// @param[in] name is a text name for this object, which will permit
00447     ///         capturing stdout to puts() and printf() directly to it.
00448     ///
00449     RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, 
00450         const char * name = "lcd");
00451     
00452     
00453     /// Constructor for a display based on the RAiO RA8875 
00454     /// display controller (use for TouchScreen: Capacitive only)
00455     ///
00456     /// This constructor differs from the alternate by including support
00457     /// for the Capactive Touch screen.
00458     ///
00459     /// @code
00460     /// #include "RA8875.h"
00461     /// RA8875 lcd(p5, p6, p7, p12, NC, p9,p10,p13, "tft");
00462     /// 
00463     /// int main()
00464     /// {
00465     ///     lcd.init();
00466     ///     lcd.printf("printing 3 x 2 = %d", 3*2);
00467     ///     lcd.circle(400,25, 25, BrightRed);
00468     ///     TouchCode_t tp = lcd.TouchPanelReadable();
00469     ///     if (tp == touch)
00470     ///         ...
00471     /// }
00472     /// @endcode
00473     ///
00474     /// @param[in] mosi is the SPI master out slave in pin on the mbed.
00475     /// @param[in] miso is the SPI master in slave out pin on the mbed.
00476     /// @param[in] sclk is the SPI shift clock pin on the mbed.
00477     /// @param[in] csel is the DigitalOut pin on the mbed to use as the
00478     ///         active low chip select for the display controller.
00479     /// @param[in] reset is the DigitalOut pin on the mbed to use as the 
00480     ///         active low reset input on the display controller - 
00481     ///         but this is not currently used.
00482     /// @param[in] sda is the I2C Serial Data pin you are wiring to the FT5206.
00483     /// @param[in] scl is the I2C Serial Clock pin you are wiring to the FT5206.
00484     /// @param[in] irq is the Interrupt Request pin you are wiring to the FT5206.
00485     /// @param[in] name is a text name for this object, which will permit
00486     ///         capturing stdout to puts() and printf() directly to it.
00487     ///
00488     RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, 
00489         PinName sda, PinName scl, PinName irq, const char * name = "lcd");
00490     
00491     
00492     // Destructor doesn't have much to do as this would typically be created
00493     // at startup, and not at runtime.
00494     //~RA8875();
00495     
00496     /// Initialize the driver.
00497     ///
00498     /// The RA8875 can control typical displays from the 480x272 to 800x480, and it supports 8 or 16-bit color. 
00499     /// It also supports 2 graphics layers, but it cannot support 2 layers at the maximum color depth and 
00500     /// screen size. When configured under 480x400, it will support both 16-bit color depth and 2 drawing layers. 
00501     /// Above 480x400 it support either 16-bit color, or 2 layers, but not both.
00502     ///
00503     /// Typical of the displays that are readily purchased, you will find 480x272 and 800x480 resolutions.
00504     ///
00505     /// @param[in] width in pixels to configure the display for. This parameter is optional
00506     ///             and the default is 480.
00507     /// @param[in] height in pixels to configure the display for. This parameter is optional
00508     ///             and the default is 272.
00509     /// @param[in] color_bpp can be either 8 or 16, but must be consistent
00510     ///             with the width and height parameters. This parameter is optional
00511     ///             and the default is 16.
00512     /// @param[in] poweron defines if the display should be initialized into the power-on or off state.
00513     ///            If power is non-zero(on), the backlight is set to this value. This parameter is optional
00514     ///             and the default is 255 (on and full brightness). See @ref Power.
00515     /// @param[in] keypadon defines if the keypad support should be enabled. This parameter is optional
00516     ///             and the default is true (enabled). See @ref KeypadInit.
00517     /// @param[in] touchscreeenon defines if the touchscreen support should be enabled. 
00518     ///             This parameter is optional and the default is true (enabled). See @ref TouchPanelInit.
00519     ///             - If the constructor was called with support for the capacitive driver, this 
00520     ///             parameter causes the driver to initialize.
00521     ///             - If the constructor was called without support for the capacitive driver, this
00522     ///             parameter is used to enable and initialize the resistive touchscreen driver.
00523     /// @returns success/failure code. See @ref RetCode_t.
00524     ///
00525     RetCode_t init(int width = 480, int height = 272, int color_bpp = 16, 
00526         uint8_t poweron = 255, bool keypadon = true, bool touchscreeenon = true);
00527 
00528 
00529     /// Get a pointer to the error code.
00530     ///
00531     /// This method returns a pointer to a text string that matches the
00532     /// code. See @ref RetCode_t.
00533     ///
00534     /// @param[in] code is the return value from RetCode_t to look up.
00535     /// @returns a pointer to the text message representing code. If code
00536     ///     is not a valid value, then it returns the text for bad_parameter;
00537     ///
00538     const char * GetErrorMessage(RetCode_t code);
00539     
00540     
00541     /// Select the drawing layer for subsequent commands.
00542     ///
00543     /// If the screen configuration is 480 x 272, or if it is 800 x 480 
00544     /// and 8-bit color, the the display supports two layers, which can 
00545     /// be independently drawn on and shown. Additionally, complex
00546     /// operations involving both layers are permitted.
00547     ///
00548     /// @attention If the current display configuration does not support
00549     ///     multiple layers, then layer 0 will be selected.
00550     ///
00551     /// @code
00552     ///     //lcd.SetLayerMode(OnlyLayer0); // default is layer 0
00553     ///     lcd.rect(400,130, 475,155,Brown);
00554     ///     lcd.SelectDrawingLayer(1);
00555     ///     lcd.circle(400,25, 25, BrightRed);
00556     ///     wait(1);
00557     ///     lcd.SetLayerMode(ShowLayer1);
00558     /// @endcode
00559     ///
00560     /// @attention The user manual refers to Layer 1 and Layer 2, however the
00561     ///     actual register values are value 0 and 1. This API as well as
00562     ///     others that reference the layers use the values 0 and 1 for
00563     ///     cleaner iteration in the code.
00564     ///
00565     /// @param[in] layer is 0 or 1 to select the layer for subsequent 
00566     ///     commands.
00567     /// @param[out] prevLayer is an optiona pointer to where the previous layer
00568     ///     will be written, making it a little easer to restore layers.
00569     ///     Writes 0 or 1 when the pointer is not NULL.
00570     /// @returns success/failure code. See @ref RetCode_t.
00571     ///
00572     virtual RetCode_t SelectDrawingLayer(uint16_t layer, uint16_t * prevLayer = NULL);
00573  
00574     
00575     /// Get the currently active drawing layer.
00576     ///
00577     /// This returns a value, 0 or 1, based on the screen configuration
00578     /// and the currently active drawing layer.
00579     ///
00580     /// @code
00581     ///     uint16_t prevLayer = lcd.GetDrawingLayer();
00582     ///     lcd.SelectDrawingLayer(x);
00583     ///     lcd.circle(400,25, 25, BrightRed);
00584     ///     lcd.SelectDrawingLayer(prevLayer);
00585     /// @endcode
00586     ///
00587     /// @attention The user manual refers to Layer 1 and Layer 2, however the
00588     ///     actual register values are value 0 and 1. This API as well as
00589     ///     others that reference the layers use the values 0 and 1 for
00590     ///     cleaner iteration in the code.
00591     ///
00592     /// @returns the current drawing layer; 0 or 1.
00593     /// 
00594     virtual uint16_t GetDrawingLayer(void);
00595  
00596     
00597     /// Set the Layer presentation mode.
00598     ///
00599     /// This sets the presentation mode for layers, and permits showing
00600     /// a single layer, or applying a mode where the two layers
00601     /// are combined using one of the hardware methods.
00602     ///
00603     /// Refer to the RA8875 data sheet for full details.
00604     ///
00605     /// @code
00606     ///     //lcd.SetLayerMode(OnlyLayer0); // default is layer 0
00607     ///     lcd.rect(400,130, 475,155,Brown);
00608     ///     lcd.SelectDrawingLayer(1);
00609     ///     lcd.circle(400,25, 25, BrightRed);
00610     ///     wait(1);
00611     ///     lcd.SetLayerMode(ShowLayer1);
00612     /// @endcode
00613     ///
00614     /// @param[in] mode sets the mode in the Layer Transparency Register.
00615     /// @returns success/failure code. See @ref RetCode_t.
00616     ///
00617     RetCode_t SetLayerMode(LayerMode_T mode);
00618  
00619     
00620     /// Get the Layer presentation mode.
00621     ///
00622     /// This gets the current layer mode. See @ref LayerMode_T.
00623     ///
00624     /// @returns layer mode.
00625     ///
00626     LayerMode_T GetLayerMode(void);
00627  
00628     
00629     /// Set the layer transparency for each layer.
00630     ///
00631     /// Set the transparency, where the range of values is
00632     /// from zero (fully visible) to eight (fully transparent).
00633     /// The input value is automatically limited to this range.
00634     ///
00635     /// @code
00636     ///     // draw something on each layer, then step-fade across
00637     ///     display.SetLayerMode(RA8875::TransparentMode);
00638     ///     for (i=0; i<=8; i++) {
00639     ///         display.SetLayerTransparency(i, 8-i);
00640     ///         wait_ms(200);
00641     ///     }
00642     /// @endcode
00643     ///
00644     /// @param[in] layer1 sets the layer 1 transparency.
00645     /// @param[in] layer2 sets the layer 2 transparency.
00646     /// @returns success/failure code. See @ref RetCode_t.
00647     /// 
00648     RetCode_t SetLayerTransparency(uint8_t layer1, uint8_t layer2);
00649  
00650     
00651     /// Set the background color register used for transparency.
00652     ///
00653     /// This command sets the background color registers that are used
00654     /// in the transparent color operations involving the layers.
00655     /// 
00656     /// @param[in] color is optional and expressed in 16-bit format. If not
00657     ///     supplied, a default of Black is used.
00658     /// @returns success/failure code. See @ref RetCode_t.
00659     ///
00660     RetCode_t SetBackgroundTransparencyColor(color_t color = RGB(0,0,0));
00661  
00662  
00663     /// Get the background color value used for transparency.
00664     ///
00665     /// This command reads the background color registers that define
00666     /// the transparency color for operations involving layers.
00667     ///
00668     /// @returns the color.
00669     ///
00670     color_t GetBackgroundTransparencyColor(void);
00671  
00672  
00673     /// Initialize theTouch Panel controller with default values 
00674     ///
00675     /// This activates the simplified touch panel init, which may work for
00676     /// most uses. The alternate API is available if fine-grained control
00677     /// of the numerous settings of the resistive panel is needed.
00678     ///
00679     /// @returns success/failure code. See @ref RetCode_t.
00680     ///
00681     RetCode_t TouchPanelInit(void);
00682         
00683  
00684     /// Initialize the Touch Panel controller with detailed settings.
00685     ///
00686     /// This is the detailed touch panel init, which provides the ability
00687     /// to set nearly every option.
00688     ///
00689     /// @note If the capacitive touch panel was constructed, this behaves
00690     ///     the same as the simplified version.
00691     ///
00692     /// @param[in]  bTpEnable           Touch Panel enable/disable control:
00693     ///                                 - TP_ENABLE: enable the touch panel
00694     ///                                 - TP_DISABLE: disable the touch panel
00695     /// @param[in]  bTpAutoManual       Touch Panel operating mode:
00696     ///                                 - TP_MODE_AUTO: automatic capture
00697     ///                                 - TP_MODE_MANUAL: manual capture
00698     /// @param[in]  bTpDebounce         Debounce circuit enable for touch panel interrupt:
00699     ///                                 - TP_DEBOUNCE_OFF: disable the debounce circuit
00700     ///                                 - TP_DEBOUNCE_ON: enable the debounce circuit     
00701     /// @param[in]  bTpManualMode       When Manual Mode is selected, this sets the mode:
00702     ///                                 - TP_MANUAL_IDLE: touch panel is idle   
00703     ///                                 - TP_MANUAL_WAIT: wait for touch panel event   
00704     ///                                 - TP_MANUAL_LATCH_X: latch X data  
00705     ///                                 - TP_MANUAL_LATCH_Y: latch Y data   
00706     /// @param[in]  bTpAdcClkDiv        Sets the ADC clock as a fraction of the System CLK:
00707     ///                                 - TP_ADC_CLKDIV_1: Use CLK   
00708     ///                                 - TP_ADC_CLKDIV_2: Use CLK/2   
00709     ///                                 - TP_ADC_CLKDIV_4: Use CLK/4   
00710     ///                                 - TP_ADC_CLKDIV_8: Use CLK/8   
00711     ///                                 - TP_ADC_CLKDIV_16: Use CLK/16   
00712     ///                                 - TP_ADC_CLKDIV_32: Use CLK/32   
00713     ///                                 - TP_ADC_CLKDIV_64: Use CLK/64   
00714     ///                                 - TP_ADC_CLKDIV_128: Use CLK/128   
00715     /// @param[in]  bTpAdcSampleTime    Touch Panel sample time delay before ADC data is ready:
00716     ///                                 - TP_ADC_SAMPLE_512_CLKS: Wait 512 system clocks   
00717     ///                                 - TP_ADC_SAMPLE_1024_CLKS: Wait 1024 system clocks   
00718     ///                                 - TP_ADC_SAMPLE_2048_CLKS: Wait 2048 system clocks   
00719     ///                                 - TP_ADC_SAMPLE_4096_CLKS: Wait 4096 system clocks   
00720     ///                                 - TP_ADC_SAMPLE_8192_CLKS: Wait 8192 system clocks   
00721     ///                                 - TP_ADC_SAMPLE_16384_CLKS: Wait 16384 system clocks   
00722     ///                                 - TP_ADC_SAMPLE_32768_CLKS: Wait 32768 system clocks   
00723     ///                                 - TP_ADC_SAMPLE_65536_CLKS: Wait 65536 system clocks
00724     /// @returns success/failure code. See @ref RetCode_t.   
00725     ///
00726     RetCode_t TouchPanelInit(uint8_t bTpEnable, uint8_t bTpAutoManual, uint8_t bTpDebounce, 
00727         uint8_t bTpManualMode, uint8_t bTpAdcClkDiv, uint8_t bTpAdcSampleTime);
00728     
00729     
00730     /// Get the screen calibrated point of touch.
00731     ///
00732     /// This method determines if there is a touch and if so it will provide
00733     /// the screen-relative touch coordinates. This method can be used in
00734     /// a manner similar to Serial.readable(), to determine if there was a 
00735     /// touch and indicate that - but not care about the coordinates. Alternately,
00736     /// if a valid pointer to a point_t is provided, then if a touch is detected
00737     /// the point_t will be populated with data. 
00738     ///
00739     /// @code
00740     ///     Timer t;
00741     ///     t.start();
00742     ///     do {
00743     ///        point_t point = {0, 0};
00744     ///        if (display.TouchPanelReadable(&point)) {
00745     ///            display.pixel(point, Red);
00746     ///        }
00747     ///    } while (t.read_ms() < 30000);
00748     /// @endcode
00749     ///
00750     /// @param[out] TouchPoint is a pointer to a point_t, which is set as the touch point, if a touch is registered.
00751     /// @returns a value indicating the state of the touch,
00752     ///         - no_cal:   no calibration matrix is available, touch coordinates are not returned.
00753     ///         - no_touch: no touch is detected, touch coordinates are not returned.
00754     ///         - touch:    touch is detected, touch coordinates are returned.
00755     ///         - held:     held after touch, touch coordinates are returned.
00756     ///         - release:  indicates a release, touch coordinates are returned.
00757     ///
00758     TouchCode_t TouchPanelReadable(point_t * TouchPoint = NULL);
00759 
00760 
00761     /// Get the reported touch gesture, if any.
00762     /// 
00763     /// If it could detect a gesture, it will return a value based on
00764     /// the interpreted gesture.
00765     ///
00766     /// Valid gesture values are:
00767     /// @li 0x00 No gesture
00768     /// @li 0x48 Zoom in
00769     /// @li 0x49 Zoom out
00770     ///
00771     /// The following gestures are defined in the FT5206 specification, but
00772     /// do not appear to work.
00773     /// @li 0x10 Move up
00774     /// @li 0x14 Move left
00775     /// @li 0x18 Move down
00776     /// @li 0x1C Move right
00777     ///
00778     /// @returns gesture information.
00779     ///
00780     uint8_t TouchGesture(void) { return gesture; }
00781     
00782 
00783     /// Get the count of registered touches.
00784     ///
00785     /// @returns count of touch points to communicate; 0 to 5.
00786     ///
00787     int TouchCount(void) { return numberOfTouchPoints; }
00788 
00789     
00790     /// Get the count of possible touch channels.
00791     ///
00792     /// @returns count of touch channels supported by the hardware.
00793     ///
00794     int TouchChannels(void);
00795 
00796     
00797     /// Get the Touch ID value for a specified touch channel.
00798     ///
00799     /// Touch ID is a tracking number based on the order of the touch
00800     /// detections. The first touch is ID 0, the next is ID 1, and 
00801     /// so on. If the first touch is lifted (no touch), the touch count
00802     /// decrements, and the remaining touch is communicated on
00803     /// touch channel zero, even as the Touch ID remains as originally
00804     /// reported (1 in this example). In this way, it is easy to track 
00805     /// a specific touch.
00806     ///
00807     /// It is possible to query the data for a channel that is not
00808     /// presently reported as touched.
00809     ///
00810     /// @param[in] channel is the touch channel, from 0 to 4, or 0 to getTouchCount()-1
00811     ///     It defaults to 0, in case the user is not interested in multi-touch.
00812     /// @returns the touch ID, or 15 if you get the ID for an untouched channel.
00813     /// @returns 0 if an invalid channel is queried.
00814     ///
00815     uint8_t TouchID(uint8_t channel = 0) { return (channel < 5) ? touchInfo[channel].touchID : touchInfo[0].touchID; }
00816 
00817     
00818     /// Get the Touch Code for a touch channel.
00819     ///
00820     /// It is possible to query the data for a channel that is not
00821     /// presently reported as touched.
00822     ///
00823     /// @param[in] channel is the touch channel, from 0 to 4, or 0 to getTouchCount()-1
00824     ///     It defaults to 0, in case the user is not interested in multi-touch.
00825     /// @returns the touch code (@ref TouchCode_t).
00826     /// @returns channel 0 information if an invalid channel is queried.
00827     ///
00828     TouchCode_t TouchCode(uint8_t channel = 0) { return (channel < 5) ? touchInfo[channel].touchCode : touchInfo[0].touchCode; }
00829 
00830 
00831     /// Get the coordinates for a touch channel.
00832     ///
00833     /// This returns the (X,Y) coordinates for a touch channel.
00834     ///
00835     ///
00836     /// It is possible to query the data for a channel that is not
00837     /// presently reported as touched.
00838     ///
00839     /// @param[in] channel is an optional touch channel, from 0 to 4, or 0 to getTouchCount()-1.
00840     ///     It defaults to 0, in case the user is not interested in multi-touch.
00841     /// @returns the coordinates as a point_t structure.
00842     /// @returns channel 0 information if an invalid channel is queried.
00843     ///
00844     point_t TouchCoordinates(uint8_t channel = 0)  { return (channel < 5) ? touchInfo[channel].coordinates : touchInfo[0].coordinates; }
00845 
00846 
00847     /// Poll the TouchPanel and on a touch event return the a to d filtered x, y coordinates.
00848     ///
00849     /// This method reads the touch controller, which has a 10-bit range for each the
00850     /// x and the y axis.
00851     ///
00852     /// @note The returned values are not in display (pixel) units but are in analog to
00853     ///     digital converter units.
00854     /// 
00855     /// @note This API is usually not needed and is likely to be deprecated. 
00856     ///     See @ref TouchPanelComputeCalibration. 
00857     ///     See @ref TouchPanelReadable.
00858     /// 
00859     /// @param[out] x is the x scale a/d value.
00860     /// @param[out] y is the y scale a/d value.
00861     /// @returns a value indicating the state of the touch,
00862     ///         - no_cal:   no calibration matrix is available, touch coordinates are not returned.
00863     ///         - no_touch: no touch is detected, touch coordinates are not returned.
00864     ///         - touch:    touch is detected, touch coordinates are returned.
00865     ///         - held:     held after touch, touch coordinates are returned.
00866     ///         - release:  indicates a release, touch coordinates are returned.
00867     ///
00868     TouchCode_t TouchPanelA2DFiltered(int *x, int *y);
00869 
00870 
00871     /// Poll the TouchPanel and on a touch event return the a to d raw x, y coordinates.
00872     ///
00873     /// This method reads the touch controller, which has a 10-bit range for each the
00874     /// x and the y axis. A number of samples of the raw data are taken, filtered,
00875     /// and the results are returned. 
00876     ///
00877     /// @note The returned values are not in display (pixel) units but are in analog to
00878     ///     digital converter units.
00879     /// 
00880     /// @note This API is usually not needed and is likely to be deprecated. 
00881     ///     See @ref TouchPanelComputeCalibration. 
00882     ///     See @ref TouchPanelReadable.
00883     /// 
00884     /// @param[out] x is the x scale a/d value.
00885     /// @param[out] y is the y scale a/d value.
00886     /// @returns a value indicating the state of the touch,
00887     ///         - no_cal:   no calibration matrix is available, touch coordinates are not returned.
00888     ///         - no_touch: no touch is detected, touch coordinates are not returned.
00889     ///         - touch:    touch is detected, touch coordinates are returned.
00890     ///         - held:     held after touch, touch coordinates are returned.
00891     ///         - release:  indicates a release, touch coordinates are returned.
00892     ///
00893     TouchCode_t TouchPanelA2DRaw(int *x, int *y);
00894 
00895     
00896     /// Wait for a touch panel touch and return it.
00897     /// 
00898     /// This method is similar to Serial.getc() in that it will wait for a touch
00899     /// and then return. In order to extract the coordinates of the touch, a
00900     /// valid pointer to a point_t must be provided.
00901     ///
00902     /// @note There is no timeout on this function, so its use is not recommended.
00903     ///
00904     /// @code
00905     ///     Timer t;
00906     ///     t.start();
00907     ///     do {
00908     ///        point_t point = {0, 0};
00909     ///        display.TouchPanelGet(&point);   // hangs here until touch
00910     ///        display.pixel(point, Red);
00911     ///    } while (t.read_ms() < 30000);
00912     /// @endcode
00913     ///
00914     /// @param[out] TouchPoint is the touch point, if a touch is registered.
00915     /// @returns a value indicating the state of the touch,
00916     ///         - no_cal:   no calibration matrix is available, touch coordinates are not returned.
00917     ///         - no_touch: no touch is detected, touch coordinates are not returned.
00918     ///         - touch:    touch is detected, touch coordinates are returned.
00919     ///         - held:     held after touch, touch coordinates are returned.
00920     ///         - release:  indicates a release, touch coordinates are returned.
00921     ///
00922     TouchCode_t TouchPanelGet(point_t * TouchPoint);
00923 
00924 
00925     /// Calibrate the touch panel.
00926     ///
00927     /// This method accepts two lists - one list is target points in ,
00928     /// display coordinates and the other is a lit of raw touch coordinate 
00929     /// values. It generates a calibration matrix for later use. This
00930     /// matrix is also accessible to the calling API, which may store
00931     /// the matrix in persistent memory and then install the calibration
00932     /// matrix on the next power cycle. By doing so, it can avoid the
00933     /// need to calibrate on every power cycle.
00934     ///
00935     /// @note The methods "TouchPanelComputeCalibration", "TouchPanelReadable", and
00936     ///     indirectly the "TouchPanelSetMatrix" methods are all derived
00937     ///     from a program by Carlos E. Vidales. See the copyright note
00938     ///     for further details. See also the article
00939     ///     http://www.embedded.com/design/system-integration/4023968/How-To-Calibrate-Touch-Screens
00940     ///
00941     /// @copyright Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
00942     ///     This sample program was written and put in the public domain 
00943     ///      by Carlos E. Vidales.  The program is provided "as is" 
00944     ///      without warranty of any kind, either expressed or implied.
00945     ///     If you choose to use the program within your own products
00946     ///      you do so at your own risk, and assume the responsibility
00947     ///      for servicing, repairing or correcting the program should
00948     ///      it prove defective in any manner.
00949     ///     You may copy and distribute the program's source code in any 
00950     ///      medium, provided that you also include in each copy an
00951     ///      appropriate copyright notice and disclaimer of warranty.
00952     ///     You may also modify this program and distribute copies of
00953     ///      it provided that you include prominent notices stating 
00954     ///      that you changed the file(s) and the date of any change,
00955     ///      and that you do not charge any royalties or licenses for 
00956     ///      its use.
00957     ///
00958     /// @param[in] display is a pointer to a set of 3 points, which 
00959     ///             are in display units of measure. These are the targets
00960     ///             the calibration was aiming for.
00961     /// @param[in] screen is a pointer to a set of 3 points, which
00962     ///             are in touchscreen units of measure. These are the
00963     ///             registered touches.
00964     /// @param[out] matrix is an optional parameter to hold the calibration matrix 
00965     ///             as a result of the calibration. This can be saved in  
00966     ///             non-volatile memory to recover the calibration after a power fail.
00967     /// @returns success/failure code. See @ref RetCode_t.
00968     ///
00969     RetCode_t TouchPanelComputeCalibration(point_t display[3], point_t screen[3], tpMatrix_t * matrix);
00970 
00971 
00972     /// Perform the touch panel calibration process.
00973     ///
00974     /// This method provides the easy "shortcut" to calibrating the touch panel.
00975     /// The process will automatically generate the calibration points, present
00976     /// the targets on-screen, detect the touches, compute the calibration
00977     /// matrix, and optionally provide the calibration matrix to the calling code
00978     /// for persistence in non-volatile memory.
00979     ///
00980     /// @param[out] matrix is an optional parameter to hold the calibration matrix 
00981     ///             as a result of the calibration. This can be saved in  
00982     ///             non-volatile memory to recover the calibration after a power fail.
00983     /// @returns success/failure code. See @ref RetCode_t.
00984     ///
00985     RetCode_t TouchPanelCalibrate(tpMatrix_t * matrix = NULL);
00986 
00987 
00988     /// Perform the touch panel calibration process.
00989     ///
00990     /// This method provides the easy "shortcut" to calibrating the touch panel.
00991     /// The process will automatically generate the calibration points, present
00992     /// the targets on-screen, detect the touches, compute the calibration
00993     /// matrix, and optionally provide the calibration matrix to the calling code
00994     /// for persistence in non-volatile memory.
00995     ///
00996     /// @param[in] msg is a text message to present on the screen during the
00997     ///             calibration process.
00998     /// @param[out] matrix is an optional parameter to hold the calibration matrix 
00999     ///             as a result of the calibration. This can be saved in  
01000     ///             non-volatile memory to recover the calibration after a power fail.
01001     /// @param[in] maxwait_s is the maximum number of seconds to wait for a touch
01002     ///             calibration. If no touch panel installed, it then reports
01003     ///             touch_cal_timeout.
01004     /// @returns success/failure code. See @ref RetCode_t.
01005     ///
01006     RetCode_t TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix = NULL, int maxwait_s = 15);
01007 
01008 
01009     /// Set the calibration matrix for the touch panel.
01010     ///
01011     /// This method is used to set the calibration matrix for the touch panel. After
01012     /// performing the calibration (See @ref TouchPanelComputeCalibration), the matrix can be stored.
01013     /// On a subsequence power cycle, the matrix may be restored from non-volatile and
01014     /// passed in to this method. It will then be held to perform the corrections when
01015     /// reading the touch panel point.
01016     ///
01017     /// @code
01018     /// FILE * fh = fopen("/local/tpmatrix.cfg", "r");
01019     /// if (fh) {
01020     ///     tpMatrix_t matrix;
01021     ///     if (fread(fh, &matrix, sizeof(tpMatrix_t))) {
01022     ///         lcd.TouchPanelSetMatrix(&matrix);
01023     ///     }
01024     ///     fclose(fh);
01025     /// }
01026     /// @endcode
01027     /// 
01028     /// @param[in] matrix is a pointer to the touch panel calibration matrix.
01029     /// @returns success/failure code. See @ref RetCode_t.
01030     ///
01031     RetCode_t TouchPanelSetMatrix(tpMatrix_t * matrix);
01032    
01033 
01034 #if 0
01035     /// Append interrupt handler for specific RA8875 interrupt source
01036     ///
01037     /// @param[in]    bISRType        Interrupt Source, should be:
01038     ///                                - RA8875_INT_KEYSCAN: KEYCAN interrupt
01039     ///                                - RA8875_INT_DMA: DMA interrupt
01040     ///                                - RA8875_INT_TP: Touch panel interrupt
01041     ///                                - RA8875_INT_BTE: BTE process complete interrupt
01042     ///                                - RA8875_INT_BTEMCU_FONTWR: Multi-purpose interrupt (see spec sheet)   
01043     /// @param[in]    fptr is a callback function to handle the interrupt event.
01044     /// @returns       none
01045     ///
01046     void AppendISR(uint8_t bISRType, void(*fptr)(void));
01047 
01048     /// Unappend interrupt handler for specific RA8875 interrupt source
01049     ///
01050     /// @param[in]    bISRType        Interrupt Source, should be:
01051     ///                                - RA8875_INT_KEYSCAN: KEYCAN interrupt
01052     ///                                - RA8875_INT_DMA: DMA interrupt
01053     ///                                - RA8875_INT_TP: Touch panel interrupt
01054     ///                                - RA8875_INT_BTE: BTE process complete interrupt
01055     ///                                - RA8875_INT_BTEMCU_FONTWR: Multi-purpose interrupt (see spec sheet)   
01056     /// @return       none
01057     ///
01058     void UnAppendISR(uint8_t bISRType);
01059 #endif
01060 
01061 
01062     /// Initialize the keypad interface on the RA8875 controller.
01063     ///
01064     /// Enables the keypad subsystem. It will scan the 4 x 5 matrix
01065     /// and make available key presses.
01066     ///
01067     /// @note See section 5-13 of RAIO RA8875 data sheet for more details.
01068     /// @note When using the display from buy-display.com, be sure that
01069     ///     the option for the keypad is configured on the hardware.
01070     ///
01071     /// All parameters are optional.
01072     /// @param[in] scanEnable when true, enables the key scan function (default: true).
01073     /// @param[in] longDetect when true, additionally enables the long key held detection (default: false).
01074     /// @param[in] sampleTime setting (range: 0 - 3, default: 0).
01075     /// @param[in] scanFrequency setting (range: 0 - 7, default: 0).
01076     /// @param[in] longTimeAdjustment (range: 0 - 3, default: 0).
01077     /// @param[in] interruptEnable when true, enables interrupts from keypress (default: false).
01078     /// @param[in] wakeupEnable when true, activates the wakeup function (default: false).
01079     ///
01080     /// @returns success/failure code. See @ref RetCode_t.
01081     ///
01082     RetCode_t  KeypadInit(bool scanEnable = true, bool longDetect = false, 
01083         uint8_t sampleTime = 0, uint8_t scanFrequency = 0, 
01084         uint8_t longTimeAdjustment = 0,
01085         bool interruptEnable = false, bool wakeupEnable = false);
01086 
01087 
01088     /// Create Key Code definitions for the key matrix.
01089     ///
01090     /// This API provides a table of 22 key-code assignments for the matrix of keys.
01091     /// This can be used to translate the keys 1 - 20 into some other value, as
01092     /// well as to communicate the "no key" (zero) and "error state" (21).
01093     ///
01094     /// In this way, a keypad could easily emulate a piece of a keyboard, transforming
01095     /// 0 - 20 into the values 0, '0', '1', '2', '3', '4', '5', '6', '7', '8',
01096     /// '9', '+', '-', '*' , '/', '=', '(bs)', '(cr)', and so on...
01097     ///
01098     /// @code
01099     /// //        Return Value by Row, Column   Example reassignment
01100     /// //    Column    0    1    2    3    4 
01101     /// //          +-------------------------+  +-------------------------+
01102     /// // Row   0  |   1    2    3    4    5 |  | '7'  '8'  '9'  ',' '<-' |
01103     /// //       1  |   6    7    8    9   10 |  | '4'  '5'  '6'  '/'  '-' |
01104     /// //       2  |  11   12   13   14   15 |  | '1'  '2'  '3'  '*'  '+' |
01105     /// //       3  |  16   17   18   19   20 |  | '0'  '.'  '('  ')' '\n' |
01106     /// //          +-------------------------+  +-------------------------+
01107     /// //     Return value  0 = No Key pressed
01108     /// //     Return value 21 = Error
01109     /// const uint8_t CodeList[22] = 
01110     ///     {0, '7', '8', '9', ',', '\h', 
01111     ///         '4', '5', '6', '/', '-',
01112     ///         '1', '2', '3', '*', '+',
01113     ///         '0', '.', '(', ')', '\n', 
01114     ///         '\x1b'};
01115     ///     lcd.SetKeyMap(CodeList);
01116     /// @endcode
01117     /// 
01118     /// @param[in] CodeList is a pointer to an always available byte-array 
01119     ///             where the first 22 bytes are used as the transformation 
01120     ///             from raw code to your reassigned value.
01121     ///            If CodeList is NULL, the original raw value key map is
01122     ///             restored.
01123     /// @returns noerror.
01124     ///
01125     RetCode_t SetKeyMap(const uint8_t * CodeList = NULL);
01126 
01127 
01128     /// Determine if a key has been hit
01129     ///
01130     /// @returns true if a key has been hit
01131     ///
01132     bool readable();
01133 
01134 
01135     /// Blocking read of the keypad.
01136     ///
01137     /// @note: This is a blocking read, so it is important to first call _kbhit()
01138     ///         to avoid hanging your processes.
01139     ///
01140     /// A keypad connected to the RA8875 is connected in a matrix of 4 rows and 5 columns.
01141     /// When pressed, this method will return a code in the range of 1 through 20, reserving
01142     /// the value 0 to indicate that no key is pressed.
01143     ///
01144     /// Additionally, if configured to detect a "long press", bit 7 will be set to indicate
01145     /// this. In this situation, first a "normal press" would be detected and signaled and
01146     /// soon after that a "long press" of the same key would be detected and communicated.
01147     ///
01148     /// @return 8-bit where bit 7 indicates a long press. The remaining bits indicate the
01149     ///     keypress using 0 = no key pressed, 1 - 20 = the key pressed.
01150     ///
01151     uint8_t getc();
01152     
01153     
01154     /// Determine if a point is within a rectangle.
01155     ///
01156     /// @param[in] rect is a rectangular region to use.
01157     /// @param[in] p is a point to analyze to see if it is within the rect.
01158     /// @returns true if p is within rect.
01159     ///
01160     bool Intersect(rect_t rect, point_t p);
01161 
01162     /// Determine if a rectangle intersects another rectangle.
01163     ///
01164     /// @param[in] rect1 is a rectangular region.
01165     /// @param[in] rect2 is a second rectangular region.
01166     /// @returns true if any part of rect2 intersects rect1.
01167     ///
01168     bool Intersect(rect_t rect1, rect_t rect2);
01169     
01170     /// Determine if a rectangle intersects another rectangle and provides
01171     /// the area of intersection.
01172     ///
01173     /// @code
01174     ///     +---------------------+
01175     ///     | rect1               |
01176     ///     |                     |
01177     ///     |          +------------------+
01178     ///     |          | rect3    |       |
01179     ///     |          |          |       |
01180     ///     +---------------------+       |
01181     ///                | rect2            |
01182     ///                +------------------+
01183     /// @endcode
01184     ///
01185     /// @note that the first parameter is a pointer to a rect and the 
01186     ///
01187     /// @param[inout] pRect1 is a pointer to a rectangular region, and returns
01188     ///             the area of intersection.
01189     /// @param[in] pRect2 is a pointer to a second rectangular region.
01190     /// @returns true if pRect1 and pRect2 intersect and pRect1 is written with
01191     ///             the rectangle describing the intersection.
01192     ///
01193     bool Intersect(rect_t * rect1, const rect_t * rect2);
01194     
01195     
01196     /// Write a command to the display with a word of data.
01197     ///
01198     /// This is a high level command, and may invoke several primitives.
01199     ///
01200     /// @param[in] command is the command to write.
01201     /// @param[in] data is data to be written to the command register.
01202     /// @returns success/failure code. See @ref RetCode_t.
01203     ///
01204     RetCode_t WriteCommandW(uint8_t command, uint16_t data);
01205 
01206 
01207     /// Write a command to the display
01208     ///
01209     /// This is a high level command, and may invoke several primitives.
01210     ///
01211     /// @param[in] command is the command to write.
01212     /// @param[in] data is optional data to be written to the command register
01213     ///     and only occurs if the data is in the range [0 - 0xFF].
01214     /// @returns success/failure code. See @ref RetCode_t.
01215     ///
01216     virtual RetCode_t WriteCommand(unsigned char command, unsigned int data = 0xFFFF);
01217 
01218     
01219     /// Write a data word to the display
01220     ///
01221     /// This is a high level command, and may invoke several primitives.
01222     ///
01223     /// @param[in] data is the data to write.
01224     /// @returns success/failure code. See @ref RetCode_t.
01225     ///
01226     RetCode_t WriteDataW(uint16_t data);
01227 
01228     
01229     /// Write a data byte to the display
01230     ///
01231     /// This is a high level command, and may invoke several primitives.
01232     ///
01233     /// @param[in] data is the data to write.
01234     /// @returns success/failure code. See @ref RetCode_t.
01235     ///
01236     virtual RetCode_t WriteData(unsigned char data);
01237 
01238     
01239     /// Read a command register
01240     ///
01241     /// @param[in] command is the command register to read.
01242     /// @returns the value read from the register.
01243     ///
01244     unsigned char ReadCommand(unsigned char command);
01245 
01246 
01247     /// Read a word from a command register
01248     ///
01249     /// @param[in] command is the command register to read.
01250     /// @returns the value read from the register.
01251     ///
01252     uint16_t ReadCommandW(unsigned char command);
01253     
01254     
01255     /// Read a data byte from the display
01256     ///
01257     /// This is a high level command, and may invoke several primitives.
01258     ///
01259     /// @returns data that was read.
01260     ///
01261     unsigned char ReadData(void);
01262 
01263     
01264     /// Read a word from the display
01265     ///
01266     /// This is a high level command, and may invoke several primitives.
01267     ///
01268     /// @returns data that was read.
01269     ///
01270     uint16_t ReadDataW(void);
01271 
01272 
01273     /// Read the display status
01274     ///
01275     /// This is a high level command, and may invoke several primitives.
01276     ///
01277     /// @returns data that was read.
01278     ///
01279     unsigned char ReadStatus(void);
01280 
01281 
01282     /// get the width in pixels of the currently active font
01283     ///
01284     /// @returns font width in pixels.
01285     ///    
01286     dim_t fontwidth(void);
01287     
01288 
01289     /// get the height in pixels of the currently active font
01290     ///
01291     /// @returns font height in pixels.
01292     ///    
01293     dim_t fontheight(void);
01294 
01295     
01296     /// get the number of colums based on the currently active font
01297     ///
01298     /// @returns number of columns.
01299     ///    
01300     virtual int columns(void);
01301 
01302 
01303     /// get the number of rows based on the currently active font
01304     ///
01305     /// @returns number of rows.
01306     ///    
01307     virtual int rows(void);
01308 
01309 
01310     /// get the screen width in pixels
01311     ///
01312     /// @returns screen width in pixels.
01313     ///
01314     virtual dim_t width(void);
01315 
01316 
01317     /// get the screen height in pixels
01318     ///
01319     /// @returns screen height in pixels.
01320     ///
01321     virtual dim_t height(void);
01322 
01323 
01324     /// get the color depth in bits per pixel.
01325     ///
01326     /// @returns 8 or 16 only.
01327     ///
01328     virtual dim_t color_bpp(void);
01329 
01330     /// Set cursor position based on the current font size.
01331     /// 
01332     /// @param[in] column is the horizontal position in character positions
01333     /// @param[in] row is the vertical position in character positions
01334     /// @returns success/failure code. See @ref RetCode_t.
01335     ///
01336     virtual RetCode_t locate(textloc_t column, textloc_t row);
01337 
01338 
01339     /// Prepare the controller to write text to the screen by positioning
01340     /// the cursor.
01341     ///
01342     /// @code
01343     ///     lcd.SetTextCursor(100, 25);
01344     ///     lcd.puts("Hello");
01345     /// @endcode
01346     ///
01347     /// @param[in] x is the horizontal position in pixels (from the left edge)
01348     /// @param[in] y is the vertical position in pixels (from the top edge)
01349     /// @returns success/failure code. See @ref RetCode_t.
01350     ///
01351     RetCode_t SetTextCursor(loc_t x, loc_t y);
01352 
01353 
01354     /// Prepare the controller to write text to the screen by positioning
01355     /// the cursor.
01356     ///
01357     /// @code
01358     ///     point_t point = {100, 25};
01359     ///     lcd.SetTextCursor(point);
01360     ///     lcd.puts("Hello");
01361     /// @endcode
01362     ///
01363     /// @param[in] p is the x:y point in pixels from the top-left.
01364     /// @returns success/failure code. See @ref RetCode_t.
01365     ///
01366     RetCode_t SetTextCursor(point_t p);
01367 
01368 
01369     /// Get the current cursor position in pixels.
01370     ///
01371     /// @code
01372     ///     point_t point = GetTextCursor();
01373     ///     if (point.x > 100 && point.y > 150)
01374     ///         //...
01375     /// @endcode
01376     ///
01377     /// @returns cursor position.
01378     ///
01379     point_t GetTextCursor(void);
01380     
01381 
01382     /// Get the current cursor horizontal position in pixels.
01383     ///
01384     /// @returns cursor position horizontal offset.
01385     ///
01386     loc_t GetTextCursor_X(void);
01387 
01388 
01389     /// Get the current cursor vertical position in pixels.
01390     ///
01391     /// @returns cursor position vertical offset.
01392     ///
01393     loc_t GetTextCursor_Y(void);
01394 
01395 
01396     /// Configure additional Cursor Control settings.
01397     ///
01398     /// This API lets you modify other cursor control settings; 
01399     /// Cursor visible/hidden, Cursor blink/normal, 
01400     /// Cursor I-Beam/underscore/box.
01401     ///
01402     /// @param[in] cursor can be set to NOCURSOR (default), IBEAM,
01403     ///         UNDER, or BLOCK.
01404     /// @param[in] blink can be set to true or false (default false)
01405     /// @returns success/failure code. See @ref RetCode_t
01406     ///
01407     RetCode_t SetTextCursorControl(cursor_t cursor = NOCURSOR, bool blink = false);
01408 
01409     
01410     /// Select the built-in ISO 8859-X font to use next.
01411     ///
01412     /// Supported fonts: ISO 8859-1, -2, -3, -4
01413     ///
01414     /// @note This only modifies the choice of font from the RA8875 internal
01415     ///     fonts.
01416     ///
01417     /// @param[in] font selects the font for the subsequent text rendering.
01418     ///
01419     /// @note if either hScale or vScale is outside of its permitted range,
01420     ///     the command is not executed.
01421     /// @returns success/failure code. See @ref RetCode_t.
01422     ///
01423     RetCode_t SetTextFont(font_t font = ISO8859_1);
01424     
01425 
01426     /// Sets the display orientation.
01427     ///
01428     /// @note This command does not let you "merge" text onto an existing
01429     ///       image, since it reuses the memory for the new orientation.
01430     ///       Therefore, it is recommended that you issue a cls() prior
01431     ///       to sending text to the screen, or you end with a blended
01432     ///       image that is probably not as intended.
01433     ///
01434     /// @note This command only operates on the RA8875 internal fonts.
01435     ///
01436     /// @code
01437     ///     lcd.cls();
01438     ///     lcd.SetOrientation(RA8875::normal);
01439     ///     lcd.puts(30,30, "Normal Landscape");
01440     ///     wait_ms(2500);
01441     ///     
01442     ///     lcd.cls();
01443     ///     lcd.SetOrientation(RA8875::rotate_90);
01444     ///     lcd.puts(30,30, "Rotated 90 Text\r\n");
01445     ///     wait_ms(2500);
01446     ///     
01447     ///     lcd.cls();
01448     ///     lcd.SetOrientation(RA8875::rotate_180);
01449     ///     lcd.puts(30,30, "Rotated 180 Text\r\n");
01450     ///     wait_ms(2500);
01451     /// 
01452     ///     lcd.cls();
01453     ///     lcd.SetOrientation(RA8875::rotate_270);
01454     ///     lcd.puts(30,30, "Rotated 270 Text\r\n");
01455     ///     wait_ms(2500);
01456     /// @endcode
01457     ///
01458     /// @param[in] angle defaults to normal, but can be rotated
01459     ///         - normal | rotate_0
01460     ///         - rotate_90 (clockwise)
01461     ///         - rotate_180
01462     ///         - rotate_270 (clockwise)
01463     /// @returns success/failure code. See @ref RetCode_t.
01464     ///
01465     RetCode_t SetOrientation(orientation_t angle = normal);
01466     
01467 
01468     /// Control the font behavior.
01469     ///
01470     /// This command lets you make several modifications to any text that
01471     /// will be written to the screen.
01472     ///
01473     /// @note This command only operates on the RA8875 internal fonts.
01474     ///
01475     /// Options can be combined:
01476     /// Default:
01477     /// @li Full alignment disabled, 
01478     /// @li Font with Background color, 
01479     /// @li Font in normal orientiation, or rotated 90, 180, or 270 clockwise,
01480     /// @li Horizontal scale x 1, 2, 3, or 4
01481     /// @li Vertical scale x 1, 2, 3, or 4
01482     ///
01483     /// @note alignment is a special mode for the fonts, when mixing half and
01484     ///     full fonts on one presentation. 'align_full' starts each full
01485     ///     character on an even alignment. See section 7-4-7 of the RA8875
01486     ///     specification.
01487     /// 
01488     /// @param[in] fillit defaults to FILL, but can be NOFILL
01489     /// @param[in] hScale defaults to 1, but can be 1, 2, 3, or 4,
01490     ///     and scales the font size by this amount.
01491     /// @param[in] vScale defaults to 1, but can be 1, 2, 3, or 4,
01492     ///     and scales the font size by this amount.
01493     /// @param[in] alignment defaults to align_none, but can be
01494     ///     align_full.
01495     /// 
01496     /// @note if either hScale or vScale is outside of its permitted range,
01497     ///     the command is not executed.
01498     /// @returns success/failure code. See @ref RetCode_t.
01499     ///
01500     RetCode_t SetTextFontControl(fill_t fillit = FILL, 
01501         HorizontalScale hScale = 1, 
01502         VerticalScale vScale = 1, 
01503         alignment_t alignment = align_none);
01504     
01505 
01506     /// Control the font size of the RA8875 internal fonts.
01507     ///
01508     /// This command lets you set the font enlargement for both horizontal
01509     /// and vertical, independent of the rotation, background, and 
01510     /// alignment. See @ref SetTextFontControl.
01511     ///
01512     /// @note This command only operates on the RA8875 internal fonts.
01513     ///
01514     /// @param[in] hScale defaults to 1, but can be 1, 2, 3, or 4,
01515     ///     and scales the font size by this amount.
01516     /// @param[in] vScale is an optional parameter that defaults to the hScale value, 
01517     ///     but can be 1, 2, 3, or 4, and scales the font size by this amount.
01518     ///
01519     /// @code
01520     ///     lcd.SetTextFontSize(2);     // Set the font to 2x normal size
01521     ///     lcd.puts("Two times");
01522     ///     lcd.SetTextFontSize(2,3);   // Set the font to 2x Width and 3x Height
01523     ///     lcd.puts("2*2 3*h");
01524     ///     lcd.SetTextFontSize();      // Restore to normal size in both dimensions
01525     ///     lcd.puts("normal");
01526     /// @endcode
01527     ///
01528     /// @note if either hScale or vScale is outside of its permitted range,
01529     ///     the command is not executed.
01530     /// @returns success/failure code. See @ref RetCode_t.
01531     ///
01532     RetCode_t SetTextFontSize(HorizontalScale hScale = 1, VerticalScale vScale = -1);
01533 
01534 
01535     /// Get the text font size of the RA8875 internal fonts.
01536     ///
01537     /// This command lets you retrieve the current settings for the font
01538     /// horizontal and vertical scale factors. The return value is 
01539     /// one of the scale factors 1, 2, 3, or 4.
01540     ///
01541     /// @param[out] hScale is a pointer to memory where the horizontal scale factor
01542     ///     will be written. If the pointer is null, that item will be ignored.
01543     /// @param[out] vScale is a pointer to memory where the vertical scale factor
01544     ///     will be written. If the pointer is null, that item will be ignored.
01545     /// @returns success/failure code. See @ref RetCode_t.
01546     ///
01547     RetCode_t GetTextFontSize(HorizontalScale * hScale, VerticalScale * vScale);
01548 
01549     /// put a character on the screen.
01550     ///
01551     /// @param[in] c is the character.
01552     /// @returns the character, or EOF if there is an error.
01553     ///
01554     virtual int _putc(int c);
01555 
01556 
01557     /// Write string of text to the display
01558     ///
01559     /// @code
01560     ///     lcd.puts("Test STring");
01561     /// @endcode
01562     ///
01563     /// @param[in] string is the null terminated string to send to the display.
01564     ///
01565     void puts(const char * string);
01566 
01567     
01568     /// Write string of text to the display at the specified location.
01569     ///
01570     /// @code
01571     ///     lcd.puts(10,25, "Test STring");
01572     /// @endcode
01573     ///
01574     /// @param[in] x is the horizontal position in pixels (from the left edge)
01575     /// @param[in] y is the vertical position in pixels (from the top edge)
01576     /// @param[in] string is the null terminated string to send to the display.
01577     ///
01578     void puts(loc_t x, loc_t y, const char * string);
01579     
01580 
01581     /// Prepare the controller to write binary data to the screen by positioning
01582     /// the memory cursor.
01583     ///
01584     /// @param[in] x is the horizontal position in pixels (from the left edge)
01585     /// @param[in] y is the vertical position in pixels (from the top edge)
01586     /// @returns success/failure code. See @ref RetCode_t.
01587     ///
01588     virtual RetCode_t SetGraphicsCursor(loc_t x, loc_t y);
01589 
01590     /// Prepare the controller to write binary data to the screen by positioning
01591     /// the memory cursor.
01592     ///
01593     /// @param[in] p is the point representing the cursor position to set
01594     /// @returns success/failure code. See @ref RetCode_t.
01595     ///
01596     virtual RetCode_t SetGraphicsCursor(point_t p);
01597     
01598     /// Read the current graphics cursor position as a point.
01599     ///
01600     /// @returns the graphics cursor as a point.
01601     ///
01602     virtual point_t GetGraphicsCursor(void);
01603 
01604     
01605     /// Prepare the controller to read binary data from the screen by positioning
01606     /// the memory read cursor.
01607     ///
01608     /// @param[in] x is the horizontal position in pixels (from the left edge)
01609     /// @param[in] y is the vertical position in pixels (from the top edge)
01610     /// @returns success/failure code. See @ref RetCode_t.
01611     ///
01612     virtual RetCode_t SetGraphicsCursorRead(loc_t x, loc_t y);
01613     
01614 
01615     /// Set the window, constraining where items are written to the screen.
01616     ///
01617     /// After setting the window, text and graphics are constrained to this
01618     /// window. Text will wrap from the right edge back to the left and down
01619     /// one row and from the bottom to the top. Graphics drawing will be clipped
01620     /// at the edge of the window.
01621     ///
01622     /// @note If the initial text write is outside the window, it will be shown
01623     /// where the cursor position it. Once the write hits the right edge of
01624     /// the defined window, it will then wrap back to the left edge. Once it
01625     /// hits the bottom, it wraps to the top of the window. For this reason,
01626     /// it is common to set the text cursor to the window.
01627     ///
01628     /// @code
01629     ///     rect_t r = {10,10, 90,90};
01630     ///     lcd.window(r);
01631     ///     lcd.SetTextCursor(r.p1.x, r.p1.y);
01632     ///     lcd.puts("012345678901234567890123456789012345678901234567890");
01633     ///     lcd.window(); restore to full screen
01634     /// @endcode
01635     ///
01636     /// @param[in] r is the rect_t used to set the window.
01637     /// @returns success/failure code. See @ref RetCode_t.
01638     ///
01639     virtual RetCode_t window(rect_t r);
01640     
01641 
01642     /// Set the window, constraining where items are written to the screen.
01643     ///
01644     /// After setting the window, text and graphics are constrained to this
01645     /// window. Text will wrap from the right edge back to the left and down
01646     /// one row and from the bottom to the top. Graphics drawing will be clipped
01647     /// at the edge of the window.
01648     ///
01649     /// @note if no parameters are provided, it restores the window to full screen.
01650     ///
01651     /// @note If the initial text write is outside the window, it will be shown
01652     /// where the cursor position it. Once the write hits the right edge of
01653     /// the defined window, it will then wrap back to the left edge. Once it
01654     /// hits the bottom, it wraps to the top of the window. For this reason,
01655     /// it is common to set the text cursor to the window.
01656     ///
01657     /// @code
01658     ///     lcd.window(10,10, 80,80);
01659     ///     lcd.SetTextCursor(10,10);
01660     ///     lcd.puts("012345678901234567890123456789012345678901234567890");
01661     ///     lcd.window(); restore to full screen
01662     /// @endcode
01663     ///
01664     /// @param[in] x is the left edge in pixels.
01665     /// @param[in] y is the top edge in pixels.
01666     /// @param[in] width is the window width in pixels.
01667     /// @param[in] height is the window height in pixels.
01668     /// @returns success/failure code. See @ref RetCode_t.
01669     ///
01670     virtual RetCode_t window(loc_t x = 0, loc_t y = 0, dim_t width = (dim_t)-1, dim_t height = (dim_t)-1);
01671     
01672 
01673     /// Clear either the specified layer, or the active layer.
01674     ///
01675     /// The behavior is to clear the whole screen for the specified
01676     /// layer. When not specified, the active drawing layer is cleared.
01677     /// This command can also be used to specifically clear either,
01678     /// or both layers. See @ref clsw().
01679     ///
01680     /// @code
01681     ///     lcd.cls();
01682     /// @endcode
01683     ///
01684     /// @param[in] layers is optional. If not provided, the active layer
01685     ///     is cleared. If bit 0 is set, layer 0 is cleared, if bit
01686     ///     1 is set, layer 1 is cleared. If both are set, both layers
01687     ///     are cleared. Any other value does not cause an action.
01688     ///     
01689     /// @returns success/failure code. See @ref RetCode_t.
01690     ///
01691     virtual RetCode_t cls(uint16_t layers = 0);
01692 
01693     
01694     /// Clear the screen, or clear only the active window.
01695     ///
01696     /// The default behavior is to clear the whole screen. With the optional 
01697     /// parameter, the action can be restricted to the active window, which
01698     /// can be set with the See @ref window method.
01699     ///
01700     /// @code
01701     ///     lcd.window(20,20, 40,10);
01702     ///     lcd.clsw();
01703     /// @endcode
01704     ///
01705     /// @param[in] region is an optional parameter that defaults to FULLWINDOW
01706     ///         or may be set to ACTIVEWINDOW.
01707     /// @returns success/failure code. See @ref RetCode_t.
01708     ///
01709     RetCode_t clsw(RA8875::Region_t region = FULLWINDOW);
01710 
01711 
01712     /// Set the background color.
01713     ///
01714     /// @param[in] color is expressed in 16-bit format.
01715     /// @returns success/failure code. See @ref RetCode_t.
01716     ///
01717     virtual RetCode_t background(color_t color);
01718 
01719     
01720     /// Set the background color.
01721     ///
01722     /// @param[in] r is the red element of the color.
01723     /// @param[in] g is the green element of the color.
01724     /// @param[in] b is the blue element of the color.
01725     /// @returns success/failure code. See @ref RetCode_t.
01726     ///
01727     virtual RetCode_t background(unsigned char r, unsigned char g, unsigned char b);
01728     
01729 
01730     /// Set the foreground color.
01731     ///
01732     /// @param[in] color is expressed in 16-bit format.
01733     /// @returns success/failure code. See @ref RetCode_t.
01734     ///
01735     virtual RetCode_t foreground(color_t color);
01736     
01737 
01738     /// Set the foreground color.
01739     ///
01740     /// @param[in] r is the red element of the color.
01741     /// @param[in] g is the green element of the color.
01742     /// @param[in] b is the blue element of the color.
01743     /// @returns success/failure code. See @ref RetCode_t.
01744     ///
01745     virtual RetCode_t foreground(unsigned char r, unsigned char g, unsigned char b);
01746     
01747     
01748     /// Get the current foreground color value.
01749     ///
01750     /// @returns the current foreground color.
01751     ///
01752     color_t GetForeColor(void);
01753     
01754     
01755     /// Draw a pixel in the specified color.
01756     ///
01757     /// @note Unlike many other operations, this does not
01758     ///         set the forecolor!
01759     ///
01760     /// @param[in] p is the point_t defining the location.
01761     /// @returns success/failure code. See @ref RetCode_t.
01762     ///
01763     virtual RetCode_t pixel(point_t p, color_t color);
01764     
01765     
01766     /// Draw a pixel in the current foreground color.
01767     ///
01768     /// @param[in] p is the point_t defining the location.
01769     /// @returns success/failure code. See @ref RetCode_t.
01770     ///
01771     virtual RetCode_t pixel(point_t p);
01772     
01773         
01774     /// Draw a pixel in the specified color.
01775     ///
01776     /// @note Unlike many other operations, this does not
01777     ///         set the forecolor!
01778     ///
01779     /// @param[in] x is the horizontal offset to this pixel.
01780     /// @param[in] y is the vertical offset to this pixel.
01781     /// @param[in] color defines the color for the pixel.
01782     /// @returns success/failure code. See @ref RetCode_t.
01783     ///
01784     virtual RetCode_t pixel(loc_t x, loc_t y, color_t color);
01785     
01786     
01787     /// Draw a pixel in the current foreground color.
01788     ///
01789     /// @param[in] x is the horizontal offset to this pixel.
01790     /// @param[in] y is the veritical offset to this pixel.
01791     /// @returns success/failure code. See @ref RetCode_t.
01792     ///
01793     virtual RetCode_t pixel(loc_t x, loc_t y);
01794     
01795     
01796     /// Get a pixel from the display.
01797     ///
01798     /// @param[in] x is the horizontal offset to this pixel.
01799     /// @param[in] y is the vertical offset to this pixel.
01800     /// @returns the pixel. see @color_t
01801     ///
01802     virtual color_t getPixel(loc_t x, loc_t y);
01803     
01804     
01805     /// Write an RGB565 stream of pixels to the display.
01806     ///
01807     /// @param[in] p is a pointer to a color_t array to write.
01808     /// @param[in] count is the number of pixels to write.
01809     /// @param[in] x is the horizontal position on the display.
01810     /// @param[in] y is the vertical position on the display.
01811     /// @returns success/failure code. See @ref RetCode_t.
01812     ///
01813     virtual RetCode_t pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y);
01814     
01815     
01816     /// Get a stream of pixels from the display.
01817     ///
01818     /// @param[in] p is a pointer to a color_t array to accept the stream.
01819     /// @param[in] count is the number of pixels to read.
01820     /// @param[in] x is the horizontal offset to this pixel.
01821     /// @param[in] y is the vertical offset to this pixel.
01822     /// @returns success/failure code. See @ref RetCode_t.
01823     ///
01824     virtual RetCode_t getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y);
01825 
01826 
01827     /// Write a boolean stream to the display.
01828     ///
01829     /// This takes a bit stream in memory and using the current color settings
01830     /// it will stream it to the display. Along the way, each bit is translated
01831     /// to either the foreground or background color value and then that pixel
01832     /// is pushed onward.
01833     ///
01834     /// This is similar, but different, to the @ref pixelStream API, which is 
01835     /// given a stream of color values.
01836     /// 
01837     /// @param[in] x is the horizontal position on the display.
01838     /// @param[in] y is the vertical position on the display.
01839     /// @param[in] w is the width of the rectangular region to fill.
01840     /// @param[in] h is the height of the rectangular region to fill.
01841     /// @param[in] boolStream is the inline memory image from which to extract
01842     ///         the bitstream.
01843     /// @returns success/failure code. See @ref RetCode_t.
01844     ///
01845     virtual RetCode_t booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream);
01846 
01847     
01848     /// Draw a line in the specified color
01849     ///
01850     /// @note As a side effect, this changes the current
01851     ///     foreground color for subsequent operations.
01852     ///
01853     /// @param[in] p1 is the point to start the line.
01854     /// @param[in] p2 is the point to end the line.
01855     /// @param[in] color defines the foreground color.
01856     /// @returns success/failure code. See @ref RetCode_t.
01857     ///
01858     RetCode_t line(point_t p1, point_t p2, color_t color);
01859 
01860 
01861     /// Draw a line
01862     ///
01863     /// Draws a line using the foreground color setting.
01864     ///
01865     /// @param[in] p1 is the point to start the line.
01866     /// @param[in] p2 is the point to end the line.
01867     /// @returns success/failure code. See @ref RetCode_t.
01868     ///
01869     RetCode_t line(point_t p1, point_t p2);
01870 
01871     
01872     /// Draw a line in the specified color
01873     ///
01874     /// @note As a side effect, this changes the current
01875     ///     foreground color for subsequent operations.
01876     ///
01877     /// @param[in] x1 is the horizontal start of the line.
01878     /// @param[in] y1 is the vertical start of the line.
01879     /// @param[in] x2 is the horizontal end of the line.
01880     /// @param[in] y2 is the vertical end of the line.
01881     /// @param[in] color defines the foreground color.
01882     /// @returns success/failure code. See @ref RetCode_t.
01883     ///
01884     RetCode_t line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color);
01885 
01886 
01887     /// Draw a line
01888     ///
01889     /// Draws a line using the foreground color setting.
01890     ///
01891     /// @param[in] x1 is the horizontal start of the line.
01892     /// @param[in] y1 is the vertical start of the line.
01893     /// @param[in] x2 is the horizontal end of the line.
01894     /// @param[in] y2 is the vertical end of the line.
01895     /// @returns success/failure code. See @ref RetCode_t.
01896     ///
01897     RetCode_t line(loc_t x1, loc_t y1, loc_t x2, loc_t y2);
01898 
01899 
01900     /// Draw a thick line
01901     ///
01902     /// Draw a line of a specified thickness and color.
01903     ///
01904     /// In order to draw a thick line, this draws filled circles using 
01905     /// bresenham's algorithm to move the center point of the circle.
01906     /// As a result, this is much slower than drawing a 1-pixel line which
01907     /// uses the hardware line drawing algorithm.
01908     ///
01909     /// Drawing multiple parallel lines to create a thick line is faster,
01910     /// however the line drawing was not guaranteed to fill every pixel
01911     /// on the diagonals.
01912     ///
01913     /// @param[in] p1 is the point to start the line.
01914     /// @param[in] p2 is the point to end the line.
01915     /// @param[in] thickness is the line thickness.
01916     /// @param[in] color defines the foreground color.
01917     /// @returns success/failure code. See @ref RetCode_t.
01918     /// 
01919     RetCode_t ThickLine(point_t p1, point_t p2, dim_t thickness, color_t color);
01920 
01921 
01922     /// Draw a rectangle in the specified color
01923     ///
01924     /// @note As a side effect, this changes the current
01925     ///     foreground color for subsequent operations.
01926     ///
01927     /// @param[in] rect defines the rectangle.
01928     /// @param[in] color defines the foreground color.
01929     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01930     /// @returns success/failure code. See @ref RetCode_t.
01931     ///
01932     RetCode_t rect(rect_t rect, color_t color, fill_t fillit = NOFILL);
01933     
01934 
01935     /// Draw a filled rectangle in the specified color
01936     ///
01937     /// @note As a side effect, this changes the current
01938     ///     foreground color for subsequent operations.
01939     ///
01940     /// @param[in] rect defines the rectangle.
01941     /// @param[in] color defines the foreground color.
01942     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01943     /// @returns success/failure code. See @ref RetCode_t.
01944     ///
01945     RetCode_t fillrect(rect_t rect, color_t color, fill_t fillit = FILL);
01946 
01947 
01948     /// Draw a rectangle in the specified color
01949     ///
01950     /// @note As a side effect, this changes the current
01951     ///     foreground color for subsequent operations.
01952     ///
01953     /// @param[in] x1 is the horizontal start of the line.
01954     /// @param[in] y1 is the vertical start of the line.
01955     /// @param[in] x2 is the horizontal end of the line.
01956     /// @param[in] y2 is the vertical end of the line.
01957     /// @param[in] color defines the foreground color.
01958     /// @param[in] fillit is optional to FILL the rectangle. default is FILL.
01959     /// @returns success/failure code. See @ref RetCode_t.
01960     ///
01961     RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01962         color_t color, fill_t fillit = NOFILL);
01963 
01964 
01965     /// Draw a filled rectangle in the specified color
01966     ///
01967     /// @note As a side effect, this changes the current
01968     ///     foreground color for subsequent operations.
01969     ///
01970     /// @param[in] x1 is the horizontal start of the line.
01971     /// @param[in] y1 is the vertical start of the line.
01972     /// @param[in] x2 is the horizontal end of the line.
01973     /// @param[in] y2 is the vertical end of the line.
01974     /// @param[in] color defines the foreground color.
01975     /// @param[in] fillit is optional to NOFILL the rectangle. default is FILL.
01976     /// @returns success/failure code. See @ref RetCode_t.
01977     ///
01978     virtual RetCode_t fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01979         color_t color, fill_t fillit = FILL);
01980 
01981 
01982     /// Draw a rectangle
01983     ///
01984     /// Draws a rectangle using the foreground color setting.
01985     ///
01986     /// @param[in] x1 is the horizontal start of the line.
01987     /// @param[in] y1 is the vertical start of the line.
01988     /// @param[in] x2 is the horizontal end of the line.
01989     /// @param[in] y2 is the vertical end of the line.
01990     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01991     /// @returns success/failure code. See @ref RetCode_t.
01992     ///
01993     RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01994         fill_t fillit = NOFILL);
01995 
01996 
01997     /// Draw a filled rectangle with rounded corners using the specified color.
01998     ///
01999     /// This draws a rounded rectangle. A numbers of checks are made on the values,
02000     /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2),
02001     /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are
02002     /// > 1/2 the length of that side (width or height), an error value is returned.
02003     ///
02004     /// @note As a side effect, this changes the current
02005     ///     foreground color for subsequent operations.
02006     ///
02007     /// @param[in] x1 is the horizontal start of the line and must be <= x2.
02008     /// @param[in] y1 is the vertical start of the line and must be <= y2.
02009     /// @param[in] x2 is the horizontal end of the line and must be >= x1.
02010     /// @param[in] y2 is the vertical end of the line and must be >= y1.
02011     /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care
02012     ///         that this value < 1/2 the width of the rectangle, or bad_parameter 
02013     ///         is returned.
02014     /// @param[in] radius2 defines the vertical radius of the curved corner. Take care
02015     ///         that this value < 1/2 the height of the rectangle, or bad_parameter 
02016     ///         is returned.
02017     /// @param[in] color defines the foreground color.
02018     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
02019     /// @returns success/failure code. See @ref RetCode_t.
02020     ///
02021     RetCode_t fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
02022         dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL);
02023 
02024 
02025     /// Draw a filled rectangle with rounded corners using the specified color.
02026     ///
02027     /// This draws a rounded rectangle. A numbers of checks are made on the values,
02028     /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2),
02029     /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are
02030     /// > 1/2 the length of that side (width or height), an error value is returned.
02031     ///
02032     /// @note As a side effect, this changes the current
02033     ///     foreground color for subsequent operations.
02034     ///
02035     /// @param[in] r is the rectangle to draw.
02036     /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care
02037     ///         that this value < 1/2 the width of the rectangle, or bad_parameter 
02038     ///         is returned.
02039     /// @param[in] radius2 defines the vertical radius of the curved corner. Take care
02040     ///         that this value < 1/2 the height of the rectangle, or bad_parameter 
02041     ///         is returned.
02042     /// @param[in] color defines the foreground color.
02043     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
02044     /// @returns success/failure code. See @ref RetCode_t.
02045     ///
02046     RetCode_t fillroundrect(rect_t r, 
02047         dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL);
02048 
02049 
02050     /// Draw a rectangle with rounded corners using the specified color.
02051     ///
02052     /// This draws a rounded rectangle. A numbers of checks are made on the values,
02053     /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2),
02054     /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are
02055     /// > 1/2 the length of that side (width or height), an error value is returned.
02056     ///
02057     /// @note As a side effect, this changes the current
02058     ///     foreground color for subsequent operations.
02059     ///
02060     /// @param[in] r is the rectangle to draw.
02061     /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care
02062     ///         that this value < 1/2 the width of the rectangle, or bad_parameter 
02063     ///         is returned.
02064     /// @param[in] radius2 defines the vertical radius of the curved corner. Take care
02065     ///         that this value < 1/2 the height of the rectangle, or bad_parameter 
02066     ///         is returned.
02067     /// @param[in] color defines the foreground color.
02068     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
02069     /// @returns success/failure code. See @ref RetCode_t.
02070     ///
02071     RetCode_t roundrect(rect_t r, 
02072         dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL);
02073 
02074 
02075     /// Draw a rectangle with rounded corners using the specified color.
02076     ///
02077     /// This draws a rounded rectangle. A numbers of checks are made on the values,
02078     /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2),
02079     /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are
02080     /// > 1/2 the length of that side (width or height), an error value is returned.
02081     ///
02082     /// @note As a side effect, this changes the current
02083     ///     foreground color for subsequent operations.
02084     ///
02085     /// @param[in] x1 is the horizontal start of the line and must be <= x2.
02086     /// @param[in] y1 is the vertical start of the line and must be <= y2.
02087     /// @param[in] x2 is the horizontal end of the line and must be >= x1.
02088     /// @param[in] y2 is the vertical end of the line and must be >= y1.
02089     /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care
02090     ///         that this value < 1/2 the width of the rectangle, or bad_parameter 
02091     ///         is returned.
02092     /// @param[in] radius2 defines the vertical radius of the curved corner. Take care
02093     ///         that this value < 1/2 the height of the rectangle, or bad_parameter 
02094     ///         is returned.
02095     /// @param[in] color defines the foreground color.
02096     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
02097     /// @returns success/failure code. See @ref RetCode_t.
02098     ///
02099     RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
02100         dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL);
02101 
02102 
02103     /// Draw a rectangle with rounded corners.
02104     ///
02105     /// This draws a rounded rectangle. A numbers of checks are made on the values,
02106     /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2),
02107     /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are
02108     /// > 1/2 the length of that side (width or height), an error value is returned.
02109     ///
02110     /// @param[in] x1 is the horizontal start of the line and must be <= x2.
02111     /// @param[in] y1 is the vertical start of the line and must be <= y2.
02112     /// @param[in] x2 is the horizontal end of the line and must be >= x1.
02113     /// @param[in] y2 is the vertical end of the line and must be >= y1.
02114     /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care
02115     ///         that this value < 1/2 the width of the rectangle, or bad_parameter 
02116     ///         is returned.
02117     /// @param[in] radius2 defines the vertical radius of the curved corner. Take care
02118     ///         that this value < 1/2 the height of the rectangle, or bad_parameter 
02119     ///         is returned.
02120     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
02121     /// @returns success/failure code. See @ref RetCode_t.
02122     ///
02123     RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
02124         dim_t radius1, dim_t radius2, fill_t fillit = NOFILL);
02125 
02126 
02127     /// Draw a triangle in the specified color.
02128     ///
02129     /// @note As a side effect, this changes the current
02130     ///     foreground color for subsequent operations.
02131     ///
02132     /// @param[in] x1 is the horizontal for point 1.
02133     /// @param[in] y1 is the vertical for point 1. 
02134     /// @param[in] x2 is the horizontal for point 2.
02135     /// @param[in] y2 is the vertical for point 2.
02136     /// @param[in] x3 is the horizontal for point 3.
02137     /// @param[in] y3 is the vertical for point 3.
02138     /// @param[in] color defines the foreground color.
02139     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
02140     /// @returns success/failure code. See @ref RetCode_t.
02141     ///
02142     RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
02143         loc_t x3, loc_t y3, color_t color, fill_t fillit = NOFILL);
02144     
02145 
02146     /// Draw a filled triangle in the specified color.
02147     ///
02148     /// @note As a side effect, this changes the current
02149     ///     foreground color for subsequent operations.
02150     ///
02151     /// @param[in] x1 is the horizontal for point 1.
02152     /// @param[in] y1 is the vertical for point 1.
02153     /// @param[in] x2 is the horizontal for point 2.
02154     /// @param[in] y2 is the vertical for point 2.
02155     /// @param[in] x3 is the horizontal for point 3.
02156     /// @param[in] y3 is the vertical for point 3.
02157     /// @param[in] color defines the foreground color.
02158     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
02159     /// @returns success/failure code. See @ref RetCode_t.
02160     ///
02161     RetCode_t filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
02162         loc_t x3, loc_t y3, color_t color, fill_t fillit = FILL);
02163 
02164 
02165     /// Draw a triangle
02166     ///
02167     /// Draws a triangle using the foreground color setting.
02168     ///
02169     /// @param[in] x1 is the horizontal for point 1.
02170     /// @param[in] y1 is the vertical for point 1.
02171     /// @param[in] x2 is the horizontal for point 2.
02172     /// @param[in] y2 is the vertical for point 2.
02173     /// @param[in] x3 is the horizontal for point 3.
02174     /// @param[in] y3 is the vertical for point 3.
02175     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
02176     /// @returns success/failure code. See @ref RetCode_t.
02177     ///
02178     RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
02179         loc_t x3, loc_t y3, fill_t fillit = NOFILL);
02180     
02181 
02182     /// Draw a circle using the specified color.
02183     ///
02184     /// @note As a side effect, this changes the current
02185     ///     foreground color for subsequent operations.
02186     ///
02187     /// @param[in] p defines the center of the circle.
02188     /// @param[in] radius defines the size of the circle.
02189     /// @param[in] color defines the foreground color.
02190     /// @param[in] fillit is optional to FILL the circle. default is NOFILL.
02191     /// @returns success/failure code. See @ref RetCode_t.
02192     ///
02193     RetCode_t circle(point_t p, dim_t radius, color_t color, fill_t fillit = NOFILL);
02194 
02195 
02196     /// Draw a filled circle using the specified color.
02197     ///
02198     /// @note As a side effect, this changes the current
02199     ///     foreground color for subsequent operations.
02200     ///
02201     /// @param[in] p defines the center of the circle.
02202     /// @param[in] radius defines the size of the circle.
02203     /// @param[in] color defines the foreground color.
02204     /// @param[in] fillit is optional to FILL the circle. default is FILL.
02205     /// @returns success/failure code. See @ref RetCode_t.
02206     ///
02207     RetCode_t fillcircle(point_t p, dim_t radius, color_t color, fill_t fillit = FILL);
02208 
02209 
02210     /// Draw a circle.
02211     ///
02212     /// Draws a circle using the foreground color setting.
02213     ///
02214     /// @param[in] p defines the center of the circle.
02215     /// @param[in] radius defines the size of the circle.
02216     /// @param[in] fillit is optional to FILL the circle. default is NOFILL.
02217     /// @returns success/failure code. See @ref RetCode_t.
02218     ///
02219     RetCode_t circle(point_t p, dim_t radius, fill_t fillit = NOFILL);
02220 
02221 
02222     /// Draw a circle using the specified color.
02223     ///
02224     /// @note As a side effect, this changes the current
02225     ///     foreground color for subsequent operations.
02226     ///
02227     /// @param[in] x is the horizontal center of the circle.
02228     /// @param[in] y is the vertical center of the circle.
02229     /// @param[in] radius defines the size of the circle.
02230     /// @param[in] color defines the foreground color.
02231     /// @param[in] fillit is optional to FILL the circle. default is NOFILL.
02232     /// @returns success/failure code. See @ref RetCode_t.
02233     ///
02234     RetCode_t circle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit = NOFILL);
02235 
02236 
02237     /// Draw a filled circle using the specified color.
02238     ///
02239     /// @note As a side effect, this changes the current
02240     ///     foreground color for subsequent operations.
02241     ///
02242     /// @param[in] x is the horizontal center of the circle.
02243     /// @param[in] y is the vertical center of the circle.
02244     /// @param[in] radius defines the size of the circle.
02245     /// @param[in] color defines the foreground color.
02246     /// @param[in] fillit is optional to FILL the circle. default is FILL.
02247     /// @returns success/failure code. See @ref RetCode_t.
02248     ///
02249     RetCode_t fillcircle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit = FILL);
02250 
02251 
02252     /// Draw a circle.
02253     ///
02254     /// Draws a circle using the foreground color setting.
02255     ///
02256     /// @param[in] x is the horizontal center of the circle.
02257     /// @param[in] y is the vertical center of the circle.
02258     /// @param[in] radius defines the size of the circle.
02259     /// @param[in] fillit is optional to FILL the circle. default is NOFILL.
02260     /// @returns success/failure code. See @ref RetCode_t.
02261     ///
02262     RetCode_t circle(loc_t x, loc_t y, dim_t radius, fill_t fillit = NOFILL);
02263 
02264     /// Draw an Ellipse using the specified color
02265     ///
02266     /// @note As a side effect, this changes the current
02267     ///     foreground color for subsequent operations.
02268     ///
02269     /// @param[in] x is the horizontal center of the ellipse.
02270     /// @param[in] y is the vertical center of the ellipse.
02271     /// @param[in] radius1 defines the horizontal radius of the ellipse.
02272     /// @param[in] radius2 defines the vertical radius of the ellipse.
02273     /// @param[in] color defines the foreground color.
02274     /// @param[in] fillit defines whether the circle is filled or not.
02275     /// @returns success/failure code. See @ref RetCode_t.
02276     ///
02277     RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, 
02278         color_t color, fill_t fillit = NOFILL);
02279 
02280 
02281     /// Draw a filled Ellipse using the specified color
02282     ///
02283     /// @note As a side effect, this changes the current
02284     ///     foreground color for subsequent operations.
02285     ///
02286     /// @param[in] x is the horizontal center of the ellipse.
02287     /// @param[in] y is the vertical center of the ellipse.
02288     /// @param[in] radius1 defines the horizontal radius of the ellipse.
02289     /// @param[in] radius2 defines the vertical radius of the ellipse.
02290     /// @param[in] color defines the foreground color.
02291     /// @param[in] fillit defines whether the circle is filled or not.
02292     /// @returns success/failure code. See @ref RetCode_t.
02293     ///
02294     RetCode_t fillellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, 
02295         color_t color, fill_t fillit = FILL);
02296 
02297 
02298     /// Draw an Ellipse
02299     ///
02300     /// Draws it using the foreground color setting.
02301     ///
02302     /// @param[in] x is the horizontal center of the ellipse.
02303     /// @param[in] y is the vertical center of the ellipse.
02304     /// @param[in] radius1 defines the horizontal radius of the ellipse.
02305     /// @param[in] radius2 defines the vertical radius of the ellipse.
02306     /// @param[in] fillit defines whether the circle is filled or not.
02307     /// @returns success/failure code. See @ref RetCode_t.
02308     ///
02309     RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit = NOFILL);
02310     
02311 
02312 
02313     /// Block Move
02314     ///
02315     /// The Block Move API activates the RA8875 Block Transfer Engine. Due to the complex
02316     /// set of possible operations, the user should read the related sections of the
02317     /// RA8875 user manual.
02318     ///
02319     /// Some operations may require that other registers are configured, such as the
02320     /// foreground and background color registers, and others. Those must be set
02321     /// outside of this API.
02322     ///
02323     /// @code
02324     /// int main()
02325     /// {
02326     ///     point_t src;
02327     ///     point_t dst;
02328     ///     TouchCode_t touch;
02329     ///     const dim_t RECT_W = 100;
02330     ///     const dim_t RECT_H = 100;
02331     ///     
02332     ///     pc.baud(460800);    //I like a snappy terminal, so crank it up!
02333     ///     pc.printf("\r\nRA8875 BTE Move Test - Build " __DATE__ " " __TIME__ "\r\n");
02334     ///     lcd.init(LCD_W,LCD_H,LCD_C, BL_NORM);
02335     ///     lcd.TouchPanelInit();
02336     ///     #ifndef CAP_TOUCH
02337     ///     InitTS();   // Calibration for resistive touch panel
02338     ///     #endif
02339     ///     
02340     ///     RetCode_t r = lcd.RenderImageFile(0,0,"/local/fullscrn.jpg");
02341     ///     if (r) pc.printf("  Error: %d; %s\r\n", r, lcd.GetErrorMessage(r));
02342     ///     while (1) {
02343     ///         touch = lcd.TouchPanelReadable();
02344     ///         if (touch) {
02345     ///             point_t xy = lcd.TouchCoordinates();
02346     ///             TouchCode_t t = lcd.TouchCode();
02347     /// 
02348     ///             if (t == touch) {
02349     ///                 src = ComputeTopLeftOfRect(xy, RECT_W/2, RECT_H/2, LCD_W, LCD_H);
02350     ///             } else if (t == release) {
02351     ///                 dst = ComputeTopLeftOfRect(xy, RECT_W/2, RECT_H/2, LCD_W, LCD_H);
02352     ///                 r = lcd.BlockMove(0,0,dst, 0,0,src, RECT_W,RECT_H, 0x2, 0xC);
02353     ///             }
02354     ///         }
02355     ///     }
02356     /// }
02357     /// @endcode
02358     ///
02359     /// @param[in] dstLayer layer [5B.7]. layer value is 0 or 1 representing layer 1 and 2.
02360     /// @param[in] dstDataSelect [50.5] defines the destination data type 0: block, 1: linear.
02361     /// @param[in] dstPoint [58-5B] is a point_t defining the destination coordinate.
02362     /// @param[in] srcLayer layer [57.7]. layer value is 0 or 1 representing layer 1 and 2.
02363     /// @param[in] srcDataSelect [50.6] defines the source data type 0: block, 1: linear.
02364     /// @param[in] srcPoint [54-57] is a point_t defining the source coordinate.
02365     /// @param[in] bte_width [5C-5D]. operation width.
02366     /// @param[in] bte_height [5E-5F]. operation height.
02367     /// @param[in] bte_op_code [51.3-0] defines the raster operation function 
02368     ///             (write/read/move/...)
02369     /// @param[in] bte_rop_code [51.7-4] defines what type of BTE operation to perform
02370     ///             (what is placed at the destination)
02371     /// @returns success/failure code. See @ref RetCode_t.
02372     ///
02373     RetCode_t BlockMove(uint8_t dstLayer, uint8_t dstDataSelect, point_t dstPoint,
02374         uint8_t srcLayer, uint8_t srcDataSelect, point_t srcPoint,
02375         dim_t bte_width, dim_t bte_height,
02376         uint8_t bte_op_code, uint8_t bte_rop_code);
02377 
02378 
02379     /// Control display power
02380     ///
02381     /// @param[in] on when set to true will turn on the display, when false it is turned off.
02382     /// @returns success/failure code. See @ref RetCode_t.
02383     ///
02384     RetCode_t Power(bool on);
02385 
02386 
02387     /// Reset the display controller via the Software Reset interface.
02388     ///
02389     /// @returns success/failure code. See @ref RetCode_t.
02390     ///
02391     RetCode_t Reset(void);
02392     
02393 
02394     /// Set backlight brightness.
02395     ///
02396     /// When the built-in PWM is used to control the backlight, this 
02397     /// API can be used to set the brightness.
02398     /// 
02399     /// @param[in] brightness ranges from 0 (off) to 255 (full on)
02400     /// @returns success/failure code. See @ref RetCode_t.
02401     ///
02402     RetCode_t Backlight_u8(uint8_t brightness);
02403 
02404     
02405     /// Get backlight brightness.
02406     ///
02407     /// @returns backlight setting from 0 (off) to 255 (full on).
02408     /// 
02409     uint8_t GetBacklight_u8(void);
02410 
02411     /// Set backlight brightness.
02412     ///
02413     /// When the built-in PWM is used to control the backlight, this 
02414     /// API can be used to set the brightness.
02415     /// 
02416     /// @param[in] brightness ranges from 0.0 (off) to 1.0 (full on)
02417     /// @returns success/failure code. See @ref RetCode_t.
02418     ///
02419     RetCode_t Backlight(float brightness);
02420 
02421 
02422     /// Get backlight brightness.
02423     ///
02424     /// @returns backlight setting from 0 (off) to 1.0 (full on).
02425     /// 
02426     float GetBacklight(void);
02427 
02428 
02429     /// Select a User Font for all subsequent text.
02430     ///
02431     /// @note Tool to create the fonts is accessible from its creator
02432     ///     available at http://www.mikroe.com. 
02433     ///     For version 1.2.0.0, choose the "Export for TFT and new GLCD"
02434     ///     format.
02435     ///
02436     /// @param[in] font is a pointer to a specially formed font resource.
02437     /// @returns error code.
02438     ///
02439     virtual RetCode_t SelectUserFont(const uint8_t * font = NULL);
02440 
02441     /// Get the currently selected user font.
02442     ///
02443     /// @returns a pointer to the font, or null, if no user font is selected.
02444     ///
02445     virtual const uint8_t * GetUserFont(void) { return font; }
02446 
02447     /// Get the RGB value for a DOS color.
02448     ///
02449     /// @code
02450     ///     color_t color = DOSColor(12);
02451     /// @endcode
02452     ///
02453     /// @param[in] i is the color, in the range 0 to 15;
02454     /// @returns the RGB color of the selected index, or 0 
02455     ///     if the index is out of bounds.
02456     ///
02457     color_t DOSColor(int i);
02458 
02459 
02460     /// Get the color name (string) for a DOS color.
02461     ///
02462     /// @code
02463     ///     printf("color is %s\n", DOSColorNames(12));
02464     /// @endcode
02465     ///
02466     /// @param[in] i is the color, in the range 0 to 15;
02467     /// @returns a pointer to a string with the color name,
02468     ///     or NULL if the index is out of bounds.
02469     /// 
02470     const char * DOSColorNames(int i);
02471 
02472 
02473     /// Advanced method indicating the start of a graphics stream.
02474     ///
02475     /// This is called prior to a stream of pixel data being sent.
02476     /// This may cause register configuration changes in the derived
02477     /// class in order to prepare the hardware to accept the streaming
02478     /// data.
02479     ///
02480     /// Following this command, a series of See @ref _putp() commands can
02481     /// be used to send individual pixels to the screen.
02482     ///
02483     /// To conclude the graphics stream, See @ref _EndGraphicsStream should
02484     /// be callled.
02485     ///
02486     /// @returns error code.
02487     ///
02488     virtual RetCode_t _StartGraphicsStream(void);
02489 
02490     
02491     /// Advanced method to put a single color pixel to the screen.
02492     ///
02493     /// This method may be called as many times as necessary after 
02494     /// See @ref _StartGraphicsStream() is called, and it should be followed 
02495     /// by _EndGraphicsStream.
02496     ///
02497     /// @code
02498     ///     _putp(DOSColor(12));
02499     /// @endcode
02500     ///
02501     /// @param[in] pixel is a color value to be put on the screen.
02502     /// @returns error code.
02503     ///
02504     virtual RetCode_t _putp(color_t pixel);
02505 
02506     
02507     /// Advanced method indicating the end of a graphics stream.
02508     ///
02509     /// This is called to conclude a stream of pixel data that was sent.
02510     /// This may cause register configuration changes in the derived
02511     /// class in order to stop the hardware from accept the streaming
02512     /// data.
02513     ///
02514     /// @returns error code.
02515     ///
02516     virtual RetCode_t _EndGraphicsStream(void);
02517 
02518 
02519     /// Set the SPI port frequency (in Hz).
02520     ///
02521     /// This uses the mbed SPI driver, and is therefore dependent on
02522     /// its capabilities. The RA8875 can accept writes via SPI faster
02523     /// than a read can be performed. The frequency set by this API
02524     /// is for the SPI writes. It will automatically reduce the SPI
02525     /// clock rate when a read is performed, and restore it for the 
02526     /// next write. Alternately, the 2nd parameters permits setting
02527     /// the read speed rather than letting it compute it automatically.
02528     ///
02529     /// @note The primary effect of this is to recover more CPU cycles
02530     ///     for your application code. Keep in mind that when more than
02531     ///     one command is sent to the display controller, that it
02532     ///     will wait for the controller to finish the prior command.
02533     ///     In this case, the performance is limited by the RA8875.
02534     ///
02535     /// @param[in] Hz is the frequency in Hz, tested range includes the
02536     ///     range from 1,000,000 (1MHz) to 10,000,000 (10 MHz). Values
02537     ///     outside this range will be accepted, but operation may
02538     ///     be unreliable. This depends partially on your hardware design
02539     ///     and the wires connecting the display module.
02540     ///     The default value is 5,000,000, which should work for most
02541     ///     applications as a starting point.
02542     /// @param[in] Hz2 is an optional parameter and will set the read
02543     ///     speed independently of the write speed.
02544     /// @returns success/failure code. See @ref RetCode_t.
02545     ///
02546     RetCode_t frequency(unsigned long Hz = RA8875_DEFAULT_SPI_FREQ, unsigned long Hz2 = 0);
02547 
02548 
02549     /// This method captures the specified area as a 24-bit bitmap file.
02550     ///
02551     /// Even though this is a 16-bit display, the stored image is in
02552     /// 24-bit format.
02553     ///
02554     /// This method will interrogate the current display setting and
02555     /// create a bitmap based on those settings. For instance, if 
02556     /// only layer 1 is visible, then the bitmap is only layer 1. However,
02557     /// if there is some other operation in effect (transparent mode).
02558     ///
02559     /// @param[in] x is the left edge of the region to capture
02560     /// @param[in] y is the top edge of the region to capture
02561     /// @param[in] w is the width of the region to capture
02562     /// @param[in] h is the height of the region to capture.
02563     /// @param[out] Name_BMP is the filename to write the image to.
02564     /// @return success or error code.
02565     ///
02566     RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP);
02567 
02568     
02569     /// This method captures the specified area as a 24-bit bitmap file
02570     /// and delivers it to the previously attached callback.
02571     ///
02572     /// Even though this is a 16-bit display, the stored image is in
02573     /// 24-bit format.
02574     ///
02575     /// This method will interrogate the current display setting and
02576     /// create a bitmap based on those settings. For instance, if 
02577     /// only layer 1 is visible, then the bitmap is only layer 1. However,
02578     /// if there is some other operation in effect (transparent mode), it
02579     /// will return the blended image.
02580     ///
02581     /// @param[in] x is the left edge of the region to capture
02582     /// @param[in] y is the top edge of the region to capture
02583     /// @param[in] w is the width of the region to capture
02584     /// @param[in] h is the height of the region to capture.
02585     /// @return success or error code.
02586     ///
02587     RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h);
02588 
02589     
02590     /// PrintScreen callback registration.
02591     ///
02592     /// This method attaches a simple c-compatible callback of type PrintCallback_T.
02593     /// Then, the PrintScreen(x,y,w,h) method is called. Each chunk of data in the
02594     /// BMP file to be created is passed to this callback.
02595     /// 
02596     /// @param callback is the optional callback function. Without a callback function
02597     ///     it will unregister the handler.
02598     ///
02599     void AttachPrintHandler(PrintCallback_T callback = NULL) { c_callback = callback; }
02600 
02601 
02602     /// PrintScreen callback registration.
02603     ///
02604     /// This method attaches a c++ class method as a callback of type PrintCallback_T.
02605     /// Then, the PrintScreen(x,y,w,h) method is called. Each chunk of data in the
02606     /// BMP file to be created is passed to this callback.
02607     /// 
02608     /// @param object is the class hosting the callback function.
02609     /// @param method is the callback method in the object to activate.
02610     ///
02611     template <class T>
02612     void AttachPrintHandler(T *object, RetCode_t (T::*method)(void)) { 
02613         obj_callback    = (FPointerDummy *)object; 
02614         method_callback = (uint32_t (FPointerDummy::*)(uint32_t, uint8_t *, uint16_t))method;
02615     }
02616 
02617 
02618     /// This method captures the specified area as a 24-bit bitmap file,
02619     /// including the option of layer selection.
02620     ///
02621     /// @note This method is deprecated as the alternate PrintScreen API
02622     ///         automatically examines the display layer configuration.
02623     ///         Therefore, calls to this API will ignore the layer parameter
02624     ///         and automatically execute the other method.
02625     ///
02626     /// Even though this is a 16-bit display, the stored image is in
02627     /// 24-bit format.
02628     ///
02629     /// @param[in] layer is 0 or 1 to select the layer to extract.
02630     /// @param[in] x is the left edge of the region to capture
02631     /// @param[in] y is the top edge of the region to capture
02632     /// @param[in] w is the width of the region to capture
02633     /// @param[in] h is the height of the region to capture.
02634     /// @param[out] Name_BMP is the filename to write the image to.
02635     /// @return success or error code.
02636     ///
02637     RetCode_t PrintScreen(uint16_t layer, loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP);
02638 
02639     
02640     /// idle callback registration.
02641     ///
02642     /// This method attaches a simple c-compatible callback of type IdleCallback_T.
02643     /// Then, at any time when the display driver is waiting, it will call the
02644     /// registered function. This is probably most useful if you want to service
02645     /// a watchdog, when you may have called an API that will "hang" waiting
02646     /// on the user.
02647     ///
02648     /// @param callback is the idle callback function. Without a callback function
02649     ///     it will unregister the handler.
02650     ///
02651     void AttachIdleHandler(IdleCallback_T callback = NULL) { idle_callback = callback; }
02652 
02653 
02654 #ifdef PERF_METRICS
02655     /// Clear the performance metrics to zero.
02656     void ClearPerformance();
02657     
02658     /// Count idle time.
02659     ///
02660     /// @param[in] t is the amount of idle time to accumulate.
02661     ///
02662     void CountIdleTime(uint32_t t);
02663     
02664     /// Report the performance metrics for drawing functions using
02665     /// the available serial channel.
02666     ///
02667     /// @param[in,out] pc is the serial channel to write to.
02668     ///
02669     void ReportPerformance(Serial & pc);
02670 #endif
02671 
02672 
02673 private:
02674     /// Touch panel parameters - common to both resistive and capacitive
02675     
02676     /// Data type to indicate which TP, if any, is in use.
02677     typedef enum {
02678         TP_NONE,            ///< no touch panel in use
02679         TP_RES,             ///< resistive touch panel using RA8875
02680         TP_CAP,             ///< capacitive touch panel using FT5206
02681     } WhichTP_T;
02682     
02683     /// boolean flag set true when using Capacitive touch panel, and false
02684     /// for resistive.
02685     WhichTP_T useTouchPanel;    ///< Indicates which TP is selected for use.
02686         
02687     /// Touch State used by TouchPanelReadable. See @ref TouchCode_t.
02688     TouchCode_t touchState;
02689 
02690     ////////////////// Start of Capacitive Touch Panel parameters
02691     
02692     uint8_t getTouchPositions(void);
02693     void TouchPanelISR(void);
02694     uint16_t numberOfTouchPoints;
02695     uint8_t gesture;            ///< Holds the reported gesture information.
02696     
02697     /// Touch Information data structure
02698     typedef struct {
02699         uint8_t touchID;        ///< Contains the touch ID, which is the "order" of touch, from 0 to n-1
02700         TouchCode_t touchCode;  ///< Contains the touch code; no_touch, touch, held, release
02701         point_t coordinates;    ///< Contains the X,Y coordinate of the touch
02702     } touchInfo_T;
02703 
02704     touchInfo_T touchInfo[5];   /// Contains the actual touch information in an array from 0 to n-1
02705 
02706     InterruptIn * m_irq;
02707     I2C * m_i2c;
02708     int m_addr;
02709     uint8_t data[2];
02710 
02711     bool panelTouched;
02712     void writeRegister8(uint8_t reg, uint8_t val);
02713     uint8_t readRegister8(uint8_t reg);
02714 
02715     
02716     ////////////////// Start of Resistive Touch Panel parameters
02717     
02718     /// Resistive Touch Panel register name definitions
02719     #define TPCR0   0x70
02720     #define TPCR1   0x71
02721     #define TPXH    0x72
02722     #define TPYH    0x73
02723     #define TPXYL   0x74
02724     #define INTC1   0xF0
02725     #define INTC2   0xF1
02726 
02727     /// Specify the default settings for the Touch Panel, where different from the chip defaults
02728     #define TP_MODE_DEFAULT             TP_MODE_AUTO
02729     #define TP_DEBOUNCE_DEFAULT         TP_DEBOUNCE_ON
02730     #define TP_ADC_CLKDIV_DEFAULT       TP_ADC_CLKDIV_8
02731 
02732     #define TP_ADC_SAMPLE_DEFAULT_CLKS  TP_ADC_SAMPLE_8192_CLKS
02733 
02734     /// Other Touch Panel params
02735     #define TPBUFSIZE   16       // Depth of the averaging buffers for x and y data
02736 
02737     // Needs both a ticker and a timer. (could have created a timer from the ticker, but this is easier).
02738     // on a touch, the timer is reset.
02739     // the ticker monitors the timer to see if it has been a long time since
02740     // a touch, and if so, it then clears the sample counter so it doesn't get partial old
02741     // and partial new.
02742     
02743     /// Touch Panel ticker
02744     Ticker touchTicker;
02745     
02746     /// Touch Panel timer
02747     Timer touchTimer;
02748     
02749     /// keeps track of which sample we're collecting to filter out the noise.
02750     int touchSample;
02751     
02752     /// Private function for touch ticker callback.
02753     void _TouchTicker(void);
02754     
02755     /// Touch Panel calibration matrix.
02756     tpMatrix_t tpMatrix;
02757 
02758     ////////////////// End of Touch Panel parameters
02759 
02760 
02761     /// Internal function to put a character using the built-in (internal) font engine
02762     ///
02763     /// @param[in] c is the character to put to the screen.
02764     /// @returns the character put.
02765     ///
02766     int _internal_putc(int c);
02767     
02768     /// Internal function to put a character using the external font engine
02769     ///
02770     /// @param[in] c is the character to put to the screen.
02771     /// @returns the character put.
02772     ///
02773     int _external_putc(int c);
02774     
02775     /// Internal function to get the actual width of a character when using the external font engine
02776     ///
02777     /// @param[in] c is the character to get the width.
02778     /// @returns the width in pixels of the character. zero if not found.
02779     ///
02780     int _external_getCharWidth(int c);
02781     
02782     /// Write color to an RGB register set
02783     ///
02784     /// This API takes a color value, and writes it into the specified
02785     /// color registers, which are a trio of 3 registers. The actual
02786     /// trio write is performed based on whether the display is configured
02787     /// for 8 or 16 bits per pixel.
02788     ///
02789     /// @param[in] regAddr is the register address starting the trio
02790     /// @param[in] color is the color to write
02791     /// @returns success/failure code. See @ref RetCode_t.
02792     ///
02793     RetCode_t _writeColorTrio(uint8_t regAddr, color_t color);
02794     
02795     /// Read color from an RGB register set
02796     ///
02797     /// This API reads a color value from a trio of registers. The actual
02798     /// trio write is performed based on whether the display is configured
02799     /// for 8 or 16 bits per pixel.
02800     ///
02801     /// @param[in] regAddr is the register address starting the trio
02802     /// @returns color_t value
02803     ///
02804     color_t _readColorTrio(uint8_t regAddr);
02805     
02806     
02807     /// Convert a 16-bit color value to an 8-bit value
02808     ///
02809     /// @param[in] c16 is the 16-bit color value to convert.
02810     /// @returns 8-bit color value.
02811     ///
02812     uint8_t _cvt16to8(color_t c16);
02813 
02814     /// Convert an 8-bit color value to a 16-bit value
02815     ///
02816     /// @param[in] c8 is the 8-bit color value to convert.
02817     /// @returns 16-bit color value.
02818     ///
02819     color_t _cvt8to16(uint8_t c8);
02820     
02821     /// Select the peripheral to use it.
02822     ///
02823     /// @param[in] chipsel when true will select the peripheral, and when false
02824     ///     will deselect the chip. This is the logical selection, and
02825     ///     the pin selection is the invert of this.
02826     /// @returns success/failure code. See @ref RetCode_t.
02827     ///
02828     RetCode_t _select(bool chipsel);
02829 
02830     /// Wait while the status register indicates the controller is busy.
02831     ///
02832     /// @param[in] mask is the mask of bits to monitor.
02833     /// @returns true if a normal exit.
02834     /// @returns false if a timeout exit.
02835     ///
02836     bool _WaitWhileBusy(uint8_t mask);
02837 
02838     /// Wait while the the register anded with the mask is true.
02839     ///
02840     /// @param[in] reg is the register to monitor
02841     /// @param[in] mask is the bit mask to monitor
02842     /// @returns true if it was a normal exit
02843     /// @returns false if it was a timeout that caused the exit.
02844     ///
02845     bool _WaitWhileReg(uint8_t reg, uint8_t mask);
02846 
02847     /// set the spi port to either the write or the read speed.
02848     ///
02849     /// This is a private API used to toggle between the write
02850     /// and the read speed for the SPI port to the RA8875, since
02851     /// it can accept writes faster than reads.
02852     ///
02853     /// @param[in] writeSpeed when true selects the write frequency,
02854     ///     and when false it selects the read frequency.
02855     ///
02856     void _setWriteSpeed(bool writeSpeed);
02857 
02858     /// The most primitive - to write a data value to the SPI interface.
02859     ///
02860     /// @param[in] data is the value to write.
02861     /// @returns a value read from the port, since SPI is often shift
02862     ///     in while shifting out.
02863     ///
02864     unsigned char _spiwrite(unsigned char data);
02865     
02866     /// The most primitive - to read a data value to the SPI interface.
02867     ///
02868     /// This is really just a specialcase of the write command, where
02869     /// the value zero is written in order to read.
02870     ///
02871     /// @returns a value read from the port, since SPI is often shift
02872     ///     in while shifting out.
02873     ///
02874     unsigned char _spiread();
02875     
02876     const uint8_t * pKeyMap;
02877     
02878     SPI spi;                        ///< spi port
02879     bool spiWriteSpeed;             ///< indicates if the current mode is write or read
02880     unsigned long spiwritefreq;     ///< saved write freq
02881     unsigned long spireadfreq;      ///< saved read freq
02882     DigitalOut cs;                  ///< chip select pin, assumed active low
02883     DigitalOut res;                 ///< reset pin, assumed active low
02884     
02885     // display metrics to avoid lengthy spi read queries
02886     uint8_t screenbpp;              ///< configured bits per pixel
02887     dim_t screenwidth;              ///< configured screen width
02888     dim_t screenheight;             ///< configured screen height
02889     rect_t windowrect;              ///< window commands are held here for speed of access 
02890     bool portraitmode;              ///< set true when in portrait mode (w,h are reversed)
02891     
02892     const unsigned char * font;     ///< reference to an external font somewhere in memory
02893     uint8_t extFontHeight;          ///< computed from the font table when the user sets the font
02894     uint8_t extFontWidth;           ///< computed from the font table when the user sets the font
02895     
02896     loc_t cursor_x, cursor_y;       ///< used for external fonts only
02897     
02898     #ifdef PERF_METRICS
02899     typedef enum
02900     {
02901         PRF_CLS,
02902         PRF_DRAWPIXEL,
02903         PRF_PIXELSTREAM,
02904         PRF_BOOLSTREAM,
02905         PRF_READPIXEL,
02906         PRF_READPIXELSTREAM,
02907         PRF_DRAWLINE,
02908         PRF_DRAWRECTANGLE,
02909         PRF_DRAWROUNDEDRECTANGLE,
02910         PRF_DRAWTRIANGLE,
02911         PRF_DRAWCIRCLE,
02912         PRF_DRAWELLIPSE,
02913         PRF_BLOCKMOVE,
02914         METRICCOUNT
02915     } method_e;
02916     unsigned long metrics[METRICCOUNT];
02917     unsigned long idletime_usec;
02918     void RegisterPerformance(method_e method);
02919     Timer performance;
02920     #endif
02921     
02922     RetCode_t _printCallback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size);
02923     
02924     FILE * _printFH;             ///< PrintScreen file handle
02925     
02926     RetCode_t privateCallback(filecmd_t cmd, uint8_t * buffer, uint16_t size) {
02927         if (c_callback != NULL) {
02928             return (*c_callback)(cmd, buffer, size);
02929         }
02930         else {
02931             if (obj_callback != NULL && method_callback != NULL) {
02932                 return (obj_callback->*method_callback)(cmd, buffer, size);
02933             }
02934         }
02935         return noerror;
02936     }
02937     
02938     RetCode_t (* c_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size);
02939     FPointerDummy  *obj_callback;
02940     RetCode_t (FPointerDummy::*method_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size);
02941     RetCode_t (* idle_callback)(IdleReason_T reason);
02942 };
02943 
02944 
02945 //}     // namespace
02946 
02947 //using namespace SW_graphics;
02948 
02949 
02950 #ifdef TESTENABLE
02951 //      ______________  ______________  ______________  _______________
02952 //     /_____   _____/ /  ___________/ /  ___________/ /_____   ______/
02953 //          /  /      /  /            /  /                  /  /
02954 //         /  /      /  /___         /  /__________        /  /
02955 //        /  /      /  ____/        /__________   /       /  /
02956 //       /  /      /  /                       /  /       /  /
02957 //      /  /      /  /__________  ___________/  /       /  /
02958 //     /__/      /_____________/ /_____________/       /__/
02959 
02960 #include "WebColors.h"
02961 #include <algorithm>
02962 
02963 extern "C" void mbed_reset();
02964 
02965 /// This activates a small set of tests for the graphics library. 
02966 ///
02967 /// Call this API and pass it the reference to the display class.
02968 /// It will then run a series of tests. It accepts interaction via
02969 /// stdin to switch from automatic test mode to manual, run a specific
02970 /// test, or to exit the test mode.
02971 ///
02972 /// @param[in] lcd is a reference to the display class.
02973 /// @param[in] pc is a reference to a serial interface, typically the USB to PC.
02974 ///
02975 void RunTestSet(RA8875 & lcd, Serial & pc);
02976 
02977 
02978 // To enable the test code, uncomment this section, or copy the
02979 // necessary pieces to your "main()".
02980 //
02981 // #include "mbed.h"
02982 // #include "RA8875.h"
02983 // RA8875 lcd(p5, p6, p7, p12, NC, "tft");    // MOSI, MISO, SCK, /ChipSelect, /reset, name
02984 // Serial pc(USBTX, USBRX);
02985 // extern "C" void mbed_reset();
02986 // int main()
02987 // {
02988 //     pc.baud(460800);    // I like a snappy terminal, so crank it up!
02989 //     pc.printf("\r\nRA8875 Test - Build " __DATE__ " " __TIME__ "\r\n");
02990 // 
02991 //     pc.printf("Turning on display\r\n");
02992 //     lcd.init();
02993 //     lcd.Reset();
02994 //     lcd.Power(true);  // display power is on, but the backlight is independent
02995 //     lcd.Backlight(0.5);
02996 //     RunTestSet(lcd, pc);
02997 // }
02998 
02999 #endif // TESTENABLE
03000 
03001 #endif