Firmware initial import

This commit is contained in:
James Bowman 2019-02-10 06:46:36 -08:00
parent 4c24651883
commit d84c5628cf
20 changed files with 2240 additions and 0 deletions

7
firmware/README.md Normal file
View File

@ -0,0 +1,7 @@
This is the firmware for the SPIDriver.
It uses the [MyForth](http://www.kiblerelectronics.com/myf/myf.shtml) compiler written by
Charley Shattuck and Bob Nash.
To compile the fonts go into ``st7735s``
and unpack the [IBM Plex OpenType](https://github.com/IBM/plex/releases) font set.
then run ``mkfont.py``. This builds the font sources in ``fonts.fs``

Binary file not shown.

BIN
firmware/assets/arrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

BIN
firmware/assets/dot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B

3
firmware/assets/go Executable file
View File

@ -0,0 +1,3 @@
set -e
python2 mkfont.py

BIN
firmware/assets/hex4x5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

BIN
firmware/assets/larrow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 B

131
firmware/assets/mkfont.py Executable file
View File

@ -0,0 +1,131 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PIL import Image, ImageDraw, ImageFont
import numpy as np
import struct
import random
def rand(n):
return random.randrange(n)
def as565(im):
""" Return RGB565 of im """
(r,g,b) = [np.array(c).astype(np.uint16) for c in im.split()]
def s(x, n):
return x * (2 ** n - 1) / 255
return (s(b, 5) << 11) | (s(g, 6) << 5) | s(r, 5)
def c3(rgb):
return (16 * (0xf & (rgb >> 8)),
16 * (0xf & (rgb >> 4)),
16 * (0xf & (rgb >> 0)))
font2 = ImageFont.truetype("IBMPlexSans-SemiBold.otf", 13)
fontSP = ImageFont.truetype("pf_ronda_seven_bold.ttf", 8)
def pad2(s):
if len(s) % 2:
s.append(s[0])
return s
def rfont2(c):
im = Image.new("L", (128, 160))
dr = ImageDraw.Draw(im)
dr.text((10,40), c, font=font2, fill=255)
# im.save("out.png")
extents = im.getbbox()
assert 10 <= extents[0]
assert 45 <= extents[1]
if c in "0123456789":
extents = (0, 0, 10 + 8, 45 + 9)
im = im.crop((10, 45) + extents[2:])
(w,h) = im.size
nyb = pad2((np.array(im).astype(int).flatten() * 15 / 255).tolist())
return [w,h] + nyb
def rf(c, font):
im = Image.new("L", (128, 160))
dr = ImageDraw.Draw(im)
dr.text((10,40), c, font=font, fill=255)
# im.save("out.png")
extents = im.getbbox()
im = im.crop(extents)
(w,h) = im.size
nyb = (np.array(im).astype(int).flatten() * 15 / 255).tolist()
return [w,h] + nyb
fs = open("../font.fs", "wt")
fb = 0
if __name__ == '__main__':
fs.write('here constant tplan\n')
fs.write('%d , %d , $%x%x , $%x , ," %s"\n' % (60, 0, 0xf, 0xf, 0xf, "V"))
fb += 5 + len("V")
# fs.write("[ %d ]\n" % fb)
fs.write('%d , %d , $%x%x , $%x , ," %s"\n' % (108, 0, 0xf, 0xf, 0xf, "mA"))
fb += 5 + len("mA")
# fs.write("[ %d ]\n" % fb)
fs.write('0 ,\n')
fb += 1
# im.save("out.png")
uniq = "".join(sorted(set("0123456789.mAVDMCS")))
f2 = sum([rfont2(c) for c in uniq], [])
print "font2 %s takes %d bytes" % (uniq, len(f2) / 2)
def nybbles(nn):
s = len(nn)
assert s % 2 == 0
b = ["$%x%x ," % tuple(nn[i:i+2]) for i in range(0, s, 2)]
return b
fs.write('here constant font\n')
for c in uniq:
bb = nybbles(rfont2(c))
print >>fs, "'%s' , " % c, " ".join(bb)
fb += 1 + len(bb)
# See http://angband.pl/font/tinyfont.html
fs.write("\nhere constant micro\n")
if 1:
tiny = Image.open("hex4x5.png").convert("L")
for i in range(16):
x = 5 * i
im = tiny.crop((x, 0, x + 4, 5))
rim = im.transpose(Image.ROTATE_90)
ch = ((np.array(rim)).flatten() * 15.99 / 255).astype(np.uint8).tolist()
fs.write(" ".join(nybbles(ch)) + "\n")
fb += len(ch) / 2
if 1:
# Image.open("arrow.png").transpose(Image.FLIP_LEFT_RIGHT).save("larrow.png")
for n in ("symbol-s", "symbol-p", "symbol-b", "arrow", "larrow", "dot", "label-sda", "label-scl"):
im = Image.open(n + ".png").convert("L")
if n.startswith("label-"):
im = im.point([0] + 254 * [64] + [255])
rim = im.transpose(Image.ROTATE_90)
(w,h) = rim.size
ch = [w,h] + pad2(((np.array(rim)).flatten() * 15.99 / 255).astype(np.uint8).tolist())
fs.write("here constant %s \n" % n)
fs.write(" ".join(nybbles(ch)) + "\n")
fb += len(ch) / 2
if 1:
w = 72
gpng = "plasma.png"
grad = Image.open(gpng).convert("RGB").resize((w, 1), Image.BILINEAR).load()
fs.write("\nHERE constant grad\n")
for x in range(w):
(r,g,b) = grad[x,0]
r = (r * 15) // 255
g = (g * 15) // 255
b = (b * 15) // 255
fs.write('$%x%x , $%x ,\n' % (r, g, b))
fb += 2 * w
fs.close()
fs = open("../fontsize.fs", "wt")
fs.write("&%d constant FONTDATA_SIZE\n" % fb)
fs.close()

Binary file not shown.

BIN
firmware/assets/plasma.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

259
firmware/capture.fs Normal file
View File

@ -0,0 +1,259 @@
here constant CAPTURE-START
[
: fake ( a - u )
dup 0= ] here [ and or ;
]
:m :: ( - )
[ >in @ label >in !
create ] here [ , hide
does> @ ] m;
\ jump if bit is 0 or 1 ( addr bit )
:m j1 ( addr bit ) [ swap fake swap ] 0=until. m;
:m j0 ( addr bit ) [ swap fake swap ] until. m;
:m j ( addr ) fake again m;
:m tx SBUF0 (#!) clra TMR3H (#!) m;
:m SDA0 ( a ) SDA j0 m;
:m SDA1 ( a ) SDA j1 m;
fwd L00.0
fwd L00.1
fwd L00.2
fwd H00.0
fwd H00.1
fwd H00.2
fwd HS
fwd HP
fwd LP
fwd LS
:m escape RI0 if. RI0 clr ; then m;
:: L11 begin LS SDA0 SCL 0=until.
:: Lidle begin begin SDA until. SCL until.
L11 j
:: L10.0 3 .t set
begin L00.0 SDA0 SCL until. begin LS SDA0 SCL 0=until. 2 .t set
:: L10.1 begin L00.1 SDA0 SCL until. begin LS SDA0 SCL 0=until. 1 .t set
:: L10.2 begin L00.2 SDA0 SCL until. begin LS SDA0 SCL 0=until. 0 .t set
tx
:: H10.0 7 .t set
:: klak begin H00.0 SDA0 SCL until. begin HS SDA0 SCL 0=until. 6 .t set
:: H10.1 begin H00.1 SDA0 SCL until. begin HS SDA0 SCL 0=until. 5 .t set
:: H10.2 begin H00.2 SDA0 SCL until. begin HS SDA0 SCL 0=until. 4 .t set
L10.0 j
:: LS $f0 # and $01 # ior tx ( start )
:: LS2 begin HP SDA1 SCL 0=until.
H00.0 j
:: HS $10 (#) ( start )
:: HS2 begin LP SDA1 SCL 0=until.
:: L00.0 3 .t set
begin L10.0 SDA1 SCL until. begin LP SDA1 SCL 0=until.
:: L00.1 begin L10.1 SDA1 SCL until. begin LP SDA1 SCL 0=until.
:: L00.2 begin L10.2 SDA1 SCL until. begin LP SDA1 SCL 0=until.
tx
:: H00.0 7 .t set
begin H10.0 SDA1 SCL until. begin HP SDA1 SCL 0=until.
:: H00.1 begin H10.1 SDA1 SCL until. begin HP SDA1 SCL 0=until.
:: H00.2 begin H10.2 SDA1 SCL until. begin HP SDA1 SCL 0=until.
L00.0 j
:: HP $20 (#)
\ L11 j
begin SDA 0=until.
escape
HS2 j
: (warm)
:: H11 begin HS SDA0 SCL 0=until.
:: Hidle begin begin SDA until. SCL until.
H11 j
:: LP $f0 # and $02 # ior tx
\ H11 j
begin SDA 0=until.
escape
LS2 j
: /timer3
$80 # EIE1 ior! \ Timer 3 interrupt enable
;
: timer3\
$80 ~# EIE1 and! \ Timer 3 interrupt disable
;
:m timer3
SBUF0 (#!) clra
$7f # TMR3CN and!
RI0 if.
RI0 clr
[ sp dec ]
[ sp dec ]
then
[ reti ] m;
: capture
[ IE push ]
[ ET2 clr ] \ Timer 2 interrupt disable
[ ES0 clr ] \ UART interrupt disable
\i2chw
[ clra ]
[ FL1 set ] t3+
(warm)
t3- [ FL1 clr ]
/i2chw
[ IE pop ]
;
\ This code all runs in register bank 1:
\ 0 scratch for heatmap
\ 1 log
\ 2
\ 3 prev cmd
\ 4 constant 72, for heatmap
\ 5
\ 6
\ 7 caller acc save
\
\ FL0 set means this is an address byte
fwd M00.0
fwd M10.0
fwd M10.1
fwd M10.2
fwd M10.3
fwd M10.4
fwd M10.5
fwd M10.6
fwd M10.7
fwd M10.8
fwd Mt
fwd MP
:m (l!) $f3 , m;
:m (log!)
$f3 , a+ m;
:m wrap
$7f # 9 and! m;
:m heat
\ byte is in t
FL0 if.
setc 2/'
0 (#!)
4 (#@) $f2 ,
then
m;
:m escape
7 (#@)
[
dirty set
PSW pop
reti
]
m;
:: MP
$00 (#) (log!)
$01 (#) (log!)
wrap
escape
begin SDA 0=until.
: (mismatch)
:: Mt
begin MP SDA1 SCL 0=until.
$82 # 3 #! FL0 set
M00.0 j
:: M00.6 begin M10.6 SDA1 SCL until. begin MP SDA1 SCL 0=until.
:: M00.7 begin M10.7 SDA1 SCL until. begin MP SDA1 SCL 0=until. (l!)
:: M00.8 begin M10.8 SDA1 SCL until. begin MP SDA1 SCL 0=until. heat
a+ 3 (#@) (l!) a+ wrap
$83 # 3 #! FL0 clr
M00.0 j
:: M10.6 begin M00.6 SDA0 SCL until. begin Mt SDA0 SCL 0=until. 1 .t set
:: M10.7 begin M00.7 SDA0 SCL until. begin Mt SDA0 SCL 0=until. 1+ (l!)
:: M10.8 begin M00.8 SDA0 SCL until. begin Mt SDA0 SCL 0=until.
a+ 3 (#@) $7f # and (l!) a+ wrap
$83 # 3 #! FL0 clr
M10.0 j
:: MP3 MP j
:: Mt3 Mt j
:: M00.3 begin M10.3 SDA1 SCL until. begin MP3 SDA1 SCL 0=until.
:: M00.4 begin M10.4 SDA1 SCL until. begin MP3 SDA1 SCL 0=until.
:: M00.5 begin M10.5 SDA1 SCL until. begin MP3 SDA1 SCL 0=until.
M00.6 j
:: M10.3 begin M00.3 SDA0 SCL until. begin Mt3 SDA0 SCL 0=until. 4 .t set
:: M10.4 begin M00.4 SDA0 SCL until. begin Mt3 SDA0 SCL 0=until. 3 .t set
:: M10.5 begin M00.5 SDA0 SCL until. begin Mt3 SDA0 SCL 0=until. 2 .t set
M10.6 j
:: MP0 MP j
:: Mt0 Mt j
: (warm)
:: M00.0 clra
begin M10.0 SDA1 SCL until. begin MP0 SDA1 SCL 0=until.
:: M00.1 begin M10.1 SDA1 SCL until. begin MP0 SDA1 SCL 0=until.
:: M00.2 begin M10.2 SDA1 SCL until. begin MP0 SDA1 SCL 0=until.
M00.3 j
:: M10.0 clra
begin M00.0 SDA0 SCL until. begin Mt0 SDA0 SCL 0=until. 7 .t set
:: M10.1 begin M00.1 SDA0 SCL until. begin Mt0 SDA0 SCL 0=until. 6 .t set
:: M10.2 begin M00.2 SDA0 SCL until. begin Mt0 SDA0 SCL 0=until. 5 .t set
M10.3 j
: /monitor
[ ET2 clr ] \ Timer 2 interrupt disable
[ ES0 clr ] \ UART interrupt disable
\i2chw
t3i- t3+ \ Timer3 running, no intr
%00000100 # P0MASK #!
%00000100 # P0MAT #! \ SDA high
%00010000 # P1MASK #!
%00010000 # P1MAT #! \ SCL high
\ constants in registers
72 # [ 4 8 + ] #!
$02 # EIE1 ior! \ EMAT
;
: \monitor
$02 ~# EIE1 and! \ EMAT off
[ ET2 set ] \ Timer 2 interrupt enable
[ ES0 set ] \ UART interrupt enable
t3i+ t3- \ Timer3 stopped, intr
/i2chw
;
:m mismatch
[
PSW push
RS0 set
]
7 (#!)
Mt j
m;
here [
CAPTURE-START xor 11 rshift 0<>
[IF]
cr .( Capture block cannot cross a 2K boundary)
abort
[THEN]
]

131
firmware/font.fs Normal file
View File

@ -0,0 +1,131 @@
here constant tplan
60 , 0 , $ff , $f , ," V"
108 , 0 , $ff , $f , ," mA"
0 ,
here constant font
'.' , $49 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $03 , $20 , $2f , $e0 , $0c , $b0 ,
'0' , $89 , $01 , $9d , $d8 , $00 , $0c , $fc , $df , $90 , $4f , $b0 , $0d , $e1 , $7f , $70 , $0b , $f4 , $9f , $70 , $0a , $f5 , $7f , $70 , $0b , $f4 , $4f , $a0 , $0d , $e1 , $0c , $fb , $cf , $90 , $01 , $ad , $d8 , $00 ,
'1' , $89 , $00 , $af , $f7 , $00 , $09 , $fd , $f7 , $00 , $6f , $a7 , $f7 , $00 , $07 , $07 , $f7 , $00 , $00 , $07 , $f7 , $00 , $00 , $07 , $f7 , $00 , $00 , $07 , $f7 , $00 , $09 , $9c , $fc , $95 , $0e , $ff , $ff , $f8 ,
'2' , $89 , $02 , $ae , $d8 , $00 , $1d , $fc , $ef , $90 , $3b , $70 , $3f , $e0 , $00 , $00 , $4f , $c0 , $00 , $02 , $de , $40 , $00 , $4d , $e4 , $00 , $06 , $ed , $30 , $00 , $4f , $fb , $aa , $a2 , $5f , $ff , $ff , $f3 ,
'3' , $89 , $04 , $ce , $d7 , $00 , $3e , $eb , $df , $80 , $05 , $10 , $5f , $b0 , $00 , $6b , $dd , $30 , $00 , $9f , $fc , $20 , $00 , $00 , $6f , $c0 , $2a , $10 , $2f , $e0 , $8f , $eb , $df , $80 , $07 , $ce , $c7 , $00 ,
'4' , $89 , $00 , $05 , $ff , $40 , $00 , $1d , $ff , $40 , $00 , $8e , $cf , $40 , $03 , $e8 , $9f , $40 , $0c , $d0 , $9f , $40 , $6f , $50 , $9f , $40 , $bf , $ff , $ff , $f7 , $69 , $99 , $cf , $a4 , $00 , $00 , $9f , $40 ,
'5' , $89 , $0c , $ff , $ff , $c0 , $0d , $eb , $bb , $90 , $0e , $a0 , $00 , $00 , $0f , $aa , $eb , $20 , $1f , $fb , $df , $d0 , $02 , $20 , $0d , $f3 , $07 , $40 , $0d , $f2 , $2e , $eb , $df , $b0 , $03 , $be , $d8 , $10 ,
'6' , $89 , $00 , $1a , $fc , $10 , $00 , $cf , $90 , $00 , $09 , $f8 , $00 , $00 , $1e , $da , $eb , $30 , $5f , $fb , $bf , $d0 , $7f , $a0 , $0c , $f4 , $5f , $a0 , $0c , $f3 , $0c , $eb , $bf , $b0 , $01 , $ad , $d9 , $10 ,
'7' , $89 , $5f , $ff , $ff , $f2 , $5f , $ba , $ae , $f2 , $5f , $50 , $3f , $c0 , $14 , $10 , $9f , $50 , $00 , $01 , $ee , $00 , $00 , $07 , $f8 , $00 , $00 , $0d , $e2 , $00 , $00 , $5f , $a0 , $00 , $00 , $bf , $40 , $00 ,
'8' , $89 , $03 , $be , $d9 , $10 , $1e , $ea , $bf , $c0 , $2f , $a0 , $0d , $e0 , $09 , $e9 , $ae , $60 , $06 , $ef , $fd , $40 , $5f , $b1 , $2d , $e2 , $7f , $80 , $0c , $f4 , $2e , $ea , $bf , $d0 , $03 , $be , $da , $20 ,
'9' , $89 , $02 , $ae , $d8 , $00 , $1d , $eb , $cf , $90 , $6f , $90 , $0d , $f1 , $7f , $80 , $0d , $f3 , $3e , $ea , $bf , $f2 , $05 , $ce , $af , $d0 , $00 , $00 , $af , $50 , $00 , $1b , $f9 , $00 , $02 , $df , $80 , $00 ,
'A' , $99 , $00 , $0e , $fa , $00 , $00 , $04 , $ff , $e1 , $00 , $00 , $9f , $9f , $50 , $00 , $0e , $c2 , $fb , $00 , $05 , $f7 , $0c , $e1 , $00 , $af , $ff , $ff , $60 , $1e , $eb , $bb , $fb , $06 , $f8 , $00 , $0d , $f1 , $bf , $40 , $00 , $8f , $70 ,
'C' , $99 , $00 , $5b , $ec , $70 , $00 , $6f , $ec , $ef , $80 , $1e , $e2 , $01 , $c7 , $04 , $fa , $00 , $00 , $00 , $6f , $90 , $00 , $00 , $04 , $fa , $00 , $00 , $00 , $1e , $e1 , $01 , $d8 , $00 , $7f , $ec , $ef , $80 , $00 , $6c , $ec , $60 , $00 ,
'D' , $99 , $1f , $ff , $eb , $50 , $01 , $fe , $cc , $ef , $60 , $1f , $d0 , $02 , $ee , $01 , $fd , $00 , $0b , $f3 , $1f , $d0 , $00 , $af , $51 , $fd , $00 , $0b , $f3 , $1f , $d0 , $01 , $ee , $11 , $fe , $bc , $ef , $60 , $1f , $ff , $eb , $50 , $01 ,
'M' , $a9 , $1f , $f5 , $00 , $0a , $fa , $1f , $fc , $00 , $3f , $fa , $1f , $ff , $60 , $bf , $fa , $1f , $dd , $d5 , $fb , $fa , $1f , $c6 , $fe , $e4 , $fa , $1f , $c0 , $cf , $63 , $fa , $1f , $c0 , $4d , $03 , $fa , $1f , $c0 , $02 , $03 , $fa , $1f , $c0 , $00 , $03 , $fa ,
'S' , $89 , $02 , $ad , $da , $20 , $0d , $fd , $df , $e1 , $4f , $b0 , $04 , $30 , $2e , $e8 , $51 , $00 , $05 , $df , $ff , $80 , $00 , $02 , $5d , $f4 , $08 , $30 , $0a , $f5 , $5f , $fd , $df , $d1 , $04 , $be , $da , $20 ,
'V' , $99 , $cf , $30 , $00 , $de , $17 , $f8 , $00 , $3f , $b0 , $2f , $d0 , $08 , $f6 , $00 , $cf , $20 , $de , $10 , $06 , $f7 , $2f , $b0 , $00 , $1f , $b6 , $f6 , $00 , $00 , $be , $ce , $10 , $00 , $06 , $ff , $a0 , $00 , $00 , $1e , $f5 , $00 , $0c ,
'm' , $b9 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $2f , $ba , $ea , $1a , $ea , $12 , $ff , $bd , $fe , $bd , $f8 , $2f , $c0 , $3f , $c0 , $3f , $b2 , $fb , $02 , $fb , $02 , $fc , $2f , $b0 , $2f , $b0 , $2f , $c2 , $fb , $02 , $fb , $02 , $fc , $2f , $b0 , $2f , $b0 , $2f , $c0 ,
here constant micro
$4f , $ff , $4f , $00 , $0f , $f0 , $00 , $f4 , $ff , $f4 ,
$00 , $00 , $0f , $ff , $ff , $f0 , $00 , $00 , $00 , $00 ,
$4f , $40 , $ff , $0f , $0f , $f0 , $f0 , $ff , $04 , $ff ,
$4f , $4f , $4f , $0f , $0f , $f0 , $f0 , $ff , $04 , $0f ,
$ff , $ff , $f0 , $0f , $00 , $00 , $f0 , $0f , $ff , $00 ,
$f0 , $4f , $4f , $0f , $0f , $f0 , $f0 , $ff , $ff , $0f ,
$40 , $4f , $4f , $0f , $0f , $f0 , $f0 , $f4 , $ff , $f4 ,
$ff , $00 , $0f , $0f , $00 , $f0 , $0f , $ff , $00 , $00 ,
$4f , $4f , $4f , $0f , $0f , $f0 , $f0 , $f4 , $f4 , $f4 ,
$4f , $ff , $4f , $0f , $0f , $f0 , $f0 , $f4 , $f4 , $04 ,
$4f , $ff , $ff , $0f , $00 , $f0 , $f0 , $04 , $ff , $ff ,
$4f , $4f , $4f , $0f , $0f , $f0 , $f0 , $ff , $ff , $ff ,
$4f , $0f , $4f , $00 , $0f , $f0 , $00 , $f4 , $ff , $f4 ,
$4f , $ff , $4f , $00 , $0f , $f0 , $00 , $ff , $ff , $ff ,
$00 , $00 , $0f , $0f , $0f , $f0 , $f0 , $ff , $ff , $ff ,
$00 , $00 , $0f , $0f , $00 , $f0 , $f0 , $0f , $ff , $ff ,
here constant symbol-s
$bc , $00 , $17 , $ce , $d8 , $20 , $00 , $2b , $ff , $ff , $fc , $30 , $0a , $ff , $ff , $ff , $fb , $15 , $fd , $0f , $d0 , $0d , $f6 , $af , $00 , $f0 , $00 , $0f , $cc , $f0 , $ff , $0f , $f0 , $fe , $cf , $0f , $f0 , $ff , $0f , $e9 , $f0 , $00 , $0f , $00 , $fb , $4e , $d0 , $0d , $f0 , $df , $60 , $9f , $ff , $ff , $ff , $a1 , $01 , $9f , $ff , $ff , $b2 , $00 , $00 , $5b , $db , $61 , $00 ,
here constant symbol-p
$bc , $00 , $17 , $ce , $d8 , $20 , $00 , $2b , $ff , $ff , $fc , $30 , $0a , $ff , $ff , $ff , $fb , $15 , $fd , $00 , $df , $ff , $f6 , $af , $00 , $00 , $ff , $ff , $cc , $f0 , $ff , $0f , $ff , $fe , $cf , $0f , $f0 , $ff , $ff , $e9 , $f0 , $00 , $00 , $00 , $fb , $4e , $00 , $00 , $00 , $0f , $60 , $9f , $ff , $ff , $ff , $a1 , $01 , $9f , $ff , $ff , $b2 , $00 , $00 , $5b , $db , $61 , $00 ,
here constant symbol-b
$bc , $00 , $17 , $ce , $d8 , $20 , $00 , $2b , $ff , $ff , $fc , $30 , $0a , $ff , $ff , $ff , $fb , $15 , $ff , $ff , $ff , $ff , $f6 , $af , $ff , $ff , $ff , $ff , $cc , $f0 , $00 , $00 , $f0 , $fe , $cf , $00 , $00 , $0f , $0f , $e9 , $ff , $ff , $ff , $ff , $fb , $4e , $ff , $ff , $ff , $ff , $60 , $9f , $ff , $ff , $ff , $a1 , $01 , $9f , $ff , $ff , $b2 , $00 , $00 , $5b , $db , $61 , $00 ,
here constant arrow
$35 , $08 , $03 , $b3 , $8f , $8b , $fb , $ef , $e0 ,
here constant larrow
$35 , $ef , $eb , $fb , $8f , $83 , $b3 , $08 , $0e ,
here constant dot
$44 , $4c , $d5 , $bf , $fd , $bf , $fc , $3b , $b4 ,
here constant label-sda
$810 , $f0 , $00 , $00 , $00 , $f0 , $00 , $00 , $00 , $f0 , $4f , $ff , $f0 , $f0 , $f0 , $f0 , $00 , $f0 , $f0 , $f0 , $00 , $f0 , $4f , $ff , $f0 , $f0 , $00 , $00 , $00 , $f0 , $4f , $ff , $40 , $f0 , $f0 , $00 , $f0 , $f0 , $f0 , $00 , $f0 , $f0 , $ff , $ff , $f0 , $f0 , $00 , $00 , $00 , $f0 , $f0 , $4f , $40 , $f0 , $f0 , $f0 , $f0 , $f0 , $f0 , $f0 , $f0 , $f0 , $4f , $40 , $f0 ,
here constant label-scl
$810 , $f0 , $00 , $00 , $00 , $f0 , $00 , $00 , $00 , $f0 , $00 , $00 , $00 , $f0 , $00 , $00 , $f0 , $f0 , $00 , $00 , $f0 , $f0 , $ff , $ff , $f0 , $f0 , $00 , $00 , $00 , $f0 , $4f , $0f , $40 , $f0 , $f0 , $00 , $f0 , $f0 , $f0 , $00 , $f0 , $f0 , $4f , $ff , $40 , $f0 , $00 , $00 , $00 , $f0 , $f0 , $4f , $40 , $f0 , $f0 , $f0 , $f0 , $f0 , $f0 , $f0 , $f0 , $f0 , $4f , $40 , $f0 ,
HERE constant grad
$00 , $7 ,
$10 , $8 ,
$10 , $8 ,
$20 , $8 ,
$20 , $8 ,
$30 , $8 ,
$30 , $9 ,
$30 , $9 ,
$40 , $9 ,
$40 , $9 ,
$40 , $9 ,
$50 , $9 ,
$50 , $9 ,
$50 , $9 ,
$60 , $9 ,
$60 , $9 ,
$60 , $9 ,
$70 , $9 ,
$70 , $9 ,
$70 , $9 ,
$70 , $9 ,
$80 , $9 ,
$80 , $9 ,
$81 , $9 ,
$91 , $9 ,
$91 , $9 ,
$91 , $8 ,
$92 , $8 ,
$a2 , $8 ,
$a2 , $8 ,
$a2 , $8 ,
$a2 , $8 ,
$b3 , $7 ,
$b3 , $7 ,
$b3 , $7 ,
$b3 , $7 ,
$b4 , $7 ,
$c4 , $6 ,
$c4 , $6 ,
$c4 , $6 ,
$c5 , $6 ,
$c5 , $6 ,
$d5 , $5 ,
$d5 , $5 ,
$d6 , $5 ,
$d6 , $5 ,
$d6 , $5 ,
$d6 , $5 ,
$d7 , $4 ,
$e7 , $4 ,
$e7 , $4 ,
$e7 , $4 ,
$e8 , $4 ,
$e8 , $3 ,
$e8 , $3 ,
$e9 , $3 ,
$e9 , $3 ,
$e9 , $3 ,
$e9 , $3 ,
$ea , $2 ,
$ea , $2 ,
$ea , $2 ,
$eb , $2 ,
$eb , $2 ,
$eb , $2 ,
$ec , $2 ,
$ec , $2 ,
$ec , $2 ,
$ed , $2 ,
$ed , $2 ,
$ed , $2 ,
$ee , $2 ,

1
firmware/fontsize.fs Normal file
View File

@ -0,0 +1 @@
&1385 constant FONTDATA_SIZE

1010
firmware/main.fs Normal file

File diff suppressed because it is too large Load Diff

698
firmware/st7735.fs Normal file
View File

@ -0,0 +1,698 @@
$00 constant NOP $2B constant RASET $C2 constant PWCTR3
$01 constant SWRESET $2C constant RAMWR $C3 constant PWCTR4
$04 constant RDDID $2E constant RAMRD $C4 constant PWCTR5
$09 constant RDDST $30 constant PTLAR $C5 constant VMCTR1
$10 constant SLPIN $36 constant MADCTL $DA constant RDID1
$11 constant SLPOUT $3A constant COLMOD $DB constant RDID2
$12 constant PTLON $B1 constant FRMCTR1 $DC constant RDID3
$13 constant NORON $B2 constant FRMCTR2 $DD constant RDID4
$20 constant INVOFF $B3 constant FRMCTR3 $E0 constant GMCTRP1
$21 constant INVON $B4 constant INVCTR $E1 constant GMCTRN1
$28 constant DISPOFF $B6 constant DISSET5 $FC constant PWCTR6
$29 constant DISPON $C0 constant PWCTR1
$2A constant CASET $C1 constant PWCTR2
$80 constant DELAY
here constant init-table
SWRESET , DELAY , \ Software reset, 0 args, w/delay
60 ,
SLPOUT , DELAY , \ Out of sleep mode, 0 args, w/delay
60 ,
FRMCTR1 , 3 , \ Frame rate ctrl - normal mode, 3 args:
0x01 , 0x2C , 0x2D , \ Rate = fosc/(1x2+40) * (LINE+2C+2D)
FRMCTR2 , 3 , \ Frame rate control - idle mode, 3 args:
0x01 , 0x2C , 0x2D , \ Rate = fosc/(1x2+40) * (LINE+2C+2D)
FRMCTR3 , 6 , \ Frame rate ctrl - partial mode, 6 args:
0x01 , 0x2C , 0x2D , \ Dot inversion mode
0x01 , 0x2C , 0x2D , \ Line inversion mode
PWCTR1 , 3 , \ Power control, 3 args:
0xA2 ,
0x02 , \ -4.6V
0x84 , \ AUTO mode
PWCTR2 , 1 , \ Power control, 1 arg:
0xC5 , \ VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
PWCTR3 , 2 , \ Power control, 2 args:
0x0A , \ Opamp current small
0x00 , \ Boost frequency
PWCTR4 , 2 , \ Power control, 2 args:
0x8A , \ BCLK/2, Opamp current small & Medium low
0x2A ,
PWCTR5 , 2 , \ Power control, 2 args:
0x8A , 0xEE ,
VMCTR1 , 1 , \ Power control, 1 arg:
0x0E ,
MADCTL , 1 , \ Memory access control (directions), 1 arg:
0xC8 , \ row addr/col addr, bottom to top refresh
COLMOD , 1 , \ set color mode, 1 arg:
0x03 , \ 12-bit color
GMCTRP1 , 16 , \ Gamma + polarity Correction Characterstics
0x02 , 0x1c , 0x07 , 0x12 ,
0x37 , 0x32 , 0x29 , 0x2d ,
0x29 , 0x25 , 0x2B , 0x39 ,
0x00 , 0x01 , 0x03 , 0x10 ,
GMCTRN1 , 16 , \ Gamma - polarity Correction Characterstics
0x03 , 0x1d , 0x07 , 0x06 ,
0x2E , 0x2C , 0x29 , 0x2D ,
0x2E , 0x2E , 0x37 , 0x3F ,
0x00 , 0x00 , 0x02 , 0x10 ,
NORON , 0 , \ Normal display on
0 ,
:m clk [ 2 .p1 set 2 .p1 clr ] m;
:m 1bit 2*' 1 .p1 movcb clk m;
:m /C/ [ 0 .p1 clr ] m;
:m /D/ [ 0 .p1 set ] m;
: (>st) 1bit 1bit 1bit 1bit
: _4 1bit 1bit 1bit 1bit 2*' ;
: (4>st) 2*' 2*' 2*' 2*' _4 ;
: 4>st (4>st) drop ;
: write-cmd ( b ) /C/
: 1>st ( b ) 1bit 1bit 1bit 1bit 1bit 1bit 1bit 1bit drop ;
: write-data ( b ) /D/ 1>st ;
: data16 ( b ) 0# write-data write-data ;
: args
begin
0=if drop; then
@p+ write-data
1-
again
: coldregs
init-table ##p!
begin
@p+
0=if drop; then
write-cmd
@p+
dup $7f # and args
-if @p+ ms then
drop
again
here [ $1000 > throw ]
$1000 org
: dim ( x w )
over data16 + 1- data16 ;
: rect ( x y w h )
twist ( x w y h )
RASET # write-cmd dim
CASET # write-cmd dim
: writing
RAMWR # write-cmd
/D/
;
: full
blu #@ (4>st)
grn (#@) (4>st) red (#@) 4>st ;
:m |4>st 1bit 1bit 1bit 1bit m;
: half 10 #
: gray
0=if
drop
: dark
1 .p1 clr
clk clk clk clk
clk clk clk clk
clk clk clk clk ;
then
5 (#!) [ blu b mov mul ] $f # + |4>st
5 (#@) [ grn b mov mul ] $f # + |4>st
5 (#@) [ red b mov mul ] $f # + |4>st drop ;
: ndark
7 #for dark 7 #next ;
: cls ( )
0# 0# 128 # 160 #
rect
160 # 6 #for
128 # ndark
6 #next ;
: /st7735
[ 3 .p1 clr ]
1 # ms
[ 3 .p1 set ]
coldregs
cls
: white
$f #
: setgray
red (#!) grn (#!) blu #! ;
: black
0# setgray ;
$1fff constant TOPMEM
947 here
include fontsize.fs
[ TOPMEM FONTDATA_SIZE - ] org
include font.fs
here TOPMEM <> throw
org 947 <> throw
:m 4.4r ( - l h )
dup clra
dup $93 , $a3 , \ |@p+
xchd [swap] m;
: 4.4 ( - h l )
4.4r swap ;
: skip
4.4 * 1+ clrc 2/'
: +p
[ dpl add ] dpl (#!)
[ clra dph addc ] dph (#!)
drop;
: seek ( c - ) \ p points to the data for character c
font ##p!
begin
dup @p+ xor 0=if 2drop ; then
drop skip
again
: xy! y #! x #! ;
: xy@ x #@ y #@ ;
: adv x #+! ; \ advance cursor
: preloop ( l h - i j )
swap if 1u+ then ;
\ Fill rect with current color
: wash ( x y w h )
2dup um* d1+ d2/ preloop 7 #! 6 #!
rect
begin begin
full full
7 #next 6 #next ;
: ch ( c - )
p>r
seek
xy@
4.4 ( w h )
over adv
2dup * push ( w h r: w*h )
rect
pop 1+ 2/ 7 #for
4.4r gray gray
7 #next
r>p ;
: blch
black
xy@ 8 # 9 # wash
8 # adv white ;
: str
@p+ 6 #for
@p+
ch
6 #next ;
: setcolor
4.4 grn #! red #! @p+ blu #! ;
: hex1 ( h - )
x #@ 3 # + $7f # xor 4 #
RASET # write-cmd dim
RAMWR # write-cmd
/D/
micro ##p!
$f # and 10 # b #! [ mul ] +p
10 # 7 #for 4.4r gray gray 7 #next
5 # x #+! ;
: drawhex ( hh - )
y #@ 5 #
CASET # write-cmd dim
dup [swap] hex1 hex1 ;
:m gap [ y inc ] m;
: clip
y #@
: (clip)
-if
$7f # and negate + ;
then
drop;
: preblank ( w )
dup y #@ + (clip)
dup push x #@ -4 # + y #@
16 # pop rect
6 #for 16 # ndark 6 #next ;
: bitmap
0 #
: +bitmap ( o )
x #@ + y #@
-if 2drop ; then
4.4 ( w h )
: (bitmap) ( x y w h )
dup y #+!
clip
2dup * push ( w h r: w*h )
rect
pop 1+ clrc 2/' 7 #for
4.4r gray gray
7 #next ;
: (hex2)
micro ##p!
$f # and 10 # * +p
y #@ -if drop; then drop
x #@ 3 # + y #@
5 # 4 #
(bitmap) ;
: hex2 ( u - )
dup (hex2)
gap
[swap] (hex2)
;
: acknak
0=if'
$c # red #!
$2 # grn #!
$2 # blu #! ;
then
$2 # red #!
$c # grn #!
$2 # blu #! ;
: d-byte-ack
acknak
18 # preblank
gap
dot ##p!
7 # +bitmap
gap
white
hex2
gap gap gap ;
: barpoint ( u - ) \ update the slash bar bounds
-if drop; then
dup
talk0 #@ umin talk0 #!
talk1 #@ umax talk1 #! ;
: slashcolor 8 # setgray ;
here constant DRAW-SEGMENT \ This block must all be in the same 2K segment
: startwave
128 # 7 #!
0 # 8 # 128 # rect
story # a!
[
SP x mov
x dec
x dec
0 y mov
] ;
: column
$df cond
: bail
[
x SP mov
y 0 mov
] then ;
: hi full dark dark dark dark dark dark dark column ;
: lo dark dark dark dark dark dark dark full column ;
: change
full full full full full full full full column ;
: undef
half half half half half half half half column ;
: d-stop
drop a+
0 # red #!
7 # grn #!
7 # blu #!
symbol-p ##p!
: (d-stop)
12 # preblank
bitmap ;
:m y; \ return if y>127
$bc , 128 , 0 , \ CJNE R4,#128,+0
0=if' ; then m;
: d-direction
arrow ##p!
if'
larrow ##p!
then
$f # red #!
$e # grn #!
$2 # blu #!
-5 # y #+!
bitmap ;
: slashv ( u - ) \ draw the bottom slash segment
$08 # <if drop; then
$78 # <if
talked. 0=if.
talker (#!)
talked. set
then
talker @=if
slashcolor
x #@ -4 # + y #@ -5 # +
dup $7f # xor barpoint
6 # 1 # wash
then
then
drop;
: d-start
acknak
18 # preblank
gap
dot ##p!
7 # +bitmap
drop @+ clrc 2/'
d-direction
gap
dup white hex2
slashv
gap gap gap
y;
$c # red #!
$8 # grn #!
$0 # blu #!
symbol-s ##p!
(d-stop) ;
: d-byte
drop @+ d-byte-ack ;
: d-bang
drop a+
15 # red #!
0 # grn #!
1 # blu #!
symbol-b ##p!
12 # preblank
bitmap ;
: d-quit a+ 128 # y #! drop;
:m jumptable 2* here [ 4 + ] ##p! $73 , ( JMP @A+DPTR ) m;
: dispatch
@+ jumptable
( 0 ) d-quit ;
( 1 ) d-stop ;
( 2 ) d-start ;
( 3 ) d-byte ;
( 4 ) d-bang ;
: l-dispatch
begin
dispatch
y;
again
:m pinkwash
8 # red #!
0 # grn #!
8 # blu #!
0 # 117 # 128 # 17 #
wash m;
: hline ( x y l ) 1 # wash ;
: vline ( x y l ) 1 # swap wash ;
: addrgrid ( u - ) \ C set if column 7
dup 2/ 2/ 2/ 7 # * 7 # + y #!
7 # and dup 17 # * x #!
-7 # + drop;
: (slash) ( u - ) \ from the address, vertical down line
addrgrid
[ y inc y inc ]
0=if'
10 # adv
xy@ 3 # hline
3 # adv
else
-4 # adv
xy@ 3 # hline
then
xy@ 117 # over - vline ;
: slash ( u - )
slashcolor (slash)
[ x slashx mov ] ;
: unslash ( u - )
black (slash) ;
: d-slashbar
0# setgray \ undraw
0# 117 # 128 # hline
slashcolor
talked. if.
slashx #@ barpoint
talk0 #@ talk1 #@ over negate + 1+
117 # swap hline
then ;
: ingrad ( u - )
2* grad ##p! +p setcolor ;
: newtalker
white
: d-addr
dup addrgrid drawhex ;
: d-sda-stop
5 # 6 #for hi 6 #next
change
6 # 6 #for lo 6 #next
prev. clr
a+ drop;
: bar
0=if'
prev. if. change else lo then lo ;
then
prev. 0=if. change else hi then hi ;
: d-sda-byte
@+
cplc
9 # 6 #for
bar
[ prev. movcb ]
2/'
6 #next
drop drop;
: d-sda-start
d-sda-byte
6 # prev. if. change 1- then
6 #for lo 6 #next
change
5 # 6 #for hi 6 #next
prev. set
;
: d-sda-none
label-sda [ 1 + ] ##p!
: (label)
16 # 1 #for
4 # 6 #for
4.4r gray gray
6 #next
column
1 #next
begin hi again
: d-sda-bang
12 # 6 #for undef 6 #next
a+ drop;
: sda-dispatch
@+
jumptable
( 0 ) d-sda-none ;
( 1 ) d-sda-stop ;
( 2 ) d-sda-start ;
( 3 ) d-sda-byte ;
( 4 ) d-sda-bang ;
: d-sda
140 # startwave
$4 # red #!
$5 # grn #!
$f # blu #!
begin
sda-dispatch
again
: 9hi
9 # 6 #for hi 6 #next ;
: 2lo
2 # 6 #for lo 6 #next ;
: d-scl-stop
9hi
change
2lo
a+ drop;
: d-scl-byte
a+
9 # 6 #for
lo change
6 #next
drop;
: d-scl-start
d-scl-byte
2lo
change
9hi
;
: d-scl-none
label-scl [ 1 + ] ##p!
(label) ;
: scl-dispatch
@+ jumptable
( 0 ) d-scl-none ;
( 1 ) d-scl-stop ;
( 2 ) d-scl-start ;
( 3 ) d-scl-byte ;
( 4 ) d-sda-bang ;
here [ DRAW-SEGMENT xor $f800 and throw ]
: d-scl
152 # startwave
$c # red #!
$b # grn #!
$1 # blu #!
begin
scl-dispatch
again
: rtl
%10101000 #
: >madctl
MADCTL # write-cmd write-data ;
: ltr
%11001000 # >madctl ;
: drawmode
black
0# 0# 2dup 10 # 9 # wash
white xy! mode #@ ch ;
: fixed
rtl
3 # setgray
$08 #
112 # 6 #for
dup d-addr
1+
6 #next
ltr
drawmode
tplan ##p!
begin
@p+ 0=if drop; then
@p+ xy!
setcolor
str
again
: d-slash
talked. if.
ptalked. if.
ptalker #@ talker @=if drop; then
unslash
then
talker #@ slash ;
then
ptalker #@ unslash ;
: cool1 ( addr - )
\ talker @=if talked. if. drop; then then
dup heatmap @x if ( addr h )
1- (!x) ingrad
d-addr ;
then
2drop ;
: cool
rtl
$08 #
112 # 6 #for
dup cool1
1+
6 #next
drop
ltr ;
\ talked. is true when talker is valid
\ ptalked. and ptalker hold previous values
\ slashx is set to the X of the slash line
: waves
\ pinkwash
rtl
122 # 0 # xy!
$ff # talk0 #!
$00 # talk1 #!
talked. clr
story # a!
l-dispatch
d-sda
d-scl
ltr
d-slash
d-slashbar
talker #@ ptalker #!
[ talked. movbc ptalked. movcb ]
DISPON # write-cmd
;