ZodiacMentor

PP3K Video Player tight loop

Feb 8th, 2022
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. asm volatile(
  2. "ldi r16,1\n\t"
  3. "mov __tmp_reg__,r16\n\t"
  4. "clr __zero_reg__\n\t"
  5. "clr r22\n\t"
  6. "clr r23\n\t"
  7. "clr r24\n\t"
  8. "clr r25\n\t"
  9. "ldi r16, 0xff\n\t"
  10.  
  11. // wait for datablock start (0xfe)
  12. "waitForDBStart:\n\t"
  13. "in r17, 0x2d\n\t"
  14. "in r17, 0x2e\n\t"
  15. "out 0x2e, r16\n\t"
  16. "waitForDBStartResponse:\n\t"
  17. "in r17, 0x2d\n\t"
  18. "sbrs r17, 7\n\t"
  19. "rjmp waitForDBStartResponse\n\t"
  20. "in r17, 0x2e\n\t"
  21. "cpi r17, 0xfe\n\t"
  22. "brne waitForDBStart\n\t"
  23.  
  24. "clr r20\n\t"
  25. "clr r21\n\t"
  26.  
  27. // initiate first SPI transfer of data block
  28. "out 0x2e, r16\n\t"
  29. "nop\n\t" // wait for the first byte to come through
  30. "nop\n\t" // wait for the first byte to come through
  31. "nop\n\t" // wait for the first byte to come through
  32. "nop\n\t" // wait for the first byte to come through
  33. "nop\n\t" // wait for the first byte to come through
  34. "nop\n\t" // wait for the first byte to come through
  35. "nop\n\t" // wait for the first byte to come through
  36. "nop\n\t" // wait for the first byte to come through
  37. "nop\n\t" // wait for the first byte to come through
  38. "nop\n\t" // wait for the first byte to come through
  39. "nop\n\t" // wait for the first byte to come through
  40. "nop\n\t" // wait for the first byte to come through
  41. "nop\n\t" // wait for the first byte to come through
  42. "nop\n\t" // wait for the first byte to come through
  43. "nop\n\t" // wait for the first byte to come through
  44. "nop\n\t" // wait for the first byte to come through
  45.  
  46. "SPItoScreenLoop:\n\t"
  47. // Read last byte from SPI
  48. "in r17, 0x2e\n\t"
  49. // initiate next SPI transfer while we output to screen
  50. "out 0x2e, r16\n\t"
  51.  
  52. // low nibble to PORTF high
  53. "mov r19, r17\n\t"
  54. "lsl r19\n\t"
  55. "lsl r19\n\t"
  56. "lsl r19\n\t"
  57. "lsl r19\n\t"
  58. "out 0x11, r19\n\t"
  59. // high nibble to PORTD low
  60. "in r18, 0x0b\n\t"
  61. "andi r18, 0xf0\n\t"
  62. "lsr r17\n\t"
  63. "lsr r17\n\t"
  64. "lsr r17\n\t"
  65. "lsr r17\n\t"
  66. "or r18, r17\n\t"
  67. "out 0x0b, r18\n\t"
  68. // Toggle ILI WR
  69. "cbi 0x08, 6\n\t"
  70. "sbi 0x08, 6\n\t"
  71.  
  72. // Check if we are done
  73. "add r20, __tmp_reg__\n\t"
  74. "adc r21, __zero_reg__\n\t"
  75. "cpi r21,2\n\t" // test against 512
  76. "brne jmpToStart\n\t"
  77. "cpi r20,0\n\t" // test against 513 as we skip the first write to let us write to screen while waiting for SPI
  78. "brne jmpToStart\n\t"
  79.  
  80. "rjmp readCRC\n\t"
  81.  
  82. "jmpToStart:\n\t"
  83. "rjmp SPItoScreenLoop\n\t"
  84.  
  85. "readCRC:\n\t"
  86. "in r17, 0x2d\n\t"
  87. "in r17, 0x2e\n\t"
  88. "out 0x2e, r16\n\t"
  89. "readCRCResponse:\n\t"
  90. "in r17, 0x2d\n\t"
  91. "sbrs r17, 7\n\t"
  92. "rjmp readCRCResponse\n\t"
  93.  
  94. "checkLoop:\n\t"
  95. "add r22, __tmp_reg__\n\t"
  96. "adc r23, __zero_reg__\n\t"
  97. "adc r24, __zero_reg__\n\t"
  98. "adc r25, __zero_reg__\n\t"
  99. "cpi r22, 0xd6\n\t"
  100. "brne jumpToDBStart\n\t"
  101. "cpi r23, 0x07\n\t"
  102. "brne jumpToDBStart\n\t"
  103. "cpi r24, 0x04\n\t"
  104. "brne jumpToDBStart\n\t"
  105. "cpi r25, 0x00\n\t"
  106. "brne jumpToDBStart\n\t"
  107. "rjmp end\n\t"
  108.  
  109. "jumpToDBStart:\n\t"
  110. "rjmp waitForDBStart\n\t"
  111.  
  112. "end:\n\t"
  113. :
  114. :
  115. : "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25"
  116. );
Advertisement
Add Comment
Please, Sign In to add comment