Mercurial > public > hwos_code
comparison src/tft.asm @ 151:5cb177f0948a
work on flip screen...
author | heinrichsweikamp |
---|---|
date | Mon, 18 Aug 2014 17:37:00 +0200 |
parents | 53409476a05f |
children | 19ad15f04f60 |
comparison
equal
deleted
inserted
replaced
150:074b1a9ded7b | 151:5cb177f0948a |
---|---|
79 rcall TFT_DataWrite | 79 rcall TFT_DataWrite |
80 endm | 80 endm |
81 | 81 |
82 | 82 |
83 basic CODE | 83 basic CODE |
84 | 84 ; |
85 | 85 ; |
86 ;============================================================================= | 86 ;;============================================================================= |
87 ; TFT_write_flash_image | 87 ;; TFT_write_flash_image |
88 ; | 88 ;; |
89 ; Inputs: FSR2 = EEPROM address / 256 | 89 ;; Inputs: FSR2 = EEPROM address / 256 |
90 ; win_left, win_top : imagte CENTER position | 90 ;; win_left, win_top : imagte CENTER position |
91 ; Outputs: win_height, win_width. | 91 ;; Outputs: win_height, win_width. |
92 ; image copyed on screen. | 92 ;; image copyed on screen. |
93 ; Trashed: PROD, hi, lo | 93 ;; Trashed: PROD, hi, lo |
94 ; | 94 ;; |
95 global TFT_write_flash_image | 95 ; global TFT_write_flash_image |
96 TFT_write_flash_image: | 96 ;TFT_write_flash_image: |
97 ; Get back the full 24bit EEPROM address | 97 ; ; Get back the full 24bit EEPROM address |
98 clrf ext_flash_address+0 | 98 ; clrf ext_flash_address+0 |
99 movff FSR2L,ext_flash_address+1 | 99 ; movff FSR2L,ext_flash_address+1 |
100 movf FSR2H,W | 100 ; movf FSR2H,W |
101 iorlw 0x30 | 101 ; iorlw 0x30 |
102 movwf ext_flash_address+2 | 102 ; movwf ext_flash_address+2 |
103 | 103 ; |
104 ; Read header: width and height | 104 ; ; Read header: width and height |
105 global TFT_write_flash_image_addr | 105 ; global TFT_write_flash_image_addr |
106 TFT_write_flash_image_addr: | 106 ;TFT_write_flash_image_addr: |
107 call ext_flash_read_block_start | 107 ; call ext_flash_read_block_start |
108 movff SSP2BUF,win_width+0 | 108 ; movff SSP2BUF,win_width+0 |
109 movwf SSP2BUF ; Write to buffer to initiate new read | 109 ; movwf SSP2BUF ; Write to buffer to initiate new read |
110 btfss SSP2STAT, BF ; Next byte ready ? | 110 ; btfss SSP2STAT, BF ; Next byte ready ? |
111 bra $-2 ; NO: wait... | 111 ; bra $-2 ; NO: wait... |
112 movff SSP2BUF,win_width+1 | 112 ; movff SSP2BUF,win_width+1 |
113 movwf SSP2BUF ; Write to buffer to initiate new read | 113 ; movwf SSP2BUF ; Write to buffer to initiate new read |
114 btfss SSP2STAT, BF ; Next byte ready ? | 114 ; btfss SSP2STAT, BF ; Next byte ready ? |
115 bra $-2 ; NO: wait... | 115 ; bra $-2 ; NO: wait... |
116 movff SSP2BUF,win_height | 116 ; movff SSP2BUF,win_height |
117 movwf SSP2BUF ; Write to buffer to initiate new read | 117 ; movwf SSP2BUF ; Write to buffer to initiate new read |
118 btfss SSP2STAT, BF ; Next byte ready ? | 118 ; btfss SSP2STAT, BF ; Next byte ready ? |
119 bra $-2 ; NO: wait... | 119 ; bra $-2 ; NO: wait... |
120 movff SSP2BUF,WREG ; drop 4th byte. | 120 ; movff SSP2BUF,WREG ; drop 4th byte. |
121 movwf SSP2BUF ; Write to buffer to initiate new read | 121 ; movwf SSP2BUF ; Write to buffer to initiate new read |
122 btfss SSP2STAT, BF ; Next byte ready ? | 122 ; btfss SSP2STAT, BF ; Next byte ready ? |
123 bra $-2 ; NO: wait... | 123 ; bra $-2 ; NO: wait... |
124 | 124 ; |
125 ; Sanity check on header to avoid badly uploaded images. | 125 ; ; Sanity check on header to avoid badly uploaded images. |
126 iorwf WREG ; Check height < 256 | 126 ; iorwf WREG ; Check height < 256 |
127 bnz TFT_write_flash_image_failed | 127 ; bnz TFT_write_flash_image_failed |
128 movf win_width+1,W ; Check width < 512 | 128 ; movf win_width+1,W ; Check width < 512 |
129 andlw 0xFE | 129 ; andlw 0xFE |
130 bnz TFT_write_flash_image_failed | 130 ; bnz TFT_write_flash_image_failed |
131 | 131 ; |
132 ; Center image on win_top, win_left values | 132 ; ; Center image on win_top, win_left values |
133 bcf STATUS,C ; Clear carry | 133 ; bcf STATUS,C ; Clear carry |
134 rrcf win_height,W ; And get height/2 | 134 ; rrcf win_height,W ; And get height/2 |
135 subwf win_top,F ; top -= height/2 | 135 ; subwf win_top,F ; top -= height/2 |
136 rrcf win_width+1,W ; Get 9th bit into carry | 136 ; rrcf win_width+1,W ; Get 9th bit into carry |
137 rrcf win_width+0,W ; Get width/2 (in 0..320 range) | 137 ; rrcf win_width+0,W ; Get width/2 (in 0..320 range) |
138 bcf STATUS,C | 138 ; bcf STATUS,C |
139 rrcf WREG,W ; Get width/2 in 0..160 range | 139 ; rrcf WREG,W ; Get width/2 in 0..160 range |
140 subwf win_leftx2,F ; left -= width/2 | 140 ; subwf win_leftx2,F ; left -= width/2 |
141 | 141 ; |
142 rcall TFT_box_write ; Inputs : win_top, win_leftx2, win_height, win_width(in 1..320 range) | 142 ; rcall TFT_box_write ; Inputs : win_top, win_leftx2, win_height, win_width(in 1..320 range) |
143 | 143 ; |
144 ; Compute number of pixels to move (result on 17 bits !) | 144 ; ; Compute number of pixels to move (result on 17 bits !) |
145 clrf TBLPTRU | 145 ; clrf TBLPTRU |
146 movf win_width+0,W | 146 ; movf win_width+0,W |
147 mulwf win_height ; Result in PRODL:H | 147 ; mulwf win_height ; Result in PRODL:H |
148 movf win_width+1,W | 148 ; movf win_width+1,W |
149 bz TFT_write_flash_image_1 ; width > 8bits ? | 149 ; bz TFT_write_flash_image_1 ; width > 8bits ? |
150 movf win_height,W ; YES: add extra | 150 ; movf win_height,W ; YES: add extra |
151 addwf PRODH,F | 151 ; addwf PRODH,F |
152 rlcf TBLPTRU ; And carry into upper register. | 152 ; rlcf TBLPTRU ; And carry into upper register. |
153 TFT_write_flash_image_1: | 153 ;TFT_write_flash_image_1: |
154 incf PRODH,F ; Pre-condition nested loops | 154 ; incf PRODH,F ; Pre-condition nested loops |
155 incf TBLPTRU,F | 155 ; incf TBLPTRU,F |
156 | 156 ; |
157 ; Write pixels | 157 ; ; Write pixels |
158 Index_out 0x22 ; Frame Memory Data Write start | 158 ; Index_out 0x22 ; Frame Memory Data Write start |
159 RS_H ; Data | 159 ; RS_H ; Data |
160 | 160 ; |
161 TFT_write_flash_image_loop: | 161 ;TFT_write_flash_image_loop: |
162 btfss SSP2STAT, BF ; Buffer full? | 162 ; btfss SSP2STAT, BF ; Buffer full? |
163 bra $-2 ; NO: wait... | 163 ; bra $-2 ; NO: wait... |
164 movff SSP2BUF,PORTH ; Read lo | 164 ; movff SSP2BUF,PORTH ; Read lo |
165 movwf SSP2BUF ; Write to buffer to initiate new read | 165 ; movwf SSP2BUF ; Write to buffer to initiate new read |
166 | 166 ; |
167 btfss SSP2STAT, BF ; Buffer full? | 167 ; btfss SSP2STAT, BF ; Buffer full? |
168 bra $-2 ; NO: wait... | 168 ; bra $-2 ; NO: wait... |
169 movff SSP2BUF,PORTA ; And read hi | 169 ; movff SSP2BUF,PORTA ; And read hi |
170 movwf SSP2BUF ; Write to buffer to initiate new read | 170 ; movwf SSP2BUF ; Write to buffer to initiate new read |
171 WR_L | 171 ; WR_L |
172 WR_H ; Write 1 Pixel | 172 ; WR_H ; Write 1 Pixel |
173 | 173 ; |
174 decfsz PRODL,F | 174 ; decfsz PRODL,F |
175 bra TFT_write_flash_image_loop | 175 ; bra TFT_write_flash_image_loop |
176 decfsz PRODH,F | 176 ; decfsz PRODH,F |
177 bra TFT_write_flash_image_loop | 177 ; bra TFT_write_flash_image_loop |
178 decfsz TBLPTRU,F | 178 ; decfsz TBLPTRU,F |
179 bra TFT_write_flash_image_loop | 179 ; bra TFT_write_flash_image_loop |
180 | 180 ; |
181 btfss SSP2STAT, BF ; Buffer full? | 181 ; btfss SSP2STAT, BF ; Buffer full? |
182 bra $-2 ; No, wait | 182 ; bra $-2 ; No, wait |
183 movf SSP2BUF,W ; Read dummy byte | 183 ; movf SSP2BUF,W ; Read dummy byte |
184 | 184 ; |
185 bsf flash_ncs ; CS=1 | 185 ; bsf flash_ncs ; CS=1 |
186 movlw 0x00 ; NOP, to stop window mode | 186 ; movlw 0x00 ; NOP, to stop window mode |
187 bra TFT_CmdWrite ; This routine "returns" | 187 ; bra TFT_CmdWrite ; This routine "returns" |
188 | 188 ; |
189 ;---- Draw a 4x4 red square in place of missing images... | 189 ; ;---- Draw a 4x4 red square in place of missing images... |
190 TFT_write_flash_image_failed: | 190 ;TFT_write_flash_image_failed: |
191 movlw -1 | 191 ; movlw -1 |
192 addwf win_leftx2,F | 192 ; addwf win_leftx2,F |
193 movlw -2 | 193 ; movlw -2 |
194 addwf win_top,F | 194 ; addwf win_top,F |
195 movlw 2 | 195 ; movlw 2 |
196 movwf win_width+0 | 196 ; movwf win_width+0 |
197 clrf win_width+1 | 197 ; clrf win_width+1 |
198 movlw 4 | 198 ; movlw 4 |
199 movwf win_height | 199 ; movwf win_height |
200 movlw color_red | 200 ; movlw color_red |
201 rcall TFT_set_color | 201 ; rcall TFT_set_color |
202 goto TFT_box | 202 ; goto TFT_box |
203 | 203 ; |
204 ;============================================================================= | 204 ;;============================================================================= |
205 ; | 205 ; |
206 | 206 |
207 global TFT_CmdWrite | 207 global TFT_CmdWrite |
208 TFT_CmdWrite: | 208 TFT_CmdWrite: |
209 RS_L ; Command | 209 RS_L ; Command |
241 Index_out 0x22 ; Frame Memory Data Write start | 241 Index_out 0x22 ; Frame Memory Data Write start |
242 | 242 |
243 RD_H ; Not Read | 243 RD_H ; Not Read |
244 RS_H ; Data | 244 RS_H ; Data |
245 NCS_L ; Not CS | 245 NCS_L ; Not CS |
246 clrf PORTA ; Data Upper | 246 ; clrf PORTA ; Data Upper |
247 clrf PORTH ; Data Lower | 247 clrf PORTH ; Data Lower |
248 | 248 |
249 movlw d'10' | 249 movlw d'10' |
250 movwf tft_temp3 | 250 movwf tft_temp3 |
251 TFT_ClearScreen2: | 251 TFT_ClearScreen2: |
490 bra half_pixel_write ; Note: Cmd 0x20 is mandatory, because | 490 bra half_pixel_write ; Note: Cmd 0x20 is mandatory, because |
491 ; of the autoincrement going vertical | 491 ; of the autoincrement going vertical |
492 | 492 |
493 global pixel_write_col320 | 493 global pixel_write_col320 |
494 pixel_write_col320: | 494 pixel_write_col320: |
495 btfss flip_screen ; 180° rotation? | |
496 bra pixel_write_noflip_H ; No | |
497 | |
498 movf PRODL,W ; 16bits 319 - PROD --> PROD | |
499 sublw LOW(.319) ; 319-W --> W | |
500 movwf PRODL | |
501 movf PRODH,W | |
502 btfss STATUS,C ; Borrow = /CARRY | |
503 incf WREG | |
504 sublw HIGH(.319) | |
505 movwf PRODH | |
506 | |
507 pixel_write_noflip_H: | |
495 Index_out 0x21 ; Frame Memory Vertical Address | 508 Index_out 0x21 ; Frame Memory Vertical Address |
496 bra TFT_DataWrite_PROD | 509 bra TFT_DataWrite_PROD |
497 | 510 |
498 ;----------------------------------------------------------------------------- | 511 ;----------------------------------------------------------------------------- |
499 ; Writes one half-pixel at position (win_top,win_leftx2). | 512 ; Writes one half-pixel at position (win_top,win_leftx2). |
502 global half_pixel_write | 515 global half_pixel_write |
503 half_pixel_write: | 516 half_pixel_write: |
504 movff win_top,WREG ; d'0' ... d'239' | 517 movff win_top,WREG ; d'0' ... d'239' |
505 ; Variant with Y position in WREG. | 518 ; Variant with Y position in WREG. |
506 half_pixel_write_1: | 519 half_pixel_write_1: |
507 sublw .239 ; 239-Y --> Y | 520 btfss flip_screen ; 180° rotation? |
508 | 521 sublw .239 ; 239-Y --> Y |
509 mullw 1 ; Copy row to PRODH:L | 522 mullw 1 ; Copy row to PRODL (PRODH=0) |
523 | |
510 Index_out 0x20 ; Frame Memory Horizontal Address | 524 Index_out 0x20 ; Frame Memory Horizontal Address |
511 rcall TFT_DataWrite_PROD | 525 rcall TFT_DataWrite_PROD |
512 | 526 |
513 Index_out 0x22 ; Frame Memory Data Write start | 527 Index_out 0x22 ; Frame Memory Data Write start |
514 RS_H ; Data | 528 RS_H ; Data |
615 global TFT_box_write | 629 global TFT_box_write |
616 TFT_box_write: | 630 TFT_box_write: |
617 movff win_leftx2,WREG ; Compute left = 2*leftx2 --> PROD | 631 movff win_leftx2,WREG ; Compute left = 2*leftx2 --> PROD |
618 mullw 2 | 632 mullw 2 |
619 | 633 |
634 btfsc flip_screen ; 180° rotation ? | |
635 bra DISP_box_flip_H ; Yes | |
636 | |
620 global TFT_box_write_16bit_win_left | 637 global TFT_box_write_16bit_win_left |
621 TFT_box_write_16bit_win_left: ; With column in PRODL:PRODH | 638 TFT_box_write_16bit_win_left: ; With column in PRODL:PRODH |
622 ;---- Normal horizontal window --------------------------------------- | 639 ;---- Normal horizontal window --------------------------------------- |
623 ; Output 0x35 left, | 640 ; Output 0x35 left, |
624 ; 0x36 right == left + width - 1. | 641 ; 0x36 right == left + width - 1. |
636 btfss STATUS,C | 653 btfss STATUS,C |
637 decf PRODH,F | 654 decf PRODH,F |
638 | 655 |
639 Index_out 0x53 ; Window Vertical End Address | 656 Index_out 0x53 ; Window Vertical End Address |
640 rcall TFT_DataWrite_PROD | 657 rcall TFT_DataWrite_PROD |
641 | 658 bra DISP_box_noflip_H |
659 | |
660 ;---- Flipped horizontal window -------------------------------------- | |
661 DISP_box_flip_H: | |
662 ; Output 0x36 flipped(left) = 319-left | |
663 ; 0x35 flipped(right) = 319-right = 320 - left - width | |
664 movf PRODL,W ; 16bits 319 - PROD --> PROD | |
665 sublw LOW(.319) ; 319-W --> W | |
666 movwf PRODL | |
667 movf PRODH,W | |
668 btfss STATUS,C ; Borrow = /CARRY | |
669 incf WREG | |
670 sublw HIGH(.319) | |
671 movwf PRODH | |
672 Index_out 0x52 ; Window Vertical Start Address | |
673 rcall TFT_DataWrite_PROD ; Output left | |
674 Index_out 0x21 ; Frame Memory Vertical Address | |
675 rcall TFT_DataWrite_PROD ; Output left | |
676 | |
677 movff win_width+0,WREG ; right = left + width - 1 | |
678 addwf PRODL,F | |
679 movff win_width+1,WREG | |
680 addwfc PRODH,F | |
681 decf PRODL,F ; decrement result | |
682 btfss STATUS,C | |
683 decf PRODH,F | |
684 | |
685 Index_out 0x53 ; Window Vertical End Address | |
686 rcall TFT_DataWrite_PROD | |
687 | |
688 DISP_box_noflip_H: | |
689 btfss flip_screen ; 180° rotation ? | |
690 bra TFT_box_flip_V ; Yes. | |
691 | |
692 ;---- Normal vertical window ----------------------------------------- | |
693 movff win_top,PRODL ; Second byte | |
694 movff win_height,WREG | |
695 addwf PRODL,W | |
696 movwf PRODH ; First byte | |
697 | |
698 | |
699 Index_out 0x50 ; Window Horizontal Start Address | |
700 clrf PORTA ; Upper | |
701 movf PRODH,W | |
702 rcall TFT_DataWrite ; Lower (and tick) | |
703 | |
704 Index_out 0x51 ; Window Horizontal End Address | |
705 clrf PORTA ; Upper | |
706 movf PRODL,W | |
707 rcall TFT_DataWrite ; Lower (and tick) | |
708 | |
709 Index_out 0x20 ; Frame Memory Horizontal Address | |
710 clrf PORTA ; Upper | |
711 movf PRODL,W | |
712 rcall TFT_DataWrite ; Lower (and tick) | |
713 return | |
714 | |
715 | |
716 TFT_box_flip_V: | |
642 ;---- Flipped vertical window ---------------------------------------- | 717 ;---- Flipped vertical window ---------------------------------------- |
643 ; Output 0x37 flipped(bottom) = 239-bottom = 240 - top - height | 718 ; Output 0x37 flipped(bottom) = 239-bottom = 240 - top - height |
644 ; flipped(top) = 239-top | 719 ; flipped(top) = 239-top |
645 TFT_box_flip_V: | |
646 movff win_top,PRODL | 720 movff win_top,PRODL |
647 movff win_height,WREG | 721 movff win_height,WREG |
648 addwf PRODL,W | 722 addwf PRODL,W |
649 sublw .240 ; 240 - top - height | 723 sublw .240 ; 240 - top - height |
650 movwf PRODH ; First byte | 724 movwf PRODH ; First byte |
651 | 725 |
652 movf PRODL,W | 726 movf PRODL,W |
653 sublw .239 ; 249-top | 727 sublw .239 ; 239-top |
654 movwf PRODL ; --> second byte. | 728 movwf PRODL ; --> second byte. |
655 | 729 |
656 Index_out 0x50 ; Window Horizontal Start Address | 730 Index_out 0x50 ; Window Horizontal Start Address |
657 clrf PORTA ; Upper | 731 clrf PORTA ; Upper |
658 movf PRODH,W | 732 movf PRODH,W |