avr: fixed button code.

This commit is contained in:
Martin Preuss
2025-11-18 19:14:40 +01:00
parent 059654b16f
commit b520ccb165
4 changed files with 183 additions and 140 deletions

View File

@@ -61,7 +61,7 @@ DlgNetStats_Handler_Fns:
rjmp dlgNetStatsOnFini rjmp dlgNetStatsOnFini
rjmp dlgNetStatsOnShow rjmp dlgNetStatsOnShow
rjmp dlgNetStatsOnHide rjmp dlgNetStatsOnHide
ret ; rjmp dlgNetStatsOnTouch rjmp dlgNetStatsOnTouch
rjmp dlgNetStatsOnTimer rjmp dlgNetStatsOnTimer

View File

@@ -68,8 +68,8 @@ buttonDraw:
lpm r13, Z+ lpm r13, Z+
rcall buttonClearBackground rcall buttonClearBackground
rcall buttonDrawText
rcall buttonDrawBorder rcall buttonDrawBorder
rcall buttonDrawText
ret ret
; @end ; @end
@@ -120,11 +120,11 @@ buttonClearBackground_bgFill:
; @clobbers any, !Y, !Z ; @clobbers any, !Y, !Z
buttonDrawBorder: buttonDrawBorder:
ldi r16, LOW(STYLE_BUTTON_COL_BORDER) ldi r16, LOW(STYLE_BUTTON_COL_BORDER)
mov r2, r16 mov r2, r16
ldi r16, HIGH(STYLE_BUTTON_COL_BORDER) ldi r16, HIGH(STYLE_BUTTON_COL_BORDER)
mov r3, r16 mov r3, r16
bigcall Display_DrawRect bigcall Display_DrawRect
ret ret
; @end ; @end
@@ -143,51 +143,43 @@ buttonDrawBorder:
; @clobbers any, !Y, !Z ; @clobbers any, !Y, !Z
buttonDrawText: buttonDrawText:
push r4 ldi r16, 2
push r5 clr r17
push r6 add r4, r16 ; x+=2
push r7 adc r5, r17
ldi r16, 2 add r6, r16 ; y+=2
clr r17 adc r7, r17
add r4, r16 ; x+=2
adc r5, r17 ; set text colors
add r6, r16 ; y+=2 tst r14
adc r7, r17 brne buttonDrawText_down
; set background color
; set text colors ldi r16, LOW(STYLE_BUTTON_COL_BG_NORM)
tst r14 mov r0, r16
brne buttonDrawText_down ldi r16, HIGH(STYLE_BUTTON_COL_BG_NORM)
; set background color mov r1, r16
ldi r16, LOW(STYLE_BUTTON_COL_BG_NORM) ; set foreground color
mov r0, r16 ldi r16, LOW(STYLE_BUTTON_COL_FG_NORM)
ldi r16, HIGH(STYLE_BUTTON_COL_BG_NORM) mov r2, r16
mov r1, r16 ldi r16, HIGH(STYLE_BUTTON_COL_FG_NORM)
; set foreground color mov r3, r16
ldi r16, LOW(STYLE_BUTTON_COL_FG_NORM) rjmp buttonDrawText_draw
mov r2, r16 buttonDrawText_down:
ldi r16, HIGH(STYLE_BUTTON_COL_FG_NORM) ; set background color
mov r3, r16 ldi r16, LOW(STYLE_BUTTON_COL_BG_PRESSED)
rjmp buttonDrawText_draw mov r0, r16
buttonDrawText_down: ldi r16, HIGH(STYLE_BUTTON_COL_BG_PRESSED)
; set background color mov r1, r16
ldi r16, LOW(STYLE_BUTTON_COL_BG_PRESSED)
mov r0, r16 ; set foreground color
ldi r16, HIGH(STYLE_BUTTON_COL_BG_PRESSED) ldi r16, LOW(STYLE_BUTTON_COL_FG_PRESSED)
mov r1, r16 mov r2, r16
ldi r16, HIGH(STYLE_BUTTON_COL_FG_PRESSED)
; set foreground color mov r3, r16
ldi r16, LOW(STYLE_BUTTON_COL_FG_PRESSED) buttonDrawText_draw:
mov r2, r16 mov zl, r12
ldi r16, HIGH(STYLE_BUTTON_COL_FG_PRESSED) mov zh, r13
mov r3, r16 bigcall Window_DrawColorTextFlash
buttonDrawText_draw:
mov zl, r12
mov zh, r13
bigcall Window_DrawColorTextFlash
pop r7
pop r6
pop r5
pop r4
ret ret
; @end ; @end

