Nano2G LCD init

From freemyipod.org
Revision as of 23:16, 2 February 2010 by 95.112.189.78 (talk) (Created page with ' static void lcd_send_cmd(uint32_t cmd) __attribute__((naked, noinline)); static void lcd_send_cmd(uint32_t cmd) { (void)cmd; asm volatile( "mov r2, #0x38000...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
static void lcd_send_cmd(uint32_t cmd) __attribute__((naked, noinline));
static void lcd_send_cmd(uint32_t cmd)
{
    (void)cmd;
    asm volatile(
        "mov r2, #0x38000000   \n\t"
        "orr r2, r2, #0x600000 \n\t"
        "lsc_wait:             \n\t"
        "ldrh r1, [r2,#0x1c]   \n\t"
        "tst r1, #0x10         \n\t"
        "bne lsc_wait          \n\t"
        "strh r0, [r2,#0x4]    \n\t"
        "mov pc, lr            \n\t"
    );
}

static void lcd_7_send_data(uint32_t data) __attribute__((naked, noinline));
static void lcd_7_send_data(uint32_t data)
{
    (void)data;
    asm volatile(
        "mov r2, #0x38000000   \n\t"
        "orr r2, r2, #0x600000 \n\t"
        "and r0, r0, #0xff     \n\t"
        "strh r0, [r2,#0x40]   \n\t"
        "ls7d_wait:            \n\t"
        "ldrh r1, [r2,#0x1c]   \n\t"
        "tst r1, #0x10         \n\t"
        "bne ls7d_wait         \n\t"
        "mov pc, lr            \n\t"
    );
}

static void lcd_delay(uint32_t time) __attribute__((naked, noinline));
static void lcd_delay(uint32_t time)
{
    (void)time;
    asm volatile(
        "mov r0, r0,lsl#16      \n\t"
        "ld_wait:              \n\t"
        "subs r0, r0, #1       \n\t"
        "bne ld_wait           \n\t"
        "mov pc, lr            \n\t"
    );
}

#define LCD_RST_TIME *((volatile uint32_t*)(0x38600024))
#define LCD_DRV_RST  *((volatile uint32_t*)(0x38600028))

void main(void)
{
    LCD_RST_TIME = 0x7FFF;
    LCD_DRV_RST = 0;
    lcd_delay(1);
    LCD_DRV_RST = 1;
    lcd_delay(5);

    lcd_send_cmd(0x01);
    lcd_7_send_data(0x00);

    lcd_delay(10);

    lcd_send_cmd(0xB1);
    lcd_7_send_data(0x16);
    lcd_7_send_data(0x03);
 
    lcd_send_cmd(0xB2);
    lcd_7_send_data(0x17);
    lcd_7_send_data(0x03);

    lcd_send_cmd(0xB4);
    lcd_7_send_data(0x00);

    lcd_send_cmd(0xB6);
    lcd_7_send_data(0x01);

    lcd_send_cmd(0xB7);
    lcd_7_send_data(0x00);
    lcd_7_send_data(0x00);
    lcd_7_send_data(0x02);
    lcd_7_send_data(0x00);
    lcd_7_send_data(0x06);
    lcd_7_send_data(0x26);
    lcd_7_send_data(0x2D);
    lcd_7_send_data(0x27);
    lcd_7_send_data(0x55);
    lcd_7_send_data(0x27);

    lcd_send_cmd(0xB8);
    lcd_7_send_data(0x10);

    lcd_send_cmd(0xB9);
    lcd_7_send_data(0x52);
    lcd_7_send_data(0x12);
    lcd_7_send_data(0x03);

    lcd_send_cmd(0xC0);
    lcd_7_send_data(0x0A);
    lcd_7_send_data(0x10);
    lcd_7_send_data(0x10);

    lcd_send_cmd(0xC2);
    lcd_7_send_data(0x14);
    lcd_7_send_data(0x23);

    lcd_send_cmd(0xC3);
    lcd_7_send_data(0x12);
    lcd_7_send_data(0x23);

    lcd_send_cmd(0xC6);
    lcd_7_send_data(0x48);

    lcd_send_cmd(0xE0);
    lcd_7_send_data(0x20);
    lcd_7_send_data(0x71);
    lcd_7_send_data(0x17);
    lcd_7_send_data(0x09);
    lcd_7_send_data(0x70);
    lcd_7_send_data(0x0C);
    lcd_7_send_data(0x13);
    lcd_7_send_data(0x25);

    lcd_send_cmd(0xE1);
    lcd_7_send_data(0x37);
    lcd_7_send_data(0x00);
    lcd_7_send_data(0x63);
    lcd_7_send_data(0x11);
    lcd_7_send_data(0xD9);
    lcd_7_send_data(0x00);
    lcd_7_send_data(0x12);
    lcd_7_send_data(0x01);

    lcd_send_cmd(0xE2);
    lcd_7_send_data(0x42);
    lcd_7_send_data(0x42);
    lcd_7_send_data(0x60);
    lcd_7_send_data(0x08);
    lcd_7_send_data(0xB4);
    lcd_7_send_data(0x07);
    lcd_7_send_data(0x0E);
    lcd_7_send_data(0x90);

    lcd_send_cmd(0xE3);
    lcd_7_send_data(0x47);
    lcd_7_send_data(0x60);
    lcd_7_send_data(0x66);
    lcd_7_send_data(0x09);
    lcd_7_send_data(0x6A);
    lcd_7_send_data(0x02);
    lcd_7_send_data(0x0E);
    lcd_7_send_data(0x09);

    lcd_send_cmd(0xE4);
    lcd_7_send_data(0x11);
    lcd_7_send_data(0x40);
    lcd_7_send_data(0x03);
    lcd_7_send_data(0x0A);
    lcd_7_send_data(0xC1);
    lcd_7_send_data(0x0D);
    lcd_7_send_data(0x17);
    lcd_7_send_data(0x30);

    lcd_send_cmd(0xE5);
    lcd_7_send_data(0x00);
    lcd_7_send_data(0x30);
    lcd_7_send_data(0x77);
    lcd_7_send_data(0x1C);
    lcd_7_send_data(0xFB);
    lcd_7_send_data(0x00);
    lcd_7_send_data(0x13);
    lcd_7_send_data(0x07);

    lcd_send_cmd(0xE6);
    lcd_7_send_data(0x01);

    lcd_send_cmd(0x35);
    lcd_7_send_data(0x00);

    lcd_send_cmd(0x36);
    lcd_7_send_data(0x00);

    lcd_send_cmd(0xF2);
    lcd_7_send_data(0x40);

    lcd_send_cmd(0xF3);
    lcd_7_send_data(0x50);

    lcd_send_cmd(0xFB);
    lcd_7_send_data(0x01);

    lcd_send_cmd(0x11);
    lcd_7_send_data(0x00);

    lcd_delay(200);

    lcd_send_cmd(0x3A);
    lcd_7_send_data(0x65);

    lcd_send_cmd(0x29);
    lcd_7_send_data(0x00);
}