Template:EPaper Codes Descriptions-IT8951

From Waveshare Wiki
Jump to: navigation, search

Codes Description

New Features

  • 1.Update 16 grayscale image in 4bpp mode to reduce the data size while transmitting via SPI.
  • 2.Speedup the SPI transmitting. Note that this feature can only valid in Raspberry Pi, it is invalid in Pi 4 because of the improving of CPU.
  • 3.Reduce the update time to 1/4. The last version of Demo codes cost 10s to update a picture on 10.3inch e-Paper (D) in GC16 Mode, with the new version, it is reduce to 3s.
  • 4.Fix the bug that memory leaks problem which is occurs after open a bmp file.
  • 5.Add 1bpp, 2bpp, 3bpp, 4bpp modes support.
  • 6.Add A2 Mode (only work for 1bpp mode)
  • 7.Add GUI functions (Draw point, line, circle, rectange and string display). Supports changing gray.
  • 8.Add GIF file displaying, you can storage pictures to buffer of IT8951, and then transmit them to e-Paper for displaying. The update rate is up t o 7fps by delecting the transmittng process between RPi and IT8951.
  • 10.Add fps testing, it can be used to test the fps when update with different windows size in different modes.
  • 11.Enhande the driver, to fix the buf of blurred display in partial area.
  • 12.Support bytes alignment for 6inch ePaper HAT and 6inch HD ePaper HAT in 1bpp mode.
  • 13.Add VCOM setting and clear ePaper function (running Demo codes directly) to protect ePaper from damaging.
  • 14.Improving the structure of driver codes for higher code readablity.

Examples Description

1 Display 16 bars in grayscale order

  • Function:DisplayColorPaletteExample
  • This function is sued to display 16 bars in different grayscale. It uses 4bpp in GC16 mode.

2 Drawing

  • Function: DisplayCharacterPatternExample
  • This function is sued to draw point, line, circle, rectange as well as display string. It suppots 1bpp, 2bpp, 4bpp and 8bpp mode. If you use 1bpp, it can also supports the A2 update mode.

3 Display BMP image

  • Function:DisplayBMPExample
  • This function is used to display a BMP image. It suppots 1bpp, 2bpp, 4bpp and 8bpp mode. If you use 1bpp, it can also supports the A2 update mode.

4 Update ePaper in A2 mode

  • Function:DynamicRefreshExample
  • This function is used to update ePaper in A2 Mode.

5 Display GIF image

  • Function:DynamicGIFExample
  • This function is used to display GIF image. We divide a GIF file to seven BMP images, and save them to buffer of IT8951 with continuous address. This demo features the fastest fps of the ePaper (about 7fps).

6 FPS Testing

  • Function:CheckFrameRateExample
  • This function is sued to test fps in different modes. The demo will auot-caculate the update time of 10 frames and the fps.。

Related Description

1 Mode

The firmware in IT8951 Driver board are different among differnt types of e-Paper. And the update mode maybe different among these e-Paper. For more information abou the update modes, you can refer to IT8951 Mode Description. There are three modes: INIT, GC16 and A2.

Mode Description 6inch/6inch HD 7.8inch/9.7inch/10.3inch
INIT This mode is used for clearing the display. If you use A2 mode for updating, we recommend you use the INIT mode to clear display after updating several times. Mode0 Mode0
GC16 This mode is used for updating ePaper with 16 grayscale. GC16 mode can provide best dispaly effect. Mode2 Mode2
A2 A2 mode can only support 2 grayscale, however, the update speed is the fastest. Mode4 Mode6
//basic mode definition
UBYTE INIT_Mode = 0;
UBYTE GC16_Mode = 2;
//A2_Mode's value is not fixed, is decide by firmware's LUT 
UBYTE A2_Mode = 6;
if( strcmp(LUT_Version, "M641") == 0 ){
    //6inch e-Paper HAT(800,600), 6inch HD e-Paper HAT(1448,1072), 6inch HD touch e-Paper HAT(1448,1072)
    A2_Mode = 4;
    Four_Byte_Align = true;
}else if( strcmp(LUT_Version, "M841") == 0 ){
    //9.7inch e-Paper HAT(1200,825)
    A2_Mode = 6;
}else if( strcmp(LUT_Version, "M841_TFA2812") == 0 ){
    //7.8inch e-Paper HAT(1872,1404)
    A2_Mode = 6;
}else if( strcmp(LUT_Version, "M841_TFA5210") == 0 ){
    //10.3inch e-Paper HAT(1872,1404)
    A2_Mode = 6;
}else{
    //default set to 6 as A2 Mode
    A2_Mode = 6;
}

