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