-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 FourWire
and I2CDisplay
argument validation
#5450
Conversation
didnt test but lgtm |
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.
@FoamyGuy Thanks for catching & fixing this issue. One suggestion, looks good otherwise.
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.
Thanks, good find!
I wonder if you can't use mp_arg_validate_type
with &busio_spi_type
instead. as it stands, won't passing in something else, like the number 7 or an empty list (or even, more plausibly, a bitbangio SPI object) still cause problems?
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.
(see above comment)
Latest commit changes to use |
I'm not sure why more boards didn't fail, but it seems you need to include the header that gives the declaration of --- a/shared-bindings/displayio/FourWire.c
+++ b/shared-bindings/displayio/FourWire.c
@@ -32,6 +32,7 @@
#include "py/binary.h"
#include "py/objproperty.h"
#include "py/runtime.h"
+#include "shared-bindings/busio/SPI.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/util.h" |
Do you mind checking out the I2CDisplay code while you're working on it? |
Indeed I2CDisplay does exhibit a similar hard crash with this reproducer: import board
import displayio
import adafruit_displayio_ssd1306
displayio.release_displays()
oled_reset = board.D9
# Use for I2C
i2c = board.I2C()
display_bus = displayio.I2CDisplay(None, device_address=0x3C, reset=oled_reset)
WIDTH = 128
HEIGHT = 32 # Change to 64 if needed
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=WIDTH, height=HEIGHT) I'll put a fix in for it as well. |
Latest commit fixes the SPI include and implements similar validation in I2CDisplay |
FourWire
and I2CDisplay
argument validation
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.
Thank you, so clean & to the point now. Nice to have those hardfaults fixed.
resolves #5449
Check spi argument for
None
and raise a ValueError instead of crashing.Tested successfully with code from the issue. on:
With the build from the PR it does successfully raise the ValueError instead of crashing into the broken state.