///////////////////////////////////////////////////////////////////////////// // 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 }
///////////////////////////////////////////////////////////////////////////// // Clear Screen // IN: - // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_Clear(void) { s32 error = 0; u8 x, y; // use default font MIOS32_LCD_FontInit((u8 *)GLCD_FONT_NORMAL); // select all LCDs error |= MIOS32_LCD_CursorSet(0, 0); // send data for(y=0; y<APP_LCD_HEIGHT; y=y+4) { error |= APP_LCD_GCursorSet(0, y); MIOS32_BOARD_J15_DataSet(0x00); MIOS32_BOARD_J15_RS_Set(1); // RS pin used to control DC for(x=0; x<APP_LCD_WIDTH; ++x){ MIOS32_BOARD_J15_SerDataShift(0x00); } } // set X=0, Y=0 error |= MIOS32_LCD_CursorSet(0, 0); return error; }
///////////////////////////////////////////////////////////////////////////// //! Sets graphical cursor to given position<BR> //! Only relevant for GLCDs //! \param[in] x position //! \param[in] y position //! \return < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 MIOS32_LCD_GCursorSet(u16 x, u16 y) { mios32_lcd_x = x; mios32_lcd_y = y; // forward new cursor position to app driver return APP_LCD_GCursorSet(x, y); }
///////////////////////////////////////////////////////////////////////////// // Sets cursor to given position // IN: <column> and <line> // OUT: returns < 0 on errors ///////////////////////////////////////////////////////////////////////////// s32 APP_LCD_CursorSet(u16 column, u16 line) { s32 error = 0; #if 0 // exit with error if line is not in allowed range if( line >= MIOS32_LCD_MAX_MAP_LINES ) return -1; // exit if mapped line >= 8 (not supported by KS0108) u8 mapped_line = mios32_lcd_cursor_map[line]; if( mapped_line >= 8 ) return -2; // ... return error; #else // mios32_lcd_x/y set by MIOS32_LCD_CursorSet() function return APP_LCD_GCursorSet(mios32_lcd_x, mios32_lcd_y); #endif }
///////////////////////////////////////////////////////////////////////////// // 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 }