View File

@@ -247,7 +247,7 @@ winCalcAbsPosAndBorders:
; @param R7:R6 absolute Y on screen ; @param R7:R6 absolute Y on screen
; @param R9:R8 first X pos right of windows ; @param R9:R8 first X pos right of windows
; @return R5:R4 X pos behind char ; @return R5:R4 X pos behind char
; @clobbers any, !Y, !R6, !R7 ; @clobbers any, !Y, !R6, !R7, !R8, !R9, !R10, !R11
winDrawChar: winDrawChar:
push zl push zl

View File

@@ -20,17 +20,16 @@
; @param r7:r6 Y0 ; @param r7:r6 Y0
; @param r9:r8 X1/W ; @param r9:r8 X1/W
; @param r11:r10 Y1/H ; @param r11:r10 Y1/H
; @clobbers R16, R17, R20, R21, R22, R23, R24, R25
Display_FillRect: Display_FillRect:
push r15 push r15
in r15, SREG in r15, SREG
cli cli
rcall ili9341BeginSpi ; (R16, R17) rcall ili9341BeginSpi ; (R16, R17)
rcall ili9341SetAddressWindow ; (R16, r20, r21) rcall ili9341SetAddressWindow ; (R16, r20, r21)
mov r18, r2 ; color
mov r19, r3
mov r22, r10 ; H low mov r22, r10 ; H low
mov r23, r11 ; H high mov r23, r11 ; H high
ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM
@@ -42,14 +41,14 @@ Display_FillRect_loopH:
mov r24, r8 ; W low mov r24, r8 ; W low
mov r25, r9 ; W high mov r25, r9 ; W high
Display_FillRect_loopW: Display_FillRect_loopW:
mov r16, r19 mov r16, r3
rcall SPIHW_MasterTransfer ; (R16) rcall SPIHW_MasterTransfer ; (R16)
mov r16, r18 mov r16, r2
rcall SPIHW_MasterTransfer ; (R16) rcall SPIHW_MasterTransfer ; (R16)
sbiw r25:r24, 1 sbiw r25:r24, 1
brne Display_FillRect_loopW brne Display_FillRect_loopW
mov r24, r22 ; H low mov r24, r22 ; remaining H low
mov r25, r23 ; H high mov r25, r23 ; remaining H high
sbiw r25:r24, 1 ; dec sbiw r25:r24, 1 ; dec
mov r22, r24 ; save in r23:r22 mov r22, r24 ; save in r23:r22
mov r23, r25 mov r23, r25
@@ -67,10 +66,10 @@ Display_FillRect_loopW:
; @routine Display_DrawRect @global ; @routine Display_DrawRect @global
; ;
; @param r3:r2 color ; @param r3:r2 color
; @param r5:r4 X0 ; @param r5:r4 X
; @param r7:r6 Y0 ; @param r7:r6 Y
; @param r9:r8 X1/W ; @param r9:r8 W
; @param r11:r10 Y1/H ; @param r11:r10 H
Display_DrawRect: Display_DrawRect:
push r15 push r15
@@ -78,31 +77,33 @@ Display_DrawRect:
cli cli
; upper H line ; upper H line
rcall Display_DrawHLine rcall Display_DrawHLine ; (R16, R17, R20, R21, R24, R25)
push r6 ; save Y0 push r6 ; save Y0
push r7 push r7
add r6, r10 add r6, r10 ; Y+=(H-1)
adc r7, r11 adc r7, r11
ldi r16, 1 ldi r16, 1
clr r17
sub r6, r16 sub r6, r16
sbc r7, r16 sbc r7, r17
add r7, r16
; lower H line ; lower H line
rcall Display_DrawHLine rcall Display_DrawHLine
pop r7 pop r7
pop r6 pop r6
; left H line ; left V line
rcall Display_DrawVLine rcall Display_DrawVLine
push r4 ; save X0 push r4 ; save X0
push r5 push r5
add r4, r8 add r4, r8 ; X+=W-1
adc r5, r9 adc r5, r9
ldi r16, 1 ldi r16, 1
clr r17
sub r4, r16 sub r4, r16
sbc r5, r16 sbc r5, r17
add r5, r16 ; right V line
; right H line
rcall Display_DrawVLine rcall Display_DrawVLine
pop r5 pop r5
pop r4 pop r4
@@ -118,36 +119,29 @@ Display_DrawRect:
; @routine Display_DrawHLine @global ; @routine Display_DrawHLine @global
; ;
; @param r3:r2 color ; @param r3:r2 color
; @param r5:r4 X0 ; @param r5:r4 X
; @param r7:r6 Y0 ; @param r7:r6 Y
; @param r9:r8 W ; @param r9:r8 W
; @clobbers R16, R17, R20, R21, R24, R25
Display_DrawHLine: Display_DrawHLine:
push r15 push r15
in r15, SREG in r15, SREG
cli cli
ldi r16, 1 ; height is 1 push r10
mov r10, r16 push r11
clr r11 clr r10
rcall ili9341BeginSpi ; (R16, R17) inc r10 ; height is 1
rcall ili9341SetAddressWindow ; (R16, r20, r21) clr r11
rcall ili9341BeginSpi ; (R16, R17)
ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM rcall ili9341SetAddressWindow ; (R16, r20, r21)
rcall ili9341SendCommand ; (R16) pop r11
pop r10
cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low mov r24, r8 ; W low
sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) mov r25, r9 ; W high
mov r24, r8 ; W low rcall displaySendColor ; (R16)
mov r25, r9 ; W high
Display_DrawHLine_loop:
mov r16, r3
rcall SPIHW_MasterTransfer ; (R16)
mov r16, r2
rcall SPIHW_MasterTransfer ; (R16)
sbiw r25:r24, 1
brne Display_DrawHLine_loop
sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high
rcall ili9341EndSpi rcall ili9341EndSpi
out SREG, r15 out SREG, r15
pop r15 pop r15
@@ -163,33 +157,26 @@ Display_DrawHLine_loop:
; @param r5:r4 X0 ; @param r5:r4 X0
; @param r7:r6 Y0 ; @param r7:r6 Y0
; @param r11:r10 H ; @param r11:r10 H
; @clobbers R16, R17, R20, R21, R24, R25
Display_DrawVLine: Display_DrawVLine:
push r15 push r15
in r15, SREG in r15, SREG
cli cli
ldi r16, 1 ; width is 1 push r8
mov r8, r16 push r9
clr r9 clr r8
rcall ili9341BeginSpi ; (R16, R17) inc r8 ; width is 1
rcall ili9341SetAddressWindow ; (R16, r20, r21) clr r9
rcall ili9341BeginSpi ; (R16, R17)
ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM rcall ili9341SetAddressWindow ; (R16, r20, r21)
rcall ili9341SendCommand ; (R16) pop r9
pop r8
cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low mov r24, r10 ; H low
sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA) mov r25, r11 ; H high
mov r24, r10 ; H low rcall displaySendColor ; (R16)
mov r25, r11 ; H high
Display_DrawVLine_loop:
mov r16, r3
rcall SPIHW_MasterTransfer ; (R16)
mov r16, r2
rcall SPIHW_MasterTransfer ; (R16)
sbiw r25:r24, 1
brne Display_DrawVLine_loop
sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high
rcall ili9341EndSpi rcall ili9341EndSpi
out SREG, r15 out SREG, r15
pop r15 pop r15
@@ -198,6 +185,32 @@ Display_DrawVLine_loop:
; ---------------------------------------------------------------------------
; @routine displaySendColor
; @param r25:r24 number of pixel to write
; @param r3:r2 color to write
; @clobbers r16
displaySendColor:
ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM
rcall ili9341SendCommand ; (R16)
cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low
sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA)
displaySendColor_loop:
mov r16, r3
rcall SPIHW_MasterTransfer ; (R16)
mov r16, r2
rcall SPIHW_MasterTransfer ; (R16)
sbiw r25:r24, 1
brne displaySendColor_loop
sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high
ret
; @end
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine Display_DrawChar @global ; @routine Display_DrawChar @global
@@ -480,6 +493,21 @@ ili9341BitBlitStretchNWriteLine_loop2:
; @clobbers R16, r20, r21 ; @clobbers R16, r20, r21
ili9341SetAddressWindow: ili9341SetAddressWindow:
rcall ili9341SetColumnAddress ; (R16, r20, r21)
rcall ili9341SetRowAddress ; (R16, r20, r21)
ret
; @end
; ---------------------------------------------------------------------------
; @routine ili9341SetColumnAddress
;
; @param r5:r4 X0
; @param r9:r8 W
; @clobbers R16, r20, r21
ili9341SetColumnAddress:
; calc XEnd (=X+W-1) ; calc XEnd (=X+W-1)
mov r20, r8 mov r20, r8
mov r21, r9 mov r21, r9
@@ -491,17 +519,35 @@ ili9341SetAddressWindow:
; send column address ; send column address
ldi r16, ILI9341_CMD_CASET ldi r16, ILI9341_CMD_CASET
rcall ili9341SendCommand ; (R16) rcall ili9341SendCommand ; (R16)
; X0
mov r16, r5
rcall ili9341SendData ; (R16)
mov r16, r4
rcall ili9341SendData ; (R16)
; X1
mov r16, r21
rcall ili9341SendData ; (R16)
mov r16, r20
rcall ili9341SendData ; (R16)
cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low
sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA)
; Xstart
mov r16, r5
rcall SPIHW_MasterTransfer ; (R16)
mov r16, r4
rcall SPIHW_MasterTransfer ; (R16)
; Xend
mov r16, r21
rcall SPIHW_MasterTransfer ; (R16)
mov r16, r20
rcall SPIHW_MasterTransfer ; (R16)
sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high
ret
; @end
; ---------------------------------------------------------------------------
; @routine ili9341SetRowAddress
;
; @param r7:r6 Y0
; @param r11:r10 H
; @clobbers R16, r20, r21
ili9341SetRowAddress:
; calc YEnd (=Y+H-1) ; calc YEnd (=Y+H-1)
mov r20, r10 mov r20, r10
mov r21, r11 mov r21, r11
@@ -512,18 +558,23 @@ ili9341SetAddressWindow:
; send row address ; send row address
ldi r16, ILI9341_CMD_PASET ldi r16, ILI9341_CMD_PASET
rcall ili9341SendCommand ; (R16) rcall ili9341SendCommand ; (R16)
; Y0
mov r16, r7
rcall ili9341SendData ; (R16)
mov r16, r6
rcall ili9341SendData
; Y1
mov r16, r21
rcall ili9341SendData ; (R16)
mov r16, r20
rcall ili9341SendData ; (R16)
cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low
sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA)
; Ystart
mov r16, r7
rcall SPIHW_MasterTransfer ; (R16)
mov r16, r6
rcall SPIHW_MasterTransfer ; (R16)
; Yend
mov r16, r21
rcall SPIHW_MasterTransfer ; (R16)
mov r16, r20
rcall SPIHW_MasterTransfer ; (R16)
sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high
ret ret
; @end ; @end