Read from TFT to check status

This commit is contained in:
Justin C. Miller
2025-04-06 14:04:10 -07:00
parent 7b1b4b916a
commit 36c4df431b
2 changed files with 27 additions and 8 deletions

View File

@@ -29,7 +29,8 @@ extern "C" {
}
static constexpr unsigned i2c_baud = 400 * 1000;
static constexpr unsigned spi_baud = 24 * 1000 * 1000;
//static constexpr unsigned spi_baud = 24 * 1000 * 1000;
static constexpr unsigned spi_baud = 800 * 1000;
static constexpr unsigned hid_update_ms = 1000/20; // 20Hz

View File

@@ -12,6 +12,8 @@ enum class cmd : uint8_t {
// Page 105
nop = 0x00, // p.114, NOP
swreset = 0x01, // p.115, Software reset
rddidif = 0x04, // p.116, Read display ID info
rddpm = 0x0a, // p.121, Read display power mode
slpin = 0x10, // p.131, Sleep in
slpout = 0x11, // p.133, Sleep out
@@ -50,8 +52,8 @@ enum class cmd : uint8_t {
namespace {
const uint8_t init_cmds[] = {
// SWRESET Soft reset, then delay 10 ms
uint8_t(cmd::swreset), 0x80 + 100 / 5,
// SWRESET Soft reset, then delay 120 ms
uint8_t(cmd::swreset), 0x80 + 120 / 5,
// SETEXTC? Set extension command
uint8_t(cmd::setextc), 3, 0xFF, 0x83, 0x57,
@@ -118,7 +120,7 @@ void tft::init()
gpio_init(m_dc);
gpio_set_dir(m_dc, GPIO_OUT);
gpio_put(m_dc, 1); // Initialize to 1 (data mode)
sleep_ms(10);
{
spi::cs {m_cs};
@@ -141,12 +143,28 @@ void tft::init()
write_command(command, buf, nargs);
if (delay) {
log::trace("Delay %dms", delay);
log::trace("delay %dms", delay);
sleep_ms(delay);
}
}
}
{
spi::cs {m_cs};
uint32_t didif = 0xbababa;
write_command(cmd::rddidif);
spi_read_blocking(spi_default, 0, reinterpret_cast<uint8_t*>(&didif), sizeof(didif));
log::debug("read display id %08x", didif);
}
{
spi::cs {m_cs};
uint16_t dpm = 0xbaba;
write_command(cmd::rddpm);
spi_read_blocking(spi_default, 0, reinterpret_cast<uint8_t*>(&dpm), sizeof(dpm));
log::debug("read display power mode %04x", dpm);
}
{
spi::cs {m_cs};
uint16_t w = 480/3;
@@ -155,11 +173,11 @@ void tft::init()
uint16_t color = __builtin_bswap16(startup_color);
//color = 0xffff;
color = 0xf800;
log::info("Drawing %dx%d square, color %04x", w, h, color);
log::info("drawing %dx%d square, color %04x", w, h, color);
set_draw_rect(0, 0, w, h);
for (unsigned i = 0; i < n; ++i)
spi_write_blocking(spi_default, reinterpret_cast<uint8_t*>(&color), sizeof(color));
log::trace("Wrote SPI %d data bytes", n);
log::trace("wrote SPI %d data bytes", n);
}
}
@@ -172,7 +190,7 @@ void tft::write_command(cmd command, uint8_t *args, unsigned args_len)
if (args_len)
spi_write_blocking(spi_default, args, args_len);
log::trace("Wrote SPI command %02x, %d data bytes", command, args_len);
log::trace("wrote SPI command %02x, %d data bytes", command, args_len);
}
void tft::set_draw_rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h)