avr: more work on fonts, added heap functions.

This commit is contained in:
Martin Preuss
2025-05-24 15:32:45 +02:00
parent fa5acddcbe
commit 391c06e7e5
14 changed files with 661 additions and 5 deletions

View File

@@ -28,6 +28,10 @@
.include "modules/xram/main.asm"
#endif
#ifdef MODULES_HEAP
.include "modules/heap/main.asm"
#endif
#ifdef MODULES_NETWORK
.include "common/crc8.asm"
.include "common/m_fixedbuffers.asm"
@@ -166,6 +170,12 @@
#endif
#ifdef MODULES_FONT_6X8
.include "modules/lcd2/font/defs.asm"
.include "modules/lcd2/font/font6x8.asm"
#endif
#ifdef APPS_MOTION
.include "modules/f_keepup/main.asm"
.include "modules/valsched/main.asm"

View File

@@ -24,6 +24,10 @@
initModules:
rcall BaseTimer_Init ; unconditionally call this
#ifdef MODULES_HEAP
rcall Heap_Init
#endif
#ifdef MODULES_CLOCK
rcall Clock_Init
#endif

View File

@@ -36,6 +36,14 @@
; ---------------------------------------------------------------------------
; heap
.equ HEAP_START = 0x260
.equ HEAP_SIZE = 32768-0x260
; ---------------------------------------------------------------------------
; firmware settings including list of modules used
@@ -48,13 +56,15 @@
; #define MODULES_TIMER
#define MODULES_CLOCK
#define MODULES_XRAM
#define MODULES_HEAP
#define MODULES_LED_SIMPLE
#define MODULES_NETWORK
;#define MODULES_COMONUART0
#define MODULES_UART_HW
#define MODULES_SPI_HW
#define MODULES_ILI9341
#define MODULES_FONT_8X8
;#define MODULES_FONT_8X8
#define MODULES_FONT_6X8
;#define MODULES_UART_BITBANG
;#define MODULES_TWI_MASTER
;#define MODULES_LCD

View File

@@ -36,6 +36,7 @@
f_keepup
valsched
xram
heap
</subdirs>
</gwbuild>

11
avr/modules/heap/0BUILD Normal file
View File

@@ -0,0 +1,11 @@
<?xml?>
<gwbuild>
<extradist>
main.asm
</extradist>
</gwbuild>

317
avr/modules/heap/main.asm Normal file
View File

@@ -0,0 +1,317 @@
; ***************************************************************************
; copyright : (C) 2025 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; Needed vars:
; - HEAP_START
; - HEAP_SIZE
.equ HEAP_HEADER_BIT_USED = 1
.dseg
heapPtr: .byte 2
heapUsed: .byte 2
heapFree: .byte 2
heapDblFree: .byte 1
.cseg
; ---------------------------------------------------------------------------
; @routine Heap_Init
Heap_Init:
ldi xl, LOW(HEAP_START)
ldi xh, HIGH(HEAP_START)
ldi r24, LOW((HEAP_SIZE-6) & 0xfffc) ; size minus chunk header, chunk footer, start, end
ldi r25, HIGH((HEAP_SIZE-6) & 0xfffc) ; we allocate multiples of 4 bytes
clr r16
sts heapUsed, r16
sts heapUsed+1, r16
st X+, r16 ; write start header
st X+, r16
sts heapPtr, xl ; store global vars
sts heapPtr+1, xl
sts heapFree, r24
sts heapFree+1, r25
st X+, r24 ; store header of first chunk
st X+, r25
add xl, r24
adc xh, r25
st X+, r24 ; store footer of first chunk
st X+, r25
st X+, r16 ; write end footer
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine heapAllocFirstFit
;
; @param r25:r24 number of bytes to alloc
; @return CFLAG set of okay, cleared otherwise
; @return X start of allocated memory
heapAllocFirstFit:
adiw r25:r24, 3 ; align size to next multiple of 4
andi r24, 0xfc ; mask lower two bits
lds xl, heapPtr
lds xh, heapPtr+1
heapAllocFirstFit_loop:
ld r18, X+ ; read chunk header
ld r19, X+
mov r16, r18 ; heap end reached?
or r16, r19
breq heapAllocFirstFit_memFull
sbrc r17, HEAP_HEADER_BIT_USED
rjmp heapAllocFirstFit_next ; jump if used
; current chunk free, check size
mov r16, r18
mov r17, r19
sub r16, r24
sbc r17, r25 ; r17:r16=remainder
brcs heapAllocFirstFit_next ; too small
rcall heapUseChunk
sec
ret
heapAllocFirstFit_next:
add xl, r18
adc xh, r19
adiw xh:xl, 2 ; skip footer
rjmp heapAllocFirstFit_loop
heapAllocFirstFit_memFull:
clc
ret
; @end
; ---------------------------------------------------------------------------
; @routine heapAdjustStatsAlloc
;
; @param r25:r24 size of allocated chunk
; @clobbers r16, r17
heapAdjustStatsAlloc:
; adjust heapUsed
lds r16, heapUsed
lds r17, heapUsed+1
add r16, r24
adc r17, r25
sts heapUsed, r16
sts heapUsed+1, r17
; adjust heapFree
lds r16, heapFree
lds r17, heapFree+1
sub r16, r24
sbc r17, r25
sts heapFree, r16
sts heapFree+1, r17
ret
; @end
; ---------------------------------------------------------------------------
; @routine heapAdjustStatsFree
;
; @param r25:r24 size of released chunk
; @clobbers r16, r17
heapAdjustStatsFree:
; adjust heapUsed
lds r16, heapUsed
lds r17, heapUsed+1
sub r16, r24
sbc r17, r25
sts heapUsed, r16
sts heapUsed+1, r17
; adjust heapFree
lds r16, heapFree
lds r17, heapFree+1
add r16, r24
adc r17, r25
sts heapFree, r16
sts heapFree+1, r17
ret
; @end
; ---------------------------------------------------------------------------
; @routine Heap_Free
;
; @param X pointer to previously allocated data
; @clobbers r16, r17, r24, r25, X
Heap_Free:
sbiw xh:xl, 2 ; go back to chunk header
ld r24, X+ ; read allocated size (and USED bit)
ld r25, X+
sbrs r24, HEAP_HEADER_BIT_USED
rjmp Heap_Free_dblFree ; not in use (double free!!)
cbr r24, (1<<HEAP_HEADER_BIT_USED) ; clear USED bit
st -X, r25 ; write back chunk header
st -X, r24 ; X now points to begin of chunk header
push xl
push xh
adiw xh:xl, 2 ; go skip chunk header
add xl, r24 ; skip data
adc xh, r25
st X+, r24 ; write chunk footer
st X+, r25 ; X points to the next chunk header now
rcall heapAdjustStatsFree ; update stats (r16, r17)
rcall heapCoalecseUp ; try to coalecse following chunk with this (r16, r17, r24, r25, X)
pop xh
pop xl
rcall heapCoalecseUp ; try to coalesce this chunk with predecessor (r16, r17, r24, r25, X)
rjmp Heap_Free_ret
Heap_Free_dblFree:
lds r24, heapDblFree
lds r25, heapDblFree+1
adiw r25:r24, 1
breq Heap_Free_ret
sts heapDblFree, r24
sts heapDblFree+1, r25
Heap_Free_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine heapCoalecseUp
;
; @param X pointer to chunk header
; @clobbers r16, r17, r24, r25, X
heapCoalecseUp:
ld r16, X+ ; end of heap reached(header==0x0000)?
ld r17, X
sbiw xh:xl, 1
or r16, r17
breq heapCoalecseUp_ret ; yes, jump
; read footer of preceeding chunk
ld r25, -X
ld r24, -X
; R25:R24=footer of preceeding chunk (i.e. size of previous chunk)
mov r16, r24 ; check: beginning of heap reached (header==0x0000)?
or r16, r25
breq heapCoalecseUp_ret ; yes, jump
sbrc r24, HEAP_HEADER_BIT_USED ; block used?
rjmp heapCoalecseUp_ret ; jump if used
; previous chunk also free, coalesce, X points to current chunk header
ld r16, X+
ld r17, X+
; X now points to beginning of current chunk's data, R17:r16=size of current chunk, R25:R24=size of previous chunk
; to go to start of previous chunk header: sub this chunk header, previous chunk footer, previous chunk header and previous data
sbiw xh:xl, 6
sub xl, r24
sbc xh, r25
; X points now to the beginning of the previous chunk header
; calculate size of new coalecsed chunk: add size of this chunk, size of previous chunk, 1 chunk header and 1 footer which are
; no longer needed now (since the one header and footer of the previous chunk now cover both chunks)
add r24, r16
adc r25, r17
adiw r25:r24, 4
; write new chunk header
st X+, r24
st X+, r25
; skip full data size of the coalesced chunk
add xl, r24
adc xh, r25
; write new chunk footer
st X+, r24
st X+, r25
; X now points to header of following chunk
heapCoalecseUp_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine heapUseChunk
;
; @param r25:r24 wanted size
; @param r17:r16 size of current chunk minus wanted size (remainder)
; @param X points to data of current chunk
; @clobbers
heapUseChunk:
push xh
push xl
tst r17
breq heapUseChunk_split
cpi r16, 8 ; at least 8 bytes left?
brcs heapUseChunk_directAlloc ; nope, use full chunk
heapUseChunk_split:
sbiw xh:xl, 2 ; go back to chunk header
; X points to start of chunk header
mov r18, r24
sbr r18, (1<<HEAP_HEADER_BIT_USED)
st X+, r18 ; set used bit
st X+, r25
add xl, r24
adc xh, r25
; X now points to the start of chunk footer
st X+, r18
st X+, r25
; create chunk header for new free chunk
subi r16, 4 ; sub chunk header and footer from size
sbci r17, 0
andi r16, 0xfc ; clear USED bit
st X+, r16 ; write new chunk header
st X+, r17
add xl, r16
adc xh, r17
st X+, r16 ; write new chunk footer
st X+, r17
; update stats, pop X and return
rjmp heapUseChunk_statsPopRet
heapUseChunk_directAlloc:
ld r17, -X ; load allocated size from chunk header
ld r16, -X
mov r18, r16
sbr r18, (1<<HEAP_HEADER_BIT_USED)
st X, r18 ; set USED bit in chunk header
adiw xh:xl, 2 ; skip chunk header
add xl, r16 ; skip chunk data
adc xh, r17
st X, r18 ; set USED bit in chunk footer
; update stats, pop X and return
heapUseChunk_statsPopRet:
rcall heapAdjustStatsAlloc ; (r16, r17)
pop xh
pop xl
sec
ret
; @end

View File

@@ -5,7 +5,9 @@
<extradist>
defs.asm
font8x8.asm
font6x8.asm
font1.asm
font2.asm
</extradist>
</gwbuild>

View File

@@ -7,6 +7,8 @@
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
#ifndef AVR_MODULES_FONT_DEFS
#define AVR_MODULES_FONT_DEFS
.equ FONT_OFFS_RENDERFN_LOW = 0
@@ -18,3 +20,7 @@
.equ FONT_OFFS_NUMCHARS = 7
#endif

View File

@@ -30,7 +30,7 @@ font1_8x8:
.db 128, 0 ; needed buffer size
.db 8, 8 ; width, height of chars
.db 32, 64 ; first char, num of chars in font
; data
; data (8x8_horizontal_LSB_2)
.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20
.db 0x0C,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x00, ; 0x21
.db 0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00, ; 0x22

View File

@@ -0,0 +1,179 @@
; ***************************************************************************
; copyright : (C) 2025 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ***************************************************************************
; This is a font from the project LCD_fonts at
; https://github.com/basti79/LCD-fonts.git
; which in turn is based on a post by Benedikt K. in a forum post on
; https://www.mikrocontroller.net/topic/54860
; ***************************************************************************
; ***************************************************************************
; code
.cseg
font2_6x8:
; header
.dw font6x8MonoRenderCharacter ; renderFn
.db 96, 0 ; needed buffer size
.db 6, 8 ; width, height of chars
.db 32, 65 ; first char, num of chars in font
; data (6x8_horizontal_LSB_2)
font:
.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20
.db 0x08,0x1C,0x1C,0x08,0x08,0x00,0x08,0x00, ; 0x21
.db 0x36,0x36,0x12,0x00,0x00,0x00,0x00,0x00, ; 0x22
.db 0x00,0x14,0x3E,0x14,0x14,0x3E,0x14,0x00, ; 0x23
.db 0x04,0x1C,0x02,0x0C,0x10,0x0E,0x08,0x00, ; 0x24
.db 0x26,0x26,0x10,0x08,0x04,0x32,0x32,0x00, ; 0x25
.db 0x04,0x0A,0x0A,0x04,0x2A,0x12,0x2C,0x00, ; 0x26
.db 0x0C,0x0C,0x04,0x00,0x00,0x00,0x00,0x00, ; 0x27
.db 0x08,0x04,0x04,0x04,0x04,0x04,0x08,0x00, ; 0x28
.db 0x04,0x08,0x08,0x08,0x08,0x08,0x04,0x00, ; 0x29
.db 0x00,0x14,0x1C,0x3E,0x1C,0x14,0x00,0x00, ; 0x2A
.db 0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00, ; 0x2B
.db 0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x04, ; 0x2C
.db 0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00, ; 0x2D
.db 0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00, ; 0x2E
.db 0x00,0x20,0x10,0x08,0x04,0x02,0x00,0x00, ; 0x2F
.db 0x1C,0x22,0x32,0x2A,0x26,0x22,0x1C,0x00, ; 0x30
.db 0x08,0x0C,0x08,0x08,0x08,0x08,0x1C,0x00, ; 0x31
.db 0x1C,0x22,0x20,0x18,0x04,0x02,0x3E,0x00, ; 0x32
.db 0x1C,0x22,0x20,0x1C,0x20,0x22,0x1C,0x00, ; 0x33
.db 0x10,0x18,0x14,0x12,0x3E,0x10,0x10,0x00, ; 0x34
.db 0x3E,0x02,0x02,0x1E,0x20,0x22,0x1C,0x00, ; 0x35
.db 0x18,0x04,0x02,0x1E,0x22,0x22,0x1C,0x00, ; 0x36
.db 0x3E,0x20,0x10,0x08,0x04,0x04,0x04,0x00, ; 0x37
.db 0x1C,0x22,0x22,0x1C,0x22,0x22,0x1C,0x00, ; 0x38
.db 0x1C,0x22,0x22,0x3C,0x20,0x10,0x0C,0x00, ; 0x39
.db 0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x00, ; 0x3A
.db 0x00,0x00,0x0C,0x0C,0x00,0x0C,0x0C,0x04, ; 0x3B
.db 0x10,0x08,0x04,0x02,0x04,0x08,0x10,0x00, ; 0x3C
.db 0x00,0x00,0x3E,0x00,0x00,0x3E,0x00,0x00, ; 0x3D
.db 0x04,0x08,0x10,0x20,0x10,0x08,0x04,0x00, ; 0x3E
.db 0x1C,0x22,0x20,0x18,0x08,0x00,0x08,0x00, ; 0x3F
.db 0x1C,0x22,0x3A,0x2A,0x3A,0x02,0x1C,0x00, ; 0x40
.db 0x1C,0x22,0x22,0x22,0x3E,0x22,0x22,0x00, ; 0x41
.db 0x1E,0x22,0x22,0x1E,0x22,0x22,0x1E,0x00, ; 0x42
.db 0x1C,0x22,0x02,0x02,0x02,0x22,0x1C,0x00, ; 0x43
.db 0x1E,0x22,0x22,0x22,0x22,0x22,0x1E,0x00, ; 0x44
.db 0x3E,0x02,0x02,0x1E,0x02,0x02,0x3E,0x00, ; 0x45
.db 0x3E,0x02,0x02,0x1E,0x02,0x02,0x02,0x00, ; 0x46
.db 0x1C,0x22,0x02,0x3A,0x22,0x22,0x3C,0x00, ; 0x47
.db 0x22,0x22,0x22,0x3E,0x22,0x22,0x22,0x00, ; 0x48
.db 0x1C,0x08,0x08,0x08,0x08,0x08,0x1C,0x00, ; 0x49
.db 0x20,0x20,0x20,0x20,0x22,0x22,0x1C,0x00, ; 0x4A
.db 0x22,0x12,0x0A,0x06,0x0A,0x12,0x22,0x00, ; 0x4B
.db 0x02,0x02,0x02,0x02,0x02,0x02,0x3E,0x00, ; 0x4C
.db 0x22,0x36,0x2A,0x22,0x22,0x22,0x22,0x00, ; 0x4D
.db 0x22,0x26,0x2A,0x32,0x22,0x22,0x22,0x00, ; 0x4E
.db 0x1C,0x22,0x22,0x22,0x22,0x22,0x1C,0x00, ; 0x4F
.db 0x1E,0x22,0x22,0x1E,0x02,0x02,0x02,0x00, ; 0x50
.db 0x1C,0x22,0x22,0x22,0x2A,0x12,0x2C,0x00, ; 0x51
.db 0x1E,0x22,0x22,0x1E,0x12,0x22,0x22,0x00, ; 0x52
.db 0x1C,0x22,0x02,0x1C,0x20,0x22,0x1C,0x00, ; 0x53
.db 0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x00, ; 0x54
.db 0x22,0x22,0x22,0x22,0x22,0x22,0x1C,0x00, ; 0x55
.db 0x22,0x22,0x22,0x22,0x22,0x14,0x08,0x00, ; 0x56
.db 0x22,0x22,0x2A,0x2A,0x2A,0x2A,0x14,0x00, ; 0x57
.db 0x22,0x22,0x14,0x08,0x14,0x22,0x22,0x00, ; 0x58
.db 0x22,0x22,0x22,0x14,0x08,0x08,0x08,0x00, ; 0x59
.db 0x1E,0x10,0x08,0x04,0x02,0x02,0x1E,0x00, ; 0x5A
.db 0x1C,0x04,0x04,0x04,0x04,0x04,0x1C,0x00, ; 0x5B
.db 0x00,0x02,0x04,0x08,0x10,0x20,0x00,0x00, ; 0x5C
.db 0x1C,0x10,0x10,0x10,0x10,0x10,0x1C,0x00, ; 0x5D
.db 0x08,0x14,0x22,0x00,0x00,0x00,0x00,0x00, ; 0x5E
.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F, ; 0x5F
.db 0x0C,0x0C,0x08,0x00,0x00,0x00,0x00,0x00, ; 0x60
#if 0
.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ; 0x20
.db 0x20,0x70,0x70,0x20,0x20,0x00,0x20,0x00, ; 0x21
.db 0xD8,0xD8,0x48,0x00,0x00,0x00,0x00,0x00, ; 0x22
.db 0x00,0x50,0xF8,0x50,0x50,0xF8,0x50,0x00, ; 0x23
.db 0x10,0x70,0x08,0x30,0x40,0x38,0x20,0x00, ; 0x24
.db 0x98,0x98,0x40,0x20,0x10,0xC8,0xC8,0x00, ; 0x25
.db 0x10,0x28,0x28,0x10,0xA8,0x48,0xB0,0x00, ; 0x26
.db 0x30,0x30,0x10,0x00,0x00,0x00,0x00,0x00, ; 0x27
.db 0x20,0x10,0x10,0x10,0x10,0x10,0x20,0x00, ; 0x28
.db 0x10,0x20,0x20,0x20,0x20,0x20,0x10,0x00, ; 0x29
.db 0x00,0x50,0x70,0xF8,0x70,0x50,0x00,0x00, ; 0x2A
.db 0x00,0x20,0x20,0xF8,0x20,0x20,0x00,0x00, ; 0x2B
.db 0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x10, ; 0x2C
.db 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00, ; 0x2D
.db 0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00, ; 0x2E
.db 0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00, ; 0x2F
.db 0x70,0x88,0xC8,0xA8,0x98,0x88,0x70,0x00, ; 0x30
.db 0x20,0x30,0x20,0x20,0x20,0x20,0x70,0x00, ; 0x31
.db 0x70,0x88,0x80,0x60,0x10,0x08,0xF8,0x00, ; 0x32
.db 0x70,0x88,0x80,0x70,0x80,0x88,0x70,0x00, ; 0x33
.db 0x40,0x60,0x50,0x48,0xF8,0x40,0x40,0x00, ; 0x34
.db 0xF8,0x08,0x08,0x78,0x80,0x88,0x70,0x00, ; 0x35
.db 0x60,0x10,0x08,0x78,0x88,0x88,0x70,0x00, ; 0x36
.db 0xF8,0x80,0x40,0x20,0x10,0x10,0x10,0x00, ; 0x37
.db 0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00, ; 0x38
.db 0x70,0x88,0x88,0xF0,0x80,0x40,0x30,0x00, ; 0x39
.db 0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x00, ; 0x3A
.db 0x00,0x00,0x30,0x30,0x00,0x30,0x30,0x10, ; 0x3B
.db 0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00, ; 0x3C
.db 0x00,0x00,0xF8,0x00,0x00,0xF8,0x00,0x00, ; 0x3D
.db 0x10,0x20,0x40,0x80,0x40,0x20,0x10,0x00, ; 0x3E
.db 0x70,0x88,0x80,0x60,0x20,0x00,0x20,0x00, ; 0x3F
.db 0x70,0x88,0xE8,0xA8,0xE8,0x08,0x70,0x00, ; 0x40
.db 0x70,0x88,0x88,0x88,0xF8,0x88,0x88,0x00, ; 0x41
.db 0x78,0x88,0x88,0x78,0x88,0x88,0x78,0x00, ; 0x42
.db 0x70,0x88,0x08,0x08,0x08,0x88,0x70,0x00, ; 0x43
.db 0x78,0x88,0x88,0x88,0x88,0x88,0x78,0x00, ; 0x44
.db 0xF8,0x08,0x08,0x78,0x08,0x08,0xF8,0x00, ; 0x45
.db 0xF8,0x08,0x08,0x78,0x08,0x08,0x08,0x00, ; 0x46
.db 0x70,0x88,0x08,0xE8,0x88,0x88,0xF0,0x00, ; 0x47
.db 0x88,0x88,0x88,0xF8,0x88,0x88,0x88,0x00, ; 0x48
.db 0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00, ; 0x49
.db 0x80,0x80,0x80,0x80,0x88,0x88,0x70,0x00, ; 0x4A
.db 0x88,0x48,0x28,0x18,0x28,0x48,0x88,0x00, ; 0x4B
.db 0x08,0x08,0x08,0x08,0x08,0x08,0xF8,0x00, ; 0x4C
.db 0x88,0xD8,0xA8,0x88,0x88,0x88,0x88,0x00, ; 0x4D
.db 0x88,0x98,0xA8,0xC8,0x88,0x88,0x88,0x00, ; 0x4E
.db 0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00, ; 0x4F
.db 0x78,0x88,0x88,0x78,0x08,0x08,0x08,0x00, ; 0x50
.db 0x70,0x88,0x88,0x88,0xA8,0x48,0xB0,0x00, ; 0x51
.db 0x78,0x88,0x88,0x78,0x48,0x88,0x88,0x00, ; 0x52
.db 0x70,0x88,0x08,0x70,0x80,0x88,0x70,0x00, ; 0x53
.db 0xF8,0x20,0x20,0x20,0x20,0x20,0x20,0x00, ; 0x54
.db 0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00, ; 0x55
.db 0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00, ; 0x56
.db 0x88,0x88,0xA8,0xA8,0xA8,0xA8,0x50,0x00, ; 0x57
.db 0x88,0x88,0x50,0x20,0x50,0x88,0x88,0x00, ; 0x58
.db 0x88,0x88,0x88,0x50,0x20,0x20,0x20,0x00, ; 0x59
.db 0x78,0x40,0x20,0x10,0x08,0x08,0x78,0x00, ; 0x5A
.db 0x70,0x10,0x10,0x10,0x10,0x10,0x70,0x00, ; 0x5B
.db 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00, ; 0x5C
.db 0x70,0x40,0x40,0x40,0x40,0x40,0x70,0x00, ; 0x5D
.db 0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00, ; 0x5E
.db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC, ; 0x5F
.db 0x30,0x30,0x20,0x00,0x00,0x00,0x00,0x00, ; 0x60
#endif

View File

@@ -0,0 +1,96 @@
; ***************************************************************************
; copyright : (C) 2025 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine font6x8RenderCharacter
; @param R16 character to write
; @param R1:R0 background color
; @param R3:R2 foreground color
; @param Z pointer to font
; @param X pointer to RAM to store data to
; @param r18 char width in pixel
; @param r19 char height in pixel
; @clobbers r16, r17, r24, r25, x
font6x8MonoRenderCharacter:
push zl
push zh
adiw zh:zl, FONT_OFFS_WIDTH
lpm r18, Z+ ; char width in pixels
lpm r19, Z ; char height in pixels
sbiw zh:zl, FONT_OFFS_WIDTH+1
rcall font6x8GetCharPosInFont ; (r16, r17, r24, r25, z)
mov r25, r19 ; height in pixels
font6x8MonoRenderCharacter_loop1:
mov r24, r18 ; width in pixels
lpm r17, Z+
font6x8MonoRenderCharacter_loop2:
lsr r17
brcs font6x8MonoRenderCharacter_writeForeground
st X+, r0
st X+, r1
rjmp font6x8MonoRenderCharacter_loop2end
font6x8MonoRenderCharacter_writeForeground:
st X+, r2
st X+, r3
font6x8MonoRenderCharacter_loop2end:
dec r24
brne font6x8MonoRenderCharacter_loop2
dec r25
brne font6x8MonoRenderCharacter_loop1
pop zh
pop zl
ret
; @end
; ---------------------------------------------------------------------------
; @routine font6x8GetCharPosInFont (same as font8x8GetCharPosInFont!)
; @param R16 character to write
; @param Z pointer to font
; @return Z pointer to begin of char data
; @clobbers r16, r17, r24, r25, z
font6x8GetCharPosInFont:
mov r24, r16
adiw zh:zl, FONT_OFFS_FIRSTCHAR
lpm r24, Z+ ; first char num
lpm r25, Z+ ; num of chars
sub r16, r24
brcs font6x8GetCharPosInFont_ret
cp r16, r25
brcc font6x8GetCharPosInFont_ret
mov r24, r16
clr r25
lsl r24 ; x2
rol r25
lsl r24 ; x4
rol r25
lsl r24 ; x8
rol r25
add zl, r24
adc zh, r25
font6x8GetCharPosInFont_ret:
ret
; @end

View File

@@ -57,3 +57,5 @@
.equ WIN_OFFS_REL_X_HIGH = 11

View File

@@ -97,8 +97,8 @@ ILI9341_Init:
mov r7, r16
; set font pos
ldi zl, LOW(font1_8x8*2)
ldi zh, HIGH(font1_8x8*2)
ldi zl, LOW(font2_6x8*2)
ldi zh, HIGH(font2_6x8*2)
; set buffer pos
; ldi xl, LOW(ILI9341_buffer)
@@ -423,6 +423,6 @@ helloWorld: .db "Hello World", 0
.include "modules/lcd2/font/font1.asm"
.include "modules/lcd2/font/font2.asm"

View File

@@ -0,0 +1,18 @@
; ***************************************************************************
; copyright : (C) 2025 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome". *
; * Please see toplevel file COPYING of that project for license details. *
; ***************************************************************************
; ---------------------------------------------------------------------------
; @routine WID_Widget_new @global
WID_Widget_new: