Skip to content

RGBMatrix: Detect invalid bit_depth selection #3661

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

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-15 16:06+0530\n"
"POT-Creation-Date: 2020-11-11 14:06-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -416,6 +416,11 @@ msgstr ""
msgid "Bit clock and word select must share a clock unit"
msgstr ""

#: shared-bindings/rgbmatrix/RGBMatrix.c
#, c-format
msgid "Bit depth must be from 1 to 6 inclusive, not %d"
msgstr ""

#: shared-bindings/audiobusio/PDMIn.c
msgid "Bit depth must be multiple of 8."
msgstr ""
Expand Down
7 changes: 6 additions & 1 deletion shared-bindings/rgbmatrix/RGBMatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n
uint8_t clock_pin = validate_pin(args[ARG_clock_pin].u_obj);
uint8_t latch_pin = validate_pin(args[ARG_latch_pin].u_obj);
uint8_t output_enable_pin = validate_pin(args[ARG_output_enable_pin].u_obj);
int bit_depth = args[ARG_bit_depth].u_int;

if (bit_depth <= 0 || bit_depth > 6) {
mp_raise_ValueError_varg(translate("Bit depth must be from 1 to 6 inclusive, not %d"), bit_depth);
}

validate_pins(MP_QSTR_rgb_pins, rgb_pins, MP_ARRAY_SIZE(self->rgb_pins), args[ARG_rgb_list].u_obj, &rgb_count);
validate_pins(MP_QSTR_addr_pins, addr_pins, MP_ARRAY_SIZE(self->addr_pins), args[ARG_addr_list].u_obj, &addr_count);
Expand Down Expand Up @@ -229,7 +234,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n

common_hal_rgbmatrix_rgbmatrix_construct(self,
args[ARG_width].u_int,
args[ARG_bit_depth].u_int,
bit_depth,
rgb_count, rgb_pins,
addr_count, addr_pins,
clock_pin, latch_pin, output_enable_pin,
Expand Down