From a6657c8aed1cd73fd361f93c0f8506e281e7c5e0 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sat, 18 Apr 2015 11:24:15 -0700 Subject: [PATCH] Adding example logo to the lcdtest and bmp conversion script. --- Scan/STLcd/bitmap2Struct.py | 195 ++++++++++++++++++++++++++++++++++++ Scan/STLcd/ic_logo_lcd.bmp | Bin 0 -> 6266 bytes Scan/STLcd/lcd_scan.c | 24 ++++- 3 files changed, 217 insertions(+), 2 deletions(-) create mode 100755 Scan/STLcd/bitmap2Struct.py create mode 100644 Scan/STLcd/ic_logo_lcd.bmp diff --git a/Scan/STLcd/bitmap2Struct.py b/Scan/STLcd/bitmap2Struct.py new file mode 100755 index 0000000..dcf30c6 --- /dev/null +++ b/Scan/STLcd/bitmap2Struct.py @@ -0,0 +1,195 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2015 by Jacob Alexander +# +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this file. If not, see . + +# Imports +import sys + +from array import * +from PIL import Image + + +# Convenience class to deal with converting images to a C array +class STLcdGraphic: + # Some constants for the LCD Driver + page_width = 8 + page_max_length = 132 + + array('B') + + def __init__( self, height, width ): + self.height = height + self.width = width + + # Calculate number of pages + self.page_count = int( self.height / self.page_width ) + self.page_length = self.width + + # Initialize pages to 0's + self.page_data = [] + for page in range( 0, self.page_count ): + self.page_data.append( array( 'B', [0] * self.page_length ) ) + + def setpixel( self, x, y ): + # Calculate which page + page = int( ( self.height - y ) / self.page_width ) + + if page == 4: + print("YAR", (x,y)) + + # Calculate which byte + byte = x + + # Calculate which bit + bit = int( ( self.height - y ) % self.page_width ) + + # Set pixel bit + self.page_data[ page ][ byte ] |= (1 << bit) + + def getpage( self, page ): + return self.page_data[ page ] + + def getarray( self ): + struct = "{\n" + + for page in range( 0, self.page_count ): + for elem in self.page_data[ page ]: + struct += "0x{0:02x}, ".format( elem ) + + if page != self.page_count - 1: + struct += "\n" + + struct += "\n}" + + return struct + + # Prints out what the image will look like on the display + def preview( self ): + # Top border first + display = "+" + for pixel in range( 0, self.width ): + display += "-" + display += "+\n" + + # Each Page + for page in range( self.page_count - 1, -1, -1 ): + # Each Bit (Line) + for line in range( 7, -1, -1 ): + # Border + display += "|" + + # Each Byte (Column/Pixel) + for byte in range( 0, self.width ): + if self.page_data[ page ][ byte ] & (1 << line): + display += "*" + else: + display += " " + + # Border + display += "|\n" + + # Bottom border + display += "+" + for pixel in range( 0, self.width ): + display += "-" + display += "+\n" + + return display + + +filename = "ic_logo_lcd.bmp" +max_height = 32 +max_width = 128 +x_offset = 0 +y_offset = 0 +output_image = STLcdGraphic( max_height, max_width ) + + + +# 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 ) ) + +# Check the image size to see if within the bounds of the display +if input_image.size[0] > max_width or input_image.size[1] > max_height: + print( "ERROR: '{0}:{1}' is too large, must be no larger than {2}x{3}".format( + filename, + ( input_image.format, input_image.size, input_image.mode ), + max_width, + max_height ) + ) + sys.exit( 1 ) + +# Center the image +height_start = int( ( max_height - input_image.size[1] ) / 2 ) +height_end = int( height_start + input_image.size[1] ) +width_start = int( ( max_width - input_image.size[0] ) / 2 ) +width_end = int( width_start + input_image.size[0] ) + +#print( height_start ) +#print( height_end ) +#print( width_start ) +#print( width_end ) + +# Iterate over all of the pixels +# Also prepare the debug view of the image (disp_test) +disp_test = "+" +for pixel in range( 0, max_width ): + disp_test += "-" +disp_test += "+\n" + +for y in range( 0, max_height ): + disp_test += "|" + + # Check if within height range + if not ( y >= height_start and y < height_end ): + disp_test += " " * max_width + "|\n|" + continue + + for x in range( 0, max_width ): + # Check if within width range + if not ( x >= width_start and x < width_end ): + disp_test += " " + continue + + # Use image value to determine pixel + try: + if input_image.getpixel( (x - width_start, y - height_start) ) == 0: + disp_test += "*" + output_image.setpixel( x, y + 1 ) # +1 is due to page boundary + else: + disp_test += " " + except IndexError: + print( (x - width_start,y - height_start) ) + pass + + disp_test += "|\n" + +disp_test += "+" +for pixel in range( 0, max_width ): + disp_test += "-" +disp_test += "+\n" + +# BMP Conversion preview +print( disp_test ) + + +print ( output_image.preview() ) +#print () +print( "uint8_t array[] = {0};".format( output_image.getarray() ) ) + diff --git a/Scan/STLcd/ic_logo_lcd.bmp b/Scan/STLcd/ic_logo_lcd.bmp new file mode 100644 index 0000000000000000000000000000000000000000..0682013cb958f01ce6ee788117aac98489479168 GIT binary patch literal 6266 zcmeH@I}XA?3`7GxJtap$X{cy82OV85%5f4afHd+*BdoPMue4eJG@iWqzMQB1EcSic zz1qFlJxt$*J@3=!T6sV7?eY4>|Gq~(xMm-{F1?#=e@%C&1>3(PpmC*l-S+V`-Jup7 zH|!MLI@cXfqx#kJ(Lbv86V-43nn09ibY5@gZtF7>tTZ2_!Ey6pCRk}cNQ2|%!%VQ! ze2@mm&4-y_rTHKYj-!04=h>mIRQrkQYq#8u>Q~RRLtUx%6V=ylx!d~81S^hDb&9J~ e;%dWAKgBbOIQ{ArSEt0)hMj(jXB2Vz>FEaP+>`?V literal 0 HcmV?d00001 diff --git a/Scan/STLcd/lcd_scan.c b/Scan/STLcd/lcd_scan.c index 5cc7c89..b5123c9 100644 --- a/Scan/STLcd/lcd_scan.c +++ b/Scan/STLcd/lcd_scan.c @@ -32,7 +32,7 @@ // ----- Defines ----- #define LCD_TOTAL_VISIBLE_PAGES 4 -#define LCD_PAGE_LEN 132 +#define LCD_PAGE_LEN 128 @@ -158,6 +158,13 @@ void LCD_writeDisplayReg( uint8_t page, uint8_t *buffer, uint8_t len ) // Set the register page LCD_writeControlReg( 0xB0 | ( 0x0F & page ) ); + // Set display start line + LCD_writeControlReg( 0x40 ); + + // Reset Column Address + LCD_writeControlReg( 0x10 ); + LCD_writeControlReg( 0x00 ); + // Write buffer to SPI SPI_write( buffer, len ); } @@ -295,10 +302,23 @@ void cliFunc_lcdTest( char* args ) //LCD_initialize(); // Test pattern uint8_t pattern[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + + +uint8_t logo[] = { +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, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 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, +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, 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, 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, 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, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 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, 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, 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, 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, +}; //uint8_t pattern[] = { 0xFF, 0x00, 0x96, 0xFF, 0x00, 0xFF, 0x00 }; // Write to page D0 - LCD_writeDisplayReg( 0, pattern, sizeof( pattern ) ); + //LCD_writeDisplayReg( 0, pattern, sizeof( pattern ) ); + + for ( uint8_t page = 0; page < LCD_TOTAL_VISIBLE_PAGES; page++ ) + { + LCD_writeDisplayReg( page, &logo[page * LCD_PAGE_LEN], LCD_PAGE_LEN ); + } } void cliFunc_lcdCmd( char* args ) -- 2.39.2