///////////////////////////////////////////////////////////////////////////// // Sends data byte to LCD // IN: data byte in <data> // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Data(u8 data) { // select LCD depending on current cursor position // THIS PART COULD BE CHANGED TO ARRANGE THE 8 DISPLAYS ON ANOTHER WAY u8 line = mios32_lcd_y / APP_LCD_HEIGHT; u8 row = (mios32_lcd_x % (2*APP_LCD_WIDTH)) / APP_LCD_WIDTH; u8 cs = 2*line + row; if( cs >= 8 ) return -1; // invalid CS line // chip select and DC #if APP_LCD_USE_J10_FOR_CS MIOS32_BOARD_J10_Set(~(1 << cs)); #else MIOS32_BOARD_J15_DataSet(~(1 << cs)); #endif MIOS32_BOARD_J15_RS_Set(1); // RS pin used to control DC // send data MIOS32_BOARD_J15_SerDataShift(data); // increment graphical cursor ++mios32_lcd_x; // if end of display segment reached: set X position of all segments to 0 if( (mios32_lcd_x % APP_LCD_WIDTH) == 0 ) { APP_LCD_Cmd(0x00); // set X=0 APP_LCD_Cmd(0x10); } return 0; // no error }
///////////////////////////////////////////////////////////////////////////// // Clear Screen // IN: - // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Clear(void) { int x, y; // use default font MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); // clear whole 128x128 screen with background colour // ST7637 specific function to set view APP_LCD_SetRect_For_Cmd(0, 0, APP_LCD_WIDTH, APP_LCD_HEIGHT); // Send command to write data on the LCD screen. APP_LCD_Cmd(ST7637_RAMWR); for(x=0; x<APP_LCD_WIDTH; ++x) { for(y=0; y<APP_LCD_HEIGHT; ++y) { APP_LCD_Data(lcd_bcolour & 0xff); APP_LCD_Data(lcd_bcolour >> 8); } } // set cursor to initial position APP_LCD_CursorSet(0, 0); return 0; // no error }
///////////////////////////////////////////////////////////////////////////// // Sets cursor to given position // IN: <column> and <line> // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_CursorSet(u16 column, u16 line) { // exit with error if line is not in allowed range if( line >= MIOS32_LCD_MAX_MAP_LINES ) return -1; // -> set cursor address return APP_LCD_Cmd(0x80 | (mios32_lcd_cursor_map[line] + column)); }
///////////////////////////////////////////////////////////////////////////// // Hack: reinitializes the screens after some time, to clean up // potentially garbled screens // ///////////////////////////////////////////////////////////////////////////// void reinit() { mios32_sys_time_t t = MIOS32_SYS_TimeGet(); charcount++; if (t.seconds > last_reinit_seconds || charcount > 500) { charcount = 0; last_reinit_seconds = t.seconds; MIOS32_BOARD_J15_RS_Set(0); MIOS32_BOARD_J15_RW_Set(0); APP_LCD_Cmd(0b00110011); APP_LCD_Cmd(0b00110010); APP_LCD_Cmd(0b00101000); // 4bit, 2 lines APP_LCD_Cmd(0b00001100); // display on, cursor off, char blinking off APP_LCD_Cmd(0b00000110); // entry mode } }
///////////////////////////////////////////////////////////////////////////// // Sends data byte to LCD // IN: data byte in <data> // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Data(u8 data) { // select LCD depending on current cursor position // THIS PART COULD BE CHANGED TO ARRANGE THE 8 DISPLAYS ON ANOTHER WAY u8 line = 0; if( mios32_lcd_y >= 3*APP_LCD_HEIGHT ) line = 3; else if( mios32_lcd_y >= 2*APP_LCD_HEIGHT ) line = 2; else if( mios32_lcd_y >= 1*APP_LCD_HEIGHT ) line = 1; u8 row = 0; if( mios32_lcd_x >= 1*APP_LCD_WIDTH ) row = 1; u8 cs = 2*line + row; if( cs >= 8 ) return -1; // invalid CS line // chip select and DC MIOS32_BOARD_J15_DataSet(~(1 << cs)); MIOS32_BOARD_J15_RS_Set(1); // RS pin used to control DC // send data MIOS32_BOARD_J15_SerDataShift(data); //MIOS32_DELAY_Wait_uS(40); // exact 10 uS delay // increment graphical cursor ++mios32_lcd_x; // if end of display segment reached: set X position of all segments to 0 if( (mios32_lcd_x % APP_LCD_WIDTH) == 0 ) { APP_LCD_Cmd(0x00); // Set lower nibble to 0 return APP_LCD_Cmd(0x10); // Set upper nibble to 0 } return 0; // no error }
///////////////////////////////////////////////////////////////////////////// // Sets graphical cursor to given position // IN: <x> and <y> // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_GCursorSet(u16 x, u16 y) { s32 error = 0; // set X position error |= APP_LCD_Cmd(0x00 | ((x % APP_LCD_WIDTH) & 0x0f)); // send LSB nibble error |= APP_LCD_Cmd(0x10 | (((x % APP_LCD_WIDTH) >> 4) & 0x0f)); // send MSB nibble // set Y position error |= APP_LCD_Cmd(0x60 | ((y>>2) % (2*APP_LCD_HEIGHT/8))); return error; }
///////////////////////////////////////////////////////////////////////////// // Sets graphical cursor to given position // IN: <x> and <y> // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_GCursorSet(u16 x, u16 y) { s32 error = 0; // set X position error |= APP_LCD_Cmd(0x00 | (x & 0xf)); error |= APP_LCD_Cmd(0x10 | ((x>>4) & 0xf)); // set Y position error |= APP_LCD_Cmd(0xb0 | ((y>>3) & 7)); return error; }
///////////////////////////////////////////////////////////////////////////// // Initializes a single special character // IN: character number (0-7) in <num>, pattern in <table[8]> // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_SpecialCharInit(u8 num, u8 table[8]) { s32 i; // send character number APP_LCD_Cmd(((num&7)<<3) | 0x40); // send 8 data bytes for(i=0; i<8; ++i) if( APP_LCD_Data(table[i]) < 0 ) return -1; // error during sending character // set cursor to original position return APP_LCD_CursorSet(mios32_lcd_column, mios32_lcd_line); }
///////////////////////////////////////////////////////////////////////////// // Initializes application specific VFD driver // IN: <mode>: optional configuration // OUT: returns < 0 if initialisation failed ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Init(u32 mode) { MIOS32_BOARD_J15_PortInit(APP_LCD_OUTPUT_MODE); MIOS32_BOARD_J15_RS_Set(0); MIOS32_BOARD_J15_RW_Set(0); APP_LCD_Cmd(0b00110011); APP_LCD_Cmd(0b00110010); APP_LCD_Cmd(0b00101000); // 4bit, 2 lines APP_LCD_Cmd(0b00001100); // display on, cursor off, char blinking off APP_LCD_Cmd(0b00000110); // entry mode APP_LCD_Cmd(0b00000001); // clear return 0; }
///////////////////////////////////////////////////////////////////////////// // Initializes application specific LCD driver // IN: <mode>: optional configuration // OUT: returns < 0 if initialisation failed ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Init(u32 mode) { GPIO_InitTypeDef GPIO_InitStructure; s32 delay; // set LCD type mios32_lcd_parameters.lcd_type = MIOS32_LCD_TYPE_GLCD_CUSTOM; // set initial font and colours MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); MIOS32_LCD_BColourSet(0xffffff); MIOS32_LCD_FColourSet(0x000000); // control lines PIN_BL(1); PIN_RS(1); PIN_RD(1); PIN_CS(1); PIN_WR(1); PIN_RST(1); GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = APP_LCD_BL_PIN; GPIO_Init(APP_LCD_BL_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_RS_PIN; GPIO_Init(APP_LCD_RS_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_RD_PIN; GPIO_Init(APP_LCD_RD_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_WR_PIN; GPIO_Init(APP_LCD_WR_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_CS_PIN; GPIO_Init(APP_LCD_CS_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = APP_LCD_RST_PIN; GPIO_Init(APP_LCD_RST_PORT, &GPIO_InitStructure); // Apply hardware reset PIN_RST(0); for(delay=0; delay<0x500; ++delay); PIN_RST(1); for(delay=0; delay<0x500; ++delay); // configure data pins as outputs GPIO_InitStructure.GPIO_Pin = APP_LCD_D_PINS; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(APP_LCD_D_PORT, &GPIO_InitStructure); //----------- software reset ------------------------------------------------ APP_LCD_Cmd(ST7637_SWRESET); //----------- disable autoread + Manual read once --------------------------- APP_LCD_Cmd( ST7637_AUTOLOADSET ); // Auto Load Set 0xD7 APP_LCD_Data( 0xBF ); // Auto Load Disable APP_LCD_Cmd( ST7637_EPCTIN ); // EE Read/write mode 0xE0 APP_LCD_Data( 0x00 ); // Set read mode APP_LCD_Cmd( ST7637_EPMRD ); // Read active 0xE3 APP_LCD_Cmd( ST7637_EPCTOUT ); // Cancel control 0xE1 //---------------------------------- Sleep OUT ------------------------------ APP_LCD_Cmd( ST7637_DISPOFF ); // display off 0x28 APP_LCD_Cmd( ST7637_SLPOUT ); // Sleep Out 0x11 //--------------------------------Vop setting-------------------------------- APP_LCD_Cmd( ST7637_VOPSET ); // Set Vop by initial Module 0xC0 APP_LCD_Data( 0xFB ); // Vop = 13.64 APP_LCD_Data( 0x00 ); // base on Module //----------------------------Set Register----------------------------------- APP_LCD_Cmd( ST7637_BIASSEL ); // Bias select 0xC3 APP_LCD_Data( 0x00 ); // 1/12 Bias, base on Module APP_LCD_Cmd( ST7637_BSTBMPXSEL ); // Setting Booster times 0xC4 APP_LCD_Data( 0x05 ); // Booster X 8 APP_LCD_Cmd( ST7637_BSTEFFSEL ); // Booster eff 0xC5 APP_LCD_Data( 0x11 ); // BE = 0x01 (Level 2) APP_LCD_Cmd( ST7637_VGSORCSEL ); // Vg with booster x2 control 0xcb APP_LCD_Data( 0x01 ); // Vg from Vdd2 APP_LCD_Cmd( ST7637_ID1SET ); // ID1 = 00 0xcc APP_LCD_Data( 0x00 ); // APP_LCD_Cmd( ST7637_ID3SET ); // ID3 = 00 0xce APP_LCD_Data( 0x00 ); // APP_LCD_Cmd( ST7637_COMSCANDIR ); // Glass direction APP_LCD_Data( 0xC0 ); // APP_LCD_Cmd( ST7637_ANASET ); // Analog circuit setting 0xd0 APP_LCD_Data( 0x1D ); // APP_LCD_Cmd( ST7637_PTLMOD ); // PTL mode set APP_LCD_Data( 0x18 ); // power normal mode APP_LCD_Cmd( ST7637_INVOFF ); // Display Inversion OFF 0x20 APP_LCD_Cmd( ST7637_CASET ); // column range APP_LCD_Data( 0x04 ); // APP_LCD_Data( 0x83 ); // APP_LCD_Cmd( ST7637_RASET ); // raw range APP_LCD_Data( 0x04 ); // APP_LCD_Data( 0x83 ); // APP_LCD_Cmd( ST7637_COLMOD ); // Color mode = 65k 0x3A APP_LCD_Data( 0x05 ); // APP_LCD_Cmd( ST7637_MADCTR ); // Memory Access Control 0x36 APP_LCD_Data( V12_MADCTRVAL ); APP_LCD_Cmd( ST7637_DUTYSET ); // Duty = 132 duty 0xb0 APP_LCD_Data( 0x7F ); APP_LCD_Cmd( ST7637_DISPON ); // Display ON APP_LCD_Cmd( ST7637_FRAMESET ); // Gamma APP_LCD_Data( 0x00 ); // APP_LCD_Data( 0x03 ); // APP_LCD_Data( 0x05 ); // APP_LCD_Data( 0x07 ); // APP_LCD_Data( 0x09 ); // APP_LCD_Data( 0x0B ); // APP_LCD_Data( 0x0D ); // APP_LCD_Data( 0x0F ); // APP_LCD_Data( 0x11 ); // APP_LCD_Data( 0x13 ); // APP_LCD_Data( 0x15 ); // APP_LCD_Data( 0x17 ); // APP_LCD_Data( 0x19 ); // APP_LCD_Data( 0x1B ); // APP_LCD_Data( 0x1D ); // APP_LCD_Data( 0x1F ); // return 0; // no error }
///////////////////////////////////////////////////////////////////////////// // Clear Screen // IN: - // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Clear(void) { // -> send clear command return APP_LCD_Cmd(0x01); }
///////////////////////////////////////////////////////////////////////////// //! Sends command byte to LCD //! \param[in] cmd command byte which should be sent to LCD //! \return < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 MIOS32_LCD_Cmd(u8 cmd) { // -> forward to app_lcd return APP_LCD_Cmd(cmd); }
///////////////////////////////////////////////////////////////////////////// // Initializes application specific LCD driver // IN: <mode>: optional configuration // OUT: returns < 0 if initialisation failed ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Init(u32 mode) { // currently only mode 0 supported if( mode != 0 ) return -1; // unsupported mode if( MIOS32_BOARD_J15_PortInit(APP_LCD_OUTPUT_MODE) < 0 ) return -2; // failed to initialize J15 // enable display by default display_available |= (1 << mios32_lcd_device); // set LCD type mios32_lcd_parameters.lcd_type = MIOS32_LCD_TYPE_GLCD_CUSTOM; mios32_lcd_parameters.num_x = APP_LCD_NUM_X; mios32_lcd_parameters.width = APP_LCD_WIDTH; mios32_lcd_parameters.num_x = APP_LCD_NUM_Y; mios32_lcd_parameters.height = APP_LCD_HEIGHT; mios32_lcd_parameters.colour_depth = APP_LCD_COLOUR_DEPTH; // initialize LCD #ifdef MIOS32_DONT_USE_DELAY u32 delay; for(delay=0; delay<50000; ++delay) MIOS32_BOARD_J15_RW_Set(0); // ca. 50 mS Delay #else MIOS32_DELAY_Wait_uS(50000); // exact 50 mS delay #endif APP_LCD_Cmd(0xf1); APP_LCD_Cmd(0x67); APP_LCD_Cmd(0xc0); APP_LCD_Cmd(0x40); APP_LCD_Cmd(0x50); APP_LCD_Cmd(0x2b); APP_LCD_Cmd(0xeb); APP_LCD_Cmd(0x81); APP_LCD_Cmd(0x58); // contrast(0x00-0xff Default 0x5f APP_LCD_Cmd(0x89); //APP_LCD_Cmd(0xd0); //Greyscale control APP_LCD_Cmd(0xaf); return (display_available & (1 << mios32_lcd_device)) ? 0 : -1; // return -1 if display not available }
///////////////////////////////////////////////////////////////////////////// // Initializes application specific LCD driver // IN: <mode>: optional configuration // OUT: returns < 0 if initialisation failed ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Init(u32 mode) { // currently only mode 0 supported if( mode != 0 ) return -1; // unsupported mode if( MIOS32_BOARD_J15_PortInit(APP_LCD_OUTPUT_MODE) < 0 ) return -2; // failed to initialize J15 #if APP_LCD_USE_J10_FOR_CS int pin; for(pin=0; pin<8; ++pin) MIOS32_BOARD_J10_PinInit(pin, APP_LCD_OUTPUT_MODE ? MIOS32_BOARD_PIN_MODE_OUTPUT_OD : MIOS32_BOARD_PIN_MODE_OUTPUT_PP); #endif // set LCD type mios32_lcd_type = MIOS32_LCD_TYPE_GLCD; // initialize LCD APP_LCD_Cmd(0xa8); // Set MUX Ratio APP_LCD_Cmd(0x3f); APP_LCD_Cmd(0xd3); // Set Display Offset APP_LCD_Cmd(0x00); APP_LCD_Cmd(0x40); // Set Display Start Line APP_LCD_Cmd(0xa0); // Set Segment re-map APP_LCD_Cmd(0xc0); // Set COM Output Scan Direction APP_LCD_Cmd(0xda); // Set COM Pins hardware configuration APP_LCD_Cmd(0x12); APP_LCD_Cmd(0x81); // Set Contrast Control APP_LCD_Cmd(0x7f); // middle APP_LCD_Cmd(0xa4); // Disable Entiere Display On APP_LCD_Cmd(0xa6); // Set Normal Display APP_LCD_Cmd(0xd5); // Set OSC Frequency APP_LCD_Cmd(0x80); APP_LCD_Cmd(0x8d); // Enable charge pump regulator APP_LCD_Cmd(0x14); APP_LCD_Cmd(0xaf); // Display On APP_LCD_Cmd(0x20); // Enable Page mode APP_LCD_Cmd(0x02); return (display_available & (1 << mios32_lcd_device)) ? 0 : -1; // return -1 if display not available }