Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display buffer for the ergodox LCD and a Non-blocking sync routine. #115

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ void delay(uint32_t ms)
yield();
}
}

35 changes: 35 additions & 0 deletions Lib/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// ----- System Includes -----

#include <stdint.h>
#include "mk20dx.h"



Expand All @@ -56,6 +57,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)
Expand Down Expand Up @@ -84,3 +90,32 @@ 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)
{
// 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;
}
}

static inline uint32_t ticks(void) __attribute__((always_inline, unused));
static inline uint32_t ticks(void)
{
return SYST_CVR;
}
27 changes: 27 additions & 0 deletions Scan/STLcd/4x6FontLicense
Original file line number Diff line number Diff line change
@@ -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.
Binary file added Scan/STLcd/4x6font.bmp
Binary file not shown.
146 changes: 146 additions & 0 deletions Scan/STLcd/bitmapfont2Struct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/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
# 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 <http://www.gnu.org/licenses/>.

# 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 + 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
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 = newy // 8 * glyph_width + x

# Calculate which bit
bit = 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] )
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 0 0'" )
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 ) // ( 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 + 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 + 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 += " "
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 + bitmap_spacing ),
y % ( glyph_height + bitmap_linespacing ) )
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 ) )
13 changes: 13 additions & 0 deletions Scan/STLcd/capabilities.kll
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ 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,
";

STLcdDefaultFont => STLcdDefaultFont_define;
STLcdDefaultFontWidth => STLcdDefaultFontWidth_define;
STLcdDefaultFontHeight => STLcdDefaultFontHeight_define;
STLcdDefaultFontSize => STLcdDefaultFontSize_define;
STLcdDefaultFontLength => STLcdDefaultFontLength_define;

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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x02, 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 = 3;
STLcdDefaultFontLength = 128;

# TTYOutputChar => TTY_outputChar_capability(charactor : 1);

# Layer Status Display

Expand Down
Loading