-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
226 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Raspberry Pi Pico PIO program to output 18 bit data to a TFT | ||
// controller via a SPI output data path. | ||
|
||
//"Set" set: 1 output pin, TFT_DC | ||
// Side set: 1 output pin, TFT_SCLK | ||
// Data set: 1 output pin, TFT_MOSI | ||
|
||
.program tft_io | ||
.side_set 1 opt ; The TFT_SCLK output. | ||
|
||
// The C++ code switches between the 8 bits and 16 bits loops | ||
// by waiting for the SM to be idle and setting its PC. | ||
// | ||
|
||
// 8 bit transfer | ||
public start_8: | ||
// Pull the next 32 bit value from the TX FIFO. | ||
pull side 0 | ||
// Lose the top 24 bits, send 1st bit | ||
out pins, 25 | ||
// Now send remaining bits | ||
jmp spi_out side 1 | ||
|
||
public set_addr_window: | ||
// Loop count in x for caset, paset and ramwr | ||
set x, 2 side 0 | ||
pull_cmd: | ||
// Set DC low | ||
set pins, 0 | ||
// Fetch and output LS byte (caset, paset or ramwr), discarding top 24 bits, set WR low | ||
pull side 0 | ||
out pins, 25 | ||
nop side 1 | ||
next_cmd_bit: | ||
out pins, 1 side 0 | ||
jmp !osre, next_cmd_bit side 1 | ||
// Set DC high | ||
set pins, 1 side 0 | ||
// Finish if 3rd cmd byte ramwr sent (x == 0) | ||
jmp !x, start_tx | ||
pull | ||
next_xy: | ||
// send 32 bit start and end coordinates | ||
out pins, 1 side 0 | ||
jmp !osre, next_xy side 1 | ||
// Loop back for next command | ||
jmp x--, pull_cmd side 0 | ||
// End | ||
jmp start_tx | ||
|
||
public block_fill: | ||
// Fetch colour value | ||
pull side 0 | ||
// Move colour to x | ||
mov x, osr | ||
// Fetch pixel count | ||
pull | ||
// Move pixel count to y | ||
mov y, osr | ||
next_16: | ||
// Copy colour value back into osr | ||
mov osr, x side 0 | ||
// Lose the top 8 bits, send 1st bit | ||
out pins, 9 side 0 | ||
nop side 1 | ||
next_bit: | ||
// Output next remaining bits | ||
out pins, 1 side 0 | ||
// Set TFT_SCLK high and jump for next bit | ||
jmp !osre, next_bit side 1 | ||
// Decrement count and loop | ||
jmp y--, next_16 side 0 | ||
// Now drop back to 16 bit output | ||
|
||
.wrap_target | ||
public start_tx: | ||
// Pull the next 32 bit value from the TX FIFO. | ||
// Send the bottom 24 bits | ||
pull side 0 | ||
// Drop the first 8 bits, write first bit | ||
out pins, 9 side 0 | ||
nop side 1 | ||
spi_out: | ||
// Output the remaining bits | ||
out pins, 1 side 0 | ||
// Set TFT_SCLK high and jump for next bit | ||
jmp !osre, spi_out side 1 | ||
// Return to start | ||
.wrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// -------------------------------------------------- // | ||
// This file is autogenerated by pioasm; do not edit! // | ||
// -------------------------------------------------- // | ||
|
||
#pragma once | ||
|
||
#if !PICO_NO_HARDWARE | ||
#include "hardware/pio.h" | ||
#endif | ||
|
||
// ------ // | ||
// tft_io // | ||
// ------ // | ||
|
||
#define tft_io_wrap_target 27 | ||
#define tft_io_wrap 31 | ||
|
||
#define tft_io_offset_start_8 0u | ||
#define tft_io_offset_set_addr_window 3u | ||
#define tft_io_offset_block_fill 17u | ||
#define tft_io_offset_start_tx 27u | ||
|
||
static const uint16_t tft_io_program_instructions[] = { | ||
0x90a0, // 0: pull block side 0 | ||
0x6019, // 1: out pins, 25 | ||
0x181e, // 2: jmp 30 side 1 | ||
0xf022, // 3: set x, 2 side 0 | ||
0xe000, // 4: set pins, 0 | ||
0x90a0, // 5: pull block side 0 | ||
0x6019, // 6: out pins, 25 | ||
0xb842, // 7: nop side 1 | ||
0x7001, // 8: out pins, 1 side 0 | ||
0x18e8, // 9: jmp !osre, 8 side 1 | ||
0xf001, // 10: set pins, 1 side 0 | ||
0x003b, // 11: jmp !x, 27 | ||
0x80a0, // 12: pull block | ||
0x7001, // 13: out pins, 1 side 0 | ||
0x18ed, // 14: jmp !osre, 13 side 1 | ||
0x1044, // 15: jmp x--, 4 side 0 | ||
0x001b, // 16: jmp 27 | ||
0x90a0, // 17: pull block side 0 | ||
0xa027, // 18: mov x, osr | ||
0x80a0, // 19: pull block | ||
0xa047, // 20: mov y, osr | ||
0xb0e1, // 21: mov osr, x side 0 | ||
0x7009, // 22: out pins, 9 side 0 | ||
0xb842, // 23: nop side 1 | ||
0x7001, // 24: out pins, 1 side 0 | ||
0x18f8, // 25: jmp !osre, 24 side 1 | ||
0x1095, // 26: jmp y--, 21 side 0 | ||
// .wrap_target | ||
0x90a0, // 27: pull block side 0 | ||
0x7009, // 28: out pins, 9 side 0 | ||
0xb842, // 29: nop side 1 | ||
0x7001, // 30: out pins, 1 side 0 | ||
0x18fe, // 31: jmp !osre, 30 side 1 | ||
// .wrap | ||
}; | ||
|
||
#if !PICO_NO_HARDWARE | ||
static const struct pio_program tft_io_program = { | ||
.instructions = tft_io_program_instructions, | ||
.length = 32, | ||
.origin = -1, | ||
}; | ||
|
||
static inline pio_sm_config tft_io_program_get_default_config(uint offset) { | ||
pio_sm_config c = pio_get_default_sm_config(); | ||
sm_config_set_wrap(&c, offset + tft_io_wrap_target, offset + tft_io_wrap); | ||
sm_config_set_sideset(&c, 2, true, false); | ||
return c; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters