Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8_t readSDToScreen_320x240i(uint32_t fromBlock)
- {
- if (!sdCardInitialized) return;
- uint8_t res1 = 0xff;
- uint8_t tries = 0;
- while (res1 == 0xff && tries < 32) {
- SPI_transfer(0xff);
- SDCS_LOW();
- SD_command(18, fromBlock, 0);
- res1 = SD_readRes1();
- if (res1 == 0xff) {
- SPI_transfer(0xff);
- SDCS_HIGH();
- tries++;
- }
- }
- cli();
- if (tries == 32)
- {
- return SD_ERR_CMD18_FAILED;
- }
- asm volatile(
- "ldi r16,1\n\t"
- "mov __tmp_reg__,r16\n\t"
- "clr __zero_reg__\n\t"
- "clr r22\n\t"
- "clr r23\n\t"
- "clr r24\n\t"
- "clr r25\n\t"
- "clr r18\n\t"
- "clr r26\n\t"
- "clr r27\n\t"
- "ldi r16, 0xff\n\t"
- // wait for datablock start (0xfe)
- "waitForDBStart:\n\t"
- "in r17, 0x2d\n\t"
- "in r17, 0x2e\n\t"
- "out 0x2e, r16\n\t"
- "waitForDBStartResponse:\n\t"
- "in r17, 0x2d\n\t"
- "sbrs r17, 7\n\t"
- "rjmp waitForDBStartResponse\n\t"
- "in r17, 0x2e\n\t"
- "cpi r17, 0xfe\n\t"
- "brne waitForDBStart\n\t"
- // initiate first SPI transfer of data block
- "out 0x2e, r16\n\t"
- "clr r20\n\t"
- "clr r21\n\t"
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "nop\n\t" // wait for the first byte to come through
- "SPItoScreenLoop:\n\t"
- // Read last byte from SPI
- "in r17, 0x2e\n\t"
- "push r17\n\t"
- // initiate next SPI transfer while we output to screen
- "out 0x2e, r16\n\t"
- // PORTF
- "out 0x11, r17\n\t"
- // PORTD
- "out 0x0b, r17\n\t"
- // Toggle ILI WR
- "cbi 0x08, 6\n\t"
- "sbi 0x08, 6\n\t"
- "rjmp checkDone\n\t"
- "sbrs r20,0\n\t"
- "rjmp checkDone\n\t"
- "rjmp checkDone\n\t"
- "add r18, __tmp_reg__\n\t"
- "adc r27, __zero_reg__\n\t"
- "cpi r18, 0x40\n\t"
- "brne checkDone\n\t"
- "cpi r27, 0x01\n\t"
- "brne checkDone\n\t"
- // next line
- "clr r18\n\t"
- "clr r27\n\t"
- "subi r26, 0xfe\n\t" // Add 2
- "sbrc r26, 0\n\t"
- "rjmp handleField1\n\t"
- "cpi r26, 0xf0\n\t" // 240 ? reset to 1
- "brne sendPASET\n\t"
- "ldi r26, 1\n\t"
- "rjmp sendPASET\n\t"
- "handleField1:\n\t"
- "cpi r26, 0xf1\n\t"
- "brne sendPASET\n\t" // 241 ? reset to 0
- "clr r26\n\t"
- "sendPASET:\n\t"
- // Send PASET command 0x2b
- "ldi r17, 0x2b\n\t"
- "out 0x11, r17\n\t"
- "out 0x0b, r17\n\t"
- "cbi 0x0e, 6\n\t"
- "cbi 0x08, 6\n\t"
- "sbi 0x08, 6\n\t"
- "sbi 0x0e, 6\n\t"
- // Send zero
- "out 0x11, __zero_reg__\n\t"
- "out 0x0b, __zero_reg__\n\t"
- "cbi 0x08, 6\n\t"
- "sbi 0x08, 6\n\t"
- // Send current row as start address
- "out 0x11, r26\n\t"
- "out 0x0b, r26\n\t"
- "cbi 0x08, 6\n\t"
- "sbi 0x08, 6\n\t"
- // Send zero
- "out 0x11, __zero_reg__\n\t"
- "out 0x0b, __zero_reg__\n\t"
- "cbi 0x08, 6\n\t"
- "sbi 0x08, 6\n\t"
- // Send 0xef as end address
- "out 0x11, r26\n\t"
- "out 0x0b, r26\n\t"
- "cbi 0x08, 6\n\t"
- "sbi 0x08, 6\n\t"
- // Send RAMWR command 0x2c
- "ldi r17, 0x2c\n\t"
- "out 0x11, r17\n\t"
- "out 0x0b, r17\n\t"
- "cbi 0x0e, 6\n\t"
- "cbi 0x08, 6\n\t"
- "sbi 0x08, 6\n\t"
- "sbi 0x0e, 6\n\t"
- "checkDone:\n\t"
- // Check if we are done
- "add r20, __tmp_reg__\n\t"
- "adc r21, __zero_reg__\n\t"
- "cpi r21,2\n\t" // test against 512
- "brne jmpToStart\n\t"
- "cpi r20,0\n\t" // test against 513 as we skip the first write to let us write to screen while waiting for SPI
- "brne jmpToStart\n\t"
- "rjmp readCRC\n\t"
- "jmpToStart:\n\t"
- "rjmp SPItoScreenLoop\n\t"
- "readCRC:\n\t"
- "in r17, 0x2d\n\t"
- "in r17, 0x2e\n\t"
- "out 0x2e, r16\n\t"
- "readCRCResponse:\n\t"
- "in r17, 0x2d\n\t"
- "sbrs r17, 7\n\t"
- "rjmp readCRCResponse\n\t"
- "checkLoop:\n\t"
- "add r22, __tmp_reg__\n\t"
- "adc r23, __zero_reg__\n\t"
- "adc r24, __zero_reg__\n\t"
- "cpi r22, 0xbe\n\t"
- "brne jumpToDBStart\n\t"
- "cpi r23, 0xd3\n\t"
- "brne jumpToDBStart\n\t"
- "cpi r24, 0x04\n\t"
- "brne jumpToDBStart\n\t"
- "rjmp end\n\t"
- "jumpToDBStart:\n\t"
- "rjmp waitForDBStart\n\t"
- "end:\n\t"
- :
- :
- : "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27"
- );
- sei();
- SDCS_HIGH();
- SD_CMD12();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement