avr: more general approach to fonts.

This commit is contained in:
Martin Preuss
2025-06-02 21:13:44 +02:00
parent cd1fce313e
commit b82e0d02df
18 changed files with 1214 additions and 238 deletions

View File

@@ -36,102 +36,12 @@
ILI9341_Init:
rcall ILI9341IoInit
rcall ILI9341_Reset
rcall ILI9341_LeaveSleepMode
ldi r16, 0xff
rcall ILI9341_SetBacklight
#if 0
ldi r16, 0xff
mov r3, r16
ldi r16, 0xff
mov r2, r16
rcall ili9341Test5
; 0bRRRRRGGGGGGBBBBB
ldi r16, 0b11111000 ; red
mov r3, r16
ldi r16, 0b00000000 ; red
mov r2, r16
rcall ili9341Test2
; 0bRRRRRGGGGGGBBBBB
ldi r16, 0b00000000
mov r3, r16
ldi r16, 0b00011111 ; blue
mov r2, r16
rcall ili9341Test3
; 0bRRRRRGGGGGGBBBBB
ldi r16, 0b00000111 ; green
mov r3, r16
ldi r16, 0b11100000 ; green
mov r2, r16
rcall ili9341Test4
; set foreground color
ldi r16, 0b11100000 ; green
mov r2, r16
ldi r16, 0b00000111 ; green
mov r3, r16
; set background color
ldi r16, 0b11111111 ; white
mov r0, r16
mov r1, r16
; set Xpos
ldi r16, LOW(100)
mov r4, r16
ldi r16, HIGH(100)
mov r5, r16
; setYpos
ldi r16, LOW(150)
mov r6, r16
ldi r16, HIGH(150)
mov r7, r16
; set font pos
ldi zl, LOW(font2_6x8*2)
ldi zh, HIGH(font2_6x8*2)
; set buffer pos
; ldi xl, LOW(ILI9341_buffer)
; ldi xh, HIGH(ILI9341_buffer)
ldi xl, LOW(0x260)
ldi xh, HIGH(0x260)
; set foreground color
ldi r16, 0b00000000 ; black
mov r2, r16
mov r3, r16
; set character
ldi r16, 'A'
rcall ili9341_WriteCharacterX4At
ldi r16, 'Q'
rcall ili9341_WriteCharacterX4At
ldi r16, 'H'
rcall ili9341_WriteCharacterX4At
ldi r16, 'O'
rcall ili9341_WriteCharacterX4At
ldi r16, 'M'
rcall ili9341_WriteCharacterX4At
ldi r16, 'E'
rcall ili9341_WriteCharacterX4At
#endif
sec
ret
; @end
@@ -269,108 +179,6 @@ ILI9341_LeaveSleepMode:
; ---------------------------------------------------------------------------
; @routine ILI9341_FillScreen
;
; @param r17:r16 color
ILI9341_FillScreen:
; TODO
ret
; @end
ili9341Test1:
rcall ili9341BeginSpi
ldi r16, 0x04
cbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D low (send command)
rcall SPIHW_MasterTransfer ; (R16)
sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (send data)
clr r16
; read byte 1
rcall SPIHW_MasterTransfer ; (R16)
; read byte 2
rcall SPIHW_MasterTransfer ; (R16)
; read byte 3
rcall SPIHW_MasterTransfer ; (R16)
; read byte 4
rcall SPIHW_MasterTransfer ; (R16)
rcall ili9341EndSpi ; (R16)
ret
; @param %0 X
; @param %1 Y
; @param %2 W
; @param %3 H
.macro M_ILI9341_FILL_RECT
ldi r16, LOW(@0) ; X0
mov r4, r16
ldi r16, HIGH(@0)
mov r5, r16
ldi r16, LOW(@1) ; Y0
mov r6, r16
ldi r16, HIGH(@1)
mov r7, r16
ldi r16, LOW(@2) ; W
mov r8, r16
ldi r16, HIGH(@2)
mov r9, r16
ldi r16, LOW(@3) ; H
mov r10, r16
ldi r16, HIGH(@3)
mov r11, r16
rcall ILI9341_FillRect
.endmacro
ili9341Test2:
M_ILI9341_FILL_RECT 10, 20, 70, 100
ret
ili9341Test3:
M_ILI9341_FILL_RECT 90, 40, 70, 100
ret
ili9341Test4:
M_ILI9341_FILL_RECT 40, 30, 70, 100
ret
ili9341Test5:
M_ILI9341_FILL_RECT 0, 0, 319, 239
ret
ili9341InitCommands:
; display off
.db 0x28, 0
@@ -421,10 +229,3 @@ ili9341InitCommands:
.db 0xff, 0xff
helloWorld: .db "Hello World", 0
.include "modules/lcd2/font/font2.asm"

View File

@@ -31,7 +31,7 @@
ili9341_WriteCharacterX1At:
push xl
push xh
rcall ili9341FontRenderChar ; (r16, r17, r24, r25, z)
rcall ili9341FontRenderChar ; (r16, r17, r24, r25, z)
rcall ili9341BitBlit ; (r16, r17, r20, r21, r22, r23, r24, r25, X)
; advance X (add char width to X)
add r4, r8
@@ -58,7 +58,7 @@ ili9341_WriteCharacterX1At:
; @clobbers r16 (r17, r18, r19, r20, r21, r22, r23, r24, r25, X)
ili9341_WriteCharacterX2At:
rcall ili9341FontRenderChar ; (r16, r17, r24, r25, z)
rcall ili9341FontRenderChar ; (r16, r17, r24, r25, z)
rcall ili9341BitBlitStretch2 ; (r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, X)
; advance X (add double char width to X)
lsl r8 ; Wx2
@@ -114,8 +114,7 @@ ili9341FontRenderChar:
; render character
push xl
push xh
; call render function of the selected font (first word of font is jmp to render function)
rcall ili9341JumpToFontRenderFn ; (r17, r24, r25, x)
rcall FONT_RenderChar
pop xh
pop xl
@@ -129,24 +128,6 @@ ili9341FontRenderChar:
; ---------------------------------------------------------------------------
; @routine ili9341JumpToFontRenderFn
;
; helper function to call function at the beginning of the given font
; @clobbers r17
ili9341JumpToFontRenderFn:
lpm r17, Z+
push r17
lpm r17, Z
push r17
sbiw zh:zl, 1
ret
; @end
; ---------------------------------------------------------------------------
; @routine textNibbleToAscii
;
@@ -169,7 +150,7 @@ textNibbleToAscii_l1:
#if 0
; ---------------------------------------------------------------------------
; @routine ili9341_WriteCharacterX4At
@@ -272,6 +253,7 @@ Debug_WriteHexBuffer_loop:
brne Debug_WriteHexBuffer_loop
ret
#endif