avr: use macros instead of costly calls for SPI on ILI9341.

This commit is contained in:
Martin Preuss
2026-01-24 01:03:31 +01:00
parent 2085ba6bbe
commit fdfc040d19
5 changed files with 79 additions and 24 deletions

View File

@@ -68,10 +68,12 @@ ili9341Font12x16MonoRenderChar_writeForeground:
mov r18, r2 mov r18, r2
mov r19, r3 mov r19, r3
ili9341Font12x16MonoRenderChar_sendToDisplay: ili9341Font12x16MonoRenderChar_sendToDisplay:
mov r16, r19 ; mov r16, r19
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
mov r16, r18 M_SPIHW_MASTER_SEND_BYTE r19
rcall SPIHW_MasterTransfer ; (R16) ; mov r16, r18
; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r18
ili9341Font12x16MonoRenderChar_loop2end: ili9341Font12x16MonoRenderChar_loop2end:
dec r24 dec r24
brne ili9341Font12x16MonoRenderChar_loop2 brne ili9341Font12x16MonoRenderChar_loop2

View File

@@ -64,10 +64,12 @@ ili9341Font6x8WriteChar_writeForeground:
mov r22, r2 mov r22, r2
mov r23, r3 mov r23, r3
ili9341Font6x8WriteChar_sendToDisplay: ili9341Font6x8WriteChar_sendToDisplay:
mov r16, r23 ; mov r16, r23
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
mov r16, r22 M_SPIHW_MASTER_SEND_BYTE r23
rcall SPIHW_MasterTransfer ; (R16) ; mov r16, r22
; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r22
ili9341Font6x8WriteChar_loop2end: ili9341Font6x8WriteChar_loop2end:
dec r24 dec r24
brne ili9341Font6x8WriteChar_loop2 brne ili9341Font6x8WriteChar_loop2

View File

@@ -23,6 +23,7 @@
; @clobbers R16, R17, R20, R21, R22, R23, R24, R25 ; @clobbers R16, R17, R20, R21, R22, R23, R24, R25
Display_FillRect: Display_FillRect:
#if 1
push r15 push r15
in r15, SREG in r15, SREG
cli cli
@@ -42,9 +43,11 @@ Display_FillRect_loopH:
mov r25, r9 ; W high mov r25, r9 ; W high
Display_FillRect_loopW: Display_FillRect_loopW:
mov r16, r3 mov r16, r3
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r16 ; (R16)
mov r16, r2 mov r16, r2
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r16 ; (R16)
sbiw r25:r24, 1 sbiw r25:r24, 1
brne Display_FillRect_loopW brne Display_FillRect_loopW
mov r24, r22 ; remaining H low mov r24, r22 ; remaining H low
@@ -58,6 +61,30 @@ Display_FillRect_loopW:
out SREG, r15 out SREG, r15
pop r15 pop r15
ret ret
#else
push r15
in r15, SREG
cli
rcall ili9341BeginSpi ; (R16, R17)
rcall ili9341SetAddressWindow ; (R16, r20, r21)
mov r20, r8
mov r21, r9
mov r22, r10
mov r23, r11
bigcall Utils_Mulu16x16_32
mov r24, r16
mov r25, r17
rcall displaySendColor
sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high
rcall ili9341EndSpi
out SREG, r15
pop r15
ret
#endif
; @end ; @end
@@ -200,9 +227,11 @@ displaySendColor:
sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA)
displaySendColor_loop: displaySendColor_loop:
mov r16, r3 mov r16, r3
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r16
mov r16, r2 mov r16, r2
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r16
sbiw r25:r24, 1 sbiw r25:r24, 1
brne displaySendColor_loop brne displaySendColor_loop
sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high
@@ -298,10 +327,12 @@ Display_BitBlit_loopH:
Display_BitBlit_loopW: Display_BitBlit_loopW:
ld r18, X+ ; read color from X ld r18, X+ ; read color from X
ld r19, X+ ld r19, X+
mov r16, r19 ; mov r16, r19
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
mov r16, r18 M_SPIHW_MASTER_SEND_BYTE r19
rcall SPIHW_MasterTransfer ; (R16) ; mov r16, r18
; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r18
sbiw r25:r24, 1 sbiw r25:r24, 1
brne Display_BitBlit_loopW brne Display_BitBlit_loopW
mov r24, r22 mov r24, r22

View File

@@ -179,10 +179,12 @@ ili9341ImageIdx2WritePixels_l1:
ld r17, X+ ld r17, X+
ld r16, X ld r16, X
; send to SPI (high byte first) ; send to SPI (high byte first)
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
mov r16, r17 M_SPIHW_MASTER_SEND_BYTE r16
rcall SPIHW_MasterTransfer ; (R16) ; mov r16, r17
; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r17
dec r22 ; pixelCounterInByte dec r22 ; pixelCounterInByte
dec r20 ; runWidth dec r20 ; runWidth
brne ili9341ImageIdx2WritePixels_horizLoop brne ili9341ImageIdx2WritePixels_horizLoop
@@ -280,10 +282,12 @@ ili9341ImageIdx2rleWritePixels_l1:
ld r17, X+ ld r17, X+
ld r16, X ld r16, X
; send to SPI (high byte first) ; send to SPI (high byte first)
rcall SPIHW_MasterTransfer ; (R16) ; rcall SPIHW_MasterTransfer ; (R16)
mov r16, r17 M_SPIHW_MASTER_SEND_BYTE r16
rcall SPIHW_MasterTransfer ; (R16) ; mov r16, r17
; rcall SPIHW_MasterTransfer ; (R16)
M_SPIHW_MASTER_SEND_BYTE r17
dec r22 ; pixelCounterInByte dec r22 ; pixelCounterInByte
dec r20 ; runWidth dec r20 ; runWidth
brne ili9341ImageIdx2rleWritePixels_horizLoop brne ili9341ImageIdx2rleWritePixels_horizLoop

View File

@@ -8,6 +8,22 @@
; *************************************************************************** ; ***************************************************************************
; ***************************************************************************
; macros
; @param @0 register to use
.macro M_SPIHW_MASTER_SEND_BYTE
outr SPDR, @0 ; masterSend Byte
l1_%:
inr @0, SPSR
sbrs @0, SPIF
rjmp l1_%
inr @0, SPDR
.endm
; *************************************************************************** ; ***************************************************************************
; defines ; defines