Я потому и спрашиваю что в библиотеке
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
А на дисплее LS020 нет выводов
LCD_CD
LCD_WR
LCD_RD
поэтому и спрашиваю чему соответствуют эти выводы если соеденять с LS020
А можно на пальцах что и куда в скетче. Сильно не пинайте только осваиваю)
/***************************************************
This is a library for the Adafruit 1.8" SPI display.
This library works with the Adafruit 1.8" TFT Breakout w/SD card
----> http://www.adafruit.com/products/358
The 1.8" TFT shield
----> https://www.adafruit.com/product/802
The 1.44" TFT breakout
----> https://www.adafruit.com/product/2088
as well as Adafruit raw 1.8" TFT display
----> http://www.adafruit.com/products/618
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define TFT1_CS 53
#define TFT2_CS 50
#define TFT1_RST 8 // you can also connect this to the Arduino reset
// in which case, set this #define pin to -1!
#define TFT2_RST 8 // you can also connect this to the Arduino reset
// in which case, set this #define pin to -1!
#define TFT1_DC 9
#define TFT2_DC 9
// Option 1 (recommended): must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
//Adafruit_ST7735 tft1 = Adafruit_ST7735(TFT1_CS, TFT1_DC, TFT1_RST);
//Adafruit_ST7735 tft2 = Adafruit_ST7735(TFT2_CS, TFT2_DC, TFT2_RST);
// Option 2: use any pins but a little slower!
#define TFT1_SCLK 52 // set these to be whatever pins you like!
#define TFT2_SCLK 52 // set these to be whatever pins you like!
#define TFT1_MOSI 51 // set these to be whatever pins you like!
#define TFT2_MOSI 51 // set these to be whatever pins you like!
Adafruit_ST7735 tft1 = Adafruit_ST7735(TFT1_CS, TFT1_DC, TFT1_MOSI, TFT1_SCLK, TFT1_RST);
Adafruit_ST7735 tft2 = Adafruit_ST7735(TFT2_CS, TFT2_DC, TFT2_MOSI, TFT2_SCLK, TFT2_RST);
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
Serial.print("Hello! ST7735 TFT Test");
//writeRegister8(0x36, 0x0A) //попробуй
// Use this initializer if you're using a 1.8" TFT
tft1.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
tft2.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
Serial.println("Initialized");
uint16_t time = millis();
tft1.fillScreen(ST7735_BLACK);
tft2.fillScreen(ST7735_GREEN);
time = millis() - time;
Serial.println(time, DEC);
delay(500);
// large block of text
tft1.fillScreen(ST7735_RED);
testdrawtext("HELLO PEOPLE ", ST7735_GREEN);
delay(11000);
// large block of text
tft2.fillScreen(ST7735_BLUE);
testdrawtext("HELLO World ", ST7735_RED);
delay(11000);
// a single pixel
tft1.drawPixel(tft1.width()/2, tft1.height()/2, ST7735_GREEN);
delay(500);
// a single pixel
tft2.drawPixel(tft2.width()/2, tft2.height()/2, ST7735_GREEN);
delay(500);
tft1.fillScreen(ST7735_BLACK);
delay(500);
tft2.fillScreen(ST7735_WHITE);
delay(500);
Serial.println("done");
delay(1000);
}
void loop() {
tft1.fillScreen(ST7735_RED);
testdrawtext("HELLO WORLD ", ST7735_GREEN);
tft2.fillScreen(ST7735_RED);
testdrawtext("HELLO PEOPLE ", ST7735_GREEN);
}
void testdrawtext(char *text, uint16_t color) {
tft1.setCursor(0, 0);
tft1.setTextColor(color);
tft1.setTextWrap(true);
tft1.print(text);
tft2.setCursor(0, 0);
tft2.setTextColor(color);
tft2.setTextWrap(true);
tft2.print(text);
}
с китайского телефона 2009-10 чтоль года (времен нокии N9) - когда пошли первые смартфоны 2х симочные еще с теликом аналоговым (антенка выдвигалась) - это те, которые подделывали аля бренды всех марок и мастей
этот вроде nexus7 обзывался (клон)
в общем он работал полностью - у него лет 5 назад сдох сенсор, а замена стоила как такойже телефон. с тех пор и валялся на полке пыль собирал...
//кстати на удивление но углы экрана шикарные, прядка 160 градусов без искажений и зизменений цвета практически....
{
Serial.println("***********use minimal init 2************");
// от ili9488
writeRegister8(0x11, 0);//Exit Sleep
delay(150);
// writeRegister8(0x00, 0x00);// очень важен, иначе перевернуто и цветопередача не та
writeRegister8(0x3A, 0x05);// очень важен, иначе черно-белые кракозябры
writeRegister8(0x29, 0);//display on
writeRegister8(0x2c, 0);//write end
}
пробовал и 0х0А и вообще разные варианты и даже просто закоментировал - экран не реагирует никак на эти манипуляции :(
хотя в порт выводит сообщение, что подтверждает, что и менно эта часть кода включается
Всем привет . Решил хоть ,что то изобрести или повторить за кем то хоть какую нибудь фитюльку. Обажаю паять и повторять за кем то какие то интересные поделки . Решил подключить дисплей от сотового телефона к ардуино . Была мобилка и умерла . Остался живой LSD c маркировкой TXDT350DH-111.Не могу найти распиновку . Если я не туда пишу , то подскажите куда обратиться с вопросом . ТУТ ПРОСТО Я ВПЕРВЫЕ .
чтото нифига толком не выходит, такое впечатление, что библиотека вообще не верно формирует запрос цвета... как я понял ДШ - на 948* цвет отправлять надо за 2 захода - а библиотека только 1 раз шлет - вот и не проходит полный цвет...
ну тут моих знаний уже не хватает это переписать...
На каком у тебя запустился? На 9488 ?
https://drive.google.com/file/d/1oMNJmfqJ3j1AiVxAJY5vqb9etbaHzF2i/view?usp=sharing https://drive.google.com/file/d/1pNr2JbChzjxZlRiuMWlYWBeUp0lfMb0D/view?usp=sharing https://drive.google.com/file/d/10JXPxplUQTyOQm-eyAiU5JWyBQAxxCB0/view?usp=sharing
Добрый день! вот фото ....Лучше не получается ...Извините.
только на 0x9341
как я понял - в библиотеке работает этот блок
writeRegister8(0x36, 0x00) попробуй так изменить
kalugin77 не нашел нормального reset.
Разводка такая
0,1,2,3 как обычно, либо RD,WR,DC,CS , либо наоборот. Подсветка у тебя больше 3В.
С ней разберешься после. Сначала подключай без нее и считывай.
RESET сначала подключи к 7, попробуй считать и выкладывай.
Если считает фигню, подключи ресет к 8.
Хочу проверить дисплей LS020 рабочий или нет подключив к ардуино уно или мега . Нашёл в интернете скетч читалку V5.2
Там идёт по SPI а в скетче
LSD_CS
LSD_CD
LSD_WR
LSD_RD
LSD_RESET
какие ножки прописать куда Если брать уно или мега .
в SPI каким выводам соответствуют например LSD_WR или LSD_RD и так далее
сМОТРИ БИБЛИОТЕКИ ДЛЯ АРДУИНО. тАМ ОН ДОЛЖЕН БЫТЬ. тАМ ЖЕ И ПОДКЛЮЧЕНИЕ.
Я потому и спрашиваю что в библиотеке
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
А на дисплее LS020 нет выводов
LCD_CD
LCD_WR
LCD_RD
поэтому и спрашиваю чему соответствуют эти выводы если соеденять с LS020
Ищи в библиотеке подключение по SPI, а ты смотришь про параллельное.
Если б я это всё знал мне бы и обрашаться не нужно было ) Там про подключение только
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// use these 8 data lines to the LCD: // For the Arduino Uno, MEGA //
D0 connects to digital pin 8
D1 connects to digital pin 9
D2 connects to digital pin 2
D3 connects to digital pin 3
Теперь так что ли
#define LCD_CS 8
#define LCD_CD 9
#define LCD_WR 2
#define LCD_RD 3
#define LCD_RESET A4
?
Я запутался )
Как это всё соеденить с ардуино и дисплеем
Спасибо!
writeRegister8(0x36, 0x00) попробуй так изменить
тоже не дало никакого результата
вообще удалил из библиотеки этот блок - оно работает по прежнему....
завтра буду думать что я не так делаю....
нужно с библиотекой разбираться.
ELITE а откуда ты снял этот дисплей?
А можете подсказать как прописывать два диспа в скетче? Пока показывают одно и тоже...
нужно с библиотекой разбираться.
writeRegister8(0x36, 0x0A) попробуй
А можно на пальцах что и куда в скетче. Сильно не пинайте только осваиваю)
ELITE а откуда ты снял этот дисплей?
с китайского телефона 2009-10 чтоль года (времен нокии N9) - когда пошли первые смартфоны 2х симочные еще с теликом аналоговым (антенка выдвигалась) - это те, которые подделывали аля бренды всех марок и мастей
этот вроде nexus7 обзывался (клон)
в общем он работал полностью - у него лет 5 назад сдох сенсор, а замена стоила как такойже телефон. с тех пор и валялся на полке пыль собирал...
//кстати на удивление но углы экрана шикарные, прядка 160 градусов без искажений и зизменений цвета практически....
writeRegister8(0x36, 0x0A) попробуй
спасибо, утром буду пробовать - все железки на работе валяются, домой не таскаю, на работе времени больше свободного, чем дома
2354resd
Сигналы на CS у тебя разведены на 2 разные ноги.
Инициализируешь дисплеи. Можно одновременно. Поднимаешь оба CS вверх.
Затем опускаешь CS 1 дисплея и пишешь в него. Поднимаешь CS.
Опускаешь CS 2 дисплея и пишешь в него. Поднимаешь CS.
ELITE Нужно искать по инициализациям или даташитам похожие команды у контроллеров.
Основные команды могут совпадать, а регистры, отвечающие за цветность и инверсию
могут быть отличными от 0х36. Начни с записи в 0х36 сначала 00, затем FF. Если ничего не поменяется, то
нужно искать, как писал выше.
2354resd
Сигналы на CS у тебя разведены на 2 разные ноги.
Инициализируешь дисплеи. Можно одновременно. Поднимаешь оба CS вверх.
Затем опускаешь CS 1 дисплея и пишешь в него. Поднимаешь CS.
Опускаешь CS 2 дисплея и пишешь в него. Поднимаешь CS.
Если не сложно поправьте пожалуйста в скетче как примерно должно быть..
Не могу разобраться. При одной инициализации оба показывают одно и тоже, прописываю оба один который tft1 молчит второй работает.
Я не пишу для ардуино. Наверное так.
voidloop() {digitalWrite(TFT1_CS, HIGH);
digitalWrite(TFT2_CS, HIGH);
digitalWrite(TFT1_CS, LOW); // пишем в 1 дисплей
tft1.fillScreen(ST7735_RED);
testdrawtext("HELLO WORLD ", ST7735_GREEN);digitalWrite(TFT1_CS, HIGH);
digitalWrite(TFT2_CS, LOW); // пишем во 2 дисплей
tft1.fillScreen(ST7735_BLUE);
testdrawtext("HELLO PEOPLE ", ST7735_GREEN);digitalWrite(TFT2_CS, HIGH);
}
Не помогло. Один работает, второй при запуске пишет Hello черно белым и перевернутым и все белый фон
Тогда начни с изучения библиотеки, которой пользуешься. Когда поймешь, как она работает,
напишешь что хочешь.
Тогда начни с изучения библиотеки, которой пользуешься. Когда поймешь, как она работает,
напишешь что хочешь.
Текст пишет на одном дисплее сразу оба варианта один поверх другого... Библиотека пока совсем потемки для меня
Я не знаю, как написана библиотека. Поэтому не смогу помочь. Жди, может появится кто разбирается,
посоветует что-нибудь.
для кеонтроля сделал вывод в порт
но результатов нет, на команды не реагирует никак
{ Serial.println("***********use minimal init 2************"); // от ili9488 writeRegister8(0x11, 0);//Exit Sleep delay(150); // writeRegister8(0x00, 0x00);// очень важен, иначе перевернуто и цветопередача не та writeRegister8(0x3A, 0x05);// очень важен, иначе черно-белые кракозябры writeRegister8(0x29, 0);//display on writeRegister8(0x2c, 0);//write end }пробовал и 0х0А и вообще разные варианты и даже просто закоментировал - экран не реагирует никак на эти манипуляции :(
хотя в порт выводит сообщение, что подтверждает, что и менно эта часть кода включается
Посмотри инициализации на контроллеры ILI. 93хх , 94хх. Разрешение у тебя скорее всего 240х320.
Больше для 3,2 дюймов врятли. Если в инициализации есть регистры 0х11 0х29, то смотри по даташитам
какие регистры отвечают за поворот и цветность (RGB - BGR) дисплея. И в них пытайся поменять в
соответствии с даташитом. У табя сейчас инициализируется режим BGR, поэтому цвета не те.
320*480 это точно, тк рисует толинейно в этом размере точно по пикселам и во весь экран
writeRegister8(0x36, 0x10)
дало правильную ориентацию :)
теперь цветность осталось победить
Всем привет . Решил хоть ,что то изобрести или повторить за кем то хоть какую нибудь фитюльку. Обажаю паять и повторять за кем то какие то интересные поделки . Решил подключить дисплей от сотового телефона к ардуино . Была мобилка и умерла . Остался живой LSD c маркировкой TXDT350DH-111.Не могу найти распиновку . Если я не туда пишу , то подскажите куда обратиться с вопросом . ТУТ ПРОСТО Я ВПЕРВЫЕ .
Вот ссылки с фото на дисплей :
https://pp.userapi.com/c841534/v841534794/6cc03/EhsILuCvHBE.jpg
сделал тест с авто подставой значений
и чтото мне кажется, что у меня картинка в негативе именно идет, тк вебый выводит черным и наоборот
Если 320х480, то посмотри даташиты на ILI 9481(86,88). В них с картинками описывается
какой бит в этом регистре за что отвечает. Возможно инверсия изображения лежит в другом регистре.
В даташите в принципе и без знания языка все понятно.
TonitoCampos
Пока его можно включить только на 9 или 18 бит. Попробуй считать ID контроллера
подключив D0-D7. 0123 это RD,WR,DC,CS или наоборот
Спасибо.. Опробуем ) Еще раз спасибо ...
если 9488 то выбор или 3 бит или 16 и 24 бит цветность
лежат в 3А блоке - но тут пробовал - или искажено или черно-белое или без картинки вобще
но по идее он умеет по SPI 3 и 4 работать (что немного обнадеживает)
чтото нифига толком не выходит, такое впечатление, что библиотека вообще не верно формирует запрос цвета... как я понял ДШ - на 948* цвет отправлять надо за 2 захода - а библиотека только 1 раз шлет - вот и не проходит полный цвет...
ну тут моих знаний уже не хватает это переписать...
у 9488 в 36 регистре есть бит переворачивающий цветность RGB --BGR
да, это я пробовал - цвета меняются, но он меняет всего 2 варианта - но конечный итог не идет
вместо желтого у меня или красный или синий
итого не хватает части зеленого
по ДШ выходит что зеленый 2 раза отправляется
RG + GB пара
при перевороте выходит BG + GR
но видимо отправка библиотекой идет только первой части
Ты запускаешь библиотеку в 8 битном или 16 битном режиме? Если в 16 битном, то она посылает два байта цвета
одновременно на D0-D15. Тогда ты теряешь часть зеленого плюс синий или красный цвет.
Какой скетч ты запускаешь?
#include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_TFTLCD.h> // Hardware-specific library #define LCD_CS A3 // Chip Select goes to Analog 3 #define LCD_CD A2 // Command/Data goes to Analog 2 #define LCD_WR A1 // LCD Write goes to Analog 1 #define LCD_RD A0 // LCD Read goes to Analog 0 #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin // use these 8 data lines to the LCD: // For the Arduino Uno, MEGA // D0 connects to digital pin 8 (Notice these are // D1 connects to digital pin 9 NOT in order!) // D2 connects to digital pin 2 // D3 connects to digital pin 3 // D4 connects to digital pin 4 // D5 connects to digital pin 5 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // Assign human-readable names to some common 16-bit color values: #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); void setup(void) { Serial.begin(9600); tft.reset(); uint16_t identifier ; // 0x9341; uint8_t minimal; identifier = 0x9341; minimal=2; // флаг использовать минимальный инит и рисование через регистры как в ili9341 // минимальный инит для часто встречающихся контроллеров , подобных ili9341 ili9327 ili9486 ili9488 HX835x R61581 ,... // у которых setXY через 2Ah 2Bh + 2Ch // (0x11, 0); ВЫХОД ИЗ СНА // delay(150); // (0x36, 0x48); очень важен, иначе перевернуто и цветопередача не та // (0x3A, 0x05); очень важен, иначе черно-белые кракозябры // (0x29, 0); ВКЛЮЧЕНИЕ ДИСПЛЕЯ // (0x2c, 0); конец записи , необязательно но желательно tft.begin(identifier, minimal); //tft.setRotation(1); } int iii=0x10; void loop(void) { // for(uint8_t rotation=0; rotation<4; rotation++) { tft.setRotation(rotation); } //tft.reset(); //tft.begin(0x9341, iii-0x10); iii++; Serial.print("* test ");Serial.println(iii-0x10); testText(iii-0x10); delay(100); // testFillScreen(); // delay(1000); // testFilledRoundRects(); // delay(2000); // testFilledTriangles(); // delay(2000); } unsigned long testFillScreen() { unsigned long start = micros(); tft.fillScreen(BLACK); tft.fillScreen(RED); tft.fillScreen(GREEN); tft.fillScreen(BLUE); tft.fillScreen(BLACK); return micros() - start; } unsigned long testText(int i) { tft.fillScreen(BLACK); unsigned long start = micros(); tft.setCursor(0, 0); tft.setTextColor(WHITE); tft.setTextSize(1); tft.println("Hello World! v5.3"); tft.setTextColor(YELLOW); tft.setTextSize(2); tft.println(1234.56); tft.setTextColor(RED); tft.setTextSize(3); tft.println(0xDEADBEEF, HEX); tft.println(); /* tft.setTextColor(GREEN); tft.setTextSize(5); tft.println("GREEN"); tft.setTextColor(RED); tft.setTextSize(5); tft.println("RED"); tft.setTextColor(BLUE); tft.setTextSize(5); tft.println("BLUE"); tft.setTextColor(BLACK); tft.setTextSize(5); tft.println("BLACK"); tft.setTextColor(WHITE); tft.setTextSize(5); tft.println("WHITE");*/ tft.setTextColor(i); tft.setTextSize(5); tft.println("color"); tft.setTextColor(BLACK); tft.setTextSize(5); tft.println(i);tft.println(i, BIN);tft.println(i, HEX); tft.setTextColor(WHITE); tft.setTextSize(5); tft.println(i);tft.println(i, BIN);tft.println(i, HEX); tft.setTextSize(2); tft.println("I implore thee,"); tft.setTextSize(1); tft.println("my foonting turlingdromes."); tft.println("And hooptiously drangle me"); tft.println("with crinkly bindlewurdles,"); tft.println("Or I will rend thee"); tft.println("in the gobberwarts"); tft.println("with my blurglecruncheon,"); tft.println("see if I don't!"); return micros() - start; } unsigned long testLines(uint16_t color) { unsigned long start, t; int x1, y1, x2, y2, w = tft.width(), h = tft.height(); tft.fillScreen(BLACK); x1 = y1 = 0; y2 = h - 1; start = micros(); for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); x2 = w - 1; for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); t = micros() - start; // fillScreen doesn't count against timing tft.fillScreen(BLACK); x1 = w - 1; y1 = 0; y2 = h - 1; start = micros(); for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); x2 = 0; for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); t += micros() - start; tft.fillScreen(BLACK); x1 = 0; y1 = h - 1; y2 = 0; start = micros(); for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); x2 = w - 1; for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); t += micros() - start; tft.fillScreen(BLACK); x1 = w - 1; y1 = h - 1; y2 = 0; start = micros(); for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color); x2 = 0; for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color); return micros() - start; } unsigned long testFastLines(uint16_t color1, uint16_t color2) { unsigned long start; int x, y, w = tft.width(), h = tft.height(); tft.fillScreen(BLACK); start = micros(); for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1); for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2); return micros() - start; } unsigned long testRects(uint16_t color) { unsigned long start; int n, i, i2, cx = tft.width() / 2, cy = tft.height() / 2; tft.fillScreen(BLACK); n = min(tft.width(), tft.height()); start = micros(); for(i=2; i<n; i+=6) { i2 = i / 2; tft.drawRect(cx-i2, cy-i2, i, i, color); } return micros() - start; } unsigned long testFilledRects(uint16_t color1, uint16_t color2) { unsigned long start, t = 0; int n, i, i2, cx = tft.width() / 2 - 1, cy = tft.height() / 2 - 1; tft.fillScreen(BLACK); n = min(tft.width(), tft.height()); for(i=n; i>0; i-=6) { i2 = i / 2; start = micros(); tft.fillRect(cx-i2, cy-i2, i, i, color1); t += micros() - start; // Outlines are not included in timing results tft.drawRect(cx-i2, cy-i2, i, i, color2); } return t; } unsigned long testFilledCircles(uint8_t radius, uint16_t color) { unsigned long start; int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2; tft.fillScreen(BLACK); start = micros(); for(x=radius; x<w; x+=r2) { for(y=radius; y<h; y+=r2) { tft.fillCircle(x, y, radius, color); } } return micros() - start; } unsigned long testCircles(uint8_t radius, uint16_t color) { unsigned long start; int x, y, r2 = radius * 2, w = tft.width() + radius, h = tft.height() + radius; // Screen is not cleared for this one -- this is // intentional and does not affect the reported time. start = micros(); for(x=0; x<w; x+=r2) { for(y=0; y<h; y+=r2) { tft.drawCircle(x, y, radius, color); } } return micros() - start; } unsigned long testTriangles() { unsigned long start; int n, i, cx = tft.width() / 2 - 1, cy = tft.height() / 2 - 1; tft.fillScreen(BLACK); n = min(cx, cy); start = micros(); for(i=0; i<n; i+=5) { tft.drawTriangle( cx , cy - i, // peak cx - i, cy + i, // bottom left cx + i, cy + i, // bottom right tft.color565(0, 0, i)); } return micros() - start; } unsigned long testFilledTriangles() { unsigned long start, t = 0; int i, cx = tft.width() / 2 - 1, cy = tft.height() / 2 - 1; tft.fillScreen(BLACK); start = micros(); for(i=min(cx,cy); i>10; i-=5) { start = micros(); tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, tft.color565(0, i, i)); t += micros() - start; tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, tft.color565(i, i, 0)); } return t; } unsigned long testRoundRects() { unsigned long start; int w, i, i2, cx = tft.width() / 2 - 1, cy = tft.height() / 2 - 1; tft.fillScreen(BLACK); w = min(tft.width(), tft.height()); start = micros(); for(i=0; i<w; i+=6) { i2 = i / 2; tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0)); } return micros() - start; } unsigned long testFilledRoundRects() { unsigned long start; int i, i2, cx = tft.width() / 2 - 1, cy = tft.height() / 2 - 1; tft.fillScreen(BLACK); start = micros(); for(i=min(tft.width(), tft.height()); i>20; i-=6) { i2 = i / 2; tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0)); } return micros() - start; }и библиотеку подправил так
// IMPORTANT: LIBRARY MUST BE SPECIFICALLY CONFIGURED FOR EITHER TFT SHIELD // OR BREAKOUT BOARD USAGE. SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h // Graphics library by ladyada/adafruit with init code from Rossum // MIT license #if defined(__SAM3X8E__) #include <include/pio.h> #define PROGMEM #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned short *)(addr)) #endif #ifdef __AVR__ #include <avr/pgmspace.h> #endif #include "pins_arduino.h" #include "wiring_private.h" #include "Adafruit_TFTLCD.h" #include "pin_magic.h" #define TFTWIDTH 320 #define TFTHEIGHT 480 //#define TFTWIDTH 240 //#define TFTHEIGHT 320 // LCD controller chip identifiers #define ID_932X 0 #define ID_7575 1 #define ID_9341 2 #define ID_HX8357D 3 #define ID_UNKNOWN 0xFF #include "registers.h" // Constructor for breakout board (configurable LCD control lines). // Can still use this w/shield, but parameters are ignored. Adafruit_TFTLCD::Adafruit_TFTLCD( uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t reset) : Adafruit_GFX(TFTWIDTH, TFTHEIGHT) { #ifndef USE_ADAFRUIT_SHIELD_PINOUT // Convert pin numbers to registers and bitmasks _reset = reset; #ifdef __AVR__ csPort = portOutputRegister(digitalPinToPort(cs)); cdPort = portOutputRegister(digitalPinToPort(cd)); wrPort = portOutputRegister(digitalPinToPort(wr)); rdPort = portOutputRegister(digitalPinToPort(rd)); #endif #if defined(__SAM3X8E__) csPort = digitalPinToPort(cs); cdPort = digitalPinToPort(cd); wrPort = digitalPinToPort(wr); rdPort = digitalPinToPort(rd); #endif csPinSet = digitalPinToBitMask(cs); cdPinSet = digitalPinToBitMask(cd); wrPinSet = digitalPinToBitMask(wr); rdPinSet = digitalPinToBitMask(rd); csPinUnset = ~csPinSet; cdPinUnset = ~cdPinSet; wrPinUnset = ~wrPinSet; rdPinUnset = ~rdPinSet; #ifdef __AVR__ *csPort |= csPinSet; // Set all control bits to HIGH (idle) *cdPort |= cdPinSet; // Signals are ACTIVE LOW *wrPort |= wrPinSet; *rdPort |= rdPinSet; #endif #if defined(__SAM3X8E__) csPort->PIO_SODR |= csPinSet; // Set all control bits to HIGH (idle) cdPort->PIO_SODR |= cdPinSet; // Signals are ACTIVE LOW wrPort->PIO_SODR |= wrPinSet; rdPort->PIO_SODR |= rdPinSet; #endif pinMode(cs, OUTPUT); // Enable outputs pinMode(cd, OUTPUT); pinMode(wr, OUTPUT); pinMode(rd, OUTPUT); if(reset) { digitalWrite(reset, HIGH); pinMode(reset, OUTPUT); } #endif init(); } // Constructor for shield (fixed LCD control lines) Adafruit_TFTLCD::Adafruit_TFTLCD(void) : Adafruit_GFX(TFTWIDTH, TFTHEIGHT) { init(); } // Initialization common to both shield & breakout configs void Adafruit_TFTLCD::init(void) { #ifdef USE_ADAFRUIT_SHIELD_PINOUT CS_IDLE; // Set all control bits to idle state WR_IDLE; RD_IDLE; CD_DATA; digitalWrite(5, HIGH); // Reset line pinMode(A3, OUTPUT); // Enable outputs pinMode(A2, OUTPUT); pinMode(A1, OUTPUT); pinMode(A0, OUTPUT); pinMode( 5, OUTPUT); #endif setWriteDir(); // Set up LCD data port(s) for WRITE operations rotation = 0; cursor_y = cursor_x = 0; textsize = 1; textcolor = 0xFFFF; _width = TFTWIDTH; _height = TFTHEIGHT; } // Initialization command tables for different LCD controllers #define TFTLCD_DELAY 0xFF static const uint8_t HX8347G_regValues[] PROGMEM = { 0x2E , 0x89, 0x29 , 0x8F, 0x2B , 0x02, 0xE2 , 0x00, 0xE4 , 0x01, 0xE5 , 0x10, 0xE6 , 0x01, 0xE7 , 0x10, 0xE8 , 0x70, 0xF2 , 0x00, 0xEA , 0x00, 0xEB , 0x20, 0xEC , 0x3C, 0xED , 0xC8, 0xE9 , 0x38, 0xF1 , 0x01, // skip gamma, do later 0x1B , 0x1A, 0x1A , 0x02, 0x24 , 0x61, 0x25 , 0x5C, 0x18 , 0x36, 0x19 , 0x01, 0x1F , 0x88, TFTLCD_DELAY , 5 , // delay 5 ms 0x1F , 0x80, TFTLCD_DELAY , 5 , 0x1F , 0x90, TFTLCD_DELAY , 5 , 0x1F , 0xD4, TFTLCD_DELAY , 5 , 0x17 , 0x05, 0x36 , 0x09, 0x28 , 0x38, TFTLCD_DELAY , 40 , 0x28 , 0x3C, 0x02 , 0x00, 0x03 , 0x00, 0x04 , 0x00, 0x05 , 0xEF, 0x06 , 0x00, 0x07 , 0x00, 0x08 , 0x01, 0x09 , 0x3F }; static const uint8_t HX8357D_regValues[] PROGMEM = { HX8357_SWRESET, 0, HX8357D_SETC, 3, 0xFF, 0x83, 0x57, TFTLCD_DELAY, 250, HX8357_SETRGB, 4, 0x00, 0x00, 0x06, 0x06, HX8357D_SETCOM, 1, 0x25, // -1.52V HX8357_SETOSC, 1, 0x68, // Normal mode 70Hz, Idle mode 55 Hz HX8357_SETPANEL, 1, 0x05, // BGR, Gate direction swapped HX8357_SETPWR1, 6, 0x00, 0x15, 0x1C, 0x1C, 0x83, 0xAA, HX8357D_SETSTBA, 6, 0x50, 0x50, 0x01, 0x3C, 0x1E, 0x08, // MEME GAMMA HERE HX8357D_SETCYC, 7, 0x02, 0x40, 0x00, 0x2A, 0x2A, 0x0D, 0x78, HX8357_COLMOD, 1, 0x55, HX8357_MADCTL, 1, 0xC0, HX8357_TEON, 1, 0x00, HX8357_TEARLINE, 2, 0x00, 0x02, HX8357_SLPOUT, 0, TFTLCD_DELAY, 150, HX8357_DISPON, 0, TFTLCD_DELAY, 50, }; static const uint16_t ILI932x_regValues[] PROGMEM = { ILI932X_START_OSC , 0x0001, // Start oscillator TFTLCD_DELAY , 50, // 50 millisecond delay ILI932X_DRIV_OUT_CTRL , 0x0100, ILI932X_DRIV_WAV_CTRL , 0x0700, ILI932X_ENTRY_MOD , 0x1030, ILI932X_RESIZE_CTRL , 0x0000, ILI932X_DISP_CTRL2 , 0x0202, ILI932X_DISP_CTRL3 , 0x0000, ILI932X_DISP_CTRL4 , 0x0000, ILI932X_RGB_DISP_IF_CTRL1, 0x0, ILI932X_FRM_MARKER_POS , 0x0, ILI932X_RGB_DISP_IF_CTRL2, 0x0, ILI932X_POW_CTRL1 , 0x0000, ILI932X_POW_CTRL2 , 0x0007, ILI932X_POW_CTRL3 , 0x0000, ILI932X_POW_CTRL4 , 0x0000, TFTLCD_DELAY , 200, ILI932X_POW_CTRL1 , 0x1690, ILI932X_POW_CTRL2 , 0x0227, TFTLCD_DELAY , 50, ILI932X_POW_CTRL3 , 0x001A, TFTLCD_DELAY , 50, ILI932X_POW_CTRL4 , 0x1800, ILI932X_POW_CTRL7 , 0x002A, TFTLCD_DELAY , 50, ILI932X_GAMMA_CTRL1 , 0x0000, ILI932X_GAMMA_CTRL2 , 0x0000, ILI932X_GAMMA_CTRL3 , 0x0000, ILI932X_GAMMA_CTRL4 , 0x0206, ILI932X_GAMMA_CTRL5 , 0x0808, ILI932X_GAMMA_CTRL6 , 0x0007, ILI932X_GAMMA_CTRL7 , 0x0201, ILI932X_GAMMA_CTRL8 , 0x0000, ILI932X_GAMMA_CTRL9 , 0x0000, ILI932X_GAMMA_CTRL10 , 0x0000, ILI932X_GRAM_HOR_AD , 0x0000, ILI932X_GRAM_VER_AD , 0x0000, ILI932X_HOR_START_AD , 0x0000, ILI932X_HOR_END_AD , 0x00EF, ILI932X_VER_START_AD , 0X0000, ILI932X_VER_END_AD , 0x013F, ILI932X_GATE_SCAN_CTRL1 , 0xA700, // Driver Output Control (R60h) ILI932X_GATE_SCAN_CTRL2 , 0x0003, // Driver Output Control (R61h) ILI932X_GATE_SCAN_CTRL3 , 0x0000, // Driver Output Control (R62h) ILI932X_PANEL_IF_CTRL1 , 0X0010, // Panel Interface Control 1 (R90h) ILI932X_PANEL_IF_CTRL2 , 0X0000, ILI932X_PANEL_IF_CTRL3 , 0X0003, ILI932X_PANEL_IF_CTRL4 , 0X1100, ILI932X_PANEL_IF_CTRL5 , 0X0000, ILI932X_PANEL_IF_CTRL6 , 0X0000, ILI932X_DISP_CTRL1 , 0x0133, // Main screen turn on }; void Adafruit_TFTLCD::begin(uint16_t id ,uint8_t mflag ) { uint8_t i = 0; reset(); delay(200); if((id == 0x9325) || (id == 0x9328)) { uint16_t a, d; driver = ID_932X; CS_ACTIVE; while(i < sizeof(ILI932x_regValues) / sizeof(uint16_t)) { a = pgm_read_word(&ILI932x_regValues[i++]); d = pgm_read_word(&ILI932x_regValues[i++]); if(a == TFTLCD_DELAY) delay(d); else writeRegister16(a, d); } setRotation(rotation); setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1); } else if (id == 0x9341) { uint16_t a, d; driver = ID_9341; CS_ACTIVE; writeRegister8(ILI9341_SOFTRESET, 0); delay(50); if (mflag==0) { //Serial.print("*************="); Serial.println(mflag); writeRegister8(ILI9341_DISPLAYOFF, 0); writeRegister8(ILI9341_POWERCONTROL1, 0x23); writeRegister8(ILI9341_POWERCONTROL2, 0x10); writeRegister16(ILI9341_VCOMCONTROL1, 0x2B2B); writeRegister8(ILI9341_VCOMCONTROL2, 0xC0); writeRegister8(ILI9341_MEMCONTROL, ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR); writeRegister8(ILI9341_PIXELFORMAT, 0x55); writeRegister16(ILI9341_FRAMECONTROL, 0x001B); writeRegister8(ILI9341_ENTRYMODE, 0x07); /* writeRegister32(ILI9341_DISPLAYFUNC, 0x0A822700);*/ writeRegister8(ILI9341_SLEEPOUT, 0); delay(150); writeRegister8(ILI9341_DISPLAYON, 0); delay(500); } else if (mflag==1) { //Serial.println("***********use minimal init************"); // от ili9488 writeRegister8(0x11, 0);//Exit Sleep delay(150); writeRegister8(0x36, 0x48);// очень важен, иначе перевернуто и цветопередача не та writeRegister8(0x3A, 0x05);// очень важен, иначе черно-белые кракозябры writeRegister8(0x29, 0);//display on writeRegister8(0x2c, 0);//write end } else { Serial.println("***********use minimal init 2************"); // от ili9488 writeRegister8(0x11, 0);//Exit Sleep delay(150); writeRegister8(0x36, 0x10);// ориентация writeRegister8(0x3A, 0x05);// очень важен, иначе черно-белые кракозябры // writeRegister8(0x3B, mflag-2);// цвета writeRegister8(0x29, 0);//display on writeRegister8(0x2c, 0);//write end } setAddrWindow(0, 0, TFTWIDTH-1, TFTHEIGHT-1); return; } else if (id == 0x8357) { // HX8357D driver = ID_HX8357D; CS_ACTIVE; while(i < sizeof(HX8357D_regValues)) { uint8_t r = pgm_read_byte(&HX8357D_regValues[i++]); uint8_t len = pgm_read_byte(&HX8357D_regValues[i++]); if(r == TFTLCD_DELAY) { delay(len); } else { //Serial.print("Register $"); Serial.print(r, HEX); //Serial.print(" datalen "); Serial.println(len); CS_ACTIVE; CD_COMMAND; write8(r); CD_DATA; for (uint8_t d=0; d<len; d++) { uint8_t x = pgm_read_byte(&HX8357D_regValues[i++]); write8(x); } CS_IDLE; } } return; } else if(id == 0x7575) { uint8_t a, d; driver = ID_7575; CS_ACTIVE; while(i < sizeof(HX8347G_regValues)) { a = pgm_read_byte(&HX8347G_regValues[i++]); d = pgm_read_byte(&HX8347G_regValues[i++]); if(a == TFTLCD_DELAY) delay(d); else writeRegister8(a, d); } setRotation(rotation); setLR(); // Lower-right corner of address window } else { driver = ID_UNKNOWN; return; } } void Adafruit_TFTLCD::reset(void) { CS_IDLE; // CD_DATA; WR_IDLE; RD_IDLE; #ifdef USE_ADAFRUIT_SHIELD_PINOUT digitalWrite(5, LOW); delay(2); digitalWrite(5, HIGH); #else if(_reset) { digitalWrite(_reset, LOW); delay(2); digitalWrite(_reset, HIGH); } #endif // Data transfer sync CS_ACTIVE; CD_COMMAND; write8(0x00); for(uint8_t i=0; i<3; i++) WR_STROBE; // Three extra 0x00s CS_IDLE; } // Sets the LCD address window (and address counter, on 932X). // Relevant to rect/screen fills and H/V lines. Input coordinates are // assumed pre-sorted (e.g. x2 >= x1). void Adafruit_TFTLCD::setAddrWindow(int x1, int y1, int x2, int y2) { CS_ACTIVE; if(driver == ID_932X) { // Values passed are in current (possibly rotated) coordinate // system. 932X requires hardware-native coords regardless of // MADCTL, so rotate inputs as needed. The address counter is // set to the top-left corner -- although fill operations can be // done in any direction, the current screen rotation is applied // because some users find it disconcerting when a fill does not // occur top-to-bottom. int x, y, t; switch(rotation) { default: x = x1; y = y1; break; case 1: t = y1; y1 = x1; x1 = TFTWIDTH - 1 - y2; y2 = x2; x2 = TFTWIDTH - 1 - t; x = x2; y = y1; break; case 2: t = x1; x1 = TFTWIDTH - 1 - x2; x2 = TFTWIDTH - 1 - t; t = y1; y1 = TFTHEIGHT - 1 - y2; y2 = TFTHEIGHT - 1 - t; x = x2; y = y2; break; case 3: t = x1; x1 = y1; y1 = TFTHEIGHT - 1 - x2; x2 = y2; y2 = TFTHEIGHT - 1 - t; x = x1; y = y2; break; } writeRegister16(0x0050, x1); // Set address window writeRegister16(0x0051, x2); writeRegister16(0x0052, y1); writeRegister16(0x0053, y2); writeRegister16(0x0020, x ); // Set address counter to top left writeRegister16(0x0021, y ); } else if(driver == ID_7575) { writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x1); writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y1); writeRegisterPair(HX8347G_COLADDREND_HI , HX8347G_COLADDREND_LO , x2); writeRegisterPair(HX8347G_ROWADDREND_HI , HX8347G_ROWADDREND_LO , y2); } else if ((driver == ID_9341) || (driver == ID_HX8357D)){ uint32_t t; t = x1; t <<= 16; t |= x2; writeRegister32(ILI9341_COLADDRSET, t); // HX8357D uses same registers! t = y1; t <<= 16; t |= y2; writeRegister32(ILI9341_PAGEADDRSET, t); // HX8357D uses same registers! } CS_IDLE; } // Unlike the 932X drivers that set the address window to the full screen // by default (using the address counter for drawPixel operations), the // 7575 needs the address window set on all graphics operations. In order // to save a few register writes on each pixel drawn, the lower-right // corner of the address window is reset after most fill operations, so // that drawPixel only needs to change the upper left each time. void Adafruit_TFTLCD::setLR(void) { CS_ACTIVE; writeRegisterPair(HX8347G_COLADDREND_HI, HX8347G_COLADDREND_LO, _width - 1); writeRegisterPair(HX8347G_ROWADDREND_HI, HX8347G_ROWADDREND_LO, _height - 1); CS_IDLE; } // Fast block fill operation for fillScreen, fillRect, H/V line, etc. // Requires setAddrWindow() has previously been called to set the fill // bounds. 'len' is inclusive, MUST be >= 1. void Adafruit_TFTLCD::flood(uint16_t color, uint32_t len) { uint16_t blocks; uint8_t i, hi = color >> 8, lo = color; CS_ACTIVE; CD_COMMAND; if (driver == ID_9341) { write8(0x2C); } else if (driver == ID_932X) { write8(0x00); // High byte of GRAM register... write8(0x22); // Write data to GRAM } else if (driver == ID_HX8357D) { write8(HX8357_RAMWR); } else { write8(0x22); // Write data to GRAM } // Write first pixel normally, decrement counter by 1 CD_DATA; write8(hi); write8(lo); len--; blocks = (uint16_t)(len / 64); // 64 pixels/block if(hi == lo) { // High and low bytes are identical. Leave prior data // on the port(s) and just toggle the write strobe. while(blocks--) { i = 16; // 64 pixels/block / 4 pixels/pass do { WR_STROBE; WR_STROBE; WR_STROBE; WR_STROBE; // 2 bytes/pixel WR_STROBE; WR_STROBE; WR_STROBE; WR_STROBE; // x 4 pixels } while(--i); } // Fill any remaining pixels (1 to 64) for(i = (uint8_t)len & 63; i--; ) { WR_STROBE; WR_STROBE; } } else { while(blocks--) { i = 16; // 64 pixels/block / 4 pixels/pass do { write8(hi); write8(lo); write8(hi); write8(lo); write8(hi); write8(lo); write8(hi); write8(lo); } while(--i); } for(i = (uint8_t)len & 63; i--; ) { write8(hi); write8(lo); } } CS_IDLE; } void Adafruit_TFTLCD::drawFastHLine(int16_t x, int16_t y, int16_t length, uint16_t color) { int16_t x2; // Initial off-screen clipping if((length <= 0 ) || (y < 0 ) || ( y >= _height) || (x >= _width) || ((x2 = (x+length-1)) < 0 )) return; if(x < 0) { // Clip left length += x; x = 0; } if(x2 >= _width) { // Clip right x2 = _width - 1; length = x2 - x + 1; } setAddrWindow(x, y, x2, y); flood(color, length); if(driver == ID_932X) setAddrWindow(0, 0, _width - 1, _height - 1); else setLR(); } void Adafruit_TFTLCD::drawFastVLine(int16_t x, int16_t y, int16_t length, uint16_t color) { int16_t y2; // Initial off-screen clipping if((length <= 0 ) || (x < 0 ) || ( x >= _width) || (y >= _height) || ((y2 = (y+length-1)) < 0 )) return; if(y < 0) { // Clip top length += y; y = 0; } if(y2 >= _height) { // Clip bottom y2 = _height - 1; length = y2 - y + 1; } setAddrWindow(x, y, x, y2); flood(color, length); if(driver == ID_932X) setAddrWindow(0, 0, _width - 1, _height - 1); else setLR(); } void Adafruit_TFTLCD::fillRect(int16_t x1, int16_t y1, int16_t w, int16_t h, uint16_t fillcolor) { int16_t x2, y2; // Initial off-screen clipping if( (w <= 0 ) || (h <= 0 ) || (x1 >= _width) || (y1 >= _height) || ((x2 = x1+w-1) < 0 ) || ((y2 = y1+h-1) < 0 )) return; if(x1 < 0) { // Clip left w += x1; x1 = 0; } if(y1 < 0) { // Clip top h += y1; y1 = 0; } if(x2 >= _width) { // Clip right x2 = _width - 1; w = x2 - x1 + 1; } if(y2 >= _height) { // Clip bottom y2 = _height - 1; h = y2 - y1 + 1; } setAddrWindow(x1, y1, x2, y2); flood(fillcolor, (uint32_t)w * (uint32_t)h); if(driver == ID_932X) setAddrWindow(0, 0, _width - 1, _height - 1); else setLR(); } void Adafruit_TFTLCD::fillScreen(uint16_t color) { if(driver == ID_932X) { // For the 932X, a full-screen address window is already the default // state, just need to set the address pointer to the top-left corner. // Although we could fill in any direction, the code uses the current // screen rotation because some users find it disconcerting when a // fill does not occur top-to-bottom. uint16_t x, y; switch(rotation) { default: x = 0 ; y = 0 ; break; case 1 : x = TFTWIDTH - 1; y = 0 ; break; case 2 : x = TFTWIDTH - 1; y = TFTHEIGHT - 1; break; case 3 : x = 0 ; y = TFTHEIGHT - 1; break; } CS_ACTIVE; writeRegister16(0x0020, x); writeRegister16(0x0021, y); } else if ((driver == ID_9341) || (driver == ID_7575) || (driver == ID_HX8357D)) { // For these, there is no settable address pointer, instead the // address window must be set for each drawing operation. However, // this display takes rotation into account for the parameters, no // need to do extra rotation math here. setAddrWindow(0, 0, _width - 1, _height - 1); } flood(color, (long)TFTWIDTH * (long)TFTHEIGHT); } void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color) { // Clip if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return; CS_ACTIVE; if(driver == ID_932X) { int16_t t; switch(rotation) { case 1: t = x; x = TFTWIDTH - 1 - y; y = t; break; case 2: x = TFTWIDTH - 1 - x; y = TFTHEIGHT - 1 - y; break; case 3: t = x; x = y; y = TFTHEIGHT - 1 - t; break; } writeRegister16(0x0020, x); writeRegister16(0x0021, y); writeRegister16(0x0022, color); } else if(driver == ID_7575) { uint8_t hi, lo; switch(rotation) { default: lo = 0 ; break; case 1 : lo = 0x60; break; case 2 : lo = 0xc0; break; case 3 : lo = 0xa0; break; } writeRegister8( HX8347G_MEMACCESS , lo); // Only upper-left is set -- bottom-right is full screen default writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x); writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y); hi = color >> 8; lo = color; CD_COMMAND; write8(0x22); CD_DATA; write8(hi); write8(lo); } else if ((driver == ID_9341) || (driver == ID_HX8357D)) { setAddrWindow(x, y, _width-1, _height-1); CS_ACTIVE; CD_COMMAND; write8(0x2C); CD_DATA; write8(color >> 8); write8(color); } CS_IDLE; } // Issues 'raw' an array of 16-bit color values to the LCD; used // externally by BMP examples. Assumes that setWindowAddr() has // previously been set to define the bounds. Max 255 pixels at // a time (BMP examples read in small chunks due to limited RAM). void Adafruit_TFTLCD::pushColors(uint16_t *data, uint8_t len, boolean first) { uint16_t color; uint8_t hi, lo; CS_ACTIVE; if(first == true) { // Issue GRAM write command only on first call CD_COMMAND; if(driver == ID_932X) write8(0x00); if ((driver == ID_9341) || (driver == ID_HX8357D)){ write8(0x2C); } else { write8(0x22); } } CD_DATA; while(len--) { color = *data++; hi = color >> 8; // Don't simplify or merge these lo = color; // lines, there's macro shenanigans write8(hi); // going on. write8(lo); } CS_IDLE; } void Adafruit_TFTLCD::setRotation(uint8_t x) { // Call parent rotation func first -- sets up rotation flags, etc. Adafruit_GFX::setRotation(x); // Then perform hardware-specific rotation operations... CS_ACTIVE; if(driver == ID_932X) { uint16_t t; switch(rotation) { default: t = 0x1030; break; case 1 : t = 0x1028; break; case 2 : t = 0x1000; break; case 3 : t = 0x1018; break; } writeRegister16(0x0003, t ); // MADCTL // For 932X, init default full-screen address window: setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here } if(driver == ID_7575) { uint8_t t; switch(rotation) { default: t = 0 ; break; case 1 : t = 0x60; break; case 2 : t = 0xc0; break; case 3 : t = 0xa0; break; } writeRegister8(HX8347G_MEMACCESS, t); // 7575 has to set the address window on most drawing operations. // drawPixel() cheats by setting only the top left...by default, // the lower right is always reset to the corner. setLR(); // CS_IDLE happens here } if (driver == ID_9341) { // MEME, HX8357D uses same registers as 9341 but different values uint16_t t; switch (rotation) { case 2: t = ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR; break; case 3: t = ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR; break; case 0: t = ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR; break; case 1: t = ILI9341_MADCTL_MX | ILI9341_MADCTL_MY | ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR; break; } writeRegister8(ILI9341_MADCTL, t ); // MADCTL // For 9341, init default full-screen address window: setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here } if (driver == ID_HX8357D) { // MEME, HX8357D uses same registers as 9341 but different values uint16_t t; switch (rotation) { case 2: t = HX8357B_MADCTL_RGB; break; case 3: t = HX8357B_MADCTL_MX | HX8357B_MADCTL_MV | HX8357B_MADCTL_RGB; break; case 0: t = HX8357B_MADCTL_MX | HX8357B_MADCTL_MY | HX8357B_MADCTL_RGB; break; case 1: t = HX8357B_MADCTL_MY | HX8357B_MADCTL_MV | HX8357B_MADCTL_RGB; break; } writeRegister8(ILI9341_MADCTL, t ); // MADCTL // For 8357, init default full-screen address window: setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here }} #ifdef read8isFunctionalized #define read8(x) x=read8fn() #endif // Because this function is used infrequently, it configures the ports for // the read operation, reads the data, then restores the ports to the write // configuration. Write operations happen a LOT, so it's advantageous to // leave the ports in that state as a default. uint16_t Adafruit_TFTLCD::readPixel(int16_t x, int16_t y) { if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return 0; CS_ACTIVE; if(driver == ID_932X) { uint8_t hi, lo; int16_t t; switch(rotation) { case 1: t = x; x = TFTWIDTH - 1 - y; y = t; break; case 2: x = TFTWIDTH - 1 - x; y = TFTHEIGHT - 1 - y; break; case 3: t = x; x = y; y = TFTHEIGHT - 1 - t; break; } writeRegister16(0x0020, x); writeRegister16(0x0021, y); // Inexplicable thing: sometimes pixel read has high/low bytes // reversed. A second read fixes this. Unsure of reason. Have // tried adjusting timing in read8() etc. to no avail. for(uint8_t pass=0; pass<2; pass++) { CD_COMMAND; write8(0x00); write8(0x22); // Read data from GRAM CD_DATA; setReadDir(); // Set up LCD data port(s) for READ operations read8(hi); // First 2 bytes back are a dummy read read8(hi); read8(hi); // Bytes 3, 4 are actual pixel value read8(lo); setWriteDir(); // Restore LCD data port(s) to WRITE configuration } CS_IDLE; return ((uint16_t)hi << 8) | lo; } else if(driver == ID_7575) { uint8_t r, g, b; writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x); writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y); CD_COMMAND; write8(0x22); // Read data from GRAM setReadDir(); // Set up LCD data port(s) for READ operations CD_DATA; read8(r); // First byte back is a dummy read read8(r); read8(g); read8(b); setWriteDir(); // Restore LCD data port(s) to WRITE configuration CS_IDLE; return (((uint16_t)r & B11111000) << 8) | (((uint16_t)g & B11111100) << 3) | ( b >> 3); } else return 0; } // Ditto with the read/write port directions, as above. uint16_t Adafruit_TFTLCD::readID(void) { uint8_t hi, lo ; Serial.println(F("v5.3 B0h <- 0xFFFFFF <- 0x040404 from Slider")) ; Serial.println(F("www.arduino.ru/forum/apparatnye-voprosy/arduino-i-displei-ot-sotikov-mobilnykh-telefonov ")); Serial.println(" "); Serial.print("reg p1 p2 p3 p4 p5 p6 p7 p8 "); //Serial.println(" "); for (uint8_t i=0; i<255; i++) { // i<128 readRegPrint8param(i); } Serial.println(" "); Serial.println("o------------------------------------o"); Serial.print("| |"); readRegPrint8param(0x00); Serial.print(" |"); readRegPrint8param(0x04); Serial.print(" |"); readRegPrint8param(0xB0); Serial.print(" |"); readRegPrint8param(0xBF); Serial.print(" |"); readRegPrint8param(0xD3); Serial.print(" |"); readRegPrint8param(0xDA); Serial.print(" |"); readRegPrint8param(0xDB); Serial.print(" |"); readRegPrint8param(0xDC); Serial.print(" |"); readRegPrint8param(0xEF); Serial.print(" |"); Serial.println(" "); Serial.println("| |"); Serial.println("o------------------------------------o"); delay(1000);Serial.print(" .");delay(1000);Serial.print(" ."); delay(1000);Serial.print(" ."); delay(1000);Serial.print(" ."); delay(1000);Serial.print(" .");delay(1000);Serial.print(" ."); delay(1000);Serial.print(" ."); delay(1000);Serial.println(" "); //Serial.println(" "); Serial.print(" writing in Manufacturer Command Access Protect (B0h) <- 0xFFFFFF "); writeRegister24(0xb0, 0xffffff); delay(300); //Serial.println(" "); readRegPrint8param(0xB0); Serial.println(" "); Serial.print("Device Code Read (BFh) "); readRegPrint8param(0xBF); Serial.println(" "); //Serial.println(" look register 0xBF 0xD3 0xDA 0xDB 0xDC 0xEF"); delay(1000);Serial.print(" .");delay(1000);Serial.print(" ."); delay(1000);Serial.print(" .");delay(1000);Serial.println(" "); Serial.println(" "); Serial.print("reg p1 p2 p3 p4 p5 p6 p7 p8 "); //Serial.println(" "); for (uint8_t i=176; i<255; i++) { // i<128 readRegPrint8param(i); } Serial.println(" "); // запись в B0h 0x04 и опрос последних Serial.print(" writing in Manufacturer Command Access Protect (B0h) <- 0x040404 "); writeRegister24(0xb0, 0x040404); //Serial.println(" "); readRegPrint8param(0xB0); Serial.println(" "); Serial.print("Device Code Read (BFh) "); readRegPrint8param(0xBF); Serial.println(" "); //Serial.println(" look register 0xBF 0xD3 0xDA 0xDB 0xDC 0xEF"); delay(1000);Serial.print(" .");delay(1000);Serial.print(" ."); delay(1000);Serial.print(" .");delay(1000);Serial.println(" "); Serial.println(" "); Serial.print("reg p1 p2 p3 p4 p5 p6 p7 p8 "); //Serial.println(" "); for (uint8_t i=176; i<255; i++) { // i<128 readRegPrint8param(i); } Serial.println(" "); //************ стандартная процедура определения известных для запуска скетча на известных ему инитах if (readReg(0x04) == 0x8000) { // eh close enough // setc! // Serial.println("! readReg(0x04) = 0x8000 "); /* for (uint8_t i=0; i<254; i++) { Serial.print("$"); Serial.print(i, HEX); Serial.print(" = 0x"); Serial.println(readReg(i), HEX); } */ writeRegister24(HX8357D_SETC, 0xFF8357); delay(300); //Serial.print("$D0 = 0x"); //Serial.println(readReg(0xD0), HEX); if (readReg(0xD0) == 0x990000) { return 0x8357; } } uint16_t id = readReg(0xD3); // испольование 16 бит , это значит что возьмутся последние 2 параметра из 4х (24бита) // иначе в сандарте бы получили ответ 02 00 93 41 if (id == 0x9341) { return id; } // чтоние с 0 адреса для других видов диспов CS_ACTIVE; CD_COMMAND; write8(0x00); WR_STROBE; // Repeat prior byte (0x00) setReadDir(); // Set up LCD data port(s) for READ operations CD_DATA; read8(hi); read8(lo); setWriteDir(); // Restore LCD data port(s) to WRITE configuration CS_IDLE; id = hi; id <<= 8; id |= lo; return id; } uint32_t Adafruit_TFTLCD::readReg(uint8_t r) { uint32_t id; uint8_t x; // try reading register #4 CS_ACTIVE; CD_COMMAND; write8(r); setReadDir(); // Set up LCD data port(s) for READ operations CD_DATA; delayMicroseconds(50); read8(x); id = x; // Do not merge or otherwise simplify id <<= 8; // these lines. It's an unfortunate read8(x); id |= x; // shenanigans that are going on. id <<= 8; // these lines. It's an unfortunate read8(x); id |= x; // shenanigans that are going on. id <<= 8; // these lines. It's an unfortunate read8(x); id |= x; // shenanigans that are going on. CS_IDLE; setWriteDir(); // Restore LCD data port(s) to WRITE configuration //Serial.print("Read $"); Serial.print(r, HEX); //Serial.print(":\t0x"); Serial.println(id, HEX); return id; } uint32_t Adafruit_TFTLCD::readRegPrint8param(uint8_t r) { uint32_t id; uint32_t id2; uint8_t x; uint8_t x1, x2, x3, x4, x5, x6, x7, x8; // try reading register #4 CS_ACTIVE; CD_COMMAND; write8(r); setReadDir(); // Set up LCD data port(s) for READ operations CD_DATA; delayMicroseconds(50); read8(x); x1=x; id = x; // Do not merge or otherwise simplify id <<= 8; // these lines. It's an unfortunate read8(x); x2=x; id |= x; // shenanigans that are going on. id <<= 8; // these lines. It's an unfortunate read8(x); x3=x; id |= x; // shenanigans that are going on. id <<= 8; // these lines. It's an unfortunate read8(x); x4=x; id |= x; // shenanigans that are going on. read8(x); x5=x; id2 = x; // Do not merge or otherwise simplify id2 <<= 8; // these lines. It's an unfortunate read8(x); x6=x; id2 |= x; // shenanigans that are going on. id2 <<= 8; // these lines. It's an unfortunate read8(x); x7=x; id2 |= x; // shenanigans that are going on. id2 <<= 8; // these lines. It's an unfortunate read8(x); x8=x; id2 |= x; // shenanigans that are going on. CS_IDLE; setWriteDir(); // Restore LCD data port(s) to WRITE configuration Serial.println(" "); if (r<0x10) Serial.print("0"); Serial.print(r,HEX); Serial.print(" = "); if (id>0 && id2>0) { if (x1<0x10) Serial.print("0"); Serial.print(x1,HEX); Serial.print(" "); if (x2<0x10) Serial.print("0"); Serial.print(x2,HEX); Serial.print(" "); if (x3<0x10) Serial.print("0"); Serial.print(x3,HEX); Serial.print(" "); if (x4<0x10) Serial.print("0"); Serial.print(x4,HEX); Serial.print(" "); if (x5<0x10) Serial.print("0"); Serial.print(x5,HEX); Serial.print(" "); if (x6<0x10) Serial.print("0"); Serial.print(x6,HEX); Serial.print(" "); if (x7<0x10) Serial.print("0"); Serial.print(x7,HEX); Serial.print(" "); if (x8<0x10) Serial.print("0"); Serial.print(x8,HEX); Serial.print(" "); if ( r==0x00 || r==0x04 || r==0xBF || r==0xD3 || r==0xDA || r==0xDB || r==0xDC || r==0xEF ) Serial.print("*****"); } else { Serial.print("0"); if ( r==0x00 || r==0x04 || r==0xBF || r==0xD3 || r==0xDA || r==0xDB || r==0xDC || r==0xEF ) Serial.print(" *"); } //Serial.print("Read $"); Serial.print(r, HEX); //Serial.print(":\t0x"); Serial.println(id, HEX); return id; } // Pass 8-bit (each) R,G,B, get back 16-bit packed color uint16_t Adafruit_TFTLCD::color565(uint8_t r, uint8_t g, uint8_t b) { return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3); } // For I/O macros that were left undefined, declare function // versions that reference the inline macros just once: #ifndef write8 void Adafruit_TFTLCD::write8(uint8_t value) { write8inline(value); } #endif #ifdef read8isFunctionalized uint8_t Adafruit_TFTLCD::read8fn(void) { uint8_t result; read8inline(result); return result; } #endif #ifndef setWriteDir void Adafruit_TFTLCD::setWriteDir(void) { setWriteDirInline(); } #endif #ifndef setReadDir void Adafruit_TFTLCD::setReadDir(void) { setReadDirInline(); } #endif #ifndef writeRegister8 void Adafruit_TFTLCD::writeRegister8(uint8_t a, uint8_t d) { writeRegister8inline(a, d); } #endif #ifndef writeRegister16 void Adafruit_TFTLCD::writeRegister16(uint16_t a, uint16_t d) { writeRegister16inline(a, d); } #endif #ifndef writeRegisterPair void Adafruit_TFTLCD::writeRegisterPair(uint8_t aH, uint8_t aL, uint16_t d) { writeRegisterPairInline(aH, aL, d); } #endif void Adafruit_TFTLCD::writeRegister24(uint8_t r, uint32_t d) { CS_ACTIVE; CD_COMMAND; write8(r); CD_DATA; delayMicroseconds(10); write8(d >> 16); delayMicroseconds(10); write8(d >> 8); delayMicroseconds(10); write8(d); CS_IDLE; } void Adafruit_TFTLCD::writeRegister32(uint8_t r, uint32_t d) { CS_ACTIVE; CD_COMMAND; write8(r); CD_DATA; delayMicroseconds(10); write8(d >> 24); delayMicroseconds(10); write8(d >> 16); delayMicroseconds(10); write8(d >> 8); delayMicroseconds(10); write8(d); CS_IDLE; }Adafruit_TFTLCD
как на 8бит переключить пока не разобрался
В ветке Слайдер писал как подсунуть нужный инит.
fps Очень навороченный шлейф. Попробую разобраться.
У тебя телефон с которого он снят есть?
Попался вот такой дисп 4" от китайца.
Поискал на просторах...ничего более-менее не нашел. Помогите с распиновкой.
Выложи хорошее фото, чтоб видно было.
Вот тут в архиве крупные
https://yadi.sk/d/n_kDgDQp3SAJ9j
Дисплей 800х480. Сейчас заточен под 24 бит. Шлейф слегка наворочен.
Придется помучаться. Ты уверен, что оно тебе надо. Плюс для ардуин библиотеки
думаю нет. Шрифт 8х8 будет очень маленьким. Для картинок памяти нужно будет немеряно.
Дисплей 800х480. Сейчас заточен под 24 бит. Шлейф слегка наворочен.
Придется помучаться. Ты уверен, что оно тебе надо. Плюс для ардуин библиотеки
думаю нет. Шрифт 8х8 будет очень маленьким. Для картинок памяти нужно будет немеряно.
Там не особо стандартный контроллер? Пока этот дисп первый у меня с нормальным паябельным шлейфом)
С двумя по SPI так толком и не разобрался, пока, один мешает второму инициализироваться...почему хз.