///////////////////////////////////////////////////////////////////////////// // 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 }
///////////////////////////////////////////////////////////////////////////// // Transfers a Bitmap within given boundaries to the LCD // IN: bitmap // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_BitmapPrint(mios32_lcd_bitmap_t bitmap) { int line; int y_lines = (bitmap.height >> 3); for(line=0; line<y_lines; ++line) { // calculate pointer to bitmap line u8 *memory_ptr = bitmap.memory + line * bitmap.line_offset; // set graphical cursor after second line has reached if( line > 0 ) { mios32_lcd_x -= bitmap.width; mios32_lcd_y += 8; APP_LCD_GCursorSet(mios32_lcd_x, mios32_lcd_y); } // transfer bitmap int x; for(x=0; x<bitmap.width; ++x) APP_LCD_Data(*memory_ptr++); } // fix graphical cursor if more than one line has been print if( y_lines >= 1 ) { mios32_lcd_y = mios32_lcd_y - (bitmap.height-8); APP_LCD_GCursorSet(mios32_lcd_x, mios32_lcd_y); } return 0; // no 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 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 }
///////////////////////////////////////////////////////////////////////////// //! Sends data byte to LCD //! \param[in] data byte which should be sent to LCD //! \return < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 MIOS32_LCD_Data(u8 data) { // -> forward to app_lcd return APP_LCD_Data(data); }
//! \param[in] c character to be print //! \return < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 MIOS32_LCD_PrintChar(char c) { s32 status; if( MIOS32_LCD_TypeIsGLCD() ) { // GLCD if( !font_bitmap.width ) return -1; // font not initialized yet! mios32_lcd_bitmap_t bitmap = font_bitmap; bitmap.memory += (bitmap.height>>3) * bitmap.line_offset * (size_t)c; status = APP_LCD_BitmapPrint(bitmap); } else { status = APP_LCD_Data(c); } if( status >= 0 ) { // increment cursor ++mios32_lcd_column; } return status; } ///////////////////////////////////////////////////////////////////////////// //! Initializes a single special character //! \param[in] num character number (0-7) //! \param[in] table 8 byte pattern
///////////////////////////////////////////////////////////////////////////// // Transfers a Bitmap within given boundaries to the LCD // IN: bitmap // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_BitmapPrint(mios32_lcd_bitmap_t bitmap) { int stored_mios32_lcd_y = mios32_lcd_y; int line; int y_lines = (bitmap.height >> 2); // we need two write accesses per 8bit line for(line=0; line<y_lines; ++line) { // set graphical cursor after second line has reached if( line > 0 ) { mios32_lcd_x -= bitmap.width; mios32_lcd_y += 4; APP_LCD_GCursorSet(mios32_lcd_x, mios32_lcd_y); } // transfer bitmap switch( bitmap.colour_depth ) { case 2: { // depth 2 // calculate pointer to bitmap line u8 *memory_ptr = bitmap.memory + line * bitmap.line_offset; int x; for(x=0; x<bitmap.width; ++x) APP_LCD_Data(*memory_ptr++); } break; default: { // depth 1 or others // calculate pointer to bitmap line u8 *memory_ptr = bitmap.memory + (line / 2) * bitmap.line_offset; if( line & 1 ) { int x; for(x=0; x<bitmap.width; ++x) { u8 b = 0; if( *memory_ptr & (1 << 4) ) b |= (3 << 0); if( *memory_ptr & (1 << 5) ) b |= (3 << 2); if( *memory_ptr & (1 << 6) ) b |= (3 << 4); if( *memory_ptr & (1 << 7) ) b |= (3 << 6); APP_LCD_Data(b); ++memory_ptr; } } else { int x; for(x=0; x<bitmap.width; ++x) { u8 b = 0; if( *memory_ptr & (1 << 0) ) b |= (3 << 0); if( *memory_ptr & (1 << 1) ) b |= (3 << 2); if( *memory_ptr & (1 << 2) ) b |= (3 << 4); if( *memory_ptr & (1 << 3) ) b |= (3 << 6); APP_LCD_Data(b); ++memory_ptr; } } } } } // fix graphical cursor if Y position has changed if( y_lines > 1 ) { mios32_lcd_y = stored_mios32_lcd_y; APP_LCD_GCursorSet(mios32_lcd_x, mios32_lcd_y); } return 0; // no error }