User avatar
idontcar3
Posts: 8
Joined: Wed Mar 09, 2016 2:54 am

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Thu Mar 10, 2016 6:51 pm

saper_2 wrote: Don't thank me before I'm done :D - I'll get lazy :P
But i really do LOVE your hack :oops:
saper_2 wrote: Well, we still hunting (or only me?) for v3 kernel patch (for source) or driver code - I'm interested in init seq.
Well i remember i downloaded a file from mega.nz called LCD_show v3 or something similar, but i can't figure out where i did get that. When i get home (aprox. 4 hours) i'll search my history and link it to you.

it has 2 bash scripts. one is for selecting the LCD display and the other one is for selecting HDMI output. they do operate on similar folder contents (some .img files, a lib folder, and i think the lcd script has a modules folder).
Anyway i'll link it here ASAP by editing this post :)

User avatar
saper_2
Posts: 239
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Thu Mar 10, 2016 7:18 pm

idontcar3 wrote:it has 2 bash scripts. one is for selecting the LCD display and the other one is for selecting HDMI output. they do operate on similar folder contents (some .img files, a lib folder, and i think the lcd script has a modules folder).
Anyway i'll link it here ASAP by editing this post :)
Niope, that's not what I looking for, I looking for file (probably) named: ili9341.c and/or text file with extension "patch" or "diff" for v3 lcd... I'm not interested in shell script for toggling between hdmi and lcd...

User avatar
idontcar3
Posts: 8
Joined: Wed Mar 09, 2016 2:54 am

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Fri Mar 11, 2016 2:50 am

saper_2 wrote:Niope, that's not what I looking for...
anyways here is the file link. (i'm sorry i totally forgot, was so tired from job)

Code: Select all

https://mega.nz/#!hhdCTCDZ!UXyyh17uZo3p0O95mNmkGrWjmCv7NUEaofx9-zqoGj0
which came from this page

Code: Select all

http://geekswithblogs.net/MobileLOB/archive/2016/01/28/8-of-lcd-screen-for-raspberry-pi-w.aspx
turns out it is posted in this forum.
its a bunch of fw, bin, ko, dfu files. Maybe it can help you out.

:roll: i have a strange DejaVu feeling, i think that i'm (or we are) close to something big, or at least in the right path for something, idk.

User avatar
saper_2
Posts: 239
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Sat Mar 12, 2016 9:34 pm

idontcar3 wrote:its a bunch of fw, bin, ko, dfu files. Maybe it can help you out.

:roll: i have a strange DejaVu feeling, i think that i'm (or we are) close to something big, or at least in the right path for something, idk.
I look through all files that shown up so far in this topic, I 've got source code only for v1.1 and v2 . For v3 - no luck so far (and I don't feel spending 12-15$ for next lcd without being sure that it will be v3)...

I'm going to built a fbtft spi adapter (I have designed one circuit using one-side pcb, and I have already prepared pcb for etching (one of 9 others PCBs :lol: )) so I might before Easter public some update/results about my hack.

I also started recently thinking about creating module for fbtft with driver for those lcds... But I have no expirence at all when it comes to writing kernel (fbtft) modules. If I feel like analyzing some fbtft drivers and I will decide to bother notro for some help then I might try write something - and I have now Pi3 which have a way more power that Pi2 so compiling code will be faster too :)

w.mo
Posts: 4
Joined: Wed Feb 10, 2016 4:40 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Sat Mar 12, 2016 11:42 pm

@saper_2
How do you analyze the transmission with the GPIO pins? Do you just use a code to read the bytes and print them on the display? I ordered this http://www.ebay.de/itm/161917725126 a week ago for logic analyzing. I actually thought that the gpio pins wouldn't be reliable enough. But then - if they are used to communicate with the display why wouldn't they be!? Well 6 euros wasted it looks like.

EDIT: well I can use so I wont' use up the gpio pins for analyzing so its not entirely wasted.

User avatar
saper_2
Posts: 239
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Sun Mar 13, 2016 12:59 pm

Hi,

I didn't analyze waveforms :D , I analyzed driver code (source) for v1 and v2 displays :)
Using driver source code, I've written simple python scripts to test/control lcd.
There is no point in digging into init sequence because as I mentioned, the ILI-drivers have some undocumented commands that are used for configuration too, so it's hard to exactly tell what ILI-controller have each display , also the interface is only unidirectional (to lcd only) so I can't read what LCD controller is really (all ILIxxxx tft controllers have at register 0x01 controller ID written - so just read this register and you know what controller is exactly in your display).

About the usb logic analyzer: If you manage to capture a 12MHz then you are lucky :D , I have this one http://www.seeedstudio.com/depot/Open-W ... p-612.html - and it can really capture signals running 50-70MHz - but I didn't have to use it with those displays.

w.mo
Posts: 4
Joined: Wed Feb 10, 2016 4:40 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Sun Mar 13, 2016 9:55 pm

Okay. I'll see if i find a use for that thing. Thanks for the tip :)

Leosleo
Posts: 10
Joined: Sun Mar 06, 2016 3:20 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Fri Mar 18, 2016 7:48 pm

Guys, I'm in the same situation!

First of all, I'm a complete noob and a newbie in Rasp world!
I bought the KeDei TFT 14$ from eBay, it's 4.0 version. I have a Raspberry Pi A+ on which i would make working the KeDei display.
I downloaded the 4.0 Raspbian img with display driver from the link of KeDei.
Because my SD card is only 2GB, I had to write the image on USB drive and then I copied the files (about 59mb) on SD Card and edited cmdline.text changing "root=/dev/mmcblk0p2" to "root=/dev/sda2".
I inserted the SD in the Raspberry, powered it, and the screen stopped at "random: non blocking pool is initialized".

What was wrong? Was the procedure from USB to SD wrong? Or is my Raspberry A+ the wrong version? Someone has this TFT display working?

What should I do to make this Display working on my Raspberry A+?
Sorry for my questions, thanks in advance to everyone could help me!

User avatar
saper_2
Posts: 239
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Fri Mar 18, 2016 8:24 pm

Leosleo wrote:Guys, I'm in the same situation!
Niop, your are not. In this topic you will find all information needed for: writing your own driver, lcd hardware design & schematics (v1.1, v2), hacking lcd, reworking lcd interface for fbtft compatible (still in progress :ugeek: ), other images for other versions. Of course, if you can provide some information for your lcd version (hi-res photo of pcb,sys image files, but most wanted is source code (or patch files) of driver for lcd v3 and v4 - you just confirmed it :) - thx, and/or lcd init sequence ).
Leosleo wrote:I inserted the SD in the Raspberry, powered it, and the screen stopped at "random: non blocking pool is initialized".
This is not topic for you, the problem is with image (wrongly downloaded) or your RPi is malfunctioning (very rare, but I found on some topic that replacing Pi solved problem) - I found this by asking uncle google - first 2 or 3 results... Re-download image, burn in onto bigger card. Find on google how to move RPi os from sd card to pendrive/usb-sata hdd - there is many tutorials. Use google, this error is pretty well discussed in few topics.

Leosleo
Posts: 10
Joined: Sun Mar 06, 2016 3:20 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Sat Mar 19, 2016 1:20 pm

saper_2 wrote:
Leosleo wrote:Guys, I'm in the same situation!
Niop, your are not. In this topic you will find all information needed for: writing your own driver, lcd hardware design & schematics (v1.1, v2), hacking lcd, reworking lcd interface for fbtft compatible (still in progress :ugeek: ), other images for other versions. Of course, if you can provide some information for your lcd version (hi-res photo of pcb,sys image files, but most wanted is source code (or patch files) of driver for lcd v3 and v4 - you just confirmed it :) - thx, and/or lcd init sequence ).
Leosleo wrote:I inserted the SD in the Raspberry, powered it, and the screen stopped at "random: non blocking pool is initialized".
This is not topic for you, the problem is with image (wrongly downloaded) or your RPi is malfunctioning (very rare, but I found on some topic that replacing Pi solved problem) - I found this by asking uncle google - first 2 or 3 results... Re-download image, burn in onto bigger card. Find on google how to move RPi os from sd card to pendrive/usb-sata hdd - there is many tutorials. Use google, this error is pretty well discussed in few topics.
Saper, thanks for your answer!
I'm sorry, but I'm completely a noob and this is the reason for my confusing, but i have good news.
I bought a big sdhc and installed img. Everything works and I have my Rasp with my LCD working.
So, I noticed this LCD has 0.5 fps, so it's impossible to play with games. Is there a solution? Are you talking about this in this post? And what I should i do if i want install RetroPie?

Thanks always and sorry for my noob questions!

User avatar
saper_2
Posts: 239
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Sat Mar 19, 2016 4:09 pm

Leosleo wrote:Saper, thanks for your answer!
Post hi-res photo of your lcd (pcb side) and what part numbers on chips are, and try to get form seller "source code" or "driver source code" - then your thanks will be accepted. Or I'll stop helping.
Leosleo wrote: I'm sorry, but I'm completely a noob and this is the reason for my confusing, but i have good news.
I bought a big sdhc and installed img. Everything works and I have my Rasp with my LCD working.
Like I thought.
Leosleo wrote: So, I noticed this LCD has 0.5 fps, so it's impossible to play with games. Is there a solution? Are you talking about this in this post? And what I should i do if i want install RetroPie?
Google " retropie lcd 3,5" " , but on this screen you won't get any decent fps (that's mean more than 2fps :D) . Waveshare compatible displays or those that can runs being driven by fbtft can give decent fps (20-25fps), and with hdmi input too (I think I saw recently 5" lcd with hdmi input & spi touch for around 24USD on aliexpress).

I'm doing "total hardware hack" or "re-interface KeDei lcd to fbtft driver" - but this will take some more time :) - summary: I replace this junk kedei serial interface for one that is supported by fbtft driver.

User avatar
idontcar3
Posts: 8
Joined: Wed Mar 09, 2016 2:54 am

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Sun Mar 20, 2016 4:05 am

Did anyone tried to contact the seller?

http://es.aliexpress.com/store/contactinfo/1823449.html

i could do it, but i have no idea on how to do it. maybe that link can help (i hope)

@saper_2 could you point me in what to ask?

User avatar
saper_2
Posts: 239
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Sun Mar 20, 2016 11:17 am

idontcar3 wrote:Did anyone tried to contact the seller?

http://es.aliexpress.com/store/contactinfo/1823449.html

i could do it, but i have no idea on how to do it. maybe that link can help (i hope)

@saper_2 could you point me in what to ask?
Damm it, your link changed my my aliexpress page language... fixed, back to English, uffff.... :)

He might not answer, because he doesn't sell anything. Write that you bought a display, what is written on display, that seller couldn't help you because didn't understand what you want, he is your last hope :) , ask for "source code of driver" for your version or at least for "initialization sequence" . Reason? I would write that, I need init because I need to control lcd from user mode application (python program), not from system kernel (kernel driver).

I don't remember if I found him on ali, but I tried to contact KeDei by taobao...

99% of Chinese sellers on aliexpress, don't understand any a little more complex English - chinese-english google translate , they get some "keyword", and if you're lucky you will get what you want, or seller play dumb or ignore you... if you bought from her/him and didn't post your feedback then he/she try to help you as can :) - most seller care about high rated feedback :) .

Leosleo
Posts: 10
Joined: Sun Mar 06, 2016 3:20 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Mon Mar 21, 2016 1:03 pm

saper_2 wrote:
Leosleo wrote:Saper, thanks for your answer!
Post hi-res photo of your lcd (pcb side) and what part numbers on chips are, and try to get form seller "source code" or "driver source code" - then your thanks will be accepted. Or I'll stop helping.
Leosleo wrote: I'm sorry, but I'm completely a noob and this is the reason for my confusing, but i have good news.
I bought a big sdhc and installed img. Everything works and I have my Rasp with my LCD working.
Like I thought.
Leosleo wrote: So, I noticed this LCD has 0.5 fps, so it's impossible to play with games. Is there a solution? Are you talking about this in this post? And what I should i do if i want install RetroPie?
Google " retropie lcd 3,5" " , but on this screen you won't get any decent fps (that's mean more than 2fps :D) . Waveshare compatible displays or those that can runs being driven by fbtft can give decent fps (20-25fps), and with hdmi input too (I think I saw recently 5" lcd with hdmi input & spi touch for around 24USD on aliexpress).

I'm doing "total hardware hack" or "re-interface KeDei lcd to fbtft driver" - but this will take some more time :) - summary: I replace this junk kedei serial interface for one that is supported by fbtft driver.
Thanks Saper, so i have to buy another TFT. I have seen some Waveshare 3.5 but I have read these display have problem with retropie, over that I have spent enough yet. Do you suggest to go with Waveshare?
However I attached a screenshot of my display and this is the link of the driver on Kedei site http://kedei.net/raspberry/raspberry.html

Thanks always!
IMG_20160321_134942.jpg
PCB side Display
IMG_20160321_134942.jpg (49.28 KiB) Viewed 6676 times

User avatar
saper_2
Posts: 239
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Mon Mar 21, 2016 3:27 pm

Thanks for photo, looks like "classic kedei interface" :) - write what chip numbers do you have - those 3 in line (I believe: 3x 74HC595D - can you confirm this?).

And the links - good, should be useful to others. But the down speed....

----- UPDATE -----

As suspected, those files "driver" are only compiled kernel. Not worth of my time to even download - I checked v5 "driver".

And, yes I suggest to go for some lcd that is supported by fbtft, e.g. Waveshare - I saw recently clones on aliexpress for around 12USD.
And I just stumbled on 4" LCD for $8 with registered shipping! And it's compatibile with fbtft :D - awesome discovery :D - those screens are 320x480 like those 3,5 kedei, but have fbtft spi interface - that's mean they can work with stock RPi (no need for custom kernel nor custom images), just setup fbtft - description I found there http://tinyurl.com/pi4inLCD

Leosleo
Posts: 10
Joined: Sun Mar 06, 2016 3:20 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Tue Mar 22, 2016 1:29 pm

saper_2 wrote:Thanks for photo, looks like "classic kedei interface" :) - write what chip numbers do you have - those 3 in line (I believe: 3x 74HC595D - can you confirm this?).

And the links - good, should be useful to others. But the down speed....

----- UPDATE -----

As suspected, those files "driver" are only compiled kernel. Not worth of my time to even download - I checked v5 "driver".

And, yes I suggest to go for some lcd that is supported by fbtft, e.g. Waveshare - I saw recently clones on aliexpress for around 12USD.
And I just stumbled on 4" LCD for $8 with registered shipping! And it's compatibile with fbtft :D - awesome discovery :D - those screens are 320x480 like those 3,5 kedei, but have fbtft spi interface - that's mean they can work with stock RPi (no need for custom kernel nor custom images), just setup fbtft - description I found there http://tinyurl.com/pi4inLCD
I have seen that screen but both the Waveshare and the 4" one you suggested me, are not good for playing game because of the frame rate ( I read comments of the link you gave me).
I think I have to go for an expensive PiTft of Adafruit :(

User avatar
saper_2
Posts: 239
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Tue Mar 22, 2016 8:30 pm

Leosleo wrote:
! CUT QUOTES !

I have seen that screen but both the Waveshare and the 4" one you suggested me, are not good for playing game because of the frame rate ( I read comments of the link you gave me).
I think I have to go for an expensive PiTft of Adafruit :(
Both lcds use SPI, so I don't know if the adafruit could run faster, but the adafruit provides it's own kernel so they might do some fine-tuning or rewritten "display output part" (framebuffer?).... Well, it's up to you what you pick. I have averse to closed-source things :) - I would pick that 4" lcd because I can see source-code and I don't need it to play games, so I would be fine having minimum 2fps, and both working screens: on hdmi and on spi....

chacwacker
Posts: 1
Joined: Tue Apr 05, 2016 7:15 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Tue Apr 05, 2016 7:21 pm

Does anyone have a link to this file rpi_35_v5_jessie8_kernel_4_1_19 for the pi 3 version 5 lcd, tried from the kedei site but is way to slow to download and will not finish.

aaron00792
Posts: 3
Joined: Tue Apr 05, 2016 9:56 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Tue Apr 05, 2016 9:59 pm

Hey i just bought one of these and got the version 2.0
im wanting to use it for retropie
any ideas how to get it to work

Conjur
Posts: 17
Joined: Wed Apr 06, 2016 8:55 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Wed Apr 06, 2016 9:24 pm

I have done a bit of optimization on the c code from the OP, to make a CLI interface for the v1.1 display. It also requires the bcm library from http://www.airspayce.com/mikem/bcm2835/ and must be ran as root.
the CLI can:
initialize the display (obviously)
send a test pattern to the display
send an RGB format image to the display at specified coordinates (use ImageMagick to convert files to the appropriate input format)
fill the display with a single color
fill a specified rectangle with a single color
close/free the SPI interface
send raw commands to the display
send raw data to the display

the CLI does not register the device as a frame buffer, so it does not interfere with other frame buffers. Personally, I use it as a "remote control" for my retropie setup, to swap between retropie/kodi, kill crashed emulators, sync xbox controllers, reboot the system, and display cpu/gpu temperature.

my xbox 360 rf module and touch interfaces are still a mess; have random python scripts scattered everywhere, called from init and whatnot; but this runs completely separate.

a good portion of the code came from https://github.com/saper-2/rpi-spi-lcd3 ... test_bcm.c

you may need to change bcm2835_spi_setClockDivider(10); depending on your configuration. that accepts any even number; but fosc/10 works well for a RPI 3b, with a core speed of 250MHz. Higher number = longer delays. If you push the display any faster than about 28MHz, it does not work.

Keep in mind that there is no error checking on input; but worse case is you have to re-init the LCD.

Interesting raw commands: (./LCDctrl - nn)
33: Display Inversion ON
32: Display Inversion OFF
41: Display ON
40: Display OFF
16: Sleep
17: Partial Sleep
19: ON

Have not found a proper way to disable the backlight.

Compile with:

Code: Select all

gcc -std=gnu11 -D_POSIX_C_SOURCE=200809L -o LCDctrl LCDctrl.c -lbcm2835
LCDctrl.c:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <bcm2835.h>

uint8_t dbe[3] = {0,0,0x15};
uint8_t daf[3] = {0,0,0x1F};
uint8_t cbe[3] = {0,0,0x11};
uint8_t caf[3] = {0,0,0x1B};

int delayus(int us) { // delay us
        struct timespec tim, timr;
        tim.tv_sec = 0;
        tim.tv_nsec = (long)(us * 1000L);
        return nanosleep(&tim, &timr);
}

int delayms(int ms) { // delay ms
        struct timespec tim, timr;
        tim.tv_sec = 0;
        tim.tv_nsec = (long)(ms * 1000000L);
        return nanosleep(&tim, &timr);
}

int delays(int s) { //delay s
        struct timespec tim, timr;
        tim.tv_sec = s;
        tim.tv_nsec = 0;
        return nanosleep(&tim, &timr);
}


int spi_open(void) { //open spi interface
  if (!bcm2835_init()) return -1;
  bcm2835_spi_begin();
  bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // MSB bit goes first
  bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // mode 0
  bcm2835_spi_setClockDivider(10); // SPI_CLK 31.25MHz - MAX
  bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // CS0 - active Low
  bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS1, LOW); // CS1 - active Low
  return 0;
}

int spi_close(void) { // close spi interface
  bcm2835_spi_end();
  if (!bcm2835_close()) { return -1; }
  return 0;
}

int spi_transmit(int devsel, uint8_t *data, int len) {
  if (devsel == 0) { bcm2835_spi_chipSelect(BCM2835_SPI_CS0); } else { bcm2835_spi_chipSelect(BCM2835_SPI_CS1); }
  bcm2835_spi_writenb((char*)data, len);
  return 0;
}


#define LCD_CS 1
#define TOUCH_CS 0

#define LCD_WIDTH 480
#define LCD_HEIGHT 320

void lcd_reset(void) { // HW reset LCD
  uint8_t b[6];
  memset(&b,0,sizeof(b));
  b[5]=0x01;
  spi_transmit(LCD_CS, &b[0], 3);
  delayus(50);
  spi_transmit(LCD_CS, &b[3], 3);
  delayus(50);
}

void lcd_data(uint16_t data) { // send screen pixel
  daf[0] = data>>8;
  daf[1] = data&0xFF;
  spi_transmit(LCD_CS, &dbe[0], 3);
  spi_transmit(LCD_CS, &daf[0], 3);
}
void lcd_cdata(uint16_t data) { // send command data
  lcd_data(data>>8);
  lcd_data(data&0xFF);
}

void lcd_cmd(uint16_t cmd) { // send command
  caf[0]=cmd>>8;
  caf[1]=cmd&0xFF;
  spi_transmit(LCD_CS, &cbe[0], 3);
  spi_transmit(LCD_CS, &caf[0], 3);
}

void lcd_setarea2(uint16_t sx, uint16_t sy, uint16_t x, uint16_t y) { // set area to exact location
  lcd_cmd(0x002A); // Column Address Set (2Ah)
  lcd_cdata(sx);
  lcd_cdata(x);
  lcd_cmd(0x002B); // Page Address Set (2Bh)
  lcd_cdata(sy);
  lcd_cdata(y);
  lcd_cmd(0x002C); // Memory Write (2Ch)
}
void lcd_setarea3(uint16_t x, uint16_t y, uint16_t w, uint16_t h) { // set area to exact x,y; relative ending x/y
  lcd_setarea2(x,y,x+(w-1),y+(h-1));
}
void lcd_setarea4(uint16_t w, uint16_t h) { // set area to center
  lcd_setarea3(((LCD_WIDTH/2)-1)-(w/2),((LCD_HEIGHT/2)-1)-(h/2),w,h);
}
void lcd_setarea(uint16_t x, uint16_t y) { // set area to x,y, and rest of screen (useless)
  lcd_setarea2(x,y,LCD_WIDTH-1,LCD_HEIGHT-1);
}

void lcd_setptr() { // set area to entire screen
  lcd_setarea2(0,0,LCD_WIDTH-1,LCD_HEIGHT-1);
}

void lcd_init(void) {
  lcd_cmd(0x0000); // NOP
  delayms(1);
  lcd_cmd(0x00B0);
    lcd_data(0x0000);
  lcd_cmd(0x0011);
  delayms(50);
  lcd_cmd(0x00B3);
    lcd_cdata(0x0200); lcd_cdata(0x0000);
  lcd_cmd(0x00C0);
    lcd_cdata(0x103B); lcd_cdata(0x0002); lcd_cdata(0x0001); lcd_cdata(0x0043); //13, 480, NW
  lcd_cmd(0x00C1);
    lcd_cdata(0x0816); lcd_cdata(0x0808); //2, 22 (clock?), 8, 8
  lcd_cmd(0x00C4);
    lcd_cdata(0x1107); lcd_cdata(0x0303);
  lcd_cmd(0x00C6);
    lcd_data(0x0000);
  lcd_cmd(0x00C8); // GAMMA
    lcd_cdata(0x0303); lcd_cdata(0x135C); lcd_cdata(0x0307); lcd_cdata(0x1408); lcd_cdata(0x0021); lcd_cdata(0x0814); lcd_cdata(0x0753); lcd_cdata(0x0C13); lcd_cdata(0x0303); lcd_cdata(0x2100);
  lcd_cmd(0x0035);
    lcd_data(0x0000);
  lcd_cmd(0x0036);
    lcd_data(0x0028);
  lcd_cmd(0x003A);
    lcd_data(0x0055); //55 lgh
  lcd_cmd(0x0044);
    lcd_cdata(0x0001);
  lcd_cmd(0x00B6);
    lcd_cdata(0x0002); lcd_data(0x003B); //220 GS SS SM ISC[3:0]
  lcd_cmd(0x00D0);
    lcd_cdata(0x0707); lcd_data(0x001D); //VCI1, VRH
  lcd_cmd(0x00D1);
    lcd_cdata(0x0003); lcd_data(0x0000); //VCM, VDV
  lcd_cmd(0x00D2);
    lcd_cdata(0x0314); lcd_data(0x0004);

        lcd_cmd(0xE0);
        lcd_data(0x1f);
        lcd_data(0x2C);
        lcd_data(0x2C);
        lcd_data(0x0B);
        lcd_data(0x0C);
        lcd_data(0x04);
        lcd_data(0x4C);
        lcd_data(0x64);
        lcd_data(0x36);
        lcd_data(0x03);
        lcd_data(0x0E);
        lcd_data(0x01);
        lcd_data(0x10);
        lcd_data(0x01);
        lcd_data(0x00);

        lcd_cmd(0XE1);
        lcd_data(0x1f);
        lcd_data(0x3f);
        lcd_data(0x3f);
        lcd_data(0x0f);
        lcd_data(0x1f);
        lcd_data(0x0f);
        lcd_data(0x7f);
        lcd_data(0x32);
        lcd_data(0x36);
        lcd_data(0x04);
        lcd_data(0x0B);
        lcd_data(0x00);
        lcd_data(0x19);
        lcd_data(0x14);
        lcd_data(0x0F);

  lcd_cmd(0xE2);
    lcd_cdata(0x0F0F);
    lcd_data(0x0F);
  lcd_cmd(0xE3);
    lcd_cdata(0x0F0F);
    lcd_data(0x0F);
  lcd_cmd(0x13);
  lcd_cmd(0x0029);
  delayms(20); //mdelay(20);
  lcd_cmd(0x00B4);
    lcd_data(0x0000);
  delayms(1); //mdelay(20);
  lcd_cmd(0x002C);
}


void lcd_fill(uint16_t color565) {
  lcd_setptr();
  for(int x=0; x<(LCD_HEIGHT*LCD_WIDTH);x++) {
    lcd_data(color565);
  }
}
void lcd_fill2(uint16_t color565, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
  lcd_setarea3(x,y,w,h);
  for(int t=0;t<(h*w);t++) {
    lcd_data(color565);
  }
}


void lcd_icon(char *fname, uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
  FILE *fp = NULL;
  unsigned int rgb[3];
  unsigned int rgb565;
  lcd_setarea3(x,y,w,h);
  memset(rgb,0,sizeof(rgb));
  fp=fopen(fname,"r");
  while (fread(rgb, 3, 1, fp)) {
    rgb565 = ((((rgb[0])&0xFF)>>3)<<11) + ((((rgb[0]>>8 )&0xFF)>>2)<<5) + (((rgb[0]>>16)&0xFF)>>3);
    lcd_data(0xFFFF&rgb565);
  }
  fclose(fp);
}

void lcd_pattern(void) {
  int r,g,b,w,x;
  lcd_setptr();
  for(r=0;r<LCD_HEIGHT;r++){
    for(g=0;g<60;g++) { lcd_data(0xFFFF); }
    for(g=0;g<60;g++) { lcd_data(0xFFE0); }
    for(g=0;g<60;g++) { lcd_data(0x07FF); }
    for(g=0;g<60;g++) { lcd_data(0x07E0); }
    for(g=0;g<60;g++) { lcd_data(0xF81F); }
    for(g=0;g<60;g++) { lcd_data(0xF800); }
    for(g=0;g<60;g++) { lcd_data(0x0031); }
    for(g=0;g<60;g++) { lcd_data(0x0000); }
  }
}

int main(int argc, char *argv[]) {
  int opt;
  if(argc<2) {opt='h';}else{opt=(int)argv[1][0];}
  switch(opt) {
    case 'i':
      if (spi_open()) { return 1; }
      lcd_reset();
      lcd_init();
      if (!bcm2835_close()) { return -1; }
      printf("Init Complete.\n");
      break;
    case 'p':
      if (!bcm2835_init()) return -1;
      lcd_pattern();
      if (!bcm2835_close()) { return -1; }
      printf("Test Pattern Sent!\n");
      break;
    case 'g':
      if (!bcm2835_init()) return -1;
      lcd_icon((char*)argv[2],atoi(argv[3]),atoi(argv[4]),atoi(argv[5]),atoi(argv[6]));
      if (!bcm2835_close()) { return -1; }
      break;
    case 'f':
      if (!bcm2835_init()) return -1;
      lcd_fill(atoi(argv[2]));
      if (!bcm2835_close()) { return -1; }
      break;
    case 'a':
      if (!bcm2835_init()) return -1;
      lcd_fill2(atoi(argv[2]),atoi(argv[3]),atoi(argv[4]),atoi(argv[5]),atoi(argv[6]));
      if (!bcm2835_close()) { return -1; }
      break;
    case 'c':
      if (!bcm2835_init()) return -1;
      spi_close();
      if (!bcm2835_close()) { return -1; }
      break;
    case '-':
      if (!bcm2835_init()) return -1;
      lcd_cmd(atoi(argv[2]));
      if (!bcm2835_close()) { return -1; }
      break;
    case '.':
      if (!bcm2835_init()) return -1;
      lcd_data(atoi(argv[2]));
      if (!bcm2835_close()) { return -1; }
      break;
    default:
      printf("Keidei v1.1 LCD CLI driver v0.01a\n  Usage: %s <cmd> [args]\n",argv[0]);
      printf("    i: perform SPI and display initialization\n");
      printf("    p: send test pattern to display\n");
      printf("    g <filename> <x> <y> <w> <h>: display .rgb file\n");
      printf("      %s g ./img480x300.rgb 0 10 480 300 (draws red border along top)\n",argv[0]);
      printf("      use ImageMagick to convert files to this format: convert icon.png -depth 8 icon.rgb\n");
      printf("    f <color>: fill entire display with color\n");
      printf("      %s f 65535 (Fills Screen with White)\n",argv[0]);
      printf("    a <color> <x> <y> <w> <h>: fill area with color\n");
      printf("      %s a 63488 0 0 480 10 (draws red border along top)\n",argv[0]);
      printf("    c: close SPI\n\n");
      printf("    - <int>: sends raw command to display\n\n");
      printf("    . <int>: sends raw data to display\n");
      break;
  }
  return 0;
}
V/r,
Mike

pborman
Posts: 1
Joined: Thu Apr 07, 2016 4:40 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Thu Apr 07, 2016 5:00 pm

@chacwacker
The full download is unnecessary, just download the LCD_Show_V5 file which is much smaller, and apply it to a stock image from raspberrypi.org. Downloads link for the stock image on the top of this page.

The keidei img seems to be an older version of raspbian, but the LCD_Show_V5 file works with the current version, and also works with the ubuntu mate image, which I'm using here. Ubuntu mate seems smoother and faster than the lxde desktop on raspbian.

aaron00792
Posts: 3
Joined: Tue Apr 05, 2016 9:56 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Mon Apr 11, 2016 6:10 am

So has anyone been able to get this to work on retro pi or retroarch

masterjon
Posts: 4
Joined: Thu Feb 18, 2016 3:45 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Wed Apr 20, 2016 4:33 pm

Does anyone know how to permanently change the size of the screen because the windows are way out of proportion.

GAMELASTER
Posts: 38
Joined: Sat Feb 14, 2015 8:05 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Wed Apr 20, 2016 6:38 pm

Hello, I have KeDei v5.0 (the 2016 version) and I want to run the RetroPie, but its not working.

And another question, is possible to increase the frequency of the display?

Thanks

Conjur
Posts: 17
Joined: Wed Apr 06, 2016 8:55 pm

Re: KeDei 3.5 inch 480x320 TFT lcd from ali

Thu Apr 21, 2016 1:30 am

GAMELASTER wrote:Hello, I have KeDei v5.0 (the 2016 version) and I want to run the RetroPie, but its not working.

And another question, is possible to increase the frequency of the display?

Thanks
GAMERLASTER,
I have 2 of the same displays (Kedei v5.0); and writing a SPI Logic Analyzer for one of my FT232 chips is on my todo list, to get these displays working. The v5.0 does not seem to be an ili chipset; and none of the "known" init sequences work with it. When I have a break from work, I will get a CLI working for it.. it will be up to the others to incorporate it into fbtft so it works as an actual display, though.

If you download their raspbian image (likely with spyware) it works; but the refresh rate is terrible. With the v1.1 I was able to make a usable CLI to feed it images; and even wrote a well-structured buffer; so it only updated the areas that were needed... However,

EDIT: Also, emulationstation somehow outputs to the HDMI adapter, bypassing the KeDei proprietary spyware drivers. I have not gotten around to figuring out how to fix this.

V/r,
Mike

Return to “Interfacing (DSI, CSI, I2C, etc.)”