From e4b9c168912799d126894dbdf44f6af5c5d4878d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 28 Sep 2020 19:03:04 -0500 Subject: [PATCH] rgbmatrix: Check that the number of rgb pins is supported. Having zero RGB pins may not have been caught, nor having a non-multiple-of-6 value. Generally, users will only have 6 RGB pins unless they are driving multiple matrices in parallel. No existing breakouts exist to do this, and there are probably not any efficient pinouts to be had anyway. --- locale/circuitpython.pot | 10 +++++++++- shared-bindings/rgbmatrix/RGBMatrix.c | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index b6de5667e2..ec27b2f6b6 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-09-29 11:11+0530\n" +"POT-Creation-Date: 2020-09-29 19:54-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1662,6 +1662,10 @@ msgid "" "exit safe mode.\n" msgstr "" +#: shared-bindings/rgbmatrix/RGBMatrix.c +msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" +msgstr "" + #: supervisor/shared/safe_mode.c msgid "" "The microcontroller's power dipped. Make sure your power supply provides\n" @@ -3516,6 +3520,10 @@ msgstr "" msgid "watchdog timeout must be greater than 0" msgstr "" +#: shared-bindings/rgbmatrix/RGBMatrix.c +msgid "width must be greater than zero" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "window must be <= interval" msgstr "" diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index 6a99e1f3dd..7ddbd36fb5 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -73,6 +73,10 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_ uint32_t port = clock_pin / 32; uint32_t bit_mask = 1 << (clock_pin % 32); + if (rgb_pin_count <= 0 || rgb_pin_count % 6 != 0 || rgb_pin_count > 30) { + mp_raise_ValueError_varg(translate("The length of rgb_pins must be 6, 12, 18, 24, or 30")); + } + for (uint8_t i = 0; i < rgb_pin_count; i++) { uint32_t pin_port = rgb_pins[i] / 32;