Skip to content

Commit

Permalink
Backup code, first working version to get KeDei Raspberry Pi 3.5 inch…
Browse files Browse the repository at this point in the history
… SPI TFTLCD 480*320 16bit/18bit version 6.3 2018/4/9 display on screen. #40
  • Loading branch information
juj committed Nov 25, 2018
1 parent edcdad7 commit 4c92290
Show file tree
Hide file tree
Showing 6 changed files with 820 additions and 625 deletions.
2 changes: 1 addition & 1 deletion config.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
// DISPLAY_FLIP_ORIENTATION_IN_SOFTWARE enabled: traditional no-vsync tearing (tear line runs in portrait // DISPLAY_FLIP_ORIENTATION_IN_SOFTWARE enabled: traditional no-vsync tearing (tear line runs in portrait
// i.e. narrow direction) // i.e. narrow direction)
#if !defined(SINGLE_CORE_BOARD) #if !defined(SINGLE_CORE_BOARD)
#define DISPLAY_FLIP_ORIENTATION_IN_SOFTWARE //#define DISPLAY_FLIP_ORIENTATION_IN_SOFTWARE
#endif #endif


// If enabled, build to utilize DMA transfers to communicate with the SPI peripheral. Otherwise polling // If enabled, build to utilize DMA transfers to communicate with the SPI peripheral. Otherwise polling
Expand Down
2 changes: 1 addition & 1 deletion display.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
#define DISPLAY_DRAWABLE_HEIGHT (DISPLAY_HEIGHT-DISPLAY_COVERED_TOP_SIDE-DISPLAY_COVERED_BOTTOM_SIDE) #define DISPLAY_DRAWABLE_HEIGHT (DISPLAY_HEIGHT-DISPLAY_COVERED_TOP_SIDE-DISPLAY_COVERED_BOTTOM_SIDE)


#ifndef DISPLAY_SPI_DRIVE_SETTINGS #ifndef DISPLAY_SPI_DRIVE_SETTINGS
#define DISPLAY_SPI_DRIVE_SETTINGS (0) #define DISPLAY_SPI_DRIVE_SETTINGS (1 | BCM2835_SPI0_CS_CPOL | BCM2835_SPI0_CS_CPHA)
#endif #endif


#ifdef DISPLAY_COLOR_FORMAT_R6X2G6X2B6X2 #ifdef DISPLAY_COLOR_FORMAT_R6X2G6X2B6X2
Expand Down
130 changes: 129 additions & 1 deletion ili9486.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
#include <memory.h> #include <memory.h>
#include <stdio.h> #include <stdio.h>


void ChipSelectHigh()
{
WAIT_SPI_FINISHED();
CLEAR_GPIO(GPIO_SPI0_CE0);
// for(int i = 0; i < 10; ++i) __sync_synchronize();
SET_GPIO(GPIO_SPI0_CE0);
SET_GPIO(GPIO_SPI0_CE1); // Disable Display
// for(int i = 0; i < 10; ++i) __sync_synchronize();
CLEAR_GPIO(GPIO_SPI0_CE1); // Enable Display
}

