brw1

Dependencies:   mbed

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 /// The controller additionally supports backlight control (via PWM), keypad scanning
00012 /// (for a 4 x 5 matrix) and resistive touch-panel support. 
00013 ///
00014 /// @section Display_Config Display Configuration
00015 ///
00016 /// This section details basics for bringing the display online. At a minimum,
00017 /// the display is instantiated. After that any of the available commands
00018 /// may be issued.
00019 ///
00020 /// During the instantiation, the display is powered on, cleared, and the backlight
00021 /// is energized. Additionally, the keypad and touchscreen features are activated.
00022 /// It is important to keep in mind that the keypad had the default mapping, and
00023 /// the touchscreen does not have the calibration matrix configured, so additional
00024 /// steps may be necessary.
00025 /// 
00026 /// @code 
00027 /// RA8875 lcd(p5, p6, p7, p12, NC, "tft");
00028 /// lcd.init();
00029 /// lcd.foreground(Blue);
00030 /// lcd.line(0,0, 479,271);
00031 /// ...
00032 /// @endcode
00033 ///
00034 /// @section Touch_Panel Touch Panel
00035 ///
00036 /// The supported touch panel interface is for a resistive panel, and is natively 
00037 /// supported by the RA8875 controller. There are a few steps to enable this interface.
00038 ///
00039 /// @subsection Touch_Panel_Enable Touch Panel Enable
00040 ///
00041 /// @see TouchPanelInit has two forms - fully automatic, and controlled. See the APIs for
00042 /// details.
00043 ///
00044 /// @subsection Touch_Panel_Calibration
00045 /// 
00046 /// The touch panel is not initially calibrated on startup. The application should 
00047 /// provide a means to activate the calibration process, and that should not require
00048 /// the touchscreen as it may not yet be usable. Alternately, a calibration matrix
00049 /// can be loaded from non-volatile and installed.
00050 ///
00051 /// @section Keypad Keypad
00052 ///
00053 /// The keypad has a default keypad mapping, but there is an API that permits
00054 /// installing a custom keymap.
00055 ///
00056 #ifndef RA8875_H
00057 #define RA8875_H
00058 #include <mbed.h>
00059 
00060 #include "RA8875_Regs.h"
00061 #include "GraphicsDisplay.h"
00062 
00063 #define RA8875_DEFAULT_SPI_FREQ 5000000
00064 
00065 // Define this to enable code that monitors the performance of various
00066 // graphics commands.
00067 //#define PERF_METRICS
00068 
00069 // What better place for some test code than in here and the companion
00070 // .cpp file. See also the bottom of this file.
00071 //#define TESTENABLE
00072 
00073 /// DOS colors - slightly color enhanced
00074 #define Black       (color_t)(RGB(0,0,0))
00075 #define Blue        (color_t)(RGB(0,0,187))
00076 #define Green       (color_t)(RGB(0,187,0))
00077 #define Cyan        (color_t)(RGB(0,187,187))
00078 #define Red         (color_t)(RGB(187,0,0))
00079 #define Magenta     (color_t)(RGB(187,0,187))
00080 #define Brown       (color_t)(RGB(63,63,0))
00081 #define Gray        (color_t)(RGB(187,187,187))
00082 #define Charcoal    (color_t)(RGB(85,85,85))
00083 #define BrightBlue  (color_t)(RGB(0,0,255))
00084 #define BrightGreen (color_t)(RGB(0,255,0))
00085 #define BrightCyan  (color_t)(RGB(0,255,255))
00086 #define BrightRed   (color_t)(RGB(255,0,0))
00087 #define Orange      (color_t)(RGB(255,85,85))
00088 #define Pink        (color_t)(RGB(255,85,255))
00089 #define Yellow      (color_t)(RGB(187,187,0))
00090 #define White       (color_t)(RGB(255,255,255))
00091 
00092 #define DarkBlue    (color_t)(RGB(0,0,63))
00093 #define DarkGreen   (color_t)(RGB(0,63,0))
00094 #define DarkCyan    (color_t)(RGB(0,63,63))
00095 #define DarkRed     (color_t)(RGB(63,0,0))
00096 #define DarkMagenta (color_t)(RGB(63,0,63))
00097 #define DarkBrown   (color_t)(RGB(63,63,0))
00098 #define DarkGray    (color_t)(RGB(63,63,63))
00099 
00100 
00101 //namespace SW_graphics
00102 //{
00103 
00104 
00105 /// This is a graphics library for the Raio RA8875 Display Controller chip
00106 /// attached to a 4-wire SPI interface.
00107 ///
00108 /// It offers both primitive and high level APIs.
00109 ///
00110 /// Central to this API is a coordinate system, where the origin (0,0) is in
00111 /// the top-left corner of the display, and the width (x) extends positive to the
00112 /// right and the height (y) extends positive toward the bottom.
00113 ///
00114 /// @caution As there are both graphics and text commands, one must take care to use
00115 /// the proper coordinate system for each. Some of the text APIs are in units
00116 /// of column and row, which is measured in character positions (and dependent
00117 /// on the font size), where other text APIs permit pixel level positioning.
00118 ///
00119 /// @code
00120 /// #include "RA8875.h"
00121 /// RA8875 lcd(p5, p6, p7, p12, NC, "tft");
00122 ///
00123 /// int main()
00124 /// {
00125 ///     lcd.init();
00126 ///     lcd.printf("printing 3 x 2 = %d", 3*2);
00127 ///     lcd.circle(       400,25,  25,               BrightRed);
00128 ///     lcd.fillcircle(   400,25,  15,               RGB(128,255,128));
00129 ///     lcd.ellipse(      440,75,  35,20,            BrightBlue);
00130 ///     lcd.fillellipse(  440,75,  25,10,            Blue);
00131 ///     lcd.triangle(     440,100, 475,110, 450,125, Magenta);
00132 ///     lcd.filltriangle( 445,105, 467,111, 452,120, Cyan);
00133 ///     lcd.rect(         400,130, 475,155,          Brown);
00134 ///     lcd.fillrect(     405,135, 470,150,          Pink);
00135 ///     lcd.roundrect(    410,160, 475,190, 10,8,    Yellow);
00136 ///     lcd.fillroundrect(415,165, 470,185,  5,3,    Orange);
00137 ///     lcd.line(         430,200, 460,230,          RGB(0,255,0));
00138 ///     for (int i=0; i<=30; i+=5) 
00139 ///         lcd.pixel(435+i,200+i, White);
00140 /// }
00141 /// @endcode
00142 ///
00143 /// @todo Add Scroll support for text.
00144 /// @todo Improve sync between internal and external font support - cursor, window, scroll.
00145 /// @todo Add Hardware reset signal - but testing to date indicates it is not needed.
00146 /// @todo Add high level objects - x-y graph, meter, others... but these will
00147 ///     probably be best served in another class, since they may not
00148 ///     be needed for many uses.
00149 /// 
00150 class RA8875 : public GraphicsDisplay
00151 {
00152 public:   
00153     /// cursor type to be shown as the text cursor.
00154     typedef enum
00155     {
00156         NOCURSOR,   ///< cursor is hidden
00157         IBEAM,      ///< | cursor
00158         UNDER,      ///< _ cursor
00159         BLOCK       ///< Block cursor
00160     } cursor_t;
00161 
00162     /// font type selection.
00163     typedef enum
00164     {
00165         ISO8859_1,      ///< ISO8859-1 font
00166         ISO8859_2,      ///< ISO8859-2 font
00167         ISO8859_3,      ///< ISO8859-3 font
00168         ISO8859_4       ///< ISO8859-4 font
00169     } font_t;
00170     
00171     /// font rotation selection
00172     typedef enum
00173     {
00174         normal,         ///< normal orientation
00175         rotated         ///< rotated orientation
00176     } font_angle_t;
00177     
00178     /// alignment  
00179     typedef enum
00180     {
00181         align_none,     ///< align - none
00182         align_full      ///< align - full
00183     } alignment_t;    
00184     
00185     /// Scale factor - 1, 2, 3 4
00186     typedef int HorizontalScale;
00187     
00188     /// Scale factor - 1, 2, 3, 4
00189     typedef int VerticalScale;
00190 
00191     /// Clear screen region
00192     typedef enum
00193     {
00194         FULLWINDOW,     ///< Full screen
00195         ACTIVEWINDOW    ///< active window/region
00196     } Region_t;
00197     
00198     /// Set the Layer Display Mode. @ref SetLayerMode
00199     typedef enum
00200     {
00201         ShowLayer0,         ///< Only layer 0 is visible, layer 1 is hidden (default)
00202         ShowLayer1,         ///< Only layer 1 is visible, layer 0 is hidden
00203         LightenOverlay,     ///< Lighten-overlay mode
00204         TransparentMode,    ///< Transparent mode
00205         BooleanOR,          ///< Boolean OR mode
00206         BooleanAND,         ///< Boolean AND mode
00207         FloatingWindow      ///< Floating Window mode
00208     } LayerMode_T;
00209     
00210     /// Touch Panel modes
00211     typedef enum
00212     {
00213         TP_Auto,               ///< Auto touch detection mode
00214         TP_Manual,             ///< Manual touch detection mode
00215     } tpmode_t;
00216     
00217     /// Constructor for a display based on the RAiO RA8875 
00218     /// display controller.
00219     ///
00220     /// This configures the registers and calls the @ref init method.
00221     ///
00222     /// @code
00223     /// #include "RA8875.h"
00224     /// RA8875 lcd(p5, p6, p7, p12, NC, "tft");
00225     ///
00226     /// int main()
00227     /// {
00228     ///     lcd.init();
00229     ///     lcd.printf("printing 3 x 2 = %d", 3*2);
00230     ///     lcd.circle(400,25, 25, BrightRed);
00231     /// }
00232     /// @endcode
00233     ///
00234     /// @param[in] mosi is the SPI master out slave in pin on the mbed.
00235     /// @param[in] miso is the SPI master in slave out pin on the mbed.
00236     /// @param[in] sclk is the SPI shift clock pin on the mbed.
00237     /// @param[in] csel is the DigitalOut pin on the mbed to use as the
00238     ///         active low chip select for the display controller.
00239     /// @param[in] reset is the DigitalOut pin on the mbed to use as the 
00240     ///         active low reset input on the display controller - 
00241     ///         but this is not currently used.
00242     /// @param[in] name is a text name for this object, which will permit
00243     ///         capturing stdout to puts() and printf() directly to it.
00244     ///
00245     RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, const char * name = "lcd");
00246     
00247     // Destructor doesn't have much to do as this would typically be created
00248     // at startup, and not at runtime.
00249     //~RA8875();
00250     
00251     /// Initialize the driver.
00252     ///
00253     /// @param[in] width in pixels to configure the display for. This parameter is optional
00254     ///             and the default is 480.
00255     /// @param[in] height in pixels to configure the display for. This parameter is optional
00256     ///             and the default is 272.
00257     /// @param[in] color_bpp can be either 8 or 16, but must be consistent
00258     ///             with the width and height parameters. This parameter is optional
00259     ///             and the default is 16.
00260     /// @param[in] power defines if the display should be left in the power-on or off state.
00261     ///            If power is true (on), the backlight is set to 100%. This parameter is optional
00262     ///             and the default is true (on). @see Power.
00263     /// @param[in] keypadon defines if the keypad support should be enabled. This parameter is optional
00264     ///             and the default is true (enabled). @see KeypadInit.
00265     /// @param[in] touchscreeenon defines if the keypad support should be enabled. This parameter is optional
00266     ///             and the default is true (enabled). @see TouchPanelInit.
00267     /// @returns success/failure code. @see RetCode_t.
00268     ///
00269     RetCode_t init(int width = 480, int height = 272, int color_bpp = 16, 
00270         bool poweron = true, bool keypadon = true, bool touchscreeenon = true);
00271     
00272     /// Get a pointer to the error code.
00273     ///
00274     /// This method returns a pointer to a text string that matches the
00275     /// code. @see RetCode_t.
00276     ///
00277     /// @param[in] code is the return value from RetCode_t to look up.
00278     /// @returns a pointer to the text message representing code. If code
00279     ///     is not a valid value, then it returns the text for bad_parameter;
00280     const char * GetErrorMessage(RetCode_t code);
00281     
00282     
00283     /// Select the drawing layer for subsequent commands.
00284     ///
00285     /// If the screen configuration is 480 x 272, or if it is 800 x 480 
00286     /// and 8-bit color, the the display supports two layers, which can 
00287     /// be independently drawn on and shown. Additionally, complex
00288     /// operations involving both layers are permitted.
00289     ///
00290     /// @code
00291     ///     //lcd.SetLayerMode(OnlyLayer0); // default is layer 0
00292     ///     lcd.rect(400,130, 475,155,Brown);
00293     ///     lcd.SelectDrawingLayer(1);
00294     ///     lcd.circle(400,25, 25, BrightRed);
00295     ///     wait(1);
00296     ///     lcd.SetLayerMode(ShowLayer1);
00297     /// @endcode
00298     ///
00299     /// @attention The user manual refers to Layer 1 and Layer 2, however the
00300     ///     actual register values are value 0 and 1. This API as well as
00301     ///     others that reference the layers use the values 0 and 1 for
00302     ///     cleaner iteration in the code.
00303     ///
00304     /// @param[in] layer is 0 or 1 to select the layer for subsequent 
00305     ///     commands.
00306     /// @returns success/failure code. @see RetCode_t.
00307     ///
00308     RetCode_t SelectDrawingLayer(uint16_t layer);
00309     
00310     /// Get the currently active drawing layer.
00311     ///
00312     /// This returns a value, 0 or 1, based on the screen configuration
00313     /// and the currently active drawing layer.
00314     ///
00315     /// @code
00316     ///     uint16_t prevLayer = lcd.GetDrawingLayer();
00317     ///     lcd.SelectDrawingLayer(x);
00318     ///     lcd.circle(400,25, 25, BrightRed);
00319     ///     lcd.SelectDrawingLayer(prevLayer);
00320     /// @endcode
00321     ///
00322     /// @attention The user manual refers to Layer 1 and Layer 2, however the
00323     ///     actual register values are value 0 and 1. This API as well as
00324     ///     others that reference the layers use the values 0 and 1 for
00325     ///     cleaner iteration in the code.
00326     ///
00327     /// @returns the current drawing layer; 0 or 1.
00328     /// 
00329     uint16_t GetDrawingLayer(void);
00330     
00331     /// Set the Layer presentation mode.
00332     ///
00333     /// This sets the presentation mode for layers, and permits showing
00334     /// a single layer, or applying a mode where the two layers
00335     /// are combined using one of the hardware methods.
00336     ///
00337     /// Refer to the RA8875 data sheet for full details.
00338     ///
00339     /// @code
00340     ///     //lcd.SetLayerMode(OnlyLayer0); // default is layer 0
00341     ///     lcd.rect(400,130, 475,155,Brown);
00342     ///     lcd.SelectDrawingLayer(1);
00343     ///     lcd.circle(400,25, 25, BrightRed);
00344     ///     wait(1);
00345     ///     lcd.SetLayerMode(ShowLayer1);
00346     /// @endcode
00347     ///
00348     /// @param[in] mode sets the mode in the Layer Transparency Register.
00349     /// @returns success/failure code. @see RetCode_t.
00350     ///
00351     RetCode_t SetLayerMode(LayerMode_T mode);
00352     
00353     /// Set the layer transparency for each layer.
00354     ///
00355     /// Set the transparency, where the range of values is
00356     /// from zero (fully visible) to eight (fully transparent).
00357     /// The input value is automatically limited to this range.
00358     ///
00359     /// @code
00360     ///     // draw something on each layer, then step-fade across
00361     ///     display.SetLayerMode(RA8875::TransparentMode);
00362     ///     for (i=0; i<=8; i++) {
00363     ///         display.SetLayerTransparency(i, 8-i);
00364     ///         wait_ms(200);
00365     ///     }
00366     /// @endcode
00367     ///
00368     /// @param[in] layer1 sets the layer 1 transparency.
00369     /// @param[in] layer2 sets the layer 2 transparency.
00370     /// @returns success/failure code. @see RetCode_t.
00371     /// 
00372     RetCode_t SetLayerTransparency(uint8_t layer1, uint8_t layer2);
00373     
00374     /// Set the background color register used for transparency.
00375     ///
00376     /// This command sets the background color registers that are used
00377     /// in the transparent color operations involving the layers.
00378     /// 
00379     /// @param[in] color is optional and expressed in 16-bit format. If not
00380     ///     supplied, a default of Black is used.
00381     /// @returns success/failure code. @see RetCode_t.
00382     ///
00383     RetCode_t SetBackgroundTransparencyColor(color_t color = RGB(0,0,0));
00384  
00385  
00386     /// Get the background color value used for transparency.
00387     ///
00388     /// This command reads the background color registers that define
00389     /// the transparency color for operations involving layers.
00390     ///
00391     /// @returns the color.
00392     ///
00393     color_t GetBackgroundTransparencyColor(void);
00394  
00395     /// Initialize theTouch Panel controller with default values 
00396     ///
00397     /// This activates the simplified touch panel init, which may work for
00398     /// most uses. The alternate API is available if fine-grained control
00399     /// is needed for the numerous settings.
00400     ///
00401     /// @returns success/failure code. @see RetCode_t.
00402     ///
00403     RetCode_t TouchPanelInit(void);
00404         
00405     /// Initialize the Touch Panel controller with detailed settings.
00406     ///
00407     /// This is the detailed touch panel init, which provides the ability
00408     /// to set nearly every possible option.
00409     ///
00410     /// @param[in]  bTpEnable           Touch Panel enable/disable control:
00411     ///                                 - TP_ENABLE: enable the touch panel
00412     ///                                 - TP_DISABLE: disable the touch panel
00413     /// @param[in]  bTpAutoManual       Touch Panel operating mode:
00414     ///                                 - TP_MODE_AUTO: automatic capture
00415     ///                                 - TP_MODE_MANUAL: manual capture
00416     /// @param[in]  bTpDebounce         Debounce circuit enable for touch panel interrupt:
00417     ///                                 - TP_DEBOUNCE_OFF: disable the debounce circuit
00418     ///                                 - TP_DEBOUNCE_ON: enable the debounce circuit     
00419     /// @param[in]  bTpManualMode       When Manual Mode is selected, this sets the mode:
00420     ///                                 - TP_MANUAL_IDLE: touch panel is idle   
00421     ///                                 - TP_MANUAL_WAIT: wait for touch panel event   
00422     ///                                 - TP_MANUAL_LATCH_X: latch X data  
00423     ///                                 - TP_MANUAL_LATCH_Y: latch Y data   
00424     /// @param[in]  bTpAdcClkDiv        Sets the ADC clock as a fraction of the System CLK:
00425     ///                                 - TP_ADC_CLKDIV_1: Use CLK   
00426     ///                                 - TP_ADC_CLKDIV_2: Use CLK/2   
00427     ///                                 - TP_ADC_CLKDIV_4: Use CLK/4   
00428     ///                                 - TP_ADC_CLKDIV_8: Use CLK/8   
00429     ///                                 - TP_ADC_CLKDIV_16: Use CLK/16   
00430     ///                                 - TP_ADC_CLKDIV_32: Use CLK/32   
00431     ///                                 - TP_ADC_CLKDIV_64: Use CLK/64   
00432     ///                                 - TP_ADC_CLKDIV_128: Use CLK/128   
00433     /// @param[in]  bTpAdcSampleTime    Touch Panel sample time delay before ADC data is ready:
00434     ///                                 - TP_ADC_SAMPLE_512_CLKS: Wait 512 system clocks   
00435     ///                                 - TP_ADC_SAMPLE_1024_CLKS: Wait 1024 system clocks   
00436     ///                                 - TP_ADC_SAMPLE_2048_CLKS: Wait 2048 system clocks   
00437     ///                                 - TP_ADC_SAMPLE_4096_CLKS: Wait 4096 system clocks   
00438     ///                                 - TP_ADC_SAMPLE_8192_CLKS: Wait 8192 system clocks   
00439     ///                                 - TP_ADC_SAMPLE_16384_CLKS: Wait 16384 system clocks   
00440     ///                                 - TP_ADC_SAMPLE_32768_CLKS: Wait 32768 system clocks   
00441     ///                                 - TP_ADC_SAMPLE_65536_CLKS: Wait 65536 system clocks
00442     /// @returns success/failure code. @see RetCode_t.   
00443     ///
00444     RetCode_t TouchPanelInit(uint8_t bTpEnable, uint8_t bTpAutoManual, uint8_t bTpDebounce, 
00445         uint8_t bTpManualMode, uint8_t bTpAdcClkDiv, uint8_t bTpAdcSampleTime);
00446     
00447     /// Poll the TouchPanel and on a touch event return the a to d filtered x, y coordinates.
00448     ///
00449     /// This method reads the touch controller, which has a 10-bit range for each the
00450     /// x and the y axis.
00451     ///
00452     /// @note The returned values are not in display (pixel) units but are in analog to
00453     ///     digital converter units.
00454     /// 
00455     /// @note This API is usually not needed. @see TouchPanelComputeCalibration. 
00456     ///     @see TouchPanelReadable.
00457     /// 
00458     /// @param[out] x is the x scale a/d value.
00459     /// @param[out] y is the y scale a/d value.
00460     /// @returns true if touch was detected, in which case the x and y values were set.
00461     ///
00462     bool TouchPanelA2DFiltered(loc_t *x, loc_t *y);
00463 
00464     /// Poll the TouchPanel and on a touch event return the a to d raw x, y coordinates.
00465     ///
00466     /// This method reads the touch controller, which has a 10-bit range for each the
00467     /// x and the y axis. A number of samples of the raw data are taken, filtered,
00468     /// and the results are returned. 
00469     ///
00470     /// @note The returned values are not in display (pixel) units but are in analog to
00471     ///     digital converter units.
00472     /// 
00473     /// @note This API is usually not needed. @see TouchPanelComputeCalibration. 
00474     ///     @see TouchPanelReadable.
00475     /// 
00476     /// @param[out] x is the x scale a/d value.
00477     /// @param[out] y is the y scale a/d value.
00478     /// @returns true if touch was detected, in which case the x and y values were set.
00479     ///
00480     bool TouchPanelA2DRaw(loc_t *x, loc_t *y);
00481     
00482     /// Calibrate the touch panel.
00483     ///
00484     /// This method accepts two lists - one list is target points in ,
00485     /// display coordinates and the other is a lit of raw touch coordinate 
00486     /// values. It generates a calibration matrix for later use. This
00487     /// matrix is also accessible to the calling API, which may store
00488     /// the matrix in persistent memory and then install the calibration
00489     /// matrix on the next power cycle. By doing so, it can avoid the
00490     /// need to calibrate on every power cycle.
00491     ///
00492     /// @note The methods "TouchPanelComputeCalibration", "TouchPanelReadable", and
00493     ///     indirectly the "TouchPanelSetMatrix" methods are all derived
00494     ///     from a program by Carlos E. Vidales. See the copyright note
00495     ///     for further details. See also the article
00496     ///     http://www.embedded.com/design/system-integration/4023968/How-To-Calibrate-Touch-Screens
00497     ///
00498     /// @copyright Copyright (c) 2001, Carlos E. Vidales. All rights reserved.
00499     ///     This sample program was written and put in the public domain 
00500     ///      by Carlos E. Vidales.  The program is provided "as is" 
00501     ///      without warranty of any kind, either expressed or implied.
00502     ///     If you choose to use the program within your own products
00503     ///      you do so at your own risk, and assume the responsibility
00504     ///      for servicing, repairing or correcting the program should
00505     ///      it prove defective in any manner.
00506     ///     You may copy and distribute the program's source code in any 
00507     ///      medium, provided that you also include in each copy an
00508     ///      appropriate copyright notice and disclaimer of warranty.
00509     ///     You may also modify this program and distribute copies of
00510     ///      it provided that you include prominent notices stating 
00511     ///      that you changed the file(s) and the date of any change,
00512     ///      and that you do not charge any royalties or licenses for 
00513     ///      its use.
00514     ///
00515     /// @param[in] display is a pointer to a set of 3 points, which 
00516     ///             are in display units of measure. These are the targets
00517     ///             the calibration was aiming for.
00518     /// @param[in] screen is a pointer to a set of 3 points, which
00519     ///             are in touchscreen units of measure. These are the
00520     ///             registered touches.
00521     /// @param[out] matrix is an optional parameter to hold the calibration matrix 
00522     ///             as a result of the calibration. This can be saved in  
00523     ///             non-volatile memory to recover the calibration after a power fail.
00524     /// @returns success/failure code. @see RetCode_t.
00525     ///
00526     RetCode_t TouchPanelComputeCalibration(point_t display[3], point_t screen[3], tpMatrix_t * matrix);
00527 
00528 
00529     /// Perform the touch panel calibration process.
00530     ///
00531     /// This method provides the easy "shortcut" to calibrating the touch panel.
00532     /// The process will automatically generate the calibration points, present
00533     /// the targets on-screen, detect the touches, compute the calibration
00534     /// matrix, and optionally provide the calibration matrix to the calling code
00535     /// for persistence in non-volatile memory.
00536     ///
00537     /// @param[out] matrix is an optional parameter to hold the calibration matrix 
00538     ///             as a result of the calibration. This can be saved in  
00539     ///             non-volatile memory to recover the calibration after a power fail.
00540     /// @returns success/failure code. @see RetCode_t.
00541     ///
00542     RetCode_t TouchPanelCalibrate(tpMatrix_t * matrix);
00543 
00544     /// Perform the touch panel calibration process.
00545     ///
00546     /// This method provides the easy "shortcut" to calibrating the touch panel.
00547     /// The process will automatically generate the calibration points, present
00548     /// the targets on-screen, detect the touches, compute the calibration
00549     /// matrix, and optionally provide the calibration matrix to the calling code
00550     /// for persistence in non-volatile memory.
00551     ///
00552     /// @param[in] msg is a text message to present on the screen during the
00553     ///             calibration process.
00554     /// @param[out] matrix is an optional parameter to hold the calibration matrix 
00555     ///             as a result of the calibration. This can be saved in  
00556     ///             non-volatile memory to recover the calibration after a power fail.
00557     /// @returns success/failure code. @see RetCode_t.
00558     ///
00559     RetCode_t TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix = NULL);
00560 
00561     /// Get the screen calibrated point of touch.
00562     ///
00563     /// This method determines if there is a touch and if so it will provide
00564     /// the screen-relative touch coordinates. This method can be used in
00565     /// a manner similar to Serial.readable(), to determine if there was a 
00566     /// touch and indicate that - but not care about the coordinates. Alternately,
00567     /// if a valid pointer to a point_t is provided, then if a touch is detected
00568     /// the point_t will be populated with data. 
00569     ///
00570     /// @code
00571     ///     Timer t;
00572     ///     t.start();
00573     ///     do {
00574     ///        point_t point = {0, 0};
00575     ///        if (display.TouchPanelReadable(&point)) {
00576     ///            display.pixel(point.x, point.y, Red);
00577     ///        }
00578     ///    } while (t.read_ms() < 30000);
00579     /// @endcode
00580     ///
00581     /// @param[out] touch is the touch point, if a touch is registered.
00582     /// @returns true if a touch was registered, and touch is updated.
00583     /// @returns false if no touch was detected, or if the calibration matrix is not defined.
00584     ///
00585     bool TouchPanelReadable(point_t * touch = NULL);
00586 
00587     /// Wait for a touch panel touch and return it.
00588     /// 
00589     /// This method is similar to Serial.getc() in that it will wait for a touch
00590     /// and then return. In order to extract the coordinates of the touch, a
00591     /// valid pointer to a point_t must be provided.
00592     ///
00593     /// @note There is no timeout on this function, so its use is not recommended.
00594     ///
00595     /// @code
00596     ///     Timer t;
00597     ///     t.start();
00598     ///     do {
00599     ///        point_t point = {0, 0};
00600     ///        display.TouchPanelGet(&point);
00601     ///        display.pixel(point.x, point.y, Red);
00602     ///    } while (t.read_ms() < 30000);
00603     /// @endcode
00604     ///
00605     /// @param[out] touch is the touch point, if a touch is registered.
00606     /// @returns true if a touch was registered, and touch is updated.
00607     /// @returns false if no touch was detected, or if the calibration matrix is not defined.
00608     ///
00609     bool TouchPanelGet(point_t * touch);
00610 
00611     /// Set the calibration matrix for the touch panel.
00612     ///
00613     /// This method is used to set the calibration matrix for the touch panel. After
00614     /// performing the calibration (@see TouchPanelComputeCalibration), the matrix can be stored.
00615     /// On a subsequence power cycle, the matrix may be restored from non-volatile and
00616     /// passed in to this method. It will then be held to perform the corrections when
00617     /// reading the touch panel point.
00618     ///
00619     /// @code
00620     /// FILE * fh = fopen("/local/tpmatrix.cfg", "r");
00621     /// if (fh) {
00622     ///     tpMatrix_t matrix;
00623     ///     if (fread(fh, &matrix, sizeof(tpMatrix_t))) {
00624     ///         lcd.TouchPanelSetMatrix(&matrix);
00625     ///     }
00626     ///     fclose(fh);
00627     /// }
00628     /// @endcode
00629     /// 
00630     /// @param[in] matrix is a pointer to the touch panel calibration matrix.
00631     /// @returns success/failure code. @see RetCode_t.
00632     ///
00633     RetCode_t TouchPanelSetMatrix(tpMatrix_t * matrix);
00634    
00635 #if 0
00636     /// Append interrupt handler for specific RA8875 interrupt source
00637     ///
00638     /// @param[in]    bISRType        Interrupt Source, should be:
00639     ///                                - RA8875_INT_KEYSCAN: KEYCAN interrupt
00640     ///                                - RA8875_INT_DMA: DMA interrupt
00641     ///                                - RA8875_INT_TP: Touch panel interrupt
00642     ///                                - RA8875_INT_BTE: BTE process complete interrupt
00643     ///                                - RA8875_INT_BTEMCU_FONTWR: Multi-purpose interrupt (see spec sheet)   
00644     /// @param[in]    fptr is a callback function to handle the interrupt event.
00645     /// @returns       none
00646     ///
00647     void AppendISR(uint8_t bISRType, void(*fptr)(void));
00648 
00649     /// Unappend interrupt handler for specific RA8875 interrupt source
00650     ///
00651     /// @param[in]    bISRType        Interrupt Source, should be:
00652     ///                                - RA8875_INT_KEYSCAN: KEYCAN interrupt
00653     ///                                - RA8875_INT_DMA: DMA interrupt
00654     ///                                - RA8875_INT_TP: Touch panel interrupt
00655     ///                                - RA8875_INT_BTE: BTE process complete interrupt
00656     ///                                - RA8875_INT_BTEMCU_FONTWR: Multi-purpose interrupt (see spec sheet)   
00657     /// @return       none
00658     ///
00659     void UnAppendISR(uint8_t bISRType);
00660 #endif
00661 
00662     /// Initialize the keypad interface on the RA8875 controller.
00663     ///
00664     /// Enables the keypad subsystem. It will scan the 4 x 5 matrix
00665     /// and make available key presses. 
00666     ///
00667     /// @note See section 5-13 of RAIO RA8875 data sheet for more details.
00668     /// @caution When using the display from buy-display.com, be sure that
00669     ///     the option for the keypad is configured on the hardware.
00670     ///
00671     /// All parameters are optional.
00672     /// @param[in] scanEnable when true, enables the key scan function (default: true).
00673     /// @param[in] longDetect when true, additionally enables the long key held detection (default: false).
00674     /// @param[in] sampleTime setting (range: 0 - 3, default: 0).
00675     /// @param[in] scanFrequency setting (range: 0 - 7, default: 0).
00676     /// @param[in] longTimeAdjustment (range: 0 - 3, default: 0).
00677     /// @param[in] interruptEnable when true, enables interrupts from keypress (default: false).
00678     /// @param[in] wakeupEnable when true, activates the wakeup function (default: false).
00679     ///
00680     /// @returns success/failure code. @see RetCode_t.
00681     ///
00682     RetCode_t  KeypadInit(bool scanEnable = true, bool longDetect = false, 
00683         uint8_t sampleTime = 0, uint8_t scanFrequency = 0, 
00684         uint8_t longTimeAdjustment = 0,
00685         bool interruptEnable = false, bool wakeupEnable = false);
00686 
00687     /// Create Key Code definitions for the key matrix.
00688     ///
00689     /// This API provides a table of 22 key-code assignments for the matrix of keys.
00690     /// This can be used to translate the keys 1 - 20 into some other value, as
00691     /// well as to communicate the "no key" (zero) and "error state" (21).
00692     ///
00693     /// In this way, a keypad could easily emulate a piece of a keyboard, transforming
00694     /// 0 - 20 into the values 0, '0', '1', '2', '3', '4', '5', '6', '7', '8',
00695     /// '9', '+', '-', '*' , '/', '=', '<bs>', '<cr>', and so on...
00696     ///
00697     /// @code
00698     /// //        Return Value by Row, Column   Example reassignment
00699     /// //    Column    0    1    2    3    4 
00700     /// //          +-------------------------+  +-------------------------+
00701     /// // Row   0  |   1    2    3    4    5 |  | '7'  '8'  '9'  ',' '<-' |
00702     /// //       1  |   6    7    8    9   10 |  | '4'  '5'  '6'  '/'  '-' |
00703     /// //       2  |  11   12   13   14   15 |  | '1'  '2'  '3'  '*'  '+' |
00704     /// //       3  |  16   17   18   19   20 |  | '0'  '.'  '('  ')' '\n' |
00705     /// //          +-------------------------+  +-------------------------+
00706     /// //     Return value  0 = No Key pressed
00707     /// //     Return value 21 = Error
00708     /// const uint8_t CodeList[22] = 
00709     ///     {0, '7', '8', '9', ',', '\h', 
00710     ///         '4', '5', '6', '/', '-',
00711     ///         '1', '2', '3', '*', '+',
00712     ///         '0', '.', '(', ')', '\n', 
00713     ///         '\x1b'};
00714     ///     lcd.SetKeyMap(CodeList);
00715     /// @endcode
00716     /// 
00717     /// @param[in] CodeList is a pointer to an always available byte-array 
00718     ///             where the first 22 bytes are used as the transformation 
00719     ///             from raw code to your reassigned value.
00720     ///            If CodeList is NULL, the original raw value key map is
00721     ///             restored.
00722     /// @returns noerror.
00723     ///
00724     RetCode_t SetKeyMap(const uint8_t * CodeList = NULL);
00725 
00726     /// Determine if a key has been hit
00727     ///
00728     /// @returns true if a key has been hit
00729     ///
00730     bool readable();
00731 
00732     /// Blocking read of the keypad.
00733     ///
00734     /// @caution: This is a blocking read, so it is important to first call _kbhit()
00735     ///         to avoid hanging your processes.
00736     ///
00737     /// A keypad connected to the RA8875 is connected in a matrix of 4 rows and 5 columns.
00738     /// When pressed, this method will return a code in the range of 1 through 20, reserving
00739     /// the value 0 to indicate that no key is pressed.
00740     ///
00741     /// Additionally, if configured to detect a "long press", bit 7 will be set to indicate
00742     /// this. In this situation, first a "normal press" would be detected and signaled and
00743     /// soon after that a "long press" of the same key would be detected and communicated.
00744     ///
00745     /// @return 8-bit where bit 7 indicates a long press. The remaining bits indicate the
00746     ///     keypress using 0 = no key pressed, 1 - 20 = the key pressed.
00747     ///
00748     uint8_t getc();
00749     
00750     /// Write a command to the display with a word of data.
00751     ///
00752     /// This is a high level command, and may invoke several primitives.
00753     ///
00754     /// @param[in] command is the command to write.
00755     /// @param[in] data is data to be written to the command register.
00756     /// @returns success/failure code. @see RetCode_t.
00757     ///
00758     RetCode_t WriteCommandW(uint8_t command, uint16_t data);
00759 
00760     /// Write a command to the display
00761     ///
00762     /// This is a high level command, and may invoke several primitives.
00763     ///
00764     /// @param[in] command is the command to write.
00765     /// @param[in] data is optional data to be written to the command register
00766     ///     and only occurs if the data is in the range [0 - 0xFF].
00767     /// @returns success/failure code. @see RetCode_t.
00768     ///
00769     virtual RetCode_t WriteCommand(unsigned char command, unsigned int data = 0xFFFF);
00770     
00771     /// Write a data word to the display
00772     ///
00773     /// This is a high level command, and may invoke several primitives.
00774     ///
00775     /// @param[in] data is the data to write.
00776     /// @returns success/failure code. @see RetCode_t.
00777     ///
00778     RetCode_t WriteDataW(uint16_t data);
00779     
00780     /// Write a data byte to the display
00781     ///
00782     /// This is a high level command, and may invoke several primitives.
00783     ///
00784     /// @param[in] data is the data to write.
00785     /// @returns success/failure code. @see RetCode_t.
00786     ///
00787     virtual RetCode_t WriteData(unsigned char data);
00788     
00789     /// Read a command register
00790     ///
00791     /// @param[in] command is the command register to read.
00792     /// @returns the value read from the register.
00793     ///
00794     unsigned char ReadCommand(unsigned char command);
00795     
00796     /// Read a data byte from the display
00797     ///
00798     /// This is a high level command, and may invoke several primitives.
00799     ///
00800     /// @returns data that was read.
00801     ///
00802     unsigned char ReadData(void);
00803     
00804     /// Read a word from the display
00805     ///
00806     /// This is a high level command, and may invoke several primitives.
00807     ///
00808     /// @returns data that was read.
00809     ///
00810     uint16_t ReadDataW(void);
00811 
00812     /// Read the display status
00813     ///
00814     /// This is a high level command, and may invoke several primitives.
00815     ///
00816     /// @returns data that was read.
00817     ///
00818     unsigned char ReadStatus(void);
00819 
00820     /// get the width in pixels of the currently active font
00821     ///
00822     /// @returns font width in pixels.
00823     ///    
00824     dim_t fontwidth(void);
00825     
00826     /// get the height in pixels of the currently active font
00827     ///
00828     /// @returns font height in pixels.
00829     ///    
00830     dim_t fontheight(void);
00831     
00832     /// get the number of colums based on the currently active font
00833     ///
00834     /// @returns number of columns.
00835     ///    
00836     virtual int columns(void);
00837 
00838     /// get the number of rows based on the currently active font
00839     ///
00840     /// @returns number of rows.
00841     ///    
00842     virtual int rows(void);
00843 
00844     /// get the screen width in pixels
00845     ///
00846     /// @returns screen width in pixels.
00847     ///
00848     virtual dim_t width(void);
00849 
00850     /// get the screen height in pixels
00851     ///
00852     /// @returns screen height in pixels.
00853     ///
00854     virtual dim_t height(void);
00855 
00856     /// get the color depth in bits per pixel.
00857     ///
00858     /// @returns 8 or 16 only.
00859     ///
00860     virtual dim_t color_bpp(void);
00861 
00862     /// Set cursor position based on the current font size.
00863     /// 
00864     /// @param[in] column is the horizontal position in character positions
00865     /// @param[in] row is the vertical position in character positions
00866     /// @returns success/failure code. @see RetCode_t.
00867     ///
00868     virtual RetCode_t locate(textloc_t column, textloc_t row);
00869 
00870     /// Prepare the controller to write text to the screen by positioning
00871     /// the cursor.
00872     ///
00873     /// @code
00874     ///     lcd.SetTextCursor(100, 25);
00875     ///     lcd.puts("Hello");
00876     /// @endcode
00877     ///
00878     /// @param[in] x is the horizontal position in pixels (from the left edge)
00879     /// @param[in] y is the vertical position in pixels (from the top edge)
00880     /// @returns success/failure code. @see RetCode_t.
00881     ///
00882     RetCode_t SetTextCursor(loc_t x, loc_t y);
00883 
00884     /// Get the current cursor position in pixels.
00885     ///
00886     /// @code
00887     ///     point_t point = GetTextCursor();
00888     ///     if (point.x > 100 && point.y > 150)
00889     ///         //...
00890     /// @endcode
00891     ///
00892     /// @returns cursor position.
00893     ///
00894     point_t GetTextCursor(void);
00895     
00896     /// Get the current cursor horizontal position in pixels.
00897     ///
00898     /// @returns cursor position horizontal offset.
00899     ///
00900     loc_t GetTextCursor_X(void);
00901 
00902     /// Get the current cursor vertical position in pixels.
00903     ///
00904     /// @returns cursor position vertical offset.
00905     ///
00906     loc_t GetTextCursor_Y(void);
00907 
00908     /// Configure additional Cursor Control settings.
00909     ///
00910     /// This API lets you modify other cursor control settings; 
00911     /// Cursor visible/hidden, Cursor blink/normal, 
00912     /// Cursor I-Beam/underscore/box.
00913     ///
00914     /// @param[in] cursor can be set to NOCURSOR (default), IBEAM,
00915     ///         UNDER, or BLOCK.
00916     /// @param[in] blink can be set to true or false (default false)
00917     /// @returns success/failure code. @see RetCode_t
00918     ///
00919     RetCode_t SetTextCursorControl(cursor_t cursor = NOCURSOR, bool blink = false);
00920     
00921     /// Select the ISO 8859-X font to use next.
00922     ///
00923     /// Supported fonts: ISO 8859-1, -2, -3, -4
00924     ///
00925     /// @param[in] font selects the font for the subsequent text rendering.
00926     ///
00927     /// @note if either hScale or vScale is outside of its permitted range,
00928     ///     the command is not executed.
00929     /// @returns success/failure code. @see RetCode_t.
00930     ///
00931     RetCode_t SetTextFont(font_t font = ISO8859_1);
00932     
00933     /// Control the font behavior.
00934     ///
00935     /// This command lets you make several modifications to any text that
00936     /// will be written to the screen.
00937     ///
00938     /// Options can be combined:
00939     /// Default:
00940     /// @li Full alignment disabled, 
00941     /// @li Font with Background color, 
00942     /// @li Font in normal orientiation,
00943     /// @li Horizontal scale x 1
00944     /// @li Vertical scale x 1
00945     /// @li alignment
00946     /// 
00947     /// @param[in] fillit defaults to FILL, but can be NOFILL
00948     /// @param[in] angle defaults to normal, but can be rotated
00949     /// @param[in] hScale defaults to 1, but can be 1, 2, 3, or 4,
00950     ///     and scales the font size by this amount.
00951     /// @param[in] vScale defaults to 1, but can be 1, 2, 3, or 4,
00952     ///     and scales the font size by this amount.
00953     /// @param[in] alignment defaults to align_none, but can be
00954     ///     align_full.
00955     /// 
00956     /// @note if either hScale or vScale is outside of its permitted range,
00957     ///     the command is not executed.
00958     /// @returns success/failure code. @see RetCode_t.
00959     ///
00960     RetCode_t SetTextFontControl(fill_t fillit = FILL, 
00961         font_angle_t angle = normal, 
00962         HorizontalScale hScale = 1, 
00963         VerticalScale vScale = 1, 
00964         alignment_t alignment = align_none);
00965     
00966     /// Control the font size
00967     ///
00968     /// This command lets you set the font enlargement for both horizontal
00969     /// and vertical, independent of the rotation, background, and 
00970     /// alignment. @see SetTextFontControl.
00971     ///
00972     /// @param[in] hScale defaults to 1, but can be 1, 2, 3, or 4,
00973     ///     and scales the font size by this amount.
00974     /// @param[in] vScale is an optional parameter that defaults to the hScale value, 
00975     ///     but can be 1, 2, 3, or 4, and scales the font size by this amount.
00976     ///
00977     /// @code
00978     ///     lcd.SetTextFontSize(2);     // Set the font to 2x normal size
00979     ///     lcd.puts("Two times");
00980     ///     lcd.SetTextFontSize(2,3);   // Set the font to 2x Width and 3x Height
00981     ///     lcd.puts("2*2 3*h");
00982     ///     lcd.SetTextFontSize();      // Restore to normal size in both dimensions
00983     ///     lcd.puts("normal");
00984     /// @endcode
00985     ///
00986     /// @note if either hScale or vScale is outside of its permitted range,
00987     ///     the command is not executed.
00988     /// @returns success/failure code. @see RetCode_t.
00989     ///
00990     RetCode_t SetTextFontSize(HorizontalScale hScale = 1, VerticalScale vScale = -1);
00991     
00992     /// put a character on the screen.
00993     ///
00994     /// @param[in] c is the character.
00995     /// @returns the character, or EOF if there is an error.
00996     ///
00997     virtual int _putc(int c);
00998 
00999     /// Write string of text to the display
01000     ///
01001     /// @code
01002     ///     lcd.puts("Test STring");
01003     /// @endcode
01004     ///
01005     /// @param[in] string is the null terminated string to send to the display.
01006     ///
01007     void puts(const char * string);
01008     
01009     /// Write string of text to the display at the specified location.
01010     ///
01011     /// @code
01012     ///     lcd.puts(10,25, "Test STring");
01013     /// @endcode
01014     ///
01015     /// @param[in] x is the horizontal position in pixels (from the left edge)
01016     /// @param[in] y is the vertical position in pixels (from the top edge)
01017     /// @param[in] string is the null terminated string to send to the display.
01018     ///
01019     void puts(loc_t x, loc_t y, const char * string);
01020     
01021     /// Prepare the controller to write binary data to the screen by positioning
01022     /// the memory cursor.
01023     ///
01024     /// @param[in] x is the horizontal position in pixels (from the left edge)
01025     /// @param[in] y is the vertical position in pixels (from the top edge)
01026     /// @returns success/failure code. @see RetCode_t.
01027     ///
01028     virtual RetCode_t SetGraphicsCursor(loc_t x, loc_t y);
01029     
01030     /// Prepare the controller to read binary data from the screen by positioning
01031     /// the memory read cursor.
01032     ///
01033     /// @param[in] x is the horizontal position in pixels (from the left edge)
01034     /// @param[in] y is the vertical position in pixels (from the top edge)
01035     /// @returns success/failure code. @see RetCode_t.
01036     ///
01037     virtual RetCode_t SetGraphicsCursorRead(loc_t x, loc_t y);
01038     
01039     /// Set the window, which controls where items are written to the screen.
01040     ///
01041     /// When something hits the window width, it wraps back to the left side
01042     /// and down a row. If the initial write is outside the window, it will
01043     /// be captured into the window when it crosses a boundary.
01044     ///
01045     /// @code
01046     ///     lcd.window(10,10, 80,80);
01047     ///     lcd.puts("012345678901234567890123456789012345678901234567890");
01048     /// @endcode
01049     ///
01050     /// @param[in] x is the left edge in pixels.
01051     /// @param[in] y is the top edge in pixels.
01052     /// @param[in] width is the window width in pixels.
01053     /// @param[in] height is the window height in pixels.
01054     /// @returns success/failure code. @see RetCode_t.
01055     ///
01056     virtual RetCode_t window(loc_t x, loc_t y, dim_t width, dim_t height);
01057     
01058     /// Clear either the specified layer, or the active layer.
01059     ///
01060     /// The behavior is to clear the whole screen for the specified
01061     /// layer. When not specified, the active drawing layer is cleared.
01062     /// This command can also be used to specifically clear either,
01063     /// or both layers. @see clsw().
01064     ///
01065     /// @code
01066     ///     lcd.cls();
01067     /// @endcode
01068     ///
01069     /// @param[in] layers is optional. If not provided, the active layer
01070     ///     is cleared. If bit 0 is set, layer 0 is cleared, if bit
01071     ///     1 is set, layer 1 is cleared. If both are set, both layers
01072     ///     are cleared. Any other value does not cause an action.
01073     ///     
01074     /// @returns success/failure code. @see RetCode_t.
01075     ///
01076     virtual RetCode_t cls(uint16_t layers = 0);
01077     
01078     /// Clear the screen, or clear only the active window.
01079     ///
01080     /// The default behavior is to clear the whole screen. With the optional 
01081     /// parameter, the action can be restricted to the active window, which
01082     /// can be set with the @see window method.
01083     ///
01084     /// @code
01085     ///     lcd.window(20,20, 40,10);
01086     ///     lcd.clsw();
01087     /// @endcode
01088     ///
01089     /// @param[in] region is an optional parameter that defaults to FULLWINDOW
01090     ///         or may be set to ACTIVEWINDOW.
01091     /// @returns success/failure code. @see RetCode_t.
01092     ///
01093     RetCode_t clsw(RA8875::Region_t region = FULLWINDOW);
01094 
01095     /// Set the background color.
01096     ///
01097     /// @param[in] color is expressed in 16-bit format.
01098     /// @returns success/failure code. @see RetCode_t.
01099     ///
01100     virtual RetCode_t background(color_t color);
01101     
01102     /// Set the background color.
01103     ///
01104     /// @param[in] r is the red element of the color.
01105     /// @param[in] g is the green element of the color.
01106     /// @param[in] b is the blue element of the color.
01107     /// @returns success/failure code. @see RetCode_t.
01108     ///
01109     virtual RetCode_t background(unsigned char r, unsigned char g, unsigned char b);
01110     
01111     /// Set the foreground color.
01112     ///
01113     /// @param[in] color is expressed in 16-bit format.
01114     /// @returns success/failure code. @see RetCode_t.
01115     ///
01116     virtual RetCode_t foreground(color_t color);
01117     
01118     /// Set the foreground color.
01119     ///
01120     /// @param[in] r is the red element of the color.
01121     /// @param[in] g is the green element of the color.
01122     /// @param[in] b is the blue element of the color.
01123     /// @returns success/failure code. @see RetCode_t.
01124     ///
01125     virtual RetCode_t foreground(unsigned char r, unsigned char g, unsigned char b);
01126     
01127     /// Get the current foreground color value.
01128     ///
01129     /// @returns the current foreground color.
01130     ///
01131     color_t GetForeColor(void);
01132         
01133     /// Draw a pixel in the specified color.
01134     ///
01135     /// @note Unlike many other operations, this does not
01136     ///         set the forecolor!
01137     ///
01138     /// @param[in] x is the horizontal offset to this pixel.
01139     /// @param[in] y is the vertical offset to this pixel.
01140     /// @param[in] color defines the color for the pixel.
01141     /// @returns success/failure code. @see RetCode_t.
01142     ///
01143     virtual RetCode_t pixel(loc_t x, loc_t y, color_t color);
01144     
01145     /// Draw a pixel in the current foreground color.
01146     ///
01147     /// @param[in] x is the horizontal offset to this pixel.
01148     /// @param[in] y is the veritical offset to this pixel.
01149     /// @returns success/failure code. @see RetCode_t.
01150     ///
01151     virtual RetCode_t pixel(loc_t x, loc_t y);
01152     
01153     /// Get a pixel from the display.
01154     ///
01155     /// @param[in] x is the horizontal offset to this pixel.
01156     /// @param[in] y is the vertical offset to this pixel.
01157     /// @returns the pixel. see @color_t
01158     ///
01159     virtual color_t getPixel(loc_t x, loc_t y);
01160     
01161     /// Write a stream of pixels to the display.
01162     ///
01163     /// @param[in] p is a pointer to a color_t array to write.
01164     /// @param[in] count is the number of pixels to write.
01165     /// @param[in] x is the horizontal position on the display.
01166     /// @param[in] y is the vertical position on the display.
01167     /// @returns success/failure code. @see RetCode_t.
01168     ///
01169     virtual RetCode_t pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y);
01170     
01171     /// Get a stream of pixels from the display.
01172     ///
01173     /// @param[in] p is a pointer to a color_t array to accept the stream.
01174     /// @param[in] count is the number of pixels to read.
01175     /// @param[in] x is the horizontal offset to this pixel.
01176     /// @param[in] y is the vertical offset to this pixel.
01177     /// @returns success/failure code. @see RetCode_t.
01178     ///
01179     virtual RetCode_t getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y);
01180     
01181     /// Draw a line in the specified color
01182     ///
01183     /// @note As a side effect, this changes the current
01184     ///     foreground color for subsequent operations.
01185     ///
01186     /// @param[in] x1 is the horizontal start of the line.
01187     /// @param[in] y1 is the vertical start of the line.
01188     /// @param[in] x2 is the horizontal end of the line.
01189     /// @param[in] y2 is the vertical end of the line.
01190     /// @param[in] color defines the foreground color.
01191     /// @returns success/failure code. @see RetCode_t.
01192     ///
01193     RetCode_t line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color);
01194 
01195     /// Draw a line
01196     ///
01197     /// Draws a line using the foreground color setting.
01198     ///
01199     /// @param[in] x1 is the horizontal start of the line.
01200     /// @param[in] y1 is the vertical start of the line.
01201     /// @param[in] x2 is the horizontal end of the line.
01202     /// @param[in] y2 is the vertical end of the line.
01203     /// @returns success/failure code. @see RetCode_t.
01204     ///
01205     RetCode_t line(loc_t x1, loc_t y1, loc_t x2, loc_t y2);
01206 
01207     /// Draw a rectangle in the specified color
01208     ///
01209     /// @note As a side effect, this changes the current
01210     ///     foreground color for subsequent operations.
01211     ///
01212     /// @param[in] rect defines the rectangle.
01213     /// @param[in] color defines the foreground color.
01214     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01215     /// @returns success/failure code. @see RetCode_t.
01216     ///
01217     RetCode_t rect(rect_t rect, color_t color, fill_t fillit);
01218     
01219      /// Draw a filled rectangle in the specified color
01220     ///
01221     /// @note As a side effect, this changes the current
01222     ///     foreground color for subsequent operations.
01223     ///
01224     /// @param[in] rect defines the rectangle.
01225     /// @param[in] color defines the foreground color.
01226     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01227     /// @returns success/failure code. @see RetCode_t.
01228     ///
01229     RetCode_t fillrect(rect_t rect, color_t color, fill_t fillit = FILL);
01230 
01231     /// Draw a rectangle in the specified color
01232     ///
01233     /// @note As a side effect, this changes the current
01234     ///     foreground color for subsequent operations.
01235     ///
01236     /// @param[in] x1 is the horizontal start of the line.
01237     /// @param[in] y1 is the vertical start of the line.
01238     /// @param[in] x2 is the horizontal end of the line.
01239     /// @param[in] y2 is the vertical end of the line.
01240     /// @param[in] color defines the foreground color.
01241     /// @param[in] fillit is optional to FILL the rectangle. default is FILL.
01242     /// @returns success/failure code. @see RetCode_t.
01243     ///
01244     RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01245         color_t color, fill_t fillit = NOFILL);
01246 
01247     /// Draw a filled rectangle in the specified color
01248     ///
01249     /// @note As a side effect, this changes the current
01250     ///     foreground color for subsequent operations.
01251     ///
01252     /// @param[in] x1 is the horizontal start of the line.
01253     /// @param[in] y1 is the vertical start of the line.
01254     /// @param[in] x2 is the horizontal end of the line.
01255     /// @param[in] y2 is the vertical end of the line.
01256     /// @param[in] color defines the foreground color.
01257     /// @param[in] fillit is optional to NOFILL the rectangle. default is FILL.
01258     /// @returns success/failure code. @see RetCode_t.
01259     ///
01260     virtual RetCode_t fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01261         color_t color, fill_t fillit = FILL);
01262 
01263     /// Draw a rectangle
01264     ///
01265     /// Draws a rectangle using the foreground color setting.
01266     ///
01267     /// @param[in] x1 is the horizontal start of the line.
01268     /// @param[in] y1 is the vertical start of the line.
01269     /// @param[in] x2 is the horizontal end of the line.
01270     /// @param[in] y2 is the vertical end of the line.
01271     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01272     /// @returns success/failure code. @see RetCode_t.
01273     ///
01274     RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01275         fill_t fillit = NOFILL);
01276 
01277     /// Draw a filled rectangle with rounded corners using the specified color.
01278     ///
01279     /// This draws a rounded rectangle. A numbers of checks are made on the values,
01280     /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2),
01281     /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are
01282     /// > 1/2 the length of that side (width or height), an error value is returned.
01283     ///
01284     /// @note As a side effect, this changes the current
01285     ///     foreground color for subsequent operations.
01286     ///
01287     /// @param[in] x1 is the horizontal start of the line and must be <= x2.
01288     /// @param[in] y1 is the vertical start of the line and must be <= y2.
01289     /// @param[in] x2 is the horizontal end of the line and must be >= x1.
01290     /// @param[in] y2 is the vertical end of the line and must be >= y1.
01291     /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care
01292     ///         that this value < 1/2 the width of the rectangle, or bad_parameter 
01293     ///         is returned.
01294     /// @param[in] radius2 defines the vertical radius of the curved corner. Take care
01295     ///         that this value < 1/2 the height of the rectangle, or bad_parameter 
01296     ///         is returned.
01297     /// @param[in] color defines the foreground color.
01298     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01299     /// @returns success/failure code. @see RetCode_t.
01300     ///
01301     RetCode_t fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01302         dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL);
01303 
01304     /// Draw a rectangle with rounded corners using the specified color.
01305     ///
01306     /// This draws a rounded rectangle. A numbers of checks are made on the values,
01307     /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2),
01308     /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are
01309     /// > 1/2 the length of that side (width or height), an error value is returned.
01310     ///
01311     /// @note As a side effect, this changes the current
01312     ///     foreground color for subsequent operations.
01313     ///
01314     /// @param[in] x1 is the horizontal start of the line and must be <= x2.
01315     /// @param[in] y1 is the vertical start of the line and must be <= y2.
01316     /// @param[in] x2 is the horizontal end of the line and must be >= x1.
01317     /// @param[in] y2 is the vertical end of the line and must be >= y1.
01318     /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care
01319     ///         that this value < 1/2 the width of the rectangle, or bad_parameter 
01320     ///         is returned.
01321     /// @param[in] radius2 defines the vertical radius of the curved corner. Take care
01322     ///         that this value < 1/2 the height of the rectangle, or bad_parameter 
01323     ///         is returned.
01324     /// @param[in] color defines the foreground color.
01325     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01326     /// @returns success/failure code. @see RetCode_t.
01327     ///
01328     RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01329         dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL);
01330 
01331     /// Draw a rectangle with rounded corners.
01332     ///
01333     /// This draws a rounded rectangle. A numbers of checks are made on the values,
01334     /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2),
01335     /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are
01336     /// > 1/2 the length of that side (width or height), an error value is returned.
01337     ///
01338     /// @param[in] x1 is the horizontal start of the line and must be <= x2.
01339     /// @param[in] y1 is the vertical start of the line and must be <= y2.
01340     /// @param[in] x2 is the horizontal end of the line and must be >= x1.
01341     /// @param[in] y2 is the vertical end of the line and must be >= y1.
01342     /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care
01343     ///         that this value < 1/2 the width of the rectangle, or bad_parameter 
01344     ///         is returned.
01345     /// @param[in] radius2 defines the vertical radius of the curved corner. Take care
01346     ///         that this value < 1/2 the height of the rectangle, or bad_parameter 
01347     ///         is returned.
01348     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01349     /// @returns success/failure code. @see RetCode_t.
01350     ///
01351     RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01352         dim_t radius1, dim_t radius2, fill_t fillit = NOFILL);
01353 
01354     /// Draw a triangle in the specified color.
01355     ///
01356     /// @note As a side effect, this changes the current
01357     ///     foreground color for subsequent operations.
01358     ///
01359     /// @param[in] x1 is the horizontal for point 1.
01360     /// @param[in] y1 is the vertical for point 1. 
01361     /// @param[in] x2 is the horizontal for point 2.
01362     /// @param[in] y2 is the vertical for point 2.
01363     /// @param[in] x3 is the horizontal for point 3.
01364     /// @param[in] y3 is the vertical for point 3.
01365     /// @param[in] color defines the foreground color.
01366     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01367     /// @returns success/failure code. @see RetCode_t.
01368     ///
01369     RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01370         loc_t x3, loc_t y3, color_t color, fill_t fillit = NOFILL);
01371     
01372     /// Draw a filled triangle in the specified color.
01373     ///
01374     /// @note As a side effect, this changes the current
01375     ///     foreground color for subsequent operations.
01376     ///
01377     /// @param[in] x1 is the horizontal for point 1.
01378     /// @param[in] y1 is the vertical for point 1.
01379     /// @param[in] x2 is the horizontal for point 2.
01380     /// @param[in] y2 is the vertical for point 2.
01381     /// @param[in] x3 is the horizontal for point 3.
01382     /// @param[in] y3 is the vertical for point 3.
01383     /// @param[in] color defines the foreground color.
01384     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01385     /// @returns success/failure code. @see RetCode_t.
01386     ///
01387     RetCode_t filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01388         loc_t x3, loc_t y3, color_t color, fill_t fillit = FILL);
01389 
01390     /// Draw a triangle
01391     ///
01392     /// Draws a triangle using the foreground color setting.
01393     ///
01394     /// @param[in] x1 is the horizontal for point 1.
01395     /// @param[in] y1 is the vertical for point 1.
01396     /// @param[in] x2 is the horizontal for point 2.
01397     /// @param[in] y2 is the vertical for point 2.
01398     /// @param[in] x3 is the horizontal for point 3.
01399     /// @param[in] y3 is the vertical for point 3.
01400     /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL.
01401     /// @returns success/failure code. @see RetCode_t.
01402     ///
01403     RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
01404         loc_t x3, loc_t y3, fill_t fillit = NOFILL);
01405     
01406     /// Draw a circle using the specified color.
01407     ///
01408     /// @note As a side effect, this changes the current
01409     ///     foreground color for subsequent operations.
01410     ///
01411     /// @param[in] x is the horizontal center of the circle.
01412     /// @param[in] y is the vertical center of the circle.
01413     /// @param[in] radius defines the size of the circle.
01414     /// @param[in] color defines the foreground color.
01415     /// @returns success/failure code. @see RetCode_t.
01416     ///
01417     RetCode_t circle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit = NOFILL);
01418 
01419     /// Draw a filled circle using the specified color.
01420     ///
01421     /// @note As a side effect, this changes the current
01422     ///     foreground color for subsequent operations.
01423     ///
01424     /// @param[in] x is the horizontal center of the circle.
01425     /// @param[in] y is the vertical center of the circle.
01426     /// @param[in] radius defines the size of the circle.
01427     /// @param[in] color defines the foreground color.
01428     /// @returns success/failure code. @see RetCode_t.
01429     ///
01430     RetCode_t fillcircle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit = FILL);
01431 
01432     /// Draw a circle.
01433     ///
01434     /// Draws a circle using the foreground color setting.
01435     ///
01436     /// @param[in] x is the horizontal center of the circle.
01437     /// @param[in] y is the vertical center of the circle.
01438     /// @param[in] radius defines the size of the circle.
01439     /// @returns success/failure code. @see RetCode_t.
01440     ///
01441     RetCode_t circle(loc_t x, loc_t y, dim_t radius, fill_t fillit = NOFILL);
01442 
01443     /// Draw an Ellipse using the specified color
01444     ///
01445     /// @note As a side effect, this changes the current
01446     ///     foreground color for subsequent operations.
01447     ///
01448     /// @param[in] x is the horizontal center of the ellipse.
01449     /// @param[in] y is the vertical center of the ellipse.
01450     /// @param[in] radius1 defines the horizontal radius of the ellipse.
01451     /// @param[in] radius2 defines the vertical radius of the ellipse.
01452     /// @param[in] color defines the foreground color.
01453     /// @param[in] fillit defines whether the circle is filled or not.
01454     /// @returns success/failure code. @see RetCode_t.
01455     ///
01456     RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, 
01457         color_t color, fill_t fillit = NOFILL);
01458 
01459     /// Draw a filled Ellipse using the specified color
01460     ///
01461     /// @note As a side effect, this changes the current
01462     ///     foreground color for subsequent operations.
01463     ///
01464     /// @param[in] x is the horizontal center of the ellipse.
01465     /// @param[in] y is the vertical center of the ellipse.
01466     /// @param[in] radius1 defines the horizontal radius of the ellipse.
01467     /// @param[in] radius2 defines the vertical radius of the ellipse.
01468     /// @param[in] color defines the foreground color.
01469     /// @param[in] fillit defines whether the circle is filled or not.
01470     /// @returns success/failure code. @see RetCode_t.
01471     ///
01472     RetCode_t fillellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, 
01473         color_t color, fill_t fillit = FILL);
01474 
01475     /// Draw an Ellipse
01476     ///
01477     /// Draws it using the foreground color setting.
01478     ///
01479     /// @param[in] x is the horizontal center of the ellipse.
01480     /// @param[in] y is the vertical center of the ellipse.
01481     /// @param[in] radius1 defines the horizontal radius of the ellipse.
01482     /// @param[in] radius2 defines the vertical radius of the ellipse.
01483     /// @param[in] fillit defines whether the circle is filled or not.
01484     /// @returns success/failure code. @see RetCode_t.
01485     ///
01486     RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit = NOFILL);
01487     
01488     /// Control display power
01489     ///
01490     /// @param[in] on when set to true will turn on the display, when false it is turned off.
01491     /// @returns success/failure code. @see RetCode_t.
01492     ///
01493     RetCode_t Power(bool on);
01494 
01495     /// Reset the display controller via the Software Reset interface.
01496     ///
01497     /// @returns success/failure code. @see RetCode_t.
01498     ///
01499     RetCode_t Reset(void);
01500     
01501     /// Set backlight brightness.
01502     ///
01503     /// When the built-in PWM is used to control the backlight, this 
01504     /// API can be used to set the brightness.
01505     /// 
01506     /// @param[in] brightness ranges from 0 (off) to 255 (full on)
01507     /// @returns success/failure code. @see RetCode_t.
01508     ///
01509     RetCode_t Backlight_u8(unsigned char brightness);
01510     
01511     /// Set backlight brightness.
01512     ///
01513     /// When the built-in PWM is used to control the backlight, this 
01514     /// API can be used to set the brightness.
01515     /// 
01516     /// @param[in] brightness ranges from 0.0 (off) to 1.0 (full on)
01517     /// @returns success/failure code. @see RetCode_t.
01518     ///
01519     RetCode_t Backlight(float brightness);
01520 
01521     /// Select a bitmap font (provided by the user) for all subsequent text.
01522     ///
01523     /// @note Tool to create the fonts is accessible from its creator
01524     ///     available at http://www.mikroe.com. 
01525     ///     Change the data to an array of type char[].
01526     ///
01527     /// @param[in] font is a pointer to a specially formed font array.
01528     ///     This special font array has a 4-byte header, followed by 
01529     ///     the data:
01530     ///   - the number of bytes per char
01531     ///   - the vertical size in pixels for each character
01532     ///   - the horizontal size in pixels for each character
01533     ///   - the number of bytes per vertical line (width of the array)
01534     /// @returns error code.
01535     ///
01536     virtual RetCode_t set_font(const unsigned char * font = NULL);
01537 
01538     /// Get the RGB value for a DOS color.
01539     ///
01540     /// @param[in] i is the color, in the range 0 to 15;
01541     /// @returns the RGB color of the selected index, or 0 
01542     ///     if the index is out of bounds.
01543     ///
01544     color_t DOSColor(int i);
01545 
01546     /// Get the color name (string) for a DOS color.
01547     ///
01548     /// @param[in] i is the color, in the range 0 to 15;
01549     /// @returns a pointer to a string with the color name,
01550     ///     or NULL if the index is out of bounds.
01551     /// 
01552     const char * DOSColorNames(int i);
01553 
01554     /// Advanced method indicating the start of a graphics stream.
01555     ///
01556     /// This is called prior to a stream of pixel data being sent.
01557     /// This may cause register configuration changes in the derived
01558     /// class in order to prepare the hardware to accept the streaming
01559     /// data.
01560     ///
01561     /// Following this command, a series of @see _putp() commands can
01562     /// be used to send individual pixels to the screen.
01563     ///
01564     /// To conclude the graphics stream, @see _EndGraphicsStream should
01565     /// be callled.
01566     ///
01567     /// @returns error code.
01568     ///
01569     virtual RetCode_t _StartGraphicsStream(void);
01570     
01571     /// Advanced method to put a single color pixel to the screen.
01572     ///
01573     /// This method may be called as many times as necessary after 
01574     /// @see _StartGraphicsStream() is called, and it should be followed 
01575     /// by _EndGraphicsStream.
01576     ///
01577     /// @param[in] pixel is a color value to be put on the screen.
01578     /// @returns error code.
01579     ///
01580     virtual RetCode_t _putp(color_t pixel);
01581     
01582     /// Advanced method indicating the end of a graphics stream.
01583     ///
01584     /// This is called to conclude a stream of pixel data that was sent.
01585     /// This may cause register configuration changes in the derived
01586     /// class in order to stop the hardware from accept the streaming
01587     /// data.
01588     ///
01589     /// @returns error code.
01590     ///
01591     virtual RetCode_t _EndGraphicsStream(void);
01592 
01593     /// Set the SPI port frequency (in Hz).
01594     ///
01595     /// This uses the mbed SPI driver, and is therefore dependent on
01596     /// its capabilities. The RA8875 can accept writes via SPI faster
01597     /// than a read can be performed. The frequency set by this API
01598     /// is for the SPI writes. It will automatically reduce the SPI
01599     /// clock rate when a read is performed, and restore it for the 
01600     /// next write. Alternately, the 2nd parameters permits setting
01601     /// the read speed rather than letting it compute it automatically.
01602     ///
01603     /// @note The primary effect of this is to recover more CPU cycles
01604     ///     for your application code. Keep in mind that when more than
01605     ///     one command is sent to the display controller, that it
01606     ///     will wait for the controller to finish the prior command.
01607     ///     In this case, the performance is limited by the RA8875.
01608     ///
01609     /// @param[in] Hz is the frequency in Hz, tested range includes the
01610     ///     range from 1,000,000 (1MHz) to 10,000,000 (10 MHz). Values
01611     ///     outside this range will be accepted, but operation may
01612     ///     be unreliable. This depends partially on your hardware design
01613     ///     and the wires connecting the display module.
01614     ///     The default value is 5,000,000, which should work for most
01615     ///     applications as a starting point.
01616     /// @param[in] Hz2 is an optional parameter and will set the read
01617     ///     speed independently of the write speed.
01618     /// @returns success/failure code. @see RetCode_t.
01619     ///
01620     RetCode_t frequency(unsigned long Hz = RA8875_DEFAULT_SPI_FREQ, unsigned long Hz2 = 0);
01621     
01622     /// This method captures the specified area as a 24-bit bitmap file.
01623     ///
01624     /// Even though this is a 16-bit display, the stored image is in
01625     /// 24-bit format.
01626     ///
01627     /// This method will interrogate the current display setting and
01628     /// create a bitmap based on those settings. For instance, if 
01629     /// only layer 1 is visible, then the bitmap is only layer 1. However,
01630     /// if there is some other operation in effect (transparent mode).
01631     ///
01632     /// @param[in] x is the left edge of the region to capture
01633     /// @param[in] y is the top edge of the region to capture
01634     /// @param[in] w is the width of the region to capture
01635     /// @param[in] h is the height of the region to capture.
01636     /// @param[out] Name_BMP is the filename to write the image to.
01637     /// @return success or error code.
01638     ///
01639     RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP);
01640     
01641     /// This method captures the specified area as a 24-bit bitmap file,
01642     /// including the option of layer selection.
01643     ///
01644     /// @caution This method is deprecated as the alternate PrintScreen API
01645     ///         automatically examines the display layer configuration.
01646     ///         Therefore, calls to this API will ignore the layer parameter
01647     ///         and automatically execute the other method.
01648     ///
01649     /// Even though this is a 16-bit display, the stored image is in
01650     /// 24-bit format.
01651     ///
01652     /// @param[in] layer is 0 or 1 to select the layer to extract.
01653     /// @param[in] x is the left edge of the region to capture
01654     /// @param[in] y is the top edge of the region to capture
01655     /// @param[in] w is the width of the region to capture
01656     /// @param[in] h is the height of the region to capture.
01657     /// @param[out] Name_BMP is the filename to write the image to.
01658     /// @return success or error code.
01659     ///
01660     RetCode_t PrintScreen(uint16_t layer, loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP);
01661     
01662 
01663 #ifdef PERF_METRICS
01664     /// Clear the performance metrics to zero.
01665     void ClearPerformance();
01666     
01667     /// Count idle time.
01668     ///
01669     /// @param[in] t is the amount of idle time to accumulate.
01670     ///
01671     void CountIdleTime(uint32_t t);
01672     
01673     /// Report the performance metrics for drawing functions using
01674     /// the available serial channel.
01675     ///
01676     /// @param[in,out] pc is the serial channel to write to.
01677     ///
01678     void ReportPerformance(Serial & pc);
01679 #endif
01680 
01681 
01682 private:
01683     /// Touch Panel register name definitions
01684     #define TPCR0   0x70
01685     #define TPCR1   0x71
01686     #define TPXH    0x72
01687     #define TPYH    0x73
01688     #define TPXYL   0x74
01689     #define INTC1   0xF0
01690     #define INTC2   0xF1
01691 
01692     /// Specify the default settings for the Touch Panel, where different from the chip defaults
01693     #define TP_MODE_DEFAULT             TP_MODE_AUTO
01694     #define TP_DEBOUNCE_DEFAULT         TP_DEBOUNCE_ON
01695     #define TP_ADC_CLKDIV_DEFAULT       TP_ADC_CLKDIV_8
01696 
01697     #define TP_ADC_SAMPLE_DEFAULT_CLKS  TP_ADC_SAMPLE_8192_CLKS
01698 
01699     /// Other Touch Panel params
01700     #define TPBUFSIZE   16       // Depth of the averaging buffers for x and y data
01701 
01702     /// Touch Panel calibration matrix.
01703     tpMatrix_t tpMatrix;
01704 
01705     /// Internal function to put a character using the built-in (internal) font engine
01706     ///
01707     /// @param[in] is the character to put to the screen.
01708     /// @returns the character put.
01709     ///
01710     int _internal_putc(int c);
01711     
01712     /// Internal function to put a character using the external font engine
01713     ///
01714     /// @param[in] is the character to put to the screen.
01715     /// @returns the character put.
01716     ///
01717     int _external_putc(int c);
01718     
01719     /// Select the peripheral to use it.
01720     ///
01721     /// @param[in] chipsel when true will select the peripheral, and when false
01722     ///     will deselect the chip. This is the logical selection, and
01723     ///     the pin selection is the invert of this.
01724     /// @returns success/failure code. @see RetCode_t.
01725     ///
01726     RetCode_t _select(bool chipsel);
01727 
01728     /// Wait while the status register indicates the controller is busy.
01729     ///
01730     /// @param[in] mask is the mask of bits to monitor.
01731     /// @returns true if a normal exit.
01732     /// @returns false if a timeout exit.
01733     ///
01734     bool _WaitWhileBusy(uint8_t mask);
01735 
01736     /// Wait while the the register anded with the mask is true.
01737     ///
01738     /// @param[in] reg is the register to monitor
01739     /// @param[in] mask is the bit mask to monitor
01740     /// @returns true if it was a normal exit
01741     /// @returns false if it was a timeout that caused the exit.
01742     ///
01743     bool _WaitWhileReg(uint8_t reg, uint8_t mask);
01744 
01745     /// set the spi port to either the write or the read speed.
01746     ///
01747     /// This is a private API used to toggle between the write
01748     /// and the read speed for the SPI port to the RA8875, since
01749     /// it can accept writes faster than reads.
01750     ///
01751     /// @param[in] writeSpeed when true selects the write frequency,
01752     ///     and when false it selects the read frequency.
01753     ///
01754     void _setWriteSpeed(bool writeSpeed);
01755 
01756     /// The most primitive - to write a data value to the SPI interface.
01757     ///
01758     /// @param[in] data is the value to write.
01759     /// @returns a value read from the port, since SPI is often shift
01760     ///     in while shifting out.
01761     ///
01762     unsigned char _spiwrite(unsigned char data);
01763     
01764     /// The most primitive - to read a data value to the SPI interface.
01765     ///
01766     /// This is really just a specialcase of the write command, where
01767     /// the value zero is written in order to read.
01768     ///
01769     /// @returns a value read from the port, since SPI is often shift
01770     ///     in while shifting out.
01771     ///
01772     unsigned char _spiread();
01773     
01774     const uint8_t * pKeyMap;
01775     
01776     SPI spi;                        ///< spi port
01777     bool spiWriteSpeed;             ///< indicates if the current mode is write or read
01778     unsigned long spiwritefreq;     ///< saved write freq
01779     unsigned long spireadfreq;      ///< saved read freq
01780     DigitalOut cs;                  ///< chip select pin, assumed active low
01781     DigitalOut res;                 ///< reset pin, assumed active low
01782     const unsigned char * font;     ///< reference to an external font somewhere in memory
01783     loc_t cursor_x, cursor_y;    ///< used for external fonts only
01784     
01785     #ifdef PERF_METRICS
01786     typedef enum
01787     {
01788         PRF_CLS,
01789         PRF_DRAWPIXEL,
01790         PRF_PIXELSTREAM,
01791         PRF_READPIXEL,
01792         PRF_READPIXELSTREAM,
01793         PRF_DRAWLINE,
01794         PRF_DRAWRECTANGLE,
01795         PRF_DRAWROUNDEDRECTANGLE,
01796         PRF_DRAWTRIANGLE,
01797         PRF_DRAWCIRCLE,
01798         PRF_DRAWELLIPSE,
01799         METRICCOUNT
01800     } method_e;
01801     unsigned long metrics[METRICCOUNT];
01802     unsigned long idletime_usec;
01803     void RegisterPerformance(method_e method);
01804     Timer performance;
01805     #endif
01806 };
01807 
01808 //}     // namespace
01809 
01810 //using namespace SW_graphics;
01811 
01812 
01813 #ifdef TESTENABLE
01814 //      ______________  ______________  ______________  _______________
01815 //     /_____   _____/ /  ___________/ /  ___________/ /_____   ______/
01816 //          /  /      /  /            /  /                  /  /
01817 //         /  /      /  /___         /  /__________        /  /
01818 //        /  /      /  ____/        /__________   /       /  /
01819 //       /  /      /  /                       /  /       /  /
01820 //      /  /      /  /__________  ___________/  /       /  /
01821 //     /__/      /_____________/ /_____________/       /__/
01822 
01823 #include "WebColors.h"
01824 #include "Arial12x12.h"
01825 #include <algorithm>
01826 
01827 extern "C" void mbed_reset();
01828 
01829 /// This activates a small set of tests for the graphics library. 
01830 ///
01831 /// Call this API and pass it the reference to the display class.
01832 /// It will then run a series of tests. It accepts interaction via
01833 /// stdin to switch from automatic test mode to manual, run a specific
01834 /// test, or to exit the test mode.
01835 ///
01836 /// @param[in] lcd is a reference to the display class.
01837 /// @param[in] pc is a reference to a serial interface, typically the USB to PC.
01838 ///
01839 void RunTestSet(RA8875 & lcd, Serial & pc);
01840 
01841 
01842 // To enable the test code, uncomment this section, or copy the
01843 // necessary pieces to your "main()".
01844 //
01845 // #include "mbed.h"
01846 // #include "RA8875.h"
01847 // RA8875 lcd(p5, p6, p7, p12, NC, "tft");    // MOSI, MISO, SCK, /ChipSelect, /reset, name
01848 // Serial pc(USBTX, USBRX);
01849 // extern "C" void mbed_reset();
01850 // int main()
01851 // {
01852 //     pc.baud(460800);    // I like a snappy terminal, so crank it up!
01853 //     pc.printf("\r\nRA8875 Test - Build " __DATE__ " " __TIME__ "\r\n");
01854 // 
01855 //     pc.printf("Turning on display\r\n");
01856 //     lcd.Reset();
01857 //     lcd.Power(true);  // display power is on, but the backlight is independent
01858 //     lcd.Backlight(0.5);
01859 //     RunTestSet(lcd, pc);
01860 // }
01861 
01862 #endif // TESTENABLE
01863 
01864 #endif