This is a port of Henning Kralsen's UTFT library for Arduino/chipKIT to mbed, refactored to make full use of C++ inheritance and access control, in order to reduce work when implementing new drivers and at the same time make the code more readable and easier to maintain. As of now supported are SSD1289 (16-bit interface), HX8340-B (serial interface) and ST7735 (serial interface). Drivers for other controllers will be added as time and resources to acquire the displays to test the code permit.

Dependents:   test SDCard capstone_display capstone_display_2 ... more

TFTLCD Library

NOTE (2013-03-25) Tested with both mbed LPC1768 and Freedom KL25Z. -todor

A TFT LCD driver library, which at the moment provides support for the following display controllers: HX8340-B (serial interface), SSD1289 (16-bit interface), ST7735-R (serial interface), ILI9325/ILI9328 (16-bit interface).

As I am acquiring and testing out new displays, I decided to combine all ported drivers into one library as with the original work done by Henning. However I also had as a goal to make the code maintenance and readability easier/better, so the code has been heavily refactored to make full use of C++ facilities as inheritance and access control. I extracted the common pieces of code into a base class, which every driver inherits and only the controller-specific side is provided in the actual driver - things like initialization, addressing, data transfer, etc.

Another nice extension is that the display's backlight can now be controlled through the driver. Either a simple on/off method of control could be selected, or the brightness can be set through use of PWM (the latter placing some restrictions on which pins can be used for this, as mbed offers hardware PWM on only 6 pins).

I also plan to add support for touch screens as part of the library. The goal is to grow this piece of software into a lightweight graphics widgets library, which can be used to construct control screens with buttons or menus in a speedy and intuitive way.

Changes

2013-07-21

  • Fixed the sleep/wake-up functions of the ILI9328 driver.

2013-06-15

  • Added driver for ILI9328 (works with ILI9325) controller, 16-bit data bus. Screen rotation works as usual with the TFTLCD library, but for now only RGB565 color depth is working and you can use both 65K and 262K color space with this driver. But for some reason the sleep function is not behaving as expected; I am working on this.
  • This is only on my to-do list for now - haven't really had the time yet - but I am going to refactor the library a bit to allow use of GPIO ports for data transfers instead of DigitalOut: faster and cleaner that way. For those who are using it already in a working design and cannot repurpose the pins anymore, the current way it's working will still be available; I am hoping not to tear up the public interfaces of the library (... too much). Anyway, since I am at it, I will also try to add support for multiple bus interfaces to drivers that support it (i.e. both 8bit and 16bit use of ILI932x or SSD1289). Thought this might be a good place to give you guys the heads-up.

2013-01-25

  • Replaced all existing fonts from the UTFT library with the free Terminus font. Two different sizes are provided: 8x12 pixels and 16x28 pixels. I found the old fonts not so good looking and then they supported only the ASCII codes in the range 30 (space) to 126 (the tilde ). The 7segment font didn't even implement anything else than the numbers from 0 to 9 - so it was unusable for anything (one couldn't even display the time or date as it lacked the colon [:] or the period [.] or the slash [/] or the space [ ] characters). So I completely revamped the fonts and added Terminus as the new default with its 2 sizes. Further more I added in both sizes most of the characters up to ASCII code 255. For any code not in there, the space character is substituted. In the case, when you already have provided your own fonts, please have a look at the API changes in the files <terminus.h> and <terminus.cpp>: I promise you whatever time you spent designing your own font, it is not wasted; you merely need to add a second array, which describes which ASCII codes are available in your font, and their byte offset in the original character bitmap array; and a struct to tie all parts together and describe the character size. I am sorry for breaking the old API, but you will like the change and new options it brings you. Now you can insert any char above 127 up to code 255 (if available, of course) with its hex representation, e.g displaying the current temperature would look something like 85\xB0 F or 26\xB0 C (the space in between degree and F or C is needed because both F and C are used in hex numbers, so \xB0F is interpreted as ASCII code 2831 instead of ASCII code 176, followed by the temperature scale denomination; if you insist on avoiding the space, you could write 85\xB0\x46 which will be displayed correctly as 85°F). You can either look up the ASCII code you need on Google or Bing, or just look at what's available - how it looks and its hex value - in the comments in <terminus.cpp>.
  • Added PWM backlight control. If you intend to use this, please make sure that control pin is either one of p21, p22, p23, p24, p25, or p26, as only they support hardware PWM. Please be aware that the mbed pins do not have much juice behind them, so if your display's backlight requires a lot of current, you are better off interfacing through as small signal transistor or a MOSFET. For the rest please consult the updated Doxygen documentation. NOTE The addition of PWM-controlled backlight will not break your existing code, the new options have default values, which initialize the used driver to behave as prior to PWM. Only if you want to use the new feature, some changes need to be made. The PWM is configured to be 120Hz (period of 8.33 milliseconds), in order to avoid noticeable flicker in the backlight. If in your opinion this value is too fine, then you can reduce the frequency in the LCD constructor in <lcd_base.cpp> by increasing the period value. My recommendation is to avoid frequencies lower than 60Hz.

