Mercurial > public > hwos_code
annotate src/tft.asm @ 489:22092d14fd8c
docu (battery info byte)
| author | heinrichsweikamp |
|---|---|
| date | Mon, 27 Mar 2017 16:06:09 +0200 |
| parents | 4927ba3bd3b5 |
| children | b455b31ce022 |
| rev | line source |
|---|---|
| 0 | 1 ;============================================================================= |
| 2 ; | |
| 3 ; File tft.asm | |
| 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 ; TFT_frame needs to backup coordinates. | |
| 21 CBLOCK tmp | |
| 22 save_top | |
| 23 save_height | |
| 24 save_left | |
| 25 save_width | |
| 26 ds_line ; Current line (0..239). | |
| 27 ds_column ; Current columnx2 (0..159) | |
| 28 ds_pixel:2 ; Current pixel color. | |
| 29 ds_count ; Repetition count. | |
| 30 ENDC | |
| 31 | |
| 32 ;============================================================================= | |
| 33 ; Basic bit-level macros | |
| 34 | |
| 35 RD_H macro | |
| 36 bsf tft_rd,0 | |
| 37 endm | |
| 38 | |
| 39 RD_L macro | |
| 40 bcf tft_rd,0 | |
| 41 endm | |
| 42 | |
| 43 RS_H macro | |
| 44 bsf tft_rs,0 | |
| 45 endm | |
| 46 | |
| 47 RS_L macro | |
| 48 bcf tft_rs,0 | |
| 49 endm | |
| 50 | |
| 51 NCS_H macro | |
| 52 bsf tft_cs,0 | |
| 53 endm | |
| 54 | |
| 55 NCS_L macro | |
| 56 bcf tft_cs,0 | |
| 57 endm | |
| 58 | |
| 59 WR_H macro | |
| 60 bsf tft_nwr,0 | |
| 61 endm | |
| 62 | |
| 63 WR_L macro | |
| 64 bcf tft_nwr,0 | |
| 65 endm | |
| 66 | |
| 67 ;============================================================================= | |
| 68 ; Byte-leve macros | |
| 69 ; | |
| 70 Index_out macro low_b | |
| 71 movlw low_b | |
| 72 rcall TFT_CmdWrite | |
| 73 endm | |
| 74 | |
| 75 Parameter_out macro high_b, low_b | |
| 76 movlw high_b | |
| 77 movwf PORTA ; Upper | |
| 78 movlw low_b | |
| 79 rcall TFT_DataWrite | |
| 80 endm | |
| 81 | |
| 82 | |
| 83 basic CODE | |
| 151 | 84 ; |
| 85 ; | |
| 86 ;;============================================================================= | |
| 87 ;; TFT_write_flash_image | |
| 88 ;; | |
| 89 ;; Inputs: FSR2 = EEPROM address / 256 | |
| 90 ;; win_left, win_top : imagte CENTER position | |
| 91 ;; Outputs: win_height, win_width. | |
| 92 ;; image copyed on screen. | |
| 93 ;; Trashed: PROD, hi, lo | |
| 94 ;; | |
| 95 ; global TFT_write_flash_image | |
| 96 ;TFT_write_flash_image: | |
| 97 ; ; Get back the full 24bit EEPROM address | |
| 98 ; clrf ext_flash_address+0 | |
| 99 ; movff FSR2L,ext_flash_address+1 | |
| 100 ; movf FSR2H,W | |
| 101 ; iorlw 0x30 | |
| 102 ; movwf ext_flash_address+2 | |
| 103 ; | |
| 104 ; ; Read header: width and height | |
| 105 ; global TFT_write_flash_image_addr | |
| 106 ;TFT_write_flash_image_addr: | |
| 107 ; call ext_flash_read_block_start | |
| 108 ; movff SSP2BUF,win_width+0 | |
| 109 ; movwf SSP2BUF ; Write to buffer to initiate new read | |
| 110 ; btfss SSP2STAT, BF ; Next byte ready ? | |
| 111 ; bra $-2 ; NO: wait... | |
| 112 ; movff SSP2BUF,win_width+1 | |
| 113 ; movwf SSP2BUF ; Write to buffer to initiate new read | |
| 114 ; btfss SSP2STAT, BF ; Next byte ready ? | |
| 115 ; bra $-2 ; NO: wait... | |
| 116 ; movff SSP2BUF,win_height | |
| 117 ; movwf SSP2BUF ; Write to buffer to initiate new read | |
| 118 ; btfss SSP2STAT, BF ; Next byte ready ? | |
| 119 ; bra $-2 ; NO: wait... | |
| 120 ; movff SSP2BUF,WREG ; drop 4th byte. | |
| 121 ; movwf SSP2BUF ; Write to buffer to initiate new read | |
| 122 ; btfss SSP2STAT, BF ; Next byte ready ? | |
| 123 ; bra $-2 ; NO: wait... | |
| 124 ; | |
| 125 ; ; Sanity check on header to avoid badly uploaded images. | |
| 126 ; iorwf WREG ; Check height < 256 | |
| 127 ; bnz TFT_write_flash_image_failed | |
| 128 ; movf win_width+1,W ; Check width < 512 | |
| 129 ; andlw 0xFE | |
| 130 ; bnz TFT_write_flash_image_failed | |
| 131 ; | |
| 132 ; ; Center image on win_top, win_left values | |
| 133 ; bcf STATUS,C ; Clear carry | |
| 134 ; rrcf win_height,W ; And get height/2 | |
| 135 ; subwf win_top,F ; top -= height/2 | |
| 136 ; rrcf win_width+1,W ; Get 9th bit into carry | |
| 137 ; rrcf win_width+0,W ; Get width/2 (in 0..320 range) | |
| 138 ; bcf STATUS,C | |
| 139 ; rrcf WREG,W ; Get width/2 in 0..160 range | |
| 140 ; subwf win_leftx2,F ; left -= width/2 | |
| 141 ; | |
| 142 ; rcall TFT_box_write ; Inputs : win_top, win_leftx2, win_height, win_width(in 1..320 range) | |
| 0 | 143 ; |
| 151 | 144 ; ; Compute number of pixels to move (result on 17 bits !) |
| 145 ; clrf TBLPTRU | |
| 146 ; movf win_width+0,W | |
| 147 ; mulwf win_height ; Result in PRODL:H | |
| 148 ; movf win_width+1,W | |
| 149 ; bz TFT_write_flash_image_1 ; width > 8bits ? | |
| 150 ; movf win_height,W ; YES: add extra | |
| 151 ; addwf PRODH,F | |
| 152 ; rlcf TBLPTRU ; And carry into upper register. | |
| 153 ;TFT_write_flash_image_1: | |
| 154 ; incf PRODH,F ; Pre-condition nested loops | |
| 155 ; incf TBLPTRU,F | |
| 156 ; | |
| 157 ; ; Write pixels | |
| 158 ; Index_out 0x22 ; Frame Memory Data Write start | |
| 159 ; RS_H ; Data | |
| 160 ; | |
| 161 ;TFT_write_flash_image_loop: | |
| 162 ; btfss SSP2STAT, BF ; Buffer full? | |
| 163 ; bra $-2 ; NO: wait... | |
| 164 ; movff SSP2BUF,PORTH ; Read lo | |
| 165 ; movwf SSP2BUF ; Write to buffer to initiate new read | |
| 166 ; | |
| 167 ; btfss SSP2STAT, BF ; Buffer full? | |
| 168 ; bra $-2 ; NO: wait... | |
| 169 ; movff SSP2BUF,PORTA ; And read hi | |
| 170 ; movwf SSP2BUF ; Write to buffer to initiate new read | |
| 171 ; WR_L | |
| 172 ; WR_H ; Write 1 Pixel | |
| 173 ; | |
| 174 ; decfsz PRODL,F | |
| 175 ; bra TFT_write_flash_image_loop | |
| 176 ; decfsz PRODH,F | |
| 177 ; bra TFT_write_flash_image_loop | |
| 178 ; decfsz TBLPTRU,F | |
| 179 ; bra TFT_write_flash_image_loop | |
| 180 ; | |
| 181 ; btfss SSP2STAT, BF ; Buffer full? | |
| 182 ; bra $-2 ; No, wait | |
| 183 ; movf SSP2BUF,W ; Read dummy byte | |
| 184 ; | |
| 185 ; bsf flash_ncs ; CS=1 | |
| 186 ; movlw 0x00 ; NOP, to stop window mode | |
| 187 ; bra TFT_CmdWrite ; This routine "returns" | |
| 188 ; | |
| 189 ; ;---- Draw a 4x4 red square in place of missing images... | |
| 190 ;TFT_write_flash_image_failed: | |
| 191 ; movlw -1 | |
| 192 ; addwf win_leftx2,F | |
| 193 ; movlw -2 | |
| 194 ; addwf win_top,F | |
| 195 ; movlw 2 | |
| 196 ; movwf win_width+0 | |
| 197 ; clrf win_width+1 | |
| 198 ; movlw 4 | |
| 199 ; movwf win_height | |
| 200 ; movlw color_red | |
| 201 ; rcall TFT_set_color | |
| 202 ; goto TFT_box | |
| 203 ; | |
| 204 ;;============================================================================= | |
| 0 | 205 ; |
| 206 | |
| 207 global TFT_CmdWrite | |
| 208 TFT_CmdWrite: | |
| 209 RS_L ; Command | |
| 210 clrf PORTA ; Upper | |
| 436 | 211 bcf INTCON,GIE |
| 0 | 212 movwf PORTH ; Lower |
| 213 WR_L | |
| 214 WR_H ; Tick | |
| 436 | 215 bsf INTCON,GIE |
| 0 | 216 return; |
| 217 | |
| 218 global TFT_DataWrite | |
| 219 TFT_DataWrite: | |
| 220 RS_H ; Data | |
| 436 | 221 bcf INTCON,GIE |
| 0 | 222 movwf PORTH ; Lower |
| 223 WR_L | |
| 224 WR_H ; Tick | |
| 436 | 225 bsf INTCON,GIE |
| 0 | 226 return |
| 227 | |
| 228 ;============================================================================= | |
| 229 ; | |
| 230 global TFT_ClearScreen | |
| 231 TFT_ClearScreen: | |
| 232 Index_out 0x50 ; Window Horizontal Start Address | |
| 233 Parameter_out 0x00, 0x00 ; 0-239 | |
| 234 Index_out 0x51 ; Window Horizontal End Address | |
| 235 Parameter_out 0x00, 0xEF ; 0-239 | |
| 236 Index_out 0x52 ; Window Vertical Start Address | |
| 237 Parameter_out 0x00, 0x00 ; 0-319 | |
| 238 Index_out 0x53 ; Window Vertical End Address | |
| 239 Parameter_out 0x01, 0x3F ; 0-319 | |
| 240 Index_out 0x20 ; Frame Memory Horizontal Address | |
| 241 Parameter_out 0x00, 0x00 ; 0-239 | |
| 242 Index_out 0x21 ; Frame Memory Vertical Address | |
| 243 Parameter_out 0x01, 0x3F ; 0-319 | |
| 244 | |
| 245 Index_out 0x22 ; Frame Memory Data Write start | |
| 246 | |
| 247 RD_H ; Not Read | |
| 248 RS_H ; Data | |
| 249 NCS_L ; Not CS | |
| 250 clrf PORTH ; Data Lower | |
| 251 | |
| 252 movlw d'10' | |
| 253 movwf tft_temp3 | |
| 254 TFT_ClearScreen2: | |
| 255 movlw d'30' | |
| 256 movwf tft_temp2 | |
| 257 TFT_ClearScreen3: | |
| 258 clrf tft_temp1 ; 30*10*256=76800 Pixels -> Clear complete 240*320 | |
| 436 | 259 bcf INTCON,GIE |
| 0 | 260 TFT_ClearScreen4: |
| 261 WR_L | |
| 262 WR_H ; Tick | |
| 263 decfsz tft_temp1,F | |
| 264 bra TFT_ClearScreen4 | |
| 436 | 265 bsf INTCON,GIE |
| 0 | 266 decfsz tft_temp2,F |
| 267 bra TFT_ClearScreen3 | |
| 268 decfsz tft_temp3,F | |
| 269 bra TFT_ClearScreen2 | |
| 436 | 270 |
| 271 movlw 0x00 ; NOP, to stop window mode | |
| 272 bra TFT_CmdWrite ; And return | |
| 273 ; return | |
| 0 | 274 |
| 275 ;============================================================================= | |
| 276 ; | |
| 277 global TFT_DisplayOff | |
| 278 TFT_DisplayOff: | |
| 279 clrf CCPR1L ; PWM OFF | |
| 280 clrf PORTA | |
| 281 clrf PORTH | |
| 282 RD_L ; LOW | |
| 283 nop | |
| 284 RS_L ; LOW | |
| 285 bcf tft_nwr | |
| 286 nop | |
| 287 bcf tft_cs | |
| 288 nop | |
| 289 bcf tft_nreset | |
| 290 WAITMS d'1' | |
| 291 bsf tft_power ; inverted... | |
| 292 bcf lightsen_power ; power-down light sensor | |
| 293 return | |
| 294 | |
| 295 ; ----------------------------- | |
| 296 ; TFT boot | |
| 297 ; ----------------------------- | |
| 298 global TFT_boot | |
| 299 TFT_boot: | |
| 300 clrf PORTA | |
| 301 clrf PORTH | |
| 302 RD_L ; LOW | |
| 303 bcf tft_nwr | |
| 304 nop | |
| 305 bcf tft_cs | |
| 306 nop | |
| 307 bcf tft_nreset | |
| 308 WAITMS d'1' | |
| 309 bcf tft_power ; inverted... | |
| 310 WAITMS d'1' | |
| 311 | |
| 312 RD_H ; Keep high | |
| 313 WR_H ; | |
| 314 NCS_L ; Not CS | |
| 315 | |
| 316 WAITMS d'2' | |
| 317 bsf tft_nreset | |
| 461 | 318 WAITMS d'5' |
| 319 bcf tft_nreset | |
| 320 WAITMS d'5' | |
| 321 bsf tft_nreset | |
| 0 | 322 WAITMS d'150' |
| 323 bsf lightsen_power ; Supply power to light sensor | |
| 324 | |
| 325 ; Data Transfer Synchronization | |
| 326 Parameter_out 0x00, 0x00 | |
| 327 Parameter_out 0x00, 0x00 | |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
328 |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
329 ; Get screentype from Bootloader-Info |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
330 movlw 0x7B |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
331 movwf TBLPTRL |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
332 movlw 0xF7 |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
333 movwf TBLPTRH |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
334 movlw 0x01 |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
335 movwf TBLPTRU |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
336 TBLRD*+ ; Reads .110 for cR and USB OSTC3, .0 for BLE (2 and 3), and .2 for display1 OSTC |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
337 movlw 0x02 |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
338 cpfseq TABLAT |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
339 bra TFT_boot_0 ; Display0 |
| 360 | 340 |
| 341 TFT_boot_1: | |
| 342 ; Init through config table... | |
| 363 | 343 movlw 0x74 |
| 360 | 344 movwf TBLPTRL |
| 363 | 345 movlw 0xF7 |
| 360 | 346 movwf TBLPTRH |
| 363 | 347 movlw 0x01 |
| 360 | 348 movwf TBLPTRU |
| 349 bsf screen_type | |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
350 bra TFT_boot_com |
| 360 | 351 |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
352 TFT_boot_0: |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
353 ; Init through config table... |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
354 movlw LOW display0_config_table |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
355 movwf TBLPTRL |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
356 movlw HIGH display0_config_table |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
357 movwf TBLPTRH |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
358 movlw UPPER display0_config_table |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
359 movwf TBLPTRU |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
360 bcf screen_type |
|
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
361 |
| 360 | 362 TFT_boot_com: |
| 0 | 363 rcall display0_init_loop |
| 364 | |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
365 Index_out 0x03 |
|
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
366 btfsc flip_screen ; 180° rotation ? |
|
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
367 bra TFT_boot2 ; Yes |
| 360 | 368 |
| 369 btfss screen_type ; display1? | |
| 370 bra TFT_boot1a ; no | |
| 371 Parameter_out 0x10, 0x00 ; display1 | |
| 372 bra TFT_boot3 | |
| 373 TFT_boot1a: | |
| 374 Parameter_out 0x50, 0x20 ; display0 | |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
375 bra TFT_boot3 |
|
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
376 TFT_boot2: |
| 360 | 377 btfss screen_type ; display1? |
| 378 bra TFT_boot2a ; no | |
| 379 Parameter_out 0x10, 0x30 ; display1 | |
| 380 bra TFT_boot3 | |
| 381 TFT_boot2a: | |
| 382 Parameter_out 0x50, 0x10 ; display0 | |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
383 TFT_boot3: |
| 0 | 384 Index_out 0x22 |
|
225
31088352ee32
BUGFIX: Show dives with >999mins divetime correctly
heinrichsweikamp
parents:
152
diff
changeset
|
385 rcall TFT_ClearScreen |
| 0 | 386 Index_out 0x07 |
| 312 | 387 Parameter_out 0x01, 0x33 |
| 0 | 388 return |
| 389 | |
| 390 display0_config_table: | |
| 391 ; Reg, Dat0, Dat1 or 0xFF,0x00,0x00 for end | |
| 392 db 0xA4,0x00,0x01,0xFF,.002,0x00 | |
| 393 db 0x09,0x00,0x01,0x92,0x04,0x00 | |
| 394 db 0x93,0x04,0x02,0x94,0x00,0x02 | |
| 395 db 0x07,0x00,0x00,0x10,0x04,0x30 | |
| 396 db 0x11,0x02,0x37,0x12,0x11,0x8D | |
| 397 db 0x13,0x11,0x00,0x01,0x01,0x00 | |
| 398 db 0x02,0x02,0x00,0x03,0x50,0x20 | |
| 399 db 0x0A,0x00,0x08,0x0D,0x00,0x00 | |
| 400 db 0x0E,0x00,0x30,0xFF,.151,0x00 | |
| 401 db 0x12,0x11,0xBD,0x20,0x00,0x00 | |
| 402 db 0x21,0x00,0x00,0x30,0x06,0x02 | |
| 403 db 0x31,0x56,0x0D,0x32,0x05,0x07 | |
| 404 db 0x33,0x06,0x09,0x34,0x00,0x00 | |
| 405 db 0x35,0x09,0x06,0x36,0x57,0x05 | |
| 406 db 0x37,0x0D,0x06,0x38,0x02,0x06 | |
| 407 db 0x39,0x00,0x00,0xFF,0x00,0x00 | |
| 408 | |
| 409 display0_init_loop: | |
| 410 TBLRD*+ | |
| 411 movlw 0xFF | |
| 412 cpfseq TABLAT | |
| 413 bra display0_config_write ; Write Config pair to Display | |
| 414 ; Delay ms or quit (return) | |
| 415 TBLRD*+ | |
| 416 tstfsz TABLAT ; End of config? | |
| 417 bra $+4 ; No | |
| 418 return ; Done. | |
| 419 movf TABLAT,W | |
| 420 call WAITMSX ; Wait WREG milliseconds | |
| 421 TBLRD*+ ; Dummy read (Third byte of delay command) | |
| 422 bra display0_init_loop ; Loop | |
| 423 | |
| 424 display0_config_write: ; With command in WREG | |
| 425 movf TABLAT,W | |
| 426 rcall TFT_CmdWrite ; Write command | |
| 427 TBLRD*+ ; Get config0 | |
| 428 movff TABLAT,PORTA | |
| 429 TBLRD*+ ; Get config1 | |
| 430 movf TABLAT,W | |
| 431 rcall TFT_DataWrite ; Write config | |
| 432 bra display0_init_loop ; Loop | |
| 433 | |
| 434 | |
| 435 ;============================================================================= | |
| 436 ; Smooth lighting-up of the display: | |
| 437 ; | |
| 438 ; Trashes: WREG, PRODL | |
| 439 ; Typical usage: | |
| 440 ; clrf CCPR1L ; Backlight off | |
| 441 ; [draw splash screen] | |
| 442 ; call TFT_DisplayFadeIn | |
| 443 ; | |
| 444 global TFT_Display_FadeIn | |
| 445 TFT_Display_FadeIn: | |
| 275 | 446 movlw CCP1CON_VALUE ; See hwos.inc |
| 0 | 447 movwf CCP1CON |
| 448 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor! | |
| 449 clrf CCPR1L ; Backlight off - to be sure | |
| 450 movff max_CCPR1L,PRODL | |
| 451 TFT_Display_FadeIn_0: | |
| 452 incf CCPR1L,F ; Duty cycle | |
| 453 WAITMS d'2' | |
| 454 decfsz PRODL,F | |
| 455 bra TFT_Display_FadeIn_0 | |
| 456 bcf tft_is_dimming ; dimming done. | |
| 457 return | |
| 458 | |
| 459 ;============================================================================= | |
| 460 ; Smooth lighting-off of the display: | |
| 461 ; Trashes: WREG, PRODL | |
| 462 global TFT_Display_FadeOut | |
| 463 TFT_Display_FadeOut: | |
| 464 movff max_CCPR1L,PRODL | |
| 465 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor! | |
| 466 TFT_Display_FadeOut_0: | |
| 467 movff PRODL,CCPR1L ; Duty cycle | |
| 468 WAITMS d'1' | |
| 469 decfsz PRODL,F | |
| 470 bra TFT_Display_FadeOut_0 | |
| 471 clrf CCPR1L | |
| 472 return | |
| 473 | |
| 474 ;============================================================================= | |
| 475 | |
| 476 global box_std_block, box_black_block, box_color_block | |
| 477 | |
| 478 box_std_block: ; Use white color | |
| 479 setf WREG | |
| 480 bra box_common | |
| 481 box_black_block: ; Use black color | |
| 482 clrf WREG | |
| 483 box_common: | |
| 484 box_color_block: | |
| 485 rcall TFT_set_color | |
| 486 VARARGS_BEGIN | |
| 487 VARARGS_GET8 win_top | |
| 488 VARARGS_GET8 win_height | |
| 489 VARARGS_GET8 win_leftx2 | |
| 490 VARARGS_GET8 win_width | |
| 491 VARARGS_END | |
| 492 bra TFT_box | |
| 493 | |
| 494 ;----------------------------------------------------------------------------- | |
| 495 | |
| 496 global box_frame_std, box_frame_common, box_frame_color, box_frame_color16 | |
| 497 | |
| 498 box_frame_std: | |
| 499 setf WREG | |
| 500 rcall TFT_set_color | |
| 501 | |
| 502 box_frame_common: | |
| 503 VARARGS_BEGIN | |
| 504 VARARGS_GET8 win_top | |
| 505 VARARGS_GET8 win_height | |
| 506 VARARGS_GET8 win_leftx2 | |
| 507 VARARGS_GET8 win_width | |
| 508 VARARGS_END | |
| 509 bra TFT_frame | |
| 510 | |
| 511 box_frame_color: | |
| 512 rcall TFT_set_color | |
| 513 box_frame_color16: | |
| 514 bra box_frame_common | |
| 515 | |
| 434 | 516 ;;============================================================================= |
| 517 ;; Init for half_pixel_write | |
| 518 ;; Set column register on TFT device, and current color. | |
| 519 ;; Inputs: win_leftx2 | |
| 520 ;; Outputs: win_color:2 | |
| 521 ;; Trashed: WREG, PROD | |
| 522 ; global init_pixel_write | |
| 523 ;init_pixel_write: | |
| 524 ; movf win_leftx2,W | |
| 525 ; mullw 2 | |
| 526 ; rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
| 527 ; setf WREG | |
| 528 ; bra TFT_set_color | |
| 0 | 529 |
| 530 ;----------------------------------------------------------------------------- | |
| 531 ; Writes two half-pixels at position (win_top,win_leftx2) | |
| 532 ; Inputs: win_leftx2, win_top, win_color:2 | |
| 533 ; Trashed: WREG, PROD | |
| 534 global pixel_write | |
| 535 pixel_write: | |
| 432 | 536 movf win_leftx2,W |
| 0 | 537 mullw 2 ; win_leftx2 x 2 -> PRODH:PRODL |
| 538 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
| 539 rcall half_pixel_write ; Write this half-one. | |
| 540 | |
| 432 | 541 movf win_leftx2,W ; Address of next one |
| 0 | 542 mullw 2 |
| 543 infsnz PRODL ; +1 | |
| 544 incf PRODH | |
| 545 rcall pixel_write_col320 | |
| 546 bra half_pixel_write ; Note: Cmd 0x20 is mandatory, because | |
| 547 ; of the autoincrement going vertical | |
| 548 | |
| 549 global pixel_write_col320 | |
| 550 pixel_write_col320: | |
| 371 | 551 btfsc screen_type ; display1? |
| 552 bra pixel_write_col320_d1 ; Yes | |
| 553 ; Display0 | |
| 554 btfss flip_screen ; 180° rotation? | |
| 555 bra pixel_write_noflip_H ; No | |
| 556 bra pixel_write_flip_H ; Yes | |
| 557 pixel_write_col320_d1: ; Display1 | |
| 558 btfsc flip_screen ; 180° rotation? | |
| 559 bra pixel_write_noflip_H ; Yes for d1 | |
| 560 pixel_write_flip_H: ; Flip d0 | |
| 151 | 561 movf PRODL,W ; 16bits 319 - PROD --> PROD |
| 562 sublw LOW(.319) ; 319-W --> W | |
| 563 movwf PRODL | |
| 564 movf PRODH,W | |
| 565 btfss STATUS,C ; Borrow = /CARRY | |
| 566 incf WREG | |
| 567 sublw HIGH(.319) | |
| 568 movwf PRODH | |
| 569 | |
| 570 pixel_write_noflip_H: | |
| 0 | 571 Index_out 0x21 ; Frame Memory Vertical Address |
| 371 | 572 bra TFT_DataWrite_PROD ; and return... |
| 0 | 573 |
| 574 ;----------------------------------------------------------------------------- | |
| 575 ; Writes one half-pixel at position (win_top,win_leftx2). | |
| 576 ; Inputs: win_leftx2, win_top, win_color:2 | |
| 577 ; Trashed: WREG, PROD | |
| 578 global half_pixel_write | |
| 579 half_pixel_write: | |
| 432 | 580 movf win_top,W ; d'0' ... d'239' |
| 0 | 581 ; Variant with Y position in WREG. |
| 582 half_pixel_write_1: | |
| 151 | 583 btfss flip_screen ; 180° rotation? |
| 584 sublw .239 ; 239-Y --> Y | |
| 371 | 585 mullw 1 ; Copy row to PRODL (PRODH=0) |
| 586 Index_out 0x20 ; Frame Memory Horizontal Address | |
| 0 | 587 rcall TFT_DataWrite_PROD |
| 588 | |
| 371 | 589 Index_out 0x22 ; Frame Memory Data Write start |
| 0 | 590 RS_H ; Data |
| 436 | 591 bcf INTCON,GIE |
| 0 | 592 movff win_color1,PORTA ; Upper |
| 593 movff win_color2,PORTH ; Lower | |
| 594 WR_L | |
| 595 WR_H ; Tick | |
| 436 | 596 bsf INTCON,GIE |
| 0 | 597 return |
| 598 | |
| 599 ;----------------------------------------------------------------------------- | |
| 600 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height). | |
| 601 ; Inputs: win_leftx2, win_top, win_height, win_color:2 | |
| 602 ; Trashed: WREG, PROD, TABLAT, TBLPTRL | |
| 603 global half_vertical_line | |
| 604 half_vertical_line: | |
| 605 clrf TABLAT ; Loop index. | |
| 606 | |
| 607 half_vertical_line_loop: | |
| 432 | 608 movf win_leftx2,W ; Init X position. |
| 0 | 609 mullw 2 |
| 610 movf TABLAT,W ; Get loop index | |
| 611 andlw 1 ; Just low bit | |
| 612 xorwf PRODL,F ; And use it to jitter current X position | |
| 613 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
| 614 | |
| 432 | 615 movf win_height,W ; Index reached height (Bank0 read) ? |
| 0 | 616 xorwf TABLAT,W |
| 617 btfsc STATUS,Z ; Equals ? | |
| 618 return ; Yes: done. | |
| 432 | 619 movf win_top,W ; Y = top + index (Bank0 read) |
| 0 | 620 addwf TABLAT,W |
| 621 rcall half_pixel_write_1 | |
| 622 incf TABLAT,F ; index++ | |
| 623 bra half_vertical_line_loop | |
| 624 | |
| 625 ;----------------------------------------------------------------------------- | |
| 626 ; Writes a horizontal line of half-pixel at position (win_top,win_leftx2,win_width). | |
| 627 ; Inputs: win_leftx2, win_top, win_width, win_color:2 | |
| 628 ; Trashed: WREG, PROD, TABLAT, TBLPTRL | |
| 629 global half_horizontal_line | |
| 630 half_horizontal_line: | |
| 631 clrf TABLAT ; Loop index. | |
| 632 | |
| 633 half_horizontal_line_loop: | |
| 432 | 634 movf win_leftx2,W ; Init X position. |
| 0 | 635 mullw 2 |
| 636 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
| 432 | 637 movf win_width,W ; Index reached height (Bank0 read) ? |
| 0 | 638 xorwf TABLAT,W |
| 639 btfsc STATUS,Z ; Equals ? | |
| 640 return ; Yes: done. | |
| 432 | 641 movf win_top,W ; Y = top + index (Bank0 read) |
| 0 | 642 addwf TABLAT,W |
| 643 rcall half_pixel_write_1 | |
| 644 incf TABLAT,F ; index++ | |
| 645 bra half_horizontal_line_loop | |
| 646 | |
| 647 | |
| 648 ;----------------------------------------------------------------------------- | |
| 649 ; TFT Data Cmd via W | |
| 650 ; | |
| 651 global TFT_DataWrite_PROD | |
| 652 TFT_DataWrite_PROD: | |
| 653 ; RD_H ; Keep high | |
| 654 RS_H ; Data | |
| 436 | 655 bcf INTCON,GIE |
| 0 | 656 movff PRODH,PORTA ; Move high byte to PORTA |
| 432 | 657 movff PRODL,PORTH ; Move low byte to PORTH |
| 0 | 658 WR_L |
| 659 WR_H ; Tick | |
| 436 | 660 bsf INTCON,GIE |
| 0 | 661 return |
| 662 | |
| 663 TFT_DataRead_PROD: | |
| 664 Index_out 0x22 ; Frame Memory Data Read start | |
| 360 | 665 TFT_CmdRead_PROD: |
| 0 | 666 setf TRISA ; PortA as input. |
| 667 setf TRISH ; PortH as input. | |
| 668 RS_H ; Data | |
|
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
669 WR_H ; Not write |
| 0 | 670 RD_L ; Read! |
| 671 nop | |
| 672 nop | |
| 673 nop | |
| 674 RD_H ; Tick | |
| 675 nop | |
| 366 | 676 nop |
| 677 nop | |
| 0 | 678 RD_L ; Read! |
| 679 nop | |
| 366 | 680 ; nop |
| 681 ; nop | |
| 0 | 682 movff PORTA,PRODH |
| 683 movff PORTH,PRODL | |
| 684 RD_H ; Tick | |
| 685 nop | |
| 686 clrf TRISA ; PortA as output | |
| 687 clrf TRISH ; PortH as output | |
| 688 return | |
| 689 | |
| 690 ;============================================================================= | |
| 691 ; Output TFT Window Address commands. | |
| 692 ; Inputs : win_top, win_leftx2, win_height, win_width. | |
| 693 ; Output : PortA/PortH commands. | |
| 694 ; Trashed: PROD | |
| 695 ; | |
| 696 global TFT_box_write | |
| 697 TFT_box_write: | |
| 432 | 698 movf win_leftx2,W ; Compute left = 2*leftx2 --> PROD |
| 699 mullw 2 | |
| 0 | 700 |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
701 global TFT_box_write_16bit_win_left |
|
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
702 TFT_box_write_16bit_win_left: ; With column in PRODL:PRODH |
| 361 | 703 btfsc screen_type ; display1? |
| 704 bra TFT_box_write_16bit_win_left_d1 ; Yes | |
| 705 ; Display0 | |
| 706 btfsc flip_screen ; 180° rotation? | |
| 151 | 707 bra DISP_box_flip_H ; Yes |
| 361 | 708 bra TFT_box_write_16bit_win_left_com ; No |
| 709 TFT_box_write_16bit_win_left_d1: ; Display1 | |
| 710 btfss flip_screen ; 180° rotation? | |
| 370 | 711 bra DISP_box_flip_H ; No for d1 |
| 712 ; Yes for d1 | |
| 361 | 713 TFT_box_write_16bit_win_left_com: |
| 0 | 714 ;---- Normal horizontal window --------------------------------------- |
| 432 | 715 Index_out 0x52 ; Window Vertical Start Address |
| 716 rcall TFT_DataWrite_PROD ; Output left | |
| 717 Index_out 0x21 ; Frame Memory Vertical Address | |
| 718 rcall TFT_DataWrite_PROD ; Output left | |
| 0 | 719 |
| 432 | 720 movf win_width+0,W ; right = left + width - 1 |
| 721 addwf PRODL,F | |
| 722 movf win_width+1,W | |
| 723 addwfc PRODH,F | |
| 724 decf PRODL,F ; decrement result | |
| 725 btfss STATUS,C | |
| 726 decf PRODH,F | |
| 0 | 727 |
| 432 | 728 Index_out 0x53 ; Window Vertical End Address |
| 729 rcall TFT_DataWrite_PROD | |
| 730 bra DISP_box_noflip_H | |
| 0 | 731 |
| 151 | 732 ;---- Flipped horizontal window -------------------------------------- |
| 733 DISP_box_flip_H: | |
| 734 movf PRODL,W ; 16bits 319 - PROD --> PROD | |
| 735 sublw LOW(.319) ; 319-W --> W | |
| 736 movwf PRODL | |
| 737 movf PRODH,W | |
| 738 btfss STATUS,C ; Borrow = /CARRY | |
| 739 incf WREG | |
| 740 sublw HIGH(.319) | |
| 741 movwf PRODH | |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
742 |
| 432 | 743 Index_out 0x53 ; Window Vertical Start Address |
| 744 rcall TFT_DataWrite_PROD ; Output left | |
| 745 Index_out 0x21 ; Frame Memory Vertical Address | |
| 746 rcall TFT_DataWrite_PROD ; Output left | |
| 151 | 747 |
| 432 | 748 movf win_width+0,W ; 16bits PROD - width --> PROD |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
749 subwf PRODL,F ; PRODL - WREG --> PRODL |
| 432 | 750 movf win_width+1,W |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
751 subwfb PRODH,F |
|
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
752 infsnz PRODL ; PROD+1 --> PROD |
|
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
753 incf PRODH |
| 151 | 754 |
| 432 | 755 Index_out 0x52 ; Window Vertical End Address |
| 756 rcall TFT_DataWrite_PROD | |
| 151 | 757 |
| 758 DISP_box_noflip_H: | |
| 759 btfss flip_screen ; 180° rotation ? | |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
760 bra TFT_box_noflip_V ; No. |
| 151 | 761 |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
762 ;---- Flipped vertical window ----------------------------------------- |
| 432 | 763 movff win_top,PRODH ; top --> PRODH (first byte) |
| 764 movf win_height,W | |
| 765 addwf PRODH,W | |
| 766 decf WREG | |
| 767 movwf PRODL ; top+height-1 --> PRODL (second byte) | |
| 151 | 768 |
| 432 | 769 Index_out 0x50 ; Window Horizontal Start Address |
| 770 movf PRODH,W | |
| 771 rcall TFT_DataWrite ; Lower (and tick) | |
| 151 | 772 |
| 432 | 773 Index_out 0x51 ; Window Horizontal End Address |
| 774 movf PRODL,W | |
| 775 rcall TFT_DataWrite ; Lower (and tick) | |
| 151 | 776 |
| 432 | 777 Index_out 0x20 ; Frame Memory Horizontal Address |
| 778 movf PRODH,W | |
| 779 bra TFT_DataWrite ; Lower (and tick) and return | |
| 780 ; return | |
| 151 | 781 |
| 782 | |
|
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
783 TFT_box_noflip_V: |
|
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
784 ;---- Normal vertical window ---------------------------------------- |
| 432 | 785 movff win_top,PRODL |
| 786 movf win_height,W | |
| 787 addwf PRODL,W | |
| 788 sublw .240 ; 240 - top - height | |
| 789 movwf PRODH ; First byte | |
| 0 | 790 |
| 432 | 791 movf PRODL,W |
| 792 sublw .239 ; 239-top | |
| 793 movwf PRODL ; --> second byte. | |
| 0 | 794 |
| 432 | 795 Index_out 0x50 ; Window Horizontal Start Address |
| 796 movf PRODH,W | |
| 797 rcall TFT_DataWrite ; Lower (and tick) | |
| 0 | 798 |
| 432 | 799 Index_out 0x51 ; Window Horizontal End Address |
| 800 movf PRODL,W | |
| 801 rcall TFT_DataWrite ; Lower (and tick) | |
| 0 | 802 |
| 432 | 803 Index_out 0x20 ; Frame Memory Horizontal Address |
| 804 movf PRODL,W | |
| 805 bra TFT_DataWrite ; Lower (and tick) and return | |
| 806 ; return | |
| 0 | 807 |
| 808 ;============================================================================= | |
| 809 ; TFT_frame : draw a frame around current box with current color. | |
| 810 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 | |
| 811 ; Outputs: (none) | |
| 812 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 | |
| 813 global TFT_frame | |
| 814 TFT_frame: | |
| 815 movff win_top,save_top ; Backup everything. | |
| 816 movff win_height,save_height | |
| 817 movff win_leftx2,save_left | |
| 818 movff win_width,save_width | |
| 819 | |
| 820 ;---- TOP line ----------------------------------------------------------- | |
| 821 movlw 1 ; row ~ height=1 | |
| 432 | 822 movwf win_height |
| 0 | 823 rcall TFT_box |
| 824 | |
| 825 ;---- BOTTOM line -------------------------------------------------------- | |
| 826 movff save_top,PRODL ; Get back top, | |
| 827 movff save_height,WREG ; and height | |
| 828 addwf PRODL,W ; top+height | |
| 829 decf WREG ; top+height-1 | |
| 432 | 830 movwf win_top ; top+height-1 --> top |
| 0 | 831 rcall TFT_box |
| 832 | |
| 833 ;---- LEFT column -------------------------------------------------------- | |
| 834 movff save_top,win_top ; Restore top/height. | |
| 835 movff save_height,win_height | |
| 836 movlw 1 ; column ~ width=1 | |
| 432 | 837 movwf win_width+0 |
| 0 | 838 rcall TFT_box |
| 839 | |
| 840 ;---- RIGHT column ------------------------------------------------------- | |
| 841 movff save_left,WREG | |
| 842 movff save_width,PRODL | |
| 843 addwf PRODL,W | |
| 844 decf WREG | |
| 432 | 845 movwf win_leftx2 |
| 846 rcall TFT_box | |
| 0 | 847 |
| 848 ;---- Restore everything ------------------------------------------------- | |
| 849 movff save_left,win_leftx2 | |
| 850 movff save_width,win_width | |
| 851 return | |
| 852 | |
| 853 ;============================================================================= | |
| 854 ; TFT_box : fills current box with current color. | |
| 855 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 | |
| 856 ; Outputs: (none) | |
| 857 ; Trashed: WREG, PROD | |
| 858 global TFT_box | |
| 859 | |
| 860 TFT_box: | |
| 861 ;---- Define Window ------------------------------------------------------ | |
| 432 | 862 bcf STATUS,C |
| 863 rlcf win_width+0,F | |
| 864 rlcf win_width+1,F ; x2 | |
| 865 rcall TFT_box_write ; Setup box | |
| 0 | 866 |
| 83 | 867 global TFT_box_16bit_win_left |
| 868 TFT_box_16bit_win_left: | |
| 431 | 869 bcf STATUS,C |
| 870 rrcf win_width+1,F ; width /= 2 | |
| 871 rrcf win_width+0,F | |
| 0 | 872 |
| 873 ;---- Fill Window -------------------------------------------------------- | |
| 432 | 874 Index_out 0x22 ; Frame Memory Data Write start |
| 0 | 875 |
| 432 | 876 clrf PRODH ; Column counter. |
| 877 RS_H ; Data | |
| 0 | 878 |
| 879 TFT_box2: ; Loop height times | |
| 880 movff win_height,PRODL | |
| 881 | |
| 882 TFT_box3: ; loop width times | |
| 436 | 883 bcf INTCON,GIE |
| 0 | 884 movff win_color1,PORTA ; Upper |
| 885 movff win_color2,PORTH ; Lower | |
| 886 WR_L | |
| 887 WR_H ; Tick | |
| 370 | 888 ; |
| 889 ; movff win_color1,PORTA ; Upper | |
| 890 ; movff win_color2,PORTH ; Lower | |
| 0 | 891 WR_L |
| 892 WR_H ; Tick | |
| 436 | 893 bsf INTCON,GIE |
| 0 | 894 decfsz PRODL,F ; row loop finished ? |
| 432 | 895 bra TFT_box3 ; No: continue. |
| 0 | 896 |
| 897 incf PRODH,F ; column count ++ | |
| 898 | |
| 432 | 899 movf win_bargraph,W ; current column == bargraph ? |
| 0 | 900 cpfseq PRODH |
| 901 bra TFT_box4 ; No: just loop. | |
| 432 | 902 ; Yes: switch to black |
| 903 clrf win_color1 | |
| 904 clrf win_color2 | |
| 0 | 905 TFT_box4: |
| 432 | 906 movf win_width+0,W ; compare ? |
| 0 | 907 xorwf PRODH,W |
| 908 bnz TFT_box2 ; Loop not finished. | |
| 909 | |
| 432 | 910 movlw 0x00 ; NOP, to stop window mode |
| 911 rcall TFT_CmdWrite | |
| 0 | 912 |
| 432 | 913 ; Reset bargraph mode... |
| 914 setf win_bargraph | |
| 915 return | |
| 0 | 916 |
| 917 ;============================================================================= | |
| 918 ;Converts 8Bit RGB b'RRRGGGBB' into 16Bit RGB b'RRRRRGGGGGGBBBBB' | |
| 919 global TFT_set_color | |
| 920 | |
| 921 TFT_set_color: | |
| 922 movwf tft_temp1 ; Get 8Bit RGB b'RRRGGGBB' | |
| 923 movwf tft_temp2 ; Copy | |
| 924 | |
| 925 ; Mask Bit 7,6,5,4,3,2 | |
| 926 movlw b'00000011' | |
| 927 andwf tft_temp2,F | |
| 928 | |
| 929 movlw b'00000000' | |
| 930 dcfsnz tft_temp2,F | |
| 931 movlw b'01010000' | |
| 932 dcfsnz tft_temp2,F | |
| 933 movlw b'10100000' | |
| 934 dcfsnz tft_temp2,F | |
| 935 movlw b'11111000' | |
| 936 movwf tft_temp3 ; Blue done. | |
| 937 | |
| 938 movff tft_temp1, tft_temp2 ; Copy | |
| 939 ; Mask Bit 7,6,5,1,0 | |
| 940 movlw b'00011100' | |
| 941 andwf tft_temp2,F | |
| 942 rrncf tft_temp2,F | |
| 943 rrncf tft_temp2,F | |
| 944 | |
| 945 movlw b'00000000' | |
| 946 dcfsnz tft_temp2,F | |
| 947 movlw b'00000100' | |
| 948 dcfsnz tft_temp2,F | |
| 949 movlw b'00001000' | |
| 950 dcfsnz tft_temp2,F | |
| 951 movlw b'00001100' | |
| 952 dcfsnz tft_temp2,F | |
| 953 movlw b'00010000' | |
| 954 dcfsnz tft_temp2,F | |
| 955 movlw b'00010100' | |
| 956 dcfsnz tft_temp2,F | |
| 957 movlw b'00100000' | |
| 958 dcfsnz tft_temp2,F | |
| 959 movlw b'00111111' | |
| 960 movwf tft_temp4 | |
| 961 | |
| 962 rrcf tft_temp4,F | |
| 963 rrcf tft_temp3,F | |
| 964 | |
| 965 rrcf tft_temp4,F | |
| 966 rrcf tft_temp3,F | |
| 967 | |
| 968 rrcf tft_temp4,F | |
| 432 | 969 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done. |
| 970 movwf win_color2 ; Set Color registers... | |
| 0 | 971 |
| 972 movff tft_temp1, tft_temp2 ; Copy | |
| 973 clrf tft_temp1 | |
| 974 | |
| 975 rrcf tft_temp4,F | |
| 976 rrcf tft_temp1,F | |
| 977 | |
| 978 rrcf tft_temp4,F | |
| 979 rrcf tft_temp1,F | |
| 980 | |
| 981 rrcf tft_temp4,F | |
| 982 rrcf tft_temp1,F ; Green done. | |
| 983 | |
| 984 ; Mask Bit 4,3,2,1,0 | |
| 985 movlw b'11100000' | |
| 986 andwf tft_temp2,F | |
| 987 | |
| 988 rrncf tft_temp2,F | |
| 989 rrncf tft_temp2,F | |
| 990 rrncf tft_temp2,F | |
| 991 rrncf tft_temp2,F | |
| 992 rrncf tft_temp2,F | |
| 993 | |
| 994 movlw b'00000000' | |
| 995 dcfsnz tft_temp2,F | |
| 996 movlw b'00000100' | |
| 997 dcfsnz tft_temp2,F | |
| 998 movlw b'00001000' | |
| 999 dcfsnz tft_temp2,F | |
| 1000 movlw b'00001100' | |
| 1001 dcfsnz tft_temp2,F | |
| 1002 movlw b'00010000' | |
| 1003 dcfsnz tft_temp2,F | |
| 1004 movlw b'00010100' | |
| 1005 dcfsnz tft_temp2,F | |
| 1006 movlw b'00100000' | |
| 1007 dcfsnz tft_temp2,F | |
| 1008 movlw b'00111111' | |
| 1009 movwf tft_temp4 | |
| 1010 | |
| 1011 rrcf tft_temp4,F | |
| 1012 rrcf tft_temp1,F | |
| 1013 | |
| 1014 rrcf tft_temp4,F | |
| 1015 rrcf tft_temp1,F | |
| 1016 | |
| 1017 rrcf tft_temp4,F | |
| 1018 rrcf tft_temp1,F | |
| 1019 | |
| 1020 rrcf tft_temp4,F | |
| 1021 rrcf tft_temp1,F | |
| 1022 | |
| 1023 rrcf tft_temp4,F | |
| 432 | 1024 rrcf tft_temp1,W ; Red done. |
| 1025 movwf win_color1 ; Set Color registers... | |
| 0 | 1026 return |
| 1027 | |
| 1028 ;============================================================================= | |
| 1029 ; Dump screen contents to the UART | |
| 1030 | |
| 1031 global TFT_dump_screen | |
| 1032 TFT_dump_screen: | |
| 1033 bsf no_sensor_int | |
| 1034 movlw 'l' | |
| 1035 movwf TXREG ; Send command echo. | |
| 1036 call rs232_wait_tx ; wait for UART | |
| 1037 ;---- Send DISPLAY box command for the full screen window ------------------- | |
| 1038 Index_out 0x50 ; Window Horizontal Start Address | |
| 1039 Parameter_out 0x00, 0x00 ; 0-239 | |
| 1040 Index_out 0x51 ; Window Horizontal End Address | |
| 1041 Parameter_out 0x00, 0xEF ; 0-239 | |
| 1042 Index_out 0x52 ; Window Vertical Start Address | |
| 1043 Parameter_out 0x00, 0x00 ; 0-319 | |
| 1044 Index_out 0x53 ; Window Vertical End Address | |
| 1045 Parameter_out 0x01, 0x3F ; 0-319 | |
| 1046 | |
| 1047 clrf ds_column | |
| 1048 rcall dump_screen_pixel_reset | |
| 1049 dump_screen_1: | |
| 1050 btg LEDr ; LED activity toggle | |
| 1051 ; Dump even column | |
| 1052 movlw .240 ; 240 lines, once. | |
| 1053 movwf ds_line | |
| 1054 dump_screen_2: | |
| 1055 Index_out 0x20 ; Frame Memory Horizontal Address | |
| 1056 movff ds_line,WREG ; d'0' ... d'239' | |
| 1057 mullw 1 ; Copy row to PRODH:L | |
| 1058 rcall TFT_DataWrite_PROD | |
| 1059 | |
| 1060 movff ds_column,WREG ; Init X position. | |
| 1061 mullw 2 | |
| 1062 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
| 1063 | |
| 1064 rcall TFT_DataRead_PROD ; read pixel | |
| 1065 rcall dump_screen_pixel | |
| 1066 | |
| 1067 decfsz ds_line,F | |
| 1068 bra dump_screen_2 | |
| 1069 rcall dump_screen_pixel_flush | |
| 1070 | |
| 1071 ; Dump odd column | |
| 1072 movlw .240 ; 240 lines, twice. | |
| 1073 movwf ds_line | |
| 1074 dump_screen_3: | |
| 1075 Index_out 0x20 ; Frame Memory Horizontal Address | |
| 1076 movff ds_line,WREG ; d'0' ... d'239' | |
| 1077 mullw 1 ; Copy row to PRODH:L | |
| 1078 rcall TFT_DataWrite_PROD | |
| 1079 | |
| 1080 movff ds_column,WREG ; Init X position. | |
| 1081 mullw 2 | |
| 1082 movlw .1 | |
| 1083 addwf PRODL,F | |
| 1084 movlw 0 | |
| 1085 addwfc PRODH,F ; +1 | |
| 1086 rcall pixel_write_col320 ; Start Address Vertical (.0 - .319) | |
| 1087 | |
| 1088 rcall TFT_DataRead_PROD ; read pixel | |
| 1089 rcall dump_screen_pixel | |
| 1090 | |
| 1091 decfsz ds_line,F | |
| 1092 bra dump_screen_3 | |
| 1093 rcall dump_screen_pixel_flush | |
| 1094 | |
| 1095 incf ds_column,F | |
| 1096 movlw .160 | |
| 1097 cpfseq ds_column | |
| 1098 bra dump_screen_1 | |
| 1099 | |
| 1100 bcf no_sensor_int | |
| 1101 clrf RCREG1 ; Clear receive buffer | |
| 1102 bcf RCSTA1,CREN ; Clear receiver status | |
| 1103 bsf RCSTA1,CREN | |
| 1104 bsf enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump) | |
| 1105 return | |
| 1106 | |
| 1107 | |
| 1108 ;============================================================================= | |
| 1109 ; Pixel compression | |
| 1110 ; | |
| 1111 ; Input: PRODH:L = pixel. | |
| 1112 ; Output: Compressed stream on output. | |
| 1113 ; Compressed format: | |
| 1114 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128). | |
| 1115 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1..64). | |
| 1116 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1..64). | |
| 1117 ; | |
| 1118 dump_screen_pixel: | |
| 1119 movf PRODH,W ; Compare pixel-high | |
| 1120 xorwf ds_pixel+1,W | |
| 1121 bnz dump_screen_pixel_1 ; Different -> dump. | |
| 1122 | |
| 1123 movf PRODL,W ; Compare pixel-low | |
| 1124 xorwf ds_pixel+0,W | |
| 1125 bnz dump_screen_pixel_1 ; Different -> dump. | |
| 1126 | |
| 1127 incf ds_count,F ; Same color: just increment. | |
| 1128 return | |
| 1129 | |
| 1130 dump_screen_pixel_1: ; Send (pixel,count) tuple | |
| 1131 movf ds_count,W ; Is count zero ? | |
| 1132 bz dump_screen_pixel_2 ; Yes: skip sending. | |
| 1133 | |
| 1134 movf ds_pixel+1,W ; This is a BLACK pixel ? | |
| 1135 iorwf ds_pixel+0,W | |
| 1136 bz dump_screen_pix_black ; YES. | |
| 1137 | |
| 1138 movf ds_pixel+1,W ; This is a white pixel ? | |
| 1139 andwf ds_pixel+0,W | |
| 1140 incf WREG | |
| 1141 bz dump_screen_pix_white ; YES. | |
| 1142 | |
| 1143 ; No: write the pixel itself... | |
| 1144 movlw .64 ; Max color pixel on a single byte. | |
| 1145 cpfsgt ds_count ; Skip if count > 64 | |
| 1146 movf ds_count,W ; W <- min(64,count) | |
| 1147 subwf ds_count,F ; ds_count <- ds_count-W | |
| 1148 decf WREG ; Save as 0..63 | |
| 1149 iorlw b'10000000' ; MARK as a color pixel. | |
| 1150 | |
| 1151 movwf TXREG | |
| 1152 call rs232_wait_tx ; wait for UART | |
| 1153 movff ds_pixel+1,TXREG | |
| 1154 call rs232_wait_tx ; wait for UART | |
| 1155 movff ds_pixel+0,TXREG | |
| 1156 call rs232_wait_tx ; wait for UART | |
| 1157 bra dump_screen_pixel_1 | |
| 1158 | |
| 1159 dump_screen_pixel_2: | |
| 1160 movff PRODH,ds_pixel+1 ; Save new pixel color | |
| 1161 movff PRODL,ds_pixel+0 | |
| 1162 movlw 1 | |
| 1163 movwf ds_count ; And set count=1. | |
| 1164 return | |
| 1165 | |
| 1166 dump_screen_pix_black: | |
| 1167 movlw .128 ; Max black pixel on a single byte. | |
| 1168 cpfsgt ds_count ; Skip if count > 128 | |
| 1169 movf ds_count,W ; W <- min(128,count) | |
| 1170 subwf ds_count,F ; ds_count <- ds_count-W | |
| 1171 decf WREG ; Save as 0..127 | |
| 1172 dump_screen_pix_3: | |
| 1173 movwf TXREG | |
| 1174 call rs232_wait_tx | |
| 1175 bra dump_screen_pixel_1 ; More to dump ? | |
| 1176 | |
| 1177 dump_screen_pix_white: | |
| 1178 movlw .64 ; Max white pixel on a single byte. | |
| 1179 cpfsgt ds_count ; Skip if count > 64 | |
| 1180 movf ds_count,W ; W <- min(64,count) | |
| 1181 subwf ds_count,F ; ds_count <- ds_count-W | |
| 1182 decf WREG ; Save as 0..63 | |
| 1183 iorlw b'11000000' ; MARK as a compressed white. | |
| 1184 bra dump_screen_pix_3 | |
| 1185 | |
| 1186 dump_screen_pixel_flush: | |
| 1187 clrf PRODH | |
| 1188 clrf PRODL | |
| 1189 rcall dump_screen_pixel_1 ; Send it | |
| 1190 dump_screen_pixel_reset: | |
| 1191 clrf ds_count ; But clear count. | |
| 1192 return | |
| 1193 | |
| 1194 end |
