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

When using another SPI device with other settings, display doesn't change SPI settings back #1

Open
MrTucks opened this issue Jan 31, 2019 · 3 comments

Comments

@MrTucks
Copy link

MrTucks commented Jan 31, 2019

This library only sets the SPI settings once, when it's initialized.
This is a problem when using multiple SPI devices with different settings. Because then the other library's settings overwrite the settings of this one and the display doesn't work properly.

I noticed this bug because drawing on the display was very slow (until restarting the Arduino) after doing anything with a SD-card because the SD library used a way slower SPI speed.

P.S: I hope you understand what I mean and please be patient with me, I'm still new to Git and GitHub. And your library saved me! Thank you so much :) The library from the vendor of the LCD wasn't compatible with AdafruitGFX. Could I have made only the Pull Request without opening an Issue?

@MrTucks
Copy link
Author

MrTucks commented Jan 31, 2019

#2 This is my fix of this bug. Please read the comment on it. :)

@prenticedavid
Copy link
Owner

Thanks for the feedback.

Yes, it is wise to use SPI transactions especially when devices use different modes and speeds.
SD (and FatFS) has always set its own SPI mode. The transactions are fairly lengthy. e.g. transferring a 512 byte sector.
Something like tft.drawPixel() is only a few SPI bytes. It is expensive to beginTransaction() for every pixel.

If you are drawing an image from SD it is more efficient to only beginTransaction(tftSetting) after an SD call.

You can either treat each SPI device as equal i.e. beginTransaction(eachSetting) with every CS_ACTIVE
Or choose one SPI device as "preferred" i.e. restore to beginTransaction(preferredSetting) after using other SPI devices.

beginTransaction(eachSetting) is the safest way to do things. I will investigate the performance cost.
It should make little difference to fillRect(), pushColors() but print(), drawPixel() will be slower.

David.

@MrTucks
Copy link
Author

MrTucks commented Feb 3, 2019

Thank you

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

2 participants