The LCD and CPU cables are divided into control lines and data lines. The control lines are generally based on the SPI protocol. We initialize the LCD registers through this. Under the premise that the output format of the main chip is fixed, LCD adjustment is the rest of the initial registers. Generally, we need to care about this part of LCD transplantation. The data line is used to transmit pixel data to the LCD, which generally does not need to be controlled, as long as the wiring is okay, it is generally OK. I have been puzzled that since this part of the code is fixed, why can't I save the control line part because there is no IC manufacturer making firmware:
From another perspective, we can see that the value of the initialization register is more than 10 B at best, far less than 1 kb. If you only add a storage device for the dozens of B data, the cost is virtually increased. Therefore, many LCD registers need to be initialized before use. Well, technically speaking, it's because of cost down.
The following describes the driver IC of ili9481ds, which is the SPI part. The following is the sequence diagram of the serial interface of ili9481ds SPEC:
The following information can be extracted:
1) read data from the LCD on the rising edge of the SCL, And the level changes on the falling edge SDA
2) The transmission unit is 9bit. The first bit is used to identify whether the following 8bit is command or data. The first bit is 0, then cmd, and the first bit is data.
The Code is as follows:
Command issuing Function
Static void evaluate (u8 Val) {int I; gpio_set_value (spi_cs, 0); // "low" enablegpio_set_value (spi_sclk, 0); gpio_set_value (spi_sdi, 0 ); udelay (1); gpio_set_value (spi_sclk, 1); // CLK generates a rising edge. The read SDI level is 0. According to the spec, The 8bit is command rather than dataudelay (1 ); /* if you want to get the Val binary, and send it out through SDI */for (I = 0; I <8; I ++) {/* #1: drive the data (high or low) */gpio_set_value (spi_sclk, 0); If (Val & bit_shift [I]) // gpio_set_value (spi_sdi, 1); elsegpio_set_value (spi_sdi, 0);/* #2: Drive the CLK high and then low */udelay (1); gpio_set_value (spi_sclk, 1); // CLK generates a rising edge, read level udelay (1);}/* fixme: idle state of SDI shocould be low */If (gpio_get_value (spi_sdi) {gpio_set_value (spi_sdi, 0);} gpio_set_value (spi_cs, 1); // disable LCD chip}
Data sending Function
Static void evaluate (u8 Val) {int I; gpio_set_value (spi_cs, 0); // "low" enablegpio_set_value (spi_sclk, 0); gpio_set_value (spi_sdi, 1 ); // dataudelay (1); gpio_set_value (spi_sclk, 1); // CLK generates a rising edge. The read SDI level is 1, and the 8bit under spec is data rather than commandudelay (1 ); /* if you want to get the Val binary, and send it out through SDI */for (I = 0; I <8; I ++) {/* #1: drive the data (high or low) */gpio_set_value (spi_sclk, 0); If (Val & bit_shift [I]) // gpio_set_value (spi_sdi, 1); elsegpio_set_value (spi_sdi, 0);/* #2: Drive the CLK high and then low */udelay (1); gpio_set_value (spi_sclk, 1); // CLK generates a rising edge, read level udelay (1);}/* fixme: idle state of SDI shocould be low */If (gpio_get_value (spi_sdi) {gpio_set_value (spi_sdi, 0);} gpio_set_value (spi_cs, 1); // disable LCD chip}
The difference between the two functions is only the red part!
To add this question, let's take a look at the data written into the LCD using SPI, What Is CMD and what is data.
Http://www.52rd.com/bbs/Detail_RD.BBS_214230_5_1_1.html