SPI LCD屏驱动

因为硬件的限制 SPI 只有三根线(cs clk sdi)

unsigned int spi_read_24date(unsigned char reg)
{
    char i;
    unsigned int buff=0;
    set_spi_cs(0);
    udelay(200);
    set_spi_clk(0);
    set_spi_sdi(0);
    set_spi_clk(1);
    udelay(100);
    for(i=0; i < 8; i++)
    {
        set_spi_clk(0);
        udelay(200);
        if(reg & 0x80)
            set_spi_sdi(1);
        else
            set_spi_sdi(0);
        udelay(100);
        set_spi_clk(1);
        udelay(200);
        reg <<= 1;
    }
    spi_sdi_set_input(1);//把sdi口设置为input
    udelay(200);
    set_spi_clk(0);
    udelay(300);
    set_spi_clk(1);
    udelay(200);
    for(i=0; i < 24; i++)
    {
        set_spi_clk(0);
        udelay(200);
        if(spi_sdi_get_input(1)) 
            buff |= 0x800000 >> i;
        udelay(100);
        set_spi_clk(1);
        udelay(200); 
    }
}
void spi_write_date(unsigned char data)
{
char i;
    set_spi_cs(0);
    udelay(200);
    set_spi_clk(0);
    set_spi_sdi(1);
    set_spi_clk(1);
    udelay(100);
    for(i=0; i < 8; i++)
    {
        set_spi_clk(0);
        udelay(200);
        if(cmd & 0x80)
            set_spi_sdi(1);
        else
            set_spi_sdi(0);
        udelay(100);
        set_spi_clk(1);
        udelay(200);
        cmd <<= 1;
    }
    set_spi_cs(1);
}
void spi_write_cmd(unsigned char cmd)
{
    char i;
    set_spi_cs(0);
    udelay(200);
    set_spi_clk(0);
    set_spi_sdi(0);
    set_spi_clk(1);
    udelay(100);
    for(i=0; i < 8; i++)
    {
        set_spi_clk(0);
        udelay(200);
        if(cmd & 0x80)
            set_spi_sdi(1);
        else
            set_spi_sdi(0);
        udelay(100);
        set_spi_clk(1);
        udelay(200);
        cmd <<= 1;
    }
    set_spi_cs(1);
}
void    init_7789v(void)
{
spi_write_cmd(0x01);
udelay(2000);//Delay 120ms
spi_write_cmd(0x11);
udelay(2000);//Delay 120ms
//---------------------Display Setting------------------------//

//-----------------------ST7789V Frame rate setting-----------------//
spi_write_cmd(0xb2);
spi_write_date(0x0c);
spi_write_date(0x0c);
spi_write_date(0x00);
spi_write_date(0x33);
spi_write_date(0x33);
spi_write_cmd(0xb7);
spi_write_date(0x35); //VGH=13V, VGL=-10.4V
//-------------------------------------------------//
spi_write_cmd(0xbb);
spi_write_date(0x19);
spi_write_cmd(0xc0);
spi_write_date(0x2c);
spi_write_cmd(0xc2);
spi_write_date(0x01);
spi_write_cmd(0xc3);
spi_write_date(0x12);
spi_write_cmd(0xc4);

spi_write_date(0x20);
spi_write_cmd(0xc6);
spi_write_date(0x0f);
spi_write_cmd(0xd0);
spi_write_date(0xa4);
spi_write_date(0xa1);
//----------------------------------------//
spi_write_cmd(0xe0); //gamma setting
spi_write_date(0xd0);
spi_write_date(0x04);
spi_write_date(0x0d);
spi_write_date(0x11);
spi_write_date(0x13);
spi_write_date(0x2b);
spi_write_date(0x3f);
spi_write_date(0x54);
spi_write_date(0x4c);
spi_write_date(0x18);
spi_write_date(0x0d);
spi_write_date(0x0b);
spi_write_date(0x1f);
spi_write_date(0x23);
spi_write_cmd(0xe1);
spi_write_date(0xd0);
spi_write_date(0x04);
spi_write_date(0x0c);
spi_write_date(0x11);
spi_write_date(0x13);
spi_write_date(0x2c);
spi_write_date(0x3f);
spi_write_date(0x44);
spi_write_date(0x51);
spi_write_date(0x2f);
spi_write_date(0x1f);
spi_write_date(0x1f);
spi_write_date(0x20);
spi_write_date(0x23);

spi_write_cmd(0xb0);
spi_write_date(0x11);
spi_write_date(0xf0);

spi_write_cmd(0xb1);
spi_write_date(0xc0); 
spi_write_date(0x02); 
spi_write_date(0x14);

spi_write_cmd(0x36);
spi_write_date(0x14);
spi_write_cmd(0x3a);
spi_write_date(0x66);

spi_write_cmd(0x29); //display on
}

你可能感兴趣的:(驱动,7789v)