more work on images on ili9341
- reading images from predefined ressources (stored at 0x8000+) works - drawing IDX2 images within widgets works - added some image ressources in IDX2 format
This commit is contained in:
@@ -78,7 +78,7 @@
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_Init @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
|
||||
Widget_Init:
|
||||
rcall Widget_GetSdramPtr ; (none)
|
||||
@@ -93,7 +93,7 @@ Widget_Init:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_OnCreate @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @return CFLAG set if signal handled
|
||||
; @clobbers any, !Z
|
||||
|
||||
@@ -108,7 +108,7 @@ Widget_OnCreate:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_OnTouch @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param xl param1
|
||||
; @param xh param2
|
||||
; @return CFLAG set if signal handled
|
||||
@@ -186,7 +186,7 @@ Widget_OnTouch_ret:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_OnDraw @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param xl param1
|
||||
; @param xh param2
|
||||
; @return CFLAG set if signal handled
|
||||
@@ -264,7 +264,7 @@ Widget_IsPointInRect_ret:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_LoadDisplayRegs @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @return R1:R0 background color
|
||||
; @return R3:R2 foreground color
|
||||
; @return R5:R4 X
|
||||
@@ -299,7 +299,7 @@ Widget_LoadDisplayRegs:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_GetSdramPtr @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @return Y pointer to SDRAM data for widget
|
||||
; @clobbers none
|
||||
|
||||
@@ -316,7 +316,7 @@ Widget_GetSdramPtr:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_AddFlagsDown @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param R16 flags to add
|
||||
; @clobbers R17, R18, R19, Y
|
||||
|
||||
@@ -354,7 +354,7 @@ Widget_AddFlagsDown_ret:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_SubFlagsDown @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param R16 flags to add
|
||||
; @clobbers R17, R18, R19, Y
|
||||
|
||||
@@ -394,7 +394,7 @@ Widget_SubFlagsDown_ret:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_Clear @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
|
||||
Widget_Clear:
|
||||
rcall Widget_LoadDisplayRegs
|
||||
@@ -414,7 +414,7 @@ Widget_Clear:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_SelectColors @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param Y pointer to Widget data in SDRAM
|
||||
; @return r1:r0 background color
|
||||
; @return r3:r2 foreground color
|
||||
@@ -457,7 +457,7 @@ Widget_SelectColors_ret:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_MakeAbsPos @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param r5:r4 X0
|
||||
; @param r7:r6 Y0
|
||||
; @clobbers r16, r17
|
||||
@@ -484,7 +484,7 @@ Widget_MakeAbsPos:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_FillRect @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param r3:r2 color
|
||||
; @param r5:r4 X0
|
||||
; @param r7:r6 Y0
|
||||
@@ -503,7 +503,7 @@ Widget_FillRect:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_DrawBorder @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param r3:r2 color
|
||||
; @clobbers any, !Z
|
||||
|
||||
@@ -519,10 +519,33 @@ Widget_DrawBorder:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_DrawImage @global
|
||||
;
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param R1:R0 background color
|
||||
; @param R5:R4 X relative to widget
|
||||
; @param R7:R6 Y relative to widget
|
||||
; @param R13:R12 byte address pointer to image in FLASH (for LPM!)
|
||||
|
||||
Widget_DrawImage:
|
||||
rcall widgetCalcAbsPosAndBorders
|
||||
push zl
|
||||
push zh
|
||||
mov zl, r12
|
||||
mov zh, r13
|
||||
bigcall ili9341ImageDraw
|
||||
pop zh
|
||||
pop zl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_DrawTextFlash @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param R5:R4 X relative to widget
|
||||
; @param R7:R6 Y relative to widget
|
||||
; @param R13:R12 byte address pointer to text in flash (for LPM!)
|
||||
@@ -539,7 +562,7 @@ Widget_DrawTextFlash:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_DrawColoredTextFlash @global
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param R1:R0 background color
|
||||
; @param R3:R2 foreground color
|
||||
; @param R5:R4 X relative to widget
|
||||
@@ -575,7 +598,7 @@ Widget_DrawColoredTextFlash_loopEnd:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine widgetCalcAbsPosAndBorders
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param R5:R4 X relative to widget
|
||||
; @param R7:R6 Y relative to widget
|
||||
; @return R9:R8 first X pos right of widget
|
||||
@@ -615,7 +638,7 @@ widgetCalcAbsPosAndBorders:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine widgetDrawChar
|
||||
;
|
||||
; @param Z byte address of object (for LPM!)
|
||||
; @param Z byte address of widget object (for LPM!)
|
||||
; @param R16 char to write
|
||||
; @param R5:R4 absolute X on screen
|
||||
; @param R7:R6 absolute Y on screen
|
||||
@@ -675,7 +698,7 @@ widgetDrawChar_done:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_Tree_Init @global
|
||||
;
|
||||
; @param Z byte address of root object (for LPM!)
|
||||
; @param Z byte address of root widget object (for LPM!)
|
||||
|
||||
Widget_Tree_Init:
|
||||
push zl
|
||||
@@ -700,7 +723,7 @@ Widget_Tree_Init_loopEnd:
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine Widget_Tree_Draw @global
|
||||
;
|
||||
; @param Z byte address of root object (for LPM!)
|
||||
; @param Z byte address of root widget object (for LPM!)
|
||||
|
||||
Widget_Tree_Draw:
|
||||
ldi r16, WIDGET_SIGNAL_DRAW
|
||||
|
||||
@@ -15,5 +15,198 @@
|
||||
.equ DISPLAY_IMAGETYPE_IDX2 = 1 ; 2 bit indexed image
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data
|
||||
|
||||
.dseg
|
||||
|
||||
ili9341ImageColormap:
|
||||
.byte 8
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ili9341ImageDraw
|
||||
|
||||
; @param R1:R0 background color
|
||||
; @param R5:R4 X (dest)
|
||||
; @param R7:R6 Y (dest)
|
||||
; @param Z pointer to image
|
||||
; @clobbers any
|
||||
|
||||
ili9341ImageDraw:
|
||||
adiw zh:zl, RES_IMAGE_OFFS_TYPE_LO
|
||||
lpm r18, Z+
|
||||
lpm r19, Z
|
||||
sbiw zh:zl, RES_IMAGE_OFFS_TYPE_LO+1
|
||||
tst r19
|
||||
brne ili9341ImageDraw_ret
|
||||
cpi r18, DISPLAY_IMAGETYPE_IDX2
|
||||
breq ili9341ImageDraw_idx2
|
||||
; add more here
|
||||
rjmp ili9341ImageDraw_ret
|
||||
ili9341ImageDraw_idx2:
|
||||
rcall ili9341ImageIdx2Draw ; (any)
|
||||
ili9341ImageDraw_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ili9341ImageIdx2Draw
|
||||
|
||||
; @param R1:R0 background color
|
||||
; @param R5:R4 X (dest)
|
||||
; @param R7:R6 Y (dest)
|
||||
; @param Z pointer to IDX2 image
|
||||
; @clobbers any
|
||||
|
||||
ili9341ImageIdx2Draw:
|
||||
rcall ili9341ImageIdx2CopyColormap ; (R16, X)
|
||||
|
||||
; read image width and height
|
||||
adiw zh:zl, RES_IMAGE_OFFS_WIDTH_LO
|
||||
lpm r8, Z+ ; read width (lo)
|
||||
lpm r9, Z+
|
||||
lpm r10, Z+ ; read height
|
||||
lpm r11, Z
|
||||
adiw zh:zl, (RES_IMAGE_OFFS_PIXELS_LO-RES_IMAGE_OFFS_HEIGHT_HI) ; skip 3 bytes
|
||||
lpm r16, Z+
|
||||
lpm zh, Z
|
||||
mov zl, r16
|
||||
or r16, zh
|
||||
breq ili9341ImageIdx2Draw_ret
|
||||
|
||||
; write image
|
||||
push r15
|
||||
in r15, SREG
|
||||
cli
|
||||
|
||||
rcall ili9341BeginSpi ; (r16, r17)
|
||||
rcall ili9341SetAddressWindow ; (R16, R20, R21)
|
||||
|
||||
ldi r16, ILI9341_CMD_RAMWR ; start writing ro RAM
|
||||
rcall ili9341SendCommand
|
||||
|
||||
cbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS low
|
||||
sbi ILI9341_DC_OUTPUT, ILI9341_DC_PIN ; D high (DATA)
|
||||
|
||||
rcall ili9341ImageIdx2WritePixels ; (R10, R16, R18, R19, R20, R21, R22, R23, R24, R25, X, Z)
|
||||
|
||||
sbi SPIHW_SS_OUTPUT, SPIHW_SS_PIN ; SS high
|
||||
rcall ili9341EndSpi ; (R16)
|
||||
out SREG, r15
|
||||
pop r15
|
||||
|
||||
ili9341ImageIdx2Draw_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ili9341ImageIdx2CopyColormap
|
||||
|
||||
; @param R1:R0 background color
|
||||
; @param Z pointer to IDX2 image
|
||||
; @clobbers r16, X
|
||||
|
||||
ili9341ImageIdx2CopyColormap:
|
||||
; get colormap
|
||||
ldi xl, LOW(ili9341ImageColormap)
|
||||
ldi xh, HIGH(ili9341ImageColormap)
|
||||
push zl
|
||||
push zh
|
||||
adiw zh:zl, RES_IMAGE_OFFS_COLORMAP_LO
|
||||
lpm r16, Z+
|
||||
lpm zh, Z
|
||||
mov zl, r16
|
||||
or r16, zh
|
||||
breq ili9341ImageIdx2CopyColormap_l1 ; no color map
|
||||
adiw zh:zl, 2 ; skip numOfEntries
|
||||
rcall ili9341ImageReadColormap
|
||||
ili9341ImageIdx2CopyColormap_l1:
|
||||
pop zh
|
||||
pop zl
|
||||
sts ili9341ImageColormap, r0
|
||||
sts ili9341ImageColormap+1, r1 ; store background color in pos 0 of colormap
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ili9341ImageIdx2WritePixels
|
||||
|
||||
; @param r9:r8 W
|
||||
; @param r11:r10 H
|
||||
; @param Z pointer to pixel data of IDX2 image
|
||||
; @clobbers R10, R16, R18, R19, R20, R21, R22, R23, R24, R25, X, Z
|
||||
|
||||
ili9341ImageIdx2WritePixels:
|
||||
clr r22
|
||||
ili9341ImageIdx2WritePixels_vertLoop:
|
||||
mov r20, r8 ; runWidth
|
||||
ili9341ImageIdx2WritePixels_horizLoop:
|
||||
tst r22 ; pixelCounterInByte
|
||||
brne ili9341ImageIdx2WritePixels_l1
|
||||
lpm r23, Z+ ; runByte
|
||||
ldi r22, 4 ; 4 pixels per byte
|
||||
ili9341ImageIdx2WritePixels_l1:
|
||||
clr r21 ; temp (receives current pixel)
|
||||
lsl r23 ; shift upper two bits into runtime var
|
||||
rol r21
|
||||
lsl r23
|
||||
rol r21
|
||||
lsl r21 ; 2 bytes per color
|
||||
ldi xl, LOW(ili9341ImageColormap)
|
||||
ldi xh, HIGH(ili9341ImageColormap)
|
||||
add xl, r21 ; add to X -> pos in palette
|
||||
adc xh, r21
|
||||
sub xh, r21
|
||||
ld r18, X+
|
||||
ld r19, X
|
||||
mov r16, r19 ; send to SPI
|
||||
rcall SPIHW_MasterTransfer ; (R16)
|
||||
mov r16, r18
|
||||
rcall SPIHW_MasterTransfer ; (R16)
|
||||
|
||||
dec r22 ; pixelCounterInByte
|
||||
dec r20 ; runWidth
|
||||
brne ili9341ImageIdx2WritePixels_horizLoop
|
||||
dec r10 ; height
|
||||
brne ili9341ImageIdx2WritePixels_vertLoop
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine ili9341ImageReadColormap
|
||||
|
||||
; @param X dest pointer for colormap in SDRAM (8 bytes, i.e. 4 colors by 2 bytes)
|
||||
; @param Z src byte pointer of colormap (for LPM!)
|
||||
|
||||
ili9341ImageReadColormap:
|
||||
ldi r17, 8 ; 8 bytes
|
||||
ili9341ImageReadColormap_loop:
|
||||
lpm r16, Z+
|
||||
st X+, r16
|
||||
dec r17
|
||||
brne ili9341ImageReadColormap_loop
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user