2012-12-21

  • Internal-only changes in the way drivers transmit colors - done to simplify the bitmap drawing routines; client API remains unchanged.

2012-12-12

  • Added the driver for the ST7735 display controller.
  • Added the RGB18 color mode: choose between 16-bit (65K distinct colors) and 18-bit (262K distinct colors) color space [supported by all drivers]. NOTE This feature requires the image drawing functions to be changed, in order to account for differences between configured display color depth and the color depth of the image. Please review the API docs, in particular the new type bitmap_t and the DrawBitmap functions.
  • Changed display rotation to be achieved through the correspondent settings in the respective controller registers: no more software translation between width and height in different display orientations.
  • Extended the orientation options: PORTRAIT (top line to 12 o'clock/upright) and LANDSCAPE (top line to 9 o'clock) positions are the old options, PORTRAIT_REV (top line to 6 o'clock/upside-down) and LANDSCAPE_REV (top line to 3 o'clock) are the new orientations.
  • Added more pre-defined colors: available now are COLOR_BLACK, COLOR_WHITE, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_CYAN, COLOR_MAGENTA and COLOR_YELLOW.

TODO

  • Finish implementing PWM-controlled backlight (current-sink configuration).
  • Add a driver for the HX8352-A controller (ITDB02-3.2WD 16:9 240x400 pixel resolution display).

How to Use

The code is documented, so please review the API docs. There is a simple example to get you started...

Committer:
ttodorov
Date:
Thu Jun 13 03:47:51 2013 +0000
Revision:
23:eca4414196ca
Child:
24:ac6e35658037
- ILI9328 driver not working yet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ttodorov 23:eca4414196ca 1 /*
ttodorov 23:eca4414196ca 2 * Copyright (C)2010-2012 Henning Karlsen. All right reserved.
ttodorov 23:eca4414196ca 3 * Copyright (C)2012-2013 Todor Todorov.
ttodorov 23:eca4414196ca 4 *
ttodorov 23:eca4414196ca 5 * This library is free software; you can redistribute it and/or
ttodorov 23:eca4414196ca 6 * modify it under the terms of the GNU Lesser General Public
ttodorov 23:eca4414196ca 7 * License as published by the Free Software Foundation; either
ttodorov 23:eca4414196ca 8 * version 2.1 of the License, or (at your option) any later version.
ttodorov 23:eca4414196ca 9 *
ttodorov 23:eca4414196ca 10 * This library is distributed in the hope that it will be useful,
ttodorov 23:eca4414196ca 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ttodorov 23:eca4414196ca 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ttodorov 23:eca4414196ca 13 * Lesser General Public License for more details.
ttodorov 23:eca4414196ca 14 *
ttodorov 23:eca4414196ca 15 * You should have received a copy of the GNU Lesser General Public
ttodorov 23:eca4414196ca 16 * License along with this library; if not, write to:
ttodorov 23:eca4414196ca 17 *
ttodorov 23:eca4414196ca 18 * Free Software Foundation, Inc.
ttodorov 23:eca4414196ca 19 * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA
ttodorov 23:eca4414196ca 20 *
ttodorov 23:eca4414196ca 21 *********************************************************************/
ttodorov 23:eca4414196ca 22 #include "ili9328.h"
ttodorov 23:eca4414196ca 23 #include "helpers.h"
ttodorov 23:eca4414196ca 24
ttodorov 23:eca4414196ca 25 #define REG_START_OSC 0x00
ttodorov 23:eca4414196ca 26
ttodorov 23:eca4414196ca 27 #define REG_DRIV_OUT_CTRL 0x01
ttodorov 23:eca4414196ca 28 #define REG_DRIV_WAV_CTRL 0x02
ttodorov 23:eca4414196ca 29 #define REG_ENTRY_MOD 0x03
ttodorov 23:eca4414196ca 30 #define REG_RESIZE_CTRL 0x04
ttodorov 23:eca4414196ca 31 #define REG_DISP_CTRL1 0x07
ttodorov 23:eca4414196ca 32 #define REG_DISP_CTRL2 0x08
ttodorov 23:eca4414196ca 33 #define REG_DISP_CTRL3 0x09
ttodorov 23:eca4414196ca 34 #define REG_DISP_CTRL4 0x0A
ttodorov 23:eca4414196ca 35 #define REG_RGB_DISP_IF_CTRL1 0x0C
ttodorov 23:eca4414196ca 36 #define REG_FRM_MARKER_POS 0x0D
ttodorov 23:eca4414196ca 37 #define REG_RGB_DISP_IF_CTRL2 0x0F
ttodorov 23:eca4414196ca 38 #define REG_PWR_CTRL1 0x10
ttodorov 23:eca4414196ca 39 #define REG_PWR_CTRL2 0x11
ttodorov 23:eca4414196ca 40 #define REG_PWR_CTRL3 0x12
ttodorov 23:eca4414196ca 41 #define REG_PWR_CTRL4 0x13
ttodorov 23:eca4414196ca 42 #define REG_GRAM_HORIZONTAL_ADDR 0x20
ttodorov 23:eca4414196ca 43 #define REG_GRAM_VERTICAL_ADDR 0x21
ttodorov 23:eca4414196ca 44 #define REG_GRAM_READWRITE 0x22
ttodorov 23:eca4414196ca 45 #define REG_PWR_CTRL7 0x29
ttodorov 23:eca4414196ca 46 #define REG_FRM_RATE_COL_CTRL 0x2B
ttodorov 23:eca4414196ca 47 #define REG_GAMMA_CTRL1 0x30
ttodorov 23:eca4414196ca 48 #define REG_GAMMA_CTRL2 0x31
ttodorov 23:eca4414196ca 49 #define REG_GAMMA_CTRL3 0x32
ttodorov 23:eca4414196ca 50 #define REG_GAMMA_CTRL4 0x35
ttodorov 23:eca4414196ca 51 #define REG_GAMMA_CTRL5 0x36
ttodorov 23:eca4414196ca 52 #define REG_GAMMA_CTRL6 0x37
ttodorov 23:eca4414196ca 53 #define REG_GAMMA_CTRL7 0x38
ttodorov 23:eca4414196ca 54 #define REG_GAMMA_CTRL8 0x39
ttodorov 23:eca4414196ca 55 #define REG_GAMMA_CTRL9 0x3C
ttodorov 23:eca4414196ca 56 #define REG_GAMMA_CTRL10 0x3D
ttodorov 23:eca4414196ca 57 #define REG_HORIZONTAL_START_ADDR 0x50
ttodorov 23:eca4414196ca 58 #define REG_HORIZONTAL_END_ADDR 0x51
ttodorov 23:eca4414196ca 59 #define REG_VERTICAL_START_ADDR 0x52
ttodorov 23:eca4414196ca 60 #define REG_VERTICAL_END_ADDR 0x53
ttodorov 23:eca4414196ca 61 #define REG_GATE_SCAN_CTRL1 0x60
ttodorov 23:eca4414196ca 62 #define REG_GATE_SCAN_CTRL2 0x61
ttodorov 23:eca4414196ca 63 #define REG_GATE_SCAN_CTRL3 0x6A
ttodorov 23:eca4414196ca 64 #define REG_PART_IMG1_DISP_POS 0x80
ttodorov 23:eca4414196ca 65 #define REG_PART_IMG1_START_ADDR 0x81
ttodorov 23:eca4414196ca 66 #define REG_PART_IMG1_END_ADDR 0x82
ttodorov 23:eca4414196ca 67 #define REG_PART_IMG2_DISP_POS 0x83
ttodorov 23:eca4414196ca 68 #define REG_PART_IMG2_START_ADDR 0x84
ttodorov 23:eca4414196ca 69 #define REG_PART_IMG2_END_ADDR 0x85
ttodorov 23:eca4414196ca 70 #define REG_PANEL_IF_CTRL1 0x90
ttodorov 23:eca4414196ca 71 #define REG_PANEL_IF_CTRL2 0x92
ttodorov 23:eca4414196ca 72 #define REG_PANEL_IF_CTRL3 0x93
ttodorov 23:eca4414196ca 73 #define REG_PANEL_IF_CTRL4 0x95
ttodorov 23:eca4414196ca 74 #define REG_PANEL_IF_CTRL5 0x97
ttodorov 23:eca4414196ca 75 #define REG_PANEL_IF_CTRL6 0x98
ttodorov 23:eca4414196ca 76
ttodorov 23:eca4414196ca 77 ILI9328_LCD::ILI9328_LCD( PinName CS, PinName RESET, PinName RS, PinName WR, BusOut* DATA_PORT, PinName BL, PinName RD, backlight_t blType, float defaultBackLightLevel )
ttodorov 23:eca4414196ca 78 : LCD( 240, 320, CS, RS, RESET, BL, blType, defaultBackLightLevel ), _lcd_pin_wr( WR )
ttodorov 23:eca4414196ca 79 {
ttodorov 23:eca4414196ca 80 _lcd_port = DATA_PORT;
ttodorov 23:eca4414196ca 81 if ( RD != NC ) _lcd_pin_rd = new DigitalOut( RD );
ttodorov 23:eca4414196ca 82 else _lcd_pin_rd = 0;
ttodorov 23:eca4414196ca 83 }
ttodorov 23:eca4414196ca 84
ttodorov 23:eca4414196ca 85 void ILI9328_LCD::Initialize( orientation_t orientation, colordepth_t colors )
ttodorov 23:eca4414196ca 86 {
ttodorov 23:eca4414196ca 87 _orientation = orientation;
ttodorov 23:eca4414196ca 88 _colorDepth = colors;
ttodorov 23:eca4414196ca 89
ttodorov 23:eca4414196ca 90 _lcd_pin_reset = HIGH;
ttodorov 23:eca4414196ca 91 wait_ms( 50 );
ttodorov 23:eca4414196ca 92 _lcd_pin_reset = LOW;
ttodorov 23:eca4414196ca 93 wait_ms( 100 );
ttodorov 23:eca4414196ca 94 _lcd_pin_reset = HIGH;
ttodorov 23:eca4414196ca 95 wait_ms( 1000 );
ttodorov 23:eca4414196ca 96 _lcd_pin_cs = HIGH;
ttodorov 23:eca4414196ca 97 if ( _lcd_pin_bl != 0 )
ttodorov 23:eca4414196ca 98 *_lcd_pin_bl = HIGH;
ttodorov 23:eca4414196ca 99 else if ( _bl_pwm != 0 )
ttodorov 23:eca4414196ca 100 *_bl_pwm = _bl_pwm_default;
ttodorov 23:eca4414196ca 101 if ( _lcd_pin_rd != 0 )
ttodorov 23:eca4414196ca 102 *_lcd_pin_rd = HIGH;
ttodorov 23:eca4414196ca 103 _lcd_pin_wr = HIGH;
ttodorov 23:eca4414196ca 104 wait_ms( 15 );
ttodorov 23:eca4414196ca 105
ttodorov 23:eca4414196ca 106 Activate();
ttodorov 23:eca4414196ca 107 //WriteCmdData( 0x00, 0x0001 ); // oscillator: 1 = on, 0 = off
ttodorov 23:eca4414196ca 108 //wait_ms( 1 );
ttodorov 23:eca4414196ca 109 WriteCmdData( REG_DRIV_OUT_CTRL, 0x0100 ); // Driver Output Control Register (R01h)
ttodorov 23:eca4414196ca 110 WriteCmdData( REG_DRIV_WAV_CTRL, 0x0700 ); // LCD Driving Waveform Control (R02h)
ttodorov 23:eca4414196ca 111 WriteCmdData( REG_ENTRY_MOD, 0x1030 ); // Entry Mode (R03h) (BGR=on;ID1=on;ID2=on;AM=0)
ttodorov 23:eca4414196ca 112 WriteCmdData( REG_DISP_CTRL2, 0x0302 );
ttodorov 23:eca4414196ca 113 WriteCmdData( REG_DISP_CTRL3, 0x0000 );
ttodorov 23:eca4414196ca 114 WriteCmdData( REG_DISP_CTRL4, 0x0000 ); // Fmark On
ttodorov 23:eca4414196ca 115 WriteCmdData( REG_PWR_CTRL1, 0x0000 ); // Power Control 1 (R10h)
ttodorov 23:eca4414196ca 116 WriteCmdData( REG_PWR_CTRL2, 0x0007 ); // Power Control 2 (R11h)
ttodorov 23:eca4414196ca 117 WriteCmdData( REG_PWR_CTRL3, 0x0000 ); // Power Control 3 (R12h)
ttodorov 23:eca4414196ca 118 WriteCmdData( REG_PWR_CTRL4, 0x0000 ); // Power Control 4 (R13h)
ttodorov 23:eca4414196ca 119 wait_ms( 1000 );
ttodorov 23:eca4414196ca 120 WriteCmdData( REG_PWR_CTRL1, 0x14B0 ); // Power Control 1 (R10h)
ttodorov 23:eca4414196ca 121 wait_ms( 500 );
ttodorov 23:eca4414196ca 122 WriteCmdData( REG_PWR_CTRL2, 0x0007 ); // Power Control 2 (R11h)
ttodorov 23:eca4414196ca 123 wait_ms( 500 );
ttodorov 23:eca4414196ca 124 WriteCmdData( REG_PWR_CTRL3, 0x008E ); // Power Control 3 (R12h)
ttodorov 23:eca4414196ca 125 WriteCmdData( REG_PWR_CTRL4, 0x0C00 ); // Power Control 4 (R13h)
ttodorov 23:eca4414196ca 126 WriteCmdData( REG_PWR_CTRL7, 0x0015 ); // NVM read data 2 (R29h)
ttodorov 23:eca4414196ca 127 wait_ms( 500 );
ttodorov 23:eca4414196ca 128 WriteCmdData( REG_GAMMA_CTRL1, 0x0000 ); // Gamma Control 1
ttodorov 23:eca4414196ca 129 WriteCmdData( REG_GAMMA_CTRL2, 0x0107 ); // Gamma Control 2
ttodorov 23:eca4414196ca 130 WriteCmdData( REG_GAMMA_CTRL3, 0x0000 ); // Gamma Control 3
ttodorov 23:eca4414196ca 131 WriteCmdData( REG_GAMMA_CTRL4, 0x0203 ); // Gamma Control 4
ttodorov 23:eca4414196ca 132 WriteCmdData( REG_GAMMA_CTRL5, 0x0402 ); // Gamma Control 5
ttodorov 23:eca4414196ca 133 WriteCmdData( REG_GAMMA_CTRL6, 0x0000 ); // Gamma Control 6
ttodorov 23:eca4414196ca 134 WriteCmdData( REG_GAMMA_CTRL7, 0x0207 ); // Gamma Control 7
ttodorov 23:eca4414196ca 135 WriteCmdData( REG_GAMMA_CTRL8, 0x0000 ); // Gamma Control 8
ttodorov 23:eca4414196ca 136 WriteCmdData( REG_GAMMA_CTRL9, 0x0203 ); // Gamma Control 9
ttodorov 23:eca4414196ca 137 WriteCmdData( REG_GAMMA_CTRL10, 0x0403 ); // Gamma Control 10
ttodorov 23:eca4414196ca 138 WriteCmdData( REG_HORIZONTAL_START_ADDR, 0x0000 ); // Window Horizontal RAM Address Start (R50h)
ttodorov 23:eca4414196ca 139 WriteCmdData( REG_HORIZONTAL_END_ADDR, _disp_width - 1); // Window Horizontal RAM Address End (R51h)
ttodorov 23:eca4414196ca 140 WriteCmdData( REG_VERTICAL_START_ADDR, 0x0000 ); // Window Vertical RAM Address Start (R52h)
ttodorov 23:eca4414196ca 141 WriteCmdData( REG_VERTICAL_END_ADDR, _disp_height - 1); // Window Vertical RAM Address End (R53h)
ttodorov 23:eca4414196ca 142 WriteCmdData( REG_GATE_SCAN_CTRL1, 0xa700 ); // Driver Output Control (R60h)
ttodorov 23:eca4414196ca 143 WriteCmdData( REG_GATE_SCAN_CTRL2, 0x0003 ); // Driver Output Control (R61h) - enable VLE
ttodorov 23:eca4414196ca 144 WriteCmdData( REG_PANEL_IF_CTRL1, 0x0010 ); // Panel Interface Control 1 (R90h)
ttodorov 23:eca4414196ca 145
ttodorov 23:eca4414196ca 146 // Display On
ttodorov 23:eca4414196ca 147 WriteCmdData( REG_DISP_CTRL1, 0x0133 ); // Display Control (R07h)
ttodorov 23:eca4414196ca 148 wait_ms( 500 );
ttodorov 23:eca4414196ca 149 WriteCmd( REG_GRAM_READWRITE );
ttodorov 23:eca4414196ca 150
ttodorov 23:eca4414196ca 151 Deactivate();
ttodorov 23:eca4414196ca 152 }
ttodorov 23:eca4414196ca 153
ttodorov 23:eca4414196ca 154 void ILI9328_LCD::Sleep( void )
ttodorov 23:eca4414196ca 155 {
ttodorov 23:eca4414196ca 156 //WriteCmdData( 0x10, 0x0001 ); // sleep mode: 0 = exit, 1 = enter
ttodorov 23:eca4414196ca 157 LCD::Sleep();
ttodorov 23:eca4414196ca 158 }
ttodorov 23:eca4414196ca 159
ttodorov 23:eca4414196ca 160 void ILI9328_LCD::WakeUp( void )
ttodorov 23:eca4414196ca 161 {
ttodorov 23:eca4414196ca 162 //WriteCmdData( 0x10, 0x0000 ); // sleep mode: 0 = exit, 1 = enter
ttodorov 23:eca4414196ca 163 LCD::WakeUp();
ttodorov 23:eca4414196ca 164 }
ttodorov 23:eca4414196ca 165
ttodorov 23:eca4414196ca 166 void ILI9328_LCD::WriteCmd( unsigned short cmd )
ttodorov 23:eca4414196ca 167 {
ttodorov 23:eca4414196ca 168 _lcd_pin_rs = LOW;
ttodorov 23:eca4414196ca 169 _lcd_port->write( cmd );
ttodorov 23:eca4414196ca 170 pulseLow( _lcd_pin_wr );
ttodorov 23:eca4414196ca 171 }
ttodorov 23:eca4414196ca 172
ttodorov 23:eca4414196ca 173 void ILI9328_LCD::WriteData( unsigned short data )
ttodorov 23:eca4414196ca 174 {
ttodorov 23:eca4414196ca 175 _lcd_pin_rs = HIGH;
ttodorov 23:eca4414196ca 176 _lcd_port->write( data );
ttodorov 23:eca4414196ca 177 pulseLow( _lcd_pin_wr );
ttodorov 23:eca4414196ca 178 }
ttodorov 23:eca4414196ca 179
ttodorov 23:eca4414196ca 180 void ILI9328_LCD::SetXY( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2 )
ttodorov 23:eca4414196ca 181 {
ttodorov 23:eca4414196ca 182 /*
ttodorov 23:eca4414196ca 183 if ( _orientation == PORTRAIT || _orientation == PORTRAIT_REV )
ttodorov 23:eca4414196ca 184 {
ttodorov 23:eca4414196ca 185 WriteCmdData( 0x44, ( x2 << 8 ) + x1 );
ttodorov 23:eca4414196ca 186 WriteCmdData( 0x45, y1 );
ttodorov 23:eca4414196ca 187 WriteCmdData( 0x46, y2 );
ttodorov 23:eca4414196ca 188 WriteCmdData( 0x4e, x1 );
ttodorov 23:eca4414196ca 189 WriteCmdData( 0x4f, y1 );
ttodorov 23:eca4414196ca 190 }
ttodorov 23:eca4414196ca 191 else
ttodorov 23:eca4414196ca 192 {
ttodorov 23:eca4414196ca 193 WriteCmdData( 0x44, ( y2 << 8 ) + y1 );
ttodorov 23:eca4414196ca 194 WriteCmdData( 0x45, x1 );
ttodorov 23:eca4414196ca 195 WriteCmdData( 0x46, x2 );
ttodorov 23:eca4414196ca 196 WriteCmdData( 0x4e, y1 );
ttodorov 23:eca4414196ca 197 WriteCmdData( 0x4f, x1 );
ttodorov 23:eca4414196ca 198 }
ttodorov 23:eca4414196ca 199 */
ttodorov 23:eca4414196ca 200 WriteCmdData( REG_HORIZONTAL_START_ADDR, x1 );
ttodorov 23:eca4414196ca 201 WriteCmdData( REG_HORIZONTAL_END_ADDR, x2 );
ttodorov 23:eca4414196ca 202 WriteCmdData( REG_VERTICAL_START_ADDR, y1 );
ttodorov 23:eca4414196ca 203 WriteCmdData( REG_VERTICAL_END_ADDR, y2 );
ttodorov 23:eca4414196ca 204 WriteCmdData( REG_GRAM_HORIZONTAL_ADDR, x1 );
ttodorov 23:eca4414196ca 205 WriteCmdData( REG_GRAM_VERTICAL_ADDR, y1 );
ttodorov 23:eca4414196ca 206 WriteCmd( 0x22 );
ttodorov 23:eca4414196ca 207 }
ttodorov 23:eca4414196ca 208
ttodorov 23:eca4414196ca 209 void ILI9328_LCD::SetPixelColor( unsigned int color, colordepth_t mode )
ttodorov 23:eca4414196ca 210 {
ttodorov 23:eca4414196ca 211 unsigned char r, g, b;
ttodorov 23:eca4414196ca 212 unsigned short clr;
ttodorov 23:eca4414196ca 213 if ( _colorDepth == RGB16 )
ttodorov 23:eca4414196ca 214 {
ttodorov 23:eca4414196ca 215 switch ( mode )
ttodorov 23:eca4414196ca 216 {
ttodorov 23:eca4414196ca 217 case RGB16:
ttodorov 23:eca4414196ca 218 WriteData( color & 0xFFFF );
ttodorov 23:eca4414196ca 219 break;
ttodorov 23:eca4414196ca 220 case RGB18:
ttodorov 23:eca4414196ca 221 r = ( color >> 10 ) & 0xF8;
ttodorov 23:eca4414196ca 222 g = ( color >> 4 ) & 0xFC;
ttodorov 23:eca4414196ca 223 b = ( color >> 1 ) & 0x1F;
ttodorov 23:eca4414196ca 224 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | b );
ttodorov 23:eca4414196ca 225 WriteData( clr );
ttodorov 23:eca4414196ca 226 break;
ttodorov 23:eca4414196ca 227 case RGB24:
ttodorov 23:eca4414196ca 228 r = ( color >> 16 ) & 0xF8;
ttodorov 23:eca4414196ca 229 g = ( color >> 8 ) & 0xFC;
ttodorov 23:eca4414196ca 230 b = color & 0xF8;
ttodorov 23:eca4414196ca 231 clr = ( ( r | ( g >> 5 ) ) << 8 ) | ( ( g << 3 ) | ( b >> 3 ) );
ttodorov 23:eca4414196ca 232 WriteData( clr );
ttodorov 23:eca4414196ca 233 break;
ttodorov 23:eca4414196ca 234 }
ttodorov 23:eca4414196ca 235 }
ttodorov 23:eca4414196ca 236 else if ( _colorDepth == RGB18 )
ttodorov 23:eca4414196ca 237 {
ttodorov 23:eca4414196ca 238 switch ( mode )
ttodorov 23:eca4414196ca 239 {
ttodorov 23:eca4414196ca 240 case RGB16:
ttodorov 23:eca4414196ca 241 r = ( ( color >> 8 ) & 0xF8 ) | ( ( color & 0x8000 ) >> 13 );
ttodorov 23:eca4414196ca 242 g = ( color >> 3 ) & 0xFC;
ttodorov 23:eca4414196ca 243 b = ( ( color << 3 ) & 0xFC ) | ( ( color >> 3 ) & 0x01 );
ttodorov 23:eca4414196ca 244 WriteData( ( r << 8 ) | g );
ttodorov 23:eca4414196ca 245 WriteData( b );
ttodorov 23:eca4414196ca 246 break;
ttodorov 23:eca4414196ca 247 case RGB18:
ttodorov 23:eca4414196ca 248 b = ( color << 2 ) & 0xFC;
ttodorov 23:eca4414196ca 249 g = ( color >> 4 ) & 0xFC;
ttodorov 23:eca4414196ca 250 r = ( color >> 10 ) & 0xFC;
ttodorov 23:eca4414196ca 251 WriteData( ( r << 8 ) | g );
ttodorov 23:eca4414196ca 252 WriteData( b );
ttodorov 23:eca4414196ca 253 break;
ttodorov 23:eca4414196ca 254 case RGB24:
ttodorov 23:eca4414196ca 255 r = ( color >> 16 ) & 0xFC;
ttodorov 23:eca4414196ca 256 g = ( color >> 8 ) & 0xFC;
ttodorov 23:eca4414196ca 257 b = color & 0xFC;
ttodorov 23:eca4414196ca 258 WriteData( ( r << 8 ) | g );
ttodorov 23:eca4414196ca 259 WriteData( b );
ttodorov 23:eca4414196ca 260 break;
ttodorov 23:eca4414196ca 261 }
ttodorov 23:eca4414196ca 262 }
ttodorov 23:eca4414196ca 263 }