void InitILI9486() void InitILI9486()
{ {
// If a Reset pin is defined, toggle it briefly high->low->high to enable the device. Some devices do not have a reset pin, in which case compile with GPIO_TFT_RESET_PIN left undefined. // If a Reset pin is defined, toggle it briefly high->low->high to enable the device. Some devices do not have a reset pin, in which case compile with GPIO_TFT_RESET_PIN left undefined.
Expand All @@ -21,12 +32,129 @@ void InitILI9486()
usleep(120 * 1000); usleep(120 * 1000);
#endif #endif


// For sanity, start with both Chip selects high to ensure that the display will see a high->low enable transition when we start.
SET_GPIO(GPIO_SPI0_CE0); // Disable Touch
SET_GPIO(GPIO_SPI0_CE1); // Disable Display
usleep(1000);

// Do the initialization with a very low SPI bus speed, so that it will succeed even if the bus speed chosen by the user is too high. // Do the initialization with a very low SPI bus speed, so that it will succeed even if the bus speed chosen by the user is too high.
spi->clk = 34; spi->clk = 34;
__sync_synchronize(); __sync_synchronize();


BEGIN_SPI_COMMUNICATION(); BEGIN_SPI_COMMUNICATION();
{ {
/*
CLEAR_GPIO(GPIO_SPI0_CE0); // Enable Touch
SET_GPIO(GPIO_SPI0_CE1); // Disable Display
// Original driver sends the command 0xE7 42 times with odd timings and Chip Select combinations, does not seem to be necessary.
for(int i = 0; i < 21; ++i)
{
WAIT_SPI_FINISHED();
SET_GPIO(GPIO_SPI0_CE0); // Enable Touch
CLEAR_GPIO(GPIO_SPI0_CE0); // Enable Touch
SPI_TRANSFER(0x0000E700);
}
usleep(50*1000);
for(int i = 0; i < 21; ++i)
{
WAIT_SPI_FINISHED();
SET_GPIO(GPIO_SPI0_CE0); // Enable Touch
CLEAR_GPIO(GPIO_SPI0_CE0); // Enable Touch
SPI_TRANSFER(0x0000E700);
}
SPI_TRANSFER(0x00008000);
END_SPI_COMMUNICATION();
BEGIN_SPI_COMMUNICATION();
usleep(10*1000);
*/
CLEAR_GPIO(GPIO_SPI0_CE0); // Enable Touch
CLEAR_GPIO(GPIO_SPI0_CE1); // Enable Display

BEGIN_SPI_COMMUNICATION();

// SPI_TRANSFER_TO_PREV_CS(0x00000100);
/////////////////////// SPI_TRANSFER(0x00000100);

// END_SPI_COMMUNICATION();
// BEGIN_SPI_COMMUNICATION();

usleep(25*1000);

SET_GPIO(GPIO_SPI0_CE0); // Disable Touch
/*
SET_GPIO(GPIO_SPI0_CE0); // Disable Touch
CLEAR_GPIO(GPIO_SPI0_CE1); // Enable Display
END_SPI_COMMUNICATION();
BEGIN_SPI_COMMUNICATION();
SET_GPIO(GPIO_SPI0_CE1); // Enable Display
usleep(30);
CLEAR_GPIO(GPIO_SPI0_CE1); // Enable Display
*/
usleep(25*1000);

// SPI_TRANSFER_TO_PREV_CS(0x00000000);
SPI_TRANSFER(0x00000000); // This command seems to be Reset
usleep(120*1000);
/*
SET_GPIO(GPIO_SPI0_CE1); // Enable Display
usleep(30);
CLEAR_GPIO(GPIO_SPI0_CE1); // Enable Display
*/

// SPI_TRANSFER_TO_PREV_CS(0x00000100);
SPI_TRANSFER(0x00000100);
usleep(50*1000);
// SPI_TRANSFER_TO_PREV_CS(0x00001100);
SPI_TRANSFER(0x00001100);
usleep(60*1000);
/*
SET_GPIO(GPIO_SPI0_CE1); // Disable Display
usleep(30);
CLEAR_GPIO(GPIO_SPI0_CE1); // Enable Display
*/
// END_SPI_COMMUNICATION();
// BEGIN_SPI_COMMUNICATION();

SPI_TRANSFER(0xB9001100, 0x00, 0xFF, 0x00, 0x83, 0x00, 0x57);
usleep(5*1000);
/*
SET_GPIO(GPIO_SPI0_CE1); // Enable Display
usleep(30);
CLEAR_GPIO(GPIO_SPI0_CE1); // Enable Display
*/
SPI_TRANSFER(0xB6001100, 0x00, 0x2C);
SPI_TRANSFER(0x11001100);
usleep(150*1000);
/*
SET_GPIO(GPIO_SPI0_CE1); // Enable Display
usleep(30);
CLEAR_GPIO(GPIO_SPI0_CE1); // Enable Display
*/
SPI_TRANSFER(0x3A001100, 0x00, 0x55);
SPI_TRANSFER(0xB0001100, 0x00, 0x68);
SPI_TRANSFER(0xCC001100, 0x00, 0x09);

SPI_TRANSFER(0xB3001100, 0x00, 0x43, 0x00, 0x00, 0x00, 0x06, 0x00, 0x06);

SPI_TRANSFER(0xB1001100, 0x00, 0x00, 0x00, 0x15, 0x00, 0x1C, 0x00, 0x1C, 0x00, 0x83, 0x00, 0x44);

SPI_TRANSFER(0xC0001100, 0x00, 0x24, 0x00, 0x24, 0x00, 0x01, 0x00, 0x3C, 0x00, 0x1E, 0x00, 0x08);

SPI_TRANSFER(0xB4001100, 0x00, 0x02, 0x00, 0x40, 0x00, 0x00, 0x00, 0x2A, 0x00, 0x2A, 0x00, 0x0D, 0x00, 0x4F);

SPI_TRANSFER(0xE0001100, 0x00, 0x02, 0x00, 0x08, 0x00, 0x11, 0x00, 0x23, 0x00, 0x2C, 0x00, 0x40, 0x00, 0x4A, 0x00, 0x52, 0x00, 0x48, 0x00, 0x41, 0x00, 0x3C, 0x00, 0x33, 0x00, 0x2E, 0x00, 0x28, 0x00, 0x27, 0x00, 0x1B, 0x00, 0x02, 0x00, 0x08, 0x00, 0x11, 0x00, 0x23, 0x00, 0x2C, 0x00, 0x40, 0x00, 0x4A, 0x00, 0x52, 0x00, 0x48, 0x00, 0x41, 0x00, 0x3C, 0x00, 0x33, 0x00, 0x2E, 0x00, 0x28, 0x00, 0x27, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x01);

SPI_TRANSFER(0x36001100, 0x00, 0x3A);

SPI_TRANSFER(0x29001100);

usleep(200*1000);
#if 0
#ifdef DISPLAY_SPI_BUS_IS_16BITS_WIDE #ifdef DISPLAY_SPI_BUS_IS_16BITS_WIDE
SPI_TRANSFER(0xB0/*Interface Mode Control*/, 0x00, 0x00/*DE polarity=High enable, PCKL polarity=data fetched at rising time, HSYNC polarity=Low level sync clock, VSYNC polarity=Low level sync clock*/); SPI_TRANSFER(0xB0/*Interface Mode Control*/, 0x00, 0x00/*DE polarity=High enable, PCKL polarity=data fetched at rising time, HSYNC polarity=Low level sync clock, VSYNC polarity=Low level sync clock*/);
#else #else
Expand Down Expand Up @@ -104,7 +232,7 @@ void InitILI9486()
printf("Setting TFT backlight on at pin %d\n", GPIO_TFT_BACKLIGHT); printf("Setting TFT backlight on at pin %d\n", GPIO_TFT_BACKLIGHT);
TurnBacklightOn(); TurnBacklightOn();
#endif #endif

#endif
ClearScreen(); ClearScreen();
} }
#ifndef USE_DMA_TRANSFERS // For DMA transfers, keep SPI CS & TA active. #ifndef USE_DMA_TRANSFERS // For DMA transfers, keep SPI CS & TA active.
Expand Down
8 changes: 5 additions & 3 deletions ili9486.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "config.h" #include "config.h"


// Data specific to the ILI9486 controller // Data specific to the ILI9486 controller
#define DISPLAY_SET_CURSOR_X 0x2A #define DISPLAY_SET_CURSOR_X 0x2A001100
#define DISPLAY_SET_CURSOR_Y 0x2B #define DISPLAY_SET_CURSOR_Y 0x2B001100
#define DISPLAY_WRITE_PIXELS 0x2C #define DISPLAY_WRITE_PIXELS 0x2C001100


#ifdef WAVESHARE35B_ILI9486 #ifdef WAVESHARE35B_ILI9486
#include "waveshare35b.h" #include "waveshare35b.h"
Expand All @@ -21,5 +21,7 @@
// ILI9486 does not behave well if one sends partial commands, but must finish each command or the command does not apply // ILI9486 does not behave well if one sends partial commands, but must finish each command or the command does not apply
#define MUST_SEND_FULL_CURSOR_WINDOW #define MUST_SEND_FULL_CURSOR_WINDOW


//// #define DISPLAY_NEEDS_CHIP_SELECT_SIGNAL

void InitILI9486(void); void InitILI9486(void);
#define InitSPIDisplay InitILI9486 #define InitSPIDisplay InitILI9486
Loading

0 comments on commit 4c92290

Please sign in to comment.