Template: EPaper Codes Descriptions-IT8951

From Waveshare Wiki
Jump to: navigation, search

Precaution

Hardware Connection

For different ink screen models, due to product upgrades and improvements, there may be certain differences between the hardware connection and the picture, and the specific FPC line pin label shall prevail:

Check example 1:
Check example 1.png
Check example 2:
Check example 2.png

DIP switch

DIP switch.png

I2C interface driver is not recommended at present, it is recommended to use a USB, I80, or SPI interface.

Whether it is driven by a USB interface, I80 interface, or SPI interface, it is necessary to turn the DIP switch circled in the red frame in the figure below to the ON position on the right, as shown in the figure below:

If the PC is connected by USB, and the E-LINK-TCON-DEMO cannot recognize the IT8951, please check whether both sides of the two DIP switches marked in the red frame are connected. Only the two DIP switches marked in the red frame are both connected. turn on to be recognized by the PC.

SPI or I80 driver.png

Choose SPI or I80 driver

If you use a USB drive, you don't need to pay attention to the DIP switch in the green frame shown in the figure below.
If you use SPI driver or I80 driver, you need to pay attention to the DIP switch in the green frame shown in the figure below. If it is dialed to the I80 terminal, it means that the I80 driver is used, and if it is dialed to the SPI terminal, it means that the SPI driver is used:

Codes Description

New Features

1. Update 16 grayscale images in 4bpp mode to reduce the data size while transmitting via SPI.
2. Double SPI transmitting speed. Note that this feature can only be valid in Raspberry Pi, it is invalid in Pi 4 because of the improvement 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 reduced to 3s.
4. Fix the bug that the memory leaks problem occurs after opening a BMP file.
5. Add 1bpp, 2bpp, 3bpp, and 4bpp modes support.
6. Add A2 Mode (only work for 1bpp mode).
7. Add GUI functions (Draw point, line, circle, rectangle, and string display). Supports changing gray.
8. Add 1bpp, 2bpp, 4bpp, and 8bpp refresh support for BMP pictures, if you choose 1bpp, it also supports A2 mode refresh.
9. Add a demo for displaying GIF pictures, which can write multiple pictures into the IT8951 cache, and directly swipe the data of different addresses in the cache into the ink screen for display, eliminating the data transmission process between RPi and IT8951, Refresh frame rate up to 7fps.
10. Add fps testing, it can be used to test the fps when updated with different windows sizes in different modes.
11. Enhance the driver, to fix the bug of blurred display in the 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 damage.
14. Improving the structure of driver codes for higher code readability.

Examples Description

Display 16 bars in grayscale order

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

Drawing

  • Function: Display CharacterPattern Example
  • This function is sued to draw points, lines, circles, and rectangles as well as display strings. It suppots 1bpp, 2bpp, 4bpp and 8bpp mode. If you use 1bpp, it can also support the A2 update mode.

Display BMP image

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

Update ePaper in A2 mode

  • Function:Dynamic Refresh Example
  • This function is used to update ePaper in A2 Mode.

Display GIF image

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

FPS Testing

  • Function:Check FrameRate Example
  • 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

Mode

The firmware in the IT8951 Driver board is different among different types of e-Paper. And the update mode may be different among these e-Paper. For more information about 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 decided by the 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;
}

bpp

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

20191219165020.png
  • 1bpp
  • 1bit cost by every pixel
  • It supports 2 grayscale displays. supports A2 mode
  • Evey byte carries 8 pixels
  • The pixel is saved in byte in Big-endian format:
  • The data is saved in IT8951 with Little-endian format, you need to convert the data before saving.
20191219164855.png
  • 2bpp
  • 2bits cost by every pixel
  • Supports 4 (2^2=4) grayscale
  • Evey byte carries 4 pixels
  • The pixel is saved in byte in Big-endian format:
  • The data is saved in IT8951 with Little-endian format, you need to convert the data before saving.
20191219164916.png
  • 4bpp
  • 4 bits cost by every pixel.
  • Supports 16(2^4=16) grayscale
  • Every byte carries 2 pixels
  • The pixel is saved in byte in Big-endian format:
  • The data is saved in IT8951 with Little-endian format, you need to convert the data before saving.
  • 4bpp mode is recommended for displaying 16 grayscale images. It reduces half of the data by comparing to 8bpp.
20191219164949.png
  • 8bpp
  • 8bits cost by every pixel
  • Supports 256 (2^8=256) grayscale. However, IT8951 only uses the first four bits for 16 grayscale displays.
  • Every byte carries one pixel
  • The pixel is saved in byte in Big-endian format:
  • The data is saved in IT8951 with Little-endian format, you need to convert the data before saving.
  • When you convert an original image for a gray image, the data of every pixel cost one byte (8 bits). You can compress the data according to the actual data format. For example: if you want to convert data for 2bpp mode, you can just use the first 2bits from one byte (original gray image). The examples 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;
    }
}

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 demo:

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);

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*/

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 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 0 x 18000038.

13.3inch epaper 01.png

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

  • Step2: Modify the data of register address 0 x 18000038

13.3inch epaper 02.png

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

  • Step3: Check the data of register address 0 x 18000038.

13.3inch epaper 03.png

Check whether the data of the registered address 0 x 18000038 is modified successfully. If the data of this address is 0 x 602, it means that the drive capacity has been enhanced.

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.

Development Notes

The above content only introduces how to use 10.3inch e-Paper HAT (D)m and how to modify and secondary development, for more demo codes, users need to learn it by themselves. Please refer to IT8951-related resources.