Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SPI_TFT_ILI9341 by
Revision 2:0a16083193a4, committed 2013-07-21
- Comitter:
- dreschpe
- Date:
- Sun Jul 21 11:57:06 2013 +0000
- Parent:
- 1:6d6125e88de7
- Commit message:
- implement set_orientation
Changed in this revision
SPI_TFT_ILI9341.cpp | Show annotated file Show diff for this revision Revisions of this file |
SPI_TFT_ILI9341.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SPI_TFT_ILI9341.cpp Thu Jun 13 19:54:24 2013 +0000 +++ b/SPI_TFT_ILI9341.cpp Sun Jul 21 11:57:06 2013 +0000 @@ -11,6 +11,7 @@ */ // 12.06.13 fork from SPI_TFT code because controller is different ... +// 14.07.13 Test with real display and bugfix #include "SPI_TFT_ILI9341.h" #include "mbed.h" @@ -43,25 +44,27 @@ } -/*void SPI_TFT_ILI9341::set_orientation(unsigned int o) +void SPI_TFT_ILI9341::set_orientation(unsigned int o) { orientation = o; + wr_cmd(0x36); // MEMORY_ACCESS_CONTROL switch (orientation) { case 0: - wr_reg(0x16, 0x08); + _spi.write(0x48); break; case 1: - wr_reg(0x16, 0x68); + _spi.write(0x28); break; case 2: - wr_reg(0x16, 0xC8); + _spi.write(0x88); break; case 3: - wr_reg(0x16, 0xA8); + _spi.write(0xE8); break; } + _cs = 1; WindowMax(); -} */ +} // write command to tft register @@ -79,7 +82,6 @@ void SPI_TFT_ILI9341::wr_dat(unsigned char dat) { _spi.write(dat); // mbed lib -// _cs = 1; } @@ -102,7 +104,7 @@ void SPI_TFT_ILI9341::tft_reset() { - _spi.format(8,3); // 8 bit spi mode 3 + _spi.format(8,3); // 8 bit spi mode 3 _spi.frequency(10000000); // 10 Mhz SPI clock _cs = 1; // cs high _dc = 1; // dc high @@ -674,18 +676,20 @@ unsigned int j; int padd; unsigned short *bitmap_ptr = (unsigned short *)bitmap; + unsigned int i; + // the lines are padded to multiple of 4 bytes in a bitmap padd = -1; do { padd ++; } while (2*(w + padd)%4 != 0); window(x, y, w, h); + bitmap_ptr += ((h - 1)* (w + padd)); wr_cmd(0x2C); // send pixel _spi.format(16,3); // switch to 16 bit Mode 3 - unsigned int i; - for (j = 0; j < h; j++) { //Lines - for (i = 0; i < w; i++) { // copy pixel data to TFT - _spi.write(*bitmap_ptr); // one line + for (j = 0; j < h; j++) { //Lines + for (i = 0; i < w; i++) { // one line + _spi.write(*bitmap_ptr); // copy pixel data to TFT bitmap_ptr++; } bitmap_ptr -= 2*w;
--- a/SPI_TFT_ILI9341.h Thu Jun 13 19:54:24 2013 +0000 +++ b/SPI_TFT_ILI9341.h Sun Jul 21 11:57:06 2013 +0000 @@ -1,5 +1,5 @@ -/* mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller - * Copyright (c) 2011 Peter Drescher - DC2PD +/* mbed library for 240*320 pixel display TFT based on ILI9341 LCD Controller + * Copyright (c) 2013 Peter Drescher - DC2PD * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, @@ -57,9 +57,10 @@ * * * - * // the TFT is connected to SPI pin 5-7 + * // the TFT is connected to SPI pin 5-7 and IO's 8-10 * SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc - * + * If your display need a signal for switch the backlight use a aditional IO pin in your program + * * int main() { * TFT.claim(stdout); // send stdout to the TFT display * //TFT.claim(stderr); // send stderr to the TFT display @@ -269,10 +270,10 @@ /** Set the orientation of the screen * x,y: 0,0 is always top left * - * @param o direction to use the screen (0-3) 90� Steps + * @param o direction to use the screen (0-3) * */ - //void set_orientation(unsigned int o); + void set_orientation(unsigned int o); SPI _spi; DigitalOut _cs;