Library to control a Graphics TFT connected to 4-wire SPI - revised for the Raio RA8875 Display Controller.
Dependents: FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more
Fork of SPI_TFT by
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 480 pixels x 16-bit color and has an integrated 00006 /// 2D graphics engine which significantly unburdens the hosting cpu. The 2D engine 00007 /// handles many drawing primitives; such as line, rectangle, triangle, circles, and 00008 /// each either filled or unfilled. Further, it supports fonts - both internal and 00009 /// with specific formats of external font roms. 00010 /// 00011 /// @image html Example_Program.png "Image of an Example Program" 00012 /// 00013 /// In more detail: 00014 /// 00015 /// Aside from 800 x 480 pixel displays, another common implementation is 00016 /// 480 x 272 x 16 with two layers. The two layers can be exchanged, or blended 00017 /// in various ways (transparency, OR, AND, and more). 00018 /// 00019 /// It is not a display for video-speed animations, and maybe could hold its own 00020 /// as a slow picture frame, at least when using the SPI interface. How the 00021 /// performance differs using I2C, 8-bit parallel or 16-bit parallel has not 00022 /// been evaluated. Certainly the parallel interface option would be expected to be 00023 /// a lot faster. 00024 /// 00025 /// What it is good at is performing as a basic display for appliances or simple 00026 /// home automation, and because of the built-in capability to draw lines, circles, 00027 /// ellipses, rectangles, rounded rectangles, and triangles, it does a lot of the 00028 /// work that your host micro would otherwise be doing, and in many cases it does 00029 /// it much faster. 00030 /// 00031 /// While it is good to know about Bresenham's algorithm (to draw a line) and how 00032 /// to implement it in software, this controller simplifies things - 00033 /// You just give it (x1,y1), (x2,y2) and tell it to draw a line. 00034 /// Without the hardware acceleration built into the RA8875, the host would have to 00035 /// compute every point, set the graphics cursor to that point, and fill in that 00036 /// point with the target color. A diagonal line of some length might take 100 00037 /// transactions instead of just a few. Other drawing primitives are similarly easy. 00038 /// 00039 /// It has some built-in fonts, which can be enhanced with optional font-chips, and 00040 /// with the software font engine that is part of this library. Instructions are provided 00041 /// to convert most any True Type Font into the data structures suitable for this display. 00042 /// The user of this library is expected to respect the copyright of those fonts (there 00043 /// are open-source fonts that can be found on the web). 00044 /// 00045 /// To round out the features, this library offers the ability to render Bitmap (BMP), 00046 /// Icon (ICO), Joint Photographic Experts Group (JPG), and Graphics Interchange Format 00047 /// (GIF) images. These are implemented primarily in software, taking advantage of the 00048 /// hardware acceleration where it can. There are some limitations, based on available 00049 /// memory. 00050 /// 00051 /// When you are satisfied with what appears on screen, there is a PrintScreen method 00052 /// to pull that image back out of the display RAM and write it to a file system as a 00053 /// BitMap image. 00054 /// 00055 /// 00056 /// The RA8875 has an integrated PWM, commonly used for backlight brightness, keypad scanning 00057 /// (for a 4 x 5 matrix) and an integrated resistive touch-panel support. Support for capacitive 00058 /// touch screens is also integrated in this library, in a manner that makes the resistive and 00059 /// capacitive interfaces nearly API identical. The capacitive touch support was crafted to 00060 /// interface with either the FT5206 or the GSL1680 controller chips (two popular controllers 00061 /// commonly integrated with the RA8875). 00062 /// 00063 /// Recent Changes: 00064 /// * @ref RA8875::SelectDrawingLayer() returns the previously selected layer, making restore quicker. 00065 /// * @ref RA8875::SetGraphicsOrientation() has been improved to support 0 deg (typical landscape), 00066 /// 90 deg, 180 deg, and 270 deg, and this includes bitmap and soft-font presentation, 00067 /// as well as touch support and to return the previous angle. 00068 /// * @ref RA8875::SetBackgroundTransparencyColor() returns the previous color value, making 00069 /// restore quicker. 00070 /// * @ref RA8875::SetWindow() accepts a rect_t, or an (x1,y1, x2,y2) point-pair, rather than a 00071 /// point-pair and a width,height. This makes it much more consisten with all other APIs. 00072 /// * @ref RA8875::SetLayerMode() returns the previous layer mode. 00073 /// * @ref RA8875::SetTextCursor() returns the previous cursor. 00074 /// * @ref RA8875::background() returns the previous color. 00075 /// * @ref RA8875::foreground() returns the previous color. 00076 00077 /// Here's a few hints to get started: 00078 /// * @ref Display_Config 00079 /// * @ref Touch_Panel 00080 /// * @ref Hardwired_KeyPad 00081 /// * @ref Example_Program 00082 /// * @ref Wiring_Diagram 00083 /// * @ref External_Resources 00084 /// * @ref Future_Plans 00085 /// 00086 /// @todo Integrate the touch as a runtime linkable feature, which can then eliminate 00087 /// the huge memory footprint for the GSL1680 firmware when it is not needed. 00088 /// @todo Move the global enums into the class (e.g. NOFILL becomes RA8875::NOFILL) to 00089 /// avoid namespace clashes. 00090 /// @todo Integrate access to an installed font-rom. 00091 /// @todo Figure out how to "init()" in the constructor. I ran into some issues if 00092 /// the display was instantiated before main(), and the code would not run, 00093 /// thus the exposure and activation of the init() function. If the constructor 00094 /// was within main(), then it seemed to work as expected. 00095 /// @todo Add Scroll support for text in a window. 00096 /// @todo Add Hardware reset signal - testing to date indicates it is not needed. 00097 /// @todo Add APIs for the 2nd RA8875 PWM channel. If the frequency can be independently 00098 /// controlled, it could be used as a simple sound channel (beeper). 00099 /// @todo Find out if 4-wire SPI can leverage 16-bit mode, and if so, how does the 00100 /// performance change? 00101 /// 00102 /// @note As the author of this library, let me state that I am not affiliated with 00103 /// Raio (silicon provider of the RA8875), or with BuyDisplay.com (where a lot 00104 /// of these displays can be purchased), I am simply a very satisfied customer 00105 /// of the technology of the RA8875 chip. 00106 /// 00107 /// @copyright Copyright © 2012-2020 by Smartware Computing, all rights reserved. 00108 /// This library is predominantly that of Smartware Computing, however some 00109 /// portions integrate the work of others. Where the contribution of 00110 /// others was listed as copyright, that copyright is maintained, even as a 00111 /// derivative work may have been created for better integration in this library. 00112 /// See @ref Copyright_References. 00113 /// 00114 /// @page Copyright_References Copyright References 00115 /// 00116 /// Following are links to the known copyright references. If I overlooked any, it was 00117 /// unintentional - please let me know so I can update it. Some portions of the code 00118 /// have been acquired from the cloud, and where any copyright information was available, 00119 /// it was preserved. 00120 /// 00121 /// * @ref GraphicDisplay_Copyright 00122 /// * @ref TextDisplay_Copyright 00123 /// * @ref TinyJPEGDecompressor_Copyright 00124 /// * @ref RA8875::TouchPanelComputeCalibration 00125 /// 00126 /// @page Display_Config Display Configuration 00127 /// 00128 /// This section details basics for bringing the display online. At a minimum, 00129 /// the display is instantiated, after which nearly any of the available commands 00130 /// may be issued. 00131 /// 00132 /// @image html RA8875_Display.png "Schematic Representation of the Display" 00133 /// 00134 /// During the instantiation, the display is powered on, cleared, and the backlight 00135 /// is energized. Additionally, the keypad and touchscreen features are activated. 00136 /// It is important to keep in mind that the keypad has its default mapping, 00137 /// a resistive touchscreen does not yet have the calibration matrix configured, 00138 /// and the RA8875::init() function is required to configure other important options 00139 /// like the display resolution. 00140 /// 00141 /// @code 00142 /// RA8875 lcd(p5, p6, p7, p12, NC, "tft"); 00143 /// lcd.init(); 00144 /// lcd.foreground(Blue); 00145 /// lcd.line(0,0, 479,271); 00146 /// ... 00147 /// @endcode 00148 /// 00149 /// @section RA8875_Capabilities Basic Capabilities 00150 /// @subsection RA8875_Resolution Display Resolution 00151 /// There are two very common display resolutions that use the RA8875: 00152 /// * 480 x 272 pixels 00153 /// * 800 x 480 pixels 00154 /// 00155 /// @subsection RA8875_Layers Display Layers 00156 /// The RA8875 Controller, depending on the resolution and color depth, can support 00157 /// multiple display layers. 00158 /// 00159 /// * 1 Layer - when the color depth is 16 bits per pixel 00160 /// * 2 Layers - when the color depth is 8 bits per pixel and the resolution is 480 x 272. 00161 /// 00162 /// @page Touch_Panel Touch Panel 00163 /// 00164 /// There is support for various touch panel interfaces. 00165 /// * @ref Resistive_Touch_Panel - native control for a resistive touch panel. 00166 /// There are a few steps to enable this interface. 00167 /// 00168 /// For the Capacitive Touch controllers, an I2C interface is required. 00169 /// 00170 /// @image html RA8875_Touch.png "Schematic Representation of the Touch Interface" 00171 /// 00172 /// * @ref CapSense_FT5206 - FT5206 capacitive touch controller, integrated in 00173 /// several popular RA8875-based displays. See @ref Capacitive_Touch_Panel. 00174 /// * @ref CapSense_GSL1680 - GSL1680 capacitive touch controller, integrated in 00175 /// several popular RA8875-based displays. See @ref Capacitive_Touch_Panel. 00176 /// 00177 /// @page MicroSD_Interface Micro SD Interface 00178 /// 00179 /// Several of the displays from BuyDisplay.com include the option for a Micro SD 00180 /// card adapter. This is not tied in to the RA8875 controller, it is just provided 00181 /// as a convenience to the display product. 00182 /// 00183 /// @image html RA8875_MicroSD.png "Schematic Representation of the Micro SD Interface" 00184 /// 00185 /// 00186 /// @page Hardwired_KeyPad Hardwired Keypad 00187 /// 00188 /// The RA8875 controller supports a hardwired matrix of keys, which can be used to 00189 /// easily monitor for up to 20 keys (4 x 5 matrix). It is quite flexible, so these 00190 /// could be a set of independent functions, or they could be wired as a simple 00191 /// calculator or telephone style of keypad. 00192 /// 00193 /// @image html RA8875_Keypad.png "Schematic Representation of the Keypad Interface" 00194 /// 00195 /// Various parameters can be configured, such as the scan rate, using @ref RA8875::KeypadInit(). 00196 /// The keypad has a default keypad mapping, but there is an API that permits 00197 /// installing a custom @ref RA8875::SetKeyMap(). 00198 /// 00199 /// @page Resistive_Touch_Panel Resistive Touch Panel 00200 /// 00201 /// The RA8875 controller supports a native resistive touchscreen interface than can 00202 /// track a single touch-point. 00203 /// 00204 /// If your display has this option, you can easily accept touch input, but it comes with 00205 /// some additional requirements - calibration being the primary concern. 00206 /// 00207 /// @section Touch_Panel_Enable Touch Panel Enable 00208 /// 00209 /// @ref RA8875::TouchPanelInit() has two forms - one fully automatic, and more controlled. 00210 /// See the APIs for details. 00211 /// 00212 /// @section Touch_Panel_Calibration 00213 /// 00214 /// The touch panel is not initially calibrated on startup. The application should 00215 /// provide a means to activate the calibration process, and that should not require 00216 /// the touchscreen as it may not yet be usable. Alternately, a calibration matrix 00217 /// can be loaded from non-volatile and installed. 00218 /// 00219 /// @page Capacitive_Touch_Panel Capacitive Touch Panel 00220 /// 00221 /// Common to many of the commercially available display modules that use the RA8875 is 00222 /// an option for a capacitive sense touch screen [Cap Sense] There are two known Cap Sense 00223 /// controllers that this library can work with: 00224 /// 00225 /// * @ref CapSense_FT5206. 00226 /// * @ref CapSense_GSL1680. 00227 /// 00228 /// @page CapSense_FT5206 Capacitive Sense - FT5206 Controller 00229 /// 00230 /// This is the more common controller. It supports up to 5 simultaneous touch point 00231 /// tracking. 00232 /// 00233 /// @page CapSense_GSL1680 Capacitive Sense - GSL1680 Controller 00234 /// 00235 /// This is the less common controller. It supports either 5 or 10 simultaneous touch point 00236 /// tracking, depending on the firmware installed in the controller. 00237 /// 00238 00239 00240 /// @page Example_Program Example Program 00241 /// 00242 /// This is just a small sample of what can be done, and what it can look like: 00243 /// @image html Example_Program.png "Example Program" 00244 /// 00245 /// @code 00246 /// // Small test program 00247 /// #include "mbed.h" // Working: v146, not fully working: v147 00248 /// #include "RA8875.h" // Working: v149 00249 /// RA8875 lcd(p5, p6, p7, p12, NC, "tft"); 00250 /// 00251 /// int main() 00252 /// { 00253 /// lcd.init(480,272,16,100); 00254 /// lcd.printf("printing 3 x 2 = %d", 3*2); 00255 /// lcd.circle( 400,25, 25, BrightRed); 00256 /// lcd.fillcircle( 400,25, 15, RGB(128,255,128)); 00257 /// lcd.ellipse( 440,75, 35,20, BrightBlue); 00258 /// lcd.fillellipse( 440,75, 25,10, Blue); 00259 /// lcd.triangle( 440,100, 475,110, 450,125, Magenta); 00260 /// lcd.filltriangle( 445,105, 467,111, 452,120, Cyan); 00261 /// lcd.rect( 400,130, 475,155, Brown); 00262 /// lcd.fillrect( 405,135, 470,150, Pink); 00263 /// lcd.roundrect( 410,160, 475,190, 10,8, Yellow); 00264 /// lcd.fillroundrect(415,165, 470,185, 5,3, Orange); 00265 /// lcd.line( 430,200, 460,230, RGB(0,255,0)); 00266 /// for (int i=0; i<=30; i+=5) 00267 /// lcd.pixel(435+i,200+i, White); 00268 /// } 00269 /// @endcode 00270 /// 00271 00272 00273 /// @page Wiring_Diagram Example Wiring Diagram 00274 /// 00275 /// This library was crafted around the 4-Wire SPI interface. This was the chosen 00276 /// interface method in order to balance the requirements of the host micro IO with 00277 /// the capability of this display. Alternatives include: 3-Wire SPI, I2C, 8-bit and 00278 /// 16-bit parallel. 00279 /// 00280 /// @section Schematic_Basic Basic Schematic 00281 /// 00282 /// The basic schematic should be the most portable to any system that has SPI support. 00283 /// 00284 /// @image html RA8875_display_schematic.png "Basic Display support" 00285 /// 00286 /// @section Schematic_DisplayTouch Display with Capacitive Touch 00287 /// 00288 /// A more advanced schematic - this with the I2C interface connecting to the Capacitive 00289 /// Touch controller. Note that this requires additional IO pins. 00290 /// 00291 /// @image html RA8875_captouch_wiring.png "Display and Capacitive Touch support" 00292 /// 00293 /// @section Schematic_DisplayTouchMicroSD Display with Capacitive Touch and micro SD 00294 /// 00295 /// The most advanced schematic - taking advantage of the display, the capacitive touch 00296 /// controller, and the peripheral support for a micro SD card on some of the display 00297 /// modules. 00298 /// 00299 /// @note There are online indications that the RA8875 has a defect in its SPI interface 00300 /// where it will not release the MISO pin. If this pin is shared with the micro SD 00301 /// port, then it could interfere with successful read/write of the files. 00302 /// The easiest solution is to put that interface on a separate SPI port. 00303 /// 00304 /// @image html RA8875_display_full.png "Display, Touch, and micro SD support" 00305 /// 00306 /// @page External_Resources External Resources 00307 /// 00308 /// There are many websites with information on the RA8875 Display. This partial list 00309 /// may be helpful: 00310 /// 00311 /// * <a href="https://os.mbed.com/components/RA8875-Based-Display/">RA8875 Library</a> 00312 /// on the <a href="https://os.mbed.com/">mbed site</a><br/> 00313 /// This page has **a lot** of detail, schematices, sample programs, instructions to 00314 /// create your own fonts, and more... 00315 /// * <a href="https://os.mbed.com/search/?q=RA8875">RA8875 search on the mbed site</a><br/> 00316 /// Many more links, discussions, questions and answers, and more... 00317 /// * <a href="https://www.buydisplay.com/">Buy Display</a> site<br/> 00318 /// Where you can find many inexpensive displays, some with the **RA8875** controller 00319 /// (which this library supports), and others using different controllers (thus not 00320 /// supported by this library). 00321 /// * <a href="https://github.com/sumotoy/RA8875/wiki/Fix-compatibility-with-other-SPI-devices">SPI Bug notes</a><br/> 00322 /// A link to a site that discusses a SPI bug on the RA8875. [I have not verified this 00323 /// bug] 00324 /// * <a href="https://www.google.com/search?safe=on&source=hp&ei=1oN1XP6hEsPq_AbZlKMw&q=RA8875">RA8875 - Google</a><br/> 00325 /// Because new things show up all the time. 00326 /// * <a href="https://www.bing.com/search?q=RA8875">RA8875 - Bing</a><br/> 00327 /// And you want to look in more than one place. 00328 /// 00329 /// @image html RA8875_display_full.png "Example Wiring Diagram" 00330 /// 00331 00332 00333 /// @page Future_Plans Future Plans 00334 /// 00335 /// Following are some notions of future plans. This does not mean they will all be 00336 /// implemented, just consider them as things I'm thinking about. If you have a suggestion, 00337 /// please send it to me. 00338 /// 00339 /// - Change the return values for several functions. Most functions return @ref RA8875::RetCode_t, 00340 /// but would benefit from returning a data type related to that function. For example, 00341 /// @ref RA8875::SelectDrawingLayer() should return the current drawing layer even as a new 00342 /// layer is defined. This can facilitate switching back and forth between configurations. 00343 /// 00344 /// Review the API for these (and other) functions for this change: 00345 /// - @ref RA8875::SelectUserFont() 00346 /// - @ref RA8875::SetLayerTransparency() 00347 /// - @ref RA8875::SetTextCursorControl() 00348 /// - @ref RA8875::SetTextFont() 00349 /// - @ref RA8875::SetTextFontControl() 00350 /// - @ref RA8875::SetTextFontSize() 00351 /// - @ref RA8875::Backlight() 00352 /// 00353 /// - Change the title-case of the functions to be consistent. Because this was adapted 00354 /// from parts of several different libraries, it isn't very consistently titled. 00355 /// 00356 /// - Change names of some of the functions to be more consistent. Why are some Set* 00357 /// and others are Select*. The layer commands SetDrawingLayer and GetDrawingLayer do 00358 /// not need 'Drawing' in them. 00359 /// 00360 /// - Improve the PrintScreen method. There are two functions - one that accepts a filename, 00361 /// and a second more experimental version that could pipe the image stream back to 00362 /// a calling process. This could be used, for example, to send the image over a 00363 /// network interface. The intended side effect is that there is then only a single 00364 /// PrintScreen method with either an internal helper (for file system access) or 00365 /// a callback for the user handled process. 00366 /// 00367 /// - Add support for the hardware reset pin 00368 /// 00369 /// - Figure out how to "init()" in the constructor when it is not in main(). I ran into 00370 /// some issues if the display was instantiated before main(), and the code would not 00371 /// run, thus the exposure and activation of the init() function. If the instantiation 00372 /// is within main(), then it seemed to work as expected. 00373 /// 00374 /// - Add Scroll support for text. 00375 /// 00376 /// - Add high level objects - x-y graph, meter, buttons, ... but these will probably be 00377 /// best served in another class, since they may not be needed for many uses. 00378 /// 00379 #ifndef RA8875_H 00380 #define RA8875_H 00381 #include <mbed.h> 00382 00383 #include "RA8875_Regs.h" 00384 #include "RA8875_Touch_FT5206.h" 00385 #include "RA8875_Touch_GSL1680.h" 00386 #include "GraphicsDisplay.h" 00387 00388 #define RA8875_DEFAULT_SPI_FREQ 5000000 00389 00390 #ifndef MBED_ENCODE_VERSION 00391 #define MBED_MAJOR_VERSION 2 00392 #define MBED_MINOR_VERSION 0 00393 #define MBED_PATCH_VERSION MBED_LIBRARY_VERSION 00394 #define MBED_ENCODE_VERSION(major, minor, patch) ((major)*10000 + (minor)*100 + (patch)) 00395 #endif 00396 00397 #if defined(__GNUC__) || defined(__clang__) 00398 #define DEPRECATED(msg) __attribute__((deprecated(msg))) 00399 #elif defined(_MSC_VER) 00400 #define DEPRECATED __declspec(deprecated) 00401 #else 00402 #pragma message("WARNING: You need to implement DEPRECATED for this compiler") 00403 #define DEPRECATED 00404 #endif 00405 00406 // Define this to enable code that monitors the performance of various 00407 // graphics commands. 00408 //#define PERF_METRICS 00409 00410 // What better place for some test code than in here and the companion 00411 // .cpp file. See also the bottom of this file. 00412 //#define TESTENABLE 00413 00414 /// @page PredefinedColors Predefined Colors 00415 /// 00416 /// Keep in mind that the color scheme shown here is unlikely to precisely match 00417 /// that on the actual display. The perceived color is additionally affected by 00418 /// other attributes, such as the polarizer, backlight brightness, liquid crystal 00419 /// fluid properties, viewing angle, and more... 00420 /// 00421 /// These are the predefined colors that are typically used where any @ref color_t 00422 /// variable is applied. 00423 /// 00424 /// <blockquote> 00425 /// <table> 00426 /// <tr> 00427 /// <td bgcolor='#000000'> </td><td>@ref Black</td> 00428 /// <td bgcolor='#0000BB'> </td><td>@ref Blue</td> 00429 /// <td bgcolor='#00BB00'> </td><td>@ref Green</td> 00430 /// <td bgcolor='#00BBBB'> </td><td>@ref Cyan</td> 00431 /// </tr> 00432 /// <tr> 00433 /// <td bgcolor='#BB0000'> </td><td>@ref Red</td> 00434 /// <td bgcolor='#BB00BB'> </td><td>@ref Magenta</td> 00435 /// <td bgcolor='#3F3F3F'> </td><td>@ref Brown</td> 00436 /// <td bgcolor='#BBBBBB'> </td><td>@ref Gray</td> 00437 /// </tr> 00438 /// <tr> 00439 /// <td bgcolor='#555555'> </td><td>@ref Charcoal</td> 00440 /// <td bgcolor='#0000FF'> </td><td>@ref BrightBlue</td> 00441 /// <td bgcolor='#00FF00'> </td><td>@ref BrightGreen</td> 00442 /// <td bgcolor='#00FFFF'> </td><td>@ref BrightCyan</td> 00443 /// </tr> 00444 /// <tr> 00445 /// <td bgcolor='#FF0000'> </td><td>@ref BrightRed</td> 00446 /// <td bgcolor='#FF5555'> </td><td>@ref Orange</td> 00447 /// <td bgcolor='#FF55FF'> </td><td>@ref Pink</td> 00448 /// <td bgcolor='#BBBB00'> </td><td>@ref Yellow</td> 00449 /// </tr> 00450 /// <tr> 00451 /// <td bgcolor='#FFFF00'> </td><td>@ref BrightYellow</td> 00452 /// <td bgcolor='#FFFFFF'> </td><td>@ref White</td> 00453 /// <td bgcolor='#00003F'> </td><td>@ref DarkBlue </td> 00454 /// <td bgcolor='#003F00'> </td><td>@ref DarkGreen</td> 00455 /// </tr> 00456 /// <tr> 00457 /// <td bgcolor='#003F3F'> </td><td>@ref DarkCyan </td> 00458 /// <td bgcolor='#3F0000'> </td><td>@ref DarkRed </td> 00459 /// <td bgcolor='#3F003F'> </td><td>@ref DarkMagenta</td> 00460 /// <td bgcolor='#3F3F00'> </td><td>@ref DarkBrown </td> 00461 /// </tr> 00462 /// <tr> 00463 /// <td bgcolor='#3F3F3F'> </td><td>@ref DarkGray </td> 00464 /// <td bgcolor='#FFFFFF'> </td><td> </td> 00465 /// <td bgcolor='#FFFFFF'> </td><td> </td> 00466 /// <td bgcolor='#FFFFFF'> </td><td> </td> 00467 /// </tr> 00468 /// </table> 00469 /// </blockquote> 00470 /// 00471 00472 #define Black (color_t)(RGB(0,0,0)) 00473 #define Blue (color_t)(RGB(0,0,187)) 00474 #define Green (color_t)(RGB(0,187,0)) 00475 #define Cyan (color_t)(RGB(0,187,187)) 00476 #define Red (color_t)(RGB(187,0,0)) 00477 #define Magenta (color_t)(RGB(187,0,187)) 00478 #define Brown (color_t)(RGB(63,63,0)) 00479 #define Gray (color_t)(RGB(187,187,187)) 00480 #define Charcoal (color_t)(RGB(85,85,85)) 00481 #define BrightBlue (color_t)(RGB(0,0,255)) 00482 #define BrightGreen (color_t)(RGB(0,255,0)) 00483 #define BrightCyan (color_t)(RGB(0,255,255)) 00484 #define BrightRed (color_t)(RGB(255,0,0)) 00485 #define Orange (color_t)(RGB(255,85,85)) 00486 #define Pink (color_t)(RGB(255,85,255)) 00487 #define Yellow (color_t)(RGB(187,187,0)) 00488 #define BrightYellow (color_t)(RGB(255,255,0)) 00489 #define White (color_t)(RGB(255,255,255)) 00490 00491 #define DarkBlue (color_t)(RGB(0,0,63)) 00492 #define DarkGreen (color_t)(RGB(0,63,0)) 00493 #define DarkCyan (color_t)(RGB(0,63,63)) 00494 #define DarkRed (color_t)(RGB(63,0,0)) 00495 #define DarkMagenta (color_t)(RGB(63,0,63)) 00496 #define DarkBrown (color_t)(RGB(63,63,0)) 00497 #define DarkGray (color_t)(RGB(63,63,63)) 00498 00499 #define RAmin(a,b) ((a<b)?a:b) 00500 #define RAmax(a,b) ((a>b)?a:b) 00501 00502 00503 //namespace SW_graphics 00504 //{ 00505 00506 class FPointerDummy; // used by the callback methods. 00507 00508 /// This is a graphics library for the Raio RA8875 Display Controller chip 00509 /// attached to a 4-wire SPI interface. 00510 /// 00511 /// It offers both primitive and high level APIs. 00512 /// 00513 /// Central to this API is a coordinate system, where the origin (0,0) is in 00514 /// the top-left corner of the display, and the width (x) extends positive to the 00515 /// right and the height (y) extends positive toward the bottom. 00516 /// 00517 /// @note As there are both graphics and text commands, one must take care to use 00518 /// the proper coordinate system for each. Some of the text APIs are in units 00519 /// of column and row, which is measured in character positions (and dependent 00520 /// on the font size), where other text APIs permit pixel level positioning. 00521 /// 00522 /// @code 00523 /// #include "RA8875.h" 00524 /// RA8875 lcd(p5, p6, p7, p12, NC, "tft"); 00525 /// 00526 /// int main() 00527 /// { 00528 /// lcd.init(); 00529 /// lcd.printf("printing 3 x 2 = %d", 3*2); 00530 /// lcd.circle( 400,25, 25, BrightRed); 00531 /// lcd.fillcircle( 400,25, 15, RGB(128,255,128)); 00532 /// lcd.ellipse( 440,75, 35,20, BrightBlue); 00533 /// lcd.fillellipse( 440,75, 25,10, Blue); 00534 /// lcd.triangle( 440,100, 475,110, 450,125, Magenta); 00535 /// lcd.filltriangle( 445,105, 467,111, 452,120, Cyan); 00536 /// lcd.rect( 400,130, 475,155, Brown); 00537 /// lcd.fillrect( 405,135, 470,150, Pink); 00538 /// lcd.roundrect( 410,160, 475,190, 10,8, Yellow); 00539 /// lcd.fillroundrect(415,165, 470,185, 5,3, Orange); 00540 /// lcd.line( 430,200, 460,230, RGB(0,255,0)); 00541 /// for (int i=0; i<=30; i+=5) 00542 /// lcd.pixel(435+i,200+i, White); 00543 /// } 00544 /// @endcode 00545 /// 00546 class RA8875 : public GraphicsDisplay 00547 { 00548 public: 00549 /// Vertical alignment attribute. Used to align one rect against another. 00550 /// @ref AlignRectInRect 00551 typedef enum { 00552 top, ///< vertically align to the top 00553 middle, ///< vertically align to the middle 00554 bottom ///< vertically align to the bottom 00555 } valign_t; 00556 00557 /// Horizontal alignment attribute. Used to align one rect against another. 00558 /// @ref AlignRectInRect 00559 typedef enum { 00560 left, ///< horizontally align to the left 00561 center, ///< horizontally align to the center 00562 right ///< horizontally align to the right 00563 } halign_t; 00564 00565 /// cursor type argument for @ref SetTextCursorControl() 00566 typedef enum { 00567 NOCURSOR, ///< cursor is hidden 00568 IBEAM, ///< I Beam '|' cursor 00569 UNDER, ///< Underscore '_' cursor 00570 BLOCK ///< Block cursor 00571 } cursor_t; 00572 00573 /// font type selection argument for @ref SetTextFont() 00574 typedef enum { 00575 ISO8859_1, ///< ISO8859-1 font 00576 ISO8859_2, ///< ISO8859-2 font 00577 ISO8859_3, ///< ISO8859-3 font 00578 ISO8859_4 ///< ISO8859-4 font 00579 } font_t; 00580 00581 /// alignment control argument for @ref SetTextFontControl() 00582 typedef enum { 00583 align_none, ///< align - none 00584 align_full ///< align - full 00585 } alignment_t; 00586 00587 /// Font Horizontal Scale factor - 1, 2, 3 4 for @ref SetTextFontSize(), @ref GetTextFontSize() 00588 typedef int HorizontalScale; 00589 00590 /// Font Vertical Scale factor - 1, 2, 3, 4 for @ref SetTextFontSize(), @ref GetTextFontSize() 00591 typedef int VerticalScale; 00592 00593 /// Clear screen region option for @ref clsw() 00594 typedef enum { 00595 FULLWINDOW, ///< Full screen 00596 ACTIVEWINDOW ///< active window/region 00597 } Region_t; 00598 00599 /// Layer Display Mode argument for @ref SetLayerMode, @ref GetLayerMode 00600 typedef enum { 00601 ShowLayer0, ///< Only layer 0 is visible, layer 1 is hidden (default) 00602 ShowLayer1, ///< Only layer 1 is visible, layer 0 is hidden 00603 LightenOverlay, ///< Lighten-overlay mode 00604 TransparentMode, ///< Transparent mode 00605 BooleanOR, ///< Boolean OR mode 00606 BooleanAND, ///< Boolean AND mode 00607 FloatingWindow ///< Floating Window mode 00608 } LayerMode_T; 00609 00610 /// Touch Panel modes 00611 typedef enum { 00612 TP_Auto, ///< Auto touch detection mode 00613 TP_Manual, ///< Manual touch detection mode 00614 } tpmode_t; 00615 00616 /// PrintScreen callback commands for the user code @ref PrintCallback_T() 00617 typedef enum { 00618 OPEN, ///< command to open the file. cast uint32_t * to the buffer to get the total size to be written. 00619 WRITE, ///< command to write some data, buffer points to the data and the size is in bytes. 00620 CLOSE, ///< command to close the file 00621 } filecmd_t; 00622 00623 /// print screen callback 00624 /// 00625 /// The special form of the print screen will pass one blob at a time 00626 /// to the callback. There are basic commands declaring that the stream 00627 /// can be opened, a block written, and the stream closed. There is 00628 /// also a command to communicate the total size being delivered. 00629 /// 00630 /// If the idle callback is registered, it will be activated passing 00631 /// a parameter indicating the percent complete, which may be of value. 00632 /// 00633 /// @code 00634 /// lcd.PrintScreen(x,y,w,h,callback); 00635 /// ... 00636 /// void callback(filecmd_t cmd, uint8_t * buffer, uint16_t size) { 00637 /// switch(cmd) { 00638 /// case OPEN: 00639 /// pc.printf("About to write %u bytes\r\n", *(uint32_t *)buffer); 00640 /// fh = fopen("file.bmp", "w+b"); 00641 /// break; 00642 /// case WRITE: 00643 /// fwrite(buffer, size, fh); 00644 /// break; 00645 /// case CLOSE: 00646 /// fclose(fh); 00647 /// break; 00648 /// default: 00649 /// pc.printf("Unexpected callback %d\r\n", cmd); 00650 /// break; 00651 /// } 00652 /// } 00653 /// @endcode 00654 /// 00655 /// @param cmd is the command to execute. See @ref filecmd_t. 00656 /// @param buffer is a pointer to the buffer being passed. 00657 /// @param size is the number of bytes in the buffer. 00658 /// @returns @ref RetCode_t value. 00659 /// 00660 typedef RetCode_t (* PrintCallback_T)(filecmd_t cmd, uint8_t * buffer, uint16_t size); 00661 00662 /// Idle reason provided in the Idle Callback @ref IdleCallback_T() 00663 typedef enum { 00664 unknown, ///< reason has not been assigned (this should not happen) 00665 status_wait, ///< driver is polling the status register while busy 00666 command_wait, ///< driver is polling the command register while busy 00667 getc_wait, ///< user has called the getc function 00668 touch_wait, ///< user has called the touch function 00669 touchcal_wait, ///< driver is performing a touch calibration 00670 progress, ///< communicates progress 00671 } IdleReason_T; 00672 00673 /// Idle Callback 00674 /// 00675 /// This defines the interface for an idle callback. That is, when the 00676 /// driver is held up, pending some event, it can call a previously registered 00677 /// idle function. This could be most useful for servicing a watchdog. 00678 /// 00679 /// The user code, which is notified via this API, can force the idle 00680 /// to abort, by returning the external_abort value back to the driver. 00681 /// It is important to note that the abort could leave the driver in 00682 /// an undesireable state, so this should be used with care. 00683 /// 00684 /// @note Should it be called the BusyCallback? It is true, that it will 00685 /// call this function when the RA8875 is busy, but this is also 00686 /// when the CPU is largely idle. 00687 /// 00688 /// @code 00689 /// RetCode_t myIdle_handler(RA8875::IdleReason_T reason, uint16_t param) 00690 /// { 00691 /// idleFlasher = !idleFlasher; 00692 /// if (it_has_been_too_long()) 00693 /// return external_abort; 00694 /// else 00695 /// return noerror; 00696 /// } 00697 /// @endcode 00698 /// 00699 /// @param reason informs the callback why it is idle. 00700 /// @param param is a 2nd parameter, which is used for certain reason codes 00701 /// for 'progress' reason code, param ranges from 0 to 100 (percent) 00702 /// @returns @ref RetCode_t value. 00703 /// 00704 typedef RetCode_t (* IdleCallback_T)(IdleReason_T reason, uint16_t param); 00705 00706 /// Basic constructor for a display based on the RAiO RA8875 00707 /// display controller, which can be used with no touchscreen, 00708 /// or the RA8875 managed resistive touchscreen. 00709 /// 00710 /// This constructor differs from the alternate by supportting 00711 /// either No Touch Screen, or the RA8875 built-in resistive 00712 /// touch screen. If the application requires the use of the 00713 /// capacitive touchscreen, the alternate constructor must 00714 /// be used. 00715 /// 00716 /// This configures the registers and calls the @ref init method. 00717 /// 00718 /// @code 00719 /// #include "RA8875.h" 00720 /// RA8875 lcd(p5, p6, p7, p12, NC, "tft"); 00721 /// 00722 /// int main() 00723 /// { 00724 /// lcd.init(); // defaults for 480x272x16 at low brightness 00725 /// lcd.printf("printing 3 x 2 = %d", 3*2); 00726 /// lcd.circle(400,25, 25, BrightRed); 00727 /// } 00728 /// @endcode 00729 /// 00730 /// @param[in] mosi is the SPI master out slave in pin on the mbed. 00731 /// @param[in] miso is the SPI master in slave out pin on the mbed. 00732 /// @param[in] sclk is the SPI shift clock pin on the mbed. 00733 /// @param[in] csel is the DigitalOut pin on the mbed to use as the 00734 /// active low chip select for the display controller. 00735 /// @param[in] reset is the DigitalOut pin on the mbed to use as the 00736 /// active low reset input on the display controller - 00737 /// but this is not currently used. 00738 /// @param[in] name is a text name for this object, which will permit 00739 /// capturing stdout to puts() and printf() directly to it. 00740 /// 00741 RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, 00742 const char * name = "lcd"); 00743 00744 00745 /// Constructor for a display based on the RAiO RA8875 display controller 00746 /// (using the FT5206 Capacitive TouchScreen Controller) 00747 /// 00748 /// @code 00749 /// #include "RA8875.h" 00750 /// RA8875 lcd(p5,p6,p7,p12,NC, p9,p10,p13, "tft"); 00751 /// 00752 /// int main() 00753 /// { 00754 /// lcd.init(); 00755 /// lcd.printf("printing 3 x 2 = %d", 3*2); 00756 /// lcd.circle(400,25, 25, BrightRed); 00757 /// TouchCode_t tp = lcd.TouchPanelReadable(); 00758 /// if (tp == touch) 00759 /// ... 00760 /// } 00761 /// @endcode 00762 /// 00763 /// @param[in] mosi is the SPI master out slave in pin on the mbed. 00764 /// @param[in] miso is the SPI master in slave out pin on the mbed. 00765 /// @param[in] sclk is the SPI shift clock pin on the mbed. 00766 /// @param[in] csel is the DigitalOut pin on the mbed to use as the 00767 /// active low chip select for the display controller. 00768 /// @param[in] reset is the DigitalOut pin on the mbed to use as the 00769 /// active low reset input on the display controller - 00770 /// but this is not currently used. 00771 /// @param[in] sda is the I2C Serial Data pin you are wiring to the FT5206. 00772 /// @param[in] scl is the I2C Serial Clock pin you are wiring to the FT5206. 00773 /// @param[in] irq is the Interrupt Request pin you are wiring to the FT5206. 00774 /// @param[in] name is a text name for this object, which will permit 00775 /// capturing stdout to puts() and printf() directly to it. 00776 /// 00777 RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, 00778 PinName sda, PinName scl, PinName irq, const char * name = "lcd"); 00779 00780 00781 /// Constructor for a display based on the RAiO RA8875 display controller 00782 /// (using the GSL1680 Capacitive TouchScreen Controller) 00783 /// 00784 /// @code 00785 /// #include "RA8875.h" 00786 /// RA8875 lcd(p5,p6,p7,p12,NC, p9,p10,p13,p14, "tft"); 00787 /// 00788 /// int main() 00789 /// { 00790 /// lcd.init(); 00791 /// lcd.printf("printing 3 x 2 = %d", 3*2); 00792 /// lcd.circle(400,25, 25, BrightRed); 00793 /// TouchCode_t tp = lcd.TouchPanelReadable(); 00794 /// if (tp == touch) 00795 /// ... 00796 /// } 00797 /// @endcode 00798 /// 00799 /// @param[in] mosi is the SPI master out slave in pin on the mbed. 00800 /// @param[in] miso is the SPI master in slave out pin on the mbed. 00801 /// @param[in] sclk is the SPI shift clock pin on the mbed. 00802 /// @param[in] csel is the DigitalOut pin on the mbed to use as the 00803 /// active low chip select for the display controller. 00804 /// @param[in] reset is the DigitalOut pin on the mbed to use as the 00805 /// active low reset input on the display controller - 00806 /// but this is not currently used. 00807 /// @param[in] sda is the I2C Serial Data pin you are wiring to the GSL1680. 00808 /// @param[in] scl is the I2C Serial Clock pin you are wiring to the GSL1680. 00809 /// @param[in] wake is the wake control pin you are wiring to the GSL1680. 00810 /// @param[in] irq is the Interrupt Request pin you are wiring to the GSL1680. 00811 /// @param[in] name is a text name for this object, which will permit 00812 /// capturing stdout to puts() and printf() directly to it. 00813 /// 00814 RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, 00815 PinName sda, PinName scl, PinName wake, PinName irq, const char * name = "lcd"); 00816 00817 00818 // Destructor doesn't have much to do as this would typically be created 00819 // at startup, and not at runtime. 00820 //~RA8875(); 00821 00822 /// Initialize the driver. 00823 /// 00824 /// The RA8875 can control typical displays from the 480x272 to 800x480, and it supports 8 or 16-bit color. 00825 /// It also supports 2 graphics layers, but it cannot support 2 layers at the maximum color depth and 00826 /// screen size. When configured under 480x400, it will support both 16-bit color depth and 2 drawing layers. 00827 /// Above 480x400 it support either 16-bit color, or 2 layers, but not both. 00828 /// 00829 /// Typical of the displays that are readily purchased, you will find 480x272 and 800x480 resolutions. 00830 /// 00831 /// @param[in] width in pixels in landscape orientation to configure the display for. 00832 /// This parameter is optional and the default is 480. 00833 /// @param[in] height in pixels in landscape orientation to configure the display for. 00834 /// This parameter is optional and the default is 272. 00835 /// @param[in] color_bpp can be either 8 or 16, but must be consistent 00836 /// with the width and height parameters. This parameter is optional 00837 /// and the default is 16. 00838 /// @param[in] poweron defines if the display should be initialized into the power-on or off state. 00839 /// If power is non-zero(on), the backlight is set to this value. This parameter is optional 00840 /// and the default is 40 (on at a low brightness level because many users power 00841 /// the module from their PC USB port and it often cannot support the curent 00842 /// required for full brightness). See @ref Power. 00843 /// @param[in] keypadon defines if the keypad support should be enabled. This parameter is optional 00844 /// and the default is true (enabled). See @ref KeypadInit. 00845 /// @param[in] touchscreeenon defines if the touchscreen support should be enabled. 00846 /// This parameter is optional and the default is true (enabled). See @ref TouchPanelInit. 00847 /// - If the constructor was called with support for the capacitive driver, this 00848 /// parameter causes the driver to initialize. 00849 /// - If the constructor was called without support for the capacitive driver, this 00850 /// parameter is used to enable and initialize the resistive touchscreen driver. 00851 /// @returns @ref RetCode_t value. 00852 /// 00853 RetCode_t init(int width = 480, int height = 272, int color_bpp = 16, 00854 uint8_t poweron = 40, bool keypadon = true, bool touchscreeenon = true); 00855 00856 00857 /// Get a pointer to the text string representing the RetCode_t 00858 /// 00859 /// This method returns a pointer to a text string that matches the 00860 /// code. See @ref RetCode_t. 00861 /// 00862 /// @param[in] code is the return value from RetCode_t to look up. 00863 /// @returns a pointer to the text message representing code. If code 00864 /// is not a valid value, then it returns the text for bad_parameter; 00865 /// 00866 const char * GetErrorMessage(RetCode_t code); 00867 00868 00869 /// Select the drawing layer for subsequent commands. 00870 /// 00871 /// If the screen configuration is 480 x 272, or if it is 800 x 480 00872 /// and 8-bit color, the the display supports two layers, which can 00873 /// be independently drawn on and shown. Additionally, complex 00874 /// operations involving both layers are permitted. 00875 /// 00876 /// @attention If the current display configuration does not support 00877 /// multiple layers, then layer 0 will be selected. 00878 /// 00879 /// @code 00880 /// //lcd.SetLayerMode(OnlyLayer0); // default is layer 0 00881 /// lcd.rect(400,130, 475,155,Brown); 00882 /// lcd.SelectDrawingLayer(1); 00883 /// lcd.circle(400,25, 25, BrightRed); 00884 /// wait(1); 00885 /// lcd.SetLayerMode(ShowLayer1); 00886 /// @endcode 00887 /// 00888 /// @attention The user manual refers to Layer 1 and Layer 2, however the 00889 /// actual register values are value 0 and 1. This API as well as 00890 /// others that reference the layers use the values 0 and 1 for 00891 /// cleaner iteration in the code. 00892 /// 00893 /// @param[in] layer is 0 or 1 to select the layer for subsequent 00894 /// commands. 00895 /// @returns previous drawing layer. 00896 /// 00897 virtual uint16_t SelectDrawingLayer(uint16_t layer); 00898 00899 00900 /// Get the currently active drawing layer. 00901 /// 00902 /// This returns a value, 0 or 1, based on the screen configuration 00903 /// and the currently active drawing layer. 00904 /// 00905 /// @code 00906 /// uint16_t prevLayer = lcd.GetDrawingLayer(); 00907 /// lcd.SelectDrawingLayer(x); 00908 /// lcd.circle(400,25, 25, BrightRed); 00909 /// lcd.SelectDrawingLayer(prevLayer); 00910 /// @endcode 00911 /// 00912 /// @attention The user manual refers to Layer 1 and Layer 2, however the 00913 /// actual register values are value 0 and 1. This API as well as 00914 /// others that reference the layers use the values 0 and 1 for 00915 /// cleaner iteration in the code. 00916 /// 00917 /// @returns the current drawing layer; 0 or 1. 00918 /// 00919 virtual uint16_t GetDrawingLayer(void); 00920 00921 00922 /// Set the Layer presentation mode. 00923 /// 00924 /// This sets the presentation mode for layers, and permits showing 00925 /// a single layer, or applying a mode where the two layers 00926 /// are combined using one of the hardware methods. 00927 /// 00928 /// Refer to the RA8875 data sheet for full details. 00929 /// 00930 /// @code 00931 /// //lcd.SetLayerMode(OnlyLayer0); // default is layer 0 00932 /// lcd.rect(400,130, 475,155,Brown); 00933 /// lcd.SelectDrawingLayer(1); 00934 /// lcd.circle(400,25, 25, BrightRed); 00935 /// wait(1); 00936 /// lcd.SetLayerMode(ShowLayer1); 00937 /// @endcode 00938 /// 00939 /// @param[in] mode sets the mode in the Layer Transparency Register. 00940 /// @returns @ref LayerMode_T as the previous layer value. 00941 /// 00942 LayerMode_T SetLayerMode(LayerMode_T mode); 00943 00944 00945 /// Get the Layer presentation mode. 00946 /// 00947 /// This gets the current layer mode. See @ref LayerMode_T. 00948 /// 00949 /// @returns layer mode. 00950 /// 00951 LayerMode_T GetLayerMode(void); 00952 00953 00954 /// Set the layer transparency for each layer. 00955 /// 00956 /// Set the transparency, where the range of values is 00957 /// from zero (fully visible) to eight (fully transparent). 00958 /// The input value is automatically limited to this range. 00959 /// 00960 /// @code 00961 /// // draw something on each layer, then step-fade across 00962 /// display.SetLayerMode(RA8875::TransparentMode); 00963 /// for (i=0; i<=8; i++) { 00964 /// display.SetLayerTransparency(i, 8-i); 00965 /// wait_us(200000); 00966 /// } 00967 /// @endcode 00968 /// 00969 /// @param[in] layer1 sets the layer 1 transparency. 00970 /// @param[in] layer2 sets the layer 2 transparency. 00971 /// @returns @ref RetCode_t value. 00972 /// 00973 RetCode_t SetLayerTransparency(uint8_t layer1, uint8_t layer2); 00974 00975 00976 /// Set the background color register used for transparency. 00977 /// 00978 /// This command sets the background color registers that are used 00979 /// in the transparent color operations involving the layers. 00980 /// 00981 /// @param[in] color is optional and expressed in 16-bit format. If not 00982 /// supplied, a default of Black is used. 00983 /// @returns @ref color_t as the previous color value. 00984 /// 00985 color_t SetBackgroundTransparencyColor(color_t color = RGB(0,0,0)); 00986 00987 00988 /// Get the background color value used for transparency. 00989 /// 00990 /// This command reads the background color registers that define 00991 /// the transparency color for operations involving layers. 00992 /// 00993 /// @returns the color. 00994 /// 00995 color_t GetBackgroundTransparencyColor(void); 00996 00997 00998 /// Initialize theTouch Panel controller with default values 00999 /// 01000 /// This activates the simplified touch panel init, which may work for 01001 /// most uses. The alternate API is available if fine-grained control 01002 /// of the numerous settings of the resistive panel is needed. 01003 /// 01004 /// Additionally, for an even simpler interface for most RESISTIVE 01005 /// touch use cases, the init() method can perform the calibration. 01006 /// 01007 /// @returns @ref RetCode_t value. 01008 /// 01009 RetCode_t TouchPanelInit(void); 01010 01011 01012 /// Initialize the Touch Panel controller with detailed settings. 01013 /// 01014 /// This is the detailed touch panel init, which provides the ability 01015 /// to set nearly every option. 01016 /// 01017 /// @note If the capacitive touch panel was constructed, this behaves 01018 /// the same as the simplified version. 01019 /// 01020 /// @param[in] bTpEnable Touch Panel enable/disable control: 01021 /// - TP_ENABLE: enable the touch panel 01022 /// - TP_DISABLE: disable the touch panel 01023 /// @param[in] bTpAutoManual Touch Panel operating mode: 01024 /// - TP_MODE_AUTO: automatic capture 01025 /// - TP_MODE_MANUAL: manual capture 01026 /// @param[in] bTpDebounce Debounce circuit enable for touch panel interrupt: 01027 /// - TP_DEBOUNCE_OFF: disable the debounce circuit 01028 /// - TP_DEBOUNCE_ON: enable the debounce circuit 01029 /// @param[in] bTpManualMode When Manual Mode is selected, this sets the mode: 01030 /// - TP_MANUAL_IDLE: touch panel is idle 01031 /// - TP_MANUAL_WAIT: wait for touch panel event 01032 /// - TP_MANUAL_LATCH_X: latch X data 01033 /// - TP_MANUAL_LATCH_Y: latch Y data 01034 /// @param[in] bTpAdcClkDiv Sets the ADC clock as a fraction of the System CLK: 01035 /// - TP_ADC_CLKDIV_1: Use CLK 01036 /// - TP_ADC_CLKDIV_2: Use CLK/2 01037 /// - TP_ADC_CLKDIV_4: Use CLK/4 01038 /// - TP_ADC_CLKDIV_8: Use CLK/8 01039 /// - TP_ADC_CLKDIV_16: Use CLK/16 01040 /// - TP_ADC_CLKDIV_32: Use CLK/32 01041 /// - TP_ADC_CLKDIV_64: Use CLK/64 01042 /// - TP_ADC_CLKDIV_128: Use CLK/128 01043 /// @param[in] bTpAdcSampleTime Touch Panel sample time delay before ADC data is ready: 01044 /// - TP_ADC_SAMPLE_512_CLKS: Wait 512 system clocks 01045 /// - TP_ADC_SAMPLE_1024_CLKS: Wait 1024 system clocks 01046 /// - TP_ADC_SAMPLE_2048_CLKS: Wait 2048 system clocks 01047 /// - TP_ADC_SAMPLE_4096_CLKS: Wait 4096 system clocks 01048 /// - TP_ADC_SAMPLE_8192_CLKS: Wait 8192 system clocks 01049 /// - TP_ADC_SAMPLE_16384_CLKS: Wait 16384 system clocks 01050 /// - TP_ADC_SAMPLE_32768_CLKS: Wait 32768 system clocks 01051 /// - TP_ADC_SAMPLE_65536_CLKS: Wait 65536 system clocks 01052 /// @returns @ref RetCode_t value. 01053 /// 01054 RetCode_t TouchPanelInit(uint8_t bTpEnable, uint8_t bTpAutoManual, uint8_t bTpDebounce, 01055 uint8_t bTpManualMode, uint8_t bTpAdcClkDiv, uint8_t bTpAdcSampleTime); 01056 01057 01058 /// Get the screen calibrated point of touch. 01059 /// 01060 /// This method determines if there is a touch and if so it will provide 01061 /// the screen-relative touch coordinates. This method can be used in 01062 /// a manner similar to Serial.readable(), to determine if there was a 01063 /// touch and indicate that - but not care about the coordinates. Alternately, 01064 /// if a valid pointer to a point_t is provided, then if a touch is detected 01065 /// the point_t will be populated with data. 01066 /// 01067 /// @code 01068 /// Timer t; 01069 /// t.start(); 01070 /// do { 01071 /// point_t point = {0, 0}; 01072 /// if (display.TouchPanelReadable(&point)) { 01073 /// display.pixel(point, Red); 01074 /// } 01075 /// } while (t.read_ms() < 30000); 01076 /// @endcode 01077 /// 01078 /// @param[out] TouchPoint is a pointer to a point_t, which is set as the touch point, 01079 /// if a touch is registered. The coordinate system is based on the 01080 /// graphics orientation (@ref SetGraphicsOrientation(), @ref GetGraphicsOrientation()) 01081 /// @returns a value indicating the state of the touch, 01082 /// - no_cal: no calibration matrix is available, touch coordinates are not returned. 01083 /// - no_touch: no touch is detected, touch coordinates are not returned. 01084 /// - touch: touch is detected, touch coordinates are returned. 01085 /// - held: held after touch, touch coordinates are returned. 01086 /// - release: indicates a release, touch coordinates are returned. 01087 /// 01088 TouchCode_t TouchPanelReadable(point_t * TouchPoint = NULL); 01089 01090 01091 /// Get the reported touch gesture, if any. 01092 /// 01093 /// If it could detect a gesture, it will return a value based on 01094 /// the interpreted gesture. 01095 /// 01096 /// Valid gesture values are: 01097 /// @li 0x00 No gesture 01098 /// @li 0x48 Zoom in 01099 /// @li 0x49 Zoom out 01100 /// 01101 /// The following gestures are defined in the FT5206 specification, but 01102 /// do not appear to work. 01103 /// @li 0x10 Move up 01104 /// @li 0x14 Move left 01105 /// @li 0x18 Move down 01106 /// @li 0x1C Move right 01107 /// 01108 /// @returns gesture information. 01109 /// 01110 uint8_t TouchGesture(void) 01111 { 01112 return gesture; 01113 } 01114 01115 01116 /// Get the count of registered touches. 01117 /// 01118 /// @returns count of touch points to communicate; 0 to 5. 01119 /// 01120 int TouchCount(void) 01121 { 01122 return numberOfTouchPoints; 01123 } 01124 01125 01126 /// Get the count of possible touch channels. 01127 /// 01128 /// @returns count of touch channels supported by the hardware. 01129 /// 01130 int TouchChannels(void); 01131 01132 01133 /// Get the Touch ID value for a specified touch channel. 01134 /// 01135 /// Touch ID is a tracking number based on the order of the touch 01136 /// detections. The first touch is ID 0, the next is ID 1, and 01137 /// so on. If the first touch is lifted (no touch), the touch count 01138 /// decrements, and the remaining touch is communicated on 01139 /// touch channel zero, even as the Touch ID remains as originally 01140 /// reported (1 in this example). In this way, it is easy to track 01141 /// a specific touch. 01142 /// 01143 /// It is possible to query the data for a channel that is not 01144 /// presently reported as touched. 01145 /// 01146 /// @param[in] channel is the touch channel, from 0 to 4, or 0 to TouchChannels()-1 01147 /// It defaults to 0, in case the user is not interested in multi-touch. 01148 /// @returns the touch ID, or 15 if you get the ID for an untouched channel. 01149 /// @returns 0 if an invalid channel is queried. 01150 /// 01151 uint8_t TouchID(uint8_t channel = 0); 01152 01153 /// Get the Touch Code for a touch channel. 01154 /// 01155 /// It is possible to query the data for a channel that is not 01156 /// presently reported as touched. 01157 /// 01158 /// @param[in] channel is the touch channel, from 0 to 4, or 0 to TouchChannels()-1 01159 /// It defaults to 0, in case the user is not interested in multi-touch. 01160 /// @returns the touch code (@ref TouchCode_t). 01161 /// @returns channel 0 information if an invalid channel is queried. 01162 /// 01163 TouchCode_t TouchCode(uint8_t channel = 0); 01164 01165 01166 /// Get the coordinates for a touch channel. 01167 /// 01168 /// This returns the (X,Y) coordinates for a touch channel. 01169 /// 01170 /// 01171 /// It is possible to query the data for a channel that is not 01172 /// presently reported as touched. 01173 /// 01174 /// @param[in] channel is an optional touch channel, from 0 to 4, or 0 to TouchChannels()-1. 01175 /// It defaults to 0, in case the user is not interested in multi-touch. 01176 /// @returns the coordinates as a point_t structure. 01177 /// @returns channel 0 information if an invalid channel is queried. 01178 /// 01179 point_t TouchCoordinates(uint8_t channel = 0); 01180 01181 01182 /// Poll the TouchPanel and on a touch event return the a to d filtered x, y coordinates. 01183 /// 01184 /// This method reads the touch controller, which has a 10-bit range for each the 01185 /// x and the y axis. 01186 /// 01187 /// @note The returned values are not in display (pixel) units but are in analog to 01188 /// digital converter units. 01189 /// 01190 /// @note This API is usually not needed and is likely to be deprecated. 01191 /// See @ref TouchPanelComputeCalibration. 01192 /// See @ref TouchPanelReadable. 01193 /// 01194 /// @param[out] x is the x scale a/d value. 01195 /// @param[out] y is the y scale a/d value. 01196 /// @returns a value indicating the state of the touch, 01197 /// - no_cal: no calibration matrix is available, touch coordinates are not returned. 01198 /// - no_touch: no touch is detected, touch coordinates are not returned. 01199 /// - touch: touch is detected, touch coordinates are returned. 01200 /// - held: held after touch, touch coordinates are returned. 01201 /// - release: indicates a release, touch coordinates are returned. 01202 /// 01203 TouchCode_t TouchPanelA2DFiltered(int *x, int *y); 01204 01205 01206 /// Poll the TouchPanel and on a touch event return the a to d raw x, y coordinates. 01207 /// 01208 /// This method reads the touch controller, which has a 10-bit range for each the 01209 /// x and the y axis. A number of samples of the raw data are taken, filtered, 01210 /// and the results are returned. 01211 /// 01212 /// @note The returned values are not in display (pixel) units but are in analog to 01213 /// digital converter units. 01214 /// 01215 /// @note This API is usually not needed and is likely to be deprecated. 01216 /// See @ref TouchPanelComputeCalibration. 01217 /// See @ref TouchPanelReadable. 01218 /// 01219 /// @param[out] x is the x scale a/d value. 01220 /// @param[out] y is the y scale a/d value. 01221 /// @returns a value indicating the state of the touch, 01222 /// - no_cal: no calibration matrix is available, touch coordinates are not returned. 01223 /// - no_touch: no touch is detected, touch coordinates are not returned. 01224 /// - touch: touch is detected, touch coordinates are returned. 01225 /// - held: held after touch, touch coordinates are returned. 01226 /// - release: indicates a release, touch coordinates are returned. 01227 /// 01228 TouchCode_t TouchPanelA2DRaw(int *x, int *y); 01229 01230 01231 /// Wait for a touch panel touch and return it. 01232 /// 01233 /// This method is similar to Serial.getc() in that it will wait for a touch 01234 /// and then return. In order to extract the coordinates of the touch, a 01235 /// valid pointer to a point_t must be provided. 01236 /// 01237 /// @note There is no timeout on this function, so its use is not recommended. 01238 /// 01239 /// @code 01240 /// Timer t; 01241 /// t.start(); 01242 /// do { 01243 /// point_t point = {0, 0}; 01244 /// display.TouchPanelGet(&point); // hangs here until touch 01245 /// display.pixel(point, Red); 01246 /// } while (t.read_ms() < 30000); 01247 /// @endcode 01248 /// 01249 /// @param[out] TouchPoint is the touch point, if a touch is registered. 01250 /// @returns a value indicating the state of the touch, 01251 /// - no_cal: no calibration matrix is available, touch coordinates are not returned. 01252 /// - no_touch: no touch is detected, touch coordinates are not returned. 01253 /// - touch: touch is detected, touch coordinates are returned. 01254 /// - held: held after touch, touch coordinates are returned. 01255 /// - release: indicates a release, touch coordinates are returned. 01256 /// 01257 TouchCode_t TouchPanelGet(point_t * TouchPoint); 01258 01259 01260 /// Configuration Option for the Resistive Touch Panel Calibration. 01261 /// 01262 /// This method is only useful for the resistive touchscreen. 01263 /// 01264 /// Also, this method is optional - the user can take all of the responsibility 01265 /// in their code, or for simplicity sake, this API can be used prior 01266 /// to the init method. 01267 /// 01268 /// @code 01269 /// RA8875 lcd(p5, p6, p7, p12, NC); 01270 /// ... 01271 /// LocalFileSystem local(); 01272 /// // Be sure you previously mounted the "/sd" file system to put the cal there. 01273 /// lcd.ResTouchPanelCfg("/sd/tpcal.cfg", "Touch '+' to calibrate the touch panel"); 01274 /// 01275 /// // Only if the touch panel is enabled, AND is configured as the resistive 01276 /// // panel will the prior command be useful. 01277 /// lcd.init(LCD_PHYS_W,LCD_PHYS_H,LCD_C,40, false, true); 01278 /// 01279 /// @endcode 01280 /// 01281 /// @param[in] tpFQFN is a pointer to a fully qualified read-write accessible 01282 /// filename where the calibration is held. 01283 /// @param[in] tpCalMessage is an optional pointer to a message shown to the 01284 /// user in the calibration process. 01285 /// - If this parameter is not included, a default message will be shown. 01286 /// - If this parameter points to a NULL string, no message is shown. 01287 /// - If this parameter points to a non-NULL string, that string will be shown. 01288 /// 01289 void ResTouchPanelCfg(const char * tpFQFN = NULL, const char * tpCalMessage = NULL); 01290 01291 01292 /// Calibrate the touch panel. 01293 /// 01294 /// This method accepts two lists - one list is target points in , 01295 /// display coordinates and the other is a lit of raw touch coordinate 01296 /// values. It generates a calibration matrix for later use. This 01297 /// matrix is also accessible to the calling API, which may store 01298 /// the matrix in persistent memory and then install the calibration 01299 /// matrix on the next power cycle. By doing so, it can avoid the 01300 /// need to calibrate on every power cycle. 01301 /// 01302 /// @note The methods "TouchPanelComputeCalibration", "TouchPanelReadable", and 01303 /// indirectly the "TouchPanelSetMatrix" methods are all derived 01304 /// from a program by Carlos E. Vidales. See the copyright note 01305 /// for further details. See also the article 01306 /// http://www.embedded.com/design/system-integration/4023968/How-To-Calibrate-Touch-Screens 01307 /// 01308 /// @copyright Copyright © 2001, Carlos E. Vidales. All rights reserved. 01309 /// This sample program was written and put in the public domain 01310 /// by Carlos E. Vidales. The program is provided "as is" 01311 /// without warranty of any kind, either expressed or implied. 01312 /// If you choose to use the program within your own products 01313 /// you do so at your own risk, and assume the responsibility 01314 /// for servicing, repairing or correcting the program should 01315 /// it prove defective in any manner. 01316 /// You may copy and distribute the program's source code in any 01317 /// medium, provided that you also include in each copy an 01318 /// appropriate copyright notice and disclaimer of warranty. 01319 /// You may also modify this program and distribute copies of 01320 /// it provided that you include prominent notices stating 01321 /// that you changed the file(s) and the date of any change, 01322 /// and that you do not charge any royalties or licenses for 01323 /// its use. 01324 /// 01325 /// @param[in] display is a pointer to a set of 3 points, which 01326 /// are in display units of measure. These are the targets 01327 /// the calibration was aiming for. 01328 /// @param[in] screen is a pointer to a set of 3 points, which 01329 /// are in touchscreen units of measure. These are the 01330 /// registered touches. 01331 /// @param[out] matrix is an optional parameter to hold the calibration matrix 01332 /// as a result of the calibration. This can be saved in 01333 /// non-volatile memory to recover the calibration after a power fail. 01334 /// @returns @ref RetCode_t value. 01335 /// 01336 RetCode_t TouchPanelComputeCalibration(point_t display[3], point_t screen[3], tpMatrix_t * matrix); 01337 01338 01339 /// Perform the touch panel calibration process. 01340 /// 01341 /// This method provides the easy "shortcut" to calibrating the touch panel. 01342 /// The process will automatically generate the calibration points, present 01343 /// the targets on-screen, detect the touches, compute the calibration 01344 /// matrix, and optionally provide the calibration matrix to the calling code 01345 /// for persistence in non-volatile memory. 01346 /// 01347 /// @param[out] matrix is an optional parameter to hold the calibration matrix 01348 /// as a result of the calibration. This can be saved in 01349 /// non-volatile memory to recover the calibration after a power fail. 01350 /// @returns @ref RetCode_t value. 01351 /// 01352 RetCode_t TouchPanelCalibrate(tpMatrix_t * matrix = NULL); 01353 01354 01355 /// Perform the touch panel calibration process. 01356 /// 01357 /// This method provides the easy "shortcut" to calibrating the touch panel. 01358 /// The process will automatically generate the calibration points, present 01359 /// the targets on-screen, detect the touches, compute the calibration 01360 /// matrix, and optionally provide the calibration matrix to the calling code 01361 /// for persistence in non-volatile memory. 01362 /// 01363 /// @param[in] msg is a text message to present on the screen during the 01364 /// calibration process. 01365 /// @param[out] matrix is an optional parameter to hold the calibration matrix 01366 /// as a result of the calibration. This can be saved in 01367 /// non-volatile memory to recover the calibration after a power fail. 01368 /// @param[in] maxwait_s is the maximum number of seconds to wait for a touch 01369 /// calibration. If no touch panel installed, it then reports 01370 /// touch_cal_timeout. Default: 30 s. 01371 /// @returns @ref RetCode_t value. 01372 /// 01373 RetCode_t TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix = NULL, int maxwait_s = 30); 01374 01375 01376 /// Set the calibration matrix for the resistive touch panel. 01377 /// 01378 /// This method is used to set the calibration matrix for the touch panel. After 01379 /// performing the calibration (See @ref TouchPanelComputeCalibration), the matrix can be stored. 01380 /// On a subsequence power cycle, the matrix may be restored from non-volatile and 01381 /// passed in to this method. It will then be held to perform the corrections when 01382 /// reading the touch panel point. 01383 /// 01384 /// @code 01385 /// FILE * fh = fopen("/local/tpmatrix.cfg", "r"); 01386 /// if (fh) { 01387 /// tpMatrix_t matrix; 01388 /// if (fread(fh, &matrix, sizeof(tpMatrix_t))) { 01389 /// lcd.TouchPanelSetMatrix(&matrix); 01390 /// } 01391 /// fclose(fh); 01392 /// } 01393 /// @endcode 01394 /// 01395 /// @param[in] matrix is a pointer to the touch panel calibration matrix. 01396 /// @returns @ref RetCode_t value. 01397 /// 01398 /// 01399 RetCode_t TouchPanelSetMatrix(tpMatrix_t * matrix); 01400 01401 /// Get the calibration matrix for the resistive touch panel. 01402 /// 01403 /// This method returns a const pointer to the matrix. If this matrix has 01404 /// not be set, with either the TouchPanelSetMatrix API or the calibration 01405 /// process, the results are indeterminate. 01406 /// 01407 /// return const tpMatrix_t pointer 01408 /// 01409 const tpMatrix_t * TouchPanelGetMatrix(); 01410 01411 #if 0 01412 /// Append interrupt handler for specific RA8875 interrupt source 01413 /// 01414 /// @param[in] bISRType Interrupt Source, should be: 01415 /// - RA8875_INT_KEYSCAN: KEYCAN interrupt 01416 /// - RA8875_INT_DMA: DMA interrupt 01417 /// - RA8875_INT_TP: Touch panel interrupt 01418 /// - RA8875_INT_BTE: BTE process complete interrupt 01419 /// - RA8875_INT_BTEMCU_FONTWR: Multi-purpose interrupt (see spec sheet) 01420 /// @param[in] fptr is a callback function to handle the interrupt event. 01421 /// @returns none 01422 /// 01423 void AppendISR(uint8_t bISRType, void(*fptr)(void)); 01424 01425 /// Unappend interrupt handler for specific RA8875 interrupt source 01426 /// 01427 /// @param[in] bISRType Interrupt Source, should be: 01428 /// - RA8875_INT_KEYSCAN: KEYCAN interrupt 01429 /// - RA8875_INT_DMA: DMA interrupt 01430 /// - RA8875_INT_TP: Touch panel interrupt 01431 /// - RA8875_INT_BTE: BTE process complete interrupt 01432 /// - RA8875_INT_BTEMCU_FONTWR: Multi-purpose interrupt (see spec sheet) 01433 /// @return none 01434 /// 01435 void UnAppendISR(uint8_t bISRType); 01436 #endif 01437 01438 01439 /// Initialize the keypad interface on the RA8875 controller. 01440 /// 01441 /// Enables the keypad subsystem. It will scan the 4 x 5 matrix 01442 /// and make available key presses. See also @ref SetKeyMap(). 01443 /// 01444 /// @note See section 5-13 of RAIO RA8875 data sheet for more details. 01445 /// @note When using the display from buy-display.com, be sure that 01446 /// the option for the keypad is configured on the hardware. 01447 /// 01448 /// All parameters are optional. 01449 /// @param[in] scanEnable when true, enables the key scan function (default: true). 01450 /// @param[in] longDetect when true, additionally enables the long key held detection (default: false). 01451 /// @param[in] sampleTime setting (range: 0 - 3, default: 0). 01452 /// @param[in] scanFrequency setting (range: 0 - 7, default: 0). 01453 /// @param[in] longTimeAdjustment (range: 0 - 3, default: 0). 01454 /// @param[in] interruptEnable when true, enables interrupts from keypress (default: false). 01455 /// @param[in] wakeupEnable when true, activates the wakeup function (default: false). 01456 /// 01457 /// @returns @ref RetCode_t value. 01458 /// 01459 RetCode_t KeypadInit(bool scanEnable = true, bool longDetect = false, 01460 uint8_t sampleTime = 0, uint8_t scanFrequency = 0, 01461 uint8_t longTimeAdjustment = 0, 01462 bool interruptEnable = false, bool wakeupEnable = false); 01463 01464 01465 /// Create Key Code definitions for the key matrix. 01466 /// 01467 /// This API provides a table of 22 key-code assignments for the matrix of keys. 01468 /// See also KeypadInit(). 01469 /// This can be used to translate the keys 1 - 20 into some other value, as 01470 /// well as to communicate the "no key" (zero) and "error state" (21). 01471 /// 01472 /// In this way, a keypad could easily emulate a piece of a keyboard, transforming 01473 /// 0 - 20 into the values 0, '0', '1', '2', '3', '4', '5', '6', '7', '8', 01474 /// '9', '+', '-', '*' , '/', '=', '(bs)', '(cr)', and so on... 01475 /// 01476 /// @code 01477 /// // Return Value by Row, Column Example reassignment 01478 /// // Column 0 1 2 3 4 01479 /// // +-------------------------+ +-------------------------+ 01480 /// // Row 0 | 1 2 3 4 5 | | '7' '8' '9' ',' '<-' | 01481 /// // 1 | 6 7 8 9 10 | | '4' '5' '6' '/' '-' | 01482 /// // 2 | 11 12 13 14 15 | | '1' '2' '3' '*' '+' | 01483 /// // 3 | 16 17 18 19 20 | | '0' '.' '(' ')' '\n' | 01484 /// // +-------------------------+ +-------------------------+ 01485 /// // Return value 0 = No Key pressed 01486 /// // Return value 21 = Error 01487 /// const uint8_t CodeList[22] = 01488 /// {0, '7', '8', '9', ',', '\h', 01489 /// '4', '5', '6', '/', '-', 01490 /// '1', '2', '3', '*', '+', 01491 /// '0', '.', '(', ')', '\n', 01492 /// '\x1b'}; 01493 /// lcd.SetKeyMap(CodeList); 01494 /// @endcode 01495 /// 01496 /// @param[in] CodeList is a pointer to an always available byte-array 01497 /// where the first 22 bytes are used as the transformation 01498 /// from raw code to your reassigned value. 01499 /// If CodeList is NULL, the original raw value key map is 01500 /// restored. 01501 /// @returns @ref RetCode_t value. 01502 /// 01503 RetCode_t SetKeyMap(const uint8_t * CodeList = NULL); 01504 01505 01506 /// Determine if a key has been hit 01507 /// 01508 /// @returns true if a key has been hit 01509 /// 01510 bool readable(); 01511 01512 01513 /// Blocking read of the keypad. 01514 /// 01515 /// @note: This is a blocking read, so it is important to first call _kbhit() 01516 /// to avoid hanging your processes. 01517 /// 01518 /// A keypad connected to the RA8875 is connected in a matrix of 4 rows and 5 columns. 01519 /// When pressed, this method will return a code in the range of 1 through 20, reserving 01520 /// the value 0 to indicate that no key is pressed. 01521 /// 01522 /// Additionally, if configured to detect a "long press", bit 7 will be set to indicate 01523 /// this. In this situation, first a "normal press" would be detected and signaled and 01524 /// soon after that a "long press" of the same key would be detected and communicated. 01525 /// 01526 /// @return 8-bit where bit 7 indicates a long press. The remaining bits indicate the 01527 /// keypress using 0 = no key pressed, 1 - 20 = the key pressed. 01528 /// 01529 uint8_t getc(); 01530 01531 01532 /// Align one rectangle against another. 01533 /// 01534 /// This will accept a rectangle to align and align it against another rectangle. 01535 /// It would be most typical if the rectangle to align is smaller than the reference rectangle. 01536 /// 01537 /// @param[in] toAlign is a rectangular region to align against another. 01538 /// @param[in] inRect is a rectangle to align against. 01539 /// @param[in] v specifies the vertical alignment - top, middle, bottom. 01540 /// @param[in] h specified the horizontal alignment - left, center, right. 01541 /// @returns a new rectangle, the size of the toAlign. 01542 /// 01543 rect_t AlignRectInRect(rect_t toAlign, rect_t inRect, valign_t v, halign_t h); 01544 01545 /// Determine if a point is within a rectangle. 01546 /// 01547 /// @param[in] rect is a rectangular region to use. 01548 /// @param[in] p is a point to analyze to see if it is within the rect. 01549 /// @returns true if p is within rect. 01550 /// 01551 bool Intersect(rect_t rect, point_t p); 01552 01553 /// Determine if a rectangle intersects another rectangle. 01554 /// 01555 /// @param[in] rect1 is a rectangular region. 01556 /// @param[in] rect2 is a second rectangular region. 01557 /// @returns true if any part of rect2 intersects rect1. 01558 /// 01559 bool Intersect(rect_t rect1, rect_t rect2); 01560 01561 /// Determine if a rectangle intersects another rectangle and provides 01562 /// the area of intersection. 01563 /// 01564 /// @code 01565 /// +---------------------+ 01566 /// | rect1 | 01567 /// | | 01568 /// | +------------------+ 01569 /// | | rect3 | | 01570 /// | | | | 01571 /// +---------------------+ | 01572 /// | rect2 | 01573 /// +------------------+ 01574 /// @endcode 01575 /// 01576 /// @note that the first parameter is a pointer to a rect and the 01577 /// 01578 /// @param[inout] pRect1 is a pointer to a rectangular region, and returns 01579 /// the area of intersection. 01580 /// @param[in] pRect2 is a pointer to a second rectangular region. 01581 /// @returns true if pRect1 and pRect2 intersect and pRect1 is written with 01582 /// the rectangle describing the intersection. 01583 /// 01584 bool Intersect(rect_t * pRect1, const rect_t * pRect2); 01585 01586 01587 /// Write a command to the display with a word of data. 01588 /// 01589 /// This is a high level command, and may invoke several primitives. 01590 /// 01591 /// @param[in] command is the command to write. 01592 /// @param[in] data is data to be written to the command register. 01593 /// @returns @ref RetCode_t value. 01594 /// 01595 RetCode_t WriteCommandW(uint8_t command, uint16_t data); 01596 01597 01598 /// Write a command to the display 01599 /// 01600 /// This is a high level command, and may invoke several primitives. 01601 /// 01602 /// @param[in] command is the command to write. 01603 /// @param[in] data is optional data to be written to the command register 01604 /// and only occurs if the data is in the range [0 - 0xFF]. 01605 /// @returns @ref RetCode_t value. 01606 /// 01607 virtual RetCode_t WriteCommand(unsigned char command, unsigned int data = 0xFFFF); 01608 01609 01610 /// Write a data word to the display 01611 /// 01612 /// This is a high level command, and may invoke several primitives. 01613 /// 01614 /// @param[in] data is the data to write. 01615 /// @returns @ref RetCode_t value. 01616 /// 01617 RetCode_t WriteDataW(uint16_t data); 01618 01619 01620 /// Write a data byte to the display 01621 /// 01622 /// This is a high level command, and may invoke several primitives. 01623 /// 01624 /// @param[in] data is the data to write. 01625 /// @returns @ref RetCode_t value. 01626 /// 01627 virtual RetCode_t WriteData(unsigned char data); 01628 01629 01630 /// Read a command register 01631 /// 01632 /// @param[in] command is the command register to read. 01633 /// @returns the value read from the register. 01634 /// 01635 unsigned char ReadCommand(unsigned char command); 01636 01637 01638 /// Read a word from a command register 01639 /// 01640 /// @param[in] command is the command register to read. 01641 /// @returns the value read from the register. 01642 /// 01643 uint16_t ReadCommandW(unsigned char command); 01644 01645 01646 /// Read a data byte from the display 01647 /// 01648 /// This is a high level command, and may invoke several primitives. 01649 /// 01650 /// @returns data that was read. 01651 /// 01652 unsigned char ReadData(void); 01653 01654 01655 /// Read a word from the display 01656 /// 01657 /// This is a high level command, and may invoke several primitives. 01658 /// 01659 /// @returns data that was read. 01660 /// 01661 uint16_t ReadDataW(void); 01662 01663 01664 /// Read the display status 01665 /// 01666 /// This is a high level command, and may invoke several primitives. 01667 /// 01668 /// @returns data that was read. 01669 /// 01670 unsigned char ReadStatus(void); 01671 01672 01673 /// get the width in pixels of the currently active font 01674 /// 01675 /// @returns font width in pixels. 01676 /// 01677 dim_t fontwidth(void); 01678 01679 01680 /// get the height in pixels of the currently active font 01681 /// 01682 /// @returns font height in pixels. 01683 /// 01684 dim_t fontheight(void); 01685 01686 01687 /// get the number of colums based on the currently active font 01688 /// 01689 /// @returns number of columns. 01690 /// 01691 virtual int columns(void); 01692 01693 01694 /// get the number of rows based on the currently active font 01695 /// 01696 /// @returns number of rows. 01697 /// 01698 virtual int rows(void); 01699 01700 01701 /// get the screen width in pixels 01702 /// 01703 /// @returns screen width in pixels. 01704 /// 01705 virtual dim_t width(void); 01706 01707 01708 /// get the screen height in pixels 01709 /// 01710 /// @returns screen height in pixels. 01711 /// 01712 virtual dim_t height(void); 01713 01714 01715 /// get the color depth in bits per pixel. 01716 /// 01717 /// @returns 8 or 16 only. 01718 /// 01719 virtual dim_t color_bpp(void); 01720 01721 /// Set cursor position based on the current font size. 01722 /// 01723 /// @param[in] column is the horizontal position in character positions 01724 /// @param[in] row is the vertical position in character positions 01725 /// @returns @ref point_t value that was the last location. 01726 /// 01727 virtual point_t locate(textloc_t column, textloc_t row); 01728 01729 /// Enable word-wrap in _puts() 01730 /// 01731 /// @todo Consider adding a method to define the word-delimiters, which could then 01732 /// include user-selection of characters (e.g. ' ', '-', ';', and so on). 01733 /// 01734 /// @param[in] _wordwrap when true controls _puts() to wrap on word-boundary, which 01735 /// is delimited by 'space' character or 'cr' 'lf' sequences. 01736 /// @returns previous wordwrap setting to permit an easy restore. 01737 /// 01738 bool SetWordWrap(bool _wordwrap); 01739 01740 01741 /// Prepare the controller to write text to the screen by positioning 01742 /// the cursor. 01743 /// 01744 /// @note If the cursor location is not valid (not on-screen), the 01745 /// cursor is not set and no error is generated. 01746 /// 01747 /// @code 01748 /// lcd.SetTextCursor(100, 25); 01749 /// lcd.puts("Hello"); 01750 /// @endcode 01751 /// 01752 /// @param[in] x is the horizontal position in pixels (from the left edge) 01753 /// @param[in] y is the vertical position in pixels (from the top edge) 01754 /// @returns @ref point_t value with the prior cursor position. 01755 /// 01756 point_t SetTextCursor(loc_t x, loc_t y); 01757 01758 01759 /// Prepare the controller to write text to the screen by positioning 01760 /// the cursor. 01761 /// 01762 /// @note If the cursor location is not valid (not on-screen), the 01763 /// cursor is not set. 01764 /// 01765 /// @code 01766 /// point_t point = {100, 25}; 01767 /// lcd.SetTextCursor(point); 01768 /// lcd.puts("Hello"); 01769 /// @endcode 01770 /// 01771 /// @param[in] p is the x:y point in pixels from the top-left. 01772 /// @returns @ref point_t value with the prior cursor position. 01773 /// 01774 point_t SetTextCursor(point_t p); 01775 01776 01777 /// Get the current cursor position in pixels. 01778 /// 01779 /// @code 01780 /// point_t point = GetTextCursor(); 01781 /// if (point.x > 100 && point.y > 150) 01782 /// //... 01783 /// @endcode 01784 /// 01785 /// @returns cursor position. 01786 /// 01787 point_t GetTextCursor(void); 01788 01789 01790 /// Get the current cursor horizontal position in pixels. 01791 /// 01792 /// @returns cursor position horizontal offset. 01793 /// 01794 loc_t GetTextCursor_X(void); 01795 01796 01797 /// Get the current cursor vertical position in pixels. 01798 /// 01799 /// @returns cursor position vertical offset. 01800 /// 01801 loc_t GetTextCursor_Y(void); 01802 01803 01804 /// Configure additional Cursor Control settings. 01805 /// 01806 /// This API lets you modify other cursor control settings; 01807 /// Cursor visible/hidden, Cursor blink/normal, 01808 /// Cursor I-Beam/underscore/box. 01809 /// 01810 /// @param[in] cursor can be set to NOCURSOR (default), IBEAM, 01811 /// UNDER, or BLOCK. 01812 /// @param[in] blink can be set to true or false (default false) 01813 /// @returns @ref RetCode_t value. 01814 /// 01815 RetCode_t SetTextCursorControl(cursor_t cursor = NOCURSOR, bool blink = false); 01816 01817 01818 /// Select the built-in ISO 8859-X font to use next. 01819 /// 01820 /// Supported fonts: ISO 8859-1, -2, -3, -4 01821 /// 01822 /// @note This only modifies the choice of font from the RA8875 internal 01823 /// fonts. 01824 /// 01825 /// @param[in] font selects the font for the subsequent text rendering. 01826 /// 01827 /// @note if either hScale or vScale is outside of its permitted range, 01828 /// the command is not executed. 01829 /// @returns @ref RetCode_t value. 01830 /// 01831 RetCode_t SetTextFont(font_t font = ISO8859_1); 01832 01833 01834 /// Translate an (x,y) orientation in the display hardware coordinates 01835 /// into (x,y) coordinates given the current orientation. 01836 /// 01837 /// @param[in] x is the hardware x coordinate 01838 /// @param[in] y is the hardware y coordinate 01839 /// @returns the translated coordinates as a point 01840 /// 01841 point_t TranslateOrientation(loc_t x, loc_t y); 01842 01843 01844 /// Gets the display orientation 01845 /// 01846 01847 /// @returns the basic display orientationas an @ref orientation_t value. 01848 /// 01849 orientation_t GetGraphicsOrientation(); 01850 01851 /// Sets the basic graphics orientation. 01852 /// 01853 /// @note This command does not let you "merge" text onto an existing 01854 /// image, since it reuses the memory for the new orientation. 01855 /// Therefore, it is recommended that you issue a cls() prior 01856 /// to sending text to the screen, or you end with a blended 01857 /// image that is probably not as intended. 01858 /// 01859 /// @note This command only operates on the RA8875 internal fonts. 01860 /// 01861 /// @note more sophisticated control of drawings with rotated text may 01862 /// be achieved by direct control of the registers. See the RA8875 01863 /// datasheet. 01864 /// 01865 /// @code 01866 /// lcd.cls(); 01867 /// lcd.SetGraphicsOrientation(RA8875::normal); 01868 /// lcd.puts(30,30, "Normal Landscape"); 01869 /// wait_us(2500000); 01870 /// 01871 /// lcd.cls(); 01872 /// lcd.SetGraphicsOrientation(RA8875::rotate_90); 01873 /// lcd.puts(30,30, "Rotated 90 Text\r\n"); 01874 /// wait_us(2500000); 01875 /// 01876 /// lcd.cls(); 01877 /// lcd.SetGraphicsOrientation(RA8875::rotate_180); 01878 /// lcd.puts(30,30, "Rotated 180 Text\r\n"); 01879 /// wait_us(2500000); 01880 /// 01881 /// lcd.cls(); 01882 /// lcd.SetGraphicsOrientation(RA8875::rotate_270); 01883 /// lcd.puts(30,30, "Rotated 270 Text\r\n"); 01884 /// wait_us(2500000); 01885 /// @endcode 01886 /// 01887 /// @param[in] angle defaults to normal, but can be rotated 01888 /// - normal | rotate_0 01889 /// - rotate_90 (clockwise) 01890 /// - rotate_180 01891 /// - rotate_270 (clockwise) 01892 /// @returns @ref RetCode_t value. 01893 /// 01894 orientation_t SetGraphicsOrientation(orientation_t angle = normal); 01895 01896 /// Sets the text orientation - Normal or 90 degree. 01897 /// 01898 /// @attention This command is experimental. 01899 /// 01900 /// @note This command does not let you "merge" text onto an existing 01901 /// image, since it reuses the memory for the new orientation. 01902 /// Therefore, it is recommended that you issue a cls() prior 01903 /// to sending text to the screen, or you end with a blended 01904 /// image that is probably not as intended. 01905 /// 01906 /// @note This command only operates on the RA8875 internal fonts. 01907 /// 01908 /// @code 01909 /// lcd.cls(); 01910 /// lcd.SetTextFontOrientation(RA8875::normal); 01911 /// lcd.puts(30,30, "Normal Landscape"); 01912 /// wait_us(2500000); 01913 /// 01914 /// lcd.cls(); 01915 /// lcd.SetTextFontOrientation(RA8875::rotate_90); 01916 /// lcd.puts(30,30, "Rotated 90 Text\r\n"); 01917 /// wait_us(2500000); 01918 /// 01919 /// lcd.cls(); 01920 /// lcd.SetTextFontOrientation(RA8875::rotate_180); 01921 /// lcd.puts(30,30, "Rotated 180 Text\r\n"); 01922 /// wait_us(2500000); 01923 /// 01924 /// lcd.cls(); 01925 /// lcd.SetTextFontOrientation(RA8875::rotate_270); 01926 /// lcd.puts(30,30, "Rotated 270 Text\r\n"); 01927 /// wait_us(2500000); 01928 /// @endcode 01929 /// 01930 /// @param[in] angle defaults to normal, but can be rotated 01931 /// - normal | rotate_0 01932 /// - rotate_90 (sets the 90 degree display bit) 01933 /// - rotate_180 01934 /// - rotate_270 (sets the 90 degree display bit) 01935 /// @returns @ref RetCode_t value. 01936 /// 01937 orientation_t SetTextFontOrientation(orientation_t angle); 01938 01939 01940 /// Control the font behavior. 01941 /// 01942 /// This command lets you make several modifications to any text that 01943 /// will be written to the screen. 01944 /// 01945 /// @note This command only operates on the RA8875 internal fonts. 01946 /// 01947 /// Options can be combined: 01948 /// Default: 01949 /// @li Full alignment disabled, 01950 /// @li Font with Background color, 01951 /// @li Font in normal orientiation, or rotated 90, 180, or 270 clockwise, 01952 /// @li Horizontal scale x 1, 2, 3, or 4 01953 /// @li Vertical scale x 1, 2, 3, or 4 01954 /// 01955 /// @note alignment is a special mode for the fonts, when mixing half and 01956 /// full fonts on one presentation. 'align_full' starts each full 01957 /// character on an even alignment. See section 7-4-7 of the RA8875 01958 /// specification. 01959 /// 01960 /// @param[in] fillit defaults to FILL, but can be NOFILL 01961 /// @param[in] hScale defaults to 1, but can be 1, 2, 3, or 4, 01962 /// and scales the font size by this amount. 01963 /// @param[in] vScale defaults to 1, but can be 1, 2, 3, or 4, 01964 /// and scales the font size by this amount. 01965 /// @param[in] alignment defaults to align_none, but can be 01966 /// align_full. 01967 /// 01968 /// @note if either hScale or vScale is outside of its permitted range, 01969 /// the command is not executed. 01970 /// @returns @ref RetCode_t value. 01971 /// 01972 RetCode_t SetTextFontControl(fill_t fillit = FILL, 01973 HorizontalScale hScale = 1, 01974 VerticalScale vScale = 1, 01975 alignment_t alignment = align_none); 01976 01977 01978 /// Control the font - to background fill or "ink-only" 01979 /// 01980 /// This command configures the font presentation to write 01981 /// only the font "ink", or to write the ink and also overwrite 01982 /// the background with the background color. 01983 /// 01984 /// @note This command applies only to the internal fonts not to user fonts 01985 /// e.g. SelectUserFont(...) out of concerns for performance. 01986 /// User fonts always write the character block as a continuous 01987 /// stream (for efficiency). This precludes first reading the 01988 /// character block before writing it. Alternately, addressing 01989 /// individual pixels would also be a significant performance 01990 /// impact. 01991 /// 01992 /// @param[in] fillit set to FILL will also write the background, 01993 /// and set to NOFILL will write only the ink. 01994 /// @returns the previous fill setting permitting easy restore. 01995 /// 01996 fill_t SetTextFontFill(fill_t fillit); 01997 01998 /// Control the font size of the RA8875 rendered fonts. 01999 /// 02000 /// This command lets you set the font enlargement for both horizontal 02001 /// and vertical, independent of the rotation, background, and 02002 /// alignment. See @ref SetTextFontControl. 02003 /// 02004 /// @note This command operates on the RA8875 internal fonts. 02005 /// @note This command also operates on the selected soft font. 02006 /// 02007 /// @param[in] hScale defaults to 1, but can be 1, 2, 3, or 4, 02008 /// and scales the font size by this amount. 02009 /// @param[in] vScale is an optional parameter that defaults to the hScale value, 02010 /// but can be 1, 2, 3, or 4, and scales the font size by this amount. 02011 /// 02012 /// @code 02013 /// lcd.SetTextFontSize(2); // Set the font to 2x normal size 02014 /// lcd.puts("Two times"); 02015 /// lcd.SetTextFontSize(2,3); // Set the font to 2x Width and 3x Height 02016 /// lcd.puts("2*2 3*h"); 02017 /// lcd.SetTextFontSize(); // Restore to normal size in both dimensions 02018 /// lcd.puts("normal"); 02019 /// lcd.SelectUserFont(BPG_Arial63x63); // Large user font 02020 /// lcd.puts("B63x63"); // Show a sample 02021 /// lcd.SetTextFontSize(2); // Now twice as big 02022 /// lcd.puts("x2"); // Show a sample 02023 /// @endcode 02024 /// 02025 /// @note if either hScale or vScale is outside of its permitted range, 02026 /// the command is not executed. 02027 /// @returns @ref RetCode_t value. 02028 /// 02029 RetCode_t SetTextFontSize(HorizontalScale hScale = 1, VerticalScale vScale = -1); 02030 02031 02032 /// Get the text font size of the RA8875 internal fonts. 02033 /// 02034 /// This command lets you retrieve the current settings for the font 02035 /// horizontal and vertical scale factors. The return value is 02036 /// one of the scale factors 1, 2, 3, or 4. 02037 /// 02038 /// @param[out] hScale is a pointer to memory where the horizontal scale factor 02039 /// will be written. If the pointer is null, that item will be ignored. 02040 /// @param[out] vScale is a pointer to memory where the vertical scale factor 02041 /// will be written. If the pointer is null, that item will be ignored. 02042 /// @returns @ref RetCode_t value. 02043 /// 02044 RetCode_t GetTextFontSize(HorizontalScale * hScale, VerticalScale * vScale); 02045 02046 /// Get the width of a string (or character) based on the current font. 02047 /// 02048 /// @param[in] text is a pointer to a text string to evaluate. 02049 /// @param[in] charOnly defaults to false, which computes over the whole string. 02050 /// @returns width in pixels, given the selected font and scale. 02051 /// 02052 dim_t GetTextWidth(const char* text, bool charOnly = false); 02053 02054 /// Get the rectange of a string (or character) based on the current font. 02055 /// 02056 /// @note This computes the rect without considering wordwrap. It will 02057 /// treat <cr> as a return to left margin and <lf> as a vertical 02058 /// advance. It will also use the currently selected font metrics, 02059 /// which includes proportional fonts. 02060 /// 02061 /// @param[in] text is a pointer to a text string to evaluate. 02062 /// @param[in] charOnly defaults to false, which computes over the whole string. 02063 /// @returns rectangle that holds this text, as a rect_t 02064 /// 02065 rect_t GetTextRect(const char* text, bool charOnly = false); 02066 02067 /// put a character on the screen. 02068 /// 02069 /// @param[in] c is the character. 02070 /// @returns the character, or EOF if there is an error. 02071 /// 02072 virtual int _putc(int c); 02073 02074 02075 /// Write string of text to the display 02076 /// 02077 /// @code 02078 /// lcd.puts("Test STring"); 02079 /// @endcode 02080 /// 02081 /// @param[in] string is the null terminated string to send to the display. 02082 /// 02083 void puts(const char * string); 02084 02085 02086 /// Write string of text to the display at the specified location. 02087 /// 02088 /// @code 02089 /// const point_t pt = {10, 25}; 02090 /// lcd.puts(pt, "Test STring"); 02091 /// @endcode 02092 /// 02093 /// @param[in] pt is the x,y position as a point 02094 /// @param[in] string is the null terminated string to send to the display. 02095 /// 02096 void puts(point_t pt, const char * string); 02097 02098 /// Write string of text to the display at the specified location. 02099 /// 02100 /// @code 02101 /// lcd.puts(10,25, "Test STring"); 02102 /// @endcode 02103 /// 02104 /// @param[in] x is the horizontal position in pixels (from the left edge) 02105 /// @param[in] y is the vertical position in pixels (from the top edge) 02106 /// @param[in] string is the null terminated string to send to the display. 02107 /// 02108 void puts(loc_t x, loc_t y, const char * string); 02109 02110 02111 /// Prepare the controller to write binary data to the screen by positioning 02112 /// the memory cursor. 02113 /// 02114 /// @param[in] x is the horizontal position in pixels (from the left edge) 02115 /// @param[in] y is the vertical position in pixels (from the top edge) 02116 /// @returns @ref RetCode_t value. 02117 /// 02118 virtual RetCode_t SetGraphicsCursor(loc_t x, loc_t y); 02119 02120 /// Prepare the controller to write binary data to the screen by positioning 02121 /// the memory cursor. 02122 /// 02123 /// @param[in] p is the point representing the cursor position to set 02124 /// @returns @ref RetCode_t value. 02125 /// 02126 virtual RetCode_t SetGraphicsCursor(point_t p); 02127 02128 /// Read the current graphics cursor position as a point. 02129 /// 02130 /// @returns the graphics cursor as a point. 02131 /// 02132 virtual point_t GetGraphicsCursor(void); 02133 02134 02135 /// Prepare the controller to read binary data from the screen by positioning 02136 /// the memory read cursor. 02137 /// 02138 /// @param[in] x is the horizontal position in pixels (from the left edge) 02139 /// @param[in] y is the vertical position in pixels (from the top edge) 02140 /// @returns @ref RetCode_t value. 02141 /// 02142 virtual RetCode_t SetGraphicsCursorRead(loc_t x, loc_t y); 02143 02144 02145 /// Set the window, constraining where items are written to the screen. 02146 /// 02147 /// After setting the window, text and graphics are constrained to this 02148 /// window. Text will wrap from the right edge back to the left and down 02149 /// one row and from the bottom to the top. Graphics drawing will be clipped 02150 /// at the edge of the window. 02151 /// 02152 /// @note If the initial text write is outside the window, it will be shown 02153 /// where the cursor position it. Once the write hits the right edge of 02154 /// the defined window, it will then wrap back to the left edge. Once it 02155 /// hits the bottom, it wraps to the top of the window. For this reason, 02156 /// it is common to set the text cursor to the window. 02157 /// 02158 /// @code 02159 /// rect_t r = {10,10, 90,90}; 02160 /// r = lcd.SetWindow(r); 02161 /// lcd.SetTextCursor(r.p1.x, r.p1.y); 02162 /// lcd.puts("012345678901234567890123456789012345678901234567890"); 02163 /// lcd.SetWindow(r); restore to previous window setting 02164 /// @endcode 02165 /// 02166 /// @param[in] r is the rect_t used to set the window. 02167 /// @returns the previous window definition. 02168 /// 02169 virtual rect_t SetWindow(rect_t r); 02170 02171 /// Set the window, constraining where items are written to the screen. 02172 /// 02173 /// After setting the window, text and graphics are constrained to this 02174 /// window. Text will wrap from the right edge back to the left and down 02175 /// one row and from the bottom to the top. Graphics drawing will be clipped 02176 /// at the edge of the window. 02177 /// 02178 /// @note if no parameters are provided, it restores the window to full screen. 02179 /// 02180 /// @note If the initial text write is outside the window, it will be shown 02181 /// where the cursor positions it. Once the write hits the right edge of 02182 /// the defined window, it will then wrap back to the left edge. Once it 02183 /// hits the bottom, it wraps to the top of the window. For this reason, 02184 /// it is common to set the text cursor to the window. 02185 /// 02186 /// @code 02187 /// lcd.SetWindow(10,10, 80,80); 02188 /// lcd.SetTextCursor(10,10); 02189 /// lcd.puts("012345678901234567890123456789012345678901234567890"); 02190 /// lcd.SetWindow(); restore to full screen 02191 /// @endcode 02192 /// 02193 /// @param[in] x1 is the left edge in pixels. 02194 /// @param[in] y1 is the top edge in pixels. 02195 /// @param[in] x2 is the right edge in pixels. 02196 /// @param[in] y2 is the bottom edge in pixels. 02197 /// @returns the previous window definition. 02198 /// 02199 virtual rect_t SetWindow(loc_t x1 = 0, loc_t y1 = 0, loc_t x2 = (loc_t)-1, loc_t y2 = (loc_t)-1); 02200 02201 /// Get the current window setting, which constrains what is written to the screen. 02202 /// 02203 /// @returns the current window definition. 02204 /// 02205 virtual rect_t GetWindow(); 02206 02207 02208 /// Clear either the specified layer, or the active layer. 02209 /// 02210 /// The behavior is to clear the whole screen for the specified 02211 /// layer. When not specified, the active drawing layer is cleared. 02212 /// This command can also be used to specifically clear either, 02213 /// or both layers. See @ref clsw(). 02214 /// 02215 /// @code 02216 /// lcd.cls(); 02217 /// @endcode 02218 /// 02219 /// @param[in] layers is optional. If not provided, the active layer 02220 /// is cleared. If bit 0 is set, layer 0 is cleared, if bit 02221 /// 1 is set, layer 1 is cleared. If both are set, both layers 02222 /// are cleared. Any other value does not cause an action. 02223 /// 02224 /// @returns @ref RetCode_t value. 02225 /// 02226 virtual RetCode_t cls(uint16_t layers = 0); 02227 02228 02229 /// Clear the screen, or clear only the active window. 02230 /// 02231 /// The default behavior is to clear the whole screen. With the optional 02232 /// parameter, the action can be restricted to the active window, which 02233 /// can be set with the See @ref SetWindow method. 02234 /// 02235 /// @code 02236 /// lcd.SetWindow(20,20, 40,10); 02237 /// lcd.clsw(); 02238 /// @endcode 02239 /// 02240 /// @param[in] region is an optional parameter that defaults to FULLWINDOW 02241 /// or may be set to ACTIVEWINDOW. 02242 /// @returns @ref RetCode_t value. 02243 /// 02244 RetCode_t clsw(RA8875::Region_t region = FULLWINDOW); 02245 02246 02247 /// Set the background color. 02248 /// 02249 /// @param[in] color is expressed in 16-bit format. 02250 /// @returns @ref color_t value as the previous background color. 02251 /// 02252 virtual color_t background(color_t color); 02253 02254 02255 /// Set the background color. 02256 /// 02257 /// @param[in] r is the red element of the color. 02258 /// @param[in] g is the green element of the color. 02259 /// @param[in] b is the blue element of the color. 02260 /// @returns @ref color_t value as the previous background color. 02261 /// 02262 virtual color_t background(unsigned char r, unsigned char g, unsigned char b); 02263 02264 02265 /// Set the foreground color. 02266 /// 02267 /// @param[in] color is expressed in 16-bit format. 02268 /// @returns @ref color_t value as the previous background color. 02269 /// 02270 virtual color_t foreground(color_t color); 02271 02272 02273 /// Set the foreground color. 02274 /// 02275 /// @param[in] r is the red element of the color. 02276 /// @param[in] g is the green element of the color. 02277 /// @param[in] b is the blue element of the color. 02278 /// @returns @ref color_t value as the previous background color. 02279 /// 02280 virtual color_t foreground(unsigned char r, unsigned char g, unsigned char b); 02281 02282 02283 /// Get the current foreground color value. 02284 /// 02285 /// @returns the current foreground color as @ref color_t. 02286 /// 02287 color_t GetForeColor(void); 02288 02289 02290 /// Get the current background color value. 02291 /// 02292 /// @returns the current background color as @ref color_t. 02293 /// 02294 color_t GetBackColor(void); 02295 02296 02297 /// Draw a pixel in the specified color. 02298 /// 02299 /// @note Unlike many other operations, this does not 02300 /// set the forecolor! 02301 /// 02302 /// @param[in] p is the point_t defining the location. 02303 /// @param[in] color is expressed in 16-bit format. 02304 /// @returns @ref RetCode_t value. 02305 /// 02306 virtual RetCode_t pixel(point_t p, color_t color); 02307 02308 02309 /// Draw a pixel in the current foreground color. 02310 /// 02311 /// @param[in] p is the point_t defining the location. 02312 /// @returns @ref RetCode_t value. 02313 /// 02314 virtual RetCode_t pixel(point_t p); 02315 02316 02317 /// Draw a pixel in the specified color. 02318 /// 02319 /// @note Unlike many other operations, this does not 02320 /// set the forecolor! 02321 /// 02322 /// @param[in] x is the horizontal offset to this pixel. 02323 /// @param[in] y is the vertical offset to this pixel. 02324 /// @param[in] color defines the color for the pixel. 02325 /// @returns @ref RetCode_t value. 02326 /// 02327 virtual RetCode_t pixel(loc_t x, loc_t y, color_t color); 02328 02329 02330 /// Draw a pixel in the current foreground color. 02331 /// 02332 /// @param[in] x is the horizontal offset to this pixel. 02333 /// @param[in] y is the veritical offset to this pixel. 02334 /// @returns @ref RetCode_t value. 02335 /// 02336 virtual RetCode_t pixel(loc_t x, loc_t y); 02337 02338 02339 /// Get a pixel from the display. 02340 /// 02341 /// @param[in] x is the horizontal offset to this pixel. 02342 /// @param[in] y is the vertical offset to this pixel. 02343 /// @returns the pixel. See @ref color_t 02344 /// 02345 virtual color_t getPixel(loc_t x, loc_t y); 02346 02347 02348 /// Write an RGB565 stream of pixels to the display. 02349 /// 02350 /// @param[in] p is a pointer to a color_t array to write. 02351 /// @param[in] count is the number of pixels to write. 02352 /// @param[in] x is the horizontal position on the display. 02353 /// @param[in] y is the vertical position on the display. 02354 /// @returns @ref RetCode_t value. 02355 /// 02356 virtual RetCode_t pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y); 02357 02358 02359 /// Get a stream of pixels from the display. 02360 /// 02361 /// @param[in] p is a pointer to a color_t array to accept the stream. 02362 /// @param[in] count is the number of pixels to read. 02363 /// @param[in] x is the horizontal offset to this pixel. 02364 /// @param[in] y is the vertical offset to this pixel. 02365 /// @returns @ref RetCode_t value. 02366 /// 02367 virtual RetCode_t getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y); 02368 02369 02370 /// Write a boolean stream to the display. 02371 /// 02372 /// This takes a bit stream in memory and using the current color settings 02373 /// it will stream it to the display. Along the way, each bit is translated 02374 /// to either the foreground or background color value and then that pixel 02375 /// is pushed onward. 02376 /// 02377 /// This is similar, but different, to the @ref pixelStream API, which is 02378 /// given a stream of color values. 02379 /// 02380 /// This is most often used for Soft Fonts, and for that reason, this method 02381 /// will scale the presentation based on the selected font size. 02382 /// See @ref SetTextFontSize, So, users may want to SetTextFontSize(1) for 02383 /// 1:1 scaling. 02384 /// 02385 /// @param[in] x is the horizontal position on the display. 02386 /// @param[in] y is the vertical position on the display. 02387 /// @param[in] w is the width of the rectangular region to fill. 02388 /// @param[in] h is the height of the rectangular region to fill. 02389 /// @param[in] boolStream is the inline memory image from which to extract 02390 /// the bitstream. 02391 /// @returns @ref RetCode_t value. 02392 /// 02393 virtual RetCode_t booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream); 02394 02395 /// Draw a line in the specified color 02396 /// 02397 /// @note As a side effect, this changes the current 02398 /// foreground color for subsequent operations. 02399 /// 02400 /// @param[in] p1 is the point to start the line. 02401 /// @param[in] p2 is the point to end the line. 02402 /// @param[in] color defines the foreground color. 02403 /// @returns @ref RetCode_t value. 02404 /// 02405 RetCode_t line(point_t p1, point_t p2, color_t color); 02406 02407 02408 /// Draw a line 02409 /// 02410 /// Draws a line using the foreground color setting. 02411 /// 02412 /// @param[in] p1 is the point to start the line. 02413 /// @param[in] p2 is the point to end the line. 02414 /// @returns @ref RetCode_t value. 02415 /// 02416 RetCode_t line(point_t p1, point_t p2); 02417 02418 02419 /// Draw a line in the specified color 02420 /// 02421 /// @note As a side effect, this changes the current 02422 /// foreground color for subsequent operations. 02423 /// 02424 /// @param[in] x1 is the horizontal start of the line. 02425 /// @param[in] y1 is the vertical start of the line. 02426 /// @param[in] x2 is the horizontal end of the line. 02427 /// @param[in] y2 is the vertical end of the line. 02428 /// @param[in] color defines the foreground color. 02429 /// @returns @ref RetCode_t value. 02430 /// 02431 RetCode_t line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color); 02432 02433 02434 /// Draw a line 02435 /// 02436 /// Draws a line using the foreground color setting. 02437 /// 02438 /// @param[in] x1 is the horizontal start of the line. 02439 /// @param[in] y1 is the vertical start of the line. 02440 /// @param[in] x2 is the horizontal end of the line. 02441 /// @param[in] y2 is the vertical end of the line. 02442 /// @returns @ref RetCode_t value. 02443 /// 02444 RetCode_t line(loc_t x1, loc_t y1, loc_t x2, loc_t y2); 02445 02446 02447 /// Draw a thick line 02448 /// 02449 /// Draw a line of a specified thickness and color. 02450 /// 02451 /// In order to draw a thick line, this draws filled circles using 02452 /// and then draws the 'body' of the thick line using filled triangles. This 02453 /// method makes it significantly faster than in prior versions. 02454 /// 02455 /// An older version of this library used Bresenham's algorithm to move the 02456 /// center point of the circle along the line. As a result, this was much 02457 /// slower than drawing a 1-pixel line which uses the hardware line drawing 02458 /// algorithm. 02459 /// 02460 /// Drawing multiple parallel lines to create a thick line is faster, 02461 /// however the line drawing was not guaranteed to fill every pixel 02462 /// on the diagonals. 02463 /// 02464 /// @param[in] p1 is the point to start the line. 02465 /// @param[in] p2 is the point to end the line. 02466 /// @param[in] thickness is the line thickness. 02467 /// @param[in] color defines the foreground color. 02468 /// @returns @ref RetCode_t value. 02469 /// 02470 RetCode_t ThickLine(point_t p1, point_t p2, dim_t thickness, color_t color); 02471 02472 02473 /// Set the end-cap for ThickLines - square (default) or rounded. 02474 /// 02475 /// @param[in] roundCap when true causes the end-cap to be drawn as a filled circle. 02476 /// @returns the previous end-cap setting, permitting easy restore. 02477 /// 02478 bool SetEndCap(bool roundCap); 02479 02480 02481 /// Draw a rectangle in the specified color 02482 /// 02483 /// @note As a side effect, this changes the current 02484 /// foreground color for subsequent operations. 02485 /// 02486 /// @param[in] rect defines the rectangle. 02487 /// @param[in] color defines the foreground color. 02488 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02489 /// @returns @ref RetCode_t value. 02490 /// 02491 RetCode_t rect(rect_t rect, color_t color, fill_t fillit = NOFILL); 02492 02493 02494 /// Draw a filled rectangle in the specified color 02495 /// 02496 /// @note As a side effect, this changes the current 02497 /// foreground color for subsequent operations. 02498 /// 02499 /// @param[in] rect defines the rectangle. 02500 /// @param[in] color defines the foreground color. 02501 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02502 /// @returns @ref RetCode_t value. 02503 /// 02504 RetCode_t fillrect(rect_t rect, color_t color, fill_t fillit = FILL); 02505 02506 02507 /// Draw a rectangle in the specified color 02508 /// 02509 /// @note As a side effect, this changes the current 02510 /// foreground color for subsequent operations. 02511 /// 02512 /// @param[in] x1 is the horizontal start of the line. 02513 /// @param[in] y1 is the vertical start of the line. 02514 /// @param[in] x2 is the horizontal end of the line. 02515 /// @param[in] y2 is the vertical end of the line. 02516 /// @param[in] color defines the foreground color. 02517 /// @param[in] fillit is optional to FILL the rectangle. default is FILL. 02518 /// @returns @ref RetCode_t value. 02519 /// 02520 RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02521 color_t color, fill_t fillit = NOFILL); 02522 02523 02524 /// Draw a filled rectangle in the specified color 02525 /// 02526 /// @note As a side effect, this changes the current 02527 /// foreground color for subsequent operations. 02528 /// 02529 /// @param[in] x1 is the horizontal start of the line. 02530 /// @param[in] y1 is the vertical start of the line. 02531 /// @param[in] x2 is the horizontal end of the line. 02532 /// @param[in] y2 is the vertical end of the line. 02533 /// @param[in] color defines the foreground color. 02534 /// @param[in] fillit is optional to NOFILL the rectangle. default is FILL. 02535 /// @returns @ref RetCode_t value. 02536 /// 02537 virtual RetCode_t fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02538 color_t color, fill_t fillit = FILL); 02539 02540 02541 /// Draw a rectangle 02542 /// 02543 /// Draws a rectangle using the foreground color setting. 02544 /// 02545 /// @param[in] x1 is the horizontal start of the line. 02546 /// @param[in] y1 is the vertical start of the line. 02547 /// @param[in] x2 is the horizontal end of the line. 02548 /// @param[in] y2 is the vertical end of the line. 02549 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02550 /// @returns @ref RetCode_t value. 02551 /// 02552 RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02553 fill_t fillit = NOFILL); 02554 02555 02556 /// Draw a filled rectangle with rounded corners using the specified color. 02557 /// 02558 /// This draws a rounded rectangle. A numbers of checks are made on the values, 02559 /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2), 02560 /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are 02561 /// > 1/2 the length of that side (width or height), an error value is returned. 02562 /// 02563 /// @note As a side effect, this changes the current 02564 /// foreground color for subsequent operations. 02565 /// 02566 /// @param[in] x1 is the horizontal start of the line and must be <= x2. 02567 /// @param[in] y1 is the vertical start of the line and must be <= y2. 02568 /// @param[in] x2 is the horizontal end of the line and must be >= x1. 02569 /// @param[in] y2 is the vertical end of the line and must be >= y1. 02570 /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care 02571 /// that this value < 1/2 the width of the rectangle, or bad_parameter 02572 /// is returned. 02573 /// @param[in] radius2 defines the vertical radius of the curved corner. Take care 02574 /// that this value < 1/2 the height of the rectangle, or bad_parameter 02575 /// is returned. 02576 /// @param[in] color defines the foreground color. 02577 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02578 /// @returns @ref RetCode_t value. 02579 /// 02580 RetCode_t fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02581 dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL); 02582 02583 02584 /// Draw a filled rectangle with rounded corners using the specified color. 02585 /// 02586 /// This draws a rounded rectangle. A numbers of checks are made on the values, 02587 /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2), 02588 /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are 02589 /// > 1/2 the length of that side (width or height), an error value is returned. 02590 /// 02591 /// @note As a side effect, this changes the current 02592 /// foreground color for subsequent operations. 02593 /// 02594 /// @param[in] r is the rectangle to draw. 02595 /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care 02596 /// that this value < 1/2 the width of the rectangle, or bad_parameter 02597 /// is returned. 02598 /// @param[in] radius2 defines the vertical radius of the curved corner. Take care 02599 /// that this value < 1/2 the height of the rectangle, or bad_parameter 02600 /// is returned. 02601 /// @param[in] color defines the foreground color. 02602 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02603 /// @returns @ref RetCode_t value. 02604 /// 02605 RetCode_t fillroundrect(rect_t r, 02606 dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL); 02607 02608 02609 /// Draw a rectangle with rounded corners using the specified color. 02610 /// 02611 /// This draws a rounded rectangle. A numbers of checks are made on the values, 02612 /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2), 02613 /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are 02614 /// > 1/2 the length of that side (width or height), an error value is returned. 02615 /// 02616 /// @note As a side effect, this changes the current 02617 /// foreground color for subsequent operations. 02618 /// 02619 /// @param[in] r is the rectangle to draw. 02620 /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care 02621 /// that this value < 1/2 the width of the rectangle, or bad_parameter 02622 /// is returned. 02623 /// @param[in] radius2 defines the vertical radius of the curved corner. Take care 02624 /// that this value < 1/2 the height of the rectangle, or bad_parameter 02625 /// is returned. 02626 /// @param[in] color defines the foreground color. 02627 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02628 /// @returns @ref RetCode_t value. 02629 /// 02630 RetCode_t roundrect(rect_t r, 02631 dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL); 02632 02633 02634 /// Draw a rectangle with rounded corners using the specified color. 02635 /// 02636 /// This draws a rounded rectangle. A numbers of checks are made on the values, 02637 /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2), 02638 /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are 02639 /// > 1/2 the length of that side (width or height), an error value is returned. 02640 /// 02641 /// @note As a side effect, this changes the current 02642 /// foreground color for subsequent operations. 02643 /// 02644 /// @param[in] x1 is the horizontal start of the line and must be <= x2. 02645 /// @param[in] y1 is the vertical start of the line and must be <= y2. 02646 /// @param[in] x2 is the horizontal end of the line and must be >= x1. 02647 /// @param[in] y2 is the vertical end of the line and must be >= y1. 02648 /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care 02649 /// that this value < 1/2 the width of the rectangle, or bad_parameter 02650 /// is returned. 02651 /// @param[in] radius2 defines the vertical radius of the curved corner. Take care 02652 /// that this value < 1/2 the height of the rectangle, or bad_parameter 02653 /// is returned. 02654 /// @param[in] color defines the foreground color. 02655 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02656 /// @returns @ref RetCode_t value. 02657 /// 02658 RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02659 dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL); 02660 02661 02662 /// Draw a rectangle with rounded corners. 02663 /// 02664 /// This draws a rounded rectangle. A numbers of checks are made on the values, 02665 /// and it could reduce this to drawing a line (if either x1 == x2, or y1 == y2), 02666 /// or a single point (x1 == x2 && y1 == y2). If the radius parameters are 02667 /// > 1/2 the length of that side (width or height), an error value is returned. 02668 /// 02669 /// @param[in] x1 is the horizontal start of the line and must be <= x2. 02670 /// @param[in] y1 is the vertical start of the line and must be <= y2. 02671 /// @param[in] x2 is the horizontal end of the line and must be >= x1. 02672 /// @param[in] y2 is the vertical end of the line and must be >= y1. 02673 /// @param[in] radius1 defines the horizontal radius of the curved corner. Take care 02674 /// that this value < 1/2 the width of the rectangle, or bad_parameter 02675 /// is returned. 02676 /// @param[in] radius2 defines the vertical radius of the curved corner. Take care 02677 /// that this value < 1/2 the height of the rectangle, or bad_parameter 02678 /// is returned. 02679 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02680 /// @returns @ref RetCode_t value. 02681 /// 02682 RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02683 dim_t radius1, dim_t radius2, fill_t fillit = NOFILL); 02684 02685 02686 /// Draw a triangle in the specified color. 02687 /// 02688 /// @note As a side effect, this changes the current 02689 /// foreground color for subsequent operations. 02690 /// 02691 /// @param[in] p1 is point 1. 02692 /// @param[in] p2 is point 2. 02693 /// @param[in] p3 is point 3. 02694 /// @param[in] color defines the foreground color. 02695 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02696 /// @returns @ref RetCode_t value. 02697 /// 02698 RetCode_t filltriangle(point_t p1, point_t p2, point_t p3, color_t color, fill_t fillit = FILL); 02699 02700 /// Draw a triangle in the specified color. 02701 /// 02702 /// @note As a side effect, this changes the current 02703 /// foreground color for subsequent operations. 02704 /// 02705 /// @param[in] p1 is point 1. 02706 /// @param[in] p2 is point 2. 02707 /// @param[in] p3 is point 3. 02708 /// @param[in] color defines the foreground color. 02709 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02710 /// @returns @ref RetCode_t value. 02711 /// 02712 RetCode_t triangle(point_t p1, point_t p2, point_t p3, color_t color, fill_t fillit = NOFILL); 02713 02714 /// Draw a triangle in the specified color. 02715 /// 02716 /// @note As a side effect, this changes the current 02717 /// foreground color for subsequent operations. 02718 /// 02719 /// @param[in] x1 is the horizontal for point 1. 02720 /// @param[in] y1 is the vertical for point 1. 02721 /// @param[in] x2 is the horizontal for point 2. 02722 /// @param[in] y2 is the vertical for point 2. 02723 /// @param[in] x3 is the horizontal for point 3. 02724 /// @param[in] y3 is the vertical for point 3. 02725 /// @param[in] color defines the foreground color. 02726 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02727 /// @returns @ref RetCode_t value. 02728 /// 02729 RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02730 loc_t x3, loc_t y3, color_t color, fill_t fillit = NOFILL); 02731 02732 02733 /// Draw a filled triangle in the specified color. 02734 /// 02735 /// @note As a side effect, this changes the current 02736 /// foreground color for subsequent operations. 02737 /// 02738 /// @param[in] x1 is the horizontal for point 1. 02739 /// @param[in] y1 is the vertical for point 1. 02740 /// @param[in] x2 is the horizontal for point 2. 02741 /// @param[in] y2 is the vertical for point 2. 02742 /// @param[in] x3 is the horizontal for point 3. 02743 /// @param[in] y3 is the vertical for point 3. 02744 /// @param[in] color defines the foreground color. 02745 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02746 /// @returns @ref RetCode_t value. 02747 /// 02748 RetCode_t filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02749 loc_t x3, loc_t y3, color_t color, fill_t fillit = FILL); 02750 02751 02752 /// Draw a triangle 02753 /// 02754 /// Draws a triangle using the foreground color setting. 02755 /// 02756 /// @param[in] x1 is the horizontal for point 1. 02757 /// @param[in] y1 is the vertical for point 1. 02758 /// @param[in] x2 is the horizontal for point 2. 02759 /// @param[in] y2 is the vertical for point 2. 02760 /// @param[in] x3 is the horizontal for point 3. 02761 /// @param[in] y3 is the vertical for point 3. 02762 /// @param[in] fillit is optional to FILL the rectangle. default is NOFILL. 02763 /// @returns @ref RetCode_t value. 02764 /// 02765 RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 02766 loc_t x3, loc_t y3, fill_t fillit = NOFILL); 02767 02768 02769 /// Draw a circle using the specified color. 02770 /// 02771 /// @note As a side effect, this changes the current 02772 /// foreground color for subsequent operations. 02773 /// 02774 /// @param[in] p defines the center of the circle. 02775 /// @param[in] radius defines the size of the circle. 02776 /// @param[in] color defines the foreground color. 02777 /// @param[in] fillit is optional to FILL the circle. default is NOFILL. 02778 /// @returns @ref RetCode_t value. 02779 /// 02780 RetCode_t circle(point_t p, dim_t radius, color_t color, fill_t fillit = NOFILL); 02781 02782 02783 /// Draw a filled circle using the specified color. 02784 /// 02785 /// @note As a side effect, this changes the current 02786 /// foreground color for subsequent operations. 02787 /// 02788 /// @param[in] p defines the center of the circle. 02789 /// @param[in] radius defines the size of the circle. 02790 /// @param[in] color defines the foreground color. 02791 /// @param[in] fillit is optional to FILL the circle. default is FILL. 02792 /// @returns @ref RetCode_t value. 02793 /// 02794 RetCode_t fillcircle(point_t p, dim_t radius, color_t color, fill_t fillit = FILL); 02795 02796 02797 /// Draw a circle. 02798 /// 02799 /// Draws a circle using the foreground color setting. 02800 /// 02801 /// @param[in] p defines the center of the circle. 02802 /// @param[in] radius defines the size of the circle. 02803 /// @param[in] fillit is optional to FILL the circle. default is NOFILL. 02804 /// @returns @ref RetCode_t value. 02805 /// 02806 RetCode_t circle(point_t p, dim_t radius, fill_t fillit = NOFILL); 02807 02808 02809 /// Draw a circle using the specified color. 02810 /// 02811 /// @note As a side effect, this changes the current 02812 /// foreground color for subsequent operations. 02813 /// 02814 /// @param[in] x is the horizontal center of the circle. 02815 /// @param[in] y is the vertical center of the circle. 02816 /// @param[in] radius defines the size of the circle. 02817 /// @param[in] color defines the foreground color. 02818 /// @param[in] fillit is optional to FILL the circle. default is NOFILL. 02819 /// @returns @ref RetCode_t value. 02820 /// 02821 RetCode_t circle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit = NOFILL); 02822 02823 02824 /// Draw a filled circle using the specified color. 02825 /// 02826 /// @note As a side effect, this changes the current 02827 /// foreground color for subsequent operations. 02828 /// 02829 /// @param[in] x is the horizontal center of the circle. 02830 /// @param[in] y is the vertical center of the circle. 02831 /// @param[in] radius defines the size of the circle. 02832 /// @param[in] color defines the foreground color. 02833 /// @param[in] fillit is optional to FILL the circle. default is FILL. 02834 /// @returns @ref RetCode_t value. 02835 /// 02836 RetCode_t fillcircle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit = FILL); 02837 02838 02839 /// Draw a circle. 02840 /// 02841 /// Draws a circle using the foreground color setting. 02842 /// 02843 /// @param[in] x is the horizontal center of the circle. 02844 /// @param[in] y is the vertical center of the circle. 02845 /// @param[in] radius defines the size of the circle. 02846 /// @param[in] fillit is optional to FILL the circle. default is NOFILL. 02847 /// @returns @ref RetCode_t value. 02848 /// 02849 RetCode_t circle(loc_t x, loc_t y, dim_t radius, fill_t fillit = NOFILL); 02850 02851 /// Draw an Ellipse using the specified color 02852 /// 02853 /// @note As a side effect, this changes the current 02854 /// foreground color for subsequent operations. 02855 /// 02856 /// @param[in] x is the horizontal center of the ellipse. 02857 /// @param[in] y is the vertical center of the ellipse. 02858 /// @param[in] radius1 defines the horizontal radius of the ellipse. 02859 /// @param[in] radius2 defines the vertical radius of the ellipse. 02860 /// @param[in] color defines the foreground color. 02861 /// @param[in] fillit defines whether the circle is filled or not. 02862 /// @returns @ref RetCode_t value. 02863 /// 02864 RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, 02865 color_t color, fill_t fillit = NOFILL); 02866 02867 02868 /// Draw a filled Ellipse using the specified color 02869 /// 02870 /// @note As a side effect, this changes the current 02871 /// foreground color for subsequent operations. 02872 /// 02873 /// @param[in] x is the horizontal center of the ellipse. 02874 /// @param[in] y is the vertical center of the ellipse. 02875 /// @param[in] radius1 defines the horizontal radius of the ellipse. 02876 /// @param[in] radius2 defines the vertical radius of the ellipse. 02877 /// @param[in] color defines the foreground color. 02878 /// @param[in] fillit defines whether the circle is filled or not. 02879 /// @returns @ref RetCode_t value. 02880 /// 02881 RetCode_t fillellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, 02882 color_t color, fill_t fillit = FILL); 02883 02884 02885 /// Draw an Ellipse 02886 /// 02887 /// Draws it using the foreground color setting. 02888 /// 02889 /// @param[in] x is the horizontal center of the ellipse. 02890 /// @param[in] y is the vertical center of the ellipse. 02891 /// @param[in] radius1 defines the horizontal radius of the ellipse. 02892 /// @param[in] radius2 defines the vertical radius of the ellipse. 02893 /// @param[in] fillit defines whether the circle is filled or not. 02894 /// @returns @ref RetCode_t value. 02895 /// 02896 RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit = NOFILL); 02897 02898 02899 /// Draw an Ellipse 02900 /// 02901 /// Draws it using the foreground color setting. 02902 /// 02903 /// @param[in] p is point for the center of the ellipse. 02904 /// @param[in] radius1 defines the horizontal radius of the ellipse. 02905 /// @param[in] radius2 defines the vertical radius of the ellipse. 02906 /// @param[in] fillit defines whether the circle is filled or not. 02907 /// @returns @ref RetCode_t value. 02908 /// 02909 RetCode_t ellipse(point_t p, dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL); 02910 02911 02912 /// Draw an filled Ellipse 02913 /// 02914 /// Draws it using the foreground color setting. 02915 /// 02916 /// @param[in] p is point for the center of the ellipse. 02917 /// @param[in] radius1 defines the horizontal radius of the ellipse. 02918 /// @param[in] radius2 defines the vertical radius of the ellipse. 02919 /// @param[in] fillit defines whether the circle is filled or not. 02920 /// @returns @ref RetCode_t value. 02921 /// 02922 RetCode_t fillellipse(point_t p, dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL); 02923 02924 02925 /// Block Move 02926 /// 02927 /// The Block Move API activates the RA8875 Block Transfer Engine. Due to the complex 02928 /// set of possible operations, the user should read the related sections of the 02929 /// RA8875 user manual. 02930 /// 02931 /// Some operations may require that other registers are configured, such as the 02932 /// foreground and background color registers, and others. Those must be set 02933 /// outside of this API. 02934 /// 02935 /// @code 02936 /// // Block Move Demo 02937 /// 02938 /// // Calibrate the resistive touch screen, and store the data on the 02939 /// // local file system. 02940 /// // 02941 /// void CalibrateTS(void) 02942 /// { 02943 /// FILE * fh; 02944 /// tpMatrix_t matrix; 02945 /// RetCode_t r; 02946 /// Timer testperiod; 02947 /// 02948 /// r = lcd.TouchPanelCalibrate("Calibrate the touch panel", &matrix); 02949 /// if (r == noerror) { 02950 /// fh = fopen("/local/tpcal.cfg", "wb"); 02951 /// if (fh) { 02952 /// fwrite(&matrix, sizeof(tpMatrix_t), 1, fh); 02953 /// fclose(fh); 02954 /// printf(" tp cal written.\r\n"); 02955 /// lcd.cls(); 02956 /// } else { 02957 /// printf(" couldn't open tpcal file.\r\n"); 02958 /// } 02959 /// } else { 02960 /// printf("error return: %d\r\n", r); 02961 /// } 02962 /// lcd.cls(); 02963 /// } 02964 /// 02965 /// // Try to load a previous resistive touch screen calibration from storage. If it 02966 /// // doesn't exist, activate the touch screen calibration process. 02967 /// // 02968 /// void InitTS(void) 02969 /// { 02970 /// FILE * fh; 02971 /// tpMatrix_t matrix; 02972 /// 02973 /// fh = fopen("/local/tpcal.cfg", "rb"); 02974 /// if (fh) { 02975 /// fread(&matrix, sizeof(tpMatrix_t), 1, fh); 02976 /// fclose(fh); 02977 /// lcd.TouchPanelSetMatrix(&matrix); 02978 /// printf(" tp cal loaded.\r\n"); 02979 /// } else { 02980 /// CalibrateTS(); 02981 /// } 02982 /// } 02983 /// 02984 /// int main() 02985 /// { 02986 /// point_t src; 02987 /// point_t dst; 02988 /// TouchCode_t touch; 02989 /// const dim_t RECT_W = 100; 02990 /// const dim_t RECT_H = 100; 02991 /// 02992 /// pc.baud(460800); //I like a snappy terminal, so crank it up! 02993 /// pc.printf("\r\nRA8875 BTE Move Test - Build " __DATE__ " " __TIME__ "\r\n"); 02994 /// lcd.init(LCD_PHYS_W,LCD_PHYS_H,LCD_C, BL_NORM); 02995 /// lcd.TouchPanelInit(); 02996 /// #ifndef CAP_TOUCH 02997 /// InitTS(); // Calibration for resistive touch panel 02998 /// #endif 02999 /// 03000 /// RetCode_t r = lcd.RenderImageFile(0,0,"/local/fullscrn.jpg"); 03001 /// if (r) pc.printf(" Error: %d; %s\r\n", r, lcd.GetErrorMessage(r)); 03002 /// while (1) { 03003 /// touch = lcd.TouchPanelReadable(); 03004 /// if (touch) { 03005 /// point_t xy = lcd.TouchCoordinates(); 03006 /// TouchCode_t t = lcd.TouchCode(); 03007 /// 03008 /// if (t == touch) { 03009 /// src = ComputeTopLeftOfRect(xy, RECT_W/2, RECT_H/2, LCD_PHYS_W, LCD_PHYS_H); 03010 /// } else if (t == release) { 03011 /// dst = ComputeTopLeftOfRect(xy, RECT_W/2, RECT_H/2, LCD_PHYS_W, LCD_PHYS_H); 03012 /// r = lcd.BlockMove(0,0,dst, 0,0,src, RECT_W,RECT_H, 0x2, 0xC); 03013 /// } 03014 /// } 03015 /// } 03016 /// } 03017 /// @endcode 03018 /// 03019 /// @param[in] dstLayer layer [5B.7]. layer value is 0 or 1 representing layer 1 and 2. 03020 /// @param[in] dstDataSelect [50.5] defines the destination data type 0: block, 1: linear. 03021 /// @param[in] dstPoint [58-5B] is a point_t defining the destination coordinate. 03022 /// @param[in] srcLayer layer [57.7]. layer value is 0 or 1 representing layer 1 and 2. 03023 /// @param[in] srcDataSelect [50.6] defines the source data type 0: block, 1: linear. 03024 /// @param[in] srcPoint [54-57] is a point_t defining the source coordinate. 03025 /// @param[in] bte_width [5C-5D]. operation width. 03026 /// @param[in] bte_height [5E-5F]. operation height. 03027 /// @param[in] bte_op_code [51.3-0] defines the raster operation function 03028 /// (write/read/move/...) 03029 /// @param[in] bte_rop_code [51.7-4] defines what type of BTE operation to perform 03030 /// (what is placed at the destination) 03031 /// @returns @ref RetCode_t value. 03032 /// 03033 RetCode_t BlockMove(uint8_t dstLayer, uint8_t dstDataSelect, point_t dstPoint, 03034 uint8_t srcLayer, uint8_t srcDataSelect, point_t srcPoint, 03035 dim_t bte_width, dim_t bte_height, 03036 uint8_t bte_op_code, uint8_t bte_rop_code); 03037 03038 03039 /// Control display power 03040 /// 03041 /// @param[in] on when set to true will turn on the display, when false it is turned off. 03042 /// @returns @ref RetCode_t value. 03043 /// 03044 RetCode_t Power(bool on); 03045 03046 03047 /// Reset the display controller via the Software Reset interface. 03048 /// 03049 /// @returns @ref RetCode_t value. 03050 /// 03051 RetCode_t Reset(void); 03052 03053 03054 /// Set backlight brightness. 03055 /// 03056 /// When the built-in PWM is used to control the backlight, this 03057 /// API can be used to set the brightness. 03058 /// 03059 /// @param[in] brightness ranges from 0 (off) to 255 (full on) 03060 /// @returns @ref RetCode_t value. 03061 /// 03062 RetCode_t Backlight_u8(uint8_t brightness); 03063 03064 03065 /// Get backlight brightness. 03066 /// 03067 /// @returns backlight setting from 0 (off) to 255 (full on). 03068 /// 03069 uint8_t GetBacklight_u8(void); 03070 03071 /// Set backlight brightness. 03072 /// 03073 /// When the built-in PWM is used to control the backlight, this 03074 /// API can be used to set the brightness. 03075 /// 03076 /// @param[in] brightness ranges from 0.0 (off) to 1.0 (full on) 03077 /// @returns @ref RetCode_t value. 03078 /// 03079 RetCode_t Backlight(float brightness); 03080 03081 03082 /// Get backlight brightness. 03083 /// 03084 /// @returns backlight setting from 0 (off) to 1.0 (full on). 03085 /// 03086 float GetBacklight(void); 03087 03088 03089 /// Select a User Font for all subsequent text. 03090 /// 03091 /// @note Tool to create the fonts is accessible from its creator 03092 /// available at http://www.mikroe.com. 03093 /// For version 1.2.0.0, choose the "Export for TFT and new GLCD" 03094 /// format. 03095 /// 03096 /// @param[in] font is a pointer to a specially formed font resource. 03097 /// @returns @ref RetCode_t value. 03098 /// 03099 virtual RetCode_t SelectUserFont(const uint8_t * font = NULL); 03100 03101 /// Get the currently selected user font. 03102 /// 03103 /// @returns a pointer to the font, or null, if no user font is selected. 03104 /// 03105 virtual const uint8_t * GetUserFont(void) 03106 { 03107 return font; 03108 } 03109 03110 /// Get the @ref color_t value from a DOS color index. 03111 /// 03112 /// See @ref PredefinedColors, @ref color_t. 03113 /// 03114 /// @code 03115 /// color_t color = DOSColor(12); 03116 /// @endcode 03117 /// 03118 /// @param[in] i is the color index, in the range 0 to 15; 03119 /// @returns the @ref color_t value of the selected index, 03120 /// or 0 (@ref Black) if the index is out of bounds. 03121 /// 03122 color_t DOSColor(int i); 03123 03124 03125 /// Get the color name (string) from a DOS color index. 03126 /// 03127 /// See @ref PredefinedColors, @ref color_t. 03128 /// 03129 /// @code 03130 /// printf("color is %s\n", DOSColorNames(12)); 03131 /// @endcode 03132 /// 03133 /// @param[in] i is the color index, in the range 0 to 15; 03134 /// @returns a pointer to a string with the color name, 03135 /// or NULL if the index is out of bounds. 03136 /// 03137 const char * DOSColorNames(int i); 03138 03139 03140 /// Advanced method indicating the start of a graphics stream. 03141 /// 03142 /// This is called prior to a stream of pixel data being sent. 03143 /// This may cause register configuration changes in the derived 03144 /// class in order to prepare the hardware to accept the streaming 03145 /// data. 03146 /// 03147 /// Following this command, a series of See @ref _putp() commands can 03148 /// be used to send individual pixels to the screen. 03149 /// 03150 /// To conclude the graphics stream, See @ref _EndGraphicsStream should 03151 /// be called. 03152 /// 03153 /// @returns @ref RetCode_t value. 03154 /// 03155 virtual RetCode_t _StartGraphicsStream(void); 03156 03157 03158 /// Advanced method to put a single color pixel to the screen. 03159 /// 03160 /// This method may be called as many times as necessary after 03161 /// See @ref _StartGraphicsStream() is called, and it should be followed 03162 /// by _EndGraphicsStream. 03163 /// 03164 /// @code 03165 /// _putp(DOSColor(12)); 03166 /// @endcode 03167 /// 03168 /// @param[in] pixel is a color value to be put on the screen. 03169 /// @returns @ref RetCode_t value. 03170 /// 03171 virtual RetCode_t _putp(color_t pixel); 03172 03173 03174 /// Advanced method indicating the end of a graphics stream. 03175 /// 03176 /// This is called to conclude a stream of pixel data that was sent. 03177 /// This may cause register configuration changes in the derived 03178 /// class in order to stop the hardware from accept the streaming 03179 /// data. 03180 /// 03181 /// @returns @ref RetCode_t value. 03182 /// 03183 virtual RetCode_t _EndGraphicsStream(void); 03184 03185 03186 /// Set the SPI port frequency (in Hz). 03187 /// 03188 /// This uses the mbed SPI driver, and is therefore dependent on 03189 /// its capabilities. The RA8875 can accept writes via SPI faster 03190 /// than a read can be performed. The frequency set by this API 03191 /// is for the SPI writes. It will automatically reduce the SPI 03192 /// clock rate when a read is performed, and restore it for the 03193 /// next write. Alternately, the 2nd parameters permits setting 03194 /// the read speed rather than letting it compute it automatically. 03195 /// 03196 /// @note The primary effect of this is to recover more CPU cycles 03197 /// for your application code. Keep in mind that when more than 03198 /// one command is sent to the display controller, that it 03199 /// will wait for the controller to finish the prior command. 03200 /// In this case, the performance is limited by the RA8875. 03201 /// 03202 /// @param[in] Hz is the frequency in Hz, tested range includes the 03203 /// range from 1,000,000 (1MHz) to 10,000,000 (10 MHz). Values 03204 /// outside this range will be accepted, but operation may 03205 /// be unreliable. This depends partially on your hardware design 03206 /// and the wires connecting the display module. 03207 /// The default value is 5,000,000, which should work for most 03208 /// applications as a starting point. 03209 /// @param[in] Hz2 is an optional parameter and will set the read 03210 /// speed independently of the write speed. 03211 /// @returns @ref RetCode_t value. 03212 /// 03213 RetCode_t frequency(unsigned long Hz = RA8875_DEFAULT_SPI_FREQ, unsigned long Hz2 = 0); 03214 03215 03216 /// This method captures the specified area as a 24-bit bitmap file. 03217 /// 03218 /// Even though this is a 16-bit display, the stored image is in 03219 /// 24-bit format. 03220 /// 03221 /// This method will interrogate the current display setting and 03222 /// create a bitmap based on those settings. For instance, if 03223 /// only layer 1 is visible, then the bitmap is only layer 1. However, 03224 /// if there is some other operation in effect (transparent mode). 03225 /// 03226 /// If the idle callback is registered, it will be activated passing 03227 /// a parameter indicating the percent complete, which may be of value. 03228 /// 03229 /// @param[in] x is the left edge of the region to capture 03230 /// @param[in] y is the top edge of the region to capture 03231 /// @param[in] w is the width of the region to capture 03232 /// @param[in] h is the height of the region to capture. 03233 /// @param[in] Name_BMP is the filename to write the image to. 03234 /// @param[in] bitsPerPixel is optional, defaults to 24, and only 03235 /// accepts the values 24, 8 03236 /// NOTE: The downscaling is CPU intensive, and the operation 03237 /// takes longer. 03238 /// @returns @ref RetCode_t value. 03239 /// 03240 RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP, uint8_t bitsPerPixel = 24); 03241 03242 03243 /// This method captures the specified area as a 24-bit bitmap file 03244 /// and delivers it to the previously attached callback. 03245 /// 03246 /// Even though this is a 16-bit display, the stored image is in 03247 /// 24-bit format. 03248 /// 03249 /// This method will interrogate the current display setting and 03250 /// create a bitmap based on those settings. For instance, if 03251 /// only layer 1 is visible, then the bitmap is only layer 1. However, 03252 /// if there is some other operation in effect (transparent mode), it 03253 /// will return the blended image. 03254 /// 03255 /// If the idle callback is registered, it will be activated passing 03256 /// a parameter indicating the percent complete, which may be of value. 03257 /// 03258 /// @param[in] x is the left edge of the region to capture 03259 /// @param[in] y is the top edge of the region to capture 03260 /// @param[in] w is the width of the region to capture 03261 /// @param[in] h is the height of the region to capture. 03262 /// @param[in] bitsPerPixel is optional, defaults to 24, and only 03263 /// accepts the values 24, 8 03264 /// NOTE: The downscaling is CPU intensive, and the operation 03265 /// takes longer. 03266 /// @returns @ref RetCode_t value. 03267 /// 03268 RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, uint8_t bitsPerPixel = 24); 03269 03270 03271 /// PrintScreen callback registration. 03272 /// 03273 /// This method attaches a simple c-compatible callback of type PrintCallback_T. 03274 /// Then, the PrintScreen(x,y,w,h) method is called. Each chunk of data in the 03275 /// BMP file to be created is passed to this callback. 03276 /// 03277 /// @param callback is the optional callback function. Without a callback function 03278 /// it will unregister the handler. 03279 /// 03280 void AttachPrintHandler(PrintCallback_T callback = NULL) 03281 { 03282 c_callback = callback; 03283 } 03284 03285 03286 /// PrintScreen callback registration. 03287 /// 03288 /// This method attaches a c++ class method as a callback of type PrintCallback_T. 03289 /// Then, the PrintScreen(x,y,w,h) method is called. Each chunk of data in the 03290 /// BMP file to be created is passed to this callback. 03291 /// 03292 /// @param object is the class hosting the callback function. 03293 /// @param method is the callback method in the object to activate. 03294 /// 03295 template <class T> 03296 void AttachPrintHandler(T *object, RetCode_t (T::*method)(void)) 03297 { 03298 obj_callback = (FPointerDummy *)object; 03299 method_callback = (RetCode_t (FPointerDummy::*)(filecmd_t, uint8_t *, uint16_t))method; 03300 } 03301 03302 03303 /// This method captures the specified area as a 24-bit bitmap file, 03304 /// including the option of layer selection. 03305 /// 03306 /// @note This method is deprecated as the alternate PrintScreen API 03307 /// automatically examines the display layer configuration. 03308 /// Therefore, calls to this API will ignore the layer parameter 03309 /// and automatically execute the other method. 03310 /// 03311 /// Even though this is a 16-bit display, the stored image is in 03312 /// 24-bit format. 03313 /// 03314 /// @param[in] layer is 0 or 1 to select the layer to extract. 03315 /// @param[in] x is the left edge of the region to capture 03316 /// @param[in] y is the top edge of the region to capture 03317 /// @param[in] w is the width of the region to capture 03318 /// @param[in] h is the height of the region to capture. 03319 /// @param[out] Name_BMP is the filename to write the image to. 03320 /// @returns @ref RetCode_t value. 03321 /// 03322 RetCode_t PrintScreen(uint16_t layer, loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP); 03323 03324 03325 /// idle callback registration. 03326 /// 03327 /// This method attaches a simple c-compatible callback of type IdleCallback_T. 03328 /// Then, at any time when the display driver is waiting, it will call the 03329 /// registered function. This is probably most useful if you want to service 03330 /// a watchdog, when you may have called an API that will "hang" waiting 03331 /// on the user. 03332 /// 03333 /// @code 03334 /// RetCode_t myIdle_handler(RA8875::IdleReason_T reason, uint16_t param) 03335 /// { 03336 /// static uint16_t lastProgress = 0xFFFF; 03337 /// 03338 /// if (reason == RA8875::progress && param != lastProgress) { 03339 /// printf("Progress %3d%%\r\n", param); 03340 /// lastProgress = progress; 03341 /// } 03342 /// return noerror; 03343 /// } 03344 /// 03345 /// ... 03346 /// lcd.AttachIdleHandler(myIdle_handler); 03347 /// ... 03348 /// RetCode_t r = lcd.PrintScreen(0,0,LCD_PHYS_W,LCD_PHYS_H,"/local/print.bmp"); 03349 /// if (r ...) 03350 /// @endcode 03351 /// 03352 /// 03353 /// @param callback is the idle callback function. Without a callback function 03354 /// it will unregister the handler. 03355 /// 03356 void AttachIdleHandler(IdleCallback_T callback = NULL) 03357 { 03358 idle_callback = callback; 03359 } 03360 03361 03362 #ifdef PERF_METRICS 03363 /// Clear the performance metrics to zero. 03364 void ClearPerformance(); 03365 03366 /// Count idle time. 03367 /// 03368 /// @param[in] t is the amount of idle time to accumulate. 03369 /// 03370 void CountIdleTime(uint32_t t); 03371 03372 /// Report the performance metrics for drawing functions using 03373 /// the available serial channel. 03374 /// 03375 /// @param[in,out] pc is the serial channel to write to. 03376 /// 03377 void ReportPerformance(Serial & pc); 03378 #endif 03379 03380 03381 private: 03382 void InitAllMemberVars(); 03383 03384 /// Touch panel parameters - common to both resistive and capacitive 03385 03386 /// Data type to indicate which TP, if any, is in use. 03387 typedef enum { 03388 TP_NONE, ///< no touch panel in use 03389 TP_RES, ///< resistive touch panel using RA8875 03390 TP_FT5206, ///< Capacitive touch panel using FT5206 03391 TP_CAP=TP_FT5206, ///< DEPRECATED: used TP_CAP5206 for that chip-set 03392 TP_GSL1680, ///< Capacitive touch panel using GSL1680 chip 03393 } WhichTP_T; 03394 03395 /// boolean flag set true when using Capacitive touch panel, and false 03396 /// for resistive. 03397 WhichTP_T useTouchPanel; ///< Indicates which TP is selected for use. 03398 03399 /// Touch State used by TouchPanelReadable. See @ref TouchCode_t. 03400 TouchCode_t touchState; 03401 03402 ////////////////// Start of Capacitive Touch Panel parameters 03403 03404 int RoundUp(int value, int roundTo); 03405 uint8_t FT5206_TouchPositions(void); 03406 uint8_t FT5206_ReadRegU8(uint8_t reg); 03407 uint8_t GSL1680_TouchPositions(void); 03408 uint8_t GSL1680_ReadRegU8(uint8_t reg, uint8_t * buf, int count); 03409 RetCode_t FT5206_Init(); 03410 RetCode_t GSL1680_Init(); 03411 void ReadResistive(); ///< Analyze the resistive touch 03412 03413 void TouchPanelISR(void); 03414 uint16_t numberOfTouchPoints; 03415 uint8_t gesture; ///< Holds the reported gesture information (which doesn't work well for the FT5206) 03416 03417 /// Touch Information data structure 03418 typedef struct { 03419 uint8_t touchID; ///< Contains the touch ID, which is the "order" of touch, from 0 to n-1 03420 TouchCode_t touchCode; ///< Contains the touch code; no_touch, touch, held, release 03421 point_t coordinates; ///< Contains the X,Y coordinate of the touch 03422 } touchInfo_T; 03423 03424 touchInfo_T * touchInfo; /// Storage allocated by the constructor to contains the touch information 03425 03426 #if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0) 03427 Thread eventThread; 03428 EventQueue queue; 03429 #endif 03430 InterruptIn * m_irq; 03431 I2C * m_i2c; 03432 int m_addr; /// I2C Address of the Cap Touch Controller 03433 03434 bool panelTouched; 03435 03436 ////////////////// Start of Resistive Touch Panel parameters 03437 03438 /// Specify the default settings for the Touch Panel, where different from the chip defaults 03439 #define TP_MODE_DEFAULT TP_MODE_AUTO 03440 #define TP_DEBOUNCE_DEFAULT TP_DEBOUNCE_ON 03441 #define TP_ADC_CLKDIV_DEFAULT TP_ADC_CLKDIV_8 03442 03443 #define TP_ADC_SAMPLE_DEFAULT_CLKS TP_ADC_SAMPLE_8192_CLKS 03444 03445 /// Other Touch Panel params 03446 #define TPBUFSIZE 16 // Depth of the averaging buffers for x and y data 03447 03448 // Needs both a ticker and a timer. (could have created a timer from the ticker, but this is easier). 03449 // on a touch, the timer is reset. 03450 // the ticker monitors the timer to see if it has been a long time since 03451 // a touch, and if so, it then clears the sample counter so it doesn't get partial old 03452 // and partial new. 03453 03454 /// Touch Panel ticker 03455 /// This it bound to a timer to call the _TouchTicker() function periodically. 03456 /// 03457 Ticker touchTicker; 03458 03459 /// Touch Panel timer 03460 /// Reset on a touch, to expire on a non-touch 03461 /// 03462 Timer timeSinceTouch; 03463 03464 /// keeps track of which sample we're collecting to filter out the noise. 03465 int touchSample; 03466 03467 /// Private function for touch ticker callback. 03468 void _TouchTicker(void); 03469 03470 /// Touch Panel calibration matrix. 03471 tpMatrix_t tpMatrix; 03472 03473 /// RESISTIVE TP: The fully qualified filename for the RESISTIVE touch panel configuration settings. 03474 const char * tpFQFN; 03475 03476 /// RESISTIVE TP: The text message shown to the user during the calibration process. 03477 const char * tpCalMessage; 03478 03479 /// Internal method that performs the TS Cal when the user has so-configured it 03480 RetCode_t _internal_ts_cal(); 03481 03482 03483 ////////////////// End of Touch Panel parameters 03484 03485 03486 /// Internal function to put a character using the built-in (internal) font engine 03487 /// 03488 /// @param[in] c is the character to put to the screen. 03489 /// @returns the character put. 03490 /// 03491 int _internal_putc(int c); 03492 03493 /// Internal function to put a character using the external font engine 03494 /// 03495 /// @param[in] c is the character to put to the screen. 03496 /// @returns the character put. 03497 /// 03498 int _external_putc(int c); 03499 03500 /// Internal function to get the actual width of a character when using the external font engine 03501 /// 03502 /// @param[in] c is the character to get the width. 03503 /// @returns the width in pixels of the character. zero if not found. 03504 /// 03505 int _external_getCharWidth(int c); 03506 03507 /// Write color to an RGB register set 03508 /// 03509 /// This API takes a color value, and writes it into the specified 03510 /// color registers, which are a trio of 3 registers. The actual 03511 /// trio write is performed based on whether the display is configured 03512 /// for 8 or 16 bits per pixel. 03513 /// 03514 /// @param[in] regAddr is the register address starting the trio 03515 /// @param[in] color is the color to write 03516 /// @returns @ref RetCode_t value. 03517 /// 03518 RetCode_t _writeColorTrio(uint8_t regAddr, color_t color); 03519 03520 /// Read color from an RGB register set 03521 /// 03522 /// This API reads a color value from a trio of registers. The actual 03523 /// trio write is performed based on whether the display is configured 03524 /// for 8 or 16 bits per pixel. 03525 /// 03526 /// @param[in] regAddr is the register address starting the trio 03527 /// @returns color_t value 03528 /// 03529 color_t _readColorTrio(uint8_t regAddr); 03530 03531 03532 /// Convert a 16-bit color value to an 8-bit value 03533 /// 03534 /// @param[in] c16 is the 16-bit color value to convert. 03535 /// @returns 8-bit color value. 03536 /// 03537 uint8_t _cvt16to8(color_t c16); 03538 03539 /// Convert an 8-bit color value to a 16-bit value 03540 /// 03541 /// @param[in] c8 is the 8-bit color value to convert. 03542 /// @returns 16-bit color value. 03543 /// 03544 color_t _cvt8to16(uint8_t c8); 03545 03546 /// Select the peripheral to use it. 03547 /// 03548 /// @param[in] chipsel when true will select the peripheral, and when false 03549 /// will deselect the chip. This is the logical selection, and 03550 /// the pin selection is the invert of this. 03551 /// @returns @ref RetCode_t value. 03552 /// 03553 RetCode_t _select(bool chipsel); 03554 03555 /// Wait while the status register indicates the controller is busy. 03556 /// 03557 /// @param[in] mask is the mask of bits to monitor. 03558 /// @returns true if a normal exit. 03559 /// @returns false if a timeout exit. 03560 /// 03561 bool _WaitWhileBusy(uint8_t mask); 03562 03563 /// Wait while the the register anded with the mask is true. 03564 /// 03565 /// @param[in] reg is the register to monitor 03566 /// @param[in] mask is the bit mask to monitor 03567 /// @returns true if it was a normal exit 03568 /// @returns false if it was a timeout that caused the exit. 03569 /// 03570 bool _WaitWhileReg(uint8_t reg, uint8_t mask); 03571 03572 /// set the spi port to either the write or the read speed. 03573 /// 03574 /// This is a private API used to toggle between the write 03575 /// and the read speed for the SPI port to the RA8875, since 03576 /// it can accept writes faster than reads. 03577 /// 03578 /// @param[in] writeSpeed when true selects the write frequency, 03579 /// and when false it selects the read frequency. 03580 /// 03581 void _setWriteSpeed(bool writeSpeed); 03582 03583 /// The most primitive - to write a data value to the SPI interface. 03584 /// 03585 /// @param[in] data is the value to write. 03586 /// @returns a value read from the port, since SPI is often shift 03587 /// in while shifting out. 03588 /// 03589 unsigned char _spiwrite(unsigned char data); 03590 03591 /// The most primitive - to read a data value to the SPI interface. 03592 /// 03593 /// This is really just a specialcase of the write command, where 03594 /// the value zero is written in order to read. 03595 /// 03596 /// @returns a value read from the port, since SPI is often shift 03597 /// in while shifting out. 03598 /// 03599 unsigned char _spiread(); 03600 03601 const uint8_t * pKeyMap; 03602 03603 SPI spi; ///< spi port 03604 bool spiWriteSpeed; ///< indicates if the current mode is write or read 03605 unsigned long spiwritefreq; ///< saved write freq 03606 unsigned long spireadfreq; ///< saved read freq 03607 DigitalOut cs; ///< RA8875 chip select pin, assumed active low 03608 DigitalOut * res; ///< RA8875 reset pin, assumed active low 03609 DigitalOut * m_wake; ///< GSL1680 wake pin 03610 03611 // display metrics to avoid lengthy spi read queries 03612 uint8_t screenbpp; ///< configured bits per pixel 03613 dim_t virt_screenwidth; ///< configured screen width cached here for speed of access 03614 dim_t virt_screenheight; ///< configured screen height cached here for speed of access 03615 rect_t windowrect; ///< window rect cached here for speed of access 03616 orientation_t screen_orientation; ///< configured graphic orientation cached here for speed of access 03617 orientation_t text_orientation; ///< configured text orientation cached here for speed of access 03618 bool wordwrap; ///< set true when wordwrap is in effect for _puts() 03619 const unsigned char * font; ///< reference to an external font somewhere in memory 03620 uint8_t extFontHeight; ///< computed from the font table when the user sets the font 03621 uint8_t extFontWidth; ///< computed from the font table when the user sets the font 03622 bool roundCap; ///< draw round end cap on thick lines when set. 03623 loc_t cursor_x, cursor_y; ///< used for external fonts only 03624 03625 #ifdef PERF_METRICS 03626 typedef enum { 03627 PRF_CLS, 03628 PRF_DRAWPIXEL, 03629 PRF_PIXELSTREAM, 03630 PRF_BOOLSTREAM, 03631 PRF_READPIXEL, 03632 PRF_READPIXELSTREAM, 03633 PRF_DRAWLINE, 03634 PRF_DRAWRECTANGLE, 03635 PRF_DRAWROUNDEDRECTANGLE, 03636 PRF_DRAWTRIANGLE, 03637 PRF_DRAWCIRCLE, 03638 PRF_DRAWELLIPSE, 03639 PRF_BLOCKMOVE, 03640 METRICCOUNT = PRF_BLOCKMOVE 03641 } method_e; 03642 unsigned long metrics[METRICCOUNT]; 03643 unsigned long idletime_usec; 03644 void RegisterPerformance(method_e method); 03645 Timer performance; 03646 #endif 03647 03648 RetCode_t _printCallback(RA8875::filecmd_t cmd, uint8_t * buffer, uint16_t size); 03649 03650 FILE * _printFH; ///< PrintScreen file handle 03651 03652 RetCode_t privateCallback(filecmd_t cmd, uint8_t * buffer, uint16_t size) 03653 { 03654 if (c_callback != NULL) { 03655 return (*c_callback)(cmd, buffer, size); 03656 } else { 03657 if (obj_callback != NULL && method_callback != NULL) { 03658 return (obj_callback->*method_callback)(cmd, buffer, size); 03659 } 03660 } 03661 return noerror; 03662 } 03663 03664 RetCode_t (* c_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size); 03665 FPointerDummy *obj_callback; 03666 RetCode_t (FPointerDummy::*method_callback)(filecmd_t cmd, uint8_t * buffer, uint16_t size); 03667 RetCode_t (* idle_callback)(IdleReason_T reason, uint16_t param); 03668 03669 }; 03670 03671 03672 //} // namespace 03673 03674 //using namespace SW_graphics; 03675 03676 03677 #ifdef TESTENABLE 03678 // ______________ ______________ ______________ _______________ 03679 // /_____ _____/ / ___________/ / ___________/ /_____ ______/ 03680 // / / / / / / / / 03681 // / / / /___ / /__________ / / 03682 // / / / ____/ /__________ / / / 03683 // / / / / / / / / 03684 // / / / /__________ ___________/ / / / 03685 // /__/ /_____________/ /_____________/ /__/ 03686 03687 #include "WebColors.h" 03688 #include <algorithm> 03689 03690 extern "C" void mbed_reset(); 03691 03692 /// This activates a small set of tests for the graphics library. 03693 /// 03694 /// Call this API and pass it the reference to the display class. 03695 /// It will then run a series of tests. It accepts interaction via 03696 /// stdin to switch from automatic test mode to manual, run a specific 03697 /// test, or to exit the test mode. 03698 /// 03699 /// @param[in] lcd is a reference to the display class. 03700 /// @param[in] pc is a reference to a serial interface, typically the USB to PC. 03701 /// 03702 void RunTestSet(RA8875 & lcd, Serial & pc); 03703 03704 03705 // To enable the test code, uncomment this section, or copy the 03706 // necessary pieces to your "main()". 03707 // 03708 // #include "mbed.h" 03709 // #include "RA8875.h" 03710 // RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name 03711 // Serial pc(USBTX, USBRX); 03712 // extern "C" void mbed_reset(); 03713 // int main() 03714 // { 03715 // pc.baud(460800); // I like a snappy terminal, so crank it up! 03716 // pc.printf("\r\nRA8875 Test - Build " __DATE__ " " __TIME__ "\r\n"); 03717 // 03718 // pc.printf("Turning on display\r\n"); 03719 // lcd.init(); 03720 // lcd.Reset(); 03721 // lcd.Power(true); // display power is on, but the backlight is independent 03722 // lcd.Backlight(0.5); 03723 // RunTestSet(lcd, pc); 03724 // } 03725 03726 #endif // TESTENABLE 03727 03728 #endif
Generated on Tue Jul 12 2022 17:28:36 by 1.7.2