/** * Lousy function for automatic LCD initialization */ void lcd_initialize(void) { unsigned char i; // set relevant pins as outputs LCD_DATA_DDR = ~DATA_MASK; LCD_RS_DDR = 0; LCD_RW_DDR = 0; LCD_EN_DDR = 0; LCD_BL_DDR = 0; // initialize the display_config for (i = 0; i < 6; i++) { display_config[i] = 0x00; } LCD_RS = 0; LCD_RW = 0; // set 4-bit mode _send_nibble(0b0010); // function set lcd_flags_set(FUNCTION_SET, DATA_LENGTH | CHAR_FONT, 0); lcd_flags_set(FUNCTION_SET, DISPLAY_LINES, 1); lcd_backlight_on(); lcd_display_on(); lcd_cursor_off(); lcd_blinking_off(); lcd_flags_set(ENTRY_MODE, CURSOR_INCREMENT, 1); lcd_flags_set(ENTRY_MODE, ENABLE_SHIFTING, 0); lcd_clear(); lcd_return_home(); }
/*--------------------------------------------------------------------------- 功能: lcd 初始化 ---------------------------------------------------------------------------*/ void __lcd_ili9325_init(void) { GPIO_PowerOn(CN_GPIO_F); GPIO_PowerOn(CN_GPIO_G); GPIO_CfgPinFunc(CN_GPIO_F,10,CN_GPIO_MODE_GPIO_OUT_OD_2Mhz); GPIO_CfgPinFunc(CN_GPIO_G,8,CN_GPIO_MODE_GPIO_OUT_PP_2Mhz); lcd_backlight_off(); lcd_reset(); Djy_DelayUs(100000); if( __ili9325_read_reg() != 0x9325) { return; } __ili9325_write_reg(0x0000, 0x0001); //Start internal OSC __ili9325_write_reg(0x0001, 0x0000); // set SS=0 and SM=0 S1---S720 __ili9325_write_reg(0x0002, 0x0700); // set 1 line inversion __ili9325_write_reg(0x0003, 0x1030); // set GRAM write direction and BGR=1. __ili9325_write_reg(0x0004, 0x0000); // Resize register __ili9325_write_reg(0x0008, 0x0207); // set the back porch and front porch __ili9325_write_reg(0x0009, 0x0000); // set non-display area refresh cycle ISC[3:0] __ili9325_write_reg(0x000a, 0x0000); // FMARK function __ili9325_write_reg(0x000c, 0x0000); // RGB interface setting __ili9325_write_reg(0x000d, 0x0000); // Frame marker Position __ili9325_write_reg(0x000f, 0x0000); // RGB interface polarity //-------------power on sequence------------ __ili9325_write_reg(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB __ili9325_write_reg(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0] __ili9325_write_reg(0x0012, 0x0000); // VREG1OUT voltage __ili9325_write_reg(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude Djy_DelayUs(5000); __ili9325_write_reg(0x0010, 0x1690); // SAP, BT[3:0], AP, DSTB, SLP, STB __ili9325_write_reg(0x0011, 0x0227); // R11H=0x0221 at VCI=3.3V, DC1[2:0], DC0[2:0], VC[2:0] Djy_DelayUs(5000); __ili9325_write_reg(0x0012, 0x001d); // External reference voltage= Vci;001d Djy_DelayUs(5000); __ili9325_write_reg(0x0013, 0x0800); // R13H=1D00 when R12H=009D;VDV[4:0] for VCOM amplitude __ili9325_write_reg(0x0029, 0x0014); // R29H=0013 when R12H=009D;VCM[5:0] for VCOMH __ili9325_write_reg(0x002b, 0x000B); // Frame Rate = 96Hz Djy_DelayUs(5000); __ili9325_write_reg(0x0020, 0x0000); // GRAM horizontal Address __ili9325_write_reg(0x0021, 0x0000); // GRAM Vertical Address // ----------- Adjust the Gamma Curve ---------- __ili9325_write_reg(0x0030, 0x0007); __ili9325_write_reg(0x0031, 0x0707); __ili9325_write_reg(0x0032, 0x0006); __ili9325_write_reg(0x0035, 0x0704); __ili9325_write_reg(0x0036, 0x1F04); __ili9325_write_reg(0x0037, 0x0004); __ili9325_write_reg(0x0038, 0x0000); __ili9325_write_reg(0x0039, 0x0706); __ili9325_write_reg(0x003c, 0x0701); __ili9325_write_reg(0x003d, 0x000F); // ------------------ Set GRAM area --------------- __ili9325_write_reg(0x0050, 0x0000); // Horizontal GRAM Start Address __ili9325_write_reg(0x0051, 239); // Horizontal GRAM End Address __ili9325_write_reg(0x0052, 0x0000); // Vertical GRAM Start Address __ili9325_write_reg(0x0053, 319); // Vertical GRAM Start Address __ili9325_write_reg(0x0060, 0x2700); // GS=0 320 line __ili9325_write_reg(0x0061, 0x0001); // NDL,VLE(滚屏允许), REV(灰度翻转) __ili9325_write_reg(0x006a, 0x0000); // set scrolling line // -------------- Partial Display Control --------- __ili9325_write_reg(0x0080, 0x0000); __ili9325_write_reg(0x0081, 0x0000); __ili9325_write_reg(0x0082, 0x0000); __ili9325_write_reg(0x0083, 0x0000); __ili9325_write_reg(0x0084, 0x0000); __ili9325_write_reg(0x0085, 0x0000); // -------------- Panel Control ------------------- __ili9325_write_reg(0x0090, 0x0010); __ili9325_write_reg(0x0092, 0x0000); __ili9325_write_reg(0x0093, 0x0003); __ili9325_write_reg(0x0095, 0x0110); __ili9325_write_reg(0x0097, 0x0000); __ili9325_write_reg(0x0098, 0x0000); // Set GRAM write direction and BGR = 1 // I/D=11 (Horizontal : increment, Vertical : increment) // AM=0 (address is updated in Horizontal writing direction) __ili9325_write_reg(0x0003, 0x1030); __ili9325_write_reg(0x0007, 0x0173); // 262K color and display ON lcd_backlight_on(); }
static void lcd_on(void *board_data, struct fb_info *info) { lcd_backlight_on(); }
int main(void) { int c; char buff[100]; int offset = 0; int started = 0; //ctc_clocksInit(12000000,60000000,1); //ctc_mamInit(MAM_FULLY_ENABLED); //ramvectorsInit(); //busywaitInit(); VPBDIV = 0x00000001; /* PCLK = CCLK */ PLLCFG = 0x00000024; /* Fosc=12MHz, CCLK=60MHz */ PLLCON = 0x00000001; /* enable the PLL */ PLLFEED = 0x000000AA; /* feed sequence */ PLLFEED = 0x00000055; while (!(PLLSTAT & 0x00000400)); PLLCON = 3; // enable and connect PLLFEED = 0xAA; PLLFEED = 0x55; vicInit(); uart0Init(); DBG("Initializing USB stack\n"); usbInit(); vcomInit(); DBG("Starting USB communication\n"); interruptsEnable(); usbConnect(); lcdInit(); // echo any character received (do USB stuff in interrupt) while (1) { c = vcomGetchar(); if (c != -1) { // show on console if ((c == 9) || (c == 10) || (c == 13) || ((c >= 32) && (c <= 126))) { uint8_t buf[2]; buf[0] = c; buf[1] = 0; DBG((char*) buf); } else { DBG("."); } vcomPutchar(c); if (c == 13) { DBG("Cmd entered.\n"); buff[offset] = '\0'; offset = 0; if (!strcmp(buff, "start")) { started = 1; } else if (started) { if (!strcmp(buff, "bl-on")) { lcd_backlight_on(); } else if (!strcmp(buff, "bl-off")) { lcd_backlight_off(); } else if (!strcmp(buff, "clear")) { lcdClear(); } else { lcdPrintString(buff); } } } else { buff[offset++] = c; } } } }
static void lcd_truely_1p3828_config_480_800() { int spi_fd, i; char buf[64]; #ifndef LCD_BRIGHEST int pwm_fd1, pwm_fd2; int lcd_brightness; int ret; #endif /* Power On */ lcd_power_on(); /* Hardware Reset */ lcd_reset(); #ifdef LCD_BRIGHEST /* Backlight on */ lcd_backlight_on(); #endif /* Program TRUELY_1P3828 to output 480x800 */ if (lcd_spi_dev_node(buf)) { perror("Unable to get lcd spi bus_id or cs_id!\n"); goto lcd_truely_1p3828_config_480_800_exit; } spi_fd = open(buf, O_WRONLY); if (spi_fd < 0) { perror("Can't open TRUELY_1P3828_SPI_DEV_NODE to write"); goto lcd_truely_1p3828_config_480_800_exit; } else { truely_1p3828_set_spi_bus(spi_fd); } truely_1p3828_write_cmd(spi_fd, 0xB9); //Set_EXTC truely_1p3828_write_data(spi_fd, 0xFF); truely_1p3828_write_data(spi_fd, 0x83); truely_1p3828_write_data(spi_fd, 0x69); truely_1p3828_write_cmd(spi_fd, 0xB1); //Set Power truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x34); truely_1p3828_write_data(spi_fd, 0x06); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x0F); // truely_1p3828_write_data(spi_fd, 0x0F); truely_1p3828_write_data(spi_fd, 0x2A); truely_1p3828_write_data(spi_fd, 0x32); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x07); truely_1p3828_write_data(spi_fd, 0x23); truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_cmd(spi_fd, 0xB2); // SET Display 480x800 truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x2b); truely_1p3828_write_data(spi_fd, 0x0A); truely_1p3828_write_data(spi_fd, 0x0A); truely_1p3828_write_data(spi_fd, 0x70); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0xFF); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x03); truely_1p3828_write_data(spi_fd, 0x03); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_cmd(spi_fd, 0xB4); // SET Display 480x800 truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x18); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x10); truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_cmd(spi_fd, 0xB6); // SET VCOM truely_1p3828_write_data(spi_fd, 0x2C); truely_1p3828_write_data(spi_fd, 0x2C); truely_1p3828_write_cmd(spi_fd, 0xD5); //SET GIP truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x05); truely_1p3828_write_data(spi_fd, 0x03); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_data(spi_fd, 0x09); truely_1p3828_write_data(spi_fd, 0x10); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x37); truely_1p3828_write_data(spi_fd, 0x37); truely_1p3828_write_data(spi_fd, 0x20); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x46); truely_1p3828_write_data(spi_fd, 0x8A); truely_1p3828_write_data(spi_fd, 0x57); truely_1p3828_write_data(spi_fd, 0x9B); truely_1p3828_write_data(spi_fd, 0x20); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x46); truely_1p3828_write_data(spi_fd, 0x8A); truely_1p3828_write_data(spi_fd, 0x57); truely_1p3828_write_data(spi_fd, 0x9B); truely_1p3828_write_data(spi_fd, 0x07); truely_1p3828_write_data(spi_fd, 0x0F); truely_1p3828_write_data(spi_fd, 0x02); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_cmd(spi_fd, 0xE0); //SET GAMMA truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x0D); truely_1p3828_write_data(spi_fd, 0x2D); truely_1p3828_write_data(spi_fd, 0x34); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0x38); truely_1p3828_write_data(spi_fd, 0x09); truely_1p3828_write_data(spi_fd, 0x0E); truely_1p3828_write_data(spi_fd, 0x0E); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x14); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x14); truely_1p3828_write_data(spi_fd, 0x13); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x0D); truely_1p3828_write_data(spi_fd, 0x2D); truely_1p3828_write_data(spi_fd, 0x34); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0x38); truely_1p3828_write_data(spi_fd, 0x09); truely_1p3828_write_data(spi_fd, 0x0E); truely_1p3828_write_data(spi_fd, 0x0E); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x14); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x14); truely_1p3828_write_data(spi_fd, 0x13); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_cmd(spi_fd, 0xC1); //set DGC truely_1p3828_write_data(spi_fd, 0x01); //enable DGC function truely_1p3828_write_data(spi_fd, 0x02); //SET R-GAMMA truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x1A); truely_1p3828_write_data(spi_fd, 0x22); truely_1p3828_write_data(spi_fd, 0x2A); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x36); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x48); truely_1p3828_write_data(spi_fd, 0x51); truely_1p3828_write_data(spi_fd, 0x58); truely_1p3828_write_data(spi_fd, 0x60); truely_1p3828_write_data(spi_fd, 0x68); truely_1p3828_write_data(spi_fd, 0x70); truely_1p3828_write_data(spi_fd, 0x78); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x88); truely_1p3828_write_data(spi_fd, 0x90); truely_1p3828_write_data(spi_fd, 0x98); truely_1p3828_write_data(spi_fd, 0xA0); truely_1p3828_write_data(spi_fd, 0xA7); truely_1p3828_write_data(spi_fd, 0xAF); truely_1p3828_write_data(spi_fd, 0xB6); truely_1p3828_write_data(spi_fd, 0xBE); truely_1p3828_write_data(spi_fd, 0xC7); truely_1p3828_write_data(spi_fd, 0xCE); truely_1p3828_write_data(spi_fd, 0xD6); truely_1p3828_write_data(spi_fd, 0xDE); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xEF); truely_1p3828_write_data(spi_fd, 0xF5); truely_1p3828_write_data(spi_fd, 0xFB); truely_1p3828_write_data(spi_fd, 0xFC); truely_1p3828_write_data(spi_fd, 0xFE); truely_1p3828_write_data(spi_fd, 0x8C); truely_1p3828_write_data(spi_fd, 0xA4); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0xEC); truely_1p3828_write_data(spi_fd, 0x1B); truely_1p3828_write_data(spi_fd, 0x4C); truely_1p3828_write_data(spi_fd, 0x40); truely_1p3828_write_data(spi_fd, 0x02); //SET G-Gamma truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x1A); truely_1p3828_write_data(spi_fd, 0x22); truely_1p3828_write_data(spi_fd, 0x2A); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x36); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x48); truely_1p3828_write_data(spi_fd, 0x51); truely_1p3828_write_data(spi_fd, 0x58); truely_1p3828_write_data(spi_fd, 0x60); truely_1p3828_write_data(spi_fd, 0x68); truely_1p3828_write_data(spi_fd, 0x70); truely_1p3828_write_data(spi_fd, 0x78); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x88); truely_1p3828_write_data(spi_fd, 0x90); truely_1p3828_write_data(spi_fd, 0x98); truely_1p3828_write_data(spi_fd, 0xA0); truely_1p3828_write_data(spi_fd, 0xA7); truely_1p3828_write_data(spi_fd, 0xAF); truely_1p3828_write_data(spi_fd, 0xB6); truely_1p3828_write_data(spi_fd, 0xBE); truely_1p3828_write_data(spi_fd, 0xC7); truely_1p3828_write_data(spi_fd, 0xCE); truely_1p3828_write_data(spi_fd, 0xD6); truely_1p3828_write_data(spi_fd, 0xDE); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xEF); truely_1p3828_write_data(spi_fd, 0xF5); truely_1p3828_write_data(spi_fd, 0xFB); truely_1p3828_write_data(spi_fd, 0xFC); truely_1p3828_write_data(spi_fd, 0xFE); truely_1p3828_write_data(spi_fd, 0x8C); truely_1p3828_write_data(spi_fd, 0xA4); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0xEC); truely_1p3828_write_data(spi_fd, 0x1B); truely_1p3828_write_data(spi_fd, 0x4C); truely_1p3828_write_data(spi_fd, 0x40); truely_1p3828_write_data(spi_fd, 0x02); //SET B-Gamma truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x1A); truely_1p3828_write_data(spi_fd, 0x22); truely_1p3828_write_data(spi_fd, 0x2A); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x36); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x48); truely_1p3828_write_data(spi_fd, 0x51); truely_1p3828_write_data(spi_fd, 0x58); truely_1p3828_write_data(spi_fd, 0x60); truely_1p3828_write_data(spi_fd, 0x68); truely_1p3828_write_data(spi_fd, 0x70); truely_1p3828_write_data(spi_fd, 0x78); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x88); truely_1p3828_write_data(spi_fd, 0x90); truely_1p3828_write_data(spi_fd, 0x98); truely_1p3828_write_data(spi_fd, 0xA0); truely_1p3828_write_data(spi_fd, 0xA7); truely_1p3828_write_data(spi_fd, 0xAF); truely_1p3828_write_data(spi_fd, 0xB6); truely_1p3828_write_data(spi_fd, 0xBE); truely_1p3828_write_data(spi_fd, 0xC7); truely_1p3828_write_data(spi_fd, 0xCE); truely_1p3828_write_data(spi_fd, 0xD6); truely_1p3828_write_data(spi_fd, 0xDE); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xEF); truely_1p3828_write_data(spi_fd, 0xF5); truely_1p3828_write_data(spi_fd, 0xFB); truely_1p3828_write_data(spi_fd, 0xFC); truely_1p3828_write_data(spi_fd, 0xFE); truely_1p3828_write_data(spi_fd, 0x8C); truely_1p3828_write_data(spi_fd, 0xA4); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0xEC); truely_1p3828_write_data(spi_fd, 0x1B); truely_1p3828_write_data(spi_fd, 0x4C); truely_1p3828_write_data(spi_fd, 0x40); truely_1p3828_write_cmd(spi_fd, 0x2D);//Look up table for(i = 0; i < 64; i++) { truely_1p3828_write_data(spi_fd, 8 * i); } for(i = 0; i < 64; i++) { truely_1p3828_write_data(spi_fd, 4 * i); } for(i = 0; i < 64; i++) { truely_1p3828_write_data(spi_fd, 8 * i); } MSLEEP(10); truely_1p3828_write_cmd(spi_fd, 0x3A); //Set COLMOD truely_1p3828_write_data(spi_fd, 0x77); truely_1p3828_write_cmd(spi_fd, 0x11); //Sleep Out MSLEEP(120); truely_1p3828_write_cmd(spi_fd, 0x29); //Display On //truely_1p3828_write_cmd(spi_fd, 0x2C); //Display On close(spi_fd); #ifndef LCD_BRIGHEST /* Backlight on */ pwm_fd1 = open(TRUELY_1P3828_PWM_PATH("max_brightness"), O_RDONLY); if (pwm_fd1 < 0) { perror("Can't open max_brightness to read"); goto lcd_truely_1p3828_config_480_800_exit; } ret = read(pwm_fd1, buf, sizeof(buf)); close(pwm_fd1); if (ret <= 0) { perror("Can't read max_brightness"); goto lcd_truely_1p3828_config_480_800_exit; } else { lcd_brightness = atoi(buf) / 2; } pwm_fd2 = open(TRUELY_1P3828_PWM_PATH("brightness"), O_WRONLY); if (pwm_fd2 < 0) { perror("Can't open brightness to write"); goto lcd_truely_1p3828_config_480_800_exit; } sprintf(buf, "%d", lcd_brightness); ret = write(pwm_fd2, buf, sizeof(buf)); close(pwm_fd2); if (ret <= 0) { perror("Can't write brightness"); goto lcd_truely_1p3828_config_480_800_exit; } #endif lcd_truely_1p3828_config_480_800_exit: return; }