-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: pin value can be higher than 127 so type should be uint8_t #359
base: master
Are you sure you want to change the base?
Conversation
i'd like to suggest Adafruit can use int16_t for pin numbers, this would prevent pin number > 127 from being treated as negative numbers. of course it'd not avoid all cases of issues but it'd avoid a majority of them. |
Issue was found by several STM32 users. ArdunioCore-API defined it as uint8_t by default: https://github.com/arduino/ArduinoCore-API/blob/173e8eadced2ad32eeb93bcbd5c49f8d6a055ea6/api/Common.h#L91 Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
I've fixed the Clang issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes a negative pin index is used to indicate that certain items (usu. reset or CS) aren’t connected to the MCU. Although the proposed changes will catch -1’s, I’m not certain that this is the only case, there may have been other negative values/meanings in certain code or libraries. Also this might generate lots of warnings or errors in any SPITFT subclasses that are still using int8_t, unless every single one of them is updated to cast pins to unsigned.
Possibly a more robust solution…and something I’d been considering a while back and just didn’t want to break everything…would be to introduce something like a GFX_pin_t, and typedef it to an int16_t only on whatever device(s) have pin ID’s > 127, and an int8_t everywhere else by default. Existing subclasses, since int8_t and GFX_pin_t are the same thing nearly everywhere, would then compile without complaint (I think)…and then one by one any SPITFT subclasses could be updated to use GFX_pin_t as the need arises.
Either approach requires eventually updating every SPITFT subclass, I don’t have a painless solution here. A third also-non-optimal solution would be only pins <= 127 are supported (but IIRC there was some chip or family, maybe it was certain STM32s, where pin numbers also incorporated the PORT # and thus are nearly always big 12-bit values).
Hi @PaintYourDragon
As stated, the STM32 core use the full range of but OK this is not the standard Arduino naming, just a convenient way to use a pin. 😉 About 12 bits, in STM32 core it does not exists. I take care about this to be Arduino compatible. |
When will this changed be merged? I have just had a longer debug session due to this issue. My finding btw is that the problem is solved by using the digital definitions of the pin ea Dx and not the analog definition PAx. I do not appose the change, but for future reference and other googlers, using the digital pin definition may solve your issue. At least for the STM32F4 generic definitions. |
Hi,
Issue was found by several STM32 users.
Several STM32 have more than 127 digital I/0's.
Moreover, STM32 uses some pin alias
PYn
(PA0
,PC13
,...) to ease usage, alias with analog capabilities start from 0xC0 soalias was also unusable to define
TFT_CS
,TFT_RST
,TFT_DC
.To go further, ArdunioCore-API defined it as uint8_t by default:
https://github.com/arduino/ArduinoCore-API/blob/173e8eadced2ad32eeb93bcbd5c49f8d6a055ea6/api/Common.h#L91
So I guess it is more compliant to use
uint8_t
.-1 default values are kept and check is done on
0xFF
Tested with SPI ST7789 and ST7735 devices.