Mercurial > public > hwos_code
annotate src/tft.asm @ 610:2ce43f09586e
Mod for new pcb designs
author | heinrichsweikamp |
---|---|
date | Wed, 09 Jan 2019 18:35:20 +0100 |
parents | d866684249bd |
children | c40025d8e750 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
604 | 3 ; File tft.asm ## V2.99c |
0 | 4 ; |
5 ; Managing the TFT screen | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code. | |
11 | |
275 | 12 #include "hwos.inc" |
0 | 13 #include "wait.inc" |
14 #include "varargs.inc" | |
15 #include "external_flash.inc" | |
16 #include "tft_outputs.inc" | |
17 #include "eeprom_rs232.inc" | |
18 | |
19 ;============================================================================= | |
20 ; Basic bit-level macros | |
21 | |
582 | 22 RD_H macro |
23 bsf tft_rd,0 | |
24 endm | |
0 | 25 |
582 | 26 RD_L macro |
27 bcf tft_rd,0 | |
28 endm | |
0 | 29 |
582 | 30 RS_H macro |
31 bsf tft_rs,0 | |
32 endm | |
0 | 33 |
582 | 34 RS_L macro |
35 bcf tft_rs,0 | |
36 endm | |
0 | 37 |
582 | 38 NCS_H macro |
39 bsf tft_cs,0 | |
40 endm | |
0 | 41 |
582 | 42 NCS_L macro |
43 bcf tft_cs,0 | |
44 endm | |
0 | 45 |
582 | 46 WR_H macro |
47 bsf tft_nwr,0 | |
48 endm | |
0 | 49 |
582 | 50 WR_L macro |
51 bcf tft_nwr,0 | |
52 endm | |
0 | 53 |
54 ;============================================================================= | |
582 | 55 ; Byte-level macros |
56 | |
0 | 57 Index_out macro low_b |
58 movlw low_b | |
59 rcall TFT_CmdWrite | |
60 endm | |
61 | |
62 Parameter_out macro high_b, low_b | |
63 movlw high_b | |
604 | 64 movwf PORTA ; upper |
0 | 65 movlw low_b |
66 rcall TFT_DataWrite | |
67 endm | |
68 | |
69 | |
604 | 70 tft CODE |
582 | 71 |
151 | 72 ;;============================================================================= |
73 ;; TFT_write_flash_image | |
74 ;; | |
75 ;; Inputs: FSR2 = EEPROM address / 256 | |
582 | 76 ;; win_left, win_top : image CENTER position |
151 | 77 ;; Outputs: win_height, win_width. |
582 | 78 ;; image copied on screen. |
151 | 79 ;; Trashed: PROD, hi, lo |
80 ;; | |
81 ; global TFT_write_flash_image | |
82 ;TFT_write_flash_image: | |
582 | 83 ; ; Get back the full 24bit EEPROM address |
84 ; clrf ext_flash_address+0 | |
85 ; movff FSR2L,ext_flash_address+1 | |
86 ; movf FSR2H,W | |
87 ; iorlw 0x30 | |
88 ; movwf ext_flash_address+2 | |
151 | 89 ; |
582 | 90 ; ; Read header: width and height |
91 ; global TFT_write_flash_image_addr | |
151 | 92 ;TFT_write_flash_image_addr: |
93 ; call ext_flash_read_block_start | |
582 | 94 ; movff SSP2BUF,win_width+0 |
604 | 95 ; movwf SSP2BUF ; write to buffer to initiate new read |
96 ; btfss SSP2STAT, BF ; next byte ready ? | |
97 ; bra $-2 ; NO - wait... | |
582 | 98 ; movff SSP2BUF,win_width+1 |
604 | 99 ; movwf SSP2BUF ; write to buffer to initiate new read |
100 ; btfss SSP2STAT, BF ; next byte ready ? | |
101 ; bra $-2 ; NO - wait... | |
582 | 102 ; movff SSP2BUF,win_height |
604 | 103 ; movwf SSP2BUF ; write to buffer to initiate new read |
104 ; btfss SSP2STAT, BF ; next byte ready ? | |
105 ; bra $-2 ; NO - wait... | |
106 ; movff SSP2BUF,WREG ; drop 4th byte | |
107 ; movwf SSP2BUF ; write to buffer to initiate new read | |
108 ; btfss SSP2STAT, BF ; next byte ready ? | |
109 ; bra $-2 ; NO - wait... | |
151 | 110 ; |
582 | 111 ; ; Sanity check on header to avoid badly uploaded images. |
604 | 112 ; iorwf WREG ; check height < 256 |
582 | 113 ; bnz TFT_write_flash_image_failed |
604 | 114 ; movf win_width+1,W ; check width < 512 |
582 | 115 ; andlw 0xFE |
116 ; bnz TFT_write_flash_image_failed | |
151 | 117 ; |
582 | 118 ; ; Center image on win_top, win_left values |
604 | 119 ; bcf STATUS,C ; clear carry |
120 ; rrcf win_height,W ; and get height/2 | |
582 | 121 ; subwf win_top,F ; top -= height/2 |
604 | 122 ; rrcf win_width+1,W ; get 9th bit into carry |
123 ; rrcf win_width+0,W ; get width/2 (in 0..320 range) | |
582 | 124 ; bcf STATUS,C |
604 | 125 ; rrcf WREG,W ; get width/2 in 0..160 range |
582 | 126 ; subwf win_leftx2,F ; left -= width/2 |
151 | 127 ; |
604 | 128 ; rcall TFT_box_write ; inputs : win_top, win_leftx2, win_height, win_width (in 1..320 range) |
0 | 129 ; |
582 | 130 ; ; Compute number of pixels to move (result on 17 bits !) |
131 ; clrf TBLPTRU | |
132 ; movf win_width+0,W | |
604 | 133 ; mulwf win_height ; result in PRODL:H |
582 | 134 ; movf win_width+1,W |
135 ; bz TFT_write_flash_image_1 ; width > 8bits ? | |
604 | 136 ; movf win_height,W ; YES - add extra |
582 | 137 ; addwf PRODH,F |
604 | 138 ; rlcf TBLPTRU ; and carry into upper register |
151 | 139 ;TFT_write_flash_image_1: |
582 | 140 ; incf PRODH,F ; pre-condition nested loops |
141 ; incf TBLPTRU,F | |
151 | 142 ; |
582 | 143 ; ; Write pixels |
604 | 144 ; Index_out 0x22 ; frame memory data write start |
145 ; RS_H ; data | |
151 | 146 ; |
147 ;TFT_write_flash_image_loop: | |
604 | 148 ; btfss SSP2STAT, BF ; buffer full? |
149 ; bra $-2 ; NO - wait... | |
150 ; movff SSP2BUF,PORTH ; read lo | |
151 ; movwf SSP2BUF ; write to buffer to initiate new read | |
151 | 152 ; |
604 | 153 ; btfss SSP2STAT, BF ; buffer full? |
154 ; bra $-2 ; NO - wait... | |
155 ; movff SSP2BUF,PORTA ; and read hi | |
156 ; movwf SSP2BUF ; write to buffer to initiate new read | |
151 | 157 ; WR_L |
604 | 158 ; WR_H ; write 1 pixel |
151 | 159 ; |
160 ; decfsz PRODL,F | |
161 ; bra TFT_write_flash_image_loop | |
162 ; decfsz PRODH,F | |
163 ; bra TFT_write_flash_image_loop | |
164 ; decfsz TBLPTRU,F | |
165 ; bra TFT_write_flash_image_loop | |
166 ; | |
604 | 167 ; btfss SSP2STAT, BF ; buffer full? |
168 ; bra $-2 ; NO - wait | |
169 ; movf SSP2BUF,W ; read dummy byte | |
151 | 170 ; |
582 | 171 ; bsf flash_ncs ; CS=1 |
172 ; movlw 0x00 ; NOP, to stop window mode | |
604 | 173 ; bra TFT_CmdWrite ; this routine "returns" |
151 | 174 ; |
175 ; ;---- Draw a 4x4 red square in place of missing images... | |
176 ;TFT_write_flash_image_failed: | |
582 | 177 ; movlw -1 |
178 ; addwf win_leftx2,F | |
179 ; movlw -2 | |
180 ; addwf win_top,F | |
181 ; movlw 2 | |
182 ; movwf win_width+0 | |
183 ; clrf win_width+1 | |
184 ; movlw 4 | |
185 ; movwf win_height | |
186 ; movlw color_red | |
187 ; rcall TFT_set_color | |
188 ; goto TFT_box | |
151 | 189 ; |
190 ;;============================================================================= | |
0 | 191 |
582 | 192 |
193 global TFT_ClearScreen | |
0 | 194 TFT_ClearScreen: |
608 | 195 btfsc screen_type2 |
196 bra TFT_ClearScreen_display2 | |
604 | 197 Index_out 0x50 ; window horizontal start address |
582 | 198 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 199 Index_out 0x51 ; window horizontal end address |
582 | 200 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 201 Index_out 0x52 ; window vertical start address |
582 | 202 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 203 Index_out 0x53 ; window vertical end address |
582 | 204 Parameter_out 0x01, 0x3F ; 0-319 |
604 | 205 Index_out 0x20 ; frame memory horizontal address |
582 | 206 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 207 Index_out 0x21 ; frame memory vertical address |
582 | 208 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 209 |
604 | 210 Index_out 0x22 ; frame memory data write start |
0 | 211 |
604 | 212 RD_H ; not read |
213 RS_H ; data | |
214 NCS_L ; not CS | |
215 clrf PORTH ; data lower | |
0 | 216 |
217 movlw d'10' | |
218 movwf tft_temp3 | |
219 TFT_ClearScreen2: | |
220 movlw d'30' | |
221 movwf tft_temp2 | |
222 TFT_ClearScreen3: | |
604 | 223 clrf tft_temp1 ; 30*10*256=76800 pixels -> clear complete 240*320 |
582 | 224 bcf INTCON,GIE |
0 | 225 TFT_ClearScreen4: |
226 WR_L | |
604 | 227 WR_H ; tick |
0 | 228 decfsz tft_temp1,F |
229 bra TFT_ClearScreen4 | |
582 | 230 bsf INTCON,GIE |
0 | 231 decfsz tft_temp2,F |
232 bra TFT_ClearScreen3 | |
233 decfsz tft_temp3,F | |
234 bra TFT_ClearScreen2 | |
582 | 235 |
236 movlw 0x00 ; NOP, to stop window mode | |
604 | 237 bra TFT_CmdWrite ; and return |
582 | 238 |
608 | 239 TFT_ClearScreen_display2: |
240 ; Column Address start | |
241 movlw 0x02 | |
242 rcall TFT_CmdWrite | |
243 movlw 0x00 | |
244 rcall TFT_DataWrite | |
245 movlw 0x03 | |
246 rcall TFT_CmdWrite | |
247 movlw 0x00 | |
248 rcall TFT_DataWrite | |
249 | |
250 ; Column Address end | |
251 movlw 0x04 | |
252 rcall TFT_CmdWrite | |
253 movlw 0x00 | |
254 rcall TFT_DataWrite | |
255 movlw 0x05 | |
256 rcall TFT_CmdWrite | |
257 movlw 0xEF | |
258 rcall TFT_DataWrite | |
259 | |
260 ; Row address start | |
261 movlw 0x06 | |
262 rcall TFT_CmdWrite | |
263 movlw 0x00 | |
264 rcall TFT_DataWrite | |
265 movlw 0x07 | |
266 rcall TFT_CmdWrite | |
267 movlw 0x00 | |
268 rcall TFT_DataWrite | |
269 | |
270 ; Row address end | |
271 movlw 0x08 | |
272 rcall TFT_CmdWrite | |
273 movlw 0x01 | |
274 rcall TFT_DataWrite | |
275 movlw 0x09 | |
276 rcall TFT_CmdWrite | |
277 movlw 0x3F | |
278 rcall TFT_DataWrite | |
279 | |
280 movlw 0x22 ; Start Writing Data to GRAM | |
281 rcall TFT_CmdWrite | |
282 | |
283 bsf tft_rs ; Data! | |
284 | |
285 movlw .160 | |
286 movwf PRODH | |
287 clrf PORTH | |
288 TFT_ClearScreen2_display2: | |
289 movlw .240 | |
290 movwf PRODL | |
291 TFT_ClearScreen3_display2: | |
292 bcf tft_nwr | |
293 bsf tft_nwr ; Upper | |
294 bcf tft_nwr | |
295 bsf tft_nwr ; High | |
296 bcf tft_nwr | |
297 bsf tft_nwr ; Lower | |
298 bcf tft_nwr | |
299 bsf tft_nwr ; Upper | |
300 bcf tft_nwr | |
301 bsf tft_nwr ; High | |
302 bcf tft_nwr | |
303 bsf tft_nwr ; Lower | |
304 decfsz PRODL,F | |
305 bra TFT_ClearScreen3_display2 | |
306 decfsz PRODH,F | |
307 bra TFT_ClearScreen2_display2 | |
308 return | |
0 | 309 |
310 ;============================================================================= | |
582 | 311 |
312 global TFT_DisplayOff | |
0 | 313 TFT_DisplayOff: |
608 | 314 clrf CCP1CON ; stop PWM |
315 bcf PORTC,2 ; Pull PWM out to GND | |
0 | 316 clrf PORTA |
582 | 317 clrf PORTH |
608 | 318 RD_L ; LOW |
319 RS_L ; LOW | |
320 bcf tft_nwr | |
321 bcf tft_cs | |
322 bcf tft_nreset | |
323 bsf tft_power ; inverted... | |
324 bcf lightsen_power ; power-down light sensor | |
0 | 325 return |
326 | |
327 ; ----------------------------- | |
328 ; TFT boot | |
329 ; ----------------------------- | |
582 | 330 |
331 global TFT_boot | |
0 | 332 TFT_boot: |
608 | 333 clrf CCP1CON ; stop PWM |
334 bcf PORTC,2 ; Pull PWM out to GND | |
0 | 335 clrf PORTA |
336 clrf PORTH | |
337 RD_L ; LOW | |
338 bcf tft_nwr | |
339 nop | |
340 bcf tft_cs | |
341 nop | |
342 bcf tft_nreset | |
343 WAITMS d'1' | |
344 bcf tft_power ; inverted... | |
345 WAITMS d'1' | |
346 | |
347 RD_H ; Keep high | |
348 WR_H ; | |
349 NCS_L ; Not CS | |
350 | |
351 WAITMS d'2' | |
352 bsf tft_nreset | |
461 | 353 WAITMS d'5' |
354 bcf tft_nreset | |
355 WAITMS d'5' | |
356 bsf tft_nreset | |
0 | 357 WAITMS d'150' |
604 | 358 bsf lightsen_power ; supply power to light sensor |
0 | 359 |
582 | 360 ; Data Transfer Synchronization |
0 | 361 Parameter_out 0x00, 0x00 |
362 Parameter_out 0x00, 0x00 | |
582 | 363 |
608 | 364 btfsc screen_type2 ; Display 2 |
365 bra TFT_boot_screen2 | |
366 | |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
367 ; Get screentype from Bootloader-Info |
582 | 368 movlw 0x7B |
369 movwf TBLPTRL | |
370 movlw 0xF7 | |
371 movwf TBLPTRH | |
372 movlw 0x01 | |
373 movwf TBLPTRU | |
604 | 374 TBLRD*+ ; reads .110 for cR and USB OSTC3, .0 for BLE (2 and 3), and .2 for display1 OSTC |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
375 movlw 0x02 |
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
376 cpfseq TABLAT |
604 | 377 bra TFT_boot_0 ; display0 |
360 | 378 |
379 TFT_boot_1: | |
582 | 380 ; Init through config table... |
381 movlw 0x74 | |
382 movwf TBLPTRL | |
383 movlw 0xF7 | |
384 movwf TBLPTRH | |
385 movlw 0x01 | |
386 movwf TBLPTRU | |
387 bsf screen_type | |
388 bra TFT_boot_com | |
360 | 389 |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
390 TFT_boot_0: |
582 | 391 ; Init through config table... |
392 movlw LOW display0_config_table | |
393 movwf TBLPTRL | |
394 movlw HIGH display0_config_table | |
395 movwf TBLPTRH | |
396 movlw UPPER display0_config_table | |
397 movwf TBLPTRU | |
398 bcf screen_type | |
399 | |
360 | 400 TFT_boot_com: |
582 | 401 rcall display0_init_loop |
0 | 402 |
582 | 403 Index_out 0x03 |
404 btfsc flip_screen ; 180° rotation ? | |
604 | 405 bra TFT_boot2 ; YES |
360 | 406 |
582 | 407 btfss screen_type ; display1? |
604 | 408 bra TFT_boot1a ; NO |
582 | 409 Parameter_out 0x10, 0x00 ; display1 |
410 bra TFT_boot3 | |
360 | 411 TFT_boot1a: |
582 | 412 Parameter_out 0x50, 0x20 ; display0 |
413 bra TFT_boot3 | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
414 TFT_boot2: |
582 | 415 btfss screen_type ; display1? |
604 | 416 bra TFT_boot2a ; NO |
582 | 417 Parameter_out 0x10, 0x30 ; display1 |
418 bra TFT_boot3 | |
360 | 419 TFT_boot2a: |
582 | 420 Parameter_out 0x50, 0x10 ; display0 |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
421 TFT_boot3: |
0 | 422 Index_out 0x22 |
225
31088352ee32
BUGFIX: Show dives with >999mins divetime correctly
heinrichsweikamp
parents:
152
diff
changeset
|
423 rcall TFT_ClearScreen |
0 | 424 Index_out 0x07 |
312 | 425 Parameter_out 0x01, 0x33 |
0 | 426 return |
427 | |
428 display0_config_table: | |
582 | 429 ; Reg, Dat0, Dat1 or 0xFF,0x00,0x00 for end |
430 db 0xA4,0x00,0x01,0xFF,.002,0x00 | |
431 db 0x09,0x00,0x01,0x92,0x04,0x00 | |
432 db 0x93,0x04,0x02,0x94,0x00,0x02 | |
433 db 0x07,0x00,0x00,0x10,0x04,0x30 | |
434 db 0x11,0x02,0x37,0x12,0x11,0x8D | |
435 db 0x13,0x11,0x00,0x01,0x01,0x00 | |
436 db 0x02,0x02,0x00,0x03,0x50,0x20 | |
437 db 0x0A,0x00,0x08,0x0D,0x00,0x00 | |
438 db 0x0E,0x00,0x30,0xFF,.151,0x00 | |
439 db 0x12,0x11,0xBD,0x20,0x00,0x00 | |
440 db 0x21,0x00,0x00,0x30,0x06,0x02 | |
441 db 0x31,0x56,0x0D,0x32,0x05,0x07 | |
442 db 0x33,0x06,0x09,0x34,0x00,0x00 | |
443 db 0x35,0x09,0x06,0x36,0x57,0x05 | |
444 db 0x37,0x0D,0x06,0x38,0x02,0x06 | |
445 db 0x39,0x00,0x00,0xFF,0x00,0x00 | |
0 | 446 |
447 display0_init_loop: | |
582 | 448 TBLRD*+ |
449 movlw 0xFF | |
450 cpfseq TABLAT | |
604 | 451 bra display0_config_write ; write config pair to display |
582 | 452 ; Delay ms or quit (return) |
453 TBLRD*+ | |
604 | 454 tstfsz TABLAT ; end of config? |
455 bra $+4 ; NO | |
456 return ; YES - done | |
582 | 457 movf TABLAT,W |
604 | 458 call WAITMSX ; wait WREG milliseconds |
459 TBLRD*+ ; dummy read (Third byte of delay command) | |
460 bra display0_init_loop ; loop | |
0 | 461 |
604 | 462 display0_config_write: ; with command in WREG |
582 | 463 movf TABLAT,W |
604 | 464 rcall TFT_CmdWrite ; write command |
465 TBLRD*+ ; get config0 | |
582 | 466 movff TABLAT,PORTA |
604 | 467 TBLRD*+ ; get config1 |
582 | 468 movf TABLAT,W |
604 | 469 rcall TFT_DataWrite ; write config |
470 bra display0_init_loop ; loop | |
0 | 471 |
608 | 472 TFT_boot_screen2: |
473 bsf tft_nwr ; release bus. | |
474 rcall display1_init ; Init sequence | |
475 | |
476 btfss flip_screen ; 180° rotation ? | |
477 bra TFT_ClearScreen ; No, done. Clearscreen and return | |
478 ; flip the GRAM | |
479 Index_out 0x16 | |
480 movlw 0x48 ; Flip image in the GRAM (Very elegant with display2...) | |
481 rcall TFT_DataWrite ; Write config | |
482 bra TFT_ClearScreen ; Clearscreen and return | |
483 | |
484 | |
485 display1_init: | |
486 movlw LOW 0x1F8BC | |
487 movwf TBLPTRL | |
488 movlw HIGH 0x1F8BC | |
489 movwf TBLPTRH | |
490 movlw UPPER 0x1F8BC | |
491 movwf TBLPTRU | |
492 display1_init_loop: | |
493 TBLRD*+ | |
494 movlw 0xFF | |
495 cpfseq TABLAT | |
496 bra display1_config_write ; Write Config pair to Display | |
497 ; Delay ms or quit (return) | |
498 TBLRD*+ | |
499 tstfsz TABLAT ; End of config? | |
500 bra $+4 ; No | |
501 return ; Done. | |
502 movf TABLAT,W | |
503 call WAITMSX ; Wait WREG milliseconds | |
504 bra display1_init_loop ; Loop | |
505 | |
506 display1_config_write: ; With command in WREG | |
507 movf TABLAT,W | |
508 rcall TFT_CmdWrite ; Write command | |
509 TBLRD*+ ; Get config | |
510 movf TABLAT,W | |
511 rcall TFT_DataWrite ; Write config | |
512 bra display1_init_loop ; Loop | |
513 | |
0 | 514 |
515 ;============================================================================= | |
608 | 516 |
517 global TFT_CmdWrite | |
518 TFT_CmdWrite: | |
519 RS_L ; command | |
520 btfsc screen_type2 | |
521 bra TFT_CmdWrite_screen2 | |
522 clrf PORTA ; upper | |
523 bcf INTCON,GIE | |
524 movwf PORTH ; lower | |
525 WR_L | |
526 WR_H ; tick | |
527 bsf INTCON,GIE | |
528 return | |
529 TFT_CmdWrite_screen2: | |
530 movwf PORTH ; Lower | |
531 WR_L | |
532 WR_H ; Tick | |
533 return; | |
534 | |
535 global TFT_DataWrite | |
536 TFT_DataWrite: | |
537 RS_H ; data | |
538 btfsc screen_type2 | |
539 bra TFT_DataWrite_screen2 | |
540 bcf INTCON,GIE | |
541 movwf PORTH ; lower | |
542 WR_L | |
543 WR_H ; tick | |
544 bsf INTCON,GIE | |
545 return | |
546 TFT_DataWrite_screen2: | |
547 movwf PORTH ; Lower | |
548 WR_L | |
549 WR_H ; Tick | |
550 return | |
551 | |
552 ;============================================================================= | |
553 | |
0 | 554 ; Smooth lighting-up of the display: |
555 ; | |
556 ; Trashes: WREG, PRODL | |
557 ; Typical usage: | |
604 | 558 ; clrf CCPR1L ; backlight off |
582 | 559 ; [draw splash screen] |
560 ; call TFT_DisplayFadeIn | |
561 | |
562 global TFT_Display_FadeIn | |
0 | 563 TFT_Display_FadeIn: |
604 | 564 movlw CCP1CON_VALUE ; see hwos.inc |
582 | 565 movwf CCP1CON |
604 | 566 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
567 clrf CCPR1L ; backlight off - to be sure | |
582 | 568 movff max_CCPR1L,PRODL |
0 | 569 TFT_Display_FadeIn_0: |
604 | 570 incf CCPR1L,F ; duty cycle |
582 | 571 WAITMS d'2' |
572 decfsz PRODL,F | |
573 bra TFT_Display_FadeIn_0 | |
604 | 574 bcf tft_is_dimming ; dimming done |
582 | 575 return |
0 | 576 |
577 ;============================================================================= | |
578 ; Smooth lighting-off of the display: | |
579 ; Trashes: WREG, PRODL | |
582 | 580 |
581 global TFT_Display_FadeOut | |
0 | 582 TFT_Display_FadeOut: |
582 | 583 movff max_CCPR1L,PRODL |
604 | 584 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
0 | 585 TFT_Display_FadeOut_0: |
604 | 586 movff PRODL,CCPR1L ; duty cycle |
582 | 587 WAITMS d'1' |
588 decfsz PRODL,F | |
589 bra TFT_Display_FadeOut_0 | |
590 clrf CCPR1L | |
591 return | |
0 | 592 |
593 ;============================================================================= | |
594 | |
604 | 595 global box_std_block, box_black_block, box_color_block |
0 | 596 |
604 | 597 box_std_block: ; use white color |
582 | 598 setf WREG |
599 bra box_common | |
604 | 600 box_black_block: ; use black color |
582 | 601 clrf WREG |
0 | 602 box_common: |
603 box_color_block: | |
582 | 604 rcall TFT_set_color |
605 VARARGS_BEGIN | |
606 VARARGS_GET8 win_top | |
607 VARARGS_GET8 win_height | |
608 VARARGS_GET8 win_leftx2 | |
609 VARARGS_GET8 win_width | |
610 VARARGS_END | |
611 bra TFT_box | |
0 | 612 |
613 ;----------------------------------------------------------------------------- | |
614 | |
582 | 615 global box_frame_std, box_frame_common, box_frame_color, box_frame_color16 |
0 | 616 |
617 box_frame_std: | |
582 | 618 setf WREG |
619 rcall TFT_set_color | |
0 | 620 box_frame_common: |
582 | 621 VARARGS_BEGIN |
622 VARARGS_GET8 win_top | |
623 VARARGS_GET8 win_height | |
624 VARARGS_GET8 win_leftx2 | |
625 VARARGS_GET8 win_width | |
626 VARARGS_END | |
627 bra TFT_frame | |
0 | 628 box_frame_color: |
582 | 629 rcall TFT_set_color |
0 | 630 box_frame_color16: |
582 | 631 bra box_frame_common |
0 | 632 |
434 | 633 ;;============================================================================= |
634 ;; Init for half_pixel_write | |
635 ;; Set column register on TFT device, and current color. | |
636 ;; Inputs: win_leftx2 | |
637 ;; Outputs: win_color:2 | |
638 ;; Trashed: WREG, PROD | |
582 | 639 ; |
640 ; global init_pixel_write | |
434 | 641 ;init_pixel_write: |
582 | 642 ; movf win_leftx2,W |
643 ; mullw 2 | |
604 | 644 ; rcall pixel_write_col320 ; start address vertical (.0 - .319) |
582 | 645 ; setf WREG |
646 ; bra TFT_set_color | |
0 | 647 |
648 ;----------------------------------------------------------------------------- | |
649 ; Writes two half-pixels at position (win_top,win_leftx2) | |
650 ; Inputs: win_leftx2, win_top, win_color:2 | |
651 ; Trashed: WREG, PROD | |
582 | 652 |
653 global pixel_write | |
0 | 654 pixel_write: |
582 | 655 movf win_leftx2,W |
656 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL | |
604 | 657 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
658 rcall half_pixel_write ; write this half-one | |
659 movf win_leftx2,W ; address of next one | |
582 | 660 mullw 2 |
661 infsnz PRODL ; +1 | |
662 incf PRODH | |
663 rcall pixel_write_col320 | |
604 | 664 bra half_pixel_write ; note: Cmd 0x20 is mandatory, because |
582 | 665 ; of the auto-increment going vertical |
0 | 666 |
667 global pixel_write_col320 | |
668 pixel_write_col320: | |
608 | 669 btfsc screen_type2 ; display2? |
670 bra pixel_write_col320_d2 ; Yes | |
582 | 671 btfsc screen_type ; display1? |
604 | 672 bra pixel_write_col320_d1 ; YES |
582 | 673 ; Display0 |
674 btfss flip_screen ; 180° rotation? | |
604 | 675 bra pixel_write_noflip_H ; NO |
676 bra pixel_write_flip_H ; YES | |
582 | 677 pixel_write_col320_d1: ; Display1 |
678 btfsc flip_screen ; 180° rotation? | |
604 | 679 bra pixel_write_noflip_H ; YES for d1 |
680 pixel_write_flip_H: ; flip d0 | |
681 movf PRODL,W ; 16 bits 319 - PROD --> PROD | |
582 | 682 sublw LOW(.319) ; 319-W --> W |
683 movwf PRODL | |
684 movf PRODH,W | |
604 | 685 btfss STATUS,C ; borrow = /CARRY |
582 | 686 incf WREG |
687 sublw HIGH(.319) | |
688 movwf PRODH | |
151 | 689 |
690 pixel_write_noflip_H: | |
604 | 691 Index_out 0x21 ; frame memory vertical address |
582 | 692 bra TFT_DataWrite_PROD ; and return... |
0 | 693 |
608 | 694 pixel_write_col320_d2: |
695 movlw 0x06 | |
696 rcall TFT_CmdWrite | |
697 movf PRODH,W | |
698 rcall TFT_DataWrite | |
699 movlw 0x07 | |
700 rcall TFT_CmdWrite | |
701 movf PRODL,W | |
702 rcall TFT_DataWrite | |
703 | |
704 incf PRODL,F | |
705 movlw .0 | |
706 addwfc PRODH,F ;+1 | |
707 | |
708 movlw 0x08 | |
709 rcall TFT_CmdWrite | |
710 movf PRODH,W | |
711 rcall TFT_DataWrite | |
712 movlw 0x09 | |
713 rcall TFT_CmdWrite | |
714 movf PRODL,W | |
715 bra TFT_DataWrite ; And return... | |
716 | |
0 | 717 ;----------------------------------------------------------------------------- |
718 ; Writes one half-pixel at position (win_top,win_leftx2). | |
719 ; Inputs: win_leftx2, win_top, win_color:2 | |
720 ; Trashed: WREG, PROD | |
582 | 721 |
722 global half_pixel_write | |
0 | 723 half_pixel_write: |
582 | 724 movf win_top,W ; d'0' ... d'239' |
725 ; Variant with Y position in WREG. | |
0 | 726 half_pixel_write_1: |
608 | 727 btfsc screen_type2 |
728 bra half_pixel_write_1_display1 ; Yes. | |
729 | |
582 | 730 btfss flip_screen ; 180° rotation? |
731 sublw .239 ; 239-Y --> Y | |
604 | 732 mullw .1 ; copy row to PRODL (PRODH=0) |
733 Index_out 0x20 ; frame memory horizontal address | |
582 | 734 rcall TFT_DataWrite_PROD |
0 | 735 |
604 | 736 Index_out 0x22 ; frame memory data write start |
737 RS_H ; data | |
582 | 738 bcf INTCON,GIE |
604 | 739 movff win_color1,PORTA ; upper |
740 movff win_color2,PORTH ; lower | |
582 | 741 WR_L |
604 | 742 WR_H ; tick |
582 | 743 bsf INTCON,GIE |
744 return | |
0 | 745 |
608 | 746 half_pixel_write_1_display1: |
747 mullw 1 ; Copy row to PRODL (PRODH=0) | |
748 ; Row address start | |
749 movlw 0x02 | |
750 rcall TFT_CmdWrite | |
751 movlw .0 | |
752 rcall TFT_DataWrite | |
753 movlw 0x03 | |
754 rcall TFT_CmdWrite | |
755 movf PRODL,W | |
756 rcall TFT_DataWrite | |
757 | |
758 incf PRODL,F | |
759 | |
760 movlw 0x04 | |
761 rcall TFT_CmdWrite | |
762 movlw .0 | |
763 rcall TFT_DataWrite | |
764 movlw 0x05 | |
765 rcall TFT_CmdWrite | |
766 movf PRODL,W | |
767 rcall TFT_DataWrite | |
768 | |
769 movff win_color1,PRODH | |
770 movff win_color2,PRODL | |
771 rcall convert_for_display2 | |
772 | |
773 movlw 0x22 ; Start Writing Data to GRAM | |
774 rcall TFT_CmdWrite | |
775 RS_H ; Data | |
776 movff win_color5, PORTH | |
777 WR_L | |
778 WR_H ; Tick | |
779 movff win_color4, PORTH | |
780 WR_L | |
781 WR_H ; Tick | |
782 movff win_color3, PORTH | |
783 WR_L | |
784 WR_H ; Tick | |
785 return | |
786 | |
0 | 787 ;----------------------------------------------------------------------------- |
788 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height). | |
789 ; Inputs: win_leftx2, win_top, win_height, win_color:2 | |
790 ; Trashed: WREG, PROD, TABLAT, TBLPTRL | |
582 | 791 |
0 | 792 global half_vertical_line |
793 half_vertical_line: | |
604 | 794 clrf TABLAT ; loop index |
0 | 795 |
796 half_vertical_line_loop: | |
604 | 797 movf win_leftx2,W ; init X position |
582 | 798 mullw .2 |
604 | 799 movf TABLAT,W ; get loop index |
800 andlw .1 ; just low bit | |
801 xorwf PRODL,F ; and use it to jitter current X position | |
802 rcall pixel_write_col320 ; start address vertical (.0 - .319) | |
0 | 803 |
604 | 804 movf win_height,W ; index reached height (bank0 read) ? |
582 | 805 xorwf TABLAT,W |
604 | 806 btfsc STATUS,Z ; Equal ? |
807 return ; YES - done | |
808 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 809 addwf TABLAT,W |
810 rcall half_pixel_write_1 | |
811 incf TABLAT,F ; index++ | |
812 bra half_vertical_line_loop | |
0 | 813 |
814 ;----------------------------------------------------------------------------- | |
815 ; Writes a horizontal line of half-pixel at position (win_top,win_leftx2,win_width). | |
816 ; Inputs: win_leftx2, win_top, win_width, win_color:2 | |
817 ; Trashed: WREG, PROD, TABLAT, TBLPTRL | |
582 | 818 |
0 | 819 global half_horizontal_line |
820 half_horizontal_line: | |
604 | 821 clrf TABLAT ; loop index |
0 | 822 |
823 half_horizontal_line_loop: | |
604 | 824 movf win_leftx2,W ; init X position |
582 | 825 mullw .2 |
604 | 826 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
827 movf win_width,W ; index reached height (bank0 read) ? | |
582 | 828 xorwf TABLAT,W |
604 | 829 btfsc STATUS,Z ; equal ? |
830 return ; YES - done | |
831 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 832 addwf TABLAT,W |
833 rcall half_pixel_write_1 | |
834 incf TABLAT,F ; index++ | |
835 bra half_horizontal_line_loop | |
0 | 836 |
837 | |
838 ;----------------------------------------------------------------------------- | |
839 ; TFT Data Cmd via W | |
582 | 840 |
841 global TFT_DataWrite_PROD | |
0 | 842 TFT_DataWrite_PROD: |
604 | 843 ; RD_H ; keep high |
844 RS_H ; data | |
608 | 845 btfsc screen_type2 |
846 bra TFT_DataWrite_PROD_display2 | |
582 | 847 bcf INTCON,GIE |
604 | 848 movff PRODH,PORTA ; move high byte to PORTA |
849 movff PRODL,PORTH ; move low byte to PORTH | |
0 | 850 WR_L |
604 | 851 WR_H ; tick |
582 | 852 bsf INTCON,GIE |
0 | 853 return |
854 | |
608 | 855 TFT_DataWrite_PROD_display2: |
856 movff PRODH,PORTH ; Move high byte to PORTH (DISPLAY is bigendian) | |
857 WR_L | |
858 WR_H | |
859 movff PRODL,PORTH ; Move low byte to PORTH | |
860 WR_L | |
861 WR_H | |
862 movff win_color3,PORTH ; Move low(est) byte to PORTH | |
863 WR_L | |
864 WR_H | |
865 return | |
866 | |
0 | 867 TFT_DataRead_PROD: |
604 | 868 Index_out 0x22 ; frame memory data read start |
360 | 869 TFT_CmdRead_PROD: |
604 | 870 setf TRISA ; port A as input |
871 setf TRISH ; port H as input | |
872 RS_H ; data | |
873 WR_H ; not write | |
874 RD_L ; read | |
582 | 875 nop |
876 nop | |
877 nop | |
604 | 878 RD_H ; tick |
582 | 879 nop |
880 nop | |
881 nop | |
604 | 882 RD_L ; read |
582 | 883 nop |
884 ;nop | |
885 ;nop | |
886 movff PORTA,PRODH | |
887 movff PORTH,PRODL | |
604 | 888 RD_H ; tick |
582 | 889 nop |
604 | 890 clrf TRISA ; port A as output |
891 clrf TRISH ; port H as output | |
0 | 892 return |
893 | |
894 ;============================================================================= | |
604 | 895 ; Output TFT Window Address commands |
896 ; Inputs : win_top, win_leftx2, win_height, win_width | |
897 ; Output : PortA/PortH commands | |
0 | 898 ; Trashed: PROD |
582 | 899 |
900 global TFT_box_write | |
0 | 901 TFT_box_write: |
604 | 902 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD |
432 | 903 mullw 2 |
0 | 904 |
608 | 905 btfsc screen_type2 |
906 bra TFT_box_write_display2 | |
907 | |
582 | 908 global TFT_box_write_16bit_win_left |
604 | 909 TFT_box_write_16bit_win_left: ; Wwth column in PRODL:PRODH |
582 | 910 btfsc screen_type ; display1? |
604 | 911 bra TFT_box_write_16bit_win_left_d1 ; YES |
582 | 912 ; Display0 |
913 btfsc flip_screen ; 180° rotation? | |
604 | 914 bra DISP_box_flip_H ; YES |
915 bra TFT_box_write_16bit_win_left_com ; NO | |
582 | 916 TFT_box_write_16bit_win_left_d1: ; Display1 |
917 btfss flip_screen ; 180° rotation? | |
604 | 918 bra DISP_box_flip_H ; NO for d1 |
582 | 919 ; Yes for d1 |
361 | 920 TFT_box_write_16bit_win_left_com: |
582 | 921 ;---- Normal horizontal window --------------------------------------- |
604 | 922 Index_out 0x52 ; window vertical start address |
923 rcall TFT_DataWrite_PROD ; output left | |
924 Index_out 0x21 ; frame memory vertical address | |
925 rcall TFT_DataWrite_PROD ; output left | |
0 | 926 |
582 | 927 movf win_width+0,W ; right = left + width - 1 |
432 | 928 addwf PRODL,F |
929 movf win_width+1,W | |
930 addwfc PRODH,F | |
582 | 931 decf PRODL,F ; decrement result |
932 btfss STATUS,C | |
432 | 933 decf PRODH,F |
0 | 934 |
604 | 935 Index_out 0x53 ; window vertical end address |
582 | 936 rcall TFT_DataWrite_PROD |
937 bra DISP_box_noflip_H | |
0 | 938 |
582 | 939 ;---- Flipped horizontal window -------------------------------------- |
151 | 940 DISP_box_flip_H: |
604 | 941 movf PRODL,W ; 16 bits 319 - PROD --> PROD |
942 sublw LOW(.319) ; 319 - WREG --> WREG | |
582 | 943 movwf PRODL |
944 movf PRODH,W | |
604 | 945 btfss STATUS,C ; borrow = /CARRY |
582 | 946 incf WREG |
947 sublw HIGH(.319) | |
948 movwf PRODH | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
949 |
604 | 950 Index_out 0x53 ; window vertical start address |
951 rcall TFT_DataWrite_PROD ; output left | |
952 Index_out 0x21 ; frame memory vertical address | |
953 rcall TFT_DataWrite_PROD ; output left | |
151 | 954 |
604 | 955 movf win_width+0,W ; 16 bits PROD - width --> PROD |
582 | 956 subwf PRODL,F ; PRODL - WREG --> PRODL |
957 movf win_width+1,W | |
958 subwfb PRODH,F | |
604 | 959 infsnz PRODL ; PROD + 1 --> PROD |
582 | 960 incf PRODH |
151 | 961 |
604 | 962 Index_out 0x52 ; window vertical end address |
582 | 963 rcall TFT_DataWrite_PROD |
151 | 964 |
965 DISP_box_noflip_H: | |
582 | 966 btfss flip_screen ; 180° rotation ? |
604 | 967 bra TFT_box_noflip_V ; NO |
151 | 968 |
582 | 969 ;---- Flipped vertical window ----------------------------------------- |
970 movff win_top,PRODH ; top --> PRODH (first byte) | |
971 movf win_height,W | |
972 addwf PRODH,W | |
432 | 973 decf WREG |
604 | 974 movwf PRODL ; top + height - 1 --> PRODL (second byte) |
151 | 975 |
604 | 976 Index_out 0x50 ; window horizontal start address |
432 | 977 movf PRODH,W |
604 | 978 rcall TFT_DataWrite ; lower (and tick) |
151 | 979 |
604 | 980 Index_out 0x51 ; window horizontal end address |
582 | 981 movf PRODL,W |
604 | 982 rcall TFT_DataWrite ; lower (and tick) |
582 | 983 |
604 | 984 Index_out 0x20 ; frame memory horizontal address |
432 | 985 movf PRODH,W |
604 | 986 bra TFT_DataWrite ; lower (and tick) and return |
151 | 987 |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
988 TFT_box_noflip_V: |
582 | 989 ;---- Normal vertical window ---------------------------------------- |
990 movff win_top,PRODL | |
991 movf win_height,W | |
992 addwf PRODL,W | |
993 sublw .240 ; 240 - top - height | |
604 | 994 movwf PRODH ; first byte |
0 | 995 |
432 | 996 movf PRODL,W |
604 | 997 sublw .239 ; 239 - top |
998 movwf PRODL ; --> second byte | |
0 | 999 |
604 | 1000 Index_out 0x50 ; window horizontal start address |
432 | 1001 movf PRODH,W |
604 | 1002 rcall TFT_DataWrite ; lower (and tick) |
0 | 1003 |
604 | 1004 Index_out 0x51 ; window horizontal end address |
432 | 1005 movf PRODL,W |
604 | 1006 rcall TFT_DataWrite ; lower (and tick) |
0 | 1007 |
604 | 1008 Index_out 0x20 ; frame memory horizontal address |
432 | 1009 movf PRODL,W |
604 | 1010 bra TFT_DataWrite ; lower (and tick) and return |
582 | 1011 |
608 | 1012 TFT_box_write_display2: |
1013 movlw 0x06 | |
1014 rcall TFT_CmdWrite | |
1015 movf PRODH,W | |
1016 rcall TFT_DataWrite | |
1017 movlw 0x07 | |
1018 rcall TFT_CmdWrite | |
1019 movf PRODL,W | |
1020 rcall TFT_DataWrite | |
1021 | |
1022 movf win_width+0,W ; right = left + width - 1 | |
1023 addwf PRODL,F | |
1024 movf win_width+1,W | |
1025 addwfc PRODH,F | |
1026 decf PRODL,F,A ; decrement result | |
1027 btfss STATUS,C | |
1028 decf PRODH,F,A | |
1029 | |
1030 movlw 0x08 | |
1031 rcall TFT_CmdWrite | |
1032 movf PRODH,W | |
1033 rcall TFT_DataWrite | |
1034 movlw 0x09 | |
1035 rcall TFT_CmdWrite | |
1036 movf PRODL,W | |
1037 rcall TFT_DataWrite | |
1038 | |
1039 ;---- Normal vertical window ----------------------------------------- | |
1040 ; Output (top) (bottom) | |
1041 movff win_top,PRODH ; top --> PRODH (first byte) | |
1042 movff win_height,WREG | |
1043 addwf PRODH,W | |
1044 decf WREG | |
1045 movwf PRODL ; top+height-1 --> PRODL (second byte) | |
1046 | |
1047 movlw 0x02 | |
1048 rcall TFT_CmdWrite | |
1049 movlw 0x00 | |
1050 rcall TFT_DataWrite | |
1051 movlw 0x03 | |
1052 rcall TFT_CmdWrite | |
1053 movf PRODH,W | |
1054 rcall TFT_DataWrite | |
1055 | |
1056 movlw 0x04 | |
1057 rcall TFT_CmdWrite | |
1058 movlw 0x00 | |
1059 rcall TFT_DataWrite | |
1060 movlw 0x05 | |
1061 rcall TFT_CmdWrite | |
1062 movf PRODL,W | |
1063 bra TFT_DataWrite ; and return | |
1064 | |
0 | 1065 |
1066 ;============================================================================= | |
604 | 1067 ; TFT_frame : draw a frame around current box with current color |
0 | 1068 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 |
1069 ; Outputs: (none) | |
1070 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 | |
1071 | |
582 | 1072 global TFT_frame |
1073 TFT_frame: | |
604 | 1074 movff win_top,save_top ; backup everything |
582 | 1075 movff win_height,save_height |
1076 movff win_leftx2,save_left | |
1077 movff win_width,save_width | |
0 | 1078 |
582 | 1079 ;---- TOP line ----------------------------------------------------------- |
604 | 1080 movlw .1 ; row ~ height = 1 |
582 | 1081 movwf win_height |
1082 rcall TFT_box | |
0 | 1083 |
582 | 1084 ;---- BOTTOM line -------------------------------------------------------- |
604 | 1085 movff save_top,PRODL ; get back top |
1086 movff save_height,WREG ; get back height | |
1087 addwf PRODL,W ; top + height | |
1088 decf WREG ; top + height - 1 | |
1089 movwf win_top ; top + height - 1 --> top | |
582 | 1090 rcall TFT_box |
0 | 1091 |
582 | 1092 ;---- LEFT column -------------------------------------------------------- |
604 | 1093 movff save_top,win_top ; restore top/height |
582 | 1094 movff save_height,win_height |
604 | 1095 movlw .1 ; column ~ width = 1 |
582 | 1096 movwf win_width+0 |
1097 rcall TFT_box | |
1098 | |
1099 ;---- RIGHT column ------------------------------------------------------- | |
1100 movff save_left,WREG | |
1101 movff save_width,PRODL | |
1102 addwf PRODL,W | |
1103 decf WREG | |
1104 movwf win_leftx2 | |
1105 rcall TFT_box | |
1106 | |
1107 ;---- Restore everything ------------------------------------------------- | |
1108 movff save_left,win_leftx2 | |
1109 movff save_width,win_width | |
1110 return | |
0 | 1111 |
1112 ;============================================================================= | |
604 | 1113 ; TFT_box: fills current box with current color |
1114 ; Inputs : win_top, win_leftx2, win_height, win_width, win_color1, win_color2 | |
0 | 1115 ; Outputs: (none) |
1116 ; Trashed: WREG, PROD | |
1117 | |
582 | 1118 global TFT_box |
0 | 1119 TFT_box: |
608 | 1120 btfsc screen_type2 |
1121 bra TFT_box_display2 | |
582 | 1122 ;---- Define Window ------------------------------------------------------ |
1123 bcf STATUS,C | |
1124 rlcf win_width+0,F | |
1125 rlcf win_width+1,F ; x2 | |
604 | 1126 rcall TFT_box_write ; setup box |
0 | 1127 |
582 | 1128 global TFT_box_16bit_win_left |
83 | 1129 TFT_box_16bit_win_left: |
582 | 1130 bcf STATUS,C |
1131 rrcf win_width+1,F ; width /= 2 | |
1132 rrcf win_width+0,F | |
0 | 1133 |
582 | 1134 ;---- Fill Window -------------------------------------------------------- |
604 | 1135 Index_out 0x22 ; frame memory data write start |
0 | 1136 |
604 | 1137 clrf PRODH ; column counter |
1138 RS_H ; data | |
0 | 1139 |
604 | 1140 TFT_box2: ; loop height times |
0 | 1141 movff win_height,PRODL |
1142 | |
582 | 1143 TFT_box3: ; loop width times |
436 | 1144 bcf INTCON,GIE |
604 | 1145 movff win_color1,PORTA ; upper |
1146 movff win_color2,PORTH ; lower | |
0 | 1147 WR_L |
604 | 1148 WR_H ; tick |
582 | 1149 |
604 | 1150 ; movff win_color1,PORTA ; upper |
1151 ; movff win_color2,PORTH ; lower | |
0 | 1152 WR_L |
604 | 1153 WR_H ; tick |
582 | 1154 bsf INTCON,GIE |
1155 decfsz PRODL,F ; row loop finished ? | |
604 | 1156 bra TFT_box3 ; NO - continue |
0 | 1157 |
582 | 1158 incf PRODH,F ; column count ++ |
0 | 1159 |
582 | 1160 movf win_bargraph,W ; current column == bargraph ? |
1161 cpfseq PRODH | |
604 | 1162 bra TFT_box4 ; NO - just loop |
1163 clrf win_color1 ; Yes - switch to black | |
1164 clrf win_color2 ; - ... | |
0 | 1165 TFT_box4: |
582 | 1166 movf win_width+0,W ; compare ? |
1167 xorwf PRODH,W | |
604 | 1168 bnz TFT_box2 ; Loop not finished |
0 | 1169 |
582 | 1170 movlw 0x00 ; NOP, to stop window mode |
1171 rcall TFT_CmdWrite | |
0 | 1172 |
604 | 1173 ; reset bargraph mode... |
582 | 1174 setf win_bargraph |
1175 return | |
608 | 1176 TFT_box_display2: |
1177 ;---- Define Window ------------------------------------------------------ | |
1178 bcf STATUS,C | |
1179 rlcf win_width+0,F | |
1180 rlcf win_width+1,F ; x2 | |
1181 rcall TFT_box_write ; Setup box | |
1182 | |
1183 bcf STATUS,C | |
1184 rrcf win_width+1,F ; width /= 2 | |
1185 rrcf win_width+0,F | |
1186 | |
1187 movff win_color1,PRODH | |
1188 movff win_color2,PRODL | |
1189 rcall convert_for_display2 | |
1190 ;---- Fill Window -------------------------------------------------------- | |
1191 Index_out 0x22 ; Frame Memory Data Write start | |
1192 | |
1193 clrf PRODH ; Column counter. | |
1194 RS_H ; Data | |
1195 | |
1196 TFT_box2_display2: ; Loop height times | |
1197 movff win_height,PRODL | |
1198 | |
1199 TFT_box3_display2: ; loop width times | |
1200 movff win_color5,PORTH | |
1201 bcf tft_nwr | |
1202 bsf tft_nwr ; Upper | |
1203 movff win_color4,PORTH | |
1204 bcf tft_nwr | |
1205 bsf tft_nwr ; High | |
1206 movff win_color3,PORTH | |
1207 bcf tft_nwr | |
1208 bsf tft_nwr ; Lower | |
1209 | |
1210 movff win_color5,PORTH | |
1211 bcf tft_nwr | |
1212 bsf tft_nwr ; Upper | |
1213 movff win_color4,PORTH | |
1214 bcf tft_nwr | |
1215 bsf tft_nwr ; High | |
1216 movff win_color3,PORTH | |
1217 bcf tft_nwr | |
1218 bsf tft_nwr ; Lower | |
1219 decfsz PRODL,F ; row loop finished ? | |
1220 bra TFT_box3_display2 ; No: continue. | |
1221 | |
1222 incf PRODH,F ; column count ++ | |
1223 | |
1224 movf win_bargraph,W ; current column == bargraph ? | |
1225 cpfseq PRODH | |
1226 bra TFT_box4_display2 ; No: just loop. | |
1227 | |
1228 ; Yes: switch to black | |
1229 clrf win_color5 | |
1230 clrf win_color4 | |
1231 clrf win_color3 | |
1232 TFT_box4_display2: | |
1233 movf win_width+0,W | |
1234 cpfseq PRODH | |
1235 bra TFT_box2_display2 | |
1236 | |
1237 ; Reset bargraph mode... | |
1238 setf win_bargraph | |
1239 return | |
1240 | |
0 | 1241 |
1242 ;============================================================================= | |
604 | 1243 ; Converts 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB' |
0 | 1244 |
582 | 1245 global TFT_set_color |
0 | 1246 TFT_set_color: |
604 | 1247 movwf tft_temp1 ; get 8 Bit RGB b'RRRGGGBB' |
1248 movwf tft_temp2 ; copy | |
0 | 1249 |
604 | 1250 ; mask bit 7,6,5,4,3,2 |
0 | 1251 movlw b'00000011' |
1252 andwf tft_temp2,F | |
1253 | |
1254 movlw b'00000000' | |
1255 dcfsnz tft_temp2,F | |
1256 movlw b'01010000' | |
1257 dcfsnz tft_temp2,F | |
1258 movlw b'10100000' | |
1259 dcfsnz tft_temp2,F | |
1260 movlw b'11111000' | |
604 | 1261 movwf tft_temp3 ; blue done |
0 | 1262 |
604 | 1263 movff tft_temp1,tft_temp2 ; copy |
1264 ; mask bit 7,6,5,1,0 | |
0 | 1265 movlw b'00011100' |
1266 andwf tft_temp2,F | |
1267 rrncf tft_temp2,F | |
1268 rrncf tft_temp2,F | |
1269 | |
1270 movlw b'00000000' | |
1271 dcfsnz tft_temp2,F | |
1272 movlw b'00000100' | |
1273 dcfsnz tft_temp2,F | |
1274 movlw b'00001000' | |
1275 dcfsnz tft_temp2,F | |
1276 movlw b'00001100' | |
1277 dcfsnz tft_temp2,F | |
1278 movlw b'00010000' | |
1279 dcfsnz tft_temp2,F | |
1280 movlw b'00010100' | |
1281 dcfsnz tft_temp2,F | |
1282 movlw b'00100000' | |
1283 dcfsnz tft_temp2,F | |
1284 movlw b'00111111' | |
582 | 1285 movwf tft_temp4 |
0 | 1286 |
1287 rrcf tft_temp4,F | |
1288 rrcf tft_temp3,F | |
1289 | |
1290 rrcf tft_temp4,F | |
1291 rrcf tft_temp3,F | |
1292 | |
1293 rrcf tft_temp4,F | |
604 | 1294 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done |
1295 movwf win_color2 ; set color registers... | |
0 | 1296 |
604 | 1297 movff tft_temp1,tft_temp2 ; copy |
0 | 1298 clrf tft_temp1 |
1299 | |
1300 rrcf tft_temp4,F | |
1301 rrcf tft_temp1,F | |
1302 | |
1303 rrcf tft_temp4,F | |
1304 rrcf tft_temp1,F | |
1305 | |
1306 rrcf tft_temp4,F | |
604 | 1307 rrcf tft_temp1,F ; green done |
0 | 1308 |
604 | 1309 ; mask bit 4,3,2,1,0 |
0 | 1310 movlw b'11100000' |
1311 andwf tft_temp2,F | |
1312 | |
1313 rrncf tft_temp2,F | |
1314 rrncf tft_temp2,F | |
1315 rrncf tft_temp2,F | |
1316 rrncf tft_temp2,F | |
1317 rrncf tft_temp2,F | |
1318 | |
1319 movlw b'00000000' | |
1320 dcfsnz tft_temp2,F | |
1321 movlw b'00000100' | |
1322 dcfsnz tft_temp2,F | |
1323 movlw b'00001000' | |
1324 dcfsnz tft_temp2,F | |
1325 movlw b'00001100' | |
1326 dcfsnz tft_temp2,F | |
1327 movlw b'00010000' | |
1328 dcfsnz tft_temp2,F | |
1329 movlw b'00010100' | |
1330 dcfsnz tft_temp2,F | |
1331 movlw b'00100000' | |
1332 dcfsnz tft_temp2,F | |
1333 movlw b'00111111' | |
582 | 1334 movwf tft_temp4 |
0 | 1335 |
1336 rrcf tft_temp4,F | |
1337 rrcf tft_temp1,F | |
1338 | |
1339 rrcf tft_temp4,F | |
604 | 1340 rrcf tft_temp1,F |
0 | 1341 |
1342 rrcf tft_temp4,F | |
1343 rrcf tft_temp1,F | |
1344 | |
1345 rrcf tft_temp4,F | |
1346 rrcf tft_temp1,F | |
1347 | |
1348 rrcf tft_temp4,F | |
604 | 1349 rrcf tft_temp1,W ; red done |
1350 movwf win_color1 ; set color registers | |
0 | 1351 return |
608 | 1352 |
1353 global convert_for_display2 | |
1354 convert_for_display2: ; Convert 16Bit RGB b'RRRRRGGG GGGBBBBB' into 24Bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00' | |
1355 ; PRODH PRODL win_color5 win_color4 win_color3 | |
1356 ; Red | |
1357 movff PRODH,win_color5 ; = RRRRRGGG | |
1358 bcf win_color5,2 ; = RRRRR0GG | |
1359 btfsc win_color5,7 | |
1360 bsf win_color5,2 ; = RRRRR1GG ; Lower two bits ignored from screen! | |
1361 ; Blue | |
1362 movff PRODL,win_color3 | |
1363 rrcf win_color3,F ; = UGGGBBBB (And the LSB-Blue in Carry) | |
1364 swapf win_color3,F ; = BBBBUGGG | |
1365 bcf win_color3,3 ; = BBBB0GGG | |
1366 btfsc STATUS,C | |
1367 bsf win_color3,3 ; = BBBB1GGG | |
1368 bcf win_color3,2 ; = BBBBB0GG | |
1369 btfsc win_color3,7 | |
1370 bsf win_color3,2 ; = BBBBB1GG | |
1371 ; Green | |
1372 rrcf PRODH,F | |
1373 rrcf PRODL,F | |
1374 rrcf PRODH,F | |
1375 rrcf PRODL,F | |
1376 rrcf PRODH,F | |
1377 rrcf PRODL,F ; = GGGGGGBB ; Lower two bits ignored from screen! | |
1378 movff PRODL,win_color4 | |
1379 return | |
1380 | |
0 | 1381 |
1382 ;============================================================================= | |
1383 ; Dump screen contents to the UART | |
1384 | |
604 | 1385 IFDEF _screendump |
1386 | |
1387 global TFT_dump_screen_check | |
582 | 1388 global TFT_dump_screen |
604 | 1389 TFT_dump_screen_check: |
1390 btfss vusb_in ; USB (still) plugged in? | |
1391 bcf enable_screen_dumps ; NO - clear flag | |
1392 call rs232_get_byte ; try to read data from RS232 | |
1393 btfsc rs232_receive_overflow ; anything received? | |
1394 return ; NO - return | |
1395 movlw "l" ; YES - load coding for screendump command | |
1396 cpfseq RCREG1 ; screendump command received? | |
1397 return ; NO - return | |
1398 TFT_dump_screen: ; YES | |
582 | 1399 bsf no_sensor_int |
1400 movlw 'l' | |
604 | 1401 movwf TXREG ; send command echo |
582 | 1402 call rs232_wait_tx ; wait for UART |
604 | 1403 |
582 | 1404 ;---- Send DISPLAY box command for the full screen window ------------------- |
604 | 1405 Index_out 0x50 ; window horizontal start address |
582 | 1406 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 1407 Index_out 0x51 ; window horizontal end address |
582 | 1408 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 1409 Index_out 0x52 ; window vertical start address |
582 | 1410 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 1411 Index_out 0x53 ; window vertical end address |
582 | 1412 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 1413 |
582 | 1414 clrf ds_column |
1415 rcall dump_screen_pixel_reset | |
0 | 1416 dump_screen_1: |
582 | 1417 btg LEDr ; LED activity toggle |
1418 ; Dump even column | |
604 | 1419 movlw .240 ; 240 lines, once |
582 | 1420 movwf ds_line |
0 | 1421 dump_screen_2: |
604 | 1422 Index_out 0x20 ; frame memory horizontal address |
582 | 1423 movff ds_line,WREG ; d'0' ... d'239' |
604 | 1424 mullw .1 ; copy row to PRODH:L |
582 | 1425 rcall TFT_DataWrite_PROD |
0 | 1426 |
604 | 1427 movff ds_column,WREG ; Init X position |
582 | 1428 mullw 2 |
604 | 1429 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1430 |
582 | 1431 rcall TFT_DataRead_PROD ; read pixel |
1432 rcall dump_screen_pixel | |
0 | 1433 |
582 | 1434 decfsz ds_line,F |
1435 bra dump_screen_2 | |
1436 rcall dump_screen_pixel_flush | |
0 | 1437 |
582 | 1438 ; Dump odd column |
604 | 1439 movlw .240 ; 240 lines, twice |
582 | 1440 movwf ds_line |
0 | 1441 dump_screen_3: |
604 | 1442 Index_out 0x20 ; frame memory horizontal address |
582 | 1443 movff ds_line,WREG ; d'0' ... d'239' |
604 | 1444 mullw 1 ; copy row to PRODH:L |
582 | 1445 rcall TFT_DataWrite_PROD |
0 | 1446 |
604 | 1447 movff ds_column,WREG ; init X position |
582 | 1448 mullw 2 |
1449 movlw .1 | |
1450 addwf PRODL,F | |
1451 movlw 0 | |
1452 addwfc PRODH,F ; +1 | |
604 | 1453 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1454 |
582 | 1455 rcall TFT_DataRead_PROD ; read pixel |
1456 rcall dump_screen_pixel | |
0 | 1457 |
582 | 1458 decfsz ds_line,F |
1459 bra dump_screen_3 | |
1460 rcall dump_screen_pixel_flush | |
0 | 1461 |
582 | 1462 incf ds_column,F |
1463 movlw .160 | |
1464 cpfseq ds_column | |
1465 bra dump_screen_1 | |
0 | 1466 |
582 | 1467 bcf no_sensor_int |
604 | 1468 clrf RCREG1 ; clear receive buffer |
1469 bcf RCSTA1,CREN ; clear receiver status | |
582 | 1470 bsf RCSTA1,CREN |
604 | 1471 bsf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (screen dump) |
582 | 1472 return |
0 | 1473 |
604 | 1474 ENDIF |
1475 | |
0 | 1476 |
1477 ;============================================================================= | |
1478 ; Pixel compression | |
1479 ; | |
604 | 1480 ; Input : PRODH:L = pixel |
0 | 1481 ; Output: Compressed stream on output. |
1482 ; Compressed format: | |
604 | 1483 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128) |
1484 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1.. 64) | |
1485 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1.. 64) | |
1486 | |
1487 IFDEF _screendump | |
582 | 1488 |
0 | 1489 dump_screen_pixel: |
604 | 1490 movf PRODH,W ; compare pixel-high |
582 | 1491 xorwf ds_pixel+1,W |
604 | 1492 bnz dump_screen_pixel_1 ; different -> dump |
0 | 1493 |
604 | 1494 movf PRODL,W ; compare pixel-low |
582 | 1495 xorwf ds_pixel+0,W |
604 | 1496 bnz dump_screen_pixel_1 ; different -> dump |
0 | 1497 |
604 | 1498 incf ds_count,F ; same color: just increment |
582 | 1499 return |
0 | 1500 |
604 | 1501 dump_screen_pixel_1: ; send (pixel,count) tuple |
1502 movf ds_count,W ; is count zero ? | |
1503 bz dump_screen_pixel_2 ; YES - skip sending | |
0 | 1504 |
604 | 1505 movf ds_pixel+1,W ; is this a BLACK pixel ? |
582 | 1506 iorwf ds_pixel+0,W |
604 | 1507 bz dump_screen_pix_black ; YES |
0 | 1508 |
604 | 1509 movf ds_pixel+1,W ; is this a white pixel ? |
582 | 1510 andwf ds_pixel+0,W |
1511 incf WREG | |
604 | 1512 bz dump_screen_pix_white ; YES |
0 | 1513 |
582 | 1514 ; No: write the pixel itself... |
604 | 1515 movlw .64 ; max color pixel on a single byte |
1516 cpfsgt ds_count ; skip if count > 64 | |
582 | 1517 movf ds_count,W ; W <- min(64,count) |
1518 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 1519 decf WREG ; save as 0..63 |
1520 iorlw b'10000000' ; mark as a color pixel | |
0 | 1521 |
582 | 1522 movwf TXREG |
1523 call rs232_wait_tx ; wait for UART | |
1524 movff ds_pixel+1,TXREG | |
1525 call rs232_wait_tx ; wait for UART | |
1526 movff ds_pixel+0,TXREG | |
1527 call rs232_wait_tx ; wait for UART | |
1528 bra dump_screen_pixel_1 | |
0 | 1529 |
1530 dump_screen_pixel_2: | |
604 | 1531 movff PRODH,ds_pixel+1 ; save new pixel color |
582 | 1532 movff PRODL,ds_pixel+0 |
1533 movlw 1 | |
604 | 1534 movwf ds_count ; and set count=1 |
582 | 1535 return |
0 | 1536 |
1537 dump_screen_pix_black: | |
604 | 1538 movlw .128 ; max black pixel on a single byte |
1539 cpfsgt ds_count ; skip if count > 128 | |
582 | 1540 movf ds_count,W ; W <- min(128,count) |
1541 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 1542 decf WREG ; save as 0..127 |
0 | 1543 dump_screen_pix_3: |
582 | 1544 movwf TXREG |
1545 call rs232_wait_tx | |
604 | 1546 bra dump_screen_pixel_1 ; more to dump ? |
0 | 1547 |
1548 dump_screen_pix_white: | |
604 | 1549 movlw .64 ; max white pixel on a single byte |
1550 cpfsgt ds_count ; skip if count > 64 | |
582 | 1551 movf ds_count,W ; W <- min(64,count) |
1552 subwf ds_count,F ; ds_count <- ds_count-W | |
1553 decf WREG ; Save as 0..63 | |
604 | 1554 iorlw b'11000000' ; mark as a compressed white |
582 | 1555 bra dump_screen_pix_3 |
0 | 1556 |
1557 dump_screen_pixel_flush: | |
582 | 1558 clrf PRODH |
1559 clrf PRODL | |
604 | 1560 rcall dump_screen_pixel_1 ; send it |
0 | 1561 dump_screen_pixel_reset: |
604 | 1562 clrf ds_count ; clear count |
582 | 1563 return |
0 | 1564 |
604 | 1565 ENDIF |
1566 | |
582 | 1567 END |