2 bpp Description

bpp(Bits Per Pixel), it stands of the bits costed by every pixel. The current versions of ePaper supports 1bpp, 2bpp, 4bpp and 8bpp modes.

  • 1bpp
  • 1bit cost by every pixel
  • It support 2 grayscale displaying. supports A2 mode
  • Evey byte carries 8 pixels
  • The pixel is saved in byte in Big-endian format:

20191219165020.png

  • The data saved in IT8951 with Little-endian format, you need to convert data before saving.


  • 2bpp
  • 2bits cost by evey pixel
  • Supports 4 (2^2=4) grayscale
  • Evey byte carries 4 pixels
  • The pixel is saved in byte in Big-endian format:

20191219164855.png

  • The data saved in IT8951 with Little-endian format, you need to convert data before saving.
  • 4bpp
  • 4bits cost by evey pixel.
  • Supports 16(2^4=16) grayscale
  • Every byte carries 2 pixels
  • The pixel is saved in byte in Big-endian format:

20191219164916.png

  • The data saved in IT8951 with Little-endian format, you need to convert data before saving.
  • 4bpp mode is recommended for display 16 grayscale image. It reduce a half of data by comparing to 8bpp.


  • 8bpp
  • 8bits cost by evey pixel
  • Supports 256 (2^8=256) grayscale. However, IT8951 only use the first four bits for 16 grayscale displaying.
  • Every byte carries one pixel
  • The pixel is saved in byte in Big-endian format:

20191219164949.png

  • The data saved in IT8951 with Little-endian format, you need to convert data before saving.
  • When you convert a original image for gray image, the data of evey pixel cost one byte (8 bits). You can compressed the data according to actual data format. For example: if you want to convert data for 2bpp mode, you can just use the first 2bits from on byte (original gray image). The exmaples below also convert the data format from big-endian to little-endian.
UDOUBLE Addr = X * (Paint.BitsPerPixel) / 8 + Y * Paint.WidthByte;
switch( Paint.BitsPerPixel ){
    case 8:{
        Paint.Image[Addr] = Color & 0xF0;
        break;
    }
    case 4:{
        Paint.Image[Addr] &= ~( (0xF0) >> (7 - (X*4+3)%8 ) );
        Paint.Image[Addr] |= (Color & 0xF0) >> (7 - (X*4+3)%8 );
        break;
    }
    case 2:{
        Paint.Image[Addr] &= ~( (0xC0) >> (7 - (X*2+1)%8 ) );
        Paint.Image[Addr] |= (Color & 0xC0) >> (7 - (X*2+1)%8 );
        break;
    }
    case 1:{
        Paint.Image[Addr] &= ~( (0x80) >> (7 - X%8) );
        Paint.Image[Addr] |= (Color & 0x80) >> (7 - X%8);
        break;
    }
}

3 4-byte alignment description

In the actual test, we found that for those 3 products: 6inch e-Paper HAT, 6inch HD e-Paper HAT, and 6inch HD touch e-Paper HAT, when refreshing in 1bpp mode, we need to make the starting point of the refresh area X and the refresh width W to perform 4-byte (32bit) alignment, otherwise, the image in the refresh area will display abnormally. The specific operation is shown in the following program:

if( strcmp(LUT_Version, "M641") == 0 ){
    //6inch e-Paper HAT(800,600), 6inch HD e-Paper HAT(1448,1072), 6inch HD touch e-Paper HAT(1448,1072)
    A2_Mode = 4;
    Four_Byte_Align = true;
}else if( strcmp(LUT_Version, "M841") == 0 ){
...
}
if(Four_Byte_Align == true){
    In_4bp_Refresh_Area_Width = Panel_Width - (Panel_Width % 32);
}else{
    In_4bp_Refresh_Area_Width = Panel_Width;
}
X_Start = Min_X < 32 ? 0 : Min_X - (Min_X % 32);
Debug("X_Start:%d\r\n",X_Start);
X_End = ( Max_X + (32 - (Max_X % 32)) ) > Touch_Pannel_Area_Width ? ( Max_X - (Max_X % 32) )  : ( Max_X + (32 - (Max_X % 32)) );
Debug("X_End:%d\r\n",X_End);
Y_Start = Min_Y;
Debug("Y_Start:%d\r\n",Y_Start);
Y_End = Max_Y;
Debug("Y_Start:%d\r\n",Y_End);
Width = X_End - X_Start;
if(Width<=0){
    Width = 32;
}
Debug("Width:%d\r\n",Width);
Height = Y_End-Y_Start;
if(Height<=0){
    Height = 32;
}
Debug("Height:%d\r\n",Height);

4 SPI transmission speed description

Due to the difference in CPU frequency between Raspberry Pi 3 and Raspberry Pi 4:

  • Raspberry Pi 3 can still transmit normally when the frequency is divided by 16, but the frequency by 16 is the fastest speed for Pi3.
  • When the frequency of the Raspberry Pi 4B uses a divide by 16, the SPI rate is too high and transmission errors will occur. Therefore, the SPI of the Raspberry Pi 4B can only use a divide by 32 at the fastest.
  • In the BCM2835 library manual, for different Raspberry Pi versions and different clock divisions, the corresponding frequency description is shown in the following figure:

20191219173204.png

  • If you need to obtain the most suitable SPI transmission speed, you need to select a different SPI clock divider according to your Raspberry Pi version, as shown in the following program and its notes:
bcm2835_spi_begin();//Start spi interface, set spi pin for the reuse function
bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);//High first transmission
bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);//spi mode 0
 
//bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16);//For RPi 3/3B/3B+
bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_32);//For RPi 4B
 
/* SPI clock reference link:*/
/*http://www.airspayce.com/mikem/bcm2835/group__constants.html#gaf2e0ca069b8caef24602a02e8a00884e*/

5 Enhance driving capability

In some cases, due to the long FPC cable and other reasons, the ink screen display will be partially blurred. In this case, you can try to increase the driving capability to effectively solve the problem of the screen display blur.

You can check the demo as below:

#if(Enhance)
    Debug("Attention! Enhanced driving ability, only used when the screen is blurred\r\n");
    Enhance_Driving_Capability();
#endif
/******************************************************************************
function :  Enhanced driving capability
parameter:  Enhanced driving capability for IT8951, in case the blurred display effect
******************************************************************************/
void Enhance_Driving_Capability(void)
{
    UWORD RegValue = EPD_IT8951_ReadReg(0x0038);
    Debug("The reg value before writing is %x\r\n", RegValue);
    EPD_IT8951_WriteReg(0x0038, 0x0602);
    RegValue = EPD_IT8951_ReadReg(0x0038);
    Debug("The reg value after writing is %x\r\n", RegValue);
}

If you use the E-LINK-TCON-DEMO software on a PC (Windows) to refresh the ink screen through the USB interface, you can modify the register value in the following ways to enhance the drive capability:

  • Step1: Read the data of register address 0x18000038.

13.3inch epaper 01.png

If the read data of register address 0x18000038 is 0x02, it means that the drive capability has not been enhanced yet.

  • Step2: Modify the data of register address 0x18000038

13.3inch epaper 02.png

Modify the data of register address 0x18000038 to 602 to enhance the driving capability.

  • Step3: Check the data of register address 0x18000038.

13.3inch epaper 03.png

Check whether the data of the register address 0x18000038 is modified successfully. If the data of this address is 0x602, it means that the drive capacity has been enhanced.

6 Use the correct VCOM value

The VCOM value of each model of the e-paper is marked on the FPC cable. Make sure that you have used the correct VCOM value when you running the demo. Otherwise, the e-paper will deteriorate by working for a long time under the wrong VCOM value.