From 330d71e314f65474dbdb051b27f7cc61bc52cf76 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Thu, 5 May 2016 19:45:41 +0800 Subject: [PATCH 01/16] Added a display buffer for the lcd. --- Scan/STLcd/4x6font.bmp | Bin 0 -> 12410 bytes Scan/STLcd/bitmapfont2Struct.py | 133 +++++++++++++++++++ Scan/STLcd/capabilities.kll | 11 ++ Scan/STLcd/lcd_scan.c | 224 +++++++++++++++++++++++--------- 4 files changed, 310 insertions(+), 58 deletions(-) create mode 100755 Scan/STLcd/4x6font.bmp create mode 100755 Scan/STLcd/bitmapfont2Struct.py diff --git a/Scan/STLcd/4x6font.bmp b/Scan/STLcd/4x6font.bmp new file mode 100755 index 0000000000000000000000000000000000000000..39cebb6e9dbc4f611a3b2a8200670de87a35d471 GIT binary patch literal 12410 zcmeH~J8~335JVSTOdL#(z!~IV;cyN-JXzcvO8d}LMpw^hb|ozsJrUb_ot2f<^ym}Z zeY^j1IzRWd{;1Ed`h2d>yVIvy>#6$34}1_#r@OD;e?IcjukQ!r@Aa%3SU0e4VBNsF zfpr7x2G$L%8(256Zs27%Q2)z#HsFZoijY@{-J1K>;g!z_fs^ERhx6Fxln8g|9>S-3 zZ$~jaw^OkU>FIo~Kb)2agR4~(J#N!5h?F#BucZ>{ny&U{m6j|~H9s?L#P3!!x|!&i za4F}YjLku27IgNIwxlQXpXD^1M@@c3s5_;)VA{K`QXt!viXu^N&wWpap@piY%sI{s zGQ@4dG%Z^&a2{76d&%sp?Uo2vPndGf+UH@!V758{Lvu8SQh0h!>FF_0|Infi(Eh^J zOlIX7IuB;IoI$^^rDNEtc70H$+Z2m)>v>)g-Xi~e>ZflBZz*T#0kZUp|GE`*=?&z2 zsb1cTB57^~oNfzp?x0ge)Hy)+sN|_U&j4rB?@M8SntfTWRSz&XtDQ17z=X zRvGlzJ}7K^^`Z0er&7=+P#V_SqG&7FVx8SHv|z}U-Xm*1(g1QtYfPE(6cd z$acDxzw3yWrkRL(G9*PAa4mp`#;IN&&A_n5ki9a1e~X9wX>Xo0ndDTGtqNH!RtH=Q zlCx{7BVxOhGkk}gTOK)QsS~0{J. + +# Imports +import sys + +from array import * +from PIL import Image # Use pillow instead of PIL, it works with Python 3 + +class Bitmap_Size: + def __init__( self, height=0, width=0, size=0, x_ppem=0, y_ppem=0): + self.height = height + self.width = width + self.size = size + self.x_ppem = x_ppem + self.y_ppem = y_ppem + +# Convenience class to deal with converting images to a C array +class STLcdFont: + # Some constants for the LCD Driver + array('B') + + def __init__( self, glyph_width, glyph_height, num_glyphs): + self.glyph_height = glyph_height + self.glyph_width = glyph_width + self.glyph_size = (glyph_height * glyph_width + 7) // 8 + self.num_fixed_sizes = 1 + self.availible_sizes = [Bitmap_Size(self.glyph_height, self.glyph_width)] + self.num_glyphs = num_glyphs + self.glyph_data = [] + for index in range( 0, self.num_glyphs ): + self.glyph_data.append( array( 'B', [0] * self.glyph_size ) ) + + def setpixel( self, index, x, y ): + newy = self.glyph_height - y - 1 + # Calculate which byte + byte = (x * self.glyph_height + newy) // 8 + + # Calculate which bit + bit = (x * self.glyph_height + newy) % 8 + + # Set pixel bit + self.glyph_data[ index ][ byte ] |= (1 << bit) + + def renderglyph( self, index, flags=0): + return self.glyph_data[ index ] + + def getarray( self ): + struct = "{\n" + + for glyph in self.glyph_data: + for elem in glyph: + struct += "0x{0:02x}, ".format( elem ) + struct += "\n}" + + return struct + +filename = sys.argv[1] +glyph_width = int(sys.argv[2]) +glyph_height = int(sys.argv[3]) +num_glyphs = 128 # ASCII +if filename is None: + print( "You must specify a bitmap filename. Try './bitmapfont2Struct.py font.bmp 4 6'" ) + sys.exit( 1 ) +output_image = STLcdFont( glyph_width, glyph_height, num_glyphs ) + + + +# Load the input filename and convert to black & white +try: + input_image = Image.open( filename ).convert('1') +except: + print( "Unable to load image '{0}'".format( filename ) ) + +input_width, input_height = input_image.size +columns = input_width // glyph_width +rows = input_height // glyph_height + +# Iterate over all of the pixels +# Also prepare the debug view of the image (disp_test) +disp_test = "+" + "-" * input_width + "+\n" +glyph_index = 0 +for y in range( 0, input_height ): + row = y // glyph_height + if row >= rows: + break + disp_test += "|" + for x in range( 0, input_width ): + column = x // glyph_width + glyph_index = row * columns + column + if column >= columns or glyph_index >= num_glyphs: + disp_test += " " + else: + # Use image value to determine pixel + try: + if input_image.getpixel( (x, y) ) == 0: + disp_test += "*" + output_image.setpixel( glyph_index, x % glyph_width, y % glyph_height ) + else: + disp_test += " " + except IndexError: + print( (x, y) ) + pass + + disp_test += "|\n" + +disp_test += "+" +for pixel in range( 0, input_width ): + disp_test += "-" +disp_test += "+\n" + +# BMP Conversion preview +print( disp_test ) +#print () +print( "uint8_t array[] = {0};".format( output_image.getarray() ) ) +print( "uint8_t font_glyphs_width = {0};".format( output_image.glyph_width ) ) +print( "uint8_t font_glyphs_height = {0};".format( output_image.glyph_height ) ) +print( "uint8_t font_glyphs_size = {0};".format( output_image.glyph_size ) ) +print( "uint8_t font_num_glyphs = {0};".format( output_image.num_glyphs ) ) diff --git a/Scan/STLcd/capabilities.kll b/Scan/STLcd/capabilities.kll index d5daaead2..f22b511cc 100644 --- a/Scan/STLcd/capabilities.kll +++ b/Scan/STLcd/capabilities.kll @@ -63,6 +63,17 @@ STLcdDefaultImage = " 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, "; +STLcdSmallFont => STLcdSmallFont_define; +STLcdSmallFontWidth => STLcdSmallFontWidth_define; +STLcdSmallFontHeight => STLcdSmallFontHeight_define; +STLcdSmallFontSize => STLcdSmallFontSize_define; + +STLcdSmallFont = "0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xef, 0x03, 0x00, 0x00, 0x00, 0x80, 0x0e, 0x00, 0x30, 0x00, 0x03, 0x3e, 0xe5, 0x03, 0x94, 0x8f, 0x02, 0x24, 0x22, 0x01, 0xbc, 0xee, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x27, 0x02, 0x22, 0x07, 0x00, 0x28, 0x84, 0x02, 0x08, 0x87, 0x00, 0x02, 0x01, 0x00, 0x08, 0x82, 0x00, 0x80, 0x00, 0x00, 0x06, 0x02, 0x03, 0x9e, 0xc8, 0x03, 0x90, 0x0f, 0x00, 0xae, 0xaa, 0x03, 0xa2, 0xea, 0x03, 0x38, 0xe2, 0x03, 0xba, 0xea, 0x02, 0xbe, 0xea, 0x02, 0x26, 0x0a, 0x03, 0xbe, 0xea, 0x03, 0xba, 0xea, 0x03, 0x00, 0x05, 0x00, 0x02, 0x05, 0x00, 0x08, 0x25, 0x02, 0x14, 0x45, 0x01, 0x22, 0x85, 0x00, 0xa0, 0x0a, 0x03, 0x9c, 0xaa, 0x01, 0x1e, 0xea, 0x01, 0xbe, 0x4a, 0x01, 0x9c, 0x28, 0x02, 0xbe, 0xc8, 0x01, 0xbe, 0xaa, 0x02, 0x3e, 0x8a, 0x02, 0x9c, 0xea, 0x02, 0x3e, 0xe2, 0x03, 0xa2, 0x2f, 0x02, 0x84, 0xc0, 0x03, 0x3e, 0x62, 0x03, 0xbe, 0x20, 0x00, 0x3e, 0xe6, 0x03, 0x3e, 0xe8, 0x03, 0x9c, 0xc8, 0x01, 0x3e, 0x0a, 0x01, 0x9c, 0xe9, 0x01, 0x3e, 0xab, 0x01, 0x92, 0x4a, 0x02, 0xa0, 0x0f, 0x02, 0xbc, 0xe0, 0x03, 0xb8, 0x81, 0x03, 0x3e, 0xe3, 0x03, 0x36, 0x62, 0x03, 0xb0, 0x03, 0x03, 0xa6, 0x2a, 0x03, 0xbe, 0x28, 0x02, 0x10, 0x42, 0x00, 0xa2, 0xe8, 0x03, 0x10, 0x08, 0x01, 0x82, 0x20, 0x00, 0x20, 0x04, 0x00, 0x96, 0xe6, 0x00, 0xbe, 0xc4, 0x00, 0x8c, 0x24, 0x01, 0x8c, 0xe4, 0x03, 0x8c, 0xa5, 0x01, 0x88, 0x87, 0x02, 0x4c, 0xe5, 0x01, 0x3e, 0xe4, 0x00, 0x80, 0x0b, 0x00, 0x42, 0xe0, 0x02, 0x3e, 0x23, 0x01, 0xa2, 0x2f, 0x00, 0x1e, 0xe7, 0x01, 0x1e, 0xe4, 0x00, 0x8c, 0xc4, 0x00, 0x9f, 0xc4, 0x00, 0x8c, 0xf4, 0x01, 0x0e, 0x04, 0x01, 0x8a, 0x47, 0x01, 0x90, 0x2f, 0x01, 0x9c, 0xe0, 0x01, 0x9c, 0xc1, 0x01, 0x9e, 0xe3, 0x01, 0x12, 0x23, 0x01, 0x58, 0xe1, 0x01, 0x96, 0xa7, 0x01, 0x88, 0x2d, 0x02, 0x80, 0x0d, 0x00, 0xa2, 0x8d, 0x00, 0x10, 0x0c, 0x02, 0xbe, 0xef, 0x03"; +STLcdSmallFontWidth = 4; +STLcdSmallFontHeight = 6; +STLcdSmallFontSize = 3; + +# LCDCharOut => LCD_charOut_capability(charactor : 1, x : 1, y : 1) # Layer Status Display diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 1dd912682..5f3f8da1f 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -40,7 +40,8 @@ #define LCD_TOTAL_VISIBLE_PAGES 4 #define LCD_TOTAL_PAGES 9 #define LCD_PAGE_LEN 128 - +#define LCD_WIDTH 128 +#define LCD_HEIGHT 32 // ----- Macros ----- @@ -68,6 +69,14 @@ void cliFunc_lcdTest ( char* args ); // Default Image - Displays on startup const uint8_t STLcdDefaultImage[] = { STLcdDefaultImage_define }; +const uint8_t STLcdSmallFont[] = { STLcdSmallFont_define }; + +const uint8_t STLcdSmallFontWidth = STLcdSmallFontWidth_define; +const uint8_t STLcdSmallFontHeight = STLcdSmallFontHeight_define; +const uint8_t STLcdSmallFontSize = STLcdSmallFontSize_define; + + + // Full Toggle State uint8_t cliFullToggleState = 0; @@ -338,11 +347,55 @@ inline void LCD_setup() PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); } +// Display buffer +static uint8_t STLcdBuffer[LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES]; +// Bounding box +static uint8_t STLcdUpdateXMin = LCD_WIDTH, STLcdUpdateXMax = 0; +static uint8_t STLcdUpdateYMin = LCD_HEIGHT, STLcdUpdateYMax = 0; + +static void STLcd_updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) { + if (xmin < STLcdUpdateXMin) STLcdUpdateXMin = xmin; + if (xmax > STLcdUpdateXMax) STLcdUpdateXMax = xmax; + if (ymin < STLcdUpdateYMin) STLcdUpdateYMin = ymin; + if (ymax > STLcdUpdateYMax) STLcdUpdateYMax = ymax; +} + +void STLcd_clear(void) { + memset(STLcdBuffer, 0, LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES); + STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); +} + +void STLcd_display(void) { + if(STLcdUpdateYMin > STLcdUpdateYMax) + return; + for(uint8_t page = STLcdUpdateYMin >> 3; page < STLcdUpdateYMax >> 3; page++) { + // check if this page is part of update + if ( STLcdUpdateYMin >= ((page + 1) * 8) ) { + continue; // nope, skip it! + } + if (STLcdUpdateYMax < page * 8) { + break; + } + LCD_writeControlReg( 0xB0 | page); + + uint8_t col = STLcdUpdateXMin; + LCD_writeControlReg( 0x10 | (col >> 4)); + LCD_writeControlReg( 0x00 | (col & 0x0f)); + // LCD_writeControlReg(0xe0); + SPI_write( STLcdBuffer + LCD_PAGE_LEN * page + col, STLcdUpdateXMax - col); + } + STLcdUpdateXMin = LCD_WIDTH - 1; + STLcdUpdateXMax = 0; + STLcdUpdateYMin = LCD_HEIGHT-1; + STLcdUpdateYMax = 0; +} + // LCD State processing loop inline uint8_t LCD_scan() { - return 0; + STLcd_display(); + return 0; } @@ -409,49 +462,35 @@ void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t * // Only display if there are layers active if ( stack_args->numArgs > 0 ) { - // Set the color according to the "top-of-stack" layer - uint16_t layerIndex = stack_args->layers[0]; - FTM0_C0V = colors[ layerIndex ][0]; - FTM0_C1V = colors[ layerIndex ][1]; - FTM0_C2V = colors[ layerIndex ][2]; - - // Iterate through each of the pages - // XXX Many of the values here are hard-coded - // Eventually a proper font rendering engine should take care of things like this... -HaaTa - for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + // Set the color according to the "top-of-stack" layer + uint16_t layerIndex = stack_args->layers[0]; + FTM0_C0V = colors[ layerIndex ][0]; + FTM0_C1V = colors[ layerIndex ][1]; + FTM0_C2V = colors[ layerIndex ][2]; + + // Iterate through each of the pages + // XXX Many of the values here are hard-coded + // Eventually a proper font rendering engine should take care of things like this... -HaaTa + STLcd_clear(); + for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + { + uint8_t offset = 0; + // Write data + for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) { - // Set the register page - LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); - - // Set starting address - LCD_writeControlReg( 0x10 ); - LCD_writeControlReg( 0x00 ); - - // Write data - for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) - { - layerIndex = stack_args->layers[ layer ]; - - // Default to 0, if over 9 - if ( layerIndex > 9 ) - { - layerIndex = 0; - } - - // Write page of number to display - SPI_write( (uint8_t*)&numbers[ layerIndex ][ page * 32 ], 32 ); - } - - // Blank out rest of display - uint8_t data = 0; - for ( uint8_t c = 0; c < 4 - stack_args->numArgs; c++ ) - { - for ( uint8_t byte = 0; byte < 32; byte++ ) - { - SPI_write( &data, 1 ); - } - } + layerIndex = stack_args->layers[ layer ]; + + // Default to 0, if over 9 + if ( layerIndex > 9 ) + { + layerIndex = 0; + } + memcpy(STLcdBuffer + page * LCD_PAGE_LEN + offset, + &numbers[layerIndex][page * 32], + 32); + offset += 32; } + } } else { @@ -461,8 +500,7 @@ void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t * FTM0_C2V = STLcdBacklightBlue_define; // Write default image - for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) - LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); + memcpy(STLcdBuffer, STLcdDefaultImage, LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES); } } @@ -525,6 +563,80 @@ void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args LCD_layerStackExact_capability( state, stateType, (uint8_t*)&stack_args ); } +/*// Takes 1 8 bit charactor and 2 8 bit x-y coordinates +typedef struct LCD_charOut_args { + uint8_t charactor; + uint8_t x; + uint8_t y; +} LCD_charOut_args; +void LCD_charOut_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +{ + // Display capability name + if ( stateType == 0xFF && state == 0xFF ) + { + print("LCD_charOut_capability(charactor, x, y)"); + return; + } + + // Read arguments + LCD_charOut_args *out_args = (LCD_charOut_args*)args; + + #uint16_t layerIndex = stack_args->layers[0]; + #FTM0_C0V = colors[ layerIndex ][0]; + #FTM0_C1V = colors[ layerIndex ][1]; + #FTM0_C2V = colors[ layerIndex ][2]; + + // Iterate through each of the pages + // XXX Many of the values here are hard-coded + // Eventually a proper font rendering engine should take care of things like this... -HaaTa + for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + { + // Set the register page + LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); + + // Set starting address + LCD_writeControlReg( 0x10 ); + LCD_writeControlReg( 0x00 ); + + // Write data + for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) + { + layerIndex = stack_args->layers[ layer ]; + + // Default to 0, if over 9 + if ( layerIndex > 9 ) + { + layerIndex = 0; + } + + // Write page of number to display + SPI_write( (uint8_t*)&numbers[ layerIndex ][ page * 32 ], 32 ); + } + + // Blank out rest of display + uint8_t data = 0; + for ( uint8_t c = 0; c < 4 - stack_args->numArgs; c++ ) + { + for ( uint8_t byte = 0; byte < 32; byte++ ) + { + SPI_write( &data, 1 ); + } + } + } + } + else + { + // Set default backlight + FTM0_C0V = STLcdBacklightRed_define; + FTM0_C1V = STLcdBacklightGreen_define; + FTM0_C2V = STLcdBacklightBlue_define; + + // Write default image + for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); + } + }*/ + // ----- CLI Command Functions ----- @@ -536,9 +648,9 @@ void cliFunc_lcdInit( char* args ) void cliFunc_lcdTest( char* args ) { - // Write default image - for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) - LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); + // Write default image + memcpy(STLcdBuffer, STLcdDefaultImage, LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES); + STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); } void cliFunc_lcdCmd( char* args ) @@ -625,13 +737,7 @@ void cliFunc_lcdDisp( char* args ) if ( *arg1Ptr == '\0' ) return; uint8_t address = numToInt( arg1Ptr ); - - // Set the register page - LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); - - // Set starting address - LCD_writeControlReg( 0x10 | ( ( 0xF0 & address ) >> 4 ) ); - LCD_writeControlReg( 0x00 | ( 0x0F & address )); + uint8_t start = address; // Process all args for ( ;; ) @@ -644,9 +750,11 @@ void cliFunc_lcdDisp( char* args ) break; uint8_t value = numToInt( arg1Ptr ); - - // Write buffer to SPI - SPI_write( &value, 1 ); + STLcdBuffer[page * LCD_PAGE_LEN + address] = value; + address++; } + STLcd_updateBoundingBox(start, page * 8, address, (page + 1) * 8); } + + From 2eebde813126721b419d0cc5061138f9cd8580c8 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Fri, 6 May 2016 18:10:09 +0800 Subject: [PATCH 02/16] Made the LCD_scan non-blocking. --- Lib/delay.c | 30 +++++++ Lib/delay.h | 8 ++ Scan/STLcd/lcd_scan.c | 184 +++++++++++++++++++++++++++++++++++------- 3 files changed, 195 insertions(+), 27 deletions(-) diff --git a/Lib/delay.c b/Lib/delay.c index 1f1d5aff5..4b3d7f1d5 100644 --- a/Lib/delay.c +++ b/Lib/delay.c @@ -75,3 +75,33 @@ void delay(uint32_t ms) } } +uint8_t isTicksPassed(uint32_t startmillis, uint32_t startticks, + uint32_t ticks) +{ + // the milliseconds must be gotten before the ticks. + uint32_t currentmillis = systick_millis_count; + uint32_t currentticks = SYST_CVR; + if (currentmillis > startmillis + 1){ + return 1; + } + if (currentmillis == startmillis + 1){ + currentticks += (F_CPU / 1000); + } + else if (currentticks < startmillis) { + // the microseconds is reset after getting the ticks. + currentticks += (F_CPU / 1000); + } + if( startticks + ticks < currentticks ){ + return 1; + } + else{ + return 0; + } +} + +uint32_t ticks(void) +{ + return SYST_CVR; +} + + diff --git a/Lib/delay.h b/Lib/delay.h index 19f042588..3a663a63d 100644 --- a/Lib/delay.h +++ b/Lib/delay.h @@ -56,6 +56,11 @@ static inline uint32_t millis(void) return systick_millis_count; // single aligned 32 bit is atomic; } +static inline uint32_t microsToTicks(uint32_t) __attribute__((always_inline, unused)); +static inline uint32_t microsToTicks(uint32_t usec) +{ + return usec * (F_CPU / 1000000); +} static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused)); static inline void delayMicroseconds(uint32_t usec) @@ -84,3 +89,6 @@ uint32_t micros(void); void delay(uint32_t ms); +uint8_t isTicksPassed(uint32_t startmillis, uint32_t startticks, uint32_t ticks); + +uint32_t ticks(void); diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 5f3f8da1f..a3cb943f2 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -33,8 +33,6 @@ // Local Includes #include "lcd_scan.h" - - // ----- Defines ----- #define LCD_TOTAL_VISIBLE_PAGES 4 @@ -347,11 +345,18 @@ inline void LCD_setup() PORTC_PCR3 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(4); } +static uint32_t STLcdSyncStartMillis; +static uint32_t STLcdSyncStartTicks; + // Display buffer -static uint8_t STLcdBuffer[LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES]; -// Bounding box -static uint8_t STLcdUpdateXMin = LCD_WIDTH, STLcdUpdateXMax = 0; -static uint8_t STLcdUpdateYMin = LCD_HEIGHT, STLcdUpdateYMax = 0; +uint8_t STLcdBuffer[LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES]; +uint8_t STLcdSyncBuffer[LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES]; + + +// Bounding box. +static uint8_t STLcdUpdateXMin = LCD_WIDTH, STLcdUpdateXMax = 0, STLcdUpdateYMin = LCD_HEIGHT, STLcdUpdateYMax = 0; +static uint8_t STLcdSync = 0; +static uint8_t STLcdSyncPageMin, STLcdSyncPageMax, STLcdSyncColumnMin, STLcdSyncColumnMax; static void STLcd_updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) { if (xmin < STLcdUpdateXMin) STLcdUpdateXMin = xmin; @@ -365,36 +370,161 @@ void STLcd_clear(void) { STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); } -void STLcd_display(void) { - if(STLcdUpdateYMin > STLcdUpdateYMax) - return; - for(uint8_t page = STLcdUpdateYMin >> 3; page < STLcdUpdateYMax >> 3; page++) { - // check if this page is part of update - if ( STLcdUpdateYMin >= ((page + 1) * 8) ) { - continue; // nope, skip it! - } - if (STLcdUpdateYMax < page * 8) { +static uint8_t STLcdSyncPageCurrent; +static uint8_t *STLcdSyncBufferColumnCurrent; +static uint8_t *STLcdSyncBufferColumnMin, *STLcdSyncBufferColumnMax; +static uint32_t STLcdSyncStage; + +#define STAGE_WRITE_START 15 +#define STAGE_WRITE_END 20 + +// a non-blocking +void STLcd_sync(void) { + for(;;){ + switch(STLcdSyncStage){ + case 0: // Begin LCD_writeControlReg( 0xB0 | page); + if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + GPIOC_PCOR |= (1<<7); + STLcdSyncStage++; + case 1: // Begin SPI_write( &byte, 1); + if( !( SPI0_SR & SPI_SR_TFFF) ) + return; + SPI0_PUSHR = ( 0xB0 | STLcdSyncPageCurrent ) | SPI_PUSHR_PCS(1); + STLcdSyncStage++; + case 2: + if( !( SPI0_SR & SPI_SR_TCF ) ) + return; + SPI0_SR |= SPI_SR_TCF; + STLcdSyncStage++; // End SPI_write + case 3: + if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + STLcdSyncStage++; + STLcdSyncStartTicks = ticks(); + STLcdSyncStartMillis = millis(); + case 4: + // delayMicroseconds(10); + if(!isTicksPassed(STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10)) + return; + GPIOC_PSOR |= (1<<7); + STLcdSyncStage++; // End LCD_writeControlReg( 0xB0 | page); + case 5: // Begin LCD_writeControlReg( 0x10 | STLcdSyncColumnCurrent >> 4); + if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + GPIOC_PCOR |= (1<<7); + STLcdSyncStage++; + case 6: // Begin SPI_write( &byte, 1); + if( !( SPI0_SR & SPI_SR_TFFF) ) + return; + SPI0_PUSHR = ( 0x10 | STLcdSyncColumnMin >> 4 ) | SPI_PUSHR_PCS(1); + STLcdSyncStage++; + case 7: + if( !( SPI0_SR & SPI_SR_TCF ) ) + return; + SPI0_SR |= SPI_SR_TCF; + STLcdSyncStage++; // End SPI_write + case 8: + if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + STLcdSyncStage++; + STLcdSyncStartTicks = ticks(); + STLcdSyncStartMillis = millis(); + case 9: + // delayMicroseconds(10); + if(!isTicksPassed(STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10)) + return; + GPIOC_PSOR |= (1<<7); + STLcdSyncStage++; // End LCD_writeControlReg( 0x10 | STLcdSyncColumnCurrent >> 4); + case 10: // Begin LCD_writeControlReg( 0x00 | STLcdSyncColumnCurrent & 0x0f); + if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + GPIOC_PCOR |= (1<<7); + STLcdSyncStage++; + case 11: // Begin SPI_write( &byte, 1); + if( !( SPI0_SR & SPI_SR_TFFF) ) + return; + SPI0_PUSHR = ( 0x00 | (STLcdSyncColumnMin & 0x0f) ) | SPI_PUSHR_PCS(1); + STLcdSyncStage++; + case 12: + if( !( SPI0_SR & SPI_SR_TCF ) ) + return; + SPI0_SR |= SPI_SR_TCF; + STLcdSyncStage++; // End SPI_write + case 13: + if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + STLcdSyncStage++; + STLcdSyncStartTicks = ticks(); + STLcdSyncStartMillis = millis(); + case 14: + // delayMicroseconds(10); + if(!isTicksPassed(STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10)) + return; + GPIOC_PSOR |= (1<<7); + STLcdSyncStage++; // End LCD_writeControlReg( 0x00 | STLcdSyncColumnCurrent & 0x0f); + STLcdSyncBufferColumnCurrent = STLcdSyncBufferColumnMin; + case STAGE_WRITE_START: // Begin SPI_write( STLcdSyncBuffer + LCD_PAGE_LEN * STLcdSyncPageCurrent + STLcdSyncColumnMin, + // STLcdSyncColumnMax - STLcdSyncColumnMin); + if(STLcdSyncBufferColumnCurrent >= STLcdSyncBufferColumnMax){ // next page + STLcdSyncStage = 0; + STLcdSyncPageCurrent++; + if(STLcdSyncPageCurrent >= STLcdSyncPageMax){ // has finished + STLcdSync = 0; + return; + } + else{ + STLcdSyncBufferColumnMin += LCD_PAGE_LEN; + STLcdSyncBufferColumnMax += LCD_PAGE_LEN; + break; + } + } + STLcdSyncStage++; + case 16: + if( !( SPI0_SR & SPI_SR_TFFF) ) + return; + SPI0_PUSHR = ( *STLcdSyncBufferColumnCurrent ) | SPI_PUSHR_PCS(1); + STLcdSyncStage++; + case 17: + if( !( SPI0_SR & SPI_SR_TCF ) ) + return; + SPI0_SR |= SPI_SR_TCF; + STLcdSyncBufferColumnCurrent++; + STLcdSyncStage=STAGE_WRITE_START; // Loop back to STAGE_WRITE_START break; } - LCD_writeControlReg( 0xB0 | page); - - uint8_t col = STLcdUpdateXMin; - LCD_writeControlReg( 0x10 | (col >> 4)); - LCD_writeControlReg( 0x00 | (col & 0x0f)); - // LCD_writeControlReg(0xe0); - SPI_write( STLcdBuffer + LCD_PAGE_LEN * page + col, STLcdUpdateXMax - col); } - STLcdUpdateXMin = LCD_WIDTH - 1; - STLcdUpdateXMax = 0; - STLcdUpdateYMin = LCD_HEIGHT-1; - STLcdUpdateYMax = 0; + } // LCD State processing loop inline uint8_t LCD_scan() { - STLcd_display(); + if(STLcdSync){ + STLcd_sync(); + } + else{ + if(STLcdUpdateYMin >= STLcdUpdateYMax) + return 0; + STLcdSyncPageMin = STLcdUpdateYMin >> 3; + STLcdSyncPageMax = STLcdUpdateYMax >> 3; + STLcdSyncColumnMin = STLcdUpdateXMin; + STLcdSyncColumnMax = STLcdUpdateXMax; + STLcdSyncBufferColumnMin = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMin; + STLcdSyncBufferColumnMax = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMax; + memcpy(STLcdSyncBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, STLcdBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, + (STLcdSyncPageMax - STLcdSyncPageMin) * LCD_PAGE_LEN); + STLcdSync = 1; + STLcdSyncPageCurrent = STLcdSyncPageMin; + STLcdSyncStage = 0; + STLcd_sync(); + STLcdUpdateXMin = LCD_WIDTH - 1; + STLcdUpdateXMax = 0; + STLcdUpdateYMin = LCD_HEIGHT-1; + STLcdUpdateYMax = 0; + } + //STLcd_display(); return 0; } From 4748cb497515f64720a176f6050d676e1a6bc2b9 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Fri, 6 May 2016 18:29:18 +0800 Subject: [PATCH 03/16] Made the ticks test routine inline. Added a blocking version of the display sync function. --- Lib/delay.c | 31 ------------------------------- Lib/delay.h | 32 ++++++++++++++++++++++++++++++-- Scan/STLcd/lcd_scan.c | 20 ++++++++++++++++---- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/Lib/delay.c b/Lib/delay.c index 4b3d7f1d5..a4c1bff2d 100644 --- a/Lib/delay.c +++ b/Lib/delay.c @@ -74,34 +74,3 @@ void delay(uint32_t ms) yield(); } } - -uint8_t isTicksPassed(uint32_t startmillis, uint32_t startticks, - uint32_t ticks) -{ - // the milliseconds must be gotten before the ticks. - uint32_t currentmillis = systick_millis_count; - uint32_t currentticks = SYST_CVR; - if (currentmillis > startmillis + 1){ - return 1; - } - if (currentmillis == startmillis + 1){ - currentticks += (F_CPU / 1000); - } - else if (currentticks < startmillis) { - // the microseconds is reset after getting the ticks. - currentticks += (F_CPU / 1000); - } - if( startticks + ticks < currentticks ){ - return 1; - } - else{ - return 0; - } -} - -uint32_t ticks(void) -{ - return SYST_CVR; -} - - diff --git a/Lib/delay.h b/Lib/delay.h index 3a663a63d..f92a0e84b 100644 --- a/Lib/delay.h +++ b/Lib/delay.h @@ -34,6 +34,7 @@ // ----- System Includes ----- #include +#include "mk20dx.h" @@ -89,6 +90,33 @@ uint32_t micros(void); void delay(uint32_t ms); -uint8_t isTicksPassed(uint32_t startmillis, uint32_t startticks, uint32_t ticks); +static inline uint8_t isTicksPassed(uint32_t, uint32_t, uint32_t) __attribute__((always_inline, unused)); +static inline uint8_t isTicksPassed(uint32_t startmillis, uint32_t startticks, + uint32_t ticks) +{ + // the milliseconds must be gotten before the ticks. + uint32_t currentmillis = systick_millis_count; + uint32_t currentticks = SYST_CVR; + if (currentmillis > startmillis + 1){ + return 1; + } + if (currentmillis == startmillis + 1){ + currentticks += (F_CPU / 1000); + } + else if (currentticks < startmillis) { + // the microseconds is reset after getting the ticks. + currentticks += (F_CPU / 1000); + } + if( startticks + ticks < currentticks ){ + return 1; + } + else{ + return 0; + } +} -uint32_t ticks(void); +static inline uint32_t ticks(void) __attribute__((always_inline, unused)); +static inline uint32_t ticks(void) +{ + return SYST_CVR; +} diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index a3cb943f2..03572a907 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -378,11 +378,22 @@ static uint32_t STLcdSyncStage; #define STAGE_WRITE_START 15 #define STAGE_WRITE_END 20 +void STLcd_blockingSync(void) { + for(;STLcdSyncPageCurrent < STLcdSyncPageMax; + STLcdSyncPageCurrent++, STLcdSyncBufferColumnMin += LCD_PAGE_LEN) + { + LCD_writeControlReg(0xB0 | STLcdSyncPageCurrent); + LCD_writeControlReg(0x10 | STLcdSyncColumnMin >> 4); + LCD_writeControlReg(0x10 | (STLcdSyncColumnMin & 0x0f)); + SPI_write(STLcdSyncBufferColumnMin, STLcdSyncColumnMax - STLcdSyncColumnMin); + } +} + // a non-blocking void STLcd_sync(void) { for(;;){ switch(STLcdSyncStage){ - case 0: // Begin LCD_writeControlReg( 0xB0 | page); + case 0: // Begin LCD_writeControlReg( 0xB0 | STLcdSyncPageCurrent); if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); return; GPIOC_PCOR |= (1<<7); @@ -409,7 +420,7 @@ void STLcd_sync(void) { return; GPIOC_PSOR |= (1<<7); STLcdSyncStage++; // End LCD_writeControlReg( 0xB0 | page); - case 5: // Begin LCD_writeControlReg( 0x10 | STLcdSyncColumnCurrent >> 4); + case 5: // Begin LCD_writeControlReg( 0x10 | STLcdSyncColumnMin >> 4); if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); return; GPIOC_PCOR |= (1<<7); @@ -462,10 +473,11 @@ void STLcd_sync(void) { if(!isTicksPassed(STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10)) return; GPIOC_PSOR |= (1<<7); - STLcdSyncStage++; // End LCD_writeControlReg( 0x00 | STLcdSyncColumnCurrent & 0x0f); + STLcdSyncStage++; // End LCD_writeControlReg( 0x00 | (STLcdSyncColumnCurrent & 0x0f)); STLcdSyncBufferColumnCurrent = STLcdSyncBufferColumnMin; - case STAGE_WRITE_START: // Begin SPI_write( STLcdSyncBuffer + LCD_PAGE_LEN * STLcdSyncPageCurrent + STLcdSyncColumnMin, + // Begin SPI_write( STLcdSyncBufferColumnMin, // STLcdSyncColumnMax - STLcdSyncColumnMin); + case STAGE_WRITE_START: if(STLcdSyncBufferColumnCurrent >= STLcdSyncBufferColumnMax){ // next page STLcdSyncStage = 0; STLcdSyncPageCurrent++; From 358372e52c6e04e97985df4ae2313ee638b4fe5c Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Fri, 6 May 2016 21:28:57 +0800 Subject: [PATCH 04/16] Fixed the default image does not display error. --- Scan/STLcd/lcd_scan.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 03572a907..dd3051b86 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -643,6 +643,7 @@ void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t * // Write default image memcpy(STLcdBuffer, STLcdDefaultImage, LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES); + STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); } } From a448e8e1fcd368d3f7738cb9959438a6eae18e12 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Fri, 6 May 2016 22:19:25 +0800 Subject: [PATCH 05/16] Fixed overflow when the layer stack is empty. --- Scan/STLcd/lcd_scan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index dd3051b86..1cc89734c 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -666,7 +666,8 @@ void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args // Ignore if the stack size hasn't changed and the top of the stack is the same if ( macroLayerIndexStackSize == LCD_layerStack_prevSize - && macroLayerIndexStack[macroLayerIndexStackSize - 1] == LCD_layerStack_prevTop ) + && (macroLayerIndexStackSize == 0 || + macroLayerIndexStack[macroLayerIndexStackSize - 1] == LCD_layerStack_prevTop )) { return; } From ac31b25c0d7fc54967724ba350e2aabf42cc906a Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Fri, 6 May 2016 23:02:53 +0800 Subject: [PATCH 06/16] Fixed the wrong start pointer in the sync loop. --- Scan/STLcd/lcd_scan.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 1cc89734c..6fd1ca87b 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -389,7 +389,7 @@ void STLcd_blockingSync(void) { } } -// a non-blocking +// a non-blocking sync function void STLcd_sync(void) { for(;;){ switch(STLcdSyncStage){ @@ -521,22 +521,27 @@ inline uint8_t LCD_scan() return 0; STLcdSyncPageMin = STLcdUpdateYMin >> 3; STLcdSyncPageMax = STLcdUpdateYMax >> 3; + STLcdSyncPageCurrent = STLcdSyncPageMin; + STLcdSyncColumnMin = STLcdUpdateXMin; STLcdSyncColumnMax = STLcdUpdateXMax; + STLcdSyncBufferColumnMin = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMin; STLcdSyncBufferColumnMax = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMax; + memcpy(STLcdSyncBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, STLcdBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, (STLcdSyncPageMax - STLcdSyncPageMin) * LCD_PAGE_LEN); + STLcdSync = 1; - STLcdSyncPageCurrent = STLcdSyncPageMin; STLcdSyncStage = 0; + //STLcd_syncBlocking(); STLcd_sync(); + STLcdUpdateXMin = LCD_WIDTH - 1; STLcdUpdateXMax = 0; STLcdUpdateYMin = LCD_HEIGHT-1; STLcdUpdateYMax = 0; } - //STLcd_display(); return 0; } From f57e1c86e6b2539f9274d4a3b24ac4c3adc47a54 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Fri, 6 May 2016 23:38:30 +0800 Subject: [PATCH 07/16] Added the license for the font. --- Scan/STLcd/4x6FontLicense | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Scan/STLcd/4x6FontLicense diff --git a/Scan/STLcd/4x6FontLicense b/Scan/STLcd/4x6FontLicense new file mode 100644 index 000000000..c6cbef1a2 --- /dev/null +++ b/Scan/STLcd/4x6FontLicense @@ -0,0 +1,27 @@ +** Copyright 1999 Brian J. Swetland +** Copyright 1999 Vassilii Khachaturov +** Portions (of vt100.c/vt100.h) copyright Dan Marks +** +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions, and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions, and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the authors may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file From 08a64569d7f59f5a2977e368dbd1bab6730a93a4 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Sun, 8 May 2016 00:26:37 +0800 Subject: [PATCH 08/16] Added a minimal TTY to the LCD. --- Scan/STLcd/bitmapfont2Struct.py | 6 +- Scan/STLcd/capabilities.kll | 6 +- Scan/STLcd/lcd_scan.c | 211 ++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+), 6 deletions(-) diff --git a/Scan/STLcd/bitmapfont2Struct.py b/Scan/STLcd/bitmapfont2Struct.py index 1d7eed612..762cdc49f 100755 --- a/Scan/STLcd/bitmapfont2Struct.py +++ b/Scan/STLcd/bitmapfont2Struct.py @@ -37,7 +37,7 @@ class STLcdFont: def __init__( self, glyph_width, glyph_height, num_glyphs): self.glyph_height = glyph_height self.glyph_width = glyph_width - self.glyph_size = (glyph_height * glyph_width + 7) // 8 + self.glyph_size = (glyph_height + 7) // 8 * glyph_width self.num_fixed_sizes = 1 self.availible_sizes = [Bitmap_Size(self.glyph_height, self.glyph_width)] self.num_glyphs = num_glyphs @@ -48,10 +48,10 @@ def __init__( self, glyph_width, glyph_height, num_glyphs): def setpixel( self, index, x, y ): newy = self.glyph_height - y - 1 # Calculate which byte - byte = (x * self.glyph_height + newy) // 8 + byte = newy // 8 * glyph_width + x # Calculate which bit - bit = (x * self.glyph_height + newy) % 8 + bit = newy % 8 # Set pixel bit self.glyph_data[ index ][ byte ] |= (1 << bit) diff --git a/Scan/STLcd/capabilities.kll b/Scan/STLcd/capabilities.kll index f22b511cc..34de5fe2a 100644 --- a/Scan/STLcd/capabilities.kll +++ b/Scan/STLcd/capabilities.kll @@ -68,12 +68,12 @@ STLcdSmallFontWidth => STLcdSmallFontWidth_define; STLcdSmallFontHeight => STLcdSmallFontHeight_define; STLcdSmallFontSize => STLcdSmallFontSize_define; -STLcdSmallFont = "0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xe8, 0x03, 0xbe, 0xef, 0x03, 0x00, 0x00, 0x00, 0x80, 0x0e, 0x00, 0x30, 0x00, 0x03, 0x3e, 0xe5, 0x03, 0x94, 0x8f, 0x02, 0x24, 0x22, 0x01, 0xbc, 0xee, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x27, 0x02, 0x22, 0x07, 0x00, 0x28, 0x84, 0x02, 0x08, 0x87, 0x00, 0x02, 0x01, 0x00, 0x08, 0x82, 0x00, 0x80, 0x00, 0x00, 0x06, 0x02, 0x03, 0x9e, 0xc8, 0x03, 0x90, 0x0f, 0x00, 0xae, 0xaa, 0x03, 0xa2, 0xea, 0x03, 0x38, 0xe2, 0x03, 0xba, 0xea, 0x02, 0xbe, 0xea, 0x02, 0x26, 0x0a, 0x03, 0xbe, 0xea, 0x03, 0xba, 0xea, 0x03, 0x00, 0x05, 0x00, 0x02, 0x05, 0x00, 0x08, 0x25, 0x02, 0x14, 0x45, 0x01, 0x22, 0x85, 0x00, 0xa0, 0x0a, 0x03, 0x9c, 0xaa, 0x01, 0x1e, 0xea, 0x01, 0xbe, 0x4a, 0x01, 0x9c, 0x28, 0x02, 0xbe, 0xc8, 0x01, 0xbe, 0xaa, 0x02, 0x3e, 0x8a, 0x02, 0x9c, 0xea, 0x02, 0x3e, 0xe2, 0x03, 0xa2, 0x2f, 0x02, 0x84, 0xc0, 0x03, 0x3e, 0x62, 0x03, 0xbe, 0x20, 0x00, 0x3e, 0xe6, 0x03, 0x3e, 0xe8, 0x03, 0x9c, 0xc8, 0x01, 0x3e, 0x0a, 0x01, 0x9c, 0xe9, 0x01, 0x3e, 0xab, 0x01, 0x92, 0x4a, 0x02, 0xa0, 0x0f, 0x02, 0xbc, 0xe0, 0x03, 0xb8, 0x81, 0x03, 0x3e, 0xe3, 0x03, 0x36, 0x62, 0x03, 0xb0, 0x03, 0x03, 0xa6, 0x2a, 0x03, 0xbe, 0x28, 0x02, 0x10, 0x42, 0x00, 0xa2, 0xe8, 0x03, 0x10, 0x08, 0x01, 0x82, 0x20, 0x00, 0x20, 0x04, 0x00, 0x96, 0xe6, 0x00, 0xbe, 0xc4, 0x00, 0x8c, 0x24, 0x01, 0x8c, 0xe4, 0x03, 0x8c, 0xa5, 0x01, 0x88, 0x87, 0x02, 0x4c, 0xe5, 0x01, 0x3e, 0xe4, 0x00, 0x80, 0x0b, 0x00, 0x42, 0xe0, 0x02, 0x3e, 0x23, 0x01, 0xa2, 0x2f, 0x00, 0x1e, 0xe7, 0x01, 0x1e, 0xe4, 0x00, 0x8c, 0xc4, 0x00, 0x9f, 0xc4, 0x00, 0x8c, 0xf4, 0x01, 0x0e, 0x04, 0x01, 0x8a, 0x47, 0x01, 0x90, 0x2f, 0x01, 0x9c, 0xe0, 0x01, 0x9c, 0xc1, 0x01, 0x9e, 0xe3, 0x01, 0x12, 0x23, 0x01, 0x58, 0xe1, 0x01, 0x96, 0xa7, 0x01, 0x88, 0x2d, 0x02, 0x80, 0x0d, 0x00, 0xa2, 0x8d, 0x00, 0x10, 0x0c, 0x02, 0xbe, 0xef, 0x03"; +STLcdSmallFont = "0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x3e, 0x14, 0x3e, 0x00, 0x14, 0x3e, 0x28, 0x00, 0x24, 0x08, 0x12, 0x00, 0x3c, 0x3a, 0x0e, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x00, 0x22, 0x1c, 0x00, 0x00, 0x28, 0x10, 0x28, 0x00, 0x08, 0x1c, 0x08, 0x00, 0x02, 0x04, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x02, 0x00, 0x00, 0x06, 0x08, 0x30, 0x00, 0x1e, 0x22, 0x3c, 0x00, 0x10, 0x3e, 0x00, 0x00, 0x2e, 0x2a, 0x3a, 0x00, 0x22, 0x2a, 0x3e, 0x00, 0x38, 0x08, 0x3e, 0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3e, 0x2a, 0x2e, 0x00, 0x26, 0x28, 0x30, 0x00, 0x3e, 0x2a, 0x3e, 0x00, 0x3a, 0x2a, 0x3e, 0x00, 0x00, 0x14, 0x00, 0x00, 0x02, 0x14, 0x00, 0x00, 0x08, 0x14, 0x22, 0x00, 0x14, 0x14, 0x14, 0x00, 0x22, 0x14, 0x08, 0x00, 0x20, 0x2a, 0x30, 0x00, 0x1c, 0x2a, 0x1a, 0x00, 0x1e, 0x28, 0x1e, 0x00, 0x3e, 0x2a, 0x14, 0x00, 0x1c, 0x22, 0x22, 0x00, 0x3e, 0x22, 0x1c, 0x00, 0x3e, 0x2a, 0x2a, 0x00, 0x3e, 0x28, 0x28, 0x00, 0x1c, 0x2a, 0x2e, 0x00, 0x3e, 0x08, 0x3e, 0x00, 0x22, 0x3e, 0x22, 0x00, 0x04, 0x02, 0x3c, 0x00, 0x3e, 0x08, 0x36, 0x00, 0x3e, 0x02, 0x02, 0x00, 0x3e, 0x18, 0x3e, 0x00, 0x3e, 0x20, 0x3e, 0x00, 0x1c, 0x22, 0x1c, 0x00, 0x3e, 0x28, 0x10, 0x00, 0x1c, 0x26, 0x1e, 0x00, 0x3e, 0x2c, 0x1a, 0x00, 0x12, 0x2a, 0x24, 0x00, 0x20, 0x3e, 0x20, 0x00, 0x3c, 0x02, 0x3e, 0x00, 0x38, 0x06, 0x38, 0x00, 0x3e, 0x0c, 0x3e, 0x00, 0x36, 0x08, 0x36, 0x00, 0x30, 0x0e, 0x30, 0x00, 0x26, 0x2a, 0x32, 0x00, 0x3e, 0x22, 0x22, 0x00, 0x10, 0x08, 0x04, 0x00, 0x22, 0x22, 0x3e, 0x00, 0x10, 0x20, 0x10, 0x00, 0x02, 0x02, 0x02, 0x00, 0x20, 0x10, 0x00, 0x00, 0x16, 0x1a, 0x0e, 0x00, 0x3e, 0x12, 0x0c, 0x00, 0x0c, 0x12, 0x12, 0x00, 0x0c, 0x12, 0x3e, 0x00, 0x0c, 0x16, 0x1a, 0x00, 0x08, 0x1e, 0x28, 0x00, 0x0c, 0x15, 0x1e, 0x00, 0x3e, 0x10, 0x0e, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x02, 0x01, 0x2e, 0x00, 0x3e, 0x0c, 0x12, 0x00, 0x22, 0x3e, 0x02, 0x00, 0x1e, 0x1c, 0x1e, 0x00, 0x1e, 0x10, 0x0e, 0x00, 0x0c, 0x12, 0x0c, 0x00, 0x1f, 0x12, 0x0c, 0x00, 0x0c, 0x12, 0x1f, 0x00, 0x0e, 0x10, 0x10, 0x00, 0x0a, 0x1e, 0x14, 0x00, 0x10, 0x3e, 0x12, 0x00, 0x1c, 0x02, 0x1e, 0x00, 0x1c, 0x06, 0x1c, 0x00, 0x1e, 0x0e, 0x1e, 0x00, 0x12, 0x0c, 0x12, 0x00, 0x18, 0x05, 0x1e, 0x00, 0x16, 0x1e, 0x1a, 0x00, 0x08, 0x36, 0x22, 0x00, 0x00, 0x36, 0x00, 0x00, 0x22, 0x36, 0x08, 0x00, 0x10, 0x30, 0x20, 0x00, 0x3e, 0x3e, 0x3e, 0x00,"; STLcdSmallFontWidth = 4; STLcdSmallFontHeight = 6; -STLcdSmallFontSize = 3; +STLcdSmallFontSize = 4; -# LCDCharOut => LCD_charOut_capability(charactor : 1, x : 1, y : 1) +# TTYOutputChar => TTY_outputChar_capability(charactor : 1); # Layer Status Display diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 6fd1ca87b..d27264155 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -59,6 +59,7 @@ void cliFunc_lcdColor( char* args ); void cliFunc_lcdDisp ( char* args ); void cliFunc_lcdInit ( char* args ); void cliFunc_lcdTest ( char* args ); +void cliFunc_ttyPrint( char* args ); @@ -87,6 +88,7 @@ CLIDict_Entry( lcdColor, "Set backlight color. 3 16-bit numbers: R G B. i.e. CLIDict_Entry( lcdDisp, "Write byte(s) to given page starting at given address. i.e. 0x1 0x5 0xFF 0x00" ); CLIDict_Entry( lcdInit, "Re-initialize the LCD display." ); CLIDict_Entry( lcdTest, "Test out the LCD display." ); +CLIDict_Entry( ttyPrint, "Output text to the LCD." ); CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { CLIDict_Item( lcdCmd ), @@ -94,6 +96,7 @@ CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { CLIDict_Item( lcdDisp ), CLIDict_Item( lcdInit ), CLIDict_Item( lcdTest ), + CLIDict_Item( ttyPrint ), { 0, 0, 0 } // Null entry for dictionary end }; @@ -786,6 +789,195 @@ void LCD_charOut_capability( uint8_t state, uint8_t stateType, uint8_t *args ) } }*/ +static uint8_t STLcdDrawMasks[8][8] = { + {0x00, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}, + {0x80, 0xbf, 0x9f, 0x8f, 0x87, 0x83, 0x81, 0x80}, + {0xc0, 0xdf, 0xcf, 0xc7, 0xc3, 0xc1, 0xc0, 0xc0}, + {0xe0, 0xef, 0xe7, 0xe3, 0xe1, 0xe0, 0xe0, 0xe0}, + {0xf0, 0xf7, 0xf3, 0xf1, 0xf0, 0xf0, 0xf0, 0xf0}, + {0xf8, 0xfb, 0xf9, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8}, + {0xfc, 0xfd, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc}, + {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe} +}; + +void STLcd_drawGlyph(uint8_t index, uint8_t x, uint8_t y) +{ + uint8_t glyphpages = (STLcdSmallFontHeight + 7)/8; + const uint8_t *glyph = STLcdSmallFont + index * STLcdSmallFontSize; + uint8_t *buffer = STLcdBuffer + (y >> 3) * LCD_PAGE_LEN + x; + uint8_t maxcolumn = (x + STLcdSmallFontWidth <= LCD_WIDTH) ? STLcdSmallFontWidth : (LCD_WIDTH - x); + if(y & 0x07){ + uint8_t highbits = 7&0x07; + uint8_t remainheight = (y + STLcdSmallFontHeight <= LCD_HEIGHT) ? STLcdSmallFontHeight : (LCD_HEIGHT - y); + + uint8_t mask = STLcdDrawMasks[highbits][(remainheight > 7) ? 0 : remainheight]; + for(uint8_t column = 0; column < maxcolumn; column++){ + buffer[column] = (buffer[column]&mask) + | (glyph[column]&(~mask)); + } + remainheight -= 8 - highbits; + for(uint8_t page = 0; remainheight > 7; page++, remainheight-=8){ + for(uint8_t column = 0; column < maxcolumn; column++){ + buffer[(page + 1) * LCD_PAGE_LEN + column] = + (glyph[page * STLcdSmallFontWidth + column] << ( 8 - highbits)) + | (glyph[(page + 1) * STLcdSmallFontWidth + column] >> (highbits)); + } + } + if(remainheight > 0){ + mask = STLcdDrawMasks[0][remainheight]; + uint8_t page = glyphpages - 1; + for(uint8_t column = 0; column < maxcolumn; column++){ + buffer[page * LCD_PAGE_LEN + column] = + (glyph[page * STLcdSmallFontWidth + column] << ( 8 - highbits)) + | (buffer[page * LCD_PAGE_LEN + column] & mask); + } + } + } + else{ + if(STLcdSmallFontHeight & 0x07){ + for(uint8_t page = 0; page < glyphpages - 1; page++){ + memcpy(buffer + page * LCD_PAGE_LEN, + glyph + page * STLcdSmallFontWidth, + maxcolumn); + } + uint8_t remainheight = STLcdSmallFontHeight & 0x07; + for(uint8_t column = 0; column < maxcolumn; column++){ + uint16_t destindex = (glyphpages - 1) * LCD_PAGE_LEN + column; + buffer[destindex] = (buffer[destindex] & STLcdDrawMasks[0][remainheight]) + | (glyph[(glyphpages - 1) * STLcdSmallFontWidth + column]); + + } + } + else{ + for(uint8_t page = 0; page < glyphpages; page++){ + memcpy(buffer + page * LCD_PAGE_LEN, + glyph + page * STLcdSmallFontWidth, + maxcolumn); + } + } + } + +} + +static uint8_t TTYInitialized = 0; +static uint8_t TTYLineHeight = 0; +static uint8_t TTYLines = 0; +static uint8_t TTYColumns = 0; +static uint8_t TTYCurrentLine = 0; +static uint8_t TTYCurrentColumn = 0; + +void TTY_initialized(void) +{ + LCD_clear(); + TTYInitialized = 1; + TTYLineHeight = STLcdSmallFontHeight; + TTYLines = LCD_HEIGHT / TTYLineHeight; + TTYColumns = LCD_WIDTH / STLcdSmallFontWidth; + TTYCurrentLine = 0; + TTYCurrentColumn = 0; +} + +void TTY_exit(void) +{ + LCD_clear(); + TTYInitialized = 0; +} + +void TTY_drawGlyph(uint8_t index) +{ + STLcd_drawGlyph(index, TTYCurrentColumn * STLcdSmallFontWidth, TTYCurrentLine * TTYLineHeight); + STLcd_updateBoundingBox(TTYCurrentColumn * STLcdSmallFontWidth, + TTYCurrentLine * TTYLineHeight, + (TTYCurrentColumn + 1) * STLcdSmallFontWidth, + (TTYCurrentLine + 1) * TTYLineHeight); +} + +void TTY_scrollUp(uint8_t lines) +{ + uint8_t scrollpixels = lines * STLcdSmallFontHeight; + uint8_t scrollshiftbits = scrollpixels & 0x07; + uint8_t scrollpages = scrollpixels >> 3; + if(scrollshiftbits == 0){ + if(scrollpages == 0){ + return; + } + memcpy(STLcdBuffer, + STLcdBuffer + scrollpages * LCD_PAGE_LEN, + LCD_PAGE_LEN * (LCD_TOTAL_VISIBLE_PAGES - scrollpages)); + memset(STLcdBuffer + LCD_PAGE_LEN * (LCD_TOTAL_VISIBLE_PAGES - scrollpages), + 0, + scrollpages * LCD_PAGE_LEN); + } + else{ + for(uint8_t destpage = 0, srcpage = scrollpages + 1; + srcpage < LCD_TOTAL_VISIBLE_PAGES; + destpage++, srcpage++) + { + for(uint8_t column = 0; column < LCD_PAGE_LEN; column++){ + STLcdBuffer[destpage * LCD_PAGE_LEN] = + (STLcdBuffer[destpage * LCD_PAGE_LEN + column] << scrollshiftbits) | + (STLcdBuffer[srcpage * LCD_PAGE_LEN + column] >> (8 - scrollshiftbits)); + } + } + for(uint8_t column = 0; column < LCD_PAGE_LEN; column++){ // last non-empty page + STLcdBuffer[(LCD_TOTAL_VISIBLE_PAGES - scrollpages - 1) * LCD_PAGE_LEN + column] <<= scrollshiftbits; + } + if(scrollpages > 0) // have empty pages + memset(STLcdBuffer + (LCD_TOTAL_VISIBLE_PAGES - scrollpages) * LCD_PAGE_LEN, + 0, + scrollpages * LCD_PAGE_LEN); + } + STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); +} + +void TTY_newLine(void) +{ + if(TTYCurrentLine < TTYLines - 1){ + TTYCurrentLine++; + TTYCurrentColumn = 0; + } + else{ + TTY_scrollUp(1); + TTYCurrentColumn = 0; + } + +} + +void TTY_outputChar(uint8_t c) +{ + + switch(c) + { + case 0x8: // \b + if(TTYCurrentColumn){ + TTYCurrentColumn--; + TTY_drawGlyph(0x20); + } + break; + case 0x9: // \t + TTYCurrentColumn = (TTYCurrentColumn & 0xfc) + 4; + if(TTYCurrentColumn >= TTYColumns){ + TTY_newLine(); + } + break; + case 0x0a: // \n + TTY_newLine(); + break; + case 0x0c: // \f + LCD_clear(); + TTYCurrentColumn = 0; + TTYCurrentLine = 0; + break; + default: + TTY_drawGlyph(c); + TTYCurrentColumn++; + if(TTYCurrentColumn >= TTYColumns){ + TTY_newLine(); + } + break; + } +} + // ----- CLI Command Functions ----- @@ -905,5 +1097,24 @@ void cliFunc_lcdDisp( char* args ) STLcd_updateBoundingBox(start, page * 8, address, (page + 1) * 8); } +void cliFunc_ttyPrint( char* args ) +{ + char* curArgs; + char* arg1Ptr; + char* arg2Ptr = args; + // Process all args + for ( ;; ) + { + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + break; + + uint8_t value = numToInt( arg1Ptr ); + TTY_outputChar(value); + } +} From 8a6a274ac25008cff58ff15a1e41c4d4b3566204 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Sun, 8 May 2016 21:21:29 +0800 Subject: [PATCH 09/16] Added cli commands for text and fixed lots of bugs 1. Wrong page numbers when the max y of the bounding box is not a multiplier of 8. 2. The LCD's coordinate system has a reversed y. Fixed nearly all the tty funcions. 3. The clear screen function changed to the STLcd_clear in the TTY APIs. 4. Added lcdTextOut and ttyScrollUp cli commands. --- Scan/STLcd/bitmapfont2Struct.py | 1 + Scan/STLcd/lcd_scan.c | 235 ++++++++++++++++++++++++++------ 2 files changed, 197 insertions(+), 39 deletions(-) diff --git a/Scan/STLcd/bitmapfont2Struct.py b/Scan/STLcd/bitmapfont2Struct.py index 762cdc49f..37ff4ee0c 100755 --- a/Scan/STLcd/bitmapfont2Struct.py +++ b/Scan/STLcd/bitmapfont2Struct.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # Copyright (C) 2015 by Jacob Alexander +# Copyright (C) 2016 by Cui Yuting # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index d27264155..886df50bc 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -59,7 +59,10 @@ void cliFunc_lcdColor( char* args ); void cliFunc_lcdDisp ( char* args ); void cliFunc_lcdInit ( char* args ); void cliFunc_lcdTest ( char* args ); +void cliFunc_lcdTextOut ( char* args); void cliFunc_ttyPrint( char* args ); +void cliFunc_ttyScrollUp( char* args ); + @@ -88,7 +91,9 @@ CLIDict_Entry( lcdColor, "Set backlight color. 3 16-bit numbers: R G B. i.e. CLIDict_Entry( lcdDisp, "Write byte(s) to given page starting at given address. i.e. 0x1 0x5 0xFF 0x00" ); CLIDict_Entry( lcdInit, "Re-initialize the LCD display." ); CLIDict_Entry( lcdTest, "Test out the LCD display." ); +CLIDict_Entry( lcdTextOut, "Output text to the LCD at the given x-y coordinate."); CLIDict_Entry( ttyPrint, "Output text to the LCD." ); +CLIDict_Entry( ttyScrollUp, "Scroll up given lines on the LCD." ); CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { CLIDict_Item( lcdCmd ), @@ -96,7 +101,9 @@ CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { CLIDict_Item( lcdDisp ), CLIDict_Item( lcdInit ), CLIDict_Item( lcdTest ), + CLIDict_Item( lcdTextOut), CLIDict_Item( ttyPrint ), + CLIDict_Item( ttyScrollUp ), { 0, 0, 0 } // Null entry for dictionary end }; @@ -522,8 +529,17 @@ inline uint8_t LCD_scan() else{ if(STLcdUpdateYMin >= STLcdUpdateYMax) return 0; + print(NL); + print("Syncing X from "); + printInt8(STLcdUpdateXMin); + print(" to "); + printInt8(STLcdUpdateXMax); + print(" Y from "); + printInt8(STLcdUpdateYMin); + print(" to "); + printInt8(STLcdUpdateYMax); STLcdSyncPageMin = STLcdUpdateYMin >> 3; - STLcdSyncPageMax = STLcdUpdateYMax >> 3; + STLcdSyncPageMax = (STLcdUpdateYMax + 7) >> 3; STLcdSyncPageCurrent = STLcdSyncPageMin; STLcdSyncColumnMin = STLcdUpdateXMin; @@ -531,6 +547,11 @@ inline uint8_t LCD_scan() STLcdSyncBufferColumnMin = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMin; STLcdSyncBufferColumnMax = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMax; + print("\tPage from"); + printInt8(STLcdSyncPageMin); + print(" to "); + printInt8(STLcdSyncPageMax); + print(NL); memcpy(STLcdSyncBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, STLcdBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, (STLcdSyncPageMax - STLcdSyncPageMin) * LCD_PAGE_LEN); @@ -790,14 +811,14 @@ void LCD_charOut_capability( uint8_t state, uint8_t stateType, uint8_t *args ) }*/ static uint8_t STLcdDrawMasks[8][8] = { - {0x00, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01}, - {0x80, 0xbf, 0x9f, 0x8f, 0x87, 0x83, 0x81, 0x80}, - {0xc0, 0xdf, 0xcf, 0xc7, 0xc3, 0xc1, 0xc0, 0xc0}, - {0xe0, 0xef, 0xe7, 0xe3, 0xe1, 0xe0, 0xe0, 0xe0}, - {0xf0, 0xf7, 0xf3, 0xf1, 0xf0, 0xf0, 0xf0, 0xf0}, - {0xf8, 0xfb, 0xf9, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8}, - {0xfc, 0xfd, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc}, - {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe} + {0x00, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80}, + {0x01, 0xfd, 0xf9, 0xf1, 0xe1, 0xc1, 0x81, 0x01}, + {0x03, 0xfb, 0xf3, 0xe3, 0xc3, 0x83, 0x03, 0x03}, + {0x07, 0xf7, 0xe7, 0xc7, 0x87, 0x07, 0x07, 0x07}, + {0x0f, 0xef, 0xcf, 0x8f, 0x0f, 0x0f, 0x0f, 0x0f}, + {0x1f, 0xdf, 0x9f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, + {0x3f, 0xbf, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f}, + {0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f} }; void STLcd_drawGlyph(uint8_t index, uint8_t x, uint8_t y) @@ -806,32 +827,88 @@ void STLcd_drawGlyph(uint8_t index, uint8_t x, uint8_t y) const uint8_t *glyph = STLcdSmallFont + index * STLcdSmallFontSize; uint8_t *buffer = STLcdBuffer + (y >> 3) * LCD_PAGE_LEN + x; uint8_t maxcolumn = (x + STLcdSmallFontWidth <= LCD_WIDTH) ? STLcdSmallFontWidth : (LCD_WIDTH - x); + print(NL); + print("buffer index: "); + printInt16((y >> 3) * LCD_PAGE_LEN + x); + print("index: "); + printInt8(index); + print("\tx: "); + printInt8(x); + print("\ty: "); + printInt8(y); + print(NL); + print("glyphpages: "); + printInt8(glyphpages); + print("\tmaxcolumn: "); + printInt8(maxcolumn); + print(NL); + print("glyphdata: "); + print(NL); + for(uint8_t page = 0; page < glyphpages; page++){ + for(uint8_t column = 0; column < maxcolumn; column++){ + printHex(glyph[page * STLcdSmallFontWidth + column]); + print(","); + } + print(NL); + } if(y & 0x07){ - uint8_t highbits = 7&0x07; + uint8_t highbits = y&0x07; uint8_t remainheight = (y + STLcdSmallFontHeight <= LCD_HEIGHT) ? STLcdSmallFontHeight : (LCD_HEIGHT - y); uint8_t mask = STLcdDrawMasks[highbits][(remainheight > 7) ? 0 : remainheight]; + print("highbits: "); + printInt8(highbits); + print("\tremainheight: "); + printInt8(remainheight); + print("\tmask: "); + printHex(mask); + print(NL); for(uint8_t column = 0; column < maxcolumn; column++){ + printHex(buffer[column]&mask); + print("|"); + printHex(glyph[column] << highbits); + print(","); buffer[column] = (buffer[column]&mask) - | (glyph[column]&(~mask)); + | (glyph[column] << highbits); } + print(NL); remainheight -= 8 - highbits; + print("remainheight: "); + printInt8(remainheight); + print(NL); for(uint8_t page = 0; remainheight > 7; page++, remainheight-=8){ for(uint8_t column = 0; column < maxcolumn; column++){ + printHex(glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)); + print("|"); + printHex(glyph[(page + 1) * STLcdSmallFontWidth + column] << highbits); + print(","); buffer[(page + 1) * LCD_PAGE_LEN + column] = - (glyph[page * STLcdSmallFontWidth + column] << ( 8 - highbits)) - | (glyph[(page + 1) * STLcdSmallFontWidth + column] >> (highbits)); + (glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)) + | (glyph[(page + 1) * STLcdSmallFontWidth + column] << highbits); } + print(NL); } + print("remainheight: "); + printInt8(remainheight); if(remainheight > 0){ - mask = STLcdDrawMasks[0][remainheight]; + mask = ~STLcdDrawMasks[remainheight][0]; uint8_t page = glyphpages - 1; + print("\tmask: "); + printHex(mask); + print("\tpage: "); + printInt8(page); + print(NL); for(uint8_t column = 0; column < maxcolumn; column++){ - buffer[page * LCD_PAGE_LEN + column] = - (glyph[page * STLcdSmallFontWidth + column] << ( 8 - highbits)) - | (buffer[page * LCD_PAGE_LEN + column] & mask); + printHex(glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)); + print("|"); + printHex(buffer[(page + 1) * LCD_PAGE_LEN + column] & mask); + print(","); + buffer[(page + 1) * LCD_PAGE_LEN + column] = + (glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)) + | (buffer[(page + 1) * LCD_PAGE_LEN + column] & mask); } } + print(NL); } else{ if(STLcdSmallFontHeight & 0x07){ @@ -839,20 +916,43 @@ void STLcd_drawGlyph(uint8_t index, uint8_t x, uint8_t y) memcpy(buffer + page * LCD_PAGE_LEN, glyph + page * STLcdSmallFontWidth, maxcolumn); + for(uint8_t column = 0; column < maxcolumn; column++){ + print("src: "); + printHex(*(glyph + page * STLcdSmallFontWidth + column)); + print("\tdest: "); + printHex(*(buffer + page * LCD_PAGE_LEN + column)); + } + print(NL); } uint8_t remainheight = STLcdSmallFontHeight & 0x07; + uint8_t mask = ~STLcdDrawMasks[remainheight][0]; + print("remainheight: "); + printInt8(remainheight); + print(NL); for(uint8_t column = 0; column < maxcolumn; column++){ uint16_t destindex = (glyphpages - 1) * LCD_PAGE_LEN + column; - buffer[destindex] = (buffer[destindex] & STLcdDrawMasks[0][remainheight]) + printHex(buffer[destindex] & mask); + print("|"); + printHex(glyph[(glyphpages - 1) * STLcdSmallFontWidth + column]); + print(","); + buffer[destindex] = (buffer[destindex] & mask) | (glyph[(glyphpages - 1) * STLcdSmallFontWidth + column]); } + print(NL); } else{ for(uint8_t page = 0; page < glyphpages; page++){ memcpy(buffer + page * LCD_PAGE_LEN, glyph + page * STLcdSmallFontWidth, maxcolumn); + for(uint8_t column = 0; column < maxcolumn; column++){ + print("src: "); + printHex(*(glyph + page * STLcdSmallFontWidth + column)); + print("\tdest: "); + printHex(*(buffer + page * LCD_PAGE_LEN + column)); + } + print(NL); } } } @@ -866,26 +966,27 @@ static uint8_t TTYColumns = 0; static uint8_t TTYCurrentLine = 0; static uint8_t TTYCurrentColumn = 0; -void TTY_initialized(void) +void TTY_initialize(void) { - LCD_clear(); + STLcd_clear(); TTYInitialized = 1; TTYLineHeight = STLcdSmallFontHeight; TTYLines = LCD_HEIGHT / TTYLineHeight; TTYColumns = LCD_WIDTH / STLcdSmallFontWidth; - TTYCurrentLine = 0; + TTYCurrentLine = TTYLines - 1; TTYCurrentColumn = 0; } void TTY_exit(void) { - LCD_clear(); + STLcd_clear(); TTYInitialized = 0; } void TTY_drawGlyph(uint8_t index) { STLcd_drawGlyph(index, TTYCurrentColumn * STLcdSmallFontWidth, TTYCurrentLine * TTYLineHeight); + //STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); STLcd_updateBoundingBox(TTYCurrentColumn * STLcdSmallFontWidth, TTYCurrentLine * TTYLineHeight, (TTYCurrentColumn + 1) * STLcdSmallFontWidth, @@ -909,21 +1010,25 @@ void TTY_scrollUp(uint8_t lines) scrollpages * LCD_PAGE_LEN); } else{ - for(uint8_t destpage = 0, srcpage = scrollpages + 1; - srcpage < LCD_TOTAL_VISIBLE_PAGES; - destpage++, srcpage++) - { - for(uint8_t column = 0; column < LCD_PAGE_LEN; column++){ - STLcdBuffer[destpage * LCD_PAGE_LEN] = - (STLcdBuffer[destpage * LCD_PAGE_LEN + column] << scrollshiftbits) | - (STLcdBuffer[srcpage * LCD_PAGE_LEN + column] >> (8 - scrollshiftbits)); + if(scrollpages < LCD_TOTAL_VISIBLE_PAGES - 1){ + for(uint8_t destpage = LCD_TOTAL_VISIBLE_PAGES - 1, srcpage = LCD_TOTAL_VISIBLE_PAGES - scrollpages - 1; + srcpage > 0; + destpage--, srcpage--) + { + for(uint8_t column = 0; column < LCD_PAGE_LEN; column++){ + STLcdBuffer[destpage * LCD_PAGE_LEN + column] = + (STLcdBuffer[srcpage * LCD_PAGE_LEN + column] << scrollshiftbits) | + (STLcdBuffer[(srcpage - 1) * LCD_PAGE_LEN + column] >> (8 - scrollshiftbits)); + } } } - for(uint8_t column = 0; column < LCD_PAGE_LEN; column++){ // last non-empty page - STLcdBuffer[(LCD_TOTAL_VISIBLE_PAGES - scrollpages - 1) * LCD_PAGE_LEN + column] <<= scrollshiftbits; + if(scrollpages < LCD_TOTAL_VISIBLE_PAGES){ + for(uint8_t column = 0; column < LCD_PAGE_LEN; column++){ // last non-empty page + STLcdBuffer[scrollpages * LCD_PAGE_LEN + column] = STLcdBuffer[column] << scrollshiftbits; + } } if(scrollpages > 0) // have empty pages - memset(STLcdBuffer + (LCD_TOTAL_VISIBLE_PAGES - scrollpages) * LCD_PAGE_LEN, + memset(STLcdBuffer, 0, scrollpages * LCD_PAGE_LEN); } @@ -932,20 +1037,21 @@ void TTY_scrollUp(uint8_t lines) void TTY_newLine(void) { - if(TTYCurrentLine < TTYLines - 1){ - TTYCurrentLine++; + if(TTYCurrentLine > 0){ + TTYCurrentLine--; TTYCurrentColumn = 0; } else{ TTY_scrollUp(1); TTYCurrentColumn = 0; } - } void TTY_outputChar(uint8_t c) { - + if(!TTYInitialized){ + TTY_initialize(); + } switch(c) { case 0x8: // \b @@ -964,9 +1070,9 @@ void TTY_outputChar(uint8_t c) TTY_newLine(); break; case 0x0c: // \f - LCD_clear(); + STLcd_clear(); TTYCurrentColumn = 0; - TTYCurrentLine = 0; + TTYCurrentLine = TTYLines - 1; break; default: TTY_drawGlyph(c); @@ -1097,6 +1203,40 @@ void cliFunc_lcdDisp( char* args ) STLcd_updateBoundingBox(start, page * 8, address, (page + 1) * 8); } +void cliFunc_lcdTextOut( char* args ) +{ + char* curArgs; + char* arg1Ptr; + char* arg2Ptr = args; + + // First process page and starting address + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + return; + uint8_t x = numToInt( arg1Ptr ); + + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + return; + uint8_t y = numToInt( arg1Ptr ); + + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + return; + uint8_t value = numToInt( arg1Ptr ); + STLcd_drawGlyph(value, x, y); + STLcd_updateBoundingBox(x, y, x+STLcdSmallFontWidth, y+STLcdSmallFontHeight); +} + void cliFunc_ttyPrint( char* args ) { char* curArgs; @@ -1118,3 +1258,20 @@ void cliFunc_ttyPrint( char* args ) } } +void cliFunc_ttyScrollUp( char* args ) +{ + char* curArgs; + char* arg1Ptr; + char* arg2Ptr = args; + + curArgs = arg2Ptr; + CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); + + // Stop processing args if no more are found + if ( *arg1Ptr == '\0' ) + return; + + uint8_t value = numToInt( arg1Ptr ); + TTY_scrollUp(value); +} + From 67273198cb0b1ce72551296913bb73450c5e5130 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Sun, 8 May 2016 21:32:55 +0800 Subject: [PATCH 10/16] Removed debug outputs. --- Scan/STLcd/lcd_scan.c | 92 ------------------------------------------- 1 file changed, 92 deletions(-) diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 886df50bc..02f615615 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -529,15 +529,6 @@ inline uint8_t LCD_scan() else{ if(STLcdUpdateYMin >= STLcdUpdateYMax) return 0; - print(NL); - print("Syncing X from "); - printInt8(STLcdUpdateXMin); - print(" to "); - printInt8(STLcdUpdateXMax); - print(" Y from "); - printInt8(STLcdUpdateYMin); - print(" to "); - printInt8(STLcdUpdateYMax); STLcdSyncPageMin = STLcdUpdateYMin >> 3; STLcdSyncPageMax = (STLcdUpdateYMax + 7) >> 3; STLcdSyncPageCurrent = STLcdSyncPageMin; @@ -547,11 +538,6 @@ inline uint8_t LCD_scan() STLcdSyncBufferColumnMin = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMin; STLcdSyncBufferColumnMax = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMax; - print("\tPage from"); - printInt8(STLcdSyncPageMin); - print(" to "); - printInt8(STLcdSyncPageMax); - print(NL); memcpy(STLcdSyncBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, STLcdBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, (STLcdSyncPageMax - STLcdSyncPageMin) * LCD_PAGE_LEN); @@ -827,88 +813,32 @@ void STLcd_drawGlyph(uint8_t index, uint8_t x, uint8_t y) const uint8_t *glyph = STLcdSmallFont + index * STLcdSmallFontSize; uint8_t *buffer = STLcdBuffer + (y >> 3) * LCD_PAGE_LEN + x; uint8_t maxcolumn = (x + STLcdSmallFontWidth <= LCD_WIDTH) ? STLcdSmallFontWidth : (LCD_WIDTH - x); - print(NL); - print("buffer index: "); - printInt16((y >> 3) * LCD_PAGE_LEN + x); - print("index: "); - printInt8(index); - print("\tx: "); - printInt8(x); - print("\ty: "); - printInt8(y); - print(NL); - print("glyphpages: "); - printInt8(glyphpages); - print("\tmaxcolumn: "); - printInt8(maxcolumn); - print(NL); - print("glyphdata: "); - print(NL); - for(uint8_t page = 0; page < glyphpages; page++){ - for(uint8_t column = 0; column < maxcolumn; column++){ - printHex(glyph[page * STLcdSmallFontWidth + column]); - print(","); - } - print(NL); - } if(y & 0x07){ uint8_t highbits = y&0x07; uint8_t remainheight = (y + STLcdSmallFontHeight <= LCD_HEIGHT) ? STLcdSmallFontHeight : (LCD_HEIGHT - y); uint8_t mask = STLcdDrawMasks[highbits][(remainheight > 7) ? 0 : remainheight]; - print("highbits: "); - printInt8(highbits); - print("\tremainheight: "); - printInt8(remainheight); - print("\tmask: "); - printHex(mask); - print(NL); for(uint8_t column = 0; column < maxcolumn; column++){ - printHex(buffer[column]&mask); - print("|"); - printHex(glyph[column] << highbits); - print(","); buffer[column] = (buffer[column]&mask) | (glyph[column] << highbits); } - print(NL); remainheight -= 8 - highbits; - print("remainheight: "); - printInt8(remainheight); - print(NL); for(uint8_t page = 0; remainheight > 7; page++, remainheight-=8){ for(uint8_t column = 0; column < maxcolumn; column++){ - printHex(glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)); - print("|"); - printHex(glyph[(page + 1) * STLcdSmallFontWidth + column] << highbits); - print(","); buffer[(page + 1) * LCD_PAGE_LEN + column] = (glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)) | (glyph[(page + 1) * STLcdSmallFontWidth + column] << highbits); } - print(NL); } - print("remainheight: "); - printInt8(remainheight); if(remainheight > 0){ mask = ~STLcdDrawMasks[remainheight][0]; uint8_t page = glyphpages - 1; - print("\tmask: "); - printHex(mask); - print("\tpage: "); - printInt8(page); - print(NL); for(uint8_t column = 0; column < maxcolumn; column++){ - printHex(glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)); - print("|"); - printHex(buffer[(page + 1) * LCD_PAGE_LEN + column] & mask); - print(","); buffer[(page + 1) * LCD_PAGE_LEN + column] = (glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)) | (buffer[(page + 1) * LCD_PAGE_LEN + column] & mask); } } - print(NL); } else{ if(STLcdSmallFontHeight & 0x07){ @@ -916,43 +846,21 @@ void STLcd_drawGlyph(uint8_t index, uint8_t x, uint8_t y) memcpy(buffer + page * LCD_PAGE_LEN, glyph + page * STLcdSmallFontWidth, maxcolumn); - for(uint8_t column = 0; column < maxcolumn; column++){ - print("src: "); - printHex(*(glyph + page * STLcdSmallFontWidth + column)); - print("\tdest: "); - printHex(*(buffer + page * LCD_PAGE_LEN + column)); - } - print(NL); } uint8_t remainheight = STLcdSmallFontHeight & 0x07; uint8_t mask = ~STLcdDrawMasks[remainheight][0]; - print("remainheight: "); - printInt8(remainheight); - print(NL); for(uint8_t column = 0; column < maxcolumn; column++){ uint16_t destindex = (glyphpages - 1) * LCD_PAGE_LEN + column; - printHex(buffer[destindex] & mask); - print("|"); - printHex(glyph[(glyphpages - 1) * STLcdSmallFontWidth + column]); - print(","); buffer[destindex] = (buffer[destindex] & mask) | (glyph[(glyphpages - 1) * STLcdSmallFontWidth + column]); } - print(NL); } else{ for(uint8_t page = 0; page < glyphpages; page++){ memcpy(buffer + page * LCD_PAGE_LEN, glyph + page * STLcdSmallFontWidth, maxcolumn); - for(uint8_t column = 0; column < maxcolumn; column++){ - print("src: "); - printHex(*(glyph + page * STLcdSmallFontWidth + column)); - print("\tdest: "); - printHex(*(buffer + page * LCD_PAGE_LEN + column)); - } - print(NL); } } } From 77900ff324e55890c510a2b92d6a38b119775810 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Sun, 8 May 2016 23:55:09 +0800 Subject: [PATCH 11/16] Made a general bitmap output function for LCD. Also changed the code style. --- Scan/STLcd/lcd_scan.c | 883 +++++++++++++++++++++--------------------- 1 file changed, 441 insertions(+), 442 deletions(-) diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 02f615615..7d9e9d845 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -54,14 +54,14 @@ // ----- Function Declarations ----- // CLI Functions -void cliFunc_lcdCmd ( char* args ); -void cliFunc_lcdColor( char* args ); -void cliFunc_lcdDisp ( char* args ); -void cliFunc_lcdInit ( char* args ); -void cliFunc_lcdTest ( char* args ); -void cliFunc_lcdTextOut ( char* args); -void cliFunc_ttyPrint( char* args ); -void cliFunc_ttyScrollUp( char* args ); +void cliFunc_lcdCmd ( char* args ); +void cliFunc_lcdColor ( char* args ); +void cliFunc_lcdDisp ( char* args ); +void cliFunc_lcdInit ( char* args ); +void cliFunc_lcdTest ( char* args ); +void cliFunc_lcdTextOut ( char* args ); +void cliFunc_ttyPrint ( char* args ); +void cliFunc_ttyScrollUp ( char* args ); @@ -72,7 +72,6 @@ void cliFunc_ttyScrollUp( char* args ); const uint8_t STLcdDefaultImage[] = { STLcdDefaultImage_define }; const uint8_t STLcdSmallFont[] = { STLcdSmallFont_define }; - const uint8_t STLcdSmallFontWidth = STLcdSmallFontWidth_define; const uint8_t STLcdSmallFontHeight = STLcdSmallFontHeight_define; const uint8_t STLcdSmallFontSize = STLcdSmallFontSize_define; @@ -93,7 +92,7 @@ CLIDict_Entry( lcdInit, "Re-initialize the LCD display." ); CLIDict_Entry( lcdTest, "Test out the LCD display." ); CLIDict_Entry( lcdTextOut, "Output text to the LCD at the given x-y coordinate."); CLIDict_Entry( ttyPrint, "Output text to the LCD." ); -CLIDict_Entry( ttyScrollUp, "Scroll up given lines on the LCD." ); +CLIDict_Entry( ttyScrollUp, "Scroll up given lines on the LCD." ); CLIDict_Def( lcdCLIDict, "ST LCD Module Commands" ) = { CLIDict_Item( lcdCmd ), @@ -185,7 +184,7 @@ void LCD_writeControlReg( uint8_t byte ) // Write to display register // Pages 0-7 normal display -// Page 8 icon buffer +// Page 8 icon buffer void LCD_writeDisplayReg( uint8_t page, uint8_t *buffer, uint8_t len ) { // Set the register page @@ -328,14 +327,14 @@ inline void LCD_setup() // @ 0xFFFF period, 72 MHz / (0xFFFF * 2) = Actual period // Higher pre-scalar will use the most power (also look the best) // Pre-scalar calculations - // 0 - 72 MHz -> 549 Hz - // 1 - 36 MHz -> 275 Hz - // 2 - 18 MHz -> 137 Hz - // 3 - 9 MHz -> 69 Hz (Slightly visible flicker) - // 4 - 4 500 kHz -> 34 Hz (Visible flickering) - // 5 - 2 250 kHz -> 17 Hz - // 6 - 1 125 kHz -> 9 Hz - // 7 - 562 500 Hz -> 4 Hz + // 0 - 72 MHz -> 549 Hz + // 1 - 36 MHz -> 275 Hz + // 2 - 18 MHz -> 137 Hz + // 3 - 9 MHz -> 69 Hz (Slightly visible flicker) + // 4 - 4 500 kHz -> 34 Hz (Visible flickering) + // 5 - 2 250 kHz -> 17 Hz + // 6 - 1 125 kHz -> 9 Hz + // 7 - 562 500 Hz -> 4 Hz // Using a higher pre-scalar without flicker is possible but FTM0_MOD will need to be reduced // Which will reduce the brightness range @@ -359,8 +358,8 @@ static uint32_t STLcdSyncStartMillis; static uint32_t STLcdSyncStartTicks; // Display buffer -uint8_t STLcdBuffer[LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES]; -uint8_t STLcdSyncBuffer[LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES]; +uint8_t STLcdBuffer [ LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES ]; +uint8_t STLcdSyncBuffer [ LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES ]; // Bounding box. @@ -368,16 +367,16 @@ static uint8_t STLcdUpdateXMin = LCD_WIDTH, STLcdUpdateXMax = 0, STLcdUpdateYMin static uint8_t STLcdSync = 0; static uint8_t STLcdSyncPageMin, STLcdSyncPageMax, STLcdSyncColumnMin, STLcdSyncColumnMax; -static void STLcd_updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax) { - if (xmin < STLcdUpdateXMin) STLcdUpdateXMin = xmin; - if (xmax > STLcdUpdateXMax) STLcdUpdateXMax = xmax; - if (ymin < STLcdUpdateYMin) STLcdUpdateYMin = ymin; - if (ymax > STLcdUpdateYMax) STLcdUpdateYMax = ymax; +static void STLcd_updateBoundingBox( uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax ) { + if ( xmin < STLcdUpdateXMin ) STLcdUpdateXMin = xmin; + if ( xmax > STLcdUpdateXMax ) STLcdUpdateXMax = xmax; + if ( ymin < STLcdUpdateYMin ) STLcdUpdateYMin = ymin; + if ( ymax > STLcdUpdateYMax ) STLcdUpdateYMax = ymax; } -void STLcd_clear(void) { - memset(STLcdBuffer, 0, LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES); - STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); +void STLcd_clear( void ) { + memset( STLcdBuffer, 0, LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES ); + STLcd_updateBoundingBox( 0, 0, LCD_WIDTH, LCD_HEIGHT ); } static uint8_t STLcdSyncPageCurrent; @@ -386,173 +385,218 @@ static uint8_t *STLcdSyncBufferColumnMin, *STLcdSyncBufferColumnMax; static uint32_t STLcdSyncStage; #define STAGE_WRITE_START 15 -#define STAGE_WRITE_END 20 void STLcd_blockingSync(void) { - for(;STLcdSyncPageCurrent < STLcdSyncPageMax; - STLcdSyncPageCurrent++, STLcdSyncBufferColumnMin += LCD_PAGE_LEN) - { - LCD_writeControlReg(0xB0 | STLcdSyncPageCurrent); - LCD_writeControlReg(0x10 | STLcdSyncColumnMin >> 4); - LCD_writeControlReg(0x10 | (STLcdSyncColumnMin & 0x0f)); - SPI_write(STLcdSyncBufferColumnMin, STLcdSyncColumnMax - STLcdSyncColumnMin); - } + for ( ; STLcdSyncPageCurrent < STLcdSyncPageMax; + STLcdSyncPageCurrent++, STLcdSyncBufferColumnMin += LCD_PAGE_LEN ) + { + LCD_writeControlReg( 0xB0 | STLcdSyncPageCurrent ); + LCD_writeControlReg( 0x10 | STLcdSyncColumnMin >> 4 ); + LCD_writeControlReg( 0x10 | ( STLcdSyncColumnMin & 0x0f ) ); + SPI_write( STLcdSyncBufferColumnMin, STLcdSyncColumnMax - STLcdSyncColumnMin ); + } } // a non-blocking sync function -void STLcd_sync(void) { - for(;;){ - switch(STLcdSyncStage){ - case 0: // Begin LCD_writeControlReg( 0xB0 | STLcdSyncPageCurrent); - if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); - return; - GPIOC_PCOR |= (1<<7); - STLcdSyncStage++; - case 1: // Begin SPI_write( &byte, 1); - if( !( SPI0_SR & SPI_SR_TFFF) ) - return; - SPI0_PUSHR = ( 0xB0 | STLcdSyncPageCurrent ) | SPI_PUSHR_PCS(1); - STLcdSyncStage++; - case 2: - if( !( SPI0_SR & SPI_SR_TCF ) ) - return; - SPI0_SR |= SPI_SR_TCF; - STLcdSyncStage++; // End SPI_write - case 3: - if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); - return; - STLcdSyncStage++; - STLcdSyncStartTicks = ticks(); - STLcdSyncStartMillis = millis(); - case 4: - // delayMicroseconds(10); - if(!isTicksPassed(STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10)) - return; - GPIOC_PSOR |= (1<<7); - STLcdSyncStage++; // End LCD_writeControlReg( 0xB0 | page); - case 5: // Begin LCD_writeControlReg( 0x10 | STLcdSyncColumnMin >> 4); - if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); - return; - GPIOC_PCOR |= (1<<7); - STLcdSyncStage++; - case 6: // Begin SPI_write( &byte, 1); - if( !( SPI0_SR & SPI_SR_TFFF) ) - return; - SPI0_PUSHR = ( 0x10 | STLcdSyncColumnMin >> 4 ) | SPI_PUSHR_PCS(1); - STLcdSyncStage++; - case 7: - if( !( SPI0_SR & SPI_SR_TCF ) ) - return; - SPI0_SR |= SPI_SR_TCF; - STLcdSyncStage++; // End SPI_write - case 8: - if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); - return; - STLcdSyncStage++; - STLcdSyncStartTicks = ticks(); - STLcdSyncStartMillis = millis(); - case 9: - // delayMicroseconds(10); - if(!isTicksPassed(STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10)) - return; - GPIOC_PSOR |= (1<<7); - STLcdSyncStage++; // End LCD_writeControlReg( 0x10 | STLcdSyncColumnCurrent >> 4); - case 10: // Begin LCD_writeControlReg( 0x00 | STLcdSyncColumnCurrent & 0x0f); - if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); - return; - GPIOC_PCOR |= (1<<7); - STLcdSyncStage++; - case 11: // Begin SPI_write( &byte, 1); - if( !( SPI0_SR & SPI_SR_TFFF) ) - return; - SPI0_PUSHR = ( 0x00 | (STLcdSyncColumnMin & 0x0f) ) | SPI_PUSHR_PCS(1); - STLcdSyncStage++; - case 12: - if( !( SPI0_SR & SPI_SR_TCF ) ) - return; - SPI0_SR |= SPI_SR_TCF; - STLcdSyncStage++; // End SPI_write - case 13: - if(SPI0_TxFIFO_CNT != 0) // while ( SPI0_TxFIFO_CNT != 0 ); - return; - STLcdSyncStage++; - STLcdSyncStartTicks = ticks(); - STLcdSyncStartMillis = millis(); - case 14: - // delayMicroseconds(10); - if(!isTicksPassed(STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10)) - return; - GPIOC_PSOR |= (1<<7); - STLcdSyncStage++; // End LCD_writeControlReg( 0x00 | (STLcdSyncColumnCurrent & 0x0f)); - STLcdSyncBufferColumnCurrent = STLcdSyncBufferColumnMin; - // Begin SPI_write( STLcdSyncBufferColumnMin, - // STLcdSyncColumnMax - STLcdSyncColumnMin); - case STAGE_WRITE_START: - if(STLcdSyncBufferColumnCurrent >= STLcdSyncBufferColumnMax){ // next page - STLcdSyncStage = 0; - STLcdSyncPageCurrent++; - if(STLcdSyncPageCurrent >= STLcdSyncPageMax){ // has finished - STLcdSync = 0; - return; - } - else{ - STLcdSyncBufferColumnMin += LCD_PAGE_LEN; - STLcdSyncBufferColumnMax += LCD_PAGE_LEN; - break; +void STLcd_sync() { + for ( ;; ) + { + switch(STLcdSyncStage) + { + // Verify SPI0 TxFIFO is not full, then enable LCD configuration registers (A0 to Low) + case 0: + if ( SPI0_TxFIFO_CNT != 0 ) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + GPIOC_PCOR |= (1<<7); + STLcdSyncStage++; + + // Verify SPI0 TxFIFO has 4 or fewer entries, then write page number to TxFIFO (CS0, CTAR0) + case 1: // Begin SPI_write( &byte, 1); + if ( !( SPI0_SR & SPI_SR_TFFF ) ) + return; + SPI0_PUSHR = ( 0xB0 | STLcdSyncPageCurrent ) | SPI_PUSHR_PCS(1); + STLcdSyncStage++; + + // TODO: Verify the transfer has completed? + case 2: + if ( !( SPI0_SR & SPI_SR_TCF ) ) + return; + SPI0_SR |= SPI_SR_TCF; + STLcdSyncStage++; // End SPI_write + + // Verify SPIO TxFIFO is empty, then save the current time. + case 3: + if ( SPI0_TxFIFO_CNT != 0 ) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + STLcdSyncStage++; + STLcdSyncStartTicks = ticks(); + STLcdSyncStartMillis = millis(); + + // Verify that 10 microseconds have passed, then enable LCD display registors (A0 to high) + case 4: + // delayMicroseconds(10); + if ( !isTicksPassed( STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10 ) ) + return; + GPIOC_PSOR |= (1<<7); + STLcdSyncStage++; // End LCD_writeControlReg( 0xB0 | page); + + // TODO: maybe these lines is not need? Because the last command also writes to the control register. + case 5: // Begin LCD_writeControlReg( 0x10 | STLcdSyncColumnMin >> 4); + if ( SPI0_TxFIFO_CNT != 0 ) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + GPIOC_PCOR |= (1<<7); + STLcdSyncStage++; + + // Verify SPI0 TxFIFO has 4 or fewer entries, + // then write the high half of column number to TxFIFO (CS0, CTAR0) + case 6: // Begin SPI_write( &byte, 1); + if ( !( SPI0_SR & SPI_SR_TFFF) ) + return; + SPI0_PUSHR = ( 0x10 | STLcdSyncColumnMin >> 4 ) | SPI_PUSHR_PCS(1); + STLcdSyncStage++; + + // TODO: Verify the transfer has completed? + case 7: + if ( !( SPI0_SR & SPI_SR_TCF ) ) + return; + SPI0_SR |= SPI_SR_TCF; + STLcdSyncStage++; // End SPI_write + + // Verify SPIO TxFIFO is empty, then save the current time. + case 8: + if ( SPI0_TxFIFO_CNT != 0 ) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + STLcdSyncStage++; + STLcdSyncStartTicks = ticks(); + STLcdSyncStartMillis = millis(); + + // Verify that 10 microseconds have passed, then enable LCD display registors (A0 to high) + case 9: + // delayMicroseconds(10); + if ( !isTicksPassed( STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10 ) ) + return; + GPIOC_PSOR |= (1<<7); + STLcdSyncStage++; // End LCD_writeControlReg( 0x10 | STLcdSyncColumnCurrent >> 4); + + // TODO: maybe these lines is not need? Because the last command also writes to the control register. + case 10: // Begin LCD_writeControlReg( 0x00 | STLcdSyncColumnCurrent & 0x0f); + if ( SPI0_TxFIFO_CNT != 0 ) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + GPIOC_PCOR |= (1<<7); + STLcdSyncStage++; + + // Verify SPI0 TxFIFO has 4 or fewer entries, + // then write the lower half of column number to TxFIFO (CS0, CTAR0) + case 11: // Begin SPI_write( &byte, 1); + if ( !( SPI0_SR & SPI_SR_TFFF) ) + return; + SPI0_PUSHR = ( 0x00 | ( STLcdSyncColumnMin & 0x0f ) ) | SPI_PUSHR_PCS(1); + STLcdSyncStage++; + + // TODO: Verify the transfer has completed? + case 12: + if ( !( SPI0_SR & SPI_SR_TCF ) ) + return; + SPI0_SR |= SPI_SR_TCF; + STLcdSyncStage++; // End SPI_write + + // Verify SPIO TxFIFO is empty, then save the current time. + case 13: + if ( SPI0_TxFIFO_CNT != 0 ) // while ( SPI0_TxFIFO_CNT != 0 ); + return; + STLcdSyncStage++; + STLcdSyncStartTicks = ticks(); + STLcdSyncStartMillis = millis(); + + // Verify that 10 microseconds have passed, then enable LCD display registors (A0 to high), + // then begin to write the buffer to SPI. + case 14: + // delayMicroseconds(10); + if ( !isTicksPassed( STLcdSyncStartMillis, STLcdSyncStartTicks, F_CPU / 1000000 * 10 ) ) + return; + GPIOC_PSOR |= (1<<7); + STLcdSyncStage++; // End LCD_writeControlReg( 0x00 | (STLcdSyncColumnCurrent & 0x0f)); + STLcdSyncBufferColumnCurrent = STLcdSyncBufferColumnMin; + // Begin SPI_write( STLcdSyncBufferColumnMin, + // STLcdSyncColumnMax - STLcdSyncColumnMin); + + // If the current page has been outputed, + // then change to next page or finish the sync( if it's the last page). + case STAGE_WRITE_START: + if ( STLcdSyncBufferColumnCurrent >= STLcdSyncBufferColumnMax ) + { // next page + STLcdSyncStage = 0; + STLcdSyncPageCurrent++; + if (STLcdSyncPageCurrent >= STLcdSyncPageMax ) + { // has finished + STLcdSync = 0; + return; + } + else{ + STLcdSyncBufferColumnMin += LCD_PAGE_LEN; + STLcdSyncBufferColumnMax += LCD_PAGE_LEN; + break; + } + } + STLcdSyncStage++; + + // Verify SPI0 TxFIFO has 4 or fewer entries, + // then write the byte of current column to TxFIFO (CS0, CTAR0) + case 16: + if( !( SPI0_SR & SPI_SR_TFFF) ) + return; + SPI0_PUSHR = ( *STLcdSyncBufferColumnCurrent ) | SPI_PUSHR_PCS(1); + STLcdSyncStage++; + + // TODO: Verify the transfer has completed? + // then changed to the next column of current page and go back to the start of this loop. + case 17: + if( !( SPI0_SR & SPI_SR_TCF ) ) + return; + SPI0_SR |= SPI_SR_TCF; + STLcdSyncBufferColumnCurrent++; + STLcdSyncStage=STAGE_WRITE_START; // Loop back to STAGE_WRITE_START + break; } - } - STLcdSyncStage++; - case 16: - if( !( SPI0_SR & SPI_SR_TFFF) ) - return; - SPI0_PUSHR = ( *STLcdSyncBufferColumnCurrent ) | SPI_PUSHR_PCS(1); - STLcdSyncStage++; - case 17: - if( !( SPI0_SR & SPI_SR_TCF ) ) - return; - SPI0_SR |= SPI_SR_TCF; - STLcdSyncBufferColumnCurrent++; - STLcdSyncStage=STAGE_WRITE_START; // Loop back to STAGE_WRITE_START - break; } - } - } // LCD State processing loop inline uint8_t LCD_scan() { - if(STLcdSync){ - STLcd_sync(); - } - else{ - if(STLcdUpdateYMin >= STLcdUpdateYMax) - return 0; - STLcdSyncPageMin = STLcdUpdateYMin >> 3; - STLcdSyncPageMax = (STLcdUpdateYMax + 7) >> 3; - STLcdSyncPageCurrent = STLcdSyncPageMin; - - STLcdSyncColumnMin = STLcdUpdateXMin; - STLcdSyncColumnMax = STLcdUpdateXMax; - - STLcdSyncBufferColumnMin = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMin; - STLcdSyncBufferColumnMax = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMax; + if ( STLcdSync ) + { + STLcd_sync(); + } + else + { + if ( STLcdUpdateYMin >= STLcdUpdateYMax ) + return 0; + STLcdSyncPageMin = STLcdUpdateYMin >> 3; + STLcdSyncPageMax = ( STLcdUpdateYMax + 7 ) >> 3; + STLcdSyncPageCurrent = STLcdSyncPageMin; + + STLcdSyncColumnMin = STLcdUpdateXMin; + STLcdSyncColumnMax = STLcdUpdateXMax; + + STLcdSyncBufferColumnMin = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMin; + STLcdSyncBufferColumnMax = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMax; - memcpy(STLcdSyncBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, STLcdBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, - (STLcdSyncPageMax - STLcdSyncPageMin) * LCD_PAGE_LEN); - - STLcdSync = 1; - STLcdSyncStage = 0; - //STLcd_syncBlocking(); - STLcd_sync(); - - STLcdUpdateXMin = LCD_WIDTH - 1; - STLcdUpdateXMax = 0; - STLcdUpdateYMin = LCD_HEIGHT-1; - STLcdUpdateYMax = 0; - } - return 0; + memcpy( STLcdSyncBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, STLcdBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, + ( STLcdSyncPageMax - STLcdSyncPageMin ) * LCD_PAGE_LEN ); + + STLcdSync = 1; + STLcdSyncStage = 0; + //STLcd_syncBlocking(); + STLcd_sync(); + + STLcdUpdateXMin = LCD_WIDTH - 1; + STLcdUpdateXMax = 0; + STLcdUpdateYMin = LCD_HEIGHT - 1; + STLcdUpdateYMax = 0; + } + return 0; } @@ -619,35 +663,35 @@ void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t * // Only display if there are layers active if ( stack_args->numArgs > 0 ) { - // Set the color according to the "top-of-stack" layer - uint16_t layerIndex = stack_args->layers[0]; - FTM0_C0V = colors[ layerIndex ][0]; - FTM0_C1V = colors[ layerIndex ][1]; - FTM0_C2V = colors[ layerIndex ][2]; - - // Iterate through each of the pages - // XXX Many of the values here are hard-coded - // Eventually a proper font rendering engine should take care of things like this... -HaaTa - STLcd_clear(); - for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) - { + // Set the color according to the "top-of-stack" layer + uint16_t layerIndex = stack_args->layers[0]; + FTM0_C0V = colors[ layerIndex ][0]; + FTM0_C1V = colors[ layerIndex ][1]; + FTM0_C2V = colors[ layerIndex ][2]; + + // Iterate through each of the pages + // XXX Many of the values here are hard-coded + // Eventually a proper font rendering engine should take care of things like this... -HaaTa + STLcd_clear(); + for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + { uint8_t offset = 0; // Write data for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) { - layerIndex = stack_args->layers[ layer ]; - - // Default to 0, if over 9 - if ( layerIndex > 9 ) - { + layerIndex = stack_args->layers[ layer ]; + + // Default to 0, if over 9 + if ( layerIndex > 9 ) + { layerIndex = 0; - } - memcpy(STLcdBuffer + page * LCD_PAGE_LEN + offset, + } + memcpy(STLcdBuffer + page * LCD_PAGE_LEN + offset, &numbers[layerIndex][page * 32], 32); - offset += 32; + offset += 32; + } } - } } else { @@ -665,7 +709,7 @@ void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t * // Determines the current layer stack, and sets the LCD output accordingly // Will only work on a master node when using the interconnect (use LCD_layerStackExact_capability instead) uint16_t LCD_layerStack_prevSize = 0; -uint16_t LCD_layerStack_prevTop = 0; +uint16_t LCD_layerStack_prevTop = 0; void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args ) { // Display capability name @@ -681,13 +725,13 @@ void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args // Ignore if the stack size hasn't changed and the top of the stack is the same if ( macroLayerIndexStackSize == LCD_layerStack_prevSize - && (macroLayerIndexStackSize == 0 || + && (macroLayerIndexStackSize == 0 || macroLayerIndexStack[macroLayerIndexStackSize - 1] == LCD_layerStack_prevTop )) { return; } LCD_layerStack_prevSize = macroLayerIndexStackSize; - LCD_layerStack_prevTop = macroLayerIndexStack[macroLayerIndexStackSize - 1]; + LCD_layerStack_prevTop = macroLayerIndexStack[macroLayerIndexStackSize - 1]; LCD_layerStackExact_args stack_args; memset( stack_args.layers, 0, sizeof( stack_args.layers ) ); @@ -722,149 +766,86 @@ void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args LCD_layerStackExact_capability( state, stateType, (uint8_t*)&stack_args ); } -/*// Takes 1 8 bit charactor and 2 8 bit x-y coordinates -typedef struct LCD_charOut_args { - uint8_t charactor; - uint8_t x; - uint8_t y; -} LCD_charOut_args; -void LCD_charOut_capability( uint8_t state, uint8_t stateType, uint8_t *args ) +static uint8_t STLcdDrawMasks[8][8] = { - // Display capability name - if ( stateType == 0xFF && state == 0xFF ) - { - print("LCD_charOut_capability(charactor, x, y)"); - return; - } - - // Read arguments - LCD_charOut_args *out_args = (LCD_charOut_args*)args; + { 0x00, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80 }, + { 0x01, 0xfd, 0xf9, 0xf1, 0xe1, 0xc1, 0x81, 0x01 }, + { 0x03, 0xfb, 0xf3, 0xe3, 0xc3, 0x83, 0x03, 0x03 }, + { 0x07, 0xf7, 0xe7, 0xc7, 0x87, 0x07, 0x07, 0x07 }, + { 0x0f, 0xef, 0xcf, 0x8f, 0x0f, 0x0f, 0x0f, 0x0f }, + { 0x1f, 0xdf, 0x9f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f }, + { 0x3f, 0xbf, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f }, + { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f } +}; - #uint16_t layerIndex = stack_args->layers[0]; - #FTM0_C0V = colors[ layerIndex ][0]; - #FTM0_C1V = colors[ layerIndex ][1]; - #FTM0_C2V = colors[ layerIndex ][2]; +void STLcd_drawBitmap( const uint8_t *bitmap, uint8_t x, uint8_t y, uint8_t width, uint8_t height ) +{ + uint8_t *buffer = STLcdBuffer + (y>>3) * LCD_PAGE_LEN + x; + uint8_t maxcolumn = ( x + width <= LCD_WIDTH ) ? width : ( LCD_WIDTH - x ); + uint8_t remainheight = + ( y + height <= LCD_HEIGHT ) + ? height : ( LCD_HEIGHT - y ); + uint8_t srcpages = ( remainheight + 7 ) / 8; + if ( y & 0x07 ) + { + uint8_t highbits = y & 0x07; - // Iterate through each of the pages - // XXX Many of the values here are hard-coded - // Eventually a proper font rendering engine should take care of things like this... -HaaTa - for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + uint8_t mask = STLcdDrawMasks[ highbits ][ ( remainheight > 7 ) ? 0 : remainheight ]; + for ( uint8_t column = 0; column < maxcolumn; column++ ) { - // Set the register page - LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); - - // Set starting address - LCD_writeControlReg( 0x10 ); - LCD_writeControlReg( 0x00 ); - - // Write data - for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) + buffer[ column ] = ( buffer[ column ] & mask ) | ( bitmap[ column ] << highbits ); + } + remainheight -= 8 - highbits; + for ( uint8_t page = 0; remainheight > 7; page++, remainheight -= 8 ) + { + for ( uint8_t column = 0; column < maxcolumn; column++ ) { - layerIndex = stack_args->layers[ layer ]; - - // Default to 0, if over 9 - if ( layerIndex > 9 ) - { - layerIndex = 0; - } - - // Write page of number to display - SPI_write( (uint8_t*)&numbers[ layerIndex ][ page * 32 ], 32 ); + buffer[ (page + 1 ) * LCD_PAGE_LEN + column ] = + ( bitmap[ page * width + column ] >> ( 8 - highbits ) ) + | ( bitmap[ ( page + 1 ) * width + column ] << highbits ); } - - // Blank out rest of display - uint8_t data = 0; - for ( uint8_t c = 0; c < 4 - stack_args->numArgs; c++ ) + } + if ( remainheight > 0 ) + { + mask = ~STLcdDrawMasks[ remainheight ][ 0 ]; + uint8_t page = srcpages - 1; + for ( uint8_t column = 0; column < maxcolumn; column++ ) { - for ( uint8_t byte = 0; byte < 32; byte++ ) - { - SPI_write( &data, 1 ); - } + buffer[ ( page + 1 ) * LCD_PAGE_LEN + column ] = + ( bitmap[ page * width + column ] >> ( 8 - highbits ) ) + | ( buffer[ ( page + 1 ) * LCD_PAGE_LEN + column ] & mask ); } } } else { - // Set default backlight - FTM0_C0V = STLcdBacklightRed_define; - FTM0_C1V = STLcdBacklightGreen_define; - FTM0_C2V = STLcdBacklightBlue_define; - - // Write default image - for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) - LCD_writeDisplayReg( page, (uint8_t *)&STLcdDefaultImage[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); - } - }*/ - -static uint8_t STLcdDrawMasks[8][8] = { - {0x00, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80}, - {0x01, 0xfd, 0xf9, 0xf1, 0xe1, 0xc1, 0x81, 0x01}, - {0x03, 0xfb, 0xf3, 0xe3, 0xc3, 0x83, 0x03, 0x03}, - {0x07, 0xf7, 0xe7, 0xc7, 0x87, 0x07, 0x07, 0x07}, - {0x0f, 0xef, 0xcf, 0x8f, 0x0f, 0x0f, 0x0f, 0x0f}, - {0x1f, 0xdf, 0x9f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}, - {0x3f, 0xbf, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f}, - {0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f} -}; - -void STLcd_drawGlyph(uint8_t index, uint8_t x, uint8_t y) -{ - uint8_t glyphpages = (STLcdSmallFontHeight + 7)/8; - const uint8_t *glyph = STLcdSmallFont + index * STLcdSmallFontSize; - uint8_t *buffer = STLcdBuffer + (y >> 3) * LCD_PAGE_LEN + x; - uint8_t maxcolumn = (x + STLcdSmallFontWidth <= LCD_WIDTH) ? STLcdSmallFontWidth : (LCD_WIDTH - x); - if(y & 0x07){ - uint8_t highbits = y&0x07; - uint8_t remainheight = (y + STLcdSmallFontHeight <= LCD_HEIGHT) ? STLcdSmallFontHeight : (LCD_HEIGHT - y); - - uint8_t mask = STLcdDrawMasks[highbits][(remainheight > 7) ? 0 : remainheight]; - for(uint8_t column = 0; column < maxcolumn; column++){ - buffer[column] = (buffer[column]&mask) - | (glyph[column] << highbits); - } - remainheight -= 8 - highbits; - for(uint8_t page = 0; remainheight > 7; page++, remainheight-=8){ - for(uint8_t column = 0; column < maxcolumn; column++){ - buffer[(page + 1) * LCD_PAGE_LEN + column] = - (glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)) - | (glyph[(page + 1) * STLcdSmallFontWidth + column] << highbits); - } - } - if(remainheight > 0){ - mask = ~STLcdDrawMasks[remainheight][0]; - uint8_t page = glyphpages - 1; - for(uint8_t column = 0; column < maxcolumn; column++){ - buffer[(page + 1) * LCD_PAGE_LEN + column] = - (glyph[page * STLcdSmallFontWidth + column] >> ( 8 - highbits)) - | (buffer[(page + 1) * LCD_PAGE_LEN + column] & mask); - } - } - } - else{ - if(STLcdSmallFontHeight & 0x07){ - for(uint8_t page = 0; page < glyphpages - 1; page++){ - memcpy(buffer + page * LCD_PAGE_LEN, - glyph + page * STLcdSmallFontWidth, - maxcolumn); - } - uint8_t remainheight = STLcdSmallFontHeight & 0x07; - uint8_t mask = ~STLcdDrawMasks[remainheight][0]; - for(uint8_t column = 0; column < maxcolumn; column++){ - uint16_t destindex = (glyphpages - 1) * LCD_PAGE_LEN + column; - buffer[destindex] = (buffer[destindex] & mask) - | (glyph[(glyphpages - 1) * STLcdSmallFontWidth + column]); - - } - } - else{ - for(uint8_t page = 0; page < glyphpages; page++){ - memcpy(buffer + page * LCD_PAGE_LEN, - glyph + page * STLcdSmallFontWidth, - maxcolumn); - } + if ( remainheight & 0x07 ) + { + for ( uint8_t page = 0; page < srcpages - 1; page++ ) + { + memcpy( buffer + page * LCD_PAGE_LEN, + bitmap + page * width, + maxcolumn ); + } + remainheight = remainheight & 0x07; + uint8_t mask = ~STLcdDrawMasks[ remainheight ][ 0 ]; + for ( uint8_t column = 0; column < maxcolumn; column++ ) + { + uint16_t destindex = ( srcpages - 1 ) * LCD_PAGE_LEN + column; + buffer[ destindex ] = ( buffer[ destindex ] & mask ) + | ( bitmap[ ( srcpages - 1 ) * width + column ] ); + } + } + else + { + for ( uint8_t page = 0; page < srcpages; page++ ) + { + memcpy( buffer + page * LCD_PAGE_LEN, + bitmap + page * width, + maxcolumn ); + } + } } - } - } static uint8_t TTYInitialized = 0; @@ -874,122 +855,140 @@ static uint8_t TTYColumns = 0; static uint8_t TTYCurrentLine = 0; static uint8_t TTYCurrentColumn = 0; -void TTY_initialize(void) +void TTY_initialize() { - STLcd_clear(); - TTYInitialized = 1; - TTYLineHeight = STLcdSmallFontHeight; - TTYLines = LCD_HEIGHT / TTYLineHeight; - TTYColumns = LCD_WIDTH / STLcdSmallFontWidth; - TTYCurrentLine = TTYLines - 1; - TTYCurrentColumn = 0; + STLcd_clear(); + TTYInitialized = 1; + TTYLineHeight = STLcdSmallFontHeight; + TTYLines = LCD_HEIGHT / TTYLineHeight; + TTYColumns = LCD_WIDTH / STLcdSmallFontWidth; + TTYCurrentLine = TTYLines - 1; + TTYCurrentColumn = 0; } -void TTY_exit(void) +void TTY_exit() { - STLcd_clear(); - TTYInitialized = 0; + STLcd_clear(); + TTYInitialized = 0; } -void TTY_drawGlyph(uint8_t index) +void TTY_drawGlyph( uint8_t index ) { - STLcd_drawGlyph(index, TTYCurrentColumn * STLcdSmallFontWidth, TTYCurrentLine * TTYLineHeight); - //STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); - STLcd_updateBoundingBox(TTYCurrentColumn * STLcdSmallFontWidth, - TTYCurrentLine * TTYLineHeight, - (TTYCurrentColumn + 1) * STLcdSmallFontWidth, - (TTYCurrentLine + 1) * TTYLineHeight); + STLcd_drawBitmap( STLcdSmallFont + index * STLcdSmallFontSize, + TTYCurrentColumn * STLcdSmallFontWidth, + TTYCurrentLine * TTYLineHeight, + STLcdSmallFontWidth, + STLcdSmallFontHeight ); + STLcd_updateBoundingBox( TTYCurrentColumn * STLcdSmallFontWidth, + TTYCurrentLine * TTYLineHeight, + ( TTYCurrentColumn + 1 ) * STLcdSmallFontWidth, + ( TTYCurrentLine + 1 ) * TTYLineHeight ); } -void TTY_scrollUp(uint8_t lines) +void TTY_scrollUp( uint8_t lines ) { - uint8_t scrollpixels = lines * STLcdSmallFontHeight; - uint8_t scrollshiftbits = scrollpixels & 0x07; - uint8_t scrollpages = scrollpixels >> 3; - if(scrollshiftbits == 0){ - if(scrollpages == 0){ - return; - } - memcpy(STLcdBuffer, - STLcdBuffer + scrollpages * LCD_PAGE_LEN, - LCD_PAGE_LEN * (LCD_TOTAL_VISIBLE_PAGES - scrollpages)); - memset(STLcdBuffer + LCD_PAGE_LEN * (LCD_TOTAL_VISIBLE_PAGES - scrollpages), - 0, - scrollpages * LCD_PAGE_LEN); - } - else{ - if(scrollpages < LCD_TOTAL_VISIBLE_PAGES - 1){ - for(uint8_t destpage = LCD_TOTAL_VISIBLE_PAGES - 1, srcpage = LCD_TOTAL_VISIBLE_PAGES - scrollpages - 1; - srcpage > 0; - destpage--, srcpage--) - { - for(uint8_t column = 0; column < LCD_PAGE_LEN; column++){ - STLcdBuffer[destpage * LCD_PAGE_LEN + column] = - (STLcdBuffer[srcpage * LCD_PAGE_LEN + column] << scrollshiftbits) | - (STLcdBuffer[(srcpage - 1) * LCD_PAGE_LEN + column] >> (8 - scrollshiftbits)); + uint8_t scrollpixels = lines * STLcdSmallFontHeight; + uint8_t scrollshiftbits = scrollpixels & 0x07; + uint8_t scrollpages = scrollpixels >> 3; + if ( scrollshiftbits == 0 ) + { + if ( scrollpages == 0 ) + { + return; } - } + memcpy( STLcdBuffer, + STLcdBuffer + scrollpages * LCD_PAGE_LEN, + LCD_PAGE_LEN * ( LCD_TOTAL_VISIBLE_PAGES - scrollpages ) ); + memset( STLcdBuffer + LCD_PAGE_LEN * ( LCD_TOTAL_VISIBLE_PAGES - scrollpages ), + 0, + scrollpages * LCD_PAGE_LEN ); } - if(scrollpages < LCD_TOTAL_VISIBLE_PAGES){ - for(uint8_t column = 0; column < LCD_PAGE_LEN; column++){ // last non-empty page - STLcdBuffer[scrollpages * LCD_PAGE_LEN + column] = STLcdBuffer[column] << scrollshiftbits; - } + else + { + if ( scrollpages < LCD_TOTAL_VISIBLE_PAGES - 1 ) + { + for ( uint8_t destpage = LCD_TOTAL_VISIBLE_PAGES - 1, + srcpage = LCD_TOTAL_VISIBLE_PAGES - scrollpages - 1; + srcpage > 0; + destpage--, srcpage-- ) + { + for ( uint8_t column = 0; column < LCD_PAGE_LEN; column++ ) + { + STLcdBuffer[ destpage * LCD_PAGE_LEN + column ] = + ( STLcdBuffer[ srcpage * LCD_PAGE_LEN + column ] << scrollshiftbits ) | + ( STLcdBuffer[ ( srcpage - 1 ) * LCD_PAGE_LEN + column ] >> ( 8 - scrollshiftbits ) ); + } + } + } + if ( scrollpages < LCD_TOTAL_VISIBLE_PAGES ) + { + for ( uint8_t column = 0; column < LCD_PAGE_LEN; column++ ) + { // last non-empty page + STLcdBuffer[ scrollpages * LCD_PAGE_LEN + column ] = STLcdBuffer[ column ] << scrollshiftbits; + } + } + if ( scrollpages > 0 ) // have empty pages + { + memset( STLcdBuffer, + 0, + scrollpages * LCD_PAGE_LEN ); + } } - if(scrollpages > 0) // have empty pages - memset(STLcdBuffer, - 0, - scrollpages * LCD_PAGE_LEN); - } - STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); + STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); } -void TTY_newLine(void) +void TTY_newLine( void ) { - if(TTYCurrentLine > 0){ - TTYCurrentLine--; - TTYCurrentColumn = 0; - } - else{ - TTY_scrollUp(1); - TTYCurrentColumn = 0; - } + if ( TTYCurrentLine > 0 ) + { + TTYCurrentLine--; + TTYCurrentColumn = 0; + } + else + { + TTY_scrollUp( 1 ); + TTYCurrentColumn = 0; + } } -void TTY_outputChar(uint8_t c) +void TTY_outputChar( uint8_t c ) { - if(!TTYInitialized){ - TTY_initialize(); - } - switch(c) - { - case 0x8: // \b - if(TTYCurrentColumn){ - TTYCurrentColumn--; - TTY_drawGlyph(0x20); + if ( !TTYInitialized ){ + TTY_initialize(); } - break; - case 0x9: // \t - TTYCurrentColumn = (TTYCurrentColumn & 0xfc) + 4; - if(TTYCurrentColumn >= TTYColumns){ - TTY_newLine(); - } - break; - case 0x0a: // \n - TTY_newLine(); - break; - case 0x0c: // \f - STLcd_clear(); - TTYCurrentColumn = 0; - TTYCurrentLine = TTYLines - 1; - break; - default: - TTY_drawGlyph(c); - TTYCurrentColumn++; - if(TTYCurrentColumn >= TTYColumns){ - TTY_newLine(); + switch ( c ) + { + case 0x8: // \b + if ( TTYCurrentColumn ) + { + TTYCurrentColumn--; + TTY_drawGlyph( 0x20 ); + } + break; + case 0x9: // \t + TTYCurrentColumn = ( TTYCurrentColumn & 0xfc ) + 4; + if ( TTYCurrentColumn >= TTYColumns ) + { + TTY_newLine(); + } + break; + case 0x0a: // \n + TTY_newLine(); + break; + case 0x0c: // \f + STLcd_clear(); + TTYCurrentColumn = 0; + TTYCurrentLine = TTYLines - 1; + break; + default: + TTY_drawGlyph( c ); + TTYCurrentColumn++; + if ( TTYCurrentColumn >= TTYColumns ) + { + TTY_newLine(); + } + break; } - break; - } } @@ -1003,9 +1002,9 @@ void cliFunc_lcdInit( char* args ) void cliFunc_lcdTest( char* args ) { - // Write default image - memcpy(STLcdBuffer, STLcdDefaultImage, LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES); - STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); + // Write default image + memcpy( STLcdBuffer, STLcdDefaultImage, LCD_PAGE_LEN * LCD_TOTAL_VISIBLE_PAGES ); + STLcd_updateBoundingBox( 0, 0, LCD_WIDTH, LCD_HEIGHT ); } void cliFunc_lcdCmd( char* args ) @@ -1105,10 +1104,10 @@ void cliFunc_lcdDisp( char* args ) break; uint8_t value = numToInt( arg1Ptr ); - STLcdBuffer[page * LCD_PAGE_LEN + address] = value; + STLcdBuffer[ page * LCD_PAGE_LEN + address ] = value; address++; } - STLcd_updateBoundingBox(start, page * 8, address, (page + 1) * 8); + STLcd_updateBoundingBox( start, page * 8, address, (page + 1) * 8 ); } void cliFunc_lcdTextOut( char* args ) @@ -1139,10 +1138,11 @@ void cliFunc_lcdTextOut( char* args ) // Stop processing args if no more are found if ( *arg1Ptr == '\0' ) - return; + return; uint8_t value = numToInt( arg1Ptr ); - STLcd_drawGlyph(value, x, y); - STLcd_updateBoundingBox(x, y, x+STLcdSmallFontWidth, y+STLcdSmallFontHeight); + STLcd_drawBitmap( STLcdSmallFont + value * STLcdSmallFontSize, x, y, + STLcdSmallFontWidth, STLcdSmallFontHeight ); + STLcd_updateBoundingBox( x, y, x + STLcdSmallFontWidth, y + STLcdSmallFontHeight ); } void cliFunc_ttyPrint( char* args ) @@ -1162,7 +1162,7 @@ void cliFunc_ttyPrint( char* args ) break; uint8_t value = numToInt( arg1Ptr ); - TTY_outputChar(value); + TTY_outputChar( value ); } } @@ -1180,6 +1180,5 @@ void cliFunc_ttyScrollUp( char* args ) return; uint8_t value = numToInt( arg1Ptr ); - TTY_scrollUp(value); + TTY_scrollUp( value ); } - From 15a9d10b22320529415effdecac630a74747f9c2 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Mon, 9 May 2016 11:21:02 +0800 Subject: [PATCH 12/16] Tabified the Lib/delay.h --- Lib/delay.h | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/Lib/delay.h b/Lib/delay.h index f92a0e84b..1f438063b 100644 --- a/Lib/delay.h +++ b/Lib/delay.h @@ -60,7 +60,7 @@ static inline uint32_t millis(void) static inline uint32_t microsToTicks(uint32_t) __attribute__((always_inline, unused)); static inline uint32_t microsToTicks(uint32_t usec) { - return usec * (F_CPU / 1000000); + return usec * (F_CPU / 1000000); } static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unused)); @@ -76,9 +76,9 @@ static inline void delayMicroseconds(uint32_t usec) uint32_t n = usec << 3; #endif asm volatile( - "L_%=_delayMicroseconds:" "\n\t" - "subs %0, #1" "\n\t" - "bne L_%=_delayMicroseconds" "\n" + "L_%=_delayMicroseconds:" "\n\t" + "subs %0, #1" "\n\t" + "bne L_%=_delayMicroseconds" "\n" : "+r" (n) : ); } @@ -91,32 +91,31 @@ uint32_t micros(void); void delay(uint32_t ms); static inline uint8_t isTicksPassed(uint32_t, uint32_t, uint32_t) __attribute__((always_inline, unused)); -static inline uint8_t isTicksPassed(uint32_t startmillis, uint32_t startticks, - uint32_t ticks) +static inline uint8_t isTicksPassed(uint32_t startmillis, uint32_t startticks, uint32_t ticks) { - // the milliseconds must be gotten before the ticks. - uint32_t currentmillis = systick_millis_count; - uint32_t currentticks = SYST_CVR; - if (currentmillis > startmillis + 1){ - return 1; - } - if (currentmillis == startmillis + 1){ - currentticks += (F_CPU / 1000); - } - else if (currentticks < startmillis) { + // the milliseconds must be gotten before the ticks. + uint32_t currentmillis = systick_millis_count; + uint32_t currentticks = SYST_CVR; + if (currentmillis > startmillis + 1) { + return 1; + } + if (currentmillis == startmillis + 1) { + currentticks += (F_CPU / 1000); + } + else if (currentticks < startmillis) { // the microseconds is reset after getting the ticks. - currentticks += (F_CPU / 1000); - } - if( startticks + ticks < currentticks ){ - return 1; - } - else{ - return 0; - } + currentticks += (F_CPU / 1000); + } + if (startticks + ticks < currentticks) { + return 1; + } + else{ + return 0; + } } -static inline uint32_t ticks(void) __attribute__((always_inline, unused)); +static inline uint32_t ticks(void) __attribute__((always_inline, unused)); static inline uint32_t ticks(void) { - return SYST_CVR; + return SYST_CVR; } From 1cb299c6c74d4759df4106ea42fd004f35464cb6 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Mon, 9 May 2016 14:58:35 +0800 Subject: [PATCH 13/16] Made the TTY being able to use different fonts. --- Lib/delay.h | 6 +- Scan/STLcd/capabilities.kll | 20 +++--- Scan/STLcd/lcd_scan.c | 128 ++++++++++++++++++++++-------------- 3 files changed, 92 insertions(+), 62 deletions(-) diff --git a/Lib/delay.h b/Lib/delay.h index 1f438063b..db738f4a6 100644 --- a/Lib/delay.h +++ b/Lib/delay.h @@ -76,9 +76,9 @@ static inline void delayMicroseconds(uint32_t usec) uint32_t n = usec << 3; #endif asm volatile( - "L_%=_delayMicroseconds:" "\n\t" - "subs %0, #1" "\n\t" - "bne L_%=_delayMicroseconds" "\n" + "L_%=_delayMicroseconds:" "\n\t" + "subs %0, #1" "\n\t" + "bne L_%=_delayMicroseconds" "\n" : "+r" (n) : ); } diff --git a/Scan/STLcd/capabilities.kll b/Scan/STLcd/capabilities.kll index 34de5fe2a..98e787f11 100644 --- a/Scan/STLcd/capabilities.kll +++ b/Scan/STLcd/capabilities.kll @@ -63,15 +63,17 @@ STLcdDefaultImage = " 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, "; -STLcdSmallFont => STLcdSmallFont_define; -STLcdSmallFontWidth => STLcdSmallFontWidth_define; -STLcdSmallFontHeight => STLcdSmallFontHeight_define; -STLcdSmallFontSize => STLcdSmallFontSize_define; - -STLcdSmallFont = "0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x3e, 0x14, 0x3e, 0x00, 0x14, 0x3e, 0x28, 0x00, 0x24, 0x08, 0x12, 0x00, 0x3c, 0x3a, 0x0e, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x00, 0x22, 0x1c, 0x00, 0x00, 0x28, 0x10, 0x28, 0x00, 0x08, 0x1c, 0x08, 0x00, 0x02, 0x04, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x02, 0x00, 0x00, 0x06, 0x08, 0x30, 0x00, 0x1e, 0x22, 0x3c, 0x00, 0x10, 0x3e, 0x00, 0x00, 0x2e, 0x2a, 0x3a, 0x00, 0x22, 0x2a, 0x3e, 0x00, 0x38, 0x08, 0x3e, 0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3e, 0x2a, 0x2e, 0x00, 0x26, 0x28, 0x30, 0x00, 0x3e, 0x2a, 0x3e, 0x00, 0x3a, 0x2a, 0x3e, 0x00, 0x00, 0x14, 0x00, 0x00, 0x02, 0x14, 0x00, 0x00, 0x08, 0x14, 0x22, 0x00, 0x14, 0x14, 0x14, 0x00, 0x22, 0x14, 0x08, 0x00, 0x20, 0x2a, 0x30, 0x00, 0x1c, 0x2a, 0x1a, 0x00, 0x1e, 0x28, 0x1e, 0x00, 0x3e, 0x2a, 0x14, 0x00, 0x1c, 0x22, 0x22, 0x00, 0x3e, 0x22, 0x1c, 0x00, 0x3e, 0x2a, 0x2a, 0x00, 0x3e, 0x28, 0x28, 0x00, 0x1c, 0x2a, 0x2e, 0x00, 0x3e, 0x08, 0x3e, 0x00, 0x22, 0x3e, 0x22, 0x00, 0x04, 0x02, 0x3c, 0x00, 0x3e, 0x08, 0x36, 0x00, 0x3e, 0x02, 0x02, 0x00, 0x3e, 0x18, 0x3e, 0x00, 0x3e, 0x20, 0x3e, 0x00, 0x1c, 0x22, 0x1c, 0x00, 0x3e, 0x28, 0x10, 0x00, 0x1c, 0x26, 0x1e, 0x00, 0x3e, 0x2c, 0x1a, 0x00, 0x12, 0x2a, 0x24, 0x00, 0x20, 0x3e, 0x20, 0x00, 0x3c, 0x02, 0x3e, 0x00, 0x38, 0x06, 0x38, 0x00, 0x3e, 0x0c, 0x3e, 0x00, 0x36, 0x08, 0x36, 0x00, 0x30, 0x0e, 0x30, 0x00, 0x26, 0x2a, 0x32, 0x00, 0x3e, 0x22, 0x22, 0x00, 0x10, 0x08, 0x04, 0x00, 0x22, 0x22, 0x3e, 0x00, 0x10, 0x20, 0x10, 0x00, 0x02, 0x02, 0x02, 0x00, 0x20, 0x10, 0x00, 0x00, 0x16, 0x1a, 0x0e, 0x00, 0x3e, 0x12, 0x0c, 0x00, 0x0c, 0x12, 0x12, 0x00, 0x0c, 0x12, 0x3e, 0x00, 0x0c, 0x16, 0x1a, 0x00, 0x08, 0x1e, 0x28, 0x00, 0x0c, 0x15, 0x1e, 0x00, 0x3e, 0x10, 0x0e, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x02, 0x01, 0x2e, 0x00, 0x3e, 0x0c, 0x12, 0x00, 0x22, 0x3e, 0x02, 0x00, 0x1e, 0x1c, 0x1e, 0x00, 0x1e, 0x10, 0x0e, 0x00, 0x0c, 0x12, 0x0c, 0x00, 0x1f, 0x12, 0x0c, 0x00, 0x0c, 0x12, 0x1f, 0x00, 0x0e, 0x10, 0x10, 0x00, 0x0a, 0x1e, 0x14, 0x00, 0x10, 0x3e, 0x12, 0x00, 0x1c, 0x02, 0x1e, 0x00, 0x1c, 0x06, 0x1c, 0x00, 0x1e, 0x0e, 0x1e, 0x00, 0x12, 0x0c, 0x12, 0x00, 0x18, 0x05, 0x1e, 0x00, 0x16, 0x1e, 0x1a, 0x00, 0x08, 0x36, 0x22, 0x00, 0x00, 0x36, 0x00, 0x00, 0x22, 0x36, 0x08, 0x00, 0x10, 0x30, 0x20, 0x00, 0x3e, 0x3e, 0x3e, 0x00,"; -STLcdSmallFontWidth = 4; -STLcdSmallFontHeight = 6; -STLcdSmallFontSize = 4; +STLcdDefaultFont => STLcdDefaultFont_define; +STLcdDefaultFontWidth => STLcdDefaultFontWidth_define; +STLcdDefaultFontHeight => STLcdDefaultFontHeight_define; +STLcdDefaultFontSize => STLcdDefaultFontSize_define; +STLcdDefaultFontLength => STLcdDefaultFontLength_define; + +STLcdDefaultFont = "0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x3e, 0x14, 0x3e, 0x00, 0x14, 0x3e, 0x28, 0x00, 0x24, 0x08, 0x12, 0x00, 0x3c, 0x3a, 0x0e, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x00, 0x22, 0x1c, 0x00, 0x00, 0x28, 0x10, 0x28, 0x00, 0x08, 0x1c, 0x08, 0x00, 0x02, 0x04, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x02, 0x00, 0x00, 0x06, 0x08, 0x30, 0x00, 0x1e, 0x22, 0x3c, 0x00, 0x10, 0x3e, 0x00, 0x00, 0x2e, 0x2a, 0x3a, 0x00, 0x22, 0x2a, 0x3e, 0x00, 0x38, 0x08, 0x3e, 0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3e, 0x2a, 0x2e, 0x00, 0x26, 0x28, 0x30, 0x00, 0x3e, 0x2a, 0x3e, 0x00, 0x3a, 0x2a, 0x3e, 0x00, 0x00, 0x14, 0x00, 0x00, 0x02, 0x14, 0x00, 0x00, 0x08, 0x14, 0x22, 0x00, 0x14, 0x14, 0x14, 0x00, 0x22, 0x14, 0x08, 0x00, 0x20, 0x2a, 0x30, 0x00, 0x1c, 0x2a, 0x1a, 0x00, 0x1e, 0x28, 0x1e, 0x00, 0x3e, 0x2a, 0x14, 0x00, 0x1c, 0x22, 0x22, 0x00, 0x3e, 0x22, 0x1c, 0x00, 0x3e, 0x2a, 0x2a, 0x00, 0x3e, 0x28, 0x28, 0x00, 0x1c, 0x2a, 0x2e, 0x00, 0x3e, 0x08, 0x3e, 0x00, 0x22, 0x3e, 0x22, 0x00, 0x04, 0x02, 0x3c, 0x00, 0x3e, 0x08, 0x36, 0x00, 0x3e, 0x02, 0x02, 0x00, 0x3e, 0x18, 0x3e, 0x00, 0x3e, 0x20, 0x3e, 0x00, 0x1c, 0x22, 0x1c, 0x00, 0x3e, 0x28, 0x10, 0x00, 0x1c, 0x26, 0x1e, 0x00, 0x3e, 0x2c, 0x1a, 0x00, 0x12, 0x2a, 0x24, 0x00, 0x20, 0x3e, 0x20, 0x00, 0x3c, 0x02, 0x3e, 0x00, 0x38, 0x06, 0x38, 0x00, 0x3e, 0x0c, 0x3e, 0x00, 0x36, 0x08, 0x36, 0x00, 0x30, 0x0e, 0x30, 0x00, 0x26, 0x2a, 0x32, 0x00, 0x3e, 0x22, 0x22, 0x00, 0x10, 0x08, 0x04, 0x00, 0x22, 0x22, 0x3e, 0x00, 0x10, 0x20, 0x10, 0x00, 0x02, 0x02, 0x02, 0x00, 0x20, 0x10, 0x00, 0x00, 0x16, 0x1a, 0x0e, 0x00, 0x3e, 0x12, 0x0c, 0x00, 0x0c, 0x12, 0x12, 0x00, 0x0c, 0x12, 0x3e, 0x00, 0x0c, 0x16, 0x1a, 0x00, 0x08, 0x1e, 0x28, 0x00, 0x0c, 0x15, 0x1e, 0x00, 0x3e, 0x10, 0x0e, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x02, 0x01, 0x2e, 0x00, 0x3e, 0x0c, 0x12, 0x00, 0x22, 0x3e, 0x02, 0x00, 0x1e, 0x1c, 0x1e, 0x00, 0x1e, 0x10, 0x0e, 0x00, 0x0c, 0x12, 0x0c, 0x00, 0x1f, 0x12, 0x0c, 0x00, 0x0c, 0x12, 0x1f, 0x00, 0x0e, 0x10, 0x10, 0x00, 0x0a, 0x1e, 0x14, 0x00, 0x10, 0x3e, 0x12, 0x00, 0x1c, 0x02, 0x1e, 0x00, 0x1c, 0x06, 0x1c, 0x00, 0x1e, 0x0e, 0x1e, 0x00, 0x12, 0x0c, 0x12, 0x00, 0x18, 0x05, 0x1e, 0x00, 0x16, 0x1e, 0x1a, 0x00, 0x08, 0x36, 0x22, 0x00, 0x00, 0x36, 0x00, 0x00, 0x22, 0x36, 0x08, 0x00, 0x10, 0x30, 0x20, 0x00, 0x3e, 0x3e, 0x3e, 0x00,"; +STLcdDefaultFontWidth = 4; +STLcdDefaultFontHeight = 6; +STLcdDefaultFontSize = 4; +STLcdDefaultFontLength = 128; # TTYOutputChar => TTY_outputChar_capability(charactor : 1); diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 7d9e9d845..96b68cd18 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -71,10 +71,11 @@ void cliFunc_ttyScrollUp ( char* args ); // Default Image - Displays on startup const uint8_t STLcdDefaultImage[] = { STLcdDefaultImage_define }; -const uint8_t STLcdSmallFont[] = { STLcdSmallFont_define }; -const uint8_t STLcdSmallFontWidth = STLcdSmallFontWidth_define; -const uint8_t STLcdSmallFontHeight = STLcdSmallFontHeight_define; -const uint8_t STLcdSmallFontSize = STLcdSmallFontSize_define; +const uint8_t STLcdDefaultFont[] = { STLcdDefaultFont_define }; +const uint8_t STLcdDefaultFontWidth = STLcdDefaultFontWidth_define; +const uint8_t STLcdDefaultFontHeight = STLcdDefaultFontHeight_define; +const uint8_t STLcdDefaultFontSize = STLcdDefaultFontSize_define; +const uint8_t STLcdDefaultFontLength = STLcdDefaultFontLength_define; @@ -584,7 +585,7 @@ inline uint8_t LCD_scan() STLcdSyncBufferColumnMax = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMax; memcpy( STLcdSyncBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, STLcdBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, - ( STLcdSyncPageMax - STLcdSyncPageMin ) * LCD_PAGE_LEN ); + ( STLcdSyncPageMax - STLcdSyncPageMin ) * LCD_PAGE_LEN ); STLcdSync = 1; STLcdSyncStage = 0; @@ -675,22 +676,22 @@ void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t * STLcd_clear(); for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) { - uint8_t offset = 0; - // Write data - for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) - { - layerIndex = stack_args->layers[ layer ]; - - // Default to 0, if over 9 - if ( layerIndex > 9 ) + uint8_t offset = 0; + // Write data + for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) { - layerIndex = 0; + layerIndex = stack_args->layers[ layer ]; + + // Default to 0, if over 9 + if ( layerIndex > 9 ) + { + layerIndex = 0; + } + memcpy(STLcdBuffer + page * LCD_PAGE_LEN + offset, + &numbers[layerIndex][page * 32], + 32); + offset += 32; } - memcpy(STLcdBuffer + page * LCD_PAGE_LEN + offset, - &numbers[layerIndex][page * 32], - 32); - offset += 32; - } } } else @@ -824,8 +825,8 @@ void STLcd_drawBitmap( const uint8_t *bitmap, uint8_t x, uint8_t y, uint8_t widt for ( uint8_t page = 0; page < srcpages - 1; page++ ) { memcpy( buffer + page * LCD_PAGE_LEN, - bitmap + page * width, - maxcolumn ); + bitmap + page * width, + maxcolumn ); } remainheight = remainheight & 0x07; uint8_t mask = ~STLcdDrawMasks[ remainheight ][ 0 ]; @@ -841,27 +842,41 @@ void STLcd_drawBitmap( const uint8_t *bitmap, uint8_t x, uint8_t y, uint8_t widt for ( uint8_t page = 0; page < srcpages; page++ ) { memcpy( buffer + page * LCD_PAGE_LEN, - bitmap + page * width, - maxcolumn ); + bitmap + page * width, + maxcolumn ); } } } } static uint8_t TTYInitialized = 0; +static const uint8_t * TTYFont = 0; +static uint8_t TTYFontHeight = 0; +static uint8_t TTYFontWidth = 0; +static uint8_t TTYFontSize = 0; +static uint8_t TTYSpacing = 0; static uint8_t TTYLineHeight = 0; +static uint8_t TTYFontLength = 0; static uint8_t TTYLines = 0; static uint8_t TTYColumns = 0; static uint8_t TTYCurrentLine = 0; static uint8_t TTYCurrentColumn = 0; -void TTY_initialize() +void TTY_initialize( const uint8_t *font, uint8_t fontSize, uint8_t fontLength, + uint8_t fontWidth, uint8_t fontHeight, + uint8_t spacing, uint8_t lineHeight ) { STLcd_clear(); TTYInitialized = 1; - TTYLineHeight = STLcdSmallFontHeight; - TTYLines = LCD_HEIGHT / TTYLineHeight; - TTYColumns = LCD_WIDTH / STLcdSmallFontWidth; + TTYFont = font; + TTYFontSize = fontSize; + TTYFontWidth = fontWidth; + TTYFontHeight = fontHeight; + TTYFontLength = fontLength; + TTYSpacing = spacing; + TTYLineHeight = lineHeight; + TTYLines = ( LCD_HEIGHT - fontHeight) / lineHeight + 1; + TTYColumns = ( LCD_WIDTH - fontWidth ) / ( fontWidth + spacing ) + 1; TTYCurrentLine = TTYLines - 1; TTYCurrentColumn = 0; } @@ -874,20 +889,22 @@ void TTY_exit() void TTY_drawGlyph( uint8_t index ) { - STLcd_drawBitmap( STLcdSmallFont + index * STLcdSmallFontSize, - TTYCurrentColumn * STLcdSmallFontWidth, - TTYCurrentLine * TTYLineHeight, - STLcdSmallFontWidth, - STLcdSmallFontHeight ); - STLcd_updateBoundingBox( TTYCurrentColumn * STLcdSmallFontWidth, - TTYCurrentLine * TTYLineHeight, - ( TTYCurrentColumn + 1 ) * STLcdSmallFontWidth, - ( TTYCurrentLine + 1 ) * TTYLineHeight ); + if ( index < TTYFontLength ) + return; + STLcd_drawBitmap( TTYFont + index * TTYFontSize, + TTYCurrentColumn * ( TTYFontWidth + TTYSpacing ), + TTYCurrentLine * TTYLineHeight, + TTYFontWidth, + TTYFontHeight ); + STLcd_updateBoundingBox( TTYCurrentColumn * ( TTYFontWidth + TTYSpacing ), + TTYCurrentLine * TTYLineHeight, + TTYCurrentColumn * ( TTYFontWidth + TTYSpacing ) + TTYFontWidth, + TTYCurrentLine * TTYLineHeight + TTYFontHeight ); } void TTY_scrollUp( uint8_t lines ) { - uint8_t scrollpixels = lines * STLcdSmallFontHeight; + uint8_t scrollpixels = lines * TTYLineHeight; uint8_t scrollshiftbits = scrollpixels & 0x07; uint8_t scrollpages = scrollpixels >> 3; if ( scrollshiftbits == 0 ) @@ -897,20 +914,20 @@ void TTY_scrollUp( uint8_t lines ) return; } memcpy( STLcdBuffer, - STLcdBuffer + scrollpages * LCD_PAGE_LEN, - LCD_PAGE_LEN * ( LCD_TOTAL_VISIBLE_PAGES - scrollpages ) ); + STLcdBuffer + scrollpages * LCD_PAGE_LEN, + LCD_PAGE_LEN * ( LCD_TOTAL_VISIBLE_PAGES - scrollpages ) ); memset( STLcdBuffer + LCD_PAGE_LEN * ( LCD_TOTAL_VISIBLE_PAGES - scrollpages ), - 0, - scrollpages * LCD_PAGE_LEN ); + 0, + scrollpages * LCD_PAGE_LEN ); } else { if ( scrollpages < LCD_TOTAL_VISIBLE_PAGES - 1 ) { for ( uint8_t destpage = LCD_TOTAL_VISIBLE_PAGES - 1, - srcpage = LCD_TOTAL_VISIBLE_PAGES - scrollpages - 1; - srcpage > 0; - destpage--, srcpage-- ) + srcpage = LCD_TOTAL_VISIBLE_PAGES - scrollpages - 1; + srcpage > 0; + destpage--, srcpage-- ) { for ( uint8_t column = 0; column < LCD_PAGE_LEN; column++ ) { @@ -930,8 +947,8 @@ void TTY_scrollUp( uint8_t lines ) if ( scrollpages > 0 ) // have empty pages { memset( STLcdBuffer, - 0, - scrollpages * LCD_PAGE_LEN ); + 0, + scrollpages * LCD_PAGE_LEN ); } } STLcd_updateBoundingBox(0, 0, LCD_WIDTH, LCD_HEIGHT); @@ -954,7 +971,9 @@ void TTY_newLine( void ) void TTY_outputChar( uint8_t c ) { if ( !TTYInitialized ){ - TTY_initialize(); + TTY_initialize ( STLcdDefaultFont, STLcdDefaultFontSize, STLcdDefaultFontLength, + STLcdDefaultFontWidth, STLcdDefaultFontHeight, + 1, 1 ); } switch ( c ) { @@ -1140,9 +1159,18 @@ void cliFunc_lcdTextOut( char* args ) if ( *arg1Ptr == '\0' ) return; uint8_t value = numToInt( arg1Ptr ); - STLcd_drawBitmap( STLcdSmallFont + value * STLcdSmallFontSize, x, y, - STLcdSmallFontWidth, STLcdSmallFontHeight ); - STLcd_updateBoundingBox( x, y, x + STLcdSmallFontWidth, y + STLcdSmallFontHeight ); + if ( value >= STLcdDefaultFontLength ) + { + print( "The charactor: " ); + printHex( value ); + print( " is out of the boundary of the font(length "); + printHex( STLcdDefaultFontLength ); + print( ")" ); + print( NL ); + } + STLcd_drawBitmap( STLcdDefaultFont + value * STLcdDefaultFontSize, x, y, + STLcdDefaultFontWidth, STLcdDefaultFontHeight ); + STLcd_updateBoundingBox( x, y, x + STLcdDefaultFontWidth, y + STLcdDefaultFontHeight ); } void cliFunc_ttyPrint( char* args ) From 368525e456731099584d84e6f85a07d2f2bcebae Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Mon, 9 May 2016 15:35:48 +0800 Subject: [PATCH 14/16] Compacted the default font more. --- Scan/STLcd/bitmapfont2Struct.py | 34 ++++++++++++++++++++++----------- Scan/STLcd/capabilities.kll | 6 +++--- Scan/STLcd/lcd_scan.c | 2 +- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Scan/STLcd/bitmapfont2Struct.py b/Scan/STLcd/bitmapfont2Struct.py index 37ff4ee0c..11bd73d4b 100755 --- a/Scan/STLcd/bitmapfont2Struct.py +++ b/Scan/STLcd/bitmapfont2Struct.py @@ -35,12 +35,12 @@ class STLcdFont: # Some constants for the LCD Driver array('B') - def __init__( self, glyph_width, glyph_height, num_glyphs): + def __init__( self, glyph_width, glyph_height, num_glyphs ): self.glyph_height = glyph_height self.glyph_width = glyph_width self.glyph_size = (glyph_height + 7) // 8 * glyph_width self.num_fixed_sizes = 1 - self.availible_sizes = [Bitmap_Size(self.glyph_height, self.glyph_width)] + self.availible_sizes = [ Bitmap_Size( self.glyph_height, self.glyph_width ) ] self.num_glyphs = num_glyphs self.glyph_data = [] for index in range( 0, self.num_glyphs ): @@ -57,7 +57,7 @@ def setpixel( self, index, x, y ): # Set pixel bit self.glyph_data[ index ][ byte ] |= (1 << bit) - def renderglyph( self, index, flags=0): + def renderglyph( self, index, flags=0 ): return self.glyph_data[ index ] def getarray( self ): @@ -71,11 +71,16 @@ def getarray( self ): return struct filename = sys.argv[1] -glyph_width = int(sys.argv[2]) -glyph_height = int(sys.argv[3]) +glyph_width = int( sys.argv[2] ) +glyph_height = int( sys.argv[3] ) +bitmap_spacing = 0 +bitmap_linespacing = 0 +if ( len( sys.argv ) >= 6 ): + bitmap_spacing = int( sys.argv[4] ) + bitmap_linespacing = int( sys.argv[5] ) num_glyphs = 128 # ASCII if filename is None: - print( "You must specify a bitmap filename. Try './bitmapfont2Struct.py font.bmp 4 6'" ) + print( "You must specify a bitmap filename. Try './bitmapfont2Struct.py font.bmp 4 6 0 0'" ) sys.exit( 1 ) output_image = STLcdFont( glyph_width, glyph_height, num_glyphs ) @@ -88,20 +93,25 @@ def getarray( self ): print( "Unable to load image '{0}'".format( filename ) ) input_width, input_height = input_image.size -columns = input_width // glyph_width -rows = input_height // glyph_height +columns = ( input_width - glyph_width ) // ( glyph_width + bitmap_spacing ) + 1 +rows = ( input_width - glyph_height ) // ( glyph_height + bitmap_linespacing ) + 1 # Iterate over all of the pixels # Also prepare the debug view of the image (disp_test) disp_test = "+" + "-" * input_width + "+\n" glyph_index = 0 for y in range( 0, input_height ): - row = y // glyph_height + row = y // ( glyph_height + bitmap_linespacing ) if row >= rows: break + if y % ( glyph_height + bitmap_linespacing ) >= glyph_height: + # empty + continue disp_test += "|" for x in range( 0, input_width ): - column = x // glyph_width + column = x // ( glyph_width + bitmap_spacing ) + if x % ( glyph_width + bitmap_spacing ) >= glyph_width: + continue glyph_index = row * columns + column if column >= columns or glyph_index >= num_glyphs: disp_test += " " @@ -110,7 +120,9 @@ def getarray( self ): try: if input_image.getpixel( (x, y) ) == 0: disp_test += "*" - output_image.setpixel( glyph_index, x % glyph_width, y % glyph_height ) + output_image.setpixel( glyph_index, + x % ( glyph_width + bitmap_spacing ), + y % ( glyph_height + bitmap_linespacing ) ) else: disp_test += " " except IndexError: diff --git a/Scan/STLcd/capabilities.kll b/Scan/STLcd/capabilities.kll index 98e787f11..460f44f53 100644 --- a/Scan/STLcd/capabilities.kll +++ b/Scan/STLcd/capabilities.kll @@ -69,10 +69,10 @@ STLcdDefaultFontHeight => STLcdDefaultFontHeight_define; STLcdDefaultFontSize => STLcdDefaultFontSize_define; STLcdDefaultFontLength => STLcdDefaultFontLength_define; -STLcdDefaultFont = "0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x22, 0x3e, 0x00, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x30, 0x00, 0x30, 0x00, 0x3e, 0x14, 0x3e, 0x00, 0x14, 0x3e, 0x28, 0x00, 0x24, 0x08, 0x12, 0x00, 0x3c, 0x3a, 0x0e, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x00, 0x22, 0x1c, 0x00, 0x00, 0x28, 0x10, 0x28, 0x00, 0x08, 0x1c, 0x08, 0x00, 0x02, 0x04, 0x00, 0x00, 0x08, 0x08, 0x08, 0x00, 0x00, 0x02, 0x00, 0x00, 0x06, 0x08, 0x30, 0x00, 0x1e, 0x22, 0x3c, 0x00, 0x10, 0x3e, 0x00, 0x00, 0x2e, 0x2a, 0x3a, 0x00, 0x22, 0x2a, 0x3e, 0x00, 0x38, 0x08, 0x3e, 0x00, 0x3a, 0x2a, 0x2e, 0x00, 0x3e, 0x2a, 0x2e, 0x00, 0x26, 0x28, 0x30, 0x00, 0x3e, 0x2a, 0x3e, 0x00, 0x3a, 0x2a, 0x3e, 0x00, 0x00, 0x14, 0x00, 0x00, 0x02, 0x14, 0x00, 0x00, 0x08, 0x14, 0x22, 0x00, 0x14, 0x14, 0x14, 0x00, 0x22, 0x14, 0x08, 0x00, 0x20, 0x2a, 0x30, 0x00, 0x1c, 0x2a, 0x1a, 0x00, 0x1e, 0x28, 0x1e, 0x00, 0x3e, 0x2a, 0x14, 0x00, 0x1c, 0x22, 0x22, 0x00, 0x3e, 0x22, 0x1c, 0x00, 0x3e, 0x2a, 0x2a, 0x00, 0x3e, 0x28, 0x28, 0x00, 0x1c, 0x2a, 0x2e, 0x00, 0x3e, 0x08, 0x3e, 0x00, 0x22, 0x3e, 0x22, 0x00, 0x04, 0x02, 0x3c, 0x00, 0x3e, 0x08, 0x36, 0x00, 0x3e, 0x02, 0x02, 0x00, 0x3e, 0x18, 0x3e, 0x00, 0x3e, 0x20, 0x3e, 0x00, 0x1c, 0x22, 0x1c, 0x00, 0x3e, 0x28, 0x10, 0x00, 0x1c, 0x26, 0x1e, 0x00, 0x3e, 0x2c, 0x1a, 0x00, 0x12, 0x2a, 0x24, 0x00, 0x20, 0x3e, 0x20, 0x00, 0x3c, 0x02, 0x3e, 0x00, 0x38, 0x06, 0x38, 0x00, 0x3e, 0x0c, 0x3e, 0x00, 0x36, 0x08, 0x36, 0x00, 0x30, 0x0e, 0x30, 0x00, 0x26, 0x2a, 0x32, 0x00, 0x3e, 0x22, 0x22, 0x00, 0x10, 0x08, 0x04, 0x00, 0x22, 0x22, 0x3e, 0x00, 0x10, 0x20, 0x10, 0x00, 0x02, 0x02, 0x02, 0x00, 0x20, 0x10, 0x00, 0x00, 0x16, 0x1a, 0x0e, 0x00, 0x3e, 0x12, 0x0c, 0x00, 0x0c, 0x12, 0x12, 0x00, 0x0c, 0x12, 0x3e, 0x00, 0x0c, 0x16, 0x1a, 0x00, 0x08, 0x1e, 0x28, 0x00, 0x0c, 0x15, 0x1e, 0x00, 0x3e, 0x10, 0x0e, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x02, 0x01, 0x2e, 0x00, 0x3e, 0x0c, 0x12, 0x00, 0x22, 0x3e, 0x02, 0x00, 0x1e, 0x1c, 0x1e, 0x00, 0x1e, 0x10, 0x0e, 0x00, 0x0c, 0x12, 0x0c, 0x00, 0x1f, 0x12, 0x0c, 0x00, 0x0c, 0x12, 0x1f, 0x00, 0x0e, 0x10, 0x10, 0x00, 0x0a, 0x1e, 0x14, 0x00, 0x10, 0x3e, 0x12, 0x00, 0x1c, 0x02, 0x1e, 0x00, 0x1c, 0x06, 0x1c, 0x00, 0x1e, 0x0e, 0x1e, 0x00, 0x12, 0x0c, 0x12, 0x00, 0x18, 0x05, 0x1e, 0x00, 0x16, 0x1e, 0x1a, 0x00, 0x08, 0x36, 0x22, 0x00, 0x00, 0x36, 0x00, 0x00, 0x22, 0x36, 0x08, 0x00, 0x10, 0x30, 0x20, 0x00, 0x3e, 0x3e, 0x3e, 0x00,"; -STLcdDefaultFontWidth = 4; +STLcdDefaultFont = "0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x22, 0x3e, 0x3e, 0x3e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x30, 0x00, 0x30, 0x3e, 0x14, 0x3e, 0x14, 0x3e, 0x28, 0x24, 0x08, 0x12, 0x3c, 0x3a, 0x0e, 0x00, 0x30, 0x00, 0x00, 0x1c, 0x22, 0x22, 0x1c, 0x00, 0x28, 0x10, 0x28, 0x08, 0x1c, 0x08, 0x02, 0x04, 0x00, 0x08, 0x08, 0x08, 0x00, 0x02, 0x00, 0x06, 0x08, 0x30, 0x1e, 0x22, 0x3c, 0x10, 0x3e, 0x00, 0x2e, 0x2a, 0x3a, 0x22, 0x2a, 0x3e, 0x38, 0x08, 0x3e, 0x3a, 0x2a, 0x2e, 0x3e, 0x2a, 0x2e, 0x26, 0x28, 0x30, 0x3e, 0x2a, 0x3e, 0x3a, 0x2a, 0x3e, 0x00, 0x14, 0x00, 0x02, 0x14, 0x00, 0x08, 0x14, 0x22, 0x14, 0x14, 0x14, 0x22, 0x14, 0x08, 0x20, 0x2a, 0x30, 0x1c, 0x2a, 0x1a, 0x1e, 0x28, 0x1e, 0x3e, 0x2a, 0x14, 0x1c, 0x22, 0x22, 0x3e, 0x22, 0x1c, 0x3e, 0x2a, 0x2a, 0x3e, 0x28, 0x28, 0x1c, 0x2a, 0x2e, 0x3e, 0x08, 0x3e, 0x22, 0x3e, 0x22, 0x04, 0x02, 0x3c, 0x3e, 0x08, 0x36, 0x3e, 0x02, 0x02, 0x3e, 0x18, 0x3e, 0x3e, 0x20, 0x3e, 0x1c, 0x22, 0x1c, 0x3e, 0x28, 0x10, 0x1c, 0x26, 0x1e, 0x3e, 0x2c, 0x1a, 0x12, 0x2a, 0x24, 0x20, 0x3e, 0x20, 0x3c, 0x02, 0x3e, 0x38, 0x06, 0x38, 0x3e, 0x0c, 0x3e, 0x36, 0x08, 0x36, 0x30, 0x0e, 0x30, 0x26, 0x2a, 0x32, 0x3e, 0x22, 0x22, 0x10, 0x08, 0x04, 0x22, 0x22, 0x3e, 0x10, 0x20, 0x10, 0x02, 0x02, 0x02, 0x20, 0x10, 0x00, 0x16, 0x1a, 0x0e, 0x3e, 0x12, 0x0c, 0x0c, 0x12, 0x12, 0x0c, 0x12, 0x3e, 0x0c, 0x16, 0x1a, 0x08, 0x1e, 0x28, 0x0c, 0x15, 0x1e, 0x3e, 0x10, 0x0e, 0x00, 0x2e, 0x00, 0x02, 0x01, 0x2e, 0x3e, 0x0c, 0x12, 0x22, 0x3e, 0x02, 0x1e, 0x1c, 0x1e, 0x1e, 0x10, 0x0e, 0x0c, 0x12, 0x0c, 0x1f, 0x12, 0x0c, 0x0c, 0x12, 0x1f, 0x0e, 0x10, 0x10, 0x0a, 0x1e, 0x14, 0x10, 0x3e, 0x12, 0x1c, 0x02, 0x1e, 0x1c, 0x06, 0x1c, 0x1e, 0x0e, 0x1e, 0x12, 0x0c, 0x12, 0x18, 0x05, 0x1e, 0x16, 0x1e, 0x1a, 0x08, 0x36, 0x22, 0x00, 0x36, 0x00, 0x22, 0x36, 0x08, 0x10, 0x30, 0x20, 0x3e, 0x3e, 0x3e,"; +STLcdDefaultFontWidth = 3; STLcdDefaultFontHeight = 6; -STLcdDefaultFontSize = 4; +STLcdDefaultFontSize = 3; STLcdDefaultFontLength = 128; # TTYOutputChar => TTY_outputChar_capability(charactor : 1); diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 96b68cd18..3ab955523 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -973,7 +973,7 @@ void TTY_outputChar( uint8_t c ) if ( !TTYInitialized ){ TTY_initialize ( STLcdDefaultFont, STLcdDefaultFontSize, STLcdDefaultFontLength, STLcdDefaultFontWidth, STLcdDefaultFontHeight, - 1, 1 ); + 1, 0 ); } switch ( c ) { From 98e98009741b18aea27c3abe3299349acb7d22d7 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Mon, 9 May 2016 17:53:13 +0800 Subject: [PATCH 15/16] Deleted the trailing space. --- Scan/STLcd/bitmapfont2Struct.py | 4 ++-- Scan/STLcd/lcd_scan.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Scan/STLcd/bitmapfont2Struct.py b/Scan/STLcd/bitmapfont2Struct.py index 11bd73d4b..089bbd5eb 100755 --- a/Scan/STLcd/bitmapfont2Struct.py +++ b/Scan/STLcd/bitmapfont2Struct.py @@ -45,7 +45,7 @@ def __init__( self, glyph_width, glyph_height, num_glyphs ): self.glyph_data = [] for index in range( 0, self.num_glyphs ): self.glyph_data.append( array( 'B', [0] * self.glyph_size ) ) - + def setpixel( self, index, x, y ): newy = self.glyph_height - y - 1 # Calculate which byte @@ -122,7 +122,7 @@ def getarray( self ): disp_test += "*" output_image.setpixel( glyph_index, x % ( glyph_width + bitmap_spacing ), - y % ( glyph_height + bitmap_linespacing ) ) + y % ( glyph_height + bitmap_linespacing ) ) else: disp_test += " " except IndexError: diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 3ab955523..12103de3f 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -405,7 +405,7 @@ void STLcd_sync() { switch(STLcdSyncStage) { // Verify SPI0 TxFIFO is not full, then enable LCD configuration registers (A0 to Low) - case 0: + case 0: if ( SPI0_TxFIFO_CNT != 0 ) // while ( SPI0_TxFIFO_CNT != 0 ); return; GPIOC_PCOR |= (1<<7); @@ -523,7 +523,7 @@ void STLcd_sync() { // If the current page has been outputed, // then change to next page or finish the sync( if it's the last page). - case STAGE_WRITE_START: + case STAGE_WRITE_START: if ( STLcdSyncBufferColumnCurrent >= STLcdSyncBufferColumnMax ) { // next page STLcdSyncStage = 0; @@ -583,7 +583,7 @@ inline uint8_t LCD_scan() STLcdSyncBufferColumnMin = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMin; STLcdSyncBufferColumnMax = STLcdSyncBuffer + STLcdSyncPageCurrent * LCD_PAGE_LEN + STLcdSyncColumnMax; - + memcpy( STLcdSyncBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, STLcdBuffer + STLcdSyncPageMin * LCD_PAGE_LEN, ( STLcdSyncPageMax - STLcdSyncPageMin ) * LCD_PAGE_LEN ); @@ -669,7 +669,7 @@ void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t * FTM0_C0V = colors[ layerIndex ][0]; FTM0_C1V = colors[ layerIndex ][1]; FTM0_C2V = colors[ layerIndex ][2]; - + // Iterate through each of the pages // XXX Many of the values here are hard-coded // Eventually a proper font rendering engine should take care of things like this... -HaaTa @@ -681,7 +681,7 @@ void LCD_layerStackExact_capability( uint8_t state, uint8_t stateType, uint8_t * for ( uint16_t layer = 0; layer < stack_args->numArgs; layer++ ) { layerIndex = stack_args->layers[ layer ]; - + // Default to 0, if over 9 if ( layerIndex > 9 ) { From 080fb5408c7883b74a256139f5681ca40aa2a968 Mon Sep 17 00:00:00 2001 From: Cui Yuting Date: Fri, 13 May 2016 12:31:22 +0800 Subject: [PATCH 16/16] Fixed an error when the bitmap has 2 or more pages. --- Scan/STLcd/lcd_scan.c | 63 +++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 12103de3f..c9685dab8 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -528,7 +528,7 @@ void STLcd_sync() { { // next page STLcdSyncStage = 0; STLcdSyncPageCurrent++; - if (STLcdSyncPageCurrent >= STLcdSyncPageMax ) + if ( STLcdSyncPageCurrent >= STLcdSyncPageMax ) { // has finished STLcdSync = 0; return; @@ -787,6 +787,7 @@ void STLcd_drawBitmap( const uint8_t *bitmap, uint8_t x, uint8_t y, uint8_t widt ( y + height <= LCD_HEIGHT ) ? height : ( LCD_HEIGHT - y ); uint8_t srcpages = ( remainheight + 7 ) / 8; + uint8_t page = 0; if ( y & 0x07 ) { uint8_t highbits = y & 0x07; @@ -797,53 +798,57 @@ void STLcd_drawBitmap( const uint8_t *bitmap, uint8_t x, uint8_t y, uint8_t widt buffer[ column ] = ( buffer[ column ] & mask ) | ( bitmap[ column ] << highbits ); } remainheight -= 8 - highbits; - for ( uint8_t page = 0; remainheight > 7; page++, remainheight -= 8 ) + page++; + for ( ; remainheight > 7; page++, remainheight -= 8 ) { for ( uint8_t column = 0; column < maxcolumn; column++ ) { - buffer[ (page + 1 ) * LCD_PAGE_LEN + column ] = - ( bitmap[ page * width + column ] >> ( 8 - highbits ) ) - | ( bitmap[ ( page + 1 ) * width + column ] << highbits ); + buffer[ page * LCD_PAGE_LEN + column ] = + ( bitmap[ ( page - 1 ) * width + column ] >> ( 8 - highbits ) ) + | ( bitmap[ page * width + column ] << highbits ); } } if ( remainheight > 0 ) { mask = ~STLcdDrawMasks[ remainheight ][ 0 ]; - uint8_t page = srcpages - 1; - for ( uint8_t column = 0; column < maxcolumn; column++ ) + if ( page == srcpages ) + { + for ( uint8_t column = 0; column < maxcolumn; column++ ) + { + buffer[ page * LCD_PAGE_LEN + column ] = + ( bitmap[ ( page - 1 ) * width + column ] >> ( 8 - highbits ) ) + | ( buffer[ page * LCD_PAGE_LEN + column ] & mask ); + } + } + else { - buffer[ ( page + 1 ) * LCD_PAGE_LEN + column ] = - ( bitmap[ page * width + column ] >> ( 8 - highbits ) ) - | ( buffer[ ( page + 1 ) * LCD_PAGE_LEN + column ] & mask ); + for ( uint8_t column = 0; column < maxcolumn; column++ ) + { + buffer[ page * LCD_PAGE_LEN + column ] = + ( bitmap[ page * width + column ] << highbits ) + | ( bitmap[ ( page - 1 ) * width + column ] >> ( 8 - highbits ) ) + | ( buffer[ page * LCD_PAGE_LEN + column ] & mask ); + } } } } else { - if ( remainheight & 0x07 ) + uint8_t page = 0; + for ( page = 0; remainheight > 7; page++, remainheight -= 8 ) + { + memcpy( buffer + page * LCD_PAGE_LEN, + bitmap + page * width, + maxcolumn ); + } + if ( remainheight > 0 ) { - for ( uint8_t page = 0; page < srcpages - 1; page++ ) - { - memcpy( buffer + page * LCD_PAGE_LEN, - bitmap + page * width, - maxcolumn ); - } - remainheight = remainheight & 0x07; uint8_t mask = ~STLcdDrawMasks[ remainheight ][ 0 ]; for ( uint8_t column = 0; column < maxcolumn; column++ ) { - uint16_t destindex = ( srcpages - 1 ) * LCD_PAGE_LEN + column; + uint16_t destindex = page * LCD_PAGE_LEN + column; buffer[ destindex ] = ( buffer[ destindex ] & mask ) - | ( bitmap[ ( srcpages - 1 ) * width + column ] ); - } - } - else - { - for ( uint8_t page = 0; page < srcpages; page++ ) - { - memcpy( buffer + page * LCD_PAGE_LEN, - bitmap + page * width, - maxcolumn ); + | ( bitmap[ page * width + column ] ); } } }