@@ -86,14 +86,16 @@ STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
8686//| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1.
8787//|
8888//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value).
89- //| Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), or bytearray.
89+ //| Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), bytearray,
90+ //| or a tuple or list of 3 integers.
9091//|
9192//| This allows you to::
9293//|
9394//| palette[0] = 0xFFFFFF # set using an integer
9495//| palette[1] = b'\xff\xff\x00' # set using 3 bytes
9596//| palette[2] = b'\xff\xff\x00\x00' # set using 4 bytes
9697//| palette[3] = bytearray(b'\x00\x00\xFF') # set using a bytearay of 3 or 4 bytes
98+ //| palette[4] = (10, 20, 30) # set using a tuple of 3 integers
9799//|
98100STATIC mp_obj_t palette_subscr (mp_obj_t self_in , mp_obj_t index_in , mp_obj_t value ) {
99101 if (value == MP_OBJ_NULL ) {
@@ -111,6 +113,12 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val
111113 return MP_OBJ_NEW_SMALL_INT (common_hal_displayio_palette_get_color (self , index ));
112114 }
113115
116+ // Convert a tuple or list to a bytearray.
117+ if (MP_OBJ_IS_TYPE (value , & mp_type_tuple ) ||
118+ MP_OBJ_IS_TYPE (value , & mp_type_list )) {
119+ value = mp_type_bytes .make_new (& mp_type_bytes , 1 , & value , NULL );
120+ }
121+
114122 uint32_t color ;
115123 mp_int_t int_value ;
116124 mp_buffer_info_t bufinfo ;
@@ -130,7 +138,7 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val
130138 }
131139 color = int_value ;
132140 } else {
133- mp_raise_TypeError (translate ("color buffer must be a buffer or int" ));
141+ mp_raise_TypeError (translate ("color buffer must be a buffer, tuple, list, or int" ));
134142 }
135143 common_hal_displayio_palette_set_color (self , index , color );
136144 return mp_const_none ;
0 commit comments