Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ST7789 display not working with FT232H expander #826

Open
HakanL opened this issue Feb 13, 2025 · 1 comment
Open

ST7789 display not working with FT232H expander #826

HakanL opened this issue Feb 13, 2025 · 1 comment

Comments

@HakanL
Copy link

HakanL commented Feb 13, 2025

Describe the bug
On my Windows 11 PC I have a FT232H connected to a ST7789 display. When calling Show() on the display (MicroGraphics) my application hangs. I have traced it into the TftSpiBase calling Exchange on the SpiBus to write the data and in the Ft232H driver it seems that if there is no data available (displays don't send anything back, MISO/CIPO isn't even connected) then the code for the FT232H will just spin, looking for bytes to receive, see this snippet:

    internal int ReadInto(Span<byte> buffer)
    {
        var totalRead = 0;
        uint read = 0;

        while (totalRead < buffer.Length)
        {
            var available = GetAvailableBytes();
            if (available > 0)
            {
                Native.CheckStatus(
                    FT_Read(Handle, in buffer[totalRead], available, ref read));

                totalRead += (int)read;
            }
        }

        return totalRead;
    }

In the above code GetAvailableBytes is always returning 0, so it will spin forever. I believe the root cause is that the TftSpiBase is calling Exchange on the SpiBus, instead of Write.

To Reproduce
Steps to reproduce the behavior:

  1. Go to the Ft232h_Sample and add this method:
async Task TestSPIDisplay(FtdiExpander expander)
{
    var display = new St7789
        (
            spiBus: expander.CreateSpiBus(),
            chipSelectPin: expander.Pins.D0,
            dcPin: expander.Pins.D1,
            resetPin: null,
            135, 240
        );

    var microGraphics = new MicroGraphics(display)
    {
        CurrentFont = new Font12x16(),
        Rotation = RotationType._270Degrees
    };

    microGraphics.Clear();
    microGraphics.DrawText(0, 0, "Loading Menu");
    microGraphics.Show();

    while (true)
    {
        Debug.WriteLine("Sleeping...");

        await Task.Delay(1000);
    }
}
  1. Run it
  2. If you set a breakpoint you'll see that we never get to the while (true) loop.
    Note that you can run this without a display connected, but you need a FT232H adapter hooked up.

Expected behavior
No hanging or spinning loop, beautiful MicroGraphics visible on the display

@HakanL
Copy link
Author

HakanL commented Feb 13, 2025

Potentially related to #727

HakanL added a commit to HakanL/Meadow.Foundation that referenced this issue Feb 13, 2025
Changed API for ST7789 to have the reset pin